// ---------------- functions used by the movie pseudo control -----------------------------
function iTalkiesMyListUpdated ()
{
	// override the html
	if (window.parent != window)
	{
		var parentMyListDiv = window.parent.document.getElementById ("MyListDiv");
		var myListDiv = window.document.getElementById ("MyListDiv");
		if ((parentMyListDiv != null) && (myListDiv != null))
		{
			parentMyListDiv.innerHTML = myListDiv.innerHTML;
		}
	}
}
function iTalkiesUpdateMyList (action, location, movieId)
{	
	if (!hasUserCookie)
	{
		alert ("You must be logged in to Add movies to you list.");
		window.document.location.href = iTalkiesGetSmartHref(false, "/RentIt.aspx?MovieID=" + movieId);
		return;
	}
	// find the hidden frame in this window itself that allows me to send updates to MyList.
	if (window.document.location.pathname.indexOf("MyList.aspx") != -1)
	{
		window.document.location.search = "Action=" + action 
						+ "&Location=" + location + "&MovieID=" + movieId;
	}
	else
	{
		var myListFrame = null;
		var secureParam = "";
		
		try
		{
			myListFrame = window.document.getElementById("HiddenMyListFrame");
			if (window.location.pathname.toLowerCase().indexOf("secure/") != -1)
			{
				secureParam = "";
			}
			else
			{
				secureParam = "&Secure=false";
			}
		}
		catch (e)
		{
			if (ie) 
				if (e.number != -2147024891)
					throw e;
		}			
		
		var test = iTalkiesGetSmartHref (true, "/secure/MyListCompactUpdater.aspx?Action=" + action
					+ "&Location=" + location + "&MovieID=" + movieId + secureParam);
		//myListFrame.src = test;
		
		myListFrame.contentWindow.location.replace (test);
	}
}


function iTalkiesAddOnClick (location, movieId, movieDVDAvailability, movieAvailabilitySpecialNotification, fromSubLevelFrame)
{
	var myListFrameElement = null;
	
	var proceed = true;
	switch (movieDVDAvailability)
	{
		case "":
			proceed = window.confirm ("No DVD release information for this title is available at the moment. We do not know if it will be released on DVD or not. Please check to see if this title is available on other medias (e.g. VCD or Streaming downloads)\n\nYou can add it to your list to reserve a copy if and when it releases on DVD and to let us know you wish to watch this title as soon as it releases on DVD. Adding it to your list also lets us communicate the demand for this title to our suppliers and can help in expediting the release of the title on DVD. \n\nContinue adding this title to your list?");
			break;
		case "Not Yet Released On DVD":
		case "Not Yet Released On Media":
			proceed = window.confirm ("This title has not yet been released on the specified media and the wait time on it is unpredictable. \n\nYou can add it to your list to reserve a copy and to let us know you wish to watch this title as soon as it releases on the specified media. Adding it to your list also lets us communicate the demand for this title to our suppliers and can help in expediting the release of the title on the specified media. \n\nContinue adding this title to your list?");
			break;
		case "Out Of Stock":
			proceed = window.confirm ("The DVD for this title is not in ready supply. We will attempt to acquire the DVD thought the wait time will be unpredictable. \n\nWe recommend you add this title to your list to let us know you wish to watch this title as soon as possible. Adding it to your list lets us communicate the demand for this title to the manufacturers so that they know to produce additional copies of this DVD. \n\nContinue adding this title to your list?");
			break;
		case "Defective Supply":
			proceed = window.confirm ("All DVDs for this title in supply have manufacturing defects that prohibits them from playing reliably on most DVD players.  We have decided not to rent this title out until a good print is available. \n\nYou can add this title to your list to let us know you wish to watch this title as soon as a good print is available. Adding it to your list also lets us communicate the demand for this film to our suppliers so that they know to re-release this title on DVD with all issues fixed. \n\nContinue adding this title to your list?");
			break;
		case "Special Requirements":
			proceed = window.confirm ("The following special notification was associated with this movie:\n\n" + movieAvailabilitySpecialNotification + "\n\nBased on this note do you want to continue adding this title to your list?");
		case "Available":
			// do nothing
			break;
	}

	if (!proceed)
	{
		return false;
	}
	
	if (movieId == null)
	{
		movieId = window.document.getElementById ("MovieIDInp").value;
	}
	
//	if (window.parent == window)
//	{
//		try
//		{
//			if (window && window.opener && window.opener.parent && window.opener.parent.document)
//			{
//				myListFrameElement = window.opener.parent.document.getElementById ("MyListFrame");
//				if (myListFrameElement == null)
//				{
//					if (window.opener.parent.parent)
//					{
//						myListFrameElement = window.opener.parent.parent.document.getElementById ("MyListFrame");
//					}
//				}
//			}
//		}
//		catch (e)
//		{
//			if (ie) 
//				if (e.number != -2147024891)
//					throw e;
//		}			
//	}
//	else if (fromSubLevelFrame)
//	{
//		myListFrameElement = window.parent.parent.document.getElementById ("MyListFrame");
//	}
//	else
//	{
//		myListFrameElement = window.parent.document.getElementById ("MyListFrame");
//	}
//	
//	var basePage = "secure/MyList.aspx";
//	
//	if (myListFrameElement != null)
//	{
//		myListFrameElement.src = basePage + "?Action=Add&Location=" + location + "&MovieID=" + movieId;
//	}
//	else
//	{
//		// find the hidden frame in this window itself that allows me to send updates to MyList.
//		window.document.getElementById ("HiddenMyListFrame").src = 
//						basePage + "?Action=Add&Location=" + location + "&MovieID=" + movieId;
//		window.document.location.reload();
//	}
	
	iTalkiesUpdateMyList ("Add", location, movieId);
}

