﻿///To remove all the titles from the cart
function funEmptyTitleCart()
{
    funBuildConfirmationMsg("Are you sure you want to Empty Cart", "OK", "Cancel", "funEmptyTitleCart1()");
    toggleVis('saveSearchDialog');
}
function funEmptyTitleCart1()
{
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartMode").value = "emptytitlecart";
    window.document.forms[0].__VIEWSTATE.name= "";
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
    toggleVis('saveSearchDialog');
}
/////////////////////////////////////////////////////////////

///To remove a title from the cart
function funRemoveTitleFromCart(Id,TitleName,WprTitleId,TvdProductType)
{
    funBuildConfirmationMsg("Are you sure you want to Remove Title from Cart", "OK", "Cancel", "funRemoveTitleFromCart1(\""+Id+"\",\""+TitleName+"\",\""+WprTitleId+"\",\""+TvdProductType+"\")");
    toggleVis('saveSearchDialog');
}

function funRemoveTitleFromCart1(Id,TitleName,WprTitleId,TvdProductType)
{
    funPBTrends(TitleName,WprTitleId,TvdProductType,"","removetitlefromcart","","","","","");
    toggleVis('saveSearchDialog');
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartMode").value = "removetitlefromcart";
    window.document.getElementById("hdnTitleId").value = Id;
    var strTitleId = Id + ",";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value.replace(strTitleId,"");
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value.replace(Id,"");           
    window.document.forms[0].__VIEWSTATE.name= "";
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");    
}
//////////////////////////////////////////////////////////////////

//To remove selected titles from the cart
function funRemoveSelectedTitlesFromCart()
{
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value == "")
    {
        funBuildAlterMsg("Please select at least one Title to Delete", "OK");
        toggleVis('saveSearchDialog');
    }
    else
    {
        funBuildConfirmationMsg("Are you sure you want to Remove Title(s) from Cart", "OK", "Cancel", "funRemoveSelectedTitlesFromCart1()");
        toggleVis('saveSearchDialog');
    }   
}

function funRemoveSelectedTitlesFromCart1()
{
    window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";
    toggleVis('saveSearchDialog');
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartMode").value = "removeselectedtitlesfromcart";
    window.document.forms[0].__VIEWSTATE.name= "";
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
}
/////////////////////////////////////////////////////////////////////////

///When Check All/UnCheckAll is clicked in the title cart
function funCheckAllTitleCart(obj)
{
   if(obj.className == "cartUnchecked")
    {
       window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "Y";
       window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTotTitObjObjIds").value;
    }
    else
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value  = "";
    }
 }
 //////////////////////////////////////////////////////////////////////////////////
 
 ///When an individual title is checked or unchecked in the title cart
 function funCheckTitlesInCart(obj,Id)
{   
    if(obj.className == "cartUnchecked")
    {
       window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value += Id + ",";
    }
    else
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";
        var strTitleId = Id + ",";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value.replace(strTitleId,"");
        
    }
 }
 //////////////////////////////////////////////////////////////////////////////////////
 
 
 ////To uncheck----CheckAll--check box when all the selected titles are removed from cart
 function funCheckAllCheckedUnChecked()
 {
     if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds") == null || window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value == "" )
     {
         if(window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll") && window.document.getElementById("assetCart0001"))
         {
            window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";        
            window.document.getElementById("assetCart0001").checked = false;            
         }
         if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnUncheckTitleCartCheckAll") && window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll"))
         {
             if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnUncheckTitleCartCheckAll").value == "Y" && window.document.getElementById("assetCart0001"))
             {
                window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";        
                window.document.getElementById("assetCart0001").checked = false;   
             }
         }
         
        
     }
      //To hide the spotlight
    if(window.document.getElementById("divDefaultPlayer"))
    {
        window.document.getElementById("divDefaultPlayer").style.display = "none";  
    }  
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////
 

function funAddCheckedToCart()
{
    if(window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value == "Y")
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAddAllTittoCart").value = "addall";
        
        window.document.getElementById("ctl00_ctl00_BodyContent_CartControls1_hdnCartCheckAll").value = "N";
        window.document.forms[0].action="SearchResults.aspx";
        window.document.forms[0].__VIEWSTATE.name = "";
        window.document.forms[0].submit();
    }
    else
    {
        if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCartIds").value == "")
        {
            funBuildAlterMsg("Please select at least one Title to Add", "OK");
            toggleVis('saveSearchDialog');
        }
        else
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAddAllTittoCart").value = "add";
            
            // Doing Asyncronous PostBack for the TitleList Page.
            window.document.forms[0].__VIEWSTATE.name= "";
            window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
        }
    }
}

function funsaveSearchDialog()
{
    var hdnAdvSrchName = document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdvSrchName").value;
    if(hdnAdvSrchName != "SmartSearch")
    {        
        if(hdnAdvSrchName != "")
        {
            funBuildAlterMsg("Record is Already Saved As : "+hdnAdvSrchName, "OK");
            toggleVis('saveSearchDialog');
        }
        else
        {
            funBuildSaveSearchMsg("Save new title search as:", "SAVE", "CANCEL", "funSaveSearchFromSrchResult()");
            toggleVis('saveSearchDialog');    
        }
    }
    return false;
}

function funSaveSearchFromSrchResult()
{
    toggleVis('saveSearchDialog');
    var SavedSearchName = window.document.getElementById("titleSearchTitle").value;
    if(Trim(SavedSearchName) != "")
    {
        var strResult;
        var vardate = new Date();
        var SavedSearchId = document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdvSrchId").value.split('~');
        
        SavedSearchName = Trim(SavedSearchName);
        strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","SearchId=" + SavedSearchId[0] +"~"+ vardate +"&SearchName="+SavedSearchName+"&Type=RenameSavedSearch");  
        if(Trim(strResult) != "")
        {
            funBuildAlterMsg(strResult, "OK")
            toggleVis('saveSearchDialog');
        } 
        else
        {
            window.document.getElementById("hdnAdvSrchId").value = SavedSearchId[0] + "~" + SavedSearchName;
            window.document.forms[0].action="SearchResults.aspx";
            window.document.forms[0].__VIEWSTATE.name = "";
            window.document.forms[0].submit();
        } 
    }
    else
    {
        funBuildSaveSearchMsg("Please Enter Search Name:", "SAVE", "CANCEL", "funSaveSearchFromSrchResult()");
        toggleVis('saveSearchDialog');   
    }  
}

function funOpenPopupforWPRIds()
{
    funPBTrends("","","","","WPRIds","","","","","");
    var vardate = new Date();
    var varTime = vardate.getTime();
    var width  = 350;
    var height = 380;
    var left   = (screen.width  - width)/2;
    var top    = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=yes';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';    

    url = "WPRIdsPopup.aspx";
    newwindow=window.open(url,varTime,params);
}

function funSpecialFeatureReport(mode)
{
    funPBTrends("","","","","specialfeaturereport","","","","","");
    var vardate = new Date();
    var varTime = vardate.getTime()
    var properties = "toolbar=no,location=no,status=no,menubar=no,width=800,height=600,scrollbars=no,resizable=yes";
    url = "DownloadPopup.aspx?mode=" + mode;
    newwindow=window.open(url,varTime,properties);
}
