
var B_ArrSupport = new Array ("EntrarUsuario", "EntrarContrasena");

var C_ArrSupport = new Array ("Nombre", "Ap_Pat", "Telefono", "Email", "Usuario", "Contrasena")

var F_ArrSupport = new Array ("Nombre", "Direccion", "Telefono", "Email");

function submitform(lenguaje)
{
	if(ValidateForm2(Entrada,lenguaje)){
		document.Entrada.submit();
	}
}

  function ValidateForm2(forma,lengua) {
    if ( 
	     (ValidaControlesNoNulos(forma,B_ArrSupport,lengua))
	    )

	{
	  return true
	}
    else {
	  return false
	}
  }

function ValidateForm3(forma) {
    if ( 
	     (ValidaControlesNoNulos(forma,C_ArrSupport))
	    )

	{
	  return true
	}
    else {
	  return false
	}
  }


function ValidateForm6(forma) {
    if ( 
	     (ValidaControlesNoNulos(forma,F_ArrSupport))&&
		 (ValidaCorreo(forma.Email.value))
	 )

	{
	  return true
	}
    else {
	  return false
	}
  }



  function ValidaControlesNoNulos(Forma,Arreglo,lenguas) {
     for (var i = 0; i < Forma.elements.length; i++) {  	
       if (EstaEnArreglo(Forma.elements[i].name,Arreglo)) {
            	if (EsVacio(Forma.elements[i].value)) {
					if(lenguas==0) {
                    	alert ("Este campo es requerido."); 
					}
					else {
						alert ("This field is required."); 
						}
					
                    Forma.elements[i].focus()
                    Forma.elements[i].select()	
                    return false           
                }         
       }         
     }
    return true;
  }

  function EstaEnArreglo(Elemento, Arreglo) {
    for (var i = 0; i < Arreglo.length; i++) {  	
      if (Arreglo[i]==Elemento) {        
          return true
      }         
    }
    return false  
  }


  function EsVacio(Cadena) {
    if (Cadena == "" || Cadena == null) {
      return true
    }
  
   for (var i = 0; i < Cadena.length; i++) {
      var Caracter = Cadena.substring(i, i + 1)
      if (Caracter!=" " && Caracter!="\t" && Caracter!="\n") {
        return false
      }
   }
  
    return true
  }


function ValidaCorreo(correo){
  var i=1
  var final = correo.length
  var valido = false
  if(final>0){
    if((EsLetra(correo.charAt(0)))){ 
       var token = correo.charAt(i)
       while((i<final)&&(token!='@')&&((EsLetra(token))||(EsNumero(token))||(token=='.')||(token=='_'))){
          i++;   
          token = correo.charAt(i);
       }
       if ((token == '@')&&(correo.charAt(i+1)!= '.')&&((i+1)<final)){
          i++;   
          token = correo.charAt(i)
          while((i<final)&&(token!='.')&&((EsLetra(token))||(EsNumero(token))||(token=='_'))){
              i++;   
              token = correo.charAt(i)
          }
          if((token == '.')&&(correo.charAt(i+1)!='.')&&((i+1)<final)){
            i++;   
            token = correo.charAt(i)
            while((i<final)&&(token!='.')&&((EsLetra(token))||(EsNumero(token)||(token=='_')))){
               i++;   
               token = correo.charAt(i)
            }
            if (i>=final){
               return true
            }else{
               if ((token == '.')&&((i+1)<final)){
                 i++;   
                 token = correo.charAt(i)
                 while((i<final)&&((EsLetra(token))||(EsNumero(token))||(token=='_'))){
                   i++;   
                   token = correo.charAt(i)
                 }
                 if(i>=final){
                    return true
                 }else{
                    alert('El email es incorrecto.')
                    return false
                 }
               }else{
                  alert('El email es incorrecto.')
                  return false
               }
            }
          }else{
             alert('El email es incorrecto.')
             return false
          }
       }else{
          alert('El email es incorrecto.')
          return false
       }
    }else{
       alert('El email es incorrecto.')
       return false;
    }
  }else{
     return true;
  }
}

