var xmlHttp
var place



function showHint(str, plc)
{
	place = plc;
    if (str.length==0) 
	{document.getElementById(place).innerHTML="";
     return;}
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
	{alert ("Your browser does not support AJAX!");
	 return;}

    var url="validar_email.php";
    url=url+"?email="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function cleaner(plc)
{
	 place = plc;
	 document.getElementById(place).innerHTML="";
     return;
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
	 {alert ("Your browser does not support AJAX!");
	  return;}
 
}




function showHintC(str, plc,strname)
{
	place = plc;
    if(str.length==0) 
	{document.getElementById(place).innerHTML="";
     return;}
	 //forma.[strname].style.border = "1px solid ";
  	
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
	 {alert ("Your browser does not support AJAX!");
	  return;}
 
 	 
 	 
	 
     var url="validar_campo.php";
     url=url+"?campo="+str;
     url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=stateChanged;
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
}

function showHintV(str, plc)
{
	place = plc;
    if (str.length==0) 
	{document.getElementById(place).innerHTML="";
     return;}
  
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
	 {alert ("Your browser does not support AJAX!");
	  return;}
 
 	document.getElementById(place).innerHTML = "";

     var url="validar_campo.php";
     url=url+"?campo="+str;
     url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=stateChanged;
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
}



function showHintF(str, plc) 
{
	place = plc;
    if (str.length==0)
	{document.getElementById(place).innerHTML="";
     return;}
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
	{alert ("Your browser does not support AJAX!");
	 return;}

    var url="validar_fecha.php";
    url=url+"?campo="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

var letras="abcdefghijklmnñopqrstuvwxyz0123456789_-!#@*() []";

function validoletras(texto){
   if(texto.length>0){
   	texto = texto.toLowerCase();
   	for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 0;
      }
	  else return 1;
   	}
   }
   else return 0;
} 

function isEmailAddress(value)
{
	
var s =value;
var filter=/^[A-Za-z][A-Za-z0-9.-_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length >0 )
	{
		if (filter.test(s)) return 0;
		else {return 1;}
	
	} else return 0;
}

var numeros="0123456789_-";

function validonumero(texto){
   if(texto.length>0){
   	texto = texto.toLowerCase();
   	for(i=0; i<texto.length; i++){
      if (numeros.indexOf(texto.charAt(i),0)!=-1){
         return 0;
      }
	  else return 1;
   	}
   }
   else return 0;
} 



