var mail=1;

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We dont want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars arent allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which arent; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Finally, lets start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	// alert("La dirección de correo no es válida.");
	return false;
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
	//alert("La dirección de correo no es válida.");
    return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			// alert("La dirección de correo no es válida.");
			return false;
	    }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	// alert("La dirección de correo no es válida.");
    return false;
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   // alert("La dirección de correo no es válida.");
	return false;
}

// Make sure theres a host name preceding the domain.
if (len<2) {
	// alert("La dirección de correo no es válida.");
	return false;
}

// If weve gotten this far, everything is valid!
return true;
}

function isDigit(s){
    return (((s >= "0") && (s <= "9"))|| (s == " "))
  }

function isCPINT(){
    var i;
	s= document.registrar_usu.cp.value;

    for (i = 0; i < s.length; i++){
      var c = s.charAt(i);
      if (!isDigit(c)){
        return false;
        break;
      }
    }
    return true;
  }

 function isCPINT2(){
    var i;
	s= document.registrar_envio.cp.value;

    for (i = 0; i < s.length; i++){
      var c = s.charAt(i);
      if (!isDigit(c)){
        return false;
        break;
      }
    }
    return true;
  }

   function isCPINT3(){
    var i;
	s= document.registrar_factura.cpfactura.value;

    for (i = 0; i < s.length; i++){
      var c = s.charAt(i);
      if (!isDigit(c)){
        return false;
        break;
      }
    }
    return true;
  }

   function isCPINT4(){
    var i;
	s= document.registrar_datos_envio.cpenvio.value;

    for (i = 0; i < s.length; i++){
      var c = s.charAt(i);
      if (!isDigit(c)){
        return false;
        break;
      }
    }
    return true;
  }



   function doVa(){
   return true;
   }

 function ChecarDatos2(){
var chForm2=document.registrar_envio;

                if(chForm2.ident.value == ""){
		alert("Tu Identificador no ha sido proporcionado.");
		chForm2.ident.focus();
		return false;
	}

                if(chForm2.calleynu.value == ""){
		alert("Tu Calle y número no ha sido proporcionada.");
		chForm2.calleynu.focus();
		return false;
	}

                if(chForm2.colonia.value == ""){
		alert("Tu Colonia no ha sido proporcionada.");
		chForm2.colonia.focus();
		return false;
	}

                if(chForm2.calles.value == ""){
		alert("Entre las calle de la dirección no han sido proporcionadas.");
		chForm2.calles.focus();
		return false;
	}

                if(chForm2.ciudad.value == ""){
		alert("Tu ciudad no han sido proporcionada.");
		chForm2.ciudad.focus();
		return false;
	}

                if(chForm2.pais.value == ""){
		alert("Tu pais no han sido proporcionada.");
		chForm2.pais.focus();
		return false;
	}

                if(chForm2.estado.value == ""){
		alert("Tu Estado no han sido proporcionada.");
		chForm2.estado.focus();
		return false;
	}

                if(chForm2.cp.value == ""){
		alert("Tu Codigo postal no ha sido proporcionado.");
		chForm2.cp.focus();
		return false;
	}

                if(!isCPINT2())
	{
	 alert("Es necesario que escribas tu Código Postal de manera correcta, unicamente números (ej. 64000)!");
	chForm2.cp.focus()
		return false;
	}

                if(chForm2.tel1.value == ""){
		alert("Tu Teléfono no ha sido proporcionado.");
		chForm2.tel1.focus();
		return false;
	}


                if(chForm2.p_aut.value == ""){
		alert("La(s) persona(s) autorizada(s) para recibir tu(s) envio(s) no ha sido proporcionada(s).");
		chForm2.p_aut.focus();
		return false;
	}

        return true;
 }/*fin funcion ChecarDatos2()*/


