
	function searchPro(form){
		var form =document.adlisting;
	    //Ajax search
	   var companyname =form.companyname.value;
	   var state = form.state.value;
	   var zip = form.zip.value;
	   var phone_1 = form.phone_1.value;
	   var phone_2 = form.phone_2.value;
	   var phone_3 = form.phone_3.value;
	   var category = form.category.value;


		var search_string = "companyname=" + companyname + "&state=" + state + "&zip=" + zip + "&phone_1=" + phone_1 + "&phone_2=" + phone_2 + "&phone_3=" + phone_3 + "&searchCategory=" + category + "&RefineSearch=Refine Search&ratingpro=true&Submit=Search and Rate";

		//alert( search_string)
	  	 check_availability( 'searchpro.php',search_string, 'answer');


	}




	function checkForm(form) {
	   form.companyname.required = true;
	   form.companyname.requiredError = 'Company Name is a required field.';
	   form.address.required = true;
	   form.address.requiredError = 'Address is a required field.';
	   form.city.required = true;
	   form.city.requiredError = 'City is a required field.';
//	   form.state.required = true;
//	   form.state.requiredError = 'State is a required field.';
	   form.zip.required = true;
	   form.zip.requiredError = 'ZIP number is a required field.';
	   form.zip.pattern = 'zipcode';
	   form.zip.patternError = 'The ZIP code entered is not valid.';
//	   form.email.required = true;
//	   form.email.requiredError = 'Email is required.';
//	   form.email.pattern = 'email';
//	   form.email.patternError = 'The email address entered is not valid.';
	   form.phone_1.required = true;
	   form.phone_1.requiredError = 'Your Phone Area Code is required.';
	   form.phone_2.required = true;
	   form.phone_2.requiredError = 'Your Phone Number prefix is required.';
	   form.phone_3.required = true;
	   form.phone_3.requiredError = 'Your Phone Number sufix is required.';
	   form.phone_1.pattern = 'numeric';
	   form.phone_1.patternError = 'Your Phone Area Code contains invalid digits.';
	   form.phone_2.pattern = 'numeric';
	   form.phone_2.patternError = 'Your Phone Number prefix contains invalid digits.';
	   form.phone_3.pattern = 'numeric';
	   form.phone_3.patternError = 'Your Phone Number sufix contains invalid digits.';
	   form.state.disallowEmptyValue = true;
	   form.state.disallowEmptyValueError = 'You have to select a state.';
	   form.category.disallowEmptyValue = true;
	   form.category.disallowEmptyValueError = 'You have to select a Service Needed.';

	 if(form.businessid.value==1){alert(' Please chosse a home pro from pro listing\n'); return false;}
	   var errors = getFormErrors(form);
	   if (errors.length > 0 && (form.businessid.value==0)	) {
		  var errorMessage = 'The form was not submitted due to the following problem' + ((errors.length > 1) ? 's' : '') + ':\n\n';
		  for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) {
			 errorMessage += '* ' + errors[errorIndex] + '\n';
		  }
		  errorMessage += '\nPlease fix ' + ((errors.length > 1) ? 'these' : 'this') + ' problem' + ((errors.length > 1) ? 's' : '') + ' and resubmit the form.';
		  alert(errorMessage);
		  return false;
	   }


	   // no errors: return true
	   return true;
	}


function autoTabRate(id){
	var frm;
	frm=document.adlisting;

	if(id==1 && frm.phone_1.value.length==3){
		frm.phone_2.focus();
		return true;
	}else if(id==2 && frm.phone_2.value.length==3){
		frm.phone_3.focus();
		return true;
	}else if(id==3 && frm.phone_3.value.length==4){
		frm.cellphone_1.focus();
	}
}

function autoTabRateEven(id){
	var frm;
	frm=document.adlisting;

	if(id==1 && frm.cellphone_1.value.length==3){
		frm.cellphone2.focus();
		return true;
	}else if(id==2 && frm.cellphone2.value.length==3){
		frm.cellphone3.focus();
		return true;
	}else if(id==3 && frm.cellphone3.value.length==4){
		frm.category.focus();
	}
}


