﻿
var popupsmrtsrchObj="";
function funloginclear(obj)
{
    if(obj.value == "Login")
    {
    window.document.getElementById(obj.id).value = "";
    }
}

function funValidateUser()
{
//    window.document.getElementById("txtUserName").value = Trim(window.document.getElementById("txtUserName").value);
//    window.document.getElementById("txtPassword").value = Trim(window.document.getElementById("txtPassword").value);
//  
    var vardate = new Date();  
    if (Trim1(window.document.getElementById("ctl00_ctl00_Login1_txtUserName")) == "" || Trim1(window.document.getElementById("ctl00_ctl00_Login1_txtUserName")) == "Login")
    {
	    ////window.document.getElementById("ctl00_ctl00_Login1_lblMessage").innerHTML="Please enter Username";
	    //window.document.getElementById("ctl00_ctl00_Login1_txtUserName").focus();
	    funBuildAlterMsg("Please enter Username", "OK");
        toggleVis('saveSearchDialog');
	    return false;
    }
    if(window.document.getElementById("ctl00_ctl00_Login1_txtPassword"))
    {
         if (Trim1(window.document.getElementById("ctl00_ctl00_Login1_txtPassword"))== "")
        {
	        ////window.document.getElementById("ctl00_ctl00_Login1_lblMessage").innerHTML="Please enter Password";
	        //window.document.getElementById("ctl00_ctl00_Login1_txtPassword").focus();
    	    funBuildAlterMsg("Please enter Password", "OK");
            toggleVis('saveSearchDialog');
	        return false;
        }
        ////window.document.getElementById("ctl00_ctl00_Login1_lblMessage").innerHTML="&nbsp;";
        //return true;   
        
        window.document.body.style.cursor = "wait";
        // Added for showing Loading wait.. Message.
        //toggleVis('divProgressDialog');
        
        var password = window.document.getElementById("ctl00_ctl00_Login1_txtPassword").value;
        var username = window.document.getElementById("ctl00_ctl00_Login1_txtUserName").value;
        
        var OSType = funGetOperatingSystem();
        //var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","UserName="+ username + "~@$~"+ vardate + "&Password="+ password +"&Type=login&OSType=" + OSType);
        PageMethods.funSubmitClick(username, password, OSType, OnSucceeded, OnFailed);
       
//        strResult = strResult.substring(0,strResult.length-2);
//        var strValues = strResult.split('~#~#');
//        //var strValues = strResult.split('~');
//         if(Trim2(strValues[0]) == "validuser")
//         {
//            //Added by Anil on 03.03.2009 for getting system info for entrique functionality.                
////            funGetSystemInfo(); 
////            toggleVis('divProgressDialog'); 
////            NavAsPerUserPreferences(strResult);
//            
//            var supAdminName =escape(strValues[1]);
//            var userName = escape(strValues[2]);
//            if(strValues[3] && Trim2(strValues[3]) == "Y")
//            {
//                funBuildConfirmationMsgWithAction("There is another session that is already active with this ID. For security reasons, only one session per login is allowed.  Do you want to terminate the other session and proceed with this login or do you want to cancel?  Click 'OK' to terminate the other session. Click 'Cancel' to end this attempt.  If additional IDs for FoxFast are needed, please contact us at foxfast@fox.com.", 
//                                        "OK", "Cancel", "funShowAgreeTermsConditions(\""+supAdminName+"\",\""+userName+"\")", "funCancelLogin()");
//                toggleVis('saveSearchDialog'); 
//            }
//            else
//            {
//                
//                funBuildTermsConditionButton("funAgreeTermsConditions(\""+supAdminName+"\",\""+userName+"\")");
//                var bhvPopupCntrExt = $find("bhvModalPopupExtender1");
//                bhvPopupCntrExt.show();
//                
//                if(strValues[4] && Trim2(strValues[4]) == "Y")
//                {
//                    var varScrolHeight = 0;
//                    if($.browser.msie)
//                      varScrolHeight = 1650;
//                    else
//                        varScrolHeight = 1760;

//                    $("#ctl00_ctl00_divTermsContent").animate({scrollTop:varScrolHeight}, 100);
//                    
//                    /* reference code:
//                    if($.browser.mozilla)
//                      varScrolHeight = 1760;
//                    else if($.msie)
//                      varScrolHeight = 1650;
//                    else if($.browser.opera)
//                      varScrolHeight = 1760;
//                    else if($.browser.safari)
//                      varScrolHeight = 1760;*/
//                }
//            }
//        }
//        else
//        {
//            //toggleVis('divProgressDialog');
//            //alert(Trim2(strResult));
//            funBuildAlterMsgWithAction(Trim2(strResult), "OK", "funClearPassword()");
//            toggleVis('saveSearchDialog');
//        }
    }
    
    window.document.body.style.cursor = "default";
}
function OnSucceeded(strResult) {

    //strResult = strResult.substring(0,strResult.length-2);
    var strValues = strResult.split('~#~#');
    if (Trim2(strValues[0]) == "N") {
        funBuildAlterMsg("Sorry, the request to play this video was not designed for the login account you entered.  Please try again or contact foxtvdigital@fox.com for assistance.", "OK");
        toggleVis('saveSearchDialog');
    }
    else {
        if (Trim2(strValues[0]) == "validuser") {
            var supAdminName = strValues[1];
            var userName = strValues[2];
            if (strValues[3] && Trim2(strValues[3]) == "Y") {
                funBuildConfirmationMsgWithAction("There is another session that is already active with this ID. For security reasons, only one session per login is allowed.  Do you want to terminate the other session and proceed with this login or do you want to cancel?  Click 'OK' to terminate the other session. Click 'Cancel' to end this attempt.  If additional IDs for FoxFast are needed, please contact us at foxfast@fox.com.",
                                    "OK", "Cancel", "funShowAgreeTermsConditions(\"" + supAdminName + "\",\"" + userName + "\")", "funCancelLogin()");
                toggleVis('divSoftwareUpdateAlterMsg');
            }
            else {

                funBuildTermsConditionButton("funAgreeTermsConditions(\"" + supAdminName + "\",\"" + userName + "\")");
                var bhvPopupCntrExt = $find("bhvModalPopupExtender1");
                bhvPopupCntrExt.show();

                if (strValues[4] && Trim2(strValues[4]) == "Y") {
                    var varScrolHeight = 0;
                    if ($.browser.msie)
                        varScrolHeight = 3120;
                    else
                        varScrolHeight = 3250;

                    $("#ctl00_ctl00_divTermsContent").animate({ scrollTop: varScrolHeight }, 100);
                }
                else {
                    var varScrollHeight = 0;
                    $("#ctl00_ctl00_divTermsContent").animate({ scrollTop: varScrollHeight }, 100);
                }
            }
        }
        else {
            funBuildAlterMsgWithAction(Trim2(strResult), "OK", "funClearPassword()");
            toggleVis('saveSearchDialog');
        }
    }
}