function MyListReplaceQueryStrings(action, movieId, actionOptionalParam)
{
	var searchPath = window.location.search;
	if ((searchPath != "") && (searchPath != null))
	{
		var tempHref = searchPath;
		
		// Remove any existing Action parameters and their optional parameters
		var re = /&?Action=[^&$]*/ig;
		tempHref = tempHref.replace (re, "");
		
		re = /&?ActionParam=[^&$]*/ig;
		tempHref = tempHref.replace (re, "");
		
		// Remove any existing MovieID parameters
		re = /&?MovieID=[^&$]*/ig;
		tempHref = tempHref.replace (re, "");
		
		// Remove any existing UpdateRating parameters
		re = /&?UpdateRating=[^&$]*/ig;
		tempHref = tempHref.replace (re, "");
		
		if (actionOptionalParam != null)
		{
			window.location.search = tempHref + "&Action=" + action + "&ActionParam=" + actionOptionalParam + "&MovieID=" + movieId
		}
		else
		{
			window.location.search = tempHref + "&Action=" + action + "&MovieID=" + movieId
		}
	}
	else
	{
		if (actionOptionalParam != null)
		{
			window.location.search = "Action=" + action + "&ActionParam=" + actionOptionalParam + "&MovieID=" + movieId
		}
		else
		{
			window.location.search = "Action=" + action + "&MovieID=" + movieId;
		}
	}
}


function iTalkiesRemoveOnClick (movieId, waitTime)
{
	if (waitTime == 'Shipping')
	{
		alert ("This item is being shipped and cannot be deleted at this time");
		return;
	}
	iTalkiesUpdateMyList ("Remove", "", movieId);
//	MyListReplaceQueryStrings ("Remove", movieId);
}

function iTalkiesMoveTopOnClick (movieId)
{
	iTalkiesUpdateMyList ("MoveTop", "", movieId);
//	MyListReplaceQueryStrings ("MoveTop", movieId);
}

function iTalkiesMoveBottomOnClick (movieId)
{
	iTalkiesUpdateMyList ("MoveBottom", "", movieId);
//	MyListReplaceQueryStrings ("MoveBottom", movieId);
}

function iTalkiesMoviePriorityOnKeyUpValidate (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	// let all keys other than alphanumeric keys pass thru
	if (normalizedEvent.keyCode == 13)
	{
		iTalkiesCheckIfMoviePriorityChanged (e);
		return;
	}
	
	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;
	
	var re = /^\d{0,3}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		normalizedEvent.returnValue = false;
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		iTalkiesIssueMissTypedWarning (srcElement);
		return false;
	}
}

function iTalkiesCheckIfMoviePriorityChanged (e)
{
	var srcElement;
	var normalizedEvent;

	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (srcElement.value != srcElement.getAttribute ("originalvalue"))
	{
		// ensure that the user can only enter numbers
		iTalkiesUpdateMyList ("ChangePri", srcElement.value, srcElement.getAttribute ("movieid"));
//		MyListReplaceQueryStrings ("ChangePri", srcElement.getAttribute ("movieid"), srcElement.value);
	}
}

