﻿//  Public Site Helper Scripts
// (c) 2008 MRI
//

var iNextScriptID = 0;
var iMID = 0;
var sNextParam = "";
var MRI_URL = "/mri.aspx";
var oMRITimout = null;
var iMRITimout = 60000;
var sMRITimoutMessage = "The server seems to be busy.\n\nDo you wish to refresh the page?";
var sDialogParent = "DIALOGPARENT";
var sFixedDialogParent = "FIXEDDIALOGPARENT";
var sSearchClass = "";
var sNavColor = "#754F00";
var sNavBackground = "#EFEFEF";
var iCurrentShareIndex = 0;
var dDVDWeekendDate = 'never';
var iGenCount = 0;
var sLastOngoingColor = "";

var pMRITimeoutProc = onMRITimeoutProc;

var oDiv = document.createElement('div');
oDiv.id = 'CALENDARDIV';
oDiv.name = 'CALENDARDIV';
oDiv.style.x = 0;
oDiv.style.y = 0;
oDiv.style.position = 'absolute';
oDiv.style.visibility = 'hidden';

function DrawCalendar(sTargetControl,sDateControl,sIgnoreControl,iSingle,bFuture) {
	sCurrentControl    = sTargetControl;
	sDateListControl   = sDateControl;
	sIgnoreListControl = sIgnoreControl;
	oParentControl     = document.getElementById(sTargetControl);
	oParentControl.appendChild(oDiv);	

	var sCal = GetCalendarMonth(GetDateString(dCurrentDate),sDateControl,sIgnoreControl,'CalTable','CalHeader','CalCell','CalSelected','CalEmpty','CalIgnore',iSingle,bFuture);

// function GetCalendarMonth(dtStr,sDateControl,sIgnoreControl,sTableClass,sDayHeaderClass,sCellClass,sSelectedClass,sEmptyClass,sIgnoreClass,iSingle,bFuture) 

	document.getElementById('CALENDARDIV').innerHTML = sCal;
	//document.getElementById('DEBUG').value = sCal;
}

function onCalendarClick(dtStr,iIndex,iSingle,bFuture) {
	dCurrentDate = new Date(dtStr);
	DrawCalendar(sCurrentControl,sDateListControl,sIgnoreListControl,iSingle,bFuture);
}

function onCalendarClose() {
    oDiv.style.visibility = 'hidden';
    SetFocus(sCurrentControl);

}

function onCalendarCellClick(sDate,iSingle,bFuture) {
	var sDates  = document.getElementById(sDateListControl).value;
	var aDates  = DecodeDelimittedList(sDates,",");
	var sIgnore = document.getElementById(sIgnoreListControl).value;
	var aIgnore = DecodeDelimittedList(sIgnore,",");
	var	iIndex  = FindCalendarDate(sDate,aIgnore);

	if (iIndex == -1) {
		iIndex = FindCalendarDate(sDate,aDates);
	
		if (iIndex > -1) {
			aDates.splice(iIndex,1);
		} else {
			aDates[aDates.length] = sDate;
		}

		if (iSingle == 1) {
			document.getElementById(sDateListControl).value = sDate;
		} else {
			document.getElementById(sDateListControl).value = aDates.toString();
		}	
		
		DrawCalendar(sCurrentControl,sDateListControl,sIgnoreListControl,iSingle,bFuture);
	}	
	
	onCalendarClose();
}

function onCalendarOpen(sName,sDateControl,sIgnoreControl,iSingle,bFuture) {
	if (document.getElementById(sDateControl).value != "") dCurrentDate = new Date(document.getElementById(sDateControl).value);
	oDiv.style.visibility = 'visible';	
	DrawCalendar(sName,sDateControl,sIgnoreControl,iSingle,bFuture);
}