function OnFailed(error) {
    //If there is any exception give a user friendly message.

}

function funShowAgreeTermsConditions(supAdminName, userName)
{
    //toggleVis('saveSearchDialog');
    toggleVis('divSoftwareUpdateAlterMsg');
    funBuildTermsConditionButton("funAgreeTermsConditions(\""+supAdminName+"\",\""+userName+"\")");
    var bhvPopupCntrExt = $find("bhvModalPopupExtender1");
    bhvPopupCntrExt.show();
}
function funCancelLogin()
{
    toggleVis('divSoftwareUpdateAlterMsg');
    if(window.document.getElementById("ctl00_ctl00_Login1_txtUserName"))
    {
        window.document.getElementById("ctl00_ctl00_Login1_txtUserName").value = "";
    }
    if(window.document.getElementById("ctl00_ctl00_Login1_txtPassword"))
    {
        window.document.getElementById("ctl00_ctl00_Login1_txtPassword").value = "";
    }
}
function funAgreeTermsConditions(SuperAdmin, UserName)
{
    SuperAdmin = unescape(SuperAdmin);
    UserName = unescape(UserName);
    toggleVis('divProgressDialog'); 
    funDisAgreeTermsConditions();

    PageMethods.GetValidUserInfo(SuperAdmin, UserName, OnAgreeTermsConditionsSucceeded, OnAgreeTermsConditionsFailed);

    //    var vardate = new Date();  
//    var strInfo =  funGetHtmlFromJQuery("Xmlhttp.aspx","date="+vardate+"&SuperAdmin="+ SuperAdmin + "&UserName="+ UserName +"&Type=logininfo");  
//    strInfo = strInfo.substring(0,strInfo.length-2);
//    //Added by Anil on 03.03.2009 for getting system info for entrique functionality.                
//    funGetSystemInfo();  
//    // strResult =  validuser~Titlelist_Default_View~Search_Id~Search_Name; 
//    NavAsPerUserPreferences(strInfo);

//    if(window.document.getElementById("ctl00_ctl00_hdnSuperAdmin") != null)
//    {
//        window.document.getElementById("ctl00_ctl00_hdnSuperAdmin").value = SuperAdmin;
//    }
//    if(window.document.getElementById("ctl00_ctl00_hdnUserName") != null)
//    {
//        window.document.getElementById("ctl00_ctl00_hdnUserName").value = UserName;
//    }

    
//	window.document.forms[0].action = "TitleList.aspx";
//    window.document.forms[0].method = "post";
//    window.document.forms[0].__VIEWSTATE.name = "";
//    window.document.forms[0].submit();
}
function OnAgreeTermsConditionsSucceeded(strOutput) {
    if (strOutput != "") {
        funNavHomPageOnLogin(strOutput);
    }
    else {
        toggleVis('divProgressDialog'); 
    }
}
function OnAgreeTermsConditionsFailed(error) {
    //If there is any exception give a user friendly message.

}