function iTalkiesMovieControlOnMouseOver(srcElement)
{
//	if (hasUserCookie)
//	{
		var movieActions = iTFindAll (srcElement, "MovieActions");
		if (movieActions != null)
		{
			if (!safari) 
			{
				movieActions.className = "ITalkiesMovieControlActions1";
			}
			else 
			{
				movieActions.className = "ITalkiesMovieControlActions1Safari"
			}
			iTFindAll (movieActions, "MovieActionsCell").style.backgroundColor = "#888888";
		}
		movieActions = iTFindAll (srcElement, "MovieActions2");
		if (movieActions != null)
		{
			if (!safari) 
			{
				movieActions.className = "ITalkiesMovieControlActions1";
			}
			else 
			{
				movieActions.className = "ITalkiesMovieControlActions1Safari"
			}
			iTFindAll (movieActions, "MovieActionsCell2").style.backgroundColor = "#888888";
		}
//	}
//	else
//	{
//		var movieActions = iTFindAll (srcElement, "MovieActions");
//		if (movieActions != null)
//		{
//			movieActions.style.display = "none";
//		}
//		movieActions = iTFindAll (srcElement, "MovieActions2");
//		if (movieActions != null)
//		{
//			movieActions.style.display = "none";
//		}
//	}
	
	// Lastly - set the background of the table so that the user knows which
	// movie they are hovering over!
	var movieDetails = iTFindAll (srcElement, "MovieDetails");
	movieDetails.style.backgroundColor = "#a9a9a9";
	if (!safari) movieDetails.style.borderColor = "#666666";
	
	var movieTitle = iTFindAll (srcElement, "MovieTitle");
	if (movieTitle != null)
	{
		movieTitle.style.backgroundColor = "#666666";
		var titleId = iTFindAll (movieTitle, "MovieTitleId");
		if (titleId == null)
		{
			titleId = iTFindAll (movieTitle, "MovieRecommendation_MovieTitleId");
		}
		if (titleId != null)
		{
			titleId.style.color = "#ffffff";
		}
	}
}

function iTalkiesMovieControlOnMouseOut (srcElement)
{
//	if (hasUserCookie)
//	{
		var movieActions = iTFindAll (srcElement, "MovieActions");
		if (movieActions != null)
		{
			movieActions.className = "ITalkiesMovieControlActions1Hider";
			iTFindAll (movieActions, "MovieActionsCell").style.backgroundColor = "#cccccc";
		}
		movieActions = iTFindAll (srcElement, "MovieActions2");
		if (movieActions != null)
		{
			movieActions.className = "ITalkiesMovieControlActions1Hider";
			iTFindAll (movieActions, "MovieActionsCell2").style.backgroundColor = "#cccccc";
		}
//	}
	
	// Lastly - set the background of the table back to normal
	var movieDetails = iTFindAll (srcElement, "MovieDetails");
	movieDetails.style.backgroundColor = "";
	if (!safari) movieDetails.style.borderColor = "#cccccc";

	var movieTitle = iTFindAll (srcElement, "MovieTitle");
	if (movieTitle != null)
	{
		movieTitle.style.backgroundColor = "";
		var titleId = iTFindAll (movieTitle, "MovieTitleId");
		if (titleId == null)
		{
			titleId = iTFindAll (movieTitle, "MovieRecommendation_MovieTitleId");
		}
		if (titleId != null)
		{
			titleId.style.color = "#404040";
		}
	}
}


function iTalkiesMovieControlOnMouseOverCompact(srcElement)
{
	// Lastly - set the background of the table so that the user knows which
	// movie they are hovering over!
//	var movieDetails = iTFindAll (srcElement, "MovieDetails");
//	movieDetails.style.backgroundColor = "#a9a9a9";
//	if (!safari) movieDetails.style.borderColor = "#666666";
	
	var movieTitle = iTFindAll (srcElement, "MovieTitle");
	movieTitle.style.backgroundColor = "#666666";
	var titleId = iTFindAll (movieTitle, "MovieTitleId");
	if (titleId == null)
	{
		titleId = iTFindAll (movieTitle, "MovieRecommendation_MovieTitleId");
	}
	if (titleId != null)
	{
		titleId.style.color = "#ffffff";
	}
}