function LoadMRIContent(sParams,pProcessProc,pTimeoutProc,iMID) {
    pProcessContent = pProcessProc;
    
    if (pTimeoutProc != null) pMRITimoutProc = pTimoutProc;
    
    oMRITimeout = setTimeout(pMRITimeoutProc,iMRITimout);
    LoadContent(MRI_URL + "?MID=" + iMID + sParams,"",true);
}

function onMRITimeoutProc() {
    clearTimeout(oMRITimeout);
    if (confirm(sMRITimoutMessage) == true) window.location.reload();
}

function ClearMRITimeout() {
    clearTimeout(oMRITimeout);
}

function OnExitPublicSite(sAnchor) {
    var oID = document.getElementById("HiddenID");
    var sParam = "";
            
    if (oID != null) {
        sParam = "?ID=" + oID.value + "&MID=" + iMID
        
        if (iNextScriptID > 0) sParam = sParam + "&NID=" + iNextScriptID;
    } else {
        sParam = "?MID=" + iMID
        
        if (iNextScriptID > 0) sParam = sParam + "&NID=" + iNextScriptID;
    }

    if (GetValue("RELEASEID") != "") sParm = sParam + "&RID=" + GetValue("RELEASEID");

    window.location = "/mri.aspx" + sParam + sNextParam + siif((sAnchor == ""),"","#"+sAnchor)
}

function SearchAheadMain(oEvent,oControl,sAnchor,sID,sName,iAID) {
    iSALocus = 2;
    return SearchAhead(oEvent,oControl,sAnchor,sID,sName,iAID);
}

function OnSurveyVote() {
    var i;
    var oControl;
    var oID;
    var bFound = false;

    iNextScriptID = GetValue("THANKYOUID");
    iMID = 1;
    
    for (i=0;i<50;i++) {
        oControl = document.getElementById("SURVEY" + i);
        
        if (oControl == null) break;
        else {
            oID = document.getElementById("SRID" + i);
            
            if (oID == null) break;
            else {
                if (oControl.checked) {
                    sNextParam = "&SID=" + oID.value;
                    bFound = true;
                    break;
                }
            }       
        }
    }
    
    if (bFound == true) OnExitPublicSite("SURVEYANCHOR");
    else alert("Please select one of the possible choices.");
}

function OnVoteClick() {
    var oTable = document.getElementById("SURVEYVOTE");
    
    if (oTable != null) oTable.style.display = "block";
}

function SetBusyMessage(sControl,sMessage) {
    SetSpanString(sControl,"<table border='0' cellpadding='0' cellspacing='0'><tr>" + 
            "<td valign='top'><img src='/images/mribusy.gif' hspace='5'></td>" +
            "<td class='mribusy' align='left' valign='top'>" + sMessage + "</td></tr></table>");
}

function onCurrentMarketMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#333333";
    oControl.style.cursor = "pointer";
}

function onCurrentMarketMouseOut(oControl) {
    oControl.style.color = "";
    oControl.style.backgroundColor = "";
}

function onCurrentMarketClick(oControl, iNID, iMID, iRID) {
    if (iRID == 0) {
        window.location = "/#EDITORNOTES";
    } else {
        window.location = "/mri.aspx?ID=" + GetSessionID() + "&NID=" + iNID +
                          "&MID=" + iMID + "&RID=" + iRID +
                          siif(iGenCount > 0, "&COUNT=" + iGenCount, "");
    }
}

function onDVDTitleClick(oControl, iNID, iMID, iRID) {
    if (iRID == 0) {
        window.location = "/#EDITORNOTES";
    } else {
        window.location = "/mri.aspx?ID=" + GetSessionID() + "&NID=" + iNID +
                      "&MID=" + iMID + "&RID=" + iRID + "&DVD=1";
    }
}

function onSearchResultsMouseOver(oControl, iID) {
    var oSpan;
    
    if (oControl != null) {
        sSearchClass = oControl.className;
        oControl.className = "float12brownover";
        oControl.style.cursor = "pointer";
    }
    
    for (i = 0; i < 7; i++) {
        oSpan = document.getElementById("COMPARE." + i + "." + iID);
        if (oSpan) oSpan.style.color = "#ffffff";
    }
    
    onCompareTitleMouseOver(iID);
}

