function getHTTPObject()
{ 
	var xmlhttp; 

	if(window.XMLHttpRequest)
	{ 
		xmlhttp = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject)
	{ 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!xmlhttp)
		{ 
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}    
	} 
	return xmlhttp;   
} 

var http; 
function getCities(prId)
{
	
 
	if(window.XMLHttpRequest)
	{ 
		http = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject)
	{ 
		http=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!http)
		{ 
			http=new ActiveXObject("Msxml2.XMLHTTP"); 
		}    
	} 
	  
	
	var prId = document.getElementById('province').value;

	var cId = document.getElementById('cityId').value;
	
	var url = 'getCities.php?prId='+prId+'&cId='+cId; 
	
	http.open('GET',url, true); 
	
	http.onreadystatechange = handleCityhttpresponse; 
	
	http.send(null); 
}


function handleCityhttpresponse()
{   
    if (http.readyState == 1 || http.readyState == 2 || http.readyState == 3 || http.readyState == 0)
	{
		var img = new Image();
		img.src ="images/ajax-loader.gif";
		document.getElementById('cityList').innerHTML = "<img src='images/ajax-loader.gif' />";
	}
	
	if (http.readyState == 4)
	{ 
		if(http.status==200)
		{ 
			var results=http.responseText; 

			if(results != '')
			{
				document.getElementById('cityList').innerHTML = results; 
			}
			else
			{
				document.getElementById('cityList').innerHTML = "Please select province"; 
			}
		}
	} 
}

var httpc;
function getPropertyType(id)
{
  
	if(window.XMLHttpRequest)
	{ 
		httpc = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject)
	{ 
		httpc=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!httpc)
		{ 
			httpc=new ActiveXObject("Msxml2.XMLHTTP"); 
		}    
	} 
	
	var url = 'getCities.php?Id='+id+'&mode=getPropertyType'; 

	httpc.open('GET',url, true); 
	
	httpc.onreadystatechange = handleCityTypehttpresponse; 
	
	httpc.send(null); 
	
}


function handleCityTypehttpresponse()
{   
  if (httpc.readyState == 1 || httpc.readyState == 2 || httpc.readyState == 3 || httpc.readyState == 0)
	{
		var img = new Image();
		img.src ="images/ajax-loader.gif";
		document.getElementById('propertyList').innerHTML = "<img src='images/ajax-loader.gif' />";
	}
	
	if (httpc.readyState == 4)
	{ 
		if(httpc.status==200)
		{ 
			var results=httpc.responseText; 

			if(results != '')
			{
				document.getElementById('propertyList').innerHTML = results; 
			}
			else
			{
				document.getElementById('propertyList').innerHTML = "Please select city"; 
			}
		}
	} 
}

var httppid
function getPropertyId(pid)
{
	if(window.XMLHttpRequest)
	{ 
		httppid = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject)
	{ 
		httppid=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!httppid)
		{ 
			httppid=new ActiveXObject("Msxml2.XMLHTTP"); 
		}    
	} 
	
	var url = 'addToFavorite.php?pId='+pid; 

	httppid.open('GET',url, true); 
	
	httppid.onreadystatechange = handleFavoriteTypehttpresponse; 
	
	httppid.send(null); 
}

function handleFavoriteTypehttpresponse()
{   
  if (httppid.readyState == 1 || httppid.readyState == 2 || httppid.readyState == 3 || httppid.readyState == 0)
	{
		var img = new Image();
		img.src ="images/ajax-loader.gif";
		document.getElementById('showInterestButton').innerHTML = "<img src='images/ajax-loader.gif' />";
	}
	
	if (httppid.readyState == 4)
	{ 
		if(httppid.status==200)
		{ 
			var results=httppid.responseText; 

			if(results == 'added')
			{
				document.getElementById('showRemoveInterestButton').style.display = 'none';
				document.getElementById('showAddInterestButton').style.display = 'block'; 
			}
			else
			{
				document.getElementById('showAddInterestButton').style.display = 'none'; 
				document.getElementById('showRemoveInterestButton').style.display = 'block';
				
			}
		}
	} 
}