function iTalkiesMovieControlOnMouseOutCompact (srcElement)
{
	// Lastly - set the background of the table back to normal
//	var movieDetails = iTFindAll (srcElement, "MovieDetails");
//	movieDetails.style.backgroundColor = "";
//	if (!safari) movieDetails.style.borderColor = "#cccccc";

	var movieTitle = iTFindAll (srcElement, "MovieTitle");
	movieTitle.style.backgroundColor = "";
	var titleId = iTFindAll (movieTitle, "MovieTitleId");
	if (titleId == null)
	{
		titleId = iTFindAll (movieTitle, "MovieRecommendation_MovieTitleId");
	}
	if (titleId != null)
	{
		titleId.style.color = "#404040";
	}
}


function iTalkiesMovieControlCompactViewActionsOnMouseOver(srcElement, x, y, imageFileName, adjustXCoordForMoz, adjustYCoordForMoz)
{
	var movieActionsHoverImage = iTFindAll (srcElement, "MovieActionHoverImage");
	if (movieActionsHoverImage != null)
	{
		movieActionsHoverImage.src = imageFileName;
		if (!safari) 
		{
			movieActionsHoverImage.style.border = "1px solid #444444";
		}
	}
	
	var movieActions = iTFindAll (srcElement, "MovieActionsSpan");
	if (movieActions != null)
	{
		var xAdjustment = 0, yAdjustment = 0;
		
		if (moz)
		{
			if (adjustXCoordForMoz)
				xAdjustment = adjustXCoordForMoz;
			if (adjustYCoordForMoz)
				yAdjustment = adjustYCoordForMoz;
		}

		iTalkiesOffsetElement (movieActions, movieActionsHoverImage, x + xAdjustment, y + yAdjustment);

		if (!safari) 
		{
			movieActions.className = "ITalkiesMovieControlActions1Compact";
		}
		else 
		{
			movieActions.className = "ITalkiesMovieControlActions1CompactSafari"
		}
		var mac = iTFindAll (movieActions, "MovieActionsCell");
		if (mac)
			mac.style.backgroundColor = "#888888";
		mac = iTFindAll (movieActions, "MovieActionsCell2");
		if (mac)
			mac.style.backgroundColor = "#888888";
	}
}

function iTalkiesMovieControlCompactViewActionsOnMouseOut (srcElement, imageFileName)
{
	var movieActionsHoverImage = iTFindAll (srcElement, "MovieActionHoverImage");
	if (movieActionsHoverImage != null)
	{
		movieActionsHoverImage.src = imageFileName;
		movieActionsHoverImage.style.border = "1px solid #cccccc";
	}
	
	var movieActions = iTFindAll (srcElement, "MovieActionsSpan");
	if (movieActions != null)
	{
		movieActions.className = "ITalkiesMovieControlActions1CompactHider";
		var mac = iTFindAll (movieActions, "MovieActionsCell");
		if (mac)
			mac.style.backgroundColor = "#cccccc";
		mac = iTFindAll (movieActions, "MovieActionsCell2");
		if (mac)
			mac.style.backgroundColor = "#cccccc";
		movieActions.style.top = 0;
		movieActions.style.left = 0;
	}
}


function iTalkiesMovieTopImageOnMouseOver (srcElement)
{
	srcElement.src = imageLocation + "/site/TopSelect.gif";
}

function iTalkiesMovieTopImageOnMouseOut (srcElement)
{
	srcElement.src = imageLocation + "/site/TopSimple.gif";
}

function iTalkiesMovieBottomImageOnMouseOver (srcElement)
{
	srcElement.src = imageLocation + "/site/BottomSelect.gif";
}

function iTalkiesMovieBottomImageOnMouseOut (srcElement)
{
	srcElement.src = imageLocation + "/site/BottomSimple.gif";
}

function iTalkiesMovieTopCompactImageOnMouseOver (srcElement)
{
	srcElement.src = imageLocation + "/site/TopCompactSelect.gif";
}

function iTalkiesMovieTopCompactImageOnMouseOut (srcElement)
{
	srcElement.src = imageLocation + "/site/TopCompactSimple.gif";
}

function iTalkiesMovieBottomCompactImageOnMouseOver (srcElement)
{
	srcElement.src = imageLocation + "/site/BottomCompactSelect.gif";
}

function iTalkiesMovieBottomCompactImageOnMouseOut (srcElement)
{
	srcElement.src = imageLocation + "/site/BottomCompactSimple.gif";
}

function iTalkiesMovieDeleteImageOnMouseOver (srcElement)
{
	srcElement.src = imageLocation + "/site/DeleteSelect.gif";
}

function iTalkiesMovieDeleteImageOnMouseOut (srcElement)
{
	srcElement.src = imageLocation + "/site/DeleteSimple.gif";
}