function onSearchResultsMouseOut(oControl, iWide, iID) {
    if (oControl != null) oControl.className = sSearchClass;
    for (i = 0; i < 7; i++) {
        oSpan = document.getElementById("COMPARE." + i + "." + iID);
        if (oSpan) {
            if (iWide == "1") oSpan.style.color = "#0071C1";
            else oSpan.style.color = "#4B6026";
        } 
    }
    
    //onCompareTitleMouseOut(iID);
}

function onLinkMouseOver(oControl) {
    oControl.className = "taglineover";
    oControl.style.cursor = "pointer";
}

function onLinkMouseOut(oControl) {
    oControl.className = "tagline";
}

function onRustLinkMouseOver(oControl) {
    oControl.className = "taglinerustover";
    oControl.style.cursor = "pointer";
}

function onRustLinkMouseOut(oControl) {
    oControl.className = "taglinerust";
}

function onReportValueMouseOver(oControl) {
    oControl.className = "reportvalueover";
    oControl.style.cursor = "pointer";
}

function onReportValueMouseOut(oControl) {
    oControl.className = "reportvalue";
}

function onLetterIndexMouseOver(oControl) {
    oControl.className = "letterindexover";
    oControl.style.cursor = "pointer";
}

function onLetterIndexMouseOut(oControl) {
    oControl.className = "letterindex";
}

function onReportMouseOver(oControl) {
    oControl.className = "floatreportover";
    oControl.style.cursor = "pointer";
}

function onReportMouseOut(oControl) {
    oControl.className = "floatreport";
}

function onHeadlineMouseOver(oControl) {
    oControl.className = "floatheadlineover";
    oControl.style.cursor = "pointer";
}

function onHeadlineMouseOut(oControl) {
    oControl.className = "floatheadline";
}

function onTitleMouseOver(oControl) {
    oControl.className = "floattitleover";
    oControl.style.cursor = "pointer";
}

function onTitleMouseOut(oControl) {
    oControl.className = "floattitle";
}

function onFooterMouseOver(oControl) {
    oControl.className = "footerover";
    oControl.style.cursor = "pointer";
}

function onFooterMouseOut(oControl) {
    oControl.className = "footer";
}

function onShowTerms() {

}

function onShowContact() {

}

function onAdvertise() {

}

function onPublicButtonMouseOver(oControl) {
    oControl.className = "dialogbuttonover";
    oControl.style.cursor = "pointer";
}

function onPublicButtonMouseOut(oControl) {
    oControl.className = "dialogbutton";
}

function onNavMouseOver(oControl) {
    sNavColor = oControl.style.color;
    sNavBackground = oControl.style.backgroundColor;
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#81885C";
    oControl.style.cursor = "pointer";
}

function onNavMouseOut(oControl) {
    oControl.style.backgroundColor = sNavBackground;
    oControl.style.color = sNavColor;
}

function onReviewLinkMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#754F00";
    oControl.style.cursor = "pointer";
}

function onReviewLinkMouseOut(oControl) {
    oControl.style.backgroundColor = "#FFFFFF";
    oControl.style.color = "#754F00";
}

function onDVDHeaderLinkMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#754F00";
    oControl.style.cursor = "pointer";
}

function onDVDHeaderLinkMouseOut(oControl) {
    oControl.style.backgroundColor = "#FFFFFF";
    oControl.style.color = "#000000";
}

function onShare(iIndex) {
    var oParent = document.getElementById("SHAREPARENT" + iIndex);
    iCurrentShareIndex = iIndex;

    if (oParent != null) {
        SwapElement("SHAREDIALOG", "SHAREPARENT" + iIndex, true);
    }
}

function onCloseShare() {
    var oParent = document.getElementById("SHAREPARENT" + iCurrentShareIndex);

    if (oParent != null) {
        SwapElement("SHAREDIALOG", "SHAREPARENT", false);
    }
}

