   function gEle(element)
   {
      return document.getElementById(element);
   } // gEle

   function formReset(IdForm)
   {
      document.getElementById(IdForm).reset();
   } // formReset
   
   function val_numerico(obj, obj_type)
   {
      if (obj_type == "INT")
         value = parseInt(obj.value);
      else if (obj_type == "FLOAT")
         value = parseFloat(obj.value);
   
     if (isNaN(value)) 
   		return false;
     else 
   		return true;
   } // val_numerico
   
   function getRadioValueChecked(obj)
   {
      for (i=0; i < obj.length; i++) {
         if (obj[i].checked)
            return obj[i].value;
      }
      
      return -1;	
   } // getRadioValueChecked
   
   function getSelectValue(obj)
   {
      for (i=0; i < obj.length; i++){
         if (obj.options[i].selected)
            return obj.options[i].value;
      }
      return "-1";	
   } // getSelectValue
   
   function val_input(obj, obj_type)
   {
      if (obj_type == "TEXT" || obj_type == "PASSWORD"){
    	   if (obj.value.length == 0) {
            obj.focus();
            return false;
         }
    	   else 
      		return true;
    	}
      else if (obj_type == "SELECT") {
         for (i=0; i < obj.length; i++){
            if (obj.options[i].selected && obj.options[i].value != -1)
               return true;
         }
         return false;	
      }
      else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX"){
         if (obj.checked)
            return true;
         else
       		return false;	
      }
      else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {
         for (i=0; i < obj.length; i++) {
            if (obj[i].checked)
               return true;
         }
         return false;	
      }
   } // val_input
   
   function confirmABC(boton)
   {
      mensaje = "";
      if (boton.value == "Alta") {
         mensaje = "Alta, presione aceptar para confirmar";
      }
      else if (boton.value == "Actualizar") {
         mensaje = "Actualizar, presione aceptar para confirmar";
      }
      else if (boton.value == "Eliminar") {
         mensaje = "Eliminar, presione aceptar para confirmar";
      }
      
      return confirm(mensaje);
   } // confirmar_abc

   function addCR(str)
   {
      return (str + " \r\n");
   } // addCR

   function validaEmail(obj)
   {
      var str = obj.value; // email string
      var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
      var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
      if (!reg1.test(str) && reg2.test(str))  // if syntax is valid
         return true;

      return false;
   } // validaEmail
   

/*********************************  Objeto FormMsg ***************************************/

   function validaClave(obj)  // valida clave de distribuidora
   {
      var clave;
      
      clave = obj.value.toUpperCase();
      if (clave.length < 5)
         return false;
      else {
         if (clave.charAt(0) != "M")
            return false;
         else if (isNaN(parseInt(clave.charAt(1))))
            return false;
         else if (isNaN(parseInt(clave.charAt(2))))
            return false;
         else if (isNaN(parseInt(clave.charAt(3))))
            return false;
         else if (isNaN(parseInt(clave.charAt(4))))
            return false;
      }
      return true;
   } // validaClave

   function input(obj, obj_type)
   {
      if (obj_type == "TEXT" || obj_type == "PASSWORD"){
    	   if (obj.value.length == 0) {
            return false;
         }
    	   else 
      		return true;
    	}
      else if (obj_type == "SELECT") {
         for (i=0; i < obj.length; i++){
            if (obj.options[i].selected && obj.options[i].value != -1)
               return true;
         }
         return false;	
      }
      else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX"){
         if (obj.checked)
            return true;
         else
       		return false;	
      }
      else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {
         for (i=0; i < obj.length; i++) {
            if (obj[i].checked)
            return true;
         }
         return false;	
      }
   } // input
   
   function formatEmail(obj)
   {
      var str = obj.value; // email string
      var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
      var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
      if (!reg1.test(str) && reg2.test(str))  // if syntax is valid
         return true;

      return false;
   } // formatEmail

   function select_empty(obj)
   {
      return (obj.length == 0);	
   } // select_empty
   
   function select_all(obj)
   {
      for (i=0; i < obj.length; i++)
         obj.options[i].selected = true;
   } // select_all
      
/************************************ Metodos de FormMsg *******************************/
   
   function chk_DisClave(obj, msg)
   {
      if (!validaClave(obj))
         this.addMsgObj(msg, obj);
   } // chk_DisClave
   
   function chk_input(obj, obj_type, msg)
   {
      if (!input(obj, obj_type)) {
         if (obj_type == "TEXT" || obj_type == "PASSWORD")
            this.addMsgObj(msg, obj);
         else
            this.addMsg(msg);
      }
   } // chk_input
   
   function chk_empty_lst(obj, msg)
   {
      if (select_empty(obj)) {
         this.addMsg(msg);
      }
   } // chk_empty_lst
   
   function chk_email(obj, msg)
   {
      if (!formatEmail(obj))
         this.addMsgObj(msg, obj);
   } // chk_email
   
   function setMsg(msg)
   {
      this.msg = addCR(msg);
   } // setMsg

   function addMsg(message)
   {
      this.msg += addCR(message);
      this.error = true;
   } // addMsg
   
   function addMsgObj(message, obj)
   {
      this.msg += addCR(message);
      if (this.error == false) {
         this.error = true;
         this.obj = obj;
      }
   } // addMsgObj
   
   function fieldError()
   {
      return (this.error);
   } // fieldError
   
   function showAlert()
   {
      alert(this.msg);
   } // showAlert
   
   function objFocus()
   {
      if (this.obj != null)
         this.obj.focus();
   } // objFocus
   
   function TFormMsg()
   {
      this.error = false;
      this.msg   = "";
      this.obj   = null;
      this.setMsg       = setMsg;
      this.addMsg       = addMsg;
      this.addMsgObj    = addMsgObj;
      this.fieldError   = fieldError;
      this.showAlert    = showAlert;
      this.chk_input    = chk_input;
      this.chk_email    = chk_email;
      this.chk_DisClave = chk_DisClave;
      this.objFocus     = objFocus;
      this.chk_empty_lst= chk_empty_lst;
   } // TFormMsg
   
