	function AjaxRequest(){
		var Ajax = false;
		if(window.XMLHttpRequest){
			Ajax = new XMLHttpRequest();			
		}else if(window.ActiveXObject){
			try{
				Ajax = new ActiveXObject("Msxml2.XMLHTTP");				
			}catch(e){
				try{
					Ajax = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e) { }
			}
		}
		return Ajax;
	}
	
	function add_favourite_property(property_id, property_type){
		ajax_request = new AjaxRequest();		
		if(!ajax_request){
			alert("Error inicializing Ajax!");
			return;
		}
		ajax_request.onreadystatechange = refresh_star_add;
		ajax_request.open('GET', 'insert_favourite_property.php?property_id='+property_id+'&property_type='+property_type, true);
		ajax_request.send(null);
	}
	function refresh_star_add(){	
		if(ajax_request.readyState == 4){
			if(ajax_request.status == 200 ){
				var response = ajax_request.responseText.split(" ");
				var star = document.getElementById("star_"+response[0]);
				//var star2 = document.getElementById("star2_"+response[0]);
				star.innerHTML = '<a href="javascript:void(0);" onclick="javascript:remove_favourite_property(\''+response[0]+'\', \''+response[1]+'\')" title="Remove from Favorites"><img src="images/staron.gif" width="12" height="12" alt="Remove from Favorites" border="0" /></a>';
				//star2.innerHTML = '<a href="javascript:void(0);" onclick="javascript:remove_favourite_property(\''+response[0]+'\', \''+response[1]+'\')" title="Remove from Favorites"><img src="images/staron.gif" width="12" height="12" alt="Remove from Favorites" border="0" /> Remove from Favorites</a>';
			}
			else{
				alert("Server error!");
			}
		}
	}
	
	function remove_favourite_property(property_id, property_type){
		confirmation = confirm("Are you sure you want to remove this property from your favorites?");
		if(!confirmation)
			return;
		
		ajax_request = new AjaxRequest();		
		if(!ajax_request){
			alert("Error inicializing Ajax!");
			return;
		}
		ajax_request.onreadystatechange = refresh_star_remove;
		ajax_request.open('GET', 'remove_favourite_property.php?property_id='+property_id+'&property_type='+property_type, true);
		ajax_request.send(null);
	}
	function refresh_star_remove(){	
		if(ajax_request.readyState == 4){
			if(ajax_request.status == 200 ){
				var response = ajax_request.responseText.split(" ");
				var star = document.getElementById("star_"+response[0]);
				//var star2 = document.getElementById("star2_"+response[0]);
				star.innerHTML = '<a href="javascript:void(0);" onclick="javascript:add_favourite_property(\''+response[0]+'\', \''+response[1]+'\')" title="Add to Favorites"><img src="images/staroff.gif" width="12" height="12" alt="Add to Favorites" border="0" /></a>';
				//star2.innerHTML = '<a href="javascript:void(0);" onclick="javascript:add_favourite_property(\''+response[0]+'\', \''+response[1]+'\')" title="Add to Favorites"><img src="images/staroff.gif" width="12" height="12" alt="Add to Favorites" border="0" /> Add to Favorites</a>';
			}
			else{
				alert("Server error!");
			}
		}
	}