var count;
count=0;
var intRef;
function dynamicText(){
	if(count==0){
		intRef=setInterval("dynamicText()",400);
		document.getElementById('searchResult').innerHTML="searching";
	}
	if(count==10){
		document.getElementById('searchResult').innerHTML="searching";
		count =1;
	}else{
		document.getElementById('searchResult').style.display="block";
		document.getElementById('searchResult').innerHTML = document.getElementById('searchResult').innerHTML + ".";
	}
	count=count +1;
}

//prepare for ajax call
function createAjaxCall(advSearch,query){


	var xmlHttp;
	try{
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		//for internet explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			     //ajax object could not be created
				 return false;
			}
		}
	}

    xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
			clearInterval(intRef);
	  		if(xmlHttp.responseText!=""){
        		document.getElementById('searchResult').innerHTML=xmlHttp.responseText;
				document.getElementById('SearchResultHead').style.display="block";
				document.getElementById('searchResultNone').style.display="block";
				document.getElementById('businessid').value=1;
				document.getElementById('proIsListed').style.display="block";
				document.getElementById('continueToRate').style.display="block";
				document.getElementById('continueToAdd').style.display="none";
				document.getElementById('ShowResultBlock').style.display="block";


      		}else{
				document.getElementById('searchResult').innerHTML="";
				document.getElementById('SearchResultHead').style.display="none";
				document.getElementById('searchResultNone').style.display="none";
				document.getElementById('businessid').value= 0;
				document.getElementById('continueToRate').style.display="none";
				document.getElementById('continueToAdd').style.display="block";
				document.getElementById('proIsListed').style.display="none";
				document.getElementById('ShowResultBlock').style.display="none";
			}
			//reintialize dynmic display of searching
			count=0;
	  }
   }


	if(advSearch==2){
		xmlHttp.open("GET",query,true);
	}else if(advSearch==0){

     		xmlHttp.open("GET","searchpro.php?state=" + document.adlisting.state.value + "&companyname=" + document.adlisting.companyname.value + "&phone_1=" + document.adlisting.phone_1.value + "&phone_2=" + document.adlisting.phone_2.value +  "&phone_3=" + document.adlisting.phone_3.value ,true);
   }else{

	   	xmlHttp.open("GET","searchpro.php?state=" + document.adlisting.state.value + "&companyname=" + document.adlisting.companyname.value +"&catid=" + document.adlisting.catid.value + "&city=" + document.adlisting.city.value + "&zip=" + document.adlisting.zip.value +  "&phone_1=" + document.adlisting.phone_1.value + "&phone_2=" + document.adlisting.phone_2.value +  "&phone_3=" + document.adlisting.phone_3.value,true);

   }
   xmlHttp.send(null);
   dynamicText();
}
//0 The request is not initialized
//1 The request has been set up
//2 The request has been sent
//3 The request is in process
//4 The request is complete



//getting business id from the results
function getBusiness(obj){

document.getElementById('businessid').value=obj.value;
document.getElementById('continueToAdd').style.display="none";
document.getElementById('continueToRate').style.display="block";

}

function showAddProDiv(obj){
	document.getElementById('continueToAdd').style.display="block";
	document.getElementById('continueToRate').style.display="none";

}


//prepare for ajax call
function getSubcatagory(obj){


	var xmlHttp;
	try{
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		//for internet explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			     //ajax object could not be created
				 return false;
			}
		}
	}

    xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
			clearInterval(intRef);
	  		if(xmlHttp.responseText!=""){
        		document.getElementById('subcatagoryResult').innerHTML=xmlHttp.responseText;


      		}else{
				document.getElementById('subcatagoryResult').innerHTML="none";

			}
			//reintialize dynmic display of searching
			count=0;
	  }
   }




	   	xmlHttp.open("GET","AjaxSearch.php?Catid=" + obj.value ,true);


   xmlHttp.send(null);

}