function save(plc)
{	
     place = plc;
     var mess = "";
	 var mess2="Please capture the fields in red";
	
     if (forma.firstname.value.length<1 )
     {
	  mess = "The First Name can't be empty";
	  document.getElementById('firstnameerror').innerHTML = mess;
	  forma.firstname.style.border = "1px solid red";
	  
     } 
 
 
     var indice =forma.dobm.selectedIndex;
	
     if (forma.dobm.options[indice].value.length<1 ||
         forma.dobd.value.length<1 ||
		 forma.doby.value.length<4 ||
	     forma.doby.value.length<1)
	  	{mess = "Bad input in Date of birth, check format (mont/dd/yyyy)";
	    document.getElementById('dobderror').innerHTML = mess;
	    forma.dobm.style.border = "1px solid red";
		forma.dobd.style.border = "1px solid red";
		forma.doby.style.border = "1px solid red";}

		

     if (forma.lastname.value<1)
	    {mess = "The Last Name can't be empty.";
	    document.getElementById('lastnameerror').innerHTML = mess;
	    forma.lastname.style.border = "1px solid red";} 
  
  	  if (forma.address1.value<1)
	   {mess = "The Address can't be empty.";
	   document.getElementById('address1error').innerHTML = mess;
	   forma.address1.style.border = "1px solid red";} 
  
     if (forma.city.value<1)
	  {mess = "The City can't be empty.";
	  document.getElementById('cityerror').innerHTML = mess;
	  forma.city.style.border = "1px solid red";}  

	 if (forma.state.value.length<1)
	  {mess = "The State/Provinc can't be empty.";
	  document.getElementById('stateerror').innerHTML = mess;
	  forma.state.style.border = "1px solid red";}  
	  
	 if (forma.zip.value.length<1)
	  {mess = "The Zip Code can't be empty.";
	  document.getElementById('ziperror').innerHTML = mess;
	  forma.zip.style.border = "1px solid red";}  
	  
	 var indice =forma.country.selectedIndex;
	 if (forma.country.options[indice].value.length<1)
	  {mess = "The Country can't be empty.";
	  document.getElementById('countryerror').innerHTML = mess;
	  }  
	  
	 if (forma.sex3.checked){
		    mess = "The Gender can't be empty.";
	  	    document.getElementById('sexerror').innerHTML = mess;
		  } 
		  
	 if (forma.homephone.value.length<1)
	  {mess = "The Homephone can't be empty.";
	  document.getElementById('homephoneerror').innerHTML = mess;
	  forma.homephone.style.border = "1px solid red";}  
	  
	 if (forma.shirt1.checked){
		    mess = "The Shirt Size can't be empty.";
	  	    document.getElementById('shirterror').innerHTML = mess;
		  } 
		  
	 if (forma.shoe.value.length<1)
	  {mess = "The Shoe Size can't be empty.";
	  document.getElementById('shoeerror').innerHTML = mess;
	  forma.shoe.style.border = "1px solid red";}
	  
	  if (forma.pants1.checked){
		    mess = "The Pants Size can't be empty.";
	  	    document.getElementById('pantserror').innerHTML = mess;
		  } 
		  
	  if (forma.emergency_contact.value.length<1)
	  {mess = "The Emergency contact name can't be empty.";
	  document.getElementById('emergency_contacterror').innerHTML = mess;
	  forma.emergency_contact.style.border = "1px solid red";}
	  
	  if (forma.relationship.value.length<1)
	  {mess = "The Relationship can't be empty.";
	  document.getElementById('relationshiperror').innerHTML = mess;
	  forma.relationship.style.border = "1px solid red";}
	  
	  if (forma.emergency_tel.value.length<1)
	  {mess = "The Telephone Number can't be empty.";
	  document.getElementById('emergency_telerror').innerHTML = mess;
	  forma.emergency_tel.style.border = "1px solid red";}
	  
	   if (forma.ambulatory1.checked){
		    mess = "Your Current Ambulatory Condition can't be empty.";
	  	    document.getElementById('ambulatoryerror').innerHTML = mess;
		  } 

	   if (forma.usana1.checked)
	   {
		   
		  if (forma.id_usana.value.length<1)
	  			{mess = "Provide your USANA ID.";
	  			document.getElementById('id_usanaerror').innerHTML = mess;
	  			forma.id_usana.style.border = "1px solid red";
				}
		}
		
		

//validando caracteres invalidos
		
		if(validonumero(forma.dobd.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('dobderror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.doby.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('dobderror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}	
		if(validonumero(forma.homephone.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('homephoneerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.workphone.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('workphoneerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.cellphone.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('cellphoneerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
				
		if(validonumero(forma.fax.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('faxerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.height1.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('height1error').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.height2.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('height1error').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.weight.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('weighterror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.altura1.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('altura1error').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.peso.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('pesoerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
		if(validonumero(forma.shoe.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('shoeerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}

		if(validonumero(forma.emergency_tel.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('emergency_telerror').innerHTML = mess;
				mess2="Contain invalid caracter(s)";
				}
				

		if(validonumero(forma.doby_comp.value)==1)
			   {mess = "Please enter only numbers";
	  			document.getElementById('dobm_comperror').innerHTML = mess;
				mess2="Please enter only numbers"+" Date Of Birth Companion";
				}
		
		/* if(isEmailAddress(forma.email.value)==1)
				{mess = "Ivalid email address";
	  			 document.getElementById('errore').innerHTML = mess;
				 mess2="Ivalid email address";
				 } */
		
//___________________

		  
		
  		if(mess.length<1) {forma.submit();
							}
		else{ alert(mess2);}
}




function guardar(plc)
{	
     place = plc;
     var mess = "";
	 var mess2="Por favor capture la informacion requerida, que se muestra en color rojo";
	
     if (forma.firstname.value.length<1 )
     {
	  mess = "El Nombre no puede quedar vacio";
	  document.getElementById('firstnameerror').innerHTML = mess;
	  forma.firstname.style.border = "1px solid red";
	  
     } 
 
 
     var indice =forma.dobm.selectedIndex;
	
     if (forma.dobm.options[indice].value.length<1 ||
         forma.dobd.value.length<1 ||
		 forma.doby.value.length<4 ||
	     forma.doby.value.length<1)
	  	{mess = "Capture la fecha de nacimiento en el siguiente formato (mm/dd/yyyy)";
	    document.getElementById('dobderror').innerHTML = mess;
	    forma.dobm.style.border = "1px solid red";
		forma.dobd.style.border = "1px solid red";
		forma.doby.style.border = "1px solid red";}

		

     if (forma.lastname.value<1)
	    {mess = "El Apellido no puede quedar vacio.";
	    document.getElementById('lastnameerror').innerHTML = mess;
	    forma.lastname.style.border = "1px solid red";} 
  
  	  if (forma.address1.value<1)
	   {mess = "La Direccion no puede quedar vacio.";
	   document.getElementById('address1error').innerHTML = mess;
	   forma.address1.style.border = "1px solid red";} 
  
     if (forma.city.value<1)
	  {mess = "La ciudad no puede quedar vacio.";
	  document.getElementById('cityerror').innerHTML = mess;
	  forma.city.style.border = "1px solid red";}  

	 if (forma.state.value.length<1)
	  {mess = "El estado/provincia no puede quedar vacio.";
	  document.getElementById('stateerror').innerHTML = mess;
	  forma.state.style.border = "1px solid red";}  
	  
	 if (forma.zip.value.length<1)
	  {mess = "El codigo postal no puede quedar vacio.";
	  document.getElementById('ziperror').innerHTML = mess;
	  forma.zip.style.border = "1px solid red";}  
	  
	 var indice =forma.country.selectedIndex;
	 if (forma.country.options[indice].value.length<1)
	  {mess = "El pais no puede quedar vacio.";
	  document.getElementById('countryerror').innerHTML = mess;
	  }  
	  
	 if (forma.sex3.checked){
		    mess = "El genero no puede quedar vacio.";
	  	    document.getElementById('sexerror').innerHTML = mess;
		  } 
		  
	 if (forma.homephone.value.length<1)
	  {mess = "El telefono de casa no puede quedar vacio.";
	  document.getElementById('homephoneerror').innerHTML = mess;
	  forma.homephone.style.border = "1px solid red";}  
	  
	 if (forma.shirt1.checked){
		    mess = "La talla de camiseta no puede quedar vacio.";
	  	    document.getElementById('shirterror').innerHTML = mess;
		  } 
		  
	 if (forma.shoe.value.length<1)
	  {mess = "La talla de zapato no puede quedar vacio.";
	  document.getElementById('shoeerror').innerHTML = mess;
	  forma.shoe.style.border = "1px solid red";}
	  
	  if (forma.pants1.checked){
		    mess = "La talla de pantalon no puede quedar vacio.";
	  	    document.getElementById('pantserror').innerHTML = mess;
		  } 
		  
	  if (forma.emergency_contact.value.length<1)
	  {mess = "El nombre del contacto de emergencia no puede quedar vacio.";
	  document.getElementById('emergency_contacterror').innerHTML = mess;
	  forma.emergency_contact.style.border = "1px solid red";}
	  
	  if (forma.relationship.value.length<1)
	  {mess = "La relacion no puede quedar vacio.";
	  document.getElementById('relationshiperror').innerHTML = mess;
	  forma.relationship.style.border = "1px solid red";}
	  
	  if (forma.emergency_tel.value.length<1)
	  {mess = "El numero de telefono no puede quedar vacio.";
	  document.getElementById('emergency_telerror').innerHTML = mess;
	  forma.emergency_tel.style.border = "1px solid red";}
	  
	   if (forma.ambulatory1.checked){
		    mess = "Su condicion actual ambulatoria no puede estar vacio.";
	  	    document.getElementById('ambulatoryerror').innerHTML = mess;
		  } 

	   if (forma.usana1.checked)
	   {
		   
		  if (forma.id_usana.value.length<1)
	  			{mess = "Proporcione a su USANA ID.";
	  			document.getElementById('id_usanaerror').innerHTML = mess;
	  			forma.id_usana.style.border = "1px solid red";
				}
		}
		
		

//validando caracteres invalidos
		

				
		 if(validonumero(forma.dobd.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('dobderror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en fecha de nacimiento";
				}
		 if(validonumero(forma.doby.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('dobderror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en fecha de nacimiento";
				}	
		if(validonumero(forma.homephone.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('homephoneerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en numero de telefono";
				}
		 if(validonumero(forma.workphone.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('workphoneerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en numero de telefono";
				}
		if(validonumero(forma.cellphone.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('cellphoneerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en numero de telefono";
				}
				
		 if(validonumero(forma.fax.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('faxerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en numeor de fax";
				}
		 if(validonumero(forma.height1.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('height1error').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en estatura";
				}
		if(validonumero(forma.height2.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('height1error').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en estatura";
				}
		 if(validonumero(forma.weight.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('weighterror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en donde peso";
				}
		if(validonumero(forma.altura1.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('altura1error').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en donde estatura";
				}
		if(validonumero(forma.peso.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('pesoerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en peso";
				}
		 if(validonumero(forma.shoe.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('shoeerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros en Talla de Zapato";
				}

		if(validonumero(forma.emergency_tel.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('emergency_telerror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros Telefono de emergencia";
				}
				

		if(validonumero(forma.doby_comp.value)==1)
			   {mess = "Por favor, introduzca solo numeros";
	  			document.getElementById('dobm_comperror').innerHTML = mess;
				mess2="Por favor, introduzca solo numeros En fecha de Nacimiento de acomp.";
				}
		
		/*if(isEmailAddress(forma.email.value)==1)
				{mess = "Ivalid email address";
	  			 document.getElementById('errore').innerHTML = mess;
				 mess2="Ivalid email address";
				 }*/
		
//___________________

		  
		
  		if(mess.length<1) {forma.submit();
							}
		else{ alert(mess2);}
}

function stateChanged() { 
  if (xmlHttp.readyState==4) { 
    document.getElementById(place).innerHTML=xmlHttp.responseText;
	
  }
}







function stateChanged() { 
  if (xmlHttp.readyState==4) { 
    document.getElementById(place).innerHTML=xmlHttp.responseText;
	
  }
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		} catch (e) {
		// Internet Explorer
		  try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  } catch (e) {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
	}
	return xmlHttp;
}