// JS stub to call myFavorites...
//
// myFavorites.js
// by Brian Johnson
// copyright 2009
//

function myFavorites(articleId) {
	
	dataString = "theArticle="+articleId;
	
	jQuery("body").css("cursor", "progress"); //progress cursor

	jQuery.ajax({
		async: false, 
		type: "POST",
		url: "/php/myFavorites.php",
		data: dataString,
		success: function(msg)  {

			if (msg=="guest") {
				
				jQuery.modal("<h2 style='display:inline; color:white;' class='myFavoritesError'>Login Required</h2><div class='myFavoritesError' onclick='jQuery.modal.close(); window.location=\"/index.php?option=com_content&view=article&id=213&Itemid=238\";'><br/><p>Please <a href='#' >Login</a>, or <a href='#'>Register</a> for an account before selecting your favorite homes.</p><br/><p>Once logged in, you can mark your favorite homes, to view later or to share with your friends.</p></div>");

				//close after 4 seconds...
				setTimeout('jQuery.modal.close()',12000);


			}
			
			jQuery.modal("<h2 style='display:inline; color:white;' class='myFavoritesError'>Favorite Added!</h2><div class='myFavoritesError' onclick='jQuery.modal.close(); '><br/><p>We've add this home to your list of favorites.</p><p> You can view your favorite homes under the \'<a href=\'/index.php?option=com_content&view=article&id=133&Itemid=226\'>MyFavorites!</a>\' menu.</p></div>");

			//close after 4 seconds...
			setTimeout('jQuery.modal.close()',5000);



		}
	});
	
	//update the changes
	jQuery("div.module-myfavorites").load("/php/viewMyFavorites.php");
	
	//return cursor to normal state
    jQuery("body").css("cursor", "auto");
}

function removeMyFavorite(articleId) {
	
	dataString = "theArticle="+articleId;
	
	jQuery("body").css("cursor", "progress"); //progress cursor


	jQuery.ajax({
		async: false, 
		type: "POST",
		url: "/php/removeMyFavorites.php",
		data: dataString
	});

		//update the changes
		jQuery("div.module-myfavorites").load("/php/viewMyFavorites.php?rand="+Math.floor(Math.random()*9999));
		
		//return cursor to normal state
	    jQuery("body").css("cursor", "auto");

}