function validate_email(field,alerttxt)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
		{
			alert(alerttxt);
			return false;
		}
		else {return true;}
	}
}
function validate_zipcode(field,alerttxt) 
{
     /* Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
	with(field)
	{
		 if (!reZip.test(value)) {
			  alert(alerttxt);
			  return false;
		 }
		 else{return true;}
	 }*/
	 
	 with(field)  
      {  
           var zip = value;  
           if(zip.length < 5)  
           {    
                alert(alerttxt);  
                return false;  
           }  
           if(zip.length >7)  
           {    
                alert(alerttxt);  
                return false;  
           }  
      }  
      return true;
}
function trim(str) {
	str = str.match(/\S+(?:\s+\S+)*/);
	return str ? str[0] : '';
}

function validate_blank(field,alerttxt)
{
	with (field)
	{
		str = trim(value);
		if (str == '')
		{
			  alert(alerttxt);
			  return false;
		}
		else
		{
			return true;
		}
	}
}
function validate_phone(phonenumber,phonenumber2,alerttxt)
{
	var e = phonenumber.length;
	var e2 = phonenumber2.length;
	if(e == 10 )
	{			  
		return true;
	}
	else
	{
		alert(alerttxt);
		return false;
	}
}

function validate_desiredusers(desiredusers,alerttxt)
{
	rValidate = true;
	var e;
	desiredusers = trim(desiredusers.value);
	
	if(isNaN(desiredusers) == true)
	{
		alert(alerttxt);
		rValidate = false;
	}
	if(desiredusers.length > 3)
	{
		alert(alerttxt);
		rValidate = false;
	}
	if(desiredusers.length < 1)
	{
		alert(alerttxt);
		rValidate = false;
	}
	return rValidate;	
}



function validate_form(thisform)
{
	validate = true;
	with (thisform)
	{
		if (validate_blank(NPA,"Required Area Code")==false)
			{
				validate=false;
			}
		if (validate_blank(First_Name,"Required First Name")==false)
			{
				validate=false;
			}
		if (validate_blank(Last_Name,"Required Last Name")==false)
			{
				validate=false;
			}
		if(validate_blank(Company_Name,"Required Company Name") == false)
		{
			validate=false;
		}
		if(validate_phone(Phone_AreaCode.value + Phone_1.value + Phone_2.value,'','Required contact phone number')==false)
		{
			validate=false;
		}
		
		if (validate_email(Email,"Not a valid e-mail address!")==false)
		  {
		  	validate=false;
		  	Email.focus();
		}
		if (validate_zipcode(Zip,"Not a valid Zip Code")==false)
			{
				validate=false;
			}/**/
		if (validate_desiredusers(Desired_Users,"Please enter numeric value between 1 to 999")==false)
			{
				validate=false;
			}
	}
		
	return validate;
}

/* Spanish validation form
 ******************************************************/
function validate_spanish_form(thisform)
{
	validate = true;
	with (thisform)
	{
		
		// Please fill in area code
		if (validate_blank(NPA,"Favor de Llenar")==false)
			{
				validate=false;
			}
		// First name reguired
		if (validate_blank(First_Name,"Llenar Primer Nombre")==false)
			{
				validate=false;
			}
			
		// Required Last Name
		if (validate_blank(Last_Name,"Llenar Apellido")==false)
			{
				validate=false;
			}
		//Required Company Name
		if(validate_blank(Company_Name,"Llenar Nombre Empresa") == false)
		{
			validate=false;
		}
		
		//Required contact phone number
		if(validate_phone(Phone_AreaCode.value + Phone_1.value + Phone_2.value,'','Llenar Contacto')==false)
		{
			validate=false;
		}
		
		// Not a valid e-mail address!
		if (validate_email(Email,"Llenar Correo Electronico")==false)
		  {
		  	validate=false;
		  	Email.focus();
		}
		
		//Not a valid Zip Code
		if (validate_zipcode(Zip,"Llenar Codigo Postal")==false)
			{
				validate=false;
			}/**/
		
		// Please enter numeric value between 1 to 999
		if (validate_desiredusers(Desired_Users,"Ingresar Numero de 0-999")==false)
			{
				validate=false;
			}
	}
		
	return validate;
}






function ShowQuotesInfoBlock(flag) 
{
	if (navigator.appName == "Opera" || navigator.appName == "Netscape"){
		var trBlock = document.getElementById("quotesInfoBlock");
		trBlock.style.display = flag ? "table-row" : "none";
		//
		var trButton = document.getElementById("searchGoButton");
		trButton.style.display = flag ? "none" : "table-row";
	}
	else
	{
		var trBlock = document.getElementById("quotesInfoBlock");
		trBlock.style.display = flag ? "block" : "none";
		//
		var trButton = document.getElementById("searchGoButton");
		trButton.style.display = flag ? "none" : "block";
	}/**/
}
function ShowStep(step)
{
	validate = true;
	var arStep = new Array();
	arStep[0] = "1";
	arStep[1] = "2";
	arStep[2] = "3";
	var dspStep;
	
	//toggle on/off div
	if(step=="2")
	{
		/**/if (validate_blank(document.getElementById("NPA"),"Required Area Code")==false)
			{
				validate=false;
				step="1";
			}
			
		if (validate_desiredusers(document.getElementById("Desired_Users"),"Please enter numeric value between 1 to 999 for number of employees using phone")==false)
			{
				validate=false;				
				step="1";
			}
	}
	for(i=0;i<arStep.length;i++)
	{
		dspStep = "step" + arStep[i];
		//alert (dspStep);
		if(arStep[i] == step)
		{
			document.getElementById(dspStep).style.display = "block";
		}
		else
		{
			document.getElementById(dspStep).style.display = "none";
		}
	}
	
	if(validate)
	{
	}
}

/* Spanish validation
*********************************************/
function ShowStepSpanish(step)
{
	validate = true;
	var arStep = new Array();
	arStep[0] = "1";
	arStep[1] = "2";
	arStep[2] = "3";
	var dspStep;
	
	//toggle on/off div
	if(step=="2")
	{
		/**/if (validate_blank(document.getElementById("NPA"),"Llenar Prefijo Telefonico")==false)
			{
				validate=false;
				step="1";
			}
			
		if (validate_desiredusers(document.getElementById("Desired_Users"),"Favor de ingresar numero de usuarios entre 1-999")==false)
			{
				validate=false;				
				step="1";
			}
	}
	for(i=0;i<arStep.length;i++)
	{
		dspStep = "step" + arStep[i];
		//alert (dspStep);
		if(arStep[i] == step)
		{
			document.getElementById(dspStep).style.display = "block";
		}
		else
		{
			document.getElementById(dspStep).style.display = "none";
		}
	}
	
	if(validate)
	{
	}
}



function SetDefaultParams()
{
	ShowStep('1');	
}

function goSearch(sURL)
{
	document.location= sURL  ;
}

			function showLead(islead)
			{
				var tLead = document.getElementById("golead");
				var tCompare = document.getElementById("gocompare");
				if(islead)
				{
					tLead.style.display = "block";
					tCompare.style.display = "none";
				}
				else
				{
					tLead.style.display = "none";
					tCompare.style.display = "block";
				}				
			}
