// JavaScript Document
// JavaScript Document
  	var captchaOK = 2;
   // 2 - not yet checked, 1 - correct, 0 - failed
   function getHTTPObject()
   { 
		try 
	    {
	     	 req = new XMLHttpRequest(); 
	    } 
		catch (err1) 
		{ 
	 		try
	  		{
	  			 req = new ActiveXObject("Msxml12.XMLHTTP");
	    	} 
			catch (err2) 
			{
		 		 try 
		 		 { 
		  			 req = new ActiveXObject("Microsoft.XMLHTTP");
		    	 }
				 catch (err3)
			 	 {
			  		 req = false;
			     } 
			}
		} 
		return req; 
	}
	var http = getHTTPObject();
	 // We create the HTTP Object 
	 function handleHttpResponse()
	 { 
	  	if (http.readyState == 4) 
		{ 
		 	captchaOK = http.responseText; 
			//document.write(captchaOK);
			 if(captchaOK == 1)
			 {
				window.location.href="thanks.php";
			 }
		 }
	  }
	  function insert_info(url) 
	  {
	   	 http.open("GET", url , true);
		 http.onreadystatechange = handleHttpResponse;
		 http.send(null);
	  }
function formVerify()
{
	var url = 'add_quote.php?';
	
	var name=document.form1.name.value;
	//alert(name);
	if(document.form1.name.value=="")
	{
		alert(" Please fill the Name");
		document.form1.name.focus();
		return false;
	}
	
	
	var country=document.form1.country.value;
	/*if(document.form1.street.value=="")
	{
		alert(" Please fill the Street Address");
		document.form1.street.select();
		return false;
	}*/
	
	
	/*var state=document.form1.state.value;
	if(document.form1.state.value=="")
	{
		alert(" Please fill the State Name");
		document.form1.state.select();
		return false;
	}
	*/
	
	var post_code=document.form1.fax.value;
	/*if(document.form1.fax.value=="")
	{
		alert(" Please fill the Fax");
		document.form1.fax.select();
		return false;
	}*/
	
	
	var phone=document.form1.phone.value;
	if(document.form1.phone.value=="")
	{
		alert(" Please fill the Phone Number");
		document.form1.phone.focus();
		return false;
	}
	else if(document.form1.phone.value!="")
	{
		if (checkInternationalPhone(phone)==false)
		{
			alert("Please Enter a Valid Phone Number");
			document.form1.phone.value="";
			document.form1.phone.focus();
			return false;
		}
	}
	
	var email=document.form1.email.value;
	if(document.form1.email.value=="")
	{
		alert(" Please fill the E-Mail Address");
		document.form1.email.focus();
		return false;
	}
	
	if(document.form1.email.value!="")
	{
		re = new RegExp("([A-Za-z0-9_.-]){2,}@([A-Za-z0-9_.-]){2,}\.([A-Za-z0-9_.-]){2,}")
		if (document.form1.email.value.match(re) == null) 
		{
			alert(" Please enter valid E-Mail Address");
			document.form1.email.value="";
			document.form1.email.focus();
			return false;
		}
	}
	
	/*var quantity=document.form1.quantity.value;
	if(document.form1.quantity.value=="")
	{
		alert(" Please fill the Quantity");
		document.form1.quantity.focus();
		return false;
	}
	else if(document.form1.quantity.value!="")
	{
			if(isInteger(quantity)==false)
			{
				alert(" Please fill the valid Quantity");
				document.form1.quantity.value="";
				document.form1.quantity.focus();
				return false;
			}
	}*/
	
	var desc=document.form1.desc.value;
	/*if(desc == "")
	{
		alert(" Please fill the Description");
		document.form1.desc.focus();
		return false;
	}*/
	var captcha=document.form1.captcha.value;
	if(document.form1.captcha.value=="")
	{
		alert(" Please enter the Code Shown.");
		document.form1.captcha.focus();
		return false;
	}
	
	var total="";
	var i;
	var c = document.getElementsByName('interest[]');
  	c = c.length ? c : [c];
	for(i=0;i<c.length;i++)
	{
		if(c[i].checked==true)
		{
			total +=c[i].value + ",";
		}
	} 
	
	
	   
	//url=url +"name="+ name + "&country="+ country + "&fax="+ fax +"&phone="+ phone + "&email="+ email + "&desc="+ desc + "&captcha="+ captcha + "&interest="+ total;
	//insert_info(url); 
	return false;
}

		var digits = "0123456789";
		// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()-";
		// characters which are allowed in international phone numbers
		// (a leading + is OK)
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 10;
		
		var maxDigitsInIPhoneNumber = 20;
		
		function isInteger(s)
		{   var i;
			for (i = 0; i < s.length; i++)
			{   
				// Check that current character is number.
				var c = s.charAt(i);
				if (((c < "0") || (c > "9"))) return false;
			}
			// All characters are numbers.
			return true;
		}


		function stripCharsInBag(s, bag)
		{   var i;
			var returnString = "";
			// Search through string's characters one by one.
			// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++)
			{   
				// Check that current character isn't whitespace.
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
		}
		
		function checkInternationalPhone(strPhone){
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= maxDigitsInIPhoneNumber);
		}