function ChecarDatos(dato){

var chDay,chYear;
var chForm=document.registrar_usu;


			if(chForm.mail.value == ""){
              alert("Tu cuenta de mail  no ha sido proporcionada.");
               chForm.mail.focus();
	           return false;
                }

                if(chForm.mail.value != ""){
		  if (!emailCheck(chForm.mail.value)) {
          alert("Tu cuenta de mail  no es válida.");
          chForm.mail.focus();
		  return false;
    	  }
	}
	

	if(chForm.clave_o.value == "" || chForm.clave_o.value.length < 4){
		alert("Tu Contraseña no ha sido proporcionada, o es menor a 4 digitos");
		chForm.clave_o.focus();
		return false;
	}


	if(chForm.clave_v.value == ""){
		alert("La confirmacion de tu Contraseña no ha sido proporcionada");
		chForm.clave_v.focus();
		return false;
	}

	if(chForm.clave_o.value != chForm.clave_v.value)
	{
		alert("Tu Contraseña y la confirmacion de tu Contraseña no son iguales.");
		chForm.clave_v.focus();
		return false;
	}
	
		if  (chForm.nombre.value == ""){
		alert("Tu nombre no ha sido proporcionado");
		chForm.nombre.focus();
		return false;
	}

	if  (chForm.apaterno.value == ""){
		alert("Tu Apellido Paterno no ha sido proporcionado");
		chForm.apaterno.focus();
		return false;
	}

	if  (chForm.amaterno.value == ""){
		alert("Tu Apellido Materno no ha sido proporcionado");
		chForm.amaterno.focus();
		return false;
	}

                

	if (chForm.dia.options[chForm.dia.selectedIndex].value == "0") {
		alert("El día de tu nacimiento no ha sido proporcionado");
		chForm.dia.focus();
		return false;
	}

	if (chForm.mes.options[chForm.mes.selectedIndex].value == "0") {
		alert("El mes de tu nacimiento no ha sido proporcionado");
		chForm.mes.focus();
		return false;
	}

	if(chForm.year.value == ""){
		alert("El año de tu nacimiento no ha sido proporcionado");
		chForm.year.focus();
		return false;
	}



	if(chForm.sexo.selectedIndex ==0){
		alert("Tu sexo no ha sido proporcionado");
		chForm.sexo.focus();
		return false;
	}
	
	                if(chForm.calle.value == ""){
		alert("Tu Calle y tu número no ha sido proporcionada");
		chForm.calle.focus();
		return false;
	}
	
		if(chForm.colonia.value == ""){
		alert("Tu colonia no ha sido proporcionada");
		chForm.colonia.focus();
		return false;
	}

	if(chForm.entrecalles.value == ""){
		alert("No ha sido proporcionada la información de Entre las calles");
		chForm.entrecalles.focus();
		return false;
	}

	if(chForm.cp.value == ""){
		alert("Tu Codigo postal no ha sido proporcionado.");
		chForm.cp.focus();
		return false;
	}

	if(!isCPINT())
	{
	 alert("Es necesario que escribas tu Código Postal de manera correcta, unicamente números (ej. 64000)!");
	chForm.cp.focus();
		return false;
	}
	
		if(chForm.cp.value.length < 5){
		alert("Es necesario que escribas tu Código Postal de manera correcta (ej. 64000)!");
		chForm.cp.focus();
		return false;
	}

	
	

		if(chForm.municipio.value == ""){
		alert("Tu Del/Municipio no ha sido proporcionada");
		chForm.municipio.focus();
		return false;
	}

                if(chForm.estado.value == ""){
		alert("Tu Estado no ha sido proporcionado.");
		chForm.estado.focus();
		return false;
	}


	if(chForm.pais.selectedIndex == 0){
		alert("Tu País no ha sido proporcionado");
		chForm.pais.focus();
		return false;
	}


if(chForm.telefono.value == ""){
		alert("Tu Teléfono no ha sido proporcionado");
		chForm.telefono.focus();
		return false;
	}


	chDay=chForm.dia.selectedIndex;
	chYear=parseInt(chForm.year.value);
	if(isNaN(chYear)){
		alert("El año está mal escrito");
		return false;
	}

	if((chYear<1900)||(chYear>dato)){
		alert("El año está mal escrito");
		return false;
	}

	if(chForm.mes.selectedIndex&1) // impar
		if(chForm.mes.selectedIndex<8){
			if(chDay>31){
				alert("El mes seleccionado no tiene esa cantidad de días");
				return false;
			}
		}else{
			if(chDay>30){
				alert("El mes seleccionado no tiene esa cantidad de días");
				return false;
			}
		}
	else
		if(chForm.mes.selectedIndex!=2){
			if(chForm.mes.selectedIndex<8){
				if(chDay>30){
					alert("El mes seleccionado no tiene esa cantidad de días");
					return false;
				}
			}else{
				if(chDay>31){
					alert("El mes seleccionado no tiene esa cantidad de días");
					return false;
				}
			}
		}else{
			if( ( ((chYear%4)==0) && ((chYear%100)!=0)) ||
					((chYear%400)==0) ){ //Es bisiesto
				if(chDay>29){
					alert("El mes seleccionado no tiene esa cantidad de días");
					return false;
				}
			}
			else{ // No es bisiesto
				if(chDay>28){
					alert("El mes seleccionado no tiene esa cantidad de días");
					return false;
				}
			}
		}



	return true;
}


   function ChecarDatosFactura(){
   
   var chForm3=document.registrar_factura;


                if(chForm3.razonsocial.value == ""){
		alert("Tu Razón Social / Nombre no ha sido proporcionado.");
		chForm3.razonsocial.focus();
		return false;
	}
   
                if(chForm3.calleynumerofactura.value == ""){
		alert("Tu Calle y número no ha sido proporcionado.");
		chForm3.calleynumerofactura.focus();
		return false;
	}
	
			if(chForm3.coloniafactura.value == ""){
		alert("Tu colonia no ha sido proporcionada");
		chForm3.coloniafactura.focus();
		return false;
	}


                if(chForm3.entrecallesfactura.value == ""){
		alert("Entre las calle de la dirección no han sido proporcionadas.");
		chForm3.entrecallesfactura.focus();
		return false;
	}

                if(chForm3.cpfactura.value == ""){
		alert("Tu Codigo postal no ha sido proporcionado.");
		chForm3.cpfactura.focus();
		return false;
	}

                if(!isCPINT3())
	{
	 alert("Es necesario que escribas tu Código Postal de manera correcta, unicamente números (ej. 64000)!");
	chForm3.cpfactura.focus()
		return false;
	}

		if(chForm3.cpfactura.value.length < 5){
		alert("Es necesario que escribas tu Código Postal de manera correcta (ej. 64000)!");
		chForm3.cp.focus();
		return false;
	}



                if(chForm3.ciudad.value == ""){
		alert("Tu ciudad no han sido proporcionada.");
		chForm3.ciudad.focus();
		return false;
	}

	if(chForm3.estadofactura.value == ""){
		alert("Tu Estado no han sido proporcionada.");
		chForm3.estadofactura.focus();
		return false;
	}
	
	if(chForm3.pais.selectedIndex == 0){
		alert("Tu País no ha sido proporcionado");
		chForm3.pais.focus();
		return false;
	}
              

                if(chForm3.telefonofactura.value == ""){
		alert("Tu Telefono no ha sido proporcionado.");
		chForm3.telefonofactura.focus();
		return false;
	}

                if(chForm3.rfc.value == ""){

                   chForm3.rfc.value = "PUBLICO EN GENERAL";

                        doVa();
	}



   }/*fin de function ChecarDatos3()*/


   function ChecarDatosEnvio(){
   
   var chForm3=document.registrar_datos_envio;


                if(chForm3.nombreenvio.value == ""){
		alert("El nombre no ha sido proporcianado.");
		chForm3.nombreenvio.focus();
		return false;
	}
	
	                if(chForm3.apaternoenvio.value == ""){
		alert("El apellido paterno no ha sido proporcianado.");
		chForm3.apaternoenvio.focus();
		return false;
	}

	                if(chForm3.amaternoenvio.value == ""){
		alert("El apellido materno no ha sido proporcianado.");
		chForm3.amaternoenvio.focus();
		return false;
	}

   
                if(chForm3.calleynumeroenvio.value == ""){
		alert("Tu Calle y número no ha sido proporcionado.");
		chForm3.calleynumeroenvio.focus();
		return false;
	}
	
			if(chForm3.coloniaenvio.value == ""){
		alert("Tu colonia no ha sido proporcionada");
		chForm3.coloniaenvio.focus();
		return false;
	}


                if(chForm3.entrecallesenvio.value == ""){
		alert("Entre las calle de la dirección no han sido proporcionadas.");
		chForm3.entrecallesenvio.focus();
		return false;
	}

                if(chForm3.cpenvio.value == ""){
		alert("Tu Codigo postal no ha sido proporcionado.");
		chForm3.cpenvio.focus();
		return false;
	}

                if(!isCPINT4())
	{
	 alert("Es necesario que escribas tu Código Postal de manera correcta, unicamente números (ej. 64000)!");
	chForm3.cpenvio.focus()
		return false;
	}

		if(chForm3.cpenvio.value.length < 5){
		alert("Es necesario que escribas tu Código Postal de manera correcta (ej. 64000)!");
		chForm3.cpenvio.focus();
		return false;
	}



                if(chForm3.ciudadenvio.value == ""){
		alert("Tu ciudad no han sido proporcionada.");
		chForm3.ciudadenvio.focus();
		return false;
	}

	if(chForm3.municipioenvio.value == ""){
		alert("Tu Municipio no han sido proporcionada.");
		chForm3.municipioenvio.focus();
		return false;
	}


	if(chForm3.estadoenvio.value == ""){
		alert("Tu Estado no han sido proporcionada.");
		chForm3.estadoenvio.focus();
		return false;
	}
	
	if(chForm3.paisenvio.selectedIndex == 0){
		alert("Tu País no ha sido proporcionado");
		chForm3.paisenvio.focus();
		return false;
	}
              

                if(chForm3.telefonoenvio.value == ""){
		alert("Tu Telefono no ha sido proporcionado.");
		chForm3.telefonoenvio.focus();
		return false;
	}

return true;


   }/*fin de function ChecarDatosEnvio()*/


function Inhabilita_cliente(id_cliente,inhabilita,condicion){

	if(inhabilita == 1){
		texto = "¿Esta seguro que desea Inhabilitar al cliente?";
	}else{
		texto = "¿Esta seguro que desea Habilitar al cliente?";
	}

		var conf = confirm(texto);
		if(conf)
		location.href = "?id_cliente="+id_cliente+"&inhabilita="+inhabilita+condicion;

}
