var Property;

function AddFavourite(PropertyCode){
	var PostData='PropertyCode='+PropertyCode;
	$.ajax({
		url:"/Includes/AJAX-Calls/AJAX-AddFavourite.asp",
		type:"POST",
		dataType:"json",
		data:PostData,
		success:function(json){
			HandleAddFavourite(json);
		}
	});
}


function HandleAddFavourite(json){
	if (json){
		var Data=new Array();
		var IncomingLength=json.incoming.Favourites.length;
		var x=0;
		if (IncomingLength>0) {
			var Status=json.incoming.Favourites[0].Status;
			switch(Status){
				case 'Error':
					$.jGrowl("There was a serious error adding this item to your shortlist. Please contact us for assistance.", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
					break;
				case 'Login':
					$.jGrowl("You must register and login to add items to your shortlist.", { header: '<img src="/images/icons/growl_notice.gif" align="absmiddle"/> LOGIN REQUIRED' });
					break;
				case 'NotFound':
					$.jGrowl("The property you are trying to add to your shortlist cannot be found!", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
					break;
				case 'Exists':
					$.jGrowl("This cottage is already in your Shortlist!", { header: '<img src="/images/icons/growl_notice.gif" align="absmiddle"/> ALREADY ADDED TO SHORTLIST' });
					break;
				case 'Ok':
					$.jGrowl("This cottage has been added to your shortlist!", { header: '<img src="/images/icons/growl_ok.gif" align="absmiddle"/> FAVOURITE ADDED' });
					break;
				case 'FULL':
					$.jGrowl("This item could not be added to your shortlist as you already have 10 items stored. Please delete some favourite items before adding any more.", { header: '<img src="/images/icons/growl_notice.gif" align="absmiddle"/> FAVOURITES FULL!' });
					break;
				default:
				  $.jGrowl("There was an unhandled error adding this item to your shortlist. Please contact us for assistance.", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
			}				
		}
	}
}
		
		
$(document).ready(function() {	
	$('.RemoveFavourite').click(
		function(){
			$(this).css('backgroundImage','url(/images/framework/loading1.gif)');
			$(this).css('background-position','0px 0px');
			var PostData='ID='+$(this).attr('rel');
			Property=$(this).attr('code');
			AjaxPost('/Includes/AJAX-Calls/AJAX-RemoveFavourite.asp',PostData,'HandleRemoveFavourite','');	
		}
	)
	$('.FormSent p span').click(
		function(){
			$('.FormSent').fadeOut(500,function(){
				$('.FormSent').remove();
				$('.FormSend').fadeIn(500);
			})
		}
	);
})

function HandleRemoveFavourite(){
	var CData=CheckStatus();
	if (CData){
		var Data=new Array();
		var IncomingLength=Cdata.incoming.Favourites.length;
		var x=0;
		if (IncomingLength>0) {
			var Status=Cdata.incoming.Favourites[0].Status;
			if (Status=='Ok'){
				$('#Prop_'+Property).slideUp(500,function(){
					$('#Prop_'+Property).remove();
					}
				);
				$.jGrowl("This item has been deleted from your shortlist!", { header: '<img src="/images/icons/growl_ok.gif" align="absmiddle"/> SHORTLIST DELETED' });
			}
			else if(Status=='LOGIN'){
				$.jGrowl("Failed to delete shortlist item. Please ensure you are logged in", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
			}
			else{
				$.jGrowl("Failed to delete shortlist item due to an error. Please contact us for assistance.", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
			}
		}
		else{
			$.jGrowl("Failed to delete shortlist item due to an error. Please contact us for assistance.", { header: '<img src="/images/icons/growl_fail.gif" align="absmiddle"/> SHORTLIST FAILED' });
		}
	}
}
