	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");
				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" />  <b>Remove from Favorites</b></a>';
			}
			else{
				alert("Server error! Please try again later!");
			}
		}
	}
	
	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");
				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" />  <b>Add to Favorites</b></a>';
			}
			else{
				alert("Server error! Please try again later!");
			}
		}
	}
	
	/* Functions property page */

function add_favourite_page_property(property_id, property_type){
	ajax_request = new AjaxRequest();

	if(!ajax_request){
		alert("Error inicializing Ajax!");
		return;
	}
	ajax_request.onreadystatechange = refresh_star_add_property;
	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_property(){	
	if(ajax_request.readyState == 4){		
		if(ajax_request.status == 200 ){
			var response = ajax_request.responseText.split(" ");			
			var star = document.getElementById("star2_"+response[0]);	
			
			star.innerHTML = '<a href="javascript:void(0);" onclick="javascript:remove_favourite_page_property(\''+response[0]+'\', \''+response[1]+'\')" title="Remove from Favorites"><img src="/images/slide_bt_fave_rm.jpg" alt="Remove from Favorites" border="0" /></a>';
			
		}
		else{
			alert("Server error!");
		}
	}
}

function remove_favourite_page_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_property;
	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_property(){	
	if(ajax_request.readyState == 4){
		if(ajax_request.status == 200 ){
			var response = ajax_request.responseText.split(" ");			
			var star = document.getElementById("star2_"+response[0]);			
			star.innerHTML = '<a href="javascript:void(0);" onclick="javascript:add_favourite_page_property(\''+response[0]+'\', \''+response[1]+'\')" title="Add to Favorites"><img src="/images/slide_bt_fave_add.jpg" alt="Add to Favorites" border="0" /></a>';
			
		}
		else{
			alert("Server error!");
		}
	}
}