function funDisAgreeTermsConditions()
{
    var bhvPopupCntrExt = $find("bhvModalPopupExtender1");
    bhvPopupCntrExt.hide();
    if(window.document.getElementById("ctl00_ctl00_Login1_txtUserName"))
    {
        window.document.getElementById("ctl00_ctl00_Login1_txtUserName").value = "";
    }
    if(window.document.getElementById("ctl00_ctl00_Login1_txtPassword"))
    {
        window.document.getElementById("ctl00_ctl00_Login1_txtPassword").value = "";
    }
}

function funClearPassword()
{
    window.document.getElementById("ctl00_ctl00_Login1_txtPassword").value="";
	//window.document.getElementById("ctl00_ctl00_Login1_txtUserName").value="";
	window.document.getElementById("ctl00_ctl00_Login1_txtUserName").focus();	
	
	toggleVis('saveSearchDialog');
}

function funGetHtmlFromJQuery(pageName, parameters)
{ 
    var html = $.ajax({
                 url: pageName,
                 data: parameters,                         
                 async: false
                }).responseText;
    html = html.replace(html.substring(html.indexOf("<!DOC")-4),"");        
    
    return html;
}

function funReset()
{
	window.document.getElementById("txtUserName").value="";
	window.document.getElementById("txtPassword").value="";
	window.document.getElementById("lblMessage").innerHTML="&nbsp;";
	window.document.getElementById("txtUserName").focus();	
	
	return false;			
}
function funCheckEnter(obj,objevent, disableYN)
{
    
	if (objevent.keyCode == 13)
	{
	    if(disableYN != "Y")
	    {
            //objevent.keyCode = 0;

            if(window.document.getElementById("ctl00_ctl00_Login1_txtUserName") && window.document.getElementById("ctl00_ctl00_Login1_txtUserName").value != "Login")
            {
                funValidateUser();
            }
            //Condition added for ForgotPassword page on 29-01-2009.
            else if(window.document.getElementById("txtEmailAddress"))
            { 
                funLoginHelpSubmit();
                objevent.keyCode = 0;
            }		
            else
            {
                if(window.document.getElementById("ctl00_ctl00_Login1_titleSearch") && window.document.getElementById("ctl00_ctl00_Login1_titleSearch").value != "Title Search")
                {
                    funGetSmartSearch('All Titles~A');
                }
                else if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName") && window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName").value.toLowerCase() == "advancedsearch")
                {
                    funAdvanceSearch();
                }
            }
        }
        else
        {
            if(window.document.getElementById("ctl00_ctl00_Login1_titleSearch") && window.document.getElementById("ctl00_ctl00_Login1_titleSearch").value != "Title Search")
            {
                funGetSmartSearch('All Titles~A');
            }
            else if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName") && window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName").value.toLowerCase() == "advancedsearch")
            {
                funAdvanceSearch();
            }
        }		
        return false;        	
	}	
}

