/* Ajax function */
var xmlHttp

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;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function selectThisTab(id){
						
	var x = document.getElementById(id);						
						
	if(x.className != "unselected"){
		var y = document.getElementById('tabs_select').getElementsByTagName("li");
							
		for (var i=0;i<y.length;i++){ 
			y[i].className = "selected";}
  							
			x.className = "unselected";
		}
	else{
		return;}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

function changeAction(str){
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return
	}
	
	var x = document.getElementById("asearch");
	x.action = str+".php";
	
	var dev = document.getElementById("devDis");
	var y = document.getElementById("search").getElementsByTagName("li");
	if(str == "development"){
		dev.style.display = "none";
		y[4].style.borderBottom = "none";
	}
	else {
		dev.style.display = "block";
		y[4].style.borderBottom = "1px dotted #56677c";			
	}
	

	
	var url="minMax.php";
	url=url+"?pid="+str
	url=url+"&sid="+Math.random()
	
	xmlHttp.open("GET",url,true)
	xmlHttp.onreadystatechange=MMStateChanged
	
	xmlHttp.send(null)
	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function MMStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//alert(xmlHttp.responseText);
		document.getElementById("minMax").innerHTML=xmlHttp.responseText 
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function  changeFormAction(str){

	if (str.length==0){ 
  		document.getElementById("prange").innerHTML=""
  		return
	}

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return
	}
	var x=document.getElementById("search_form");
	x.action=str+".php";
	
	var url="prange.php";
	url=url+"?cat="+str
	url=url+"&sid="+Math.random()
	
	xmlHttp.open("GET",url,true)
	xmlHttp.onreadystatechange=priceStateChanged
	
	xmlHttp.send(null)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function priceStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//alert(xmlHttp.responseText);
		document.getElementById("max_price").innerHTML=xmlHttp.responseText 
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function changeProvince(str){
	if (str.length==0){ 
  		document.getElementById("content").innerHTML=""
  		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return
	}
	
	var url="optgroups.php";

	url=url+"?opt="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
// For changeProvince()
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("state_province").innerHTML=xmlHttp.responseText 	
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//Investor relations page
function checkPass(){
	var str = document.getElementById("password").value
	if (str.length==null){ 
  		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return
	}
	
var url="inv.php";

url=url+"?p="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged_inv
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
// For checkPass()
function stateChanged_inv() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		if(xmlHttp.responseText.length > 100){
			document.getElementById("content_body").innerHTML=xmlHttp.responseText 
			document.getElementById("p_div").style.display="none";
			document.getElementById("a_print").style.display="block";		
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function openWin(page){
	w = 500;
	h = 600;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=1,resizable=0,location=0,status=1,menubar=0,toolbar=0'
	win = window.open(page+'.php', "", winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function viewThis(src){
	var main_src = document.getElementById("main_img").src
	var pic = document.getElementById(src).src
				
	document.getElementById("main_img").src = pic
	document.getElementById(src).src = main_src
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
function changeLabel(str){
	var x = document.getElementById("con_label")
	var y = document.getElementById("hidden").getElementsByTagName("p");
	var emailReq = document.getElementById("email_req");
	
	if(y[1].style.display == "block" && str != "mail"){
		for(i = 1; i < 4; i++){
		y[i].style.display="none";	
		}
	}	
	
	switch (str){

	case "phone":
		emailReq.style.display="none";
		y[0].style.display="block";
		x.innerHTML = "Phone No. <span class='required'>*</span>"
		break;
	case "fax":
		emailReq.style.display="none";
		y[0].style.display="block";
		x.innerHTML = "Fax No.  <span class='required'>*</span>"
		break;
		
	case "email":
		y[0].style.display="none";
		emailReq.style.display="inline";
		break;

	case "mail":
		emailReq.style.display="none";
		y[0].style.display="none";
		for(i = 1; i < 4; i++){
		y[i].style.display="block";	
		}
		
		break;
	default:
		emailReq.style.display="none";
		y[0].style.display="none";
		break;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

function validateSearch(){
	var minPrice = document.getElementById("minp")
	minPrice = parseInt(minPrice.value);
	var maxPrice = document.getElementById("maxp")
	maxPrice = parseInt(maxPrice.value)

	//alert("Minmum price: "+ minPrice.value + " Max price: "+maxPrice.value)
	if(maxPrice != "NaN"){
		if(maxPrice < minPrice){
			alert("Please note that the minimum price can not exceed the maximum price")
			return false
		}
	}
	
	
	var minBeds = document.getElementById("minb")
	minBeds = parseInt(minBeds.value)
	var maxBeds = document.getElementById("maxb")
	maxBeds = parseInt(maxBeds.value)	
	
	if(maxBeds != "NaN"){
		if(maxBeds < minBeds){
			alert("Please note that the minimum bedrooms can not exceed the maximum bedrooms")
			return false
		}
	}
	
	return true
	

	
}

















