// JavaScript Document
/////////////////////////////////////////////////////////////////////////////
function echeck(str) { //valida el email.
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		{return false}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false}

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false}
		
		 if (str.indexOf(" ")!=-1){
		    return false}
 		 return true					
	}

/////////////////////////////////////////////////////////////////////////////
function checkPhone(str) /* Validate a telephone/fax number... */
{
	var num = "0123456789()- +.";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if ( num.indexOf(str.value.charAt(intLoop)) == -1 ) 
			{return false;}
}
/////////////////////////////////////////////////////////////////////////////
function checkNumber(str) /* Validate a NUMBER */
{
	var num = "0123456789";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if (-1 == num.indexOf(str.value.charAt(intLoop)) ) 
			{return false;}
}
///////////////////////////////////
function validateForgotUser()
{
	var cadenaError = "";
	
	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError =  "You must provide your EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}
}

//////////////////////////////////////////
function validateRegister()
{
	var cadenaError = "";
	
	document.form.name.value = trim(document.form.name.value);
		if(document.form.name.value=="")
			{cadenaError = "You must provide your NAME.\n";}
			
	document.form.lastname.value = trim(document.form.lastname.value);
		if(document.form.lastname.value=="")
			{cadenaError += "You must provide your LAST NAME.\n";}

	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide your EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	document.form.agency.value = trim(document.form.agency.value);
		if(document.form.agency.value=="")
			{cadenaError += "You must provide your AGENCY.\n";}

	document.form.clia_arc.value = trim(document.form.clia_arc.value);
	document.form.iata.value = trim(document.form.iata.value);
		if(document.form.clia_arc.value=="" && document.form.iata.value=="")
			{cadenaError += "You must provide your IATA number OR your CLIA/ARC number.\n";}
	
	if(document.form.country.value=="Select")
		{cadenaError += "You must select your COUNTRY.\n";}

	document.form.state.value = trim(document.form.state.value);
		if(document.form.state.value=="")
			{cadenaError += "You must provide your STATE.\n";}
			
	document.form.city.value = trim(document.form.city.value);
		if(document.form.city.value=="")
			{cadenaError += "You must provide your CITY.\n";}
			
	document.form.address.value = trim(document.form.address.value);
		if(document.form.address.value=="")
			{cadenaError += "You must provide your ADDRESS.\n";}

	document.form.zip.value = trim(document.form.zip.value);
		if( (document.form.zip.value == "") || (checkNumber(document.form.zip) == false) )
			{cadenaError += "You must provide your ZIP CODE or WRITE IT CORRECTLY.\n";}

	document.form.phone.value = trim(document.form.phone.value);
		if( (document.form.phone.value == "") || (checkPhone(document.form.phone) == false) )
			{cadenaError += "You must provide your TELEPHONE or WRITE IT CORRECTLY.\n";}

	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
////////////////////////////////////////////////////////////////////////
function validateUserUpdate()
{
	var cadenaError = "";
	
	document.form.login.value = trim(document.form.login.value);
		if(document.form.login.value=="")
			{cadenaError = "You must provide User Login.\n";}

	document.form.password.value = trim(document.form.password.value);
		if(document.form.password.value=="")
			{cadenaError += "You must provide PASSWORD.\n";}
			
	document.form.name.value = trim(document.form.name.value);
		if(document.form.name.value=="")
			{cadenaError += "You must provide NAME.\n";}
			
	document.form.lastname.value = trim(document.form.lastname.value);
		if(document.form.lastname.value=="")
			{cadenaError += "You must provide LAST NAME.\n";}	
	
	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	document.form.agency.value = trim(document.form.agency.value);
		if(document.form.agency.value=="")
			{cadenaError += "You must provide AGENCY.\n";}

	document.form.iata.value = trim(document.form.iata.value);
	document.form.clia_arc.value = trim(document.form.clia_arc.value);
	if( (document.form.iata.value=="") && (document.form.clia_arc.value=="") )
		{cadenaError += "You must provide IATA or CLIA/ARC number.\n";}
		
	if(document.form.country.value=="Select")
		{cadenaError += "You must select COUNTRY.\n";}

	document.form.state.value = trim(document.form.state.value);
		if(document.form.state.value=="")
			{cadenaError += "You must provide STATE.\n";}
			
	document.form.city.value = trim(document.form.city.value);
		if(document.form.city.value=="")
			{cadenaError += "You must provide CITY.\n";}
			
	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
//////////////////////////////////////
function validateAdminUpdate()
{
	var cadenaError = "";
	
	document.form.login.value = trim(document.form.login.value);
		if(document.form.login.value=="")
			{cadenaError = "You must provide User Login.\n";}

	document.form.password.value = trim(document.form.password.value);
		if(document.form.password.value=="")
			{cadenaError += "You must provide PASSWORD.\n";}
			
	document.form.name.value = trim(document.form.name.value);
		if(document.form.name.value=="")
			{cadenaError += "You must provide NAME.\n";}
			
	document.form.lastname.value = trim(document.form.lastname.value);
		if(document.form.lastname.value=="")
			{cadenaError += "You must provide LAST NAME.\n";}	
	
	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
//////////////////////////////////////
function validateNewUser()
{
	var cadenaError = "";
	
	document.form.password.value = trim(document.form.password.value);
		if(document.form.password.value=="")
			{cadenaError = "You must provide your PASSWORD.\n";}
			
	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide your EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	document.form.agency.value = trim(document.form.agency.value);
		if(document.form.agency.value=="")
			{cadenaError += "You must provide your AGENCY.\n";}

	document.form.clia_arc.value = trim(document.form.clia_arc.value);
		if(document.form.clia_arc.value=="")
			{cadenaError += "You must provide your CLIA/ARC number.\n";}
	
	if(document.form.country.value=="Select")
		{cadenaError += "You must select your COUNTRY.\n";}

	document.form.state.value = trim(document.form.state.value);
		if(document.form.state.value=="")
			{cadenaError += "You must provide your STATE.\n";}
			
	document.form.city.value = trim(document.form.city.value);
		if(document.form.city.value=="")
			{cadenaError += "You must provide your CITY.\n";}
			
	document.form.address.value = trim(document.form.address.value);
		if(document.form.address.value=="")
			{cadenaError += "You must provide your ADDRESS.\n";}

	document.form.zip.value = trim(document.form.zip.value);
		if( (document.form.zip.value == "") || (checkNumber(document.form.zip) == false) )
			{cadenaError += "You must provide your ZIP CODE or WRITE IT CORRECTLY.\n";}

	document.form.phone.value = trim(document.form.phone.value);
		if( (document.form.phone.value == "") || (checkPhone(document.form.phone) == false) )
			{cadenaError += "You must provide your TELEPHONE or WRITE IT CORRECTLY.\n";}

	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
//////////////////////////////////
function validateUserUpdate2()
{
	var cadenaError = "";
	
	document.form.password.value = trim(document.form.password.value);
		if(document.form.password.value=="")
			{cadenaError = "You must provide PASSWORD.\n";}
			
	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}

	document.form.agency.value = trim(document.form.agency.value);
		if(document.form.agency.value=="")
			{cadenaError += "You must provide AGENCY.\n";}

	document.form.iata.value = trim(document.form.iata.value);
	document.form.clia_arc.value = trim(document.form.clia_arc.value);
	if( (document.form.iata.value=="") && (document.form.clia_arc.value=="") )
		{cadenaError += "You must provide IATA or CLIA/ARC number.\n";}
			
	
	if(document.form.country.value=="Select")
		{cadenaError += "You must select COUNTRY.\n";}

	document.form.state.value = trim(document.form.state.value);
		if(document.form.state.value=="")
			{cadenaError += "You must provide STATE.\n";}
			
	document.form.city.value = trim(document.form.city.value);
		if(document.form.city.value=="")
			{cadenaError += "You must provide CITY.\n";}
			
	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
function trim(s) { 	
	var temp = ""; 	
	var left; 	
	var right;  	
	
	// trim a la izquierda	 	
	for(left = 0; left < s.length; left++) { 		
		var c = s.charAt(left); 
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	
	
	// trim a la derecha	 	
	for(right = s.length-1; right >= 0; right--) { 		
		var c = s.charAt(right); 		
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	 	
		
	temp = s.slice(left, right+1); 	return temp; 
}
////////////////////////////////////////////////////////////////////////