function searchdata()
{
	document.getElementById('result').style.display = 'block';  
}



var tname ='';
	var tphone = '';
	var tmobile ='';
	var temail = '';

function fetchcontact()
{
	 tname = document.getElementById('cname').value;
	 tphone = document.getElementById('cphone').value;
	 tmobile =document.getElementById('cmobile').value;
	 temail = document.getElementById('cemail').value;
}


function changecontact()
{
	for (var i=0; i < document.form1.contactfor.length; i++)
   {
	   if (document.form1.contactfor[i].checked)
    	  { var rad_val = document.form1.contactfor[i].value;    }
   }
	if(rad_val==1) // IF SELF
	{
		document.getElementById('cname').value=document.getElementById('hcname').value;
		document.getElementById('cphone').value=document.getElementById('hcontact').value;
		document.getElementById('cmobile').value=document.getElementById('hmobile').value;
		document.getElementById('cemail').value=document.getElementById('hemail').value;
	}
	else
	{
		document.getElementById('cname').value=tname;
		document.getElementById('cphone').value=tphone;
		document.getElementById('cmobile').value=tmobile;
		document.getElementById('cemail').value=temail;
	}

}



///////// FUNCTION FIRES ON CLICK OF SUBMIT BUTTON

function checkWholeForm(theForm) {
	
    var why = "";
	
   
   

	  why += checkDropdown(theForm.country.value, 'country');
	why += checkDropdown(theForm.States.value, 'States');
	why += checkDropdown(theForm.Cities.value, 'Cities');
	 why += checkDropdown(theForm.category.value, 'category');
	 why += checkDropdown(theForm.Types.value, 'Types');
	//why += checkDropdown(theForm.Cities.value, 'Cities');
	
     
//    why += isDifferent(theForm.different.value);
    /////// IF OTHER INFORMATION IS DISPLAY THEN DO CHECK OTHER VALIDATIONS
		
	
	
	/////////// OTHE INFORMATION VALIDATION ENDS HERE
   
    if (why != "") {
       alert(why);
       return false;
    }
	else
	{
	searchdata();	//alert("Well done! Data is Valid");
	searchdetail();
	}
return true;
}





/**********************  VALIDATION FUNCTIONS BELOW ********************
/**********************                              *******************/


// email

function checkEmail (strng, nm) {
	document.getElementById(nm).style.background="#ffffff";
var error="";
if (strng == "") {
  // error = "You didn't enter an email address.\n";
    document.getElementById(nm).style.background="#ffbeaa";
}
else
{

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
}
return error;    
}





// non-empty textbox

function isEmpty(strng, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
  if (strng.length == 0) {
     error = " ";

	 if(nm=='minarea')
	 { error += 'Minimum Area';	 }
	 else if(nm=='maxarea')
	 { error += 'Maximum Area';	 }
	  else if(nm=='cname')
	 { error += 'Contact Person Name';	 }
	 else if(nm=='cphone')
	 { error += 'Contact Phone';	 }
	 else if(nm=='cmobile')
	 { error += 'Contact Mobile';	 }
	 else if(nm=='cemail')
	 { error += 'Contact Email';	 }
 	 else if(nm=='maxprice')
	 { error += 'Maximum Price';	 }
 	 else if(nm=='minprice')
	 { error += 'Minimum Price';	 }


	 else
	 {
	 error += nm;
	 }
	 error += "  has not been filled in.\n";
	  document.getElementById(nm).style.background="#ffbeaa";
  }
return error;	  
}


// exactly one radio button is chosen

function checkRadio(checkvalue, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
   if (!(checkvalue)) {
       error = "Please choose category.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
    if (choice == '')
	{
    error = "You didn't choose an option from the drop-down ";
	error += nm;
	error += "\n";
	 document.getElementById(nm).style.background="#ffbeaa";
    } 
	else if(choice == 0)
	{	//alert("Hi I am 0");
		if(nm=='Country')
		{			}
		if(nm=='States')
		{	if(document.getElementById('otherstate').value=='')
			{document.getElementById('otherstate').style.background="#ffbeaa";
			error = "You didn't fill in 'Other State' \n ";
			}
		}
		if(nm=='Cities')
		{
			if(document.getElementById('othercity').value=='')
			{error = "You didn't fill in 'other City' \n ";
			document.getElementById('othercity').style.background="#ffbeaa";
			}
		}
		if(nm=='Localities')
		{
			if(document.getElementById('otherlocality').value=='')
			{error = "You didn't fill in 'other City' \n ";
			document.getElementById('otherlocality').style.background="#ffbeaa";
			}
		}
	}
		
		
	
return error;
}    




////////////////////////////////////////
/////////////////////////////////////

// Text Field Validation Functions



var numb = '0123456789 ';
var lwr = 'abcdefghijklmnopqrstuvwxyz ';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';

function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}
function isDecimal(parm) {return isValid(parm,numb+'.');}


////////////////////////////sending property deatail to php///////////////////

var xmlHttp
function searchdetail()
{ 
var pro=document.getElementById('propertyfor').value; //////for property for rent/sale
var con=document.getElementById('country').value; //////for Country
var state=document.getElementById('States').value; //////for States
var city=document.getElementById('Cities').value; //////for Cities
var pcat=document.getElementById('category').value; //////for Property Category
var ptype=document.getElementById('Types').value; //////for Property Type
var minprice=document.getElementById('minprice').value; //////for Minimum price
var maxprice=document.getElementById('maxprice').value; //////for Maximum price




xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/ajaxphp/search/basicsearch.php"
//url=url+"?q="+str
url=url+"?pro="+pro+"&con="+con+"&state="+state+"&city="+city+"&pcat="+pcat+"&ptype="+ptype+"&minprice="+minprice+"&maxprice="+maxprice;
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChangedent 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

function stateChangedent() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
document.getElementById('result').innerHTML=xmlHttp.responseText;
//alert('Form has been submited. Pls Fill another entry');

  
// document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


