/*
	This is the JavaScript file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial

	You may use this code in your own projects as long as this 
	copyright is left in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.WebCheatSheet.com
	
	Copyright 2006 WebCheatSheet.com	

*/
//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePage; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }   
}

//Called every time our XmlHttpRequest objects state changes
function updatePage() {
 //Check if our response is ready
 if (receiveReq.readyState == 4) {
   //Set the content of the DIV element with the response text
 
if(receiveReq.responseText=='go')
{
	
	document.frmQuote.submit();
}
else
{
	
  
if(frmQuote.strFirstName.value=="")
{
	alert("You cannot leave FirstName empty!");
	frmQuote.strFirstName.focus();
	return false;
}
else if(frmQuote.strLastName.value=="")
{
	alert("You cannot leave LastName empty!");
	frmQuote.strLastName.focus();
	return false;
}

else if(frmQuote.strEmail.value=="")
{
	alert("You cannot leave Email empty!");
	frmQuote.strEmail.focus();
	return false;
}

else if(frmQuote.strPhone.value=="")
{
	alert("You cannot leave Phone no. empty!");
	frmQuote.strPhone.focus();
	return false;
}

else if(frmQuote.strFax.value=="")
{
	alert("You cannot leave Fax empty!");
	frmQuote.strFax.focus();
	return false;
}

else if(frmQuote.strAddress.value=="")
{
	alert("You cannot leave Address empty!");
	frmQuote.strAddress.focus();
	return false;
}

else if(frmQuote.strCity.value=="")
{
	alert("You cannot leave City empty!");
	frmQuote.strCity.focus();
	return false;
}

else if(frmQuote.strState.value=="")
{
	alert("please select a state!");
	frmQuote.strState.focus();
	return false;
}
else if(frmQuote.strContactZip.value=="")
{
	alert("You cannot leave Zip empty!");
	frmQuote.strContactZip.focus();
	return false;
}

else if(frmQuote.strContactMethod.value=="")
{
	alert("please select an option!");
	frmQuote.strContactMethod.focus();
	return false;
}
else if(frmQuote.strContactTime.value=="")
{
	alert("You cannot leave Best time to call empty!");
	frmQuote.strContactTime.focus();
	return false;
}


else if(frmQuote.strInsuredName.value=="")
{
	alert("You cannot leave Insured Name empty!");
	frmQuote.strInsuredName.focus();
	return false;
}

else if(frmQuote.strInsuredAddress.value=="")
{
	alert("You cannot leave Insured Address empty!");
	frmQuote.strInsuredAddress.focus();
	return false;
}

else if(frmQuote.strInsuredCity.value=="")
{
	alert("You cannot leave Insured City empty!");
	frmQuote.strInsuredCity.focus();
	return false;
}

else if(frmQuote.strInsuredState.value=="")
{
	alert("You cannot leave Insured State empty!");
	frmQuote.strInsuredState.focus();
	return false;
}

else if(frmQuote.strInsuredZip.value=="")
{
	alert("You cannot leave Insured Zip empty!");
	frmQuote.strInsuredZip.focus();
	return false;
}

else if(frmQuote.strInsuredBuilding.value=="")
{
	alert("You cannot leave Insured Building empty!");
	frmQuote.strInsuredBuilding.focus();
	return false;
}

else if(frmQuote.strInsuredBlock.value=="")
{
	alert("You cannot leave Insured Block empty!");
	frmQuote.strInsuredBlock.focus();
	return false;
}


else if(frmQuote.strInsuredParcel.value=="")
{
	alert("You cannot leave Insured Parcel empty!");
	frmQuote.strInsuredParcel.focus();
	return false;
}

else if(frmQuote.strDateConstruction.value=="")
{
	alert("You cannot leave Construction Date empty!");
	frmQuote.strDateConstruction.focus();
	return false;
}

else if(frmQuote.strStructure.value=="")
{
	alert("You cannot leave Structure empty!");
	frmQuote.strStructure.focus();
	return false;
}

else if(frm.strFloodZone.value=="")
{
	alert("You cannot leave Flood Zone empty!");
	frmQuote.strFloodZone.focus();
	return false;
}

else if(frm.strPropertyType.value=="")
{
	alert("You cannot leave Property Type empty!");
	frmQuote.strPropertyType.focus();
	return false;
}

else if(frm.strNumFloors.value=="")
{
	alert("You cannot leave Num Floors empty!");
	frmQuote.strNumFloors.focus();
	return false;
}

else if(frmQuote.strElevated.value=="")
{
	alert("You cannot leave Elevated empty!");
	frmQuote.strElevated.focus();
	return false;
}

else if(frmQuote.strLowElevation.value=="")
{
	alert("You cannot leave Low Elevation empty!");
	frmQuote.strLowElevation.focus();
	return false;
}

else if(frmQuote.strBaseElevation.value=="")
{
	alert("You cannot leave Base Elevation empty!");
	frmQuote.strBaseElevation.focus();
	return false;
}

else if(frmQuote.strUnitOwner.value=="")
{
	alert("You cannot leave Unit Owner empty!");
	frmQuote.strUnitOwner.focus();
	return false;
}


else if(frmQuote.strHighRise.value=="")
{
	alert("You cannot leave High Rise empty!");
	frmQuote.strHighRise.focus();
	return false;
}
else if(frmQuote.strPurchasePrice.value=="")
{
	alert("You cannot leave Purchase Price empty!");
	frmQuote.strPurchasePrice.focus();
	return false;
}

else{
  document.getElementById('result').innerHTML = "Invalid Verification Code! Please try again.";	
  }

}
   //Get a reference to CAPTCHA image
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = 'create_image.php?' + Math.random();
 }
}

//Called every time when form is perfomed
function getParam(theForm) {
	
 //Set the URL
 var url = 'captcha.php';
 //Set up the parameters of our AJAX call
 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
 //Call the function that initiate the AJAX request
 makeRequest(url, postStr);
}