function Trim1(obj)
{
	var firstIndex,lastIndex;
	var value = obj.value;
	firstIndex = 0;
	lastIndex = value.length;
	for(i=0;i<value.length;i++)
	if(value.charAt(i)==" ")
		firstIndex ++;
	else
		break;
	for(i=(value.length-1);i>=firstIndex;i--)
	if(value.charAt(i)==" ")
		lastIndex --;
	else
		break;
	return value.substring(firstIndex,lastIndex);
}
function Trim2(strValue)
{
	var firstIndex,lastIndex;
	var value = strValue;
	firstIndex = 0;
	lastIndex = value.length;
	for(i=0;i<value.length;i++)
	if(value.charAt(i)==" ")
		firstIndex ++;
	else
		break;
	for(i=(value.length-1);i>=firstIndex;i--)
	if(value.charAt(i)==" ")
		lastIndex --;
	else
		break;
	return value.substring(firstIndex,lastIndex);
}


/*Functions for Building Smart Search*/
function funShowPopup()
{
    var obj = document.getElementById("ctl00_ctl00_Login1_titleSearch");
    var txtValue = Trim(obj.value);
    if(obj && (txtValue == "Title Search" || txtValue == ""))
    {
        var bhvPopupCntrExt = $find("bhvPopupCntrExt");
        obj.value = "";
        bhvPopupCntrExt._popupBehavior.hide();
    }
    else
    {
        clearTimeout(popupsmrtsrchObj);    
        popupsmrtsrchObj=window.setTimeout("funShowPopup1()",1000);
    }
}
function funShowPopup1()
{
    window.document.getElementById("PopupDiv").innerHTML = "";
    var vardate = new Date();
    var bhvPopupCntrExt = $find("bhvPopupCntrExt");
    var chkScrRoom = "";
    if(window.document.getElementById("screeningRoom").checked)
    {
        chkScrRoom = "1";
    }
    else
    {
        chkScrRoom = "0";
    }    
    var strValue = Trim(window.document.getElementById("ctl00_ctl00_Login1_titleSearch").value);
    if(strValue.length > 1)
    {
        var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","TitleName="+ strValue + "~"+ vardate + "&Type=SmartSearch&Mode=" + chkScrRoom);
        strResult = Trim(strResult)
        if(strResult != "")
        {
            var strResultArr = strResult.split('###');
            window.document.getElementById("PopupDiv").innerHTML = strResultArr[0];
            if(window.document.getElementById("hdnTitleSearchMode") && strResultArr[1])
            {
                window.document.getElementById("hdnTitleSearchMode").value = strResultArr[1];
            }
            bhvPopupCntrExt._popupBehavior.show();
            
        }
        else
        {
            window.document.getElementById("PopupDiv").innerHTML = "&nbsp;";
            bhvPopupCntrExt._popupBehavior.hide();
        }
        
    }
    else
    {
        bhvPopupCntrExt._popupBehavior.hide();
    }
    
    //document.getElementById("ctl00_ctl00_Login1_titleSearch").value = strValue;
}
function SetValue(obj)
{
    window.document.getElementById("ctl00_ctl00_Login1_titleSearch").value = obj.id;
    var bhvPopupCntrExt = $find("bhvPopupCntrExt");
    bhvPopupCntrExt._popupBehavior.hide();
    
}
function funHidePopup()
{
    var bhvPopupCntrExt = $find("bhvPopupCntrExt");
    bhvPopupCntrExt._popupBehavior.hide();
    
}

