// JavaScript Document

function GetPropertyEmail(mlsid,City,Price){
window.open("sendtofriend.php?mlsid="+mlsid+"&city="+City+"&price="+Price,
	"mywindow","location=0,width=500,height=300");
}

	var req = new XMLHttpRequest();	
	function getState(countryId) {		
		var strURL="findState.php?country="+countryId;
	
		if (req) {
			
			req.onreadystatechange = function() {
//alert(req.responseText);
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;	
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
function GetMlsNumber(mlsid)
 {
 window.open ("mlscontact.php?mlsid="+mlsid,
"mywindow","width=500,height=400");	 
 
 }
	function getCity(stateId,PropertyId) {		
		var strURL="findCity.php?state="+stateId+"&propertyid="+PropertyId;
		//alert("");
		var req = new XMLHttpRequest();

		if (req) {
			req.onreadystatechange = function() {
				//alert(req.readyState);
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {	
					
						document.getElementById('citydiv').innerHTML=req.responseText;	
						//document.getElementById('displaynone').innerHTML = '';					
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
		
				
	}
	
	function getCity1(stateId,PropertyId) {		
		var strURL="findState.php?state="+stateId+"&propertyid="+PropertyId;
		//alert(strURL);
		var req = new XMLHttpRequest();

		if (req) {
			req.onreadystatechange = function() {
				//alert(req.readyState);
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {	
					
						document.getElementById('citydiv').innerHTML=req.responseText;	
						//document.getElementById('displaynone').innerHTML = '';					
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
		
				
	}	
//State City selection

	function getState1(PropertyId) {		
		var strURL="getstate.php?propertyid="+PropertyId;
		var req = new XMLHttpRequest();

		if (req) {
			req.onreadystatechange = function() {
				//alert(req.readyState);
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {	
					
						document.getElementById('statediv').innerHTML=req.responseText;	
						//document.getElementById('displaynone').innerHTML = '';					
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
		
				
	}	
	
function  isValidTelephone(tel){
	validRegExp = /^[0-9]+$/;
    if (tel.match(validRegExp) == null) {
      return false;
    } 
		return true;
}

function checknumber(data) {
    var checkOK = "0123456789";
    var checkStr = data.value;
    var allValid = true;
    var allNum = "";
    
      for (i = 0;  i < checkStr.length;  i++) {
        ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
        if (j == checkOK.length) {
          allValid = false;
          break;
        }
        if (ch != ",")
          allNum += ch;
        }
        if (!allValid) {
          alert("Please enter a valid phone number");
          data.value = "";
        return (false);
      }
    }
function loadstate(prpvalue){
	window.location = "index.html?propertyid="+prpvalue;			   
}
function loadstatehome(prpvalue){
	window.location = "search-homes.html?property_type1="+prpvalue;			   
}