function formVerify2()
{
	//var url = 'add_quote.php?';
	
	//var name=document.form1.name.value;
	//alert(name);
	if(document.form1.name.value=="")
	{
		alert(" Please fill the Name");
		document.form1.name.focus();
		return false;
	}
	
	
	//var street=document.form1.street.value;
	if(document.form1.address.value=="")
	{
		alert(" Please fill the  Address");
		document.form1.address.select();
		return false;
	}
	
	
	//var state=document.form1.state.value;
	
	
	//var post_code=document.form1.post_code.value;
	if(document.form1.postal.value=="")
	{
		alert(" Please fill the Postal Code");
		document.form1.postal.select();
		return false;
	}
	
	
	//var phone=document.form1.phone.value;
	if(document.form1.phone.value=="")
	{
		alert(" Please fill the Phone Number");
		document.form1.phone.focus();
		return false;
	}
	else if(document.form1.phone.value!="")
	{
		if (checkInternationalPhone(phone)==false)
		{
			alert("Please Enter a Valid Phone Number");
			document.form1.phone.value="";
			document.form1.phone.focus();
			return false;
		}
	}
	
	if(document.form1.fax.value=="")
	{
		alert(" Please fill the FAX Number.");
		document.form1.fax.select();
		return false;
	}
	
	//var email=document.form1.email.value;
	if(document.form1.email.value=="")
	{
		alert(" Please fill the E-Mail Address");
		document.form1.email.focus();
		return false;
	}
	
	if(document.form1.email.value!="")
	{
		re = new RegExp("([A-Za-z0-9_.-]){2,}@([A-Za-z0-9_.-]){2,}\.([A-Za-z0-9_.-]){2,}")
		if (document.form1.email.value.match(re) == null) 
		{
			alert(" Please enter valid E-Mail Address");
			document.form1.email.value="";
			document.form1.email.focus();
			return false;
		}
	}
	
	if(document.form1.username.value=="")
	{
		alert(" Please fill the UserName");
		document.form1.username.select();
		return false;
	}
	
	if(document.form1.password.value=="")
	{
		alert(" Please fill the Password");
		document.form1.password.select();
		return false;
	}
	
	if(document.form1.password2.value=="")
	{
		alert(" Please confirm the Password");
		document.form1.password2.select();
		return false;
	}
	
	 if(document.form1.password.value != document.form1.password2.value)
 {
  alert ("Password Confirmation Mismatch!!!");
  document.form1.password2.focus();
  return false;
 } 
	/*var quantity=document.form1.quantity.value;
	if(document.form1.quantity.value=="")
	{
		alert(" Please fill the Quantity");
		document.form1.quantity.focus();
		return false;
	}
	else if(document.form1.quantity.value!="")
	{
			if(isInteger(quantity)==false)
			{
				alert(" Please fill the valid Quantity");
				document.form1.quantity.value="";
				document.form1.quantity.focus();
				return false;
			}
	}
	
	var desc=document.form1.desc.value;
	if(desc == "")
	{
		alert(" Please fill the Description");
		document.form1.desc.focus();
		return false;
	}*/
	var captcha=document.form1.captcha.value;
	if(document.form1.captcha.value=="")
	{
		alert(" Please enter the Code Shown.");
		document.form1.captcha.focus();
		return false;
	}
	
}