function addToWishlist(movieId, targetObject)
{
	var t_id = targetObject.id.substring(0, targetObject.id.lastIndexOf("_"));
	// submit off to the ajax
	var temp = ajax.AddToWishlist(movieId, t_id, addToWishlist_callback);
	// switch the icon
	SwitchWishList(t_id);
	
	// update number of items on the wish list
	//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}

function addToWishlist_callback(response)
{
	var div = document.getElementById("Sidebar_SidebarWishlist_LoggedIn");
	if(div!=null)
	{
		div.innerHTML = response.value.Body;
		eval(response.value.DirectToEval);
		
	}
}


var ALT_ON_WISHLIST = "On Your Wish List";
var ALT_ADD_WISHLIST = "Add to Wish List";
var TITLE_ON_WISHLIST = "On Your Wish List";
var TITLE_ADD_WISHLIST = "Add to Wish List";
var WISHLIST_PAGE = "Wishlist.php";
SIDEBAR_FRAME = "frmSide"; //Same as in ratingStars.js

function wlb(MovieID, isOn, srcAdd, srcOn, w, h) {
	var imgID = "img_" + MovieID;
	var lnkID = "lnk_" + MovieID;
	var thisHtml = "";
	alttext = (isOn)?ALT_ON_WISHLIST:ALT_ADD_WISHLIST;
	titletext = (isOn)?TITLE_ON_WISHLIST:TITLE_ADD_WISHLIST;
	href = (isOn)?WISHLIST_PAGE:"javascript:addToWishlist('" + imgID + "','" + lnkID + "', false)";
	try {
		if (IN_SIDEBAR) {
			href = (isOn)?WISHLIST_PAGE:"javascript:addToWishlist('" + imgID + "','" + lnkID + "', true)";
		}
	}catch(er){}	
	thisHtml += "<a id=\"" + lnkID + "\" href=\"" + href + "\" target=\"_top\">";
	thisHtml += "<img id=\"" + imgID + "\" title=\"" +titletext + "\" alt=\"" + alttext + "\" border='0' width='" + w + "' height='" + h + "' >";
	thisHtml += "</a>";
	document.write(thisHtml);
	Img = document.getElementById(imgID);
	if (Img)
	{
		Img.src = ((isOn)?srcOn:srcAdd);
		Img.srcOn = srcOn;
	}
}
		
function addToWishlist1(ImgID, LnkID, bInSidebar) {
	submitRating(ImgID);
	if (bInSidebar) {
		sidebarCursorWait();
		if (window.location.pathname.toLowerCase().indexOf("Wishlist.php") > 0) {
			window.location.href = window.location.href;	
		}
		else {
			window.setTimeout('refreshSidebar()',1000);
		}
	} else {
		displayOn(ImgID, LnkID);
		window.setTimeout('refreshSidebar()',1000);	
	}
}

function submitRating(ImgID) {
	MovieID = ImgID.substring(ImgID.lastIndexOf("_")+1, ImgID.length);
	submitURL = "/util/addToWishlist.php?mid=" + MovieID + "&source=" + escape(window.location.pathname + window.location.search);
	window.location.href = submitURL;
}
function displayOn(ImgID, LnkID)
{
	Img = document.getElementById(ImgID);
	if (Img.src.indexOf(Img.srcOn) < 0) {
		Img.src = Img.srcOn;
		Img.alt = ALT_ON_WISHLIST;
	}
	Lnk = document.getElementById(LnkID);
	Lnk.href = WISHLIST_PAGE;
}
function sidebarCursorWait() {
	if (document.getElementById(SIDEBAR_FRAME) ) {
		oFrame = document.getElementById(SIDEBAR_FRAME);
		d = null;
		if (oFrame.contentDocument) d=oFrame.contentDocument; 
		else if (oFrame.contentWindow) d=oFrame.contentWindow.document;
		if (null != d) { d.body.style.cursor = "wait"; }
	}
}
function refreshSidebar() {
	if (document.getElementById(SIDEBAR_FRAME) ) {
		document.getElementById(SIDEBAR_FRAME).src = document.getElementById(SIDEBAR_FRAME).src;
	}
}
