﻿//Script to manage picking favorite properties

function Favorite(propertyID)
{
	//Update the icon image
	var isFavorite;
	var icon = document.getElementById('Fav_' + propertyID);	
	var link = document.getElementById('RL_MarkAsFavoriteText');
	
	//alert(link);
	
	if(icon.src.indexOf('foff') > 0)
	{
		icon.src = '/images/fon.gif';
		isFavorite = true;
		
		if(link != null) link.innerHTML = 'Unmark&nbsp;as&nbsp;favorite';
	}
	else
	{
		icon.src = '/images/foff.gif';
		isFavorite = false;
		
		if(link != null) link.innerHTML = 'Mark&nbsp;as&nbsp;favorite';
	}	
	
	ScriptServices.MarkFavorite(propertyID, isFavorite, OnSucceeded, OnError, OnTimeOut);	
}


function OnSucceeded(result)
{
	var args = result.split(",");

	//Update the spot that indicates how many favorites this user has
	var favoritesSpot = document.getElementById('RL_NumFavorites');
	var number = '(' + args[0] + ')';
	favoritesSpot.innerHTML = number;
	
	var warningMsg = document.getElementById('RL_NotLoggedInWarning');
	
	
	//Optionally show a warning
	if(args[1] > 0)
	{
		warningMsg.style.display = 'block';
	}
	else
	{
		warningMsg.style.display = 'none';
	}
	
}

function OnTimeOut(result)
{
	alert('Timeout: ' + result);
}
function OnError(result)
{
	alert('Error: ' + result);
}