function CountGenerator(iGenValueID, iReleaseID) {
    var sURL = "/mri.aspx?MID=16&NID=" + iGenValueID + "&RID=" + iReleaseID;
    pProcessContent = null;
    LoadContent(sURL, "", true);
}

function onMenuItemMouseOver(oControl) {
    if (oControl == null) return;
    oControl.style.color = "#c5a086";
    oControl.style.cursor = 'pointer';

    // if (oControl.id == "MENU7") SetImageSrc("URSLUG", "/Images/contentsluguraover.gif");
}

function onMenuItemMouseOut(oControl) {
    if (oControl == null) return;

    var iGenValueID = parseInt(GetValue("GENVALUEID"));
    var sMenuID = GetMenuIDFromGenID(iGenValueID);

    if (("MENU" + sMenuID) != oControl.id) {
        oControl.style.color = "";
        oControl.style.backgroundColor = "";
        oControl.style.fontWeight = "";
    }
    
    //if ((oControl.id == "MENU7") && (sMenuID != "7")) SetImageSrc("URSLUG", "/Images/contentslugura.png");
}

function onMainMenuItemMouseOver(sControl) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = "#c5a086";
    oControl.style.cursor = 'pointer';
}

function onMainMenuItemMouseOut(sControl) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = "";
}

function onMainMarketMouseOver(sControl) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = "#ffffff";
    oControl.style.cursor = 'pointer';
}

function onMainMarketMouseOut(sControl) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = "#000000";
}

function onMenuItemClick(iIndex, sLink) {
    var sURL = "/publish.aspx?BID=" + iIndex;

    if (sLink != null) {
        if (sLink != "") {
            sURL = "/movie-reviews/" + sLink + "/";
        } else {
            if (parseInt(iIndex) == 0) sURL = "/";
        }
    } else {
        if (parseInt(iIndex) == 0) sURL = "/";
    }
    
    window.location = sURL;
}

function GetMenuIDFromGenID(iGenID) {
    if (iGenID == 2) return "0";
    else if (iGenID == 4) return "1";
    else if (iGenID == 6) return "2";
    else if (iGenID == 9) return "3";
    else if (iGenID == 8) return "4";
    else if (iGenID == 7) return "5";
    else if (iGenID == 19) return "6";
    else if (iGenID == 10) return "7";
    else return "";
}

function onLoadMenu() {
    var iGenValueID = parseInt(GetValue("GENVALUEID"));
    var sMenuID = GetMenuIDFromGenID(iGenValueID);

    if (sMenuID != "") {
        oControl = document.getElementById("MENU" + sMenuID);
        oControl.style.color = "#c5a086";
        //oControl.style.backgroundColor = "#AEAEAE";
        //oControl.style.fontWeight = "bold";
        //if (sMenuID == "7") SetImageSrc("URSLUG", "/Images/contentsluguraover.gif");
    }
}

function onLimitedMouseOver(oControl) {
    if (oControl != null) {
        oControl.style.color = "#FFFFFF";
        oControl.style.backgroundColor = "#8a400c";
    }
}

function onLimitedMouseOut(oControl) {
    if (oControl != null) {
        oControl.style.color = "#8a400c";
        oControl.style.backgroundColor = "";
    }
}

function onPressRoomBoxMouseOver(oControl) {
    oControl.style.backgroundColor = "#333333";
    oControl.style.color = "#FFFFFF";
    oControl.style.cursor = 'pointer';
}

function onPressRoomBoxMouseOut(oControl) {
    oControl.style.backgroundColor = "";
    oControl.style.color = "#000000";
}

function onPressRoomBoxClick(iGenID) {
    window.location = "/movie-reviews/press_kit/";
}

