var xmlHttp

function updateRank(rating,account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	} 
	if(account_num == "")
	{
		alert("Please Login or Create a Home Quest Account To Rate This Home");
		return;
	} 
	var   url="includes/mls/ajax_php/update_rank.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num
	url	= url+"&rating="+ rating 
	url	= url+"&sid="+Math.random()
	 
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			//document.getElementById('mls_rating_' + mls_num).innerHTML = xmlHttp.responseText; 
			//setTimeout("clearDiv('"+mls_num+"')",5000);
			rating = rating * 25;
			document.getElementById('current_rating_'+ mls_num).style.width = rating+'px';
			
			if(rating != 0)
			{
				document.getElementById('no_rating_' + mls_num).style.display = 'block';
			}
			else
			{
				document.getElementById('no_rating_' + mls_num).style.display = 'none';
			}
		}  
	}   
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null); 
} 

function clearDiv(mls_num)  
{
	document.getElementById('mls_rating_' + mls_num).innerHTML = ""; 
}
function saveHome(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	} 
	if(account_num == "")
	{
		alert("Please Login or Create a Home Quest Account To Save This Home.");
		return;
	} 
	
	var   url="includes/mls/ajax_php/save_homes.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt("",url);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var is_saved_home = xmlHttp.responseText; 
			if(is_saved_home != 0)
			{
				alert("You have already saved this home.");
				return;
			}  
			else
			{
				document.getElementById('sh_' + mls_num).innerHTML = '<a href="javascript:removeMyHome('+account_num+','+mls_num+');" class="mls_result"><img src="images/mls/save_icon_checked.jpg" alt="Already Saved to My Homes" width="20" height="40" border="0" /></a>';
				document.getElementById('sh_change_' + mls_num).innerHTML = '<a href="javascript:removeMyHome('+account_num+','+mls_num+');" class="mls_result">Unsave Home</a>';				
				//alert("Your home has been saved.");
				return;
			}  
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}
function removeMyHome(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	} 
	/*
	if (!confirm("Are you sure you want to delete this home from your saved homes?"))
	{
		return;
	}
	*/	
	var   url="includes/mls/ajax_php/remove_home.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			document.getElementById('sh_' + mls_num).innerHTML = '<a href="javascript:saveHome('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/save_icon.jpg" alt="Add to My Homes" width="20" height="40" border="0" /></a>';
			document.getElementById('sh_change_' + mls_num).innerHTML = '<a href="javascript:saveHome('+account_num+','+mls_num+');"  class="mls_result">Save Home</a>';							
			//alert("Your home has been Unsaved.");
	   		//document.getElementById('mls_num_' + mls_num).style.display = 'none';
			return; 
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		Compare Functions
// 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function compareHome(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	} 
	if(account_num == "")
	{
		alert("Please Login or Create a Home Quest Account To Compare This Home.");
		return;
	} 
	if(mls_num == "")
	{
		activateWindowCompare("http://www.johncastillo.com/listings/compare_saved_homes.php");
		return;
	}  
	var   url="../includes/mls/ajax_php/compare_homes.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var is_compared_home = xmlHttp.responseText; 
			
			/*
			if(is_compared_home == 0)
			{				
				alert("You must first do a home search to choose the homes you'd like to compare.");
				return;
			}			
			*/
			if(is_compared_home != 0)
			{
				document.getElementById('ch_' + mls_num).innerHTML = '<a href="javascript:compareHomePopup('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/compare_icon_checked.jpg" alt="Already Compared" width="20" height="40" border="0" /></a>';
				document.getElementById('ch_change_' + mls_num).innerHTML = '<a href="javascript:compareHomePopup('+account_num+','+mls_num+');"  class="mls_result">View Compared</a>';				
				
				return;
			}  
			else
			{
				document.getElementById('ch_' + mls_num).innerHTML = '<a href="javascript:compareHomePopup('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/compare_icon_checked.jpg" alt="Already Compared" width="20" height="40" border="0" /></a>';
				document.getElementById('ch_change_' + mls_num).innerHTML = '<a href="javascript:compareHomePopup('+account_num+','+mls_num+');"  class="mls_result">View Compared</a>';								
			
				return;
			}  
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}   
function compareHomePopup(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	} 
	if(account_num == "")
	{
		alert("Please Login or Create a Home Tracker Account To Compare This Home.");
		return;
	} 
	if(mls_num == "")
	{
		activateWindowCompare("../listings/compare.php");
		return;
	}  
	var   url="http://www.johncastillo.com/listings/includes/mls/ajax_php/compare_homes.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var is_compared_home = xmlHttp.responseText; 
			
			if(is_compared_home == 0)
			{				
				alert("You must first do a home search to choose the homes you'd like to compare.");
				return;
			}	
			if(is_compared_home != 0)
			{
				
				document.getElementById('ch_' + mls_num).innerHTML = '<a href="javascript:compareHome('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/compare_icon_checked.jpg" alt="Already Compared" width="20" height="40" border="0" /></a>';
				document.getElementById('ch_change_' + mls_num).innerHTML = '<a href="javascript:compareHome('+account_num+','+mls_num+');"  class="mls_result">View Compared</a>';				
				
				activateWindowCompare("compare.php");				
				return;
			}			
			else
			{
				document.getElementById('ch_' + mls_num).innerHTML = '<a href="javascript:compareHome('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/compare_icon_checked.jpg" alt="Already Compared" width="20" height="40" border="0" /></a>';
				document.getElementById('ch_change_' + mls_num).innerHTML = '<a href="javascript:compareHome('+account_num+','+mls_num+');"  class="mls_result">View Compared</a>';								
				
				activateWindowCompare("compare.php");
				return;
			}  
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
} 
function updateCompareHome(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}  
	if(mls_num != '')
	{
		if (!confirm("Are you sure you want to delete this home from your compare list?"))
		{
			return;
		}
	}
	
	var   url="includes/mls/ajax_php/update_my_compared_homes.php"
	url	= url+"?account_num="+ account_num
	url	= url+"&mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{  
			document.getElementById('mls_compare_homes').innerHTML = xmlHttp.responseText;
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		END Compare Functions
// 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function drivingRoute(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();
	if(account_num == "")
	{
		alert("Please Login or Create a Home Tracker Account To Add Homes To Your Driving Route.");
		return;
	} 
	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}  
	var   url="includes/mls/ajax_php/driving_route.php" 
	url	= url+"?mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var already_added = xmlHttp.responseText; 
			//alert(already_added);
			if(already_added == 0)
			{
				document.getElementById('dr_' + mls_num).innerHTML = '<a href="javascript:removedrivingRoute('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/driving_route_icon_checked.jpg" alt="Already Added to Driving Route" width="20" height="40" border="0" /></a>';
				document.getElementById('dr_change_' + mls_num).innerHTML = '<a href="javascript:removedrivingRoute('+account_num+','+mls_num+');"  class="mls_result">Remove From My<br />Driving Route</a>';
				//alert("This home has been added to your driving route.");
				return;
			}
			else
			{
				alert("This home has already been added to your driving route.");
				return;
			}
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}   
function removedrivingRoute(account_num,mls_num)
{
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}  
	/*
	if(mls_num != '')
	{
		if (!confirm("Are you sure you want to delete this listing from your driving route?"))
		{
			return;
		}
	}
	*/
	var   url="includes/mls/ajax_php/update_driving_route.php" 
	url	= url+"?mls_num="+ mls_num 
	url	= url+"&sid="+Math.random()
	
	//prompt ("",url)
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{  
			var thing = xmlHttp.responseText;
			document.getElementById('dr_' + mls_num).innerHTML = '<a href="javascript:drivingRoute('+account_num+','+mls_num+');"  class="mls_result"><img src="images/mls/driving_route_icon.jpg" alt="Add to Driving Route" width="20" height="40" border="0" /></a>';
			document.getElementById('dr_change_' + mls_num).innerHTML = '<a href="javascript:drivingRoute('+account_num+','+mls_num+');"  class="mls_result">Add to My<br />Driving Route</a>';							
			//alert("Your listing has been removed from your driving route.");
		}  
	}   
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
}
function GetXmlHttpObject(){var xmlHttp=null;try{ xmlHttp=new XMLHttpRequest();}catch (e){ try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}