function setSearchInput(obj, objevent)
{
    var txtValue = Trim(obj.value);
    if(objevent == "blur")
    {
        if(txtValue == "")
        {
            obj.value = "Title Search";
        }
    }
    else
    {
       if(txtValue == "Title Search" || txtValue == "")
       {
            var bhvPopupCntrExt = $find("bhvPopupCntrExt");
            bhvPopupCntrExt._popupBehavior.hide();
            obj.value = "";
       }
       else
       {
            funShowPopup();
       }
    }
}
function setSearchInputonFocus(obj, objevent)
{
    if( Trim(obj.value) == "Title Search")
    {
        obj.value = "";
    }
}

function funGetSmartSearch(condition)
{
    var strValue = window.document.getElementById("ctl00_ctl00_Login1_titleSearch").value;
    strValue = Trim(strValue);
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo") != null)
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
    }
    
    funPBTrends("","","","smartsearch","smartsearch - " + strValue,"","","","","");
    var chkScrRoom = "";
    if(window.document.getElementById("screeningRoom").checked)
    {        
        funNavScrRoomForSmartSearch('','SearchAll');
    }
    else
    {
        // Added for showing Loading wait.. Message.
        if(strValue != "" && strValue != "Title Search")
        {
            toggleVis('divProgressDialog');
            var type = condition.split('~');
            if(condition == "All Titles~A" || type[1] == "O")
            {
                // Function call to update the All Filter Option in Session_member_preference_type table when request for titles in this mode.
                funLeftFilter_SessionMemberPreference_Update('SS');
            }
        
            window.document.getElementById("hdnTitleSearchMode").value = condition;
            window.document.getElementById("hdnTitleSearchText").value = strValue;
            
            window.document.forms[0].action = "SearchResults.aspx";
            window.document.forms[0].method = "post";
            window.document.forms[0].__VIEWSTATE.name = "";
            window.document.forms[0].submit();
        }
    }

    return false;
}

//*Forgot Password Block*//
//function Trim(obj)
//{
//	var firstIndex,lastIndex;
//	var value = obj.value;
//	firstIndex = 0;
//	lastIndex = value.length;
//	for(i=0;i<value.length;i++)
//		if(value.charAt(i)==" ")
//			firstIndex ++;
//		else
//			break;
//	for(i=(value.length-1);i>=firstIndex;i--)
//		if(value.charAt(i)==" ")
//			lastIndex --;
//		else
//			break;
//	return value.substring(firstIndex,lastIndex);
//}

function funLoginHelpSubmit(objevent)
{	
	if (Trim(window.document.frmLoginHelp.txtEmailAddress.value) == '')
	{
		window.document.getElementById('lblMessage').innerHTML = 'Please Enter E-Mail Address';
		window.document.getElementById("txtEmailAddress").value="";
		window.document.getElementById("txtEmailAddress").focus();
	}
	else
	{
		window.document.getElementById('lblMessage').innerHTML = '&nbsp;';
		window.document.getElementById('hdnLoginHelpMode').value = "submit";
		window.document.forms[0].action = "LoginHelp.aspx";
        window.document.forms[0].method = "post";
        window.document.forms[0].__VIEWSTATE.name = "";
        window.document.forms[0].submit();
	}
}
//function funFoxFastLogoClick()
//{
//    //funLeftFilter_SessionMemberPreference_Update('MP');
//    window.location.href = "TitlesList.aspx";
//}

function funClearDownloadFlag()
{
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    var Mode = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMode");
    
    if(Mode && pageName && pageName.value == "AssetCart")
    {
        Mode.value = "";
    }
    if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTrendsDownloadYN")) {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTrendsDownloadYN").value = "N";
    }
}
function funChangePwdMode() {
    window.document.getElementById("hdnChangePwd").value = "change";
    window.document.forms[0].action = "UserPreferences.aspx";
    window.document.forms[0].method = "post";
    window.document.forms[0].__VIEWSTATE.name = "";
    window.document.forms[0].submit();
}

function funChangePwdNavigation(strvalue) {
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnChangePwdMode").value = strvalue;
    window.document.forms[0].action = "ChangePwd.aspx";
    window.document.forms[0].method = "post";
    window.document.forms[0].__VIEWSTATE.name = "";
    window.document.forms[0].submit();
}
function funEmail() {
    window.location = "mailto:FoxFast@fox.com";
    return true;
}