function onOngoingMouseOver(oControl, iTag) {
    var sTag = siif((iTag == "0"), "wide", "limited");

    oControl.className = "floatreport" + sTag + "over";
    oControl.style.cursor = "pointer";
    //if (oControl.childNodes[0].childNodes[0].childNodes.length > 0) oControl.childNodes[0].childNodes[0].childNodes[0].style.color = "#FFFFFF";
}

function onOngoingMouseOut(oControl, iTag) {
    var sTag = siif((iTag == "0"), "wide", "limited");
    oControl.className = "floatreport" + sTag;
    //if (oControl.childNodes[0].childNodes[0].childNodes.length > 0) oControl.childNodes[0].childNodes[0].childNodes[0].style.color = "";
}

function onMainOngoingMouseOver(sControl, sColor) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    sLastOngoingColor = sColor;
    oControl.style.color = "#FFFFFF";
}

function onMainOngoingMouseOut(sControl) {
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = sLastOngoingColor;
}

function onMainOpeningSoonMouseOver(oTD, sTag, sControl, sColor) {
    oTD.className = "floatreport" + sTag + "over";
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    sLastOngoingColor = sColor;
    oControl.style.color = "#FFFFFF";
}

function onMainOpeningSoonMouseOut(oTD, sTag, sControl) {
    oTD.className = "floatreport" + sTag;
    var oControl = document.getElementById(sControl);
    if (oControl == null) return;
    oControl.style.color = sLastOngoingColor;
}


function onOngoingClick(oControl, iNID, iMID, sRID, iRID) {
    //window.location = "/mri.aspx?NID=" + iNID + "&MID=" + iMID + "&RID=" + iRID + "&COUNT=39";
}

function onDVDTitleMouseOver(sControl) {
    var oControl = document.getElementById("DVD" + sControl);
    if (oControl == null) return;
    oControl.style.color = "#FFFFFF";
}

function onDVDTitleMouseOut(sControl) {
    var oControl = document.getElementById("DVD" + sControl);
    if (oControl == null) return;
    oControl.style.color = "#000000";
}

function onCompareTitleMouseOver(sControl) {
    var oControl = document.getElementById("COMPARE" + sControl);
    if (oControl == null) return;
    oControl.style.color = "#FFFFFF";
}

function onCompareTitleMouseOut(sControl) {
    var oControl = document.getElementById("COMPARE" + sControl);
    if (oControl == null) return;
    oControl.style.color = "#754F00";
}


function onColumnHeaderMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#754F00";
    oControl.style.cursor = "pointer";
}

function onColumnHeaderMouseOut(oControl) {
    oControl.style.color = "#754F00";
    oControl.style.backgroundColor = "#FFFFFF";
}

function onReportResultsMouseOver(oControl, iID) {
    if (oControl != null) {
        sSearchClass = oControl.className;
        oControl.className = "float10brownover";
        oControl.style.cursor = "pointer";
    }

    onCompareTitleMouseOver(iID);
}

function onReportResultsMouseOut(oControl, iID) {
    if (oControl != null) oControl.className = sSearchClass;
    onCompareTitleMouseOut(iID);
}

function onReportNavMouseOver(oControl) {
    sSearchClass = oControl.className;
    oControl.className = "menuitemdbover";
    oControl.style.cursor = "pointer";
}

function onReviewsLinkMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#8a400c";
    oControl.style.cursor = "pointer";
}

function onReviewsLinkMouseOut(oControl) {
    oControl.style.color = "#8a400c";
    oControl.style.backgroundColor = "#FFFFFF";
}

function onDVDBuyMouseOver(oControl) {
    oControl.style.color = "#FFFFFF";
    oControl.style.backgroundColor = "#000080";
    oControl.style.cursor = "pointer";
}

function onDVDBuyMouseOut(oControl) {
    oControl.style.color = "#000080";
    oControl.style.backgroundColor = "#FFFFFF";
}

function onAppTextOver() {
    SetImageSrc("IMGAPPTEXT", "/Images/apptextover.jpg");
}

function onAppTextOut() {
    SetImageSrc("IMGAPPTEXT", "/Images/apptext.png");
}
