	// 08/15/2006 Amy: Attaches function to window.onerror event
	// 09/11/2006 Amy: Added try catch
	try{
		HandleJSErrors();
	}catch(err){
		//do nothing, we don't want js errors if ClientCommon isn't included
	}
	
	function PopupBlocked() {
		window.navigate("ReportError.asp?Type=ART&Article=Message-PopupBlocked");
	}
	
	/**
	 * Open the latest Hunk Of theDay
	 * @param String hunkUrl: The url for the latest hunk	 
	 */   	
	function Hunk(hunkURL) {
		height = window.screen.availHeight-350;
		width = window.screen.availWidth-400;
		left = Math.round((window.screen.availWidth-656)/2);		
		window.open(hunkURL, "HunkOfTheDay", "width=" + width + ",height=" + height + ",left=" + left + ",top=20,directories=no,scrollbars=yes,resizable=yes,location=yes,toolbar=yes");
	}
	
	//This function open a pop-up window with the 2257 law
	// sampleCode: The code of the movie
	function ProofOfAge(sampleCode)
	{
		var height = '350';
		
		if (sampleCode==""){
			height = '550';
		}else if (sampleCode.indexOf('P=') !=-1){
			height = '550';
		}
		
		proofWindow = window.open("ProofOfAge.asp?Movie=" + sampleCode,'nw',"width=500,height=" + height + ",scrollbars=no,toolbar=no,directories=no,resizable=yes,status=no");
		if (!proofWindow) {
			PopupBlocked();
		} else {
			proofWindow.focus();
		}
	}
	

	function ShowTerms(terms) {
		if (!window.open("Terms.asp?Terms="+terms, "Terms", "width=640,height=440,scrollbars=no,toolbar=no,directories=no,status=no,resizable=no"))
			PopupBlocked();
	}
	
	
	function GetBandwidth() {
		//TO DO: temporary wrapper to be deprecated
		return Sureflix.Vod.getBandwidth();
	}
	
	
	function SetBandwidth(bandwidth) {
		//TO DO: temporary wrapper to be deprecated
		Sureflix.Vod.setBandwidth(bandwidth);
	}


	function GetPlayFormat(streamOrDownload) {
		//TO DO: temporary wrapper to be deprecated
		return Sureflix.Vod.getPlayFormat(streamOrDownload);
	}


	function GetConsole(whichConsole) {
		var consoleArray;

		if (whichConsole == 0) {
			consoleArray = "V|0|0|clos|clos|0|0".split("|");
		} else {
			consoleArray = Sureflix.Utilities.GetCookie("Console" + whichConsole).split("|");
			if (consoleArray.length < 7) consoleArray = "V|20|20|clos|rent|892|606".split("|");
			if (consoleArray[3].length < 4) consoleArray[3] = "clos";
			if (consoleArray[4].length < 4) consoleArray[4] = "rent";
		}
		
		return consoleArray.join("|");
	}


	function PlayScene(movie, scene, days, evt, onload) {
		// movie & scene: scene to play
		// days: Number of days the rental is for
		// evt: event object
		// onload: if true, PlayScene is being called from page_onload, not onclick
		
		var console = 1;
		if (evt != undefined) {
			if (evt.altKey)
				console = 2;
			else
				console = 1;
		}
		
		consoleStr = GetConsole(console);
		consoleArray = consoleStr.split("|");
	
		playerSize = consoleArray[0];
		playerLeft = consoleArray[1];
		playerTop = consoleArray[2];
		tabBottom = consoleArray[3];
		tabSide = consoleArray[4];
		playerWidth = consoleArray[5];
		playerHeight = consoleArray[6];
		
		//don't allow player to go completely off the screen
		if (playerLeft >= window.screen.width-20) playerLeft = 20;
		if (playerTop >= window.screen.height-20) playerTop = 20;
									
		if (!window.open("Player.asp?Movie=" + movie + "&Scene=" + scene + "&Days=" + days + "&Console=" + console, "SureFlix"+console, "left=" + playerLeft + ",top=" + playerTop + ",width=" + playerWidth +",height=" + playerHeight + ",scrollbars=yes,toolbar=no,directories=no,status=no,resizable=yes")) {
			if (!onload) PopupBlocked();
		}
	}


	/******************************************************
	*	11/1/2006 Harjinder: This function will update the innerHTML of an element
	*	param elementName: Name of the element
	*	param updatedValue: element will be updated with this value
	*	param updateWhere: it could be 'opener' or ''
	******************************************************/
	function UpdateElement(elementName, updatedValue, updateWhere) {

		if(updateWhere == "opener") {
			if(opener) {
				element = opener.document.getElementById(elementName);
			} else {
				element = null;
			}
		} else {
			//element = document.getElementById(elementName); //08/13/2007 Harjinder: PPMSite related changes
			element = parent.document.getElementById(elementName); 
		}
		if(element) {
			element.innerHTML = updatedValue;
		}
	}


	/******************************************************
	*	11/1/2006 Harjinder: This function will get the Member.Value from the WebService Member.asmx?GetMemberValue
	*	param p_memberId: Member Id
	*	return: Member.Value
	******************************************************/
	function GetMemberValue(p_memberId, p_curcy) {
		//08/13/2007 Harjinder: PPMSite related changes	
		
		var w = "../Pull/Member.asmx/GetMemberValue?memberId="+ p_memberId +"&curcy=" + p_curcy;
		//alert(w);
		var result = null;
		try {
			result = DoCall("GET", w ,"","xml");
		} catch(e){}

		var MemberValue = '';
		var memberValueNode = null;
		var memberCurcyNode = null;
		
		try {
			if (result != null)
			{
				memberValueNode = result.documentElement.selectSingleNode("MemberValue");
				memberCurcyNode = result.documentElement.selectSingleNode("MemberCurcy");
			}
		
			if (memberValueNode != null)
			{
				MemberValue = memberValueNode.text;
			}
			
			if (memberCurcyNode != null)
			{
				MemberCurcy = memberCurcyNode.text;
			}
			
		
			if (isNaN(MemberValue))
			{
				MemberValue = '';
			}
		
			if (MemberValue != "") {
				if(MemberCurcy + "" == "TOK") {
					MemberValue = Math.round(MemberValue) + "";
				} else {
					MemberValue = Math.round(MemberValue * 100) + "";
					if (MemberValue.length < 3) MemberValue = "0" + MemberValue;
					if (MemberValue.length < 3) MemberValue = "0" + MemberValue;
					MemberValue = MemberValue.substr(0, MemberValue.length-2) + "." + MemberValue.substr(MemberValue.length-2, 2);
				}
			}
		} catch(e) {}

		return(MemberValue); 		
	}

	
	//Hernan: 2006-12-01 Bookmarks with AJAX functions
	/************************************************
	*	This function call the ws to add the bookmark to the database
	*	param memberId: The id of the member to add the bookmark for
	*	param bookmarkType: The type of object to bookmark (movie, scene, channel, star)
	*	param bookmarkItem: The code of the object to bookmark
	*	param bookmarkTitle: The title to show in the bookmarks
	*	param ctrIdToHide:	The id of the control to hide
	*	param ctrIdToShow:	The id of the control to show
	************************************************/
	function AddBookmark(memberId, bookmarkType, bookmarkItem, bookmarkTitle, ctrIdToShow, ctrIdToHide) {
		if (SxUt.isEmpty(memberId)) memberId = Sureflix.getMember().member;
		
		if (SxUt.isEmpty(memberId) || memberId == 'GUEST')
		{
			alert(jsNeedToLogIn);
			return;
		}
		
		var w = "../Pull/Member.asmx/AddBookmark?memberId=" + memberId + "&bookmarkType=" + bookmarkType + "&bookmarkItem=" + bookmarkItem;
		//prompt('',w);
		var result = null;
		var bookmarkIdstr = "";
		try 
		{
			result = DoCall("GET", w ,"","xml");
			if (result != null)
			{
				var bookmarkId	  = result.getElementsByTagName("bookmark")[0].firstChild;
									
				try{
					bookmarkIdstr = bookmarkId.nodeValue;
				}catch(e)
				{
				//	alert(e.message);
				}
					
				RefreshBookmark('add', bookmarkIdstr, bookmarkType, bookmarkItem, bookmarkTitle );
				SxUt.SetCookie("UsedBookmark", "true");
				UpdateDeleteLink(ctrIdToShow, bookmarkIdstr);
				HideCtr(ctrIdToHide);
				ShowCtr(ctrIdToShow);					
				alert(jsDetBookmark);
			}
		} 
		catch(e)
		{
		//	alert(e.message);
		}
	}


	
	/************************************************
	*	This function updates the name parameter in the anchor tag with the new id
	*	param ctrId:	The id of the control to show and the one to get updated
	*	param bookmarkIdstr:	The id of the bookmark
	************************************************/
	function UpdateDeleteLink(ctrId, bookmarkIdstr)
	{
		var ctr = document.getElementById(ctrId);
		if (ctr != null)
		{
			ctr.name = bookmarkIdstr;
		}
	}	
	
	

	/************************************************
	*	This function call the ws to delete the bookmark from the database
	*	param ctrIdToShow:	The id of the control to show
	*	param ctrIdToHide:	The id of the control to hide
	************************************************/
	function DelBookmark(ctrIdToShow, ctrIdToHide)
	{
		try 
		{	
			var ctrDel = document.getElementById(ctrIdToHide);
		
			if (ctrDel != null)
			{
				var bookmarkId = ctrDel.name;
				if ( (bookmarkId+"") == "undefined")
				{
					bookmarkId = ctrDel.getAttribute("name");
				}				
				var w = "../Pull/Member.asmx/DeleteBookmark?bookmarkId=" + bookmarkId;		
			}

			var result = null;

			result = DoCall("GET", w ,"","xml");
			if (result != null)
			{
				if (result.getElementsByTagName("result")[0].firstChild.nodeValue == "OK")
				{
					RefreshBookmark('delete',bookmarkId, '','','');
					Sureflix.Utilities.SetCookie("UsedBookmark", "true");
					HideCtr(ctrIdToHide);
					ShowCtr(ctrIdToShow);
				}
			}
			alert(jsBookmarkRemoved);
		} 
		catch(e)
		{
			//alert(e.message);
		}
	}

	
	
	/************************************************
	*	This function refresh the bookmarks as they are displyed
	*	param action: Add or delete a bookmark
	*	param bookmarkId: The id (unique identifier) for this bookmark.
	*	param bookmarkType: The type of object to bookmark (movie, scene, channel, star, studio, theme)
	*	param bookmarkItem: The code of the object to bookmark
	*	param bookmarkTitle: The text to display
	************************************************/	
	function RefreshBookmark(action,bookmarkId,bookmarkType,bookmarkItem, bookmarkTitle)
	{
		try
		{
			if (action != null)
			{
				var w = "AjaxToSessionBridge.asp?Session=BookMarks&todo=" + action + "&bookmarkId=" + bookmarkId + "&bookmarkType=" + bookmarkType + "&bookmarkItem=" + bookmarkItem + "&bookmarkTitle=" + bookmarkTitle;
				//prompt('',w);
				DoCall("GET", w ,"","xml");
				
				var bookmarkContainer = document.getElementById("BookmarkContainer");
				switch (action.toLowerCase())
				{
					case "add":
						var ctr = document.createElement("DIV");
						ctr.className = "BookmarkItem";						
						ctr.id = "bookmark" + bookmarkId;
						var a1 = document.createElement("a");
						a1.style.width = "100px";
						a1.href = CreateBookMarkLink(bookmarkType,bookmarkItem);
						a1.innerHTML = bookmarkTitle;
						ctr.appendChild(a1);

						if (bookmarkContainer != null && ctr != null)
						{
							bookmarkContainer.appendChild(ctr);
						}
						
						if (document.getElementById("CollBookmarks").style.display == 'none')
						{
							ShowHideCollapser("CollBookmarks");					
						}
						break;
					case "delete":
						var ctr = document.getElementById("bookmark" + bookmarkId);
						if (bookmarkContainer != null && ctr != null)
						{
							bookmarkContainer.removeChild(ctr);
						}
						break;
				}
			}
		}catch(e){}
	}
	
	/************************************************
	*	This function creates a link to the bookmark
	*	param action: Add or delete a bookmark
	*	param bookmarkType: The type of object to bookmark (movie, scene, channel, star, studio, theme)
	*	param bookmarkItem: The code of the object to bookmark
	************************************************/		
	function CreateBookMarkLink(bookmarkType,bookmarkItem)
	{
		if (bookmarkType != null)
		{
			switch(bookmarkType.toLowerCase())
			{
				case "scene":
					var arrMovieScene = bookmarkItem.split("|");
					return "Detail.asp?Movie=" + arrMovieScene[0] + "#Scene" + arrMovieScene[1];
					break;
				case "movie":
					return "Detail.asp?Movie=" + bookmarkItem;
					break;
				case "channel":
					return "ChannelDetail.asp?Channel=" + URLencode(bookmarkItem);
					break;
				case "star":
					return "Star.asp?Star=" + URLencode(bookmarkItem);
					break;
				case "studio":
					return "StudioList.asp?Licensor=" + URLencode(bookmarkItem);
					break;
				case "theme":
					return "Theme.asp?Theme=" + URLencode(bookmarkItem);
					break;
			}
		}
	}
	//END Hernan: Bookmarks with AJAX functions
	


	/******************************************************
	*	12/29/2006 Harjinder: Change to "wait"(hourglass) cursor
	******************************************************/
	function ChangeCursorToWait() {
		var ctBody = document.getElementsByTagName("body");
		var ctDiv = document.getElementsByTagName("div");
		var ctrDiv = 0;
		ctBody[0].style.cursor = "wait";
		while(ctrDiv < ctDiv.length) {
			ctDiv[ctrDiv].style.cursor = "wait";
			ctrDiv++;
		}
	}

	
