﻿ 
//This Function is used to Delete and Insert Assets into MemberAssetsCart using Jquery.
function funInsAssetintoCart(strFileObjObjId,obj,TitleName,WprTitleId,TitleCat,AssetType,AssetFormatType,AssetName,FileName,FileSize)
{   
    var vardate = new Date();
    var strResult;
    var lblAssetsInCart = window.document.getElementById("ctl00_ctl00_MainMenu1_lblAssetsInCart");
    var lblBQAssetsInCart = window.document.getElementById("ctl00_ctl00_MainMenu1_lblBQAssetsInCart");  
    if(obj.title.toLowerCase() == "add to cart")
    {        
        obj.title = "remove from cart";        
        strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","FileObjObjId=" + strFileObjObjId +"~"+ vardate + "&Type=InsAsset");
        funPBTrends(TitleName,WprTitleId,TitleCat,"","addtocart",AssetType,AssetFormatType,AssetName,FileName,FileSize);  
    }
    else
    {
         obj.title = "add to cart";                
         strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","FileObjObjId=" + strFileObjObjId +"~"+ vardate +"&Type=delasset");
         funPBTrends(TitleName,WprTitleId,TitleCat,"","removefromcart",AssetType,AssetFormatType,AssetName,FileName,FileSize);  
    }
    if (lblAssetsInCart != null && strResult != null) {
        var strAssetCartCount = Trim(strResult.split('~')[0]);
        lblAssetsInCart.innerHTML = (strAssetCartCount == "1") ? strAssetCartCount + " asset" : strAssetCartCount + " assets";
    }
    if (lblBQAssetsInCart != null && strResult != null) {
        var strBQAssetCartCount = Trim(strResult.split('~')[1]);
        lblBQAssetsInCart.innerHTML = (strBQAssetCartCount == "1") ? strBQAssetCartCount + " BQ Asset" : strBQAssetCartCount + " BQ Assets";
    }
    funSessionExpiryNav(strResult);     
}
function funAddGrouptoCart(strCatObjDefId)
{
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCatObjDefId").value = strCatObjDefId + ",";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetMode").value = "AddGrouptoCart";
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
}

function funAddSeriresGrouptoCart(strTitleId, strCatObjDefId)
{
    window.document.getElementById("hdnSeriesPCId").value = strTitleId;
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCatObjDefId").value = strCatObjDefId;
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetMode").value = "AddSeriesGrouptoCart";
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
}
/*###################################################*/
/*Asset Action Confirmation Dialog related functions*/
/*###################################################*/
//function to open Asset Action Confirmation Dialog popup 
function funTitleDetailsClick(obj, strTtlObjObjId,strFileObjObjId,strParams,strRelatedAssetsYN,TitleName,WprTitleId,TitleCat,AssetType,AssetFormatType,AssetName,FileName,FileSize,strMode) 
{
    funCloseVideoDialog();
    funPBTrends(TitleName, WprTitleId, TitleCat, "", "ClickOnAsset", AssetType, AssetFormatType, AssetName, FileName, FileSize);  
    document.getElementById("hdnIdCount").value = obj;
    var groupvalue = obj.split('~')[0];    
    var vardate = new Date();
    var strResult = funGetHtmlFromJQuery("Xmlhttp.aspx", "&TtlObjObjId=" + strTtlObjObjId + "~" + vardate + "&FileId=" + strFileObjObjId + "&GroupValue=" + groupvalue + "&ParamArray=" + strParams + "&Type=TtlDetClick" + "&Mode=" + strMode);     
    if(Trim(strResult) != "")
    {
        window.document.getElementById("detailsWrappper").innerHTML = strResult.split('~^~^')[0]; 
        if(document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId"))
        {
            document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId").value = strResult.split('~^~^')[1];
        }
    }
    toggleVis("divTitDetClick");
    //The below method had been called for applying checkbox styles after asynchronous postback in the popUp.
    $().cssCartCheckbox();
    
}

function funGetNextAssetDetails(asset,strParams,strMode)
{
    var obj1 = document.getElementById("hdnIdCount").value;
    var flag = "";
    if(asset == "next")
    {
        var Id = parseInt(obj1.split('~')[1]) + 1;
          
    }
    else if(asset == "previous")
    {
        var Id = parseInt(obj1.split('~')[1]) - 1;
            
    }
               
    var objChk = document.getElementById(obj1.split('~')[0] + "~" + Id);
    
    if(objChk!= null)
    {
        window.document.getElementById("detailsWrappper").innerHTML = "";
        var vardate = new Date();
        document.getElementById("hdnIdCount").value =objChk.id;
        var groupvalue = objChk.id.split('~')[0];
        var strTtlObjObjId = objChk.name.split('~')[0];
        var strFileObjObjId =  objChk.name.split('~')[1];
        var strAssetCount =  objChk.name.split('~')[2];
        var strResult = funGetHtmlFromJQuery("Xmlhttp.aspx", "TtlObjObjId=" + strTtlObjObjId + "~" + vardate + "&FileId=" + strFileObjObjId + "~" + vardate + "&GroupValue=" + groupvalue + "~" + vardate + "&ParamArray=" + strParams + "&Type=TtlDetClick&Mode=" + strMode);    
        var strHTMLText = strResult.split('~^~^')[0];
        if(Trim(strHTMLText) != "")
        {
            window.document.getElementById("detailsWrappper").innerHTML = strHTMLText;
            if(document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId"))
            {
                document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId").value = strResult.split('~^~^')[1];
            }
        }
        else
        {
            toggleVis("divTitDetClick");    
        }
        
        //The below method had been called for applying checkbox styles after asynchronous postback in the popUp.
        $().cssCartCheckbox(); 
               
    }    
    
    return false;
}


//function to append checked AssetIds to hidden variable
function funAssetActionCartCheck(obj,Id)
{
    var hdnAsstActConDlgCartId = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId");
    var ID = Id.split('~')[0];
    if(obj.className=="cartUnchecked")
    {
        hdnAsstActConDlgCartId.value +=ID + ",";
    }
    else
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartCheckAll").value = "N";
        var strAssetObjObjId = ID + ",";
        hdnAsstActConDlgCartId.value = hdnAsstActConDlgCartId.value.replace(strAssetObjObjId,"");
        hdnAsstActConDlgCartId.value = hdnAsstActConDlgCartId.value.replace(ID,"");
    }
}
//function to append All AssetIds to a hidden variable
function funAssetActionCartCheckAll(obj,Ids)
{
    if(obj.className == "cartUnchecked")
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartCheckAll").value = "Y";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId").value = Ids;//window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgTotTtlIds").value;
    }
    else
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartCheckAll").value = "N";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId").value  = "";
    }
}

//To implement the download functionality
function funDownload(strImgPath)
{
    window.document.getElementById("hdnImgPath").value = strImgPath;
    window.document.forms[0].action="TitleDetailsList.aspx";
    window.document.forms[0].__VIEWSTATE.name = "";
    window.document.forms[0].submit();
}
function funClearDownload()
{
    window.document.getElementById("hdnImgPath").value  = "";
}


/* To Hide the unecessary user controls */
function funShowHideControlsInTitleDetails()
{
    if(window.document.getElementById("ctl00_ctl00_BodyContent_TitleOptionsBottom1_spanAccessLegends")!= null)
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_TitleOptionsBottom1_spanAccessLegends").style.display = "none";
      }
    if(window.document.getElementById("titleOptionsBottom")!= null)
    {
        window.document.getElementById("titleOptionsBottom").style.display = "none";
    }
    if(window.document.getElementById("divPagenation")!= null)
    {
        window.document.getElementById("divPagenation").style.display = "none";
    }
    //To hide the spotlight
    if(window.document.getElementById("divDefaultPlayer"))
    {
        window.document.getElementById("divDefaultPlayer").style.display = "none";  
    }  
}
/* To implement more functcionality in titledetailslist screen */
function funMoreAssets(CatId)
{
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets") != null && window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets").value != "" )
    {
        if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets").value.indexOf(CatId) < 0)
        {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets").value + CatId+",";
        }
    }
    else
    {
      window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMoreAssets").value = CatId+",";
    }
    window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
}

function funMoreVideoDetails(TitleObjObjId,CatNames,Mode)
{
    if(TitleObjObjId && TitleObjObjId !="")
    {
        var vardate = new Date();
        funGetHtmlFromJQuery("Xmlhttp.aspx","TitObjObjId=" + TitleObjObjId + "~" + vardate + "&Type=otherassetrightslevel3");
    }
    funAssetCategoryNav(TitleObjObjId,CatNames,Mode);
}
/*To provide navigation for the assets menu*/
function funAssetCategoryNav(TitleObjObjId,CatNames,Mode) {
    if (Mode == "overview") {
        if (window.document.getElementById("hdnAssetsMenuClickActionYN")) {
            window.document.getElementById("hdnAssetsMenuClickActionYN").value = "N";
        }
    }
    else {
        if (window.document.getElementById("hdnAssetsMenuClickActionYN")) {
            window.document.getElementById("hdnAssetsMenuClickActionYN").value = "Y";
        }
    }
    //When alldownloadable assets is clicked
    if (Mode == "downloadable") {
        if (window.document.getElementById("hdnAssetMenuDownlaodableAssetsMode")) {
            window.document.getElementById("hdnAssetMenuDownlaodableAssetsMode").value = "Y";
        }
    }
    else {
        if (window.document.getElementById("hdnAssetMenuDownlaodableAssetsMode")) {
            window.document.getElementById("hdnAssetMenuDownlaodableAssetsMode").value = "N";
        }
    }
    //When preview under video category of assets top menu is clicked
    if (Mode == "preview") {
        if (window.document.getElementById("hdnAssetMenuPreview")) {
            window.document.getElementById("hdnAssetMenuPreview").value = "Y";
        }
    }
    else {
        if (window.document.getElementById("hdnAssetMenuPreview")) {
            window.document.getElementById("hdnAssetMenuPreview").value = "N";
        }
    }
    if (TitleObjObjId.indexOf('~') != -1) {
        if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTVDProductType")) {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTVDProductType").value = TitleObjObjId.split('~')[1];
        }
        TitleObjObjId = TitleObjObjId.split('~')[0];
    }
    // Added for showing Loading wait.. Message.
    toggleVis('divProgressDialog');
        
    ////////////////////////////////////////For BQ Download click/////////
    if(CatNames == "")
    {
        if(window.document.getElementById("hdnAssetMenuBQDownload"))
        {
            window.document.getElementById("hdnAssetMenuBQDownload").value = "Y";
        }
    }
    else if(CatNames == "radio")
    {
        if(window.document.getElementById("hdnAssetMenuRadioSpots"))
        {
            window.document.getElementById("hdnAssetMenuRadioSpots").value = "Y";
        }
    }
    else
    {
        if(window.document.getElementById("hdnAssetMenuBQDownload"))
        {
            window.document.getElementById("hdnAssetMenuBQDownload").value = "N";
        }
        if(window.document.getElementById("hdnAssetMenuRadioSpots"))
        {
            window.document.getElementById("hdnAssetMenuRadioSpots").value = "N";
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    if(window.document.getElementById("ctl00_ctl00_BodyContent_LeftNav1_hdnSeriesCatEnable"))
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_LeftNav1_hdnSeriesCatEnable").value = "";
    }
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitObjObjId").value = TitleObjObjId;
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = CatNames + ",";
    window.document.forms[0].action="TitleDetailsList.aspx";
    window.document.forms[0].__VIEWSTATE.name = "";
    window.document.forms[0].submit();
}


 /*######################################################*/
    /*LeftNav Functions*/
 /*######################################################*/
 
 //Function to build the details based on selected funGetSelectedBQAssetfilterOpt in LeftNav
function funGetSelectedBQAssetfilterOpt(obj,Id)
{
    var flag = "I";
    if(obj.className == "filterUnchecked")
    {
        if(Id == 'all')
        {
            flag = "A"; 
        }
    }
    else
    {
        if(Id == 'all')
        {
            flag = "R"; 
        }
        else
        {
            var flag = "D";
        }
    }
    
    //bqassetsfilters -- OptionCat
    var vardate = new Date();
    var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","Date="+vardate+"&Type=bqassetsfilters&Id="+ Id + "&flag="+flag);
    
    /*Checkbox delay functionality*/
    clearTimeout(timer);    
    timer=window.setTimeout("funAssetsAsynSubmit()",2000);
}

//Function to build the details based on selected categories in LeftNav
function funGetSelectedAssetCategories(obj,Id)
{
    if (obj.className == "filterUnchecked") {
        if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.indexOf(Id) < 0) {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value += Id + ",";
        }
    }
    else {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.replace(Id + ",", "");
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.replace(Id, "");
    }
    if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnBQDownload")) {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnBQDownload").value = "N";
    }
    if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots")) {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value = "N";
    }
    if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnDownlaodableAssetsMode")) {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnDownlaodableAssetsMode").value = "N";
    }
    if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPreview")) {
        if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.toLowerCase().indexOf('video') != -1) {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPreview").value = "Y";
        }
        else {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPreview").value = "N";
        }        
    }
    /*Checkbox delay functionality*/
    clearTimeout(timer);    
    timer=window.setTimeout("funAssetsAsynSubmit()",2000);
}
//---------------------------------------------------------------------------------------------  
//Description		: Adding/Removing all the CategoryIds to Hiddenvariable.
//Remarks		    : On Click of All CheckBox from LeftNav.
//Input Params		: CheckBoxGroupName, CheckBoxId
//--------------------------------------------------------------------------------------------- 
function funCheckAllAssetCatOptions(obj,Ids)
{
  if(obj.className == "filterUnchecked")
  {
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = "";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = Ids + ",";
  }
  else
  {
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value = "";
  }
  if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnBQDownload"))
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnBQDownload").value = "N";
    }
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots"))
    {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value = "N";
    }
  clearTimeout(timer);    
  timer=window.setTimeout("funAssetsAsynSubmit()",2000);
}

//To check and uncheck asset categories when page is loaded
 function funCheckAssetCategories()
 {
    
    var obj = window.document.getElementsByName("chkAssetCategories");
    var intCatCount = 0;
    for(var intCount=0; intCount<obj.length;intCount++)
    {
        if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.indexOf(obj[intCount].id) != -1)
        {
            obj[intCount].checked = true;
            intCatCount = intCatCount + 1;
        }
    }
    
    var obj1 = window.document.getElementsByName("filter1000AssetCheckAll");
    if(obj1[0])
    {
        if(intCatCount == obj.length)
        {
            obj1[0].checked = true;
        }
        else
        {
            obj1[0].checked = false;
        }
    }
    
    
    if(window.document.getElementById("adrestrictionsall"))
    {
        var arrAssetFilter = ['aspectratio','filetype','adrestrictions'];
    }
    else
    {
        var arrAssetFilter = ['aspectratio','filetype'];
    }
    for(var intAssetFilterCount = 0; intAssetFilterCount < arrAssetFilter.length; intAssetFilterCount++)
    {
        var obj = window.document.getElementsByName(arrAssetFilter[intAssetFilterCount]);
        var hdnVariable = "";
        if(arrAssetFilter[intAssetFilterCount] == "aspectratio")
        {
            hdnVariable = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value;
        }
        else if(arrAssetFilter[intAssetFilterCount] == "filetype")
        {
            hdnVariable = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value;
        }
        else if(arrAssetFilter[intAssetFilterCount] == "adrestrictions")
        {
            hdnVariable = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value;
        }
        var intCatCount = 0;
        for(var intCount=0; intCount<obj.length;intCount++)
        {
            if(hdnVariable.indexOf(obj[intCount].id) != -1)
            {
                obj[intCount].checked = true;
                intCatCount = intCatCount + 1;
            }
        }
        
        var obj1 = window.document.getElementsByName(arrAssetFilter[intAssetFilterCount] + "all");
        if(obj1[0])
        {
            if(intCatCount == obj.length)
            {
                obj1[0].checked = true;
            }
            else
            {
                obj1[0].checked = false;
            }
        }
    }
    
    // Styles all checkboxes
	$().cssFilterCheckbox();
 }
 //Function to build the details based on selected categories in LeftNav
function funGetSelectedAssetFilters(obj,Id,type)
{

    if(type == 'aspectratio')
    {
        if(obj.className == "filterUnchecked")
        {
            if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value.indexOf(Id) < 0)
            {
                window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value += Id + ",";
            }
        }
        else
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value.replace(Id+",","");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value.replace(Id,"");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value.replace("allaspectratio,","");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value.replace("allaspectratio","");
        }
    }
    if(type == 'filetype')
    {
        if(obj.className == "filterUnchecked")
        {
            if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value.indexOf(Id) < 0)
            {
                window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value += Id + ",";
            }
        }
        else
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value.replace(Id+",","");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value.replace(Id,"");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value.replace("allfiletype,","");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value.replace("allfiletype","");
        }
    }
    if(type == 'adrestrictions')
    {
        if(obj.className == "filterUnchecked")
        {
            if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value.indexOf(Id) < 0)
            {
                window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value += Id + ",";
            }
        }
        else
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value.replace(Id+",","");
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value.replace(Id,"");
        }
    }
    if(type == 'relatedassets')
    {

           var vardate = new Date();
           funGetHtmlFromJQuery("Xmlhttp.aspx", "AssetDefaultView=" + Id + "~" + vardate + "&Type=UdpateAssetDefaultView");
           window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRelatedAssets").value = Id;
           
    }
   

    /*Checkbox delay functionality*/
    clearTimeout(timer);    
    timer=window.setTimeout("funAssetsAsynSubmit()",2000);

}
//---------------------------------------------------------------------------------------------  
//Description		: Adding/Removing all the CategoryIds to Hiddenvariable.
//Remarks		    : On Click of All CheckBox from LeftNav.
//Input Params		: CheckBoxGroupName, CheckBoxId
//--------------------------------------------------------------------------------------------- 
function funCheckAllAssetFilters(obj,Ids,type)
{
    if(type == 'aspectratio')
    {
      if(obj.className == "filterUnchecked")
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = "";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = Ids + ",allaspectratio,";
      }
      else
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAspectRatio").value = "";
      }
    }
    if(type == 'filetype')
    {
      if(obj.className == "filterUnchecked")
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = "";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = Ids + ",allfiletype,";
      }
      else
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnFileType").value = "";
      }
    }
    if(type == 'adrestrictions')
    {
      if(obj.className == "filterUnchecked")
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value = "";
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value = Ids + ",";

      }
      else
      {
        window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictions").value = "";
      }
    }
  clearTimeout(timer);    
  timer=window.setTimeout("funAssetsAsynSubmit()",2000);
}

 function funCheckStyle1()
 {
    $().cssRadioCheckbox();
    $('div.toggler-sidebar').toggleElements( 
            { fxAnimation:'slide', fxSpeed:'fast', className:'togglerSide' } );
            SetPlaylistYN();
            
 }
  
 function funAssetsAsynSubmit()
 {
     
     window.__doPostBack("ctl00_ctl00_BodyContent_updPanelMain","");
 }
 
 ///////////////////////////////////////////// End Of Left Nav Filters ////////////////////////////
 
 
 //To change the background color of assets menu 
 function funAssetMenuBackGroundChange()
 {
    var obj = window.document.getElementsByName("chkAssetCategories");
    for(var intCount = 0; intCount<obj.length;intCount++)
    {
        if(window.document.getElementById("li_"+obj[intCount].id))
        {
            window.document.getElementById("li_"+obj[intCount].id).style.backgroundColor = "";
        }
    }
    if(window.document.getElementById("li_images"))
    {
        window.document.getElementById("li_images").style.backgroundColor = "";
    }
    if(window.document.getElementById("li_video"))
    {
        window.document.getElementById("li_video").style.backgroundColor = "";
    }

    if(window.document.getElementById("li_MarketingAssets"))
    {
        window.document.getElementById("li_MarketingAssets").style.backgroundColor = "";        
    }
     if(window.document.getElementById("li_More"))
    {
        window.document.getElementById("li_More").style.backgroundColor = "";        
    }
    if(window.document.getElementById("li_AllDownloadable"))
    {
        window.document.getElementById("li_AllDownloadable").style.backgroundColor = "";
    }
    
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnBQDownload").value != "Y" && window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value != "Y")
    {
        var arrCatIds = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetCatIds").value.split(',');

        var strMore = "N";
        var strVideo = "N";
        var strMarketAssets = "N";
        for(var intCatCount1 = 0; intCatCount1<arrCatIds.length-1; intCatCount1++)
        { 
            if(arrCatIds[intCatCount1] == "ratings" || arrCatIds[intCatCount1] == "misc/merch" )
            {
                if(window.document.getElementById("li_More"))
                {
                    window.document.getElementById("li_More").style.backgroundColor = "#ffac13";        
                }
                strMore = "Y";
            }
            else if(arrCatIds[intCatCount1] == "video")
            {
                if(window.document.getElementById("li_video"))
                {
                    window.document.getElementById("li_video").style.backgroundColor = "#ffac13";        
                }
                strVideo = "Y";
            }
            else
            {
                if(window.document.getElementById("li_MarketingAssets"))
                {
                    window.document.getElementById("li_MarketingAssets").style.backgroundColor = "#ffac13";        
                }
                strMarketAssets = "Y";
            }
        }
        if((strMarketAssets == "Y" &&  strMore == "Y")||(strMarketAssets == "Y" &&  strVideo == "Y")||(strVideo == "Y" &&  strMore == "Y"))
        {
                if(window.document.getElementById("li_MarketingAssets"))
                {
                    window.document.getElementById("li_MarketingAssets").style.backgroundColor = "";        
                }
                 if(window.document.getElementById("li_More"))
                {
                    window.document.getElementById("li_More").style.backgroundColor = "";        
                }
                if(window.document.getElementById("li_video"))
                {
                    window.document.getElementById("li_video").style.backgroundColor = "";        
                }
        }
        //To hightlight more option when alldownloadable assets is clicked
        if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnDownlaodableAssetsMode").value == "Y")
        {
            if (window.document.getElementById("li_More")) {
                window.document.getElementById("li_More").style.backgroundColor = "#ffac13";
            }
            if (window.document.getElementById("li_MarketingAssets")) {
                window.document.getElementById("li_MarketingAssets").style.backgroundColor = "";
            }
            if (window.document.getElementById("li_video")) {
                window.document.getElementById("li_video").style.backgroundColor = "";
            }
            if (window.document.getElementById("li_AllDownloadable")) {
                window.document.getElementById("li_AllDownloadable").style.backgroundColor = "";
            }
        }

    }
    else if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value == "Y")
    {
         if(window.document.getElementById("li_More"))
            {
                window.document.getElementById("li_More").style.backgroundColor = "#ffac13";     
            }
    }
    else
        {
              if(window.document.getElementById("li_video"))
                {
                    window.document.getElementById("li_video").style.backgroundColor = "#ffac13";        
                }
        }
 }
 
 ///Function to change the background in top menu of sysnopsis,usagerestriction,factsheets,bios,press,awards category 
function funAssetMoreMenuBackGroundChange(strAssetMoreMenuItem)
{


    if(strAssetMoreMenuItem != "UsageRestriction")
    {
        if(window.document.getElementById("li_MarketingAssets"))
        {
            window.document.getElementById("li_MarketingAssets").style.backgroundColor = "#ffac13";        
        }
    }
    else
    {
         if(window.document.getElementById("li_More"))
        {
            window.document.getElementById("li_More").style.backgroundColor = "#ffac13";        
        }
    }
}

//To hide the unnecessary content on this page
function funShowHideControlsInTitlesText()
{
  if(window.document.getElementById("titleOptionsTop")!= null)
  {
    window.document.getElementById("titleOptionsTop").style.display = "none";
  }
  if(window.document.getElementById("titleTypeLegend")!= null)
  {
    window.document.getElementById("titleTypeLegend").style.display = "none";
  }
  if(window.document.getElementById("titleOptionsBottom")!= null)
  {
    window.document.getElementById("titleOptionsBottom").style.display = "none";
  }
  if(window.document.getElementById("divDefaultPlayer"))
    {
        window.document.getElementById("divDefaultPlayer").style.display = "none";
    }
}

function funGetAssetsunderImageCat(obj,strCatObjDefId,strTitObjObjId,strMode,strParams)
{
    var vardate = new Date();
    var strResult;
    var strCat = strCatObjDefId.replace("&","$@$");
    var strRadio = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value;
    if(obj.className.toLowerCase() == "level4title collapsable" || obj.className.toLowerCase() == "level4title collapsable lastcollapsable" || obj.className.toLowerCase() == "level2 title collapsable lastcollapsable" || obj.className.toLowerCase() == "level2 title collapsable" || obj.className.toLowerCase() == "level3title collapsable lastcollapsable" || obj.className.toLowerCase() == "level3title collapsable")
    {        
        strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","CatObjDefId=" + strCat + "&TitObjObjId=" + strTitObjObjId + "~"+ vardate + "&Mode=" + strMode + "&Params=" + strParams +  "&Radio=" + strRadio + "&Type=Assets");
        if(window.document.getElementById("li_images_" + strTitObjObjId))
        {
             window.document.getElementById("li_images_" + strTitObjObjId).innerHTML = strResult;
        }   
    }   
    //function for Cart icon class changing when the document is onready.
    SetAddtoCartYN();
    //Function for calling jquery script when the Asset Hovers for getting the hover popup.
    funSetHoverforAssets();
    
}
function funGetAssetsunderCat(obj,strCatObjDefId,strTitObjObjId,strMode,strParams)
{
    var vardate = new Date();
    var strResult;
    var strCat = strCatObjDefId.replace("&","$@$");
    var strRadio = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnRadioSpots").value;
    if(obj.className.toLowerCase() == "level4title collapsable" || obj.className.toLowerCase() == "level4title collapsable lastcollapsable" || obj.className.toLowerCase() == "level2 title collapsable lastcollapsable" || obj.className.toLowerCase() == "level2 title collapsable" || obj.className.toLowerCase() == "level3title collapsable lastcollapsable" || obj.className.toLowerCase() == "level3title collapsable")
    {        
        strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","CatObjDefId=" + strCat + "&TitObjObjId=" + strTitObjObjId + "~"+ vardate + "&Mode=" + strMode + "&Params=" + strParams + "&Radio=" + strRadio + "&Type=Assets");
        if(window.document.getElementById("li_" + strCatObjDefId + "_" + strTitObjObjId))
        {
             window.document.getElementById("li_" + strCatObjDefId + "_" + strTitObjObjId).innerHTML = strResult;
        }   
    }    
    //function for Cart icon class changing when the document is onready.
    SetAddtoCartYN();
    //Function for calling jquery script when the Asset Hovers for getting the hover popup.
    funSetHoverforAssets();
    
}







/////////////////// Script functions for Customer List Screen ////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

function funGroupOptionsForCustomerList()
{
     window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_CView_hdnGroupby").value = "group";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCustomerGroupby").value = "group";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
   
     window.__doPostBack("ctl00_ctl00_BodyContent_SubBodyContent_updPanelMain","");
     
}
function funUngroupOptionsForCustomerList()
{
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_CView_hdnGroupby").value = "user";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCustomerGroupby").value = "user";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
   
   
     window.__doPostBack("ctl00_ctl00_BodyContent_SubBodyContent_updPanelMain","");
}

function funShowInactiveCustomerList(obj)
{
    if(obj.className=="groupCheckbox group_off")
    {
     window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_CView_hdnShowInactive").value = "Y";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCustomerShowInactive").value = "Y";
   
    }
    else
    {
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_CView_hdnShowInactive").value = "N";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCustomerShowInactive").value = "N";

    }
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
    
   window.__doPostBack("ctl00_ctl00_BodyContent_SubBodyContent_updPanelMain","");
    
}

function funCustomerListSearch()
{
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnGroupOrCustomerNo").value = window.document.getElementById("txtGroupOrCustomerNo").value;
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnLoginOrEmail").value = window.document.getElementById("txtLoginOrEmail").value;
    window.__doPostBack("ctl00_ctl00_BodyContent_SubBodyContent_updPanelMain","");
}
function funCustomerListEmulation(strCustomerLogonName)
{

    var vardate = new Date();
    var strResult = funGetHtmlFromJQuery("Xmlhttp.aspx","vardate=" + vardate + "&CustomerLogonName=" + strCustomerLogonName + "&Type=CustomerListEmulation");    
    
//    window.location.href = "AdvancedSearch.aspx";

    strResult = strResult.substring(0,strResult.length-2);
    var strValues = strResult.split('~');
    if (strValues[1] == "BQAssetsY")
    {
        window.document.getElementById("hdnNavigationMode").value = "cart";
        window.document.forms[0].action = "BQAssetCart.aspx";
        window.document.forms[0].method = "post";
        window.document.forms[0].__VIEWSTATE.name = "";
        window.document.forms[0].submit();    
    }
    else
    {
        NavAsPerUserPreferences(strResult);
    }

}
///////////////////////// End of Script functions in CustomerList screen ////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

/*Ad Restrictions related scripts*/
function funOpenAdRestforSingleDwnld(strTtlObjObjId, fileObjObjId, AdRestObjObjId, source)
{
    var vardate = new Date(); 
    var downloadmode = "single";
    var strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","TtlObjObjId=" + strTtlObjObjId + "~" + vardate + "&Type=AdRestriction&downloadmode="+downloadmode+ "&fileObjObjId="+fileObjObjId+"&AdRestObjObjId="+AdRestObjObjId);
    var strArray = strresult.split('~^~^');
    if(Trim(strArray[0]) == "")
    {
        var FoxFastDownloaderGroupYN = document.getElementById("ctl00_ctl00_hdnFoxFastDownloaderGroupYN").value;
        if(source.toLowerCase() == "origin" && FoxFastDownloaderGroupYN == "Y")
        {
            funDownloadVideoForOrigin(fileObjObjId);
        }
        else
        {
            funDownloadSingleFile(fileObjObjId, AdRestObjObjId);
        }
    }
    else
    {
        window.document.getElementById("adRestrictDetailsWrapper").innerHTML = strArray[0];    
        toggleVis("adRestrictionsClick");
        if(downloadmode == "multiple")
        {
            $().cssFilterCheckbox();
        }    
   
        var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
        if(pageName && pageName.value != "TitleDetailsList")
        {
            return false;
        }
    }
}


function funAgreeForSingleDownload(strTtlObjObjId, path, filtObjObjId, mode, source, strTitleName,sourceurl1, strAdRestObjObjId)
{
    strTitleName = strTitleName.replace("~@@~" , "'");
//    if(mode == "scrRoom")
//    {
        var vardate = new Date();
        var strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","TtlObjObjId=" + strAdRestObjObjId + "~" + vardate + "&Type=SetAddRestrictioninSession");
//    }
    var FoxFastDownloaderGroupYN = document.getElementById("ctl00_ctl00_hdnFoxFastDownloaderGroupYN").value;
    toggleVis("adRestrictionsClick");
    if(source == "ESPRIT")
    {
        funDownloadVideoForEsprit(strTitleName, sourceurl1);
    }
    else if(source.toLowerCase() == "origin" && FoxFastDownloaderGroupYN == "Y")
    {
        funDownloadVideoForOrigin(filtObjObjId);
    }
    else
    {
        funDownloadSingleFile(filtObjObjId, strAdRestObjObjId);
    }
    
    if(window.document.getElementById("hdnSelTitleforAdRest"))
    {
        window.document.getElementById("hdnSelTitleforAdRest").value = "";
    }
    
//    if(window.document.getElementById('ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictionTitleId') && window.document.getElementById('ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictionFlag'))
//    {
//        var el = document.getElementById("divTitDetClick");
//        if ( el && el.style.display != 'none' )
//        {
//        }
//        else
//        {
//            window.document.getElementById('ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictionTitleId').value = strTtlObjObjId;
//            window.document.getElementById('ctl00_ctl00_BodyContent_SubBodyContent_hdnAdRestrictionFlag').value = "Y";    
//            
//            window.document.forms[0].__VIEWSTATE.name = "";
//            window.document.forms[0].action = "#";
//            window.document.forms[0].method = "post";
//            window.document.forms[0].submit();
//        }
//    }
    
    return false;
}

function funDownloadSingleFile(filtObjObjId, strAdRestObjObjId)
{
    var vardate = new Date();
    var varTime = vardate.getTime()
    funStoreLicenseforDownload(filtObjObjId);
    
    /***Sami: Backup-Remove Assest from cart after download functionality.************/
    funRemoveAssetsfromCartAfterDownload(filtObjObjId);
    /**************************/

    var properties = "toolbar=no,location=no,status=no,menubar=no,width=800,height=600,scrollbars=no,resizable=yes";
    url = "../aspxfiles/DownloadPopup.aspx?filtObjObjId=" + filtObjObjId;
    window.open(url,varTime,properties);
    return false;
}



function funDisAgree()
{
    toggleVis("adRestrictionsClick");
    
    
}

function SetCheckItem(obj, objobjId)
{
    var hdnSelTitleforAdRest = window.document.getElementById("hdnSelTitleforAdRest");
    if(hdnSelTitleforAdRest)
    {
        if(obj.className == "filterUnchecked")
        {
            hdnSelTitleforAdRest.value += objobjId + ",";
        }
        else
        {
            hdnSelTitleforAdRest.value = hdnSelTitleforAdRest.value.replace(objobjId+",","");
        }
    }
}


function funRefreshContentClick(strTitleObjObjId)
{
   var vardate = new Date();
   funGetHtmlFromJQuery("Xmlhttp.aspx","TitObjObjId=" + strTitleObjObjId + "~"+ vardate + "&Type=RefreshContent");
   //   window.document.location.href = "TitleDetailsHome.aspx?TitleId="+ strTitleObjObjId + "&IsRefCont=Y";
   toggleVis('divProgressDialog');
   var TitleSearchMode = "";
   var TitleSearchText = "";
   if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchMode")) 
   {
       TitleSearchMode = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchMode").value;
   }
   if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchText")) 
   {
       TitleSearchText = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchText").value;
   }
   hdnCategoryLinkId = window.document.getElementById('ctl00_ctl00_BodyContent_SubBodyContent_hdnCategoryLinkId');
   if (hdnCategoryLinkId && hdnCategoryLinkId.value != "") 
   {
       window.location.href = "TitleDetailsHome.aspx?TitleId=" + strTitleObjObjId + "&Type=CL~" + hdnCategoryLinkId.value + "&IsRefCont=Y";
   }
   else if (TitleSearchMode != "") 
   {
       window.location.href = "TitleDetailsHome.aspx?TitleId=" + strTitleObjObjId + "&Type=SR&TtlSrchMode=" + TitleSearchMode + "&TtlSrchTxt=" + TitleSearchText + "&IsRefCont=Y";
   }
   else 
   {
       window.location.href = "TitleDetailsHome.aspx?TitleId=" + strTitleObjObjId + "&IsRefCont=Y";
   }   
 }
 
 
 /* Functions for Multiple download functionality in Asset Cart.*/
 
function funDownloadFiles(AssetObjObjIds)
{
    var hdnAssetIds =  window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetIds");
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnMode").value = "downloadall";
    
    window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnDownloadAssetIds").value = AssetObjObjIds;
    
    if(pageName && pageName.value == "BQAssetCart")
    {
        window.document.forms[0].action = "BQAssetCart.aspx";
    }
    else
    {
        window.document.forms[0].action = "AssetCart.aspx";
    }
    window.document.forms[0].method = "post";
    window.document.forms[0].__VIEWSTATE.name = "";
    window.document.forms[0].submit();
}

function funDownloadFilesFromCart()
{
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    var hdnSelTitleforAdRest = window.document.getElementById("hdnSelTitleforAdRest");
    var divtitlesContainer = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_titlesContainer");
    var hdnAssetIds = "";
//    if(pageName && pageName.value == "BQAssetCart")
//    {
//        hdnAssetIds =  window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTotAssetObjObjIds");
//    }
//    else
//    {
        hdnAssetIds =  window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAssetIds");
//    }
    if(hdnAssetIds && hdnAssetIds.value != "")
    {
        if(divtitlesContainer && divtitlesContainer.innerHTML.indexOf('<b>There are no Assets in the List') != -1)
        {
            funBuildAlterMsg("Please select at least one asset to download", "OK");
            toggleVis('saveSearchDialog');
        }
        else
        {
            funDownloadFiles(hdnAssetIds.value);
        }
    }
    else
    {
        funBuildAlterMsg("Please select at least one asset to download", "OK");
        toggleVis('saveSearchDialog');
    }
   
    
}
 
function funOpenWinforMultipleDwnld(AssetObjObjIds)
{
    var vardate = new Date();
    var varTime = vardate.getTime();
    var hdnSelTitleforAdRest = window.document.getElementById("hdnSelTitleforAdRest");
    // HttpRequest for checking whether Add Restriction Req, Any Esprit Downloads.
    var strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","date=" + vardate + "&Type=adrestformultipledwnld");   
    var strArray = strresult.split('~^~^');
    // If Add Restriction Requires.
    if(Trim(strArray[0]) != "")
    {
        hdnSelTitleforAdRest.value = "";
        window.document.getElementById("adRestrictDetailsWrapper").innerHTML = Trim(strArray[0]);    
        toggleVis("adRestrictionsClick");
        
    }
    // If Add Restriction Not Required.
    else 
    {
        //If any nonEsprit files Exists for Download.
//        if(strArray[3] != null && Trim(strArray[3]) > 0)
//        {
            funOpenDownloadPopup();
//        }
        // if any Esprit files Exists for Download.
        if(strArray[2] != null && Trim(strArray[2]) != "")
        {
            funDownloadVideoForEsprit('', Trim(strArray[2]));
        }
    }
}

function funAgreeForDownload(downloadMode, count, strEspiritSourceURL1, intNonEspritFilesCount, titleObjObjId)
{
    var hdnSelTitleforAdRest = window.document.getElementById("hdnSelTitleforAdRest");
    var arr = hdnSelTitleforAdRest.value.split(',');
    
    // For Multiple download and if any checkbox in add Rest. is unchecked then showing msg.
    if(downloadMode == "multiple" && count != (arr.length-1))
    {
        funBuildAlterMsg("You must select all of the titles listed on this page before choosing to ACCEPT the complete list of Ad Restrictions.", "OK");
        toggleVis('saveSearchDialog');
    }
    else
    { 
        
            // Closign AD Rest. Popup.
            toggleVis("adRestrictionsClick");
            
            // HttpRequest for Updating the Ad Rest. Titles in Session Variable.
            var vardate = new Date();
            var strresult;
            if(downloadMode == "single")
            {
                strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","TtlObjObjId=" + titleObjObjId + "~" + vardate + "&Type=SetAddRestrictioninSession");
            }
            else
            {
                strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","TtlObjObjId=" + hdnSelTitleforAdRest.value + "~" + vardate + "&Type=SetAddRestrictioninSession");
            }
            
            //If any nonEsprit files Exists for Download.
            if(intNonEspritFilesCount > 0)
            {
                funOpenDownloadPopup();
            }
            // if any Esprit files Exists for Download.
            if(Trim(strEspiritSourceURL1) != "")
            {
                funDownloadVideoForEsprit('', strEspiritSourceURL1);
            }
       
    }
}
function funOpenDownloadPopup()
{
    var vardate = new Date();
    var varTime = vardate.getTime();
    funStoreLicenseforDownload('');
    
    /***Sami: Remove Assest from cart after download functionality.************/
    funRemoveAssetsfromCartAfterDownload('');
    /**************************/
    
    var properties = "toolbar=no,location=no,status=no,menubar=no,width=800,height=600,scrollbars=no,resizable=yes";
    url = "../aspxfiles/DownloadPopup.aspx";
    newwindow=window.open(url,varTime,properties);
}
function funSmartSearchTitleClick(strId,strWprTitleId,strTitleName,strTvdProductType,strSearchText)
{
    funPBTrends(strTitleName,strWprTitleId,strTvdProductType,"smartsearch","titleclick","","","","","");
    window.location.href = "TitleDetailsHome.aspx?TitleId=" + strId + "&Type=SS&TtlSrchTxt=" + strSearchText;
}
function funStoreLicenseforDownload(filtObjObjId)
{
    var vardate = new Date();
    var strresult = "";
    if(filtObjObjId !="")
    {
        strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","date=" + vardate + "&Type=getlicensefordownload&filtObjObjId="+filtObjObjId);  
    }
    else
    {
        strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","date=" + vardate + "&Type=getlicensefordownload");
    }
    strresult = strresult.substring(0,strresult.length-2); 
    
    if(strresult != "")
    {
        var strArr = strresult.split('~#~#');
        for(var i=0; i<strArr.length-1; i++)
        {
            if(window.document.getElementById('netobj') && strArr[i] != "")
            {
                try
                {
                    window.document.getElementById('netobj').StoreLicense(strArr[i]);
                }
                catch(e){}
            }
        }
    }
}

function funStoreLicenseforDownloadedAssets(filtObjObjId) {
    var vardate = new Date();
    var strresult = "";
    var strError = "";
    if (filtObjObjId != "") {
        strresult = funGetHtmlFromJQuery("Xmlhttp.aspx", "date=" + vardate + "&Type=getlicensefordownload&mode=downloadedassets&filtObjObjId=" + filtObjObjId);
        strresult = strresult.substring(0, strresult.length - 2);
        if (strresult != "") {
            var strArr = strresult.split('~#~#');
            if (window.document.getElementById('netobj') && strArr[0] != "") {
                try {
                    window.document.getElementById('netobj').StoreLicense(strArr[0]);
                }
                catch (e) {
                    strError = "Error";
                }
            }
        }
    }

    return strError;
}

function funSeriesNavClick(id)
{
    var hdnCategoryLinkId = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCategoryLinkId");
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchMode"))
    {
        var strSearchMode = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchMode").value;
    }
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchText"))
    {
        var strSearchText = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleSearchText").value;
    }
    if(hdnCategoryLinkId && hdnCategoryLinkId.value != "")
    {
        window.document.location.href = "TitleDetailsHome.aspx?TitleId="+ id + "&Type=SN&TtlSrchMode=" + strSearchMode + "&TtlSrchTxt=" + strSearchText + "&CategoryLinkId=" + hdnCategoryLinkId.value;    
    }
    else
    {
        window.document.location.href = "TitleDetailsHome.aspx?TitleId="+ id + "&Type=SN&TtlSrchMode=" + strSearchMode + "&TtlSrchTxt=" + strSearchText;    
    }
}

//Sami:-DownloadNow-RelatedAssets.
function funDownloadRelatedAssets(Ids,AssetId)
{
    var vardate = new Date();
    var strresult = "";
    var fileObjObjId = document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId");
    if(fileObjObjId && fileObjObjId.value !="") {
        var RelatedAllChecked = "Y";
        var RelatedAssetsIds = Ids.split(',');
        for (var intCount = 0; intCount < RelatedAssetsIds.length-1; intCount++) {
            if (fileObjObjId.value.toLowerCase().indexOf(RelatedAssetsIds[intCount].toLowerCase()) == -1) {
                RelatedAllChecked = "N";
            }
        }
        if (RelatedAllChecked == "Y") {
            //Ids = Ids + AssetId;
            strresult = funGetHtmlFromJQuery("Xmlhttp.aspx", "date=" + vardate + "&Type=setrelatedassesfordwnld&fileObjObjId=" + Ids);

        }
        else {
            strresult = funGetHtmlFromJQuery("Xmlhttp.aspx", "date=" + vardate + "&Type=setrelatedassesfordwnld&fileObjObjId=" + fileObjObjId.value);
        
        }
        funOpenWinforMultipleDwnld('');
    }
    else
    {
        funBuildAlterMsg("Please select at least one asset to download", "OK");
        toggleVis('saveSearchDialog');
    }
    
    return false;
}

/***Sami: Remove Assest from cart after download functionality.************/
function funRemoveAssetsfromCartAfterDownload(fileObjObjId)
{
    var strresult = "";
    var vardate = new Date();
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    if(pageName && pageName.value == "AssetCart")
    {
        if(fileObjObjId && fileObjObjId != "")
        {
            strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","date=" + vardate + "&fileObjObjId=" + fileObjObjId + "&Type=removeassetsafterdownload");
        }
        else
        {
            strresult = funGetHtmlFromJQuery("Xmlhttp.aspx","date=" + vardate + "&Type=removeassetsafterdownload");
        }
        if(Trim(strresult) == "Y")
        {
            window.document.location.href = "AssetCart.aspx";
        }
    }
}
/***********************************************************************/

function funAssetActionConfirmationDialogAddtoCart(WprTitleId, TitleName, TitleCat, AssetType, AssetFormatType,Ids,AssetFileId,strParentSource,strAssetCartIds) 
{
    var vardate = new Date();
    var strresult = "";
    var fileObjObjId = document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId");
    if (fileObjObjId && fileObjObjId.value != "") {
        var RelatedAllChecked = "Y";
        var RelatedAssetsIds = Ids.split(',');
        var strResultIds = "";
        for (var intCount = 0; intCount < RelatedAssetsIds.length-1; intCount++) {
            if (fileObjObjId.value.toLowerCase().indexOf(RelatedAssetsIds[intCount].toLowerCase()) == -1) {
                RelatedAllChecked = "N";
            }
            if ((strAssetCartIds.toLowerCase().indexOf(RelatedAssetsIds[intCount].toLowerCase()) != -1) && (fileObjObjId.value.toLowerCase().indexOf(RelatedAssetsIds[intCount].toLowerCase()) != -1)) {
                strResultIds = strResultIds + RelatedAssetsIds[intCount].toLowerCase() + ",";
            }
        }
        if (RelatedAllChecked == "Y") {
//            if (AssetType.toLowerCase() != 'video' || (AssetType.toLowerCase() == 'video' && (strParentSource.toLowerCase() == 'dapr' || strParentSource.toLowerCase() == 'esprit'))) {
//                strResultIds = strResultIds + AssetFileId;
//            }
            strResult = funGetHtmlFromJQuery("Xmlhttp.aspx", "date=" + vardate + "&Type=insasset&FileObjObjId=" + strResultIds);
        }
        else {
            strResult = funGetHtmlFromJQuery("Xmlhttp.aspx", "date=" + vardate + "&Type=insasset&FileObjObjId=" + strResultIds);
        }
        funPBTrends(TitleName, WprTitleId, TitleCat, "", "addtocartfromassetconfirmationdialog", AssetType, AssetFormatType, "", "", "");
        var lblAssetsInCart = window.document.getElementById("ctl00_ctl00_MainMenu1_lblAssetsInCart");
        var lblBQAssetsInCart = window.document.getElementById("ctl00_ctl00_MainMenu1_lblBQAssetsInCart");
        if (lblAssetsInCart != null && strResult != null) {
            var strAssetCartCount = Trim(strResult.split('~')[0]);
            lblAssetsInCart.innerHTML = (strAssetCartCount == "1") ? strAssetCartCount + " asset" : strAssetCartCount + " assets";
        }
        if (lblBQAssetsInCart != null && strResult != null) {
            var strBQAssetCartCount = Trim(strResult.split('~')[1]);
            lblBQAssetsInCart.innerHTML = (strBQAssetCartCount == "1") ? strBQAssetCartCount + " BQ Asset" : strBQAssetCartCount + " BQ Assets";
        }
        var fileIds = fileObjObjId.value.split(',');
        for (var intCount = 0; intCount < fileIds.length; intCount++) 
        {
            if (window.document.getElementById("divCart_" + fileIds[intCount].toUpperCase()))
             {
                 var Id = window.document.getElementById("divCart_" + fileIds[intCount].toUpperCase());
                 var imgId = window.document.getElementById("imgADD_" + fileIds[intCount].toUpperCase());
                $("#" + Id.id).removeClass('titleCart_off');
                $("#" + Id.id).removeClass('titleCart_on');
                $("#" + Id.id).addClass('titleCart_on');
                $("#" + imgId.id).removeAttr("title");
                $("#" + imgId.id).attr("title", "remove from cart");
                

            }

        }
    }
    else {
        funBuildAlterMsg("Please select at least one asset for add to cart", "OK");
        toggleVis('saveSearchDialog');
    }
    
    return false;
}

function funSpotlightRefresh() {
    var vardate = new Date();
    funGetHtmlFromJQuery("Xmlhttp.aspx", "Date=" + vardate + "&Type=RefreshSpotlight");
}
function funClickOnRelatedAsset(TitleObjObjId, FileObjObjId, GroupValue, strParams, strMode) {
    var obj1 = window.document.getElementById("hdnIdCount").value;
    window.document.getElementById("hdnIdCount").value = obj1;
    window.document.getElementById("detailsWrappper").innerHTML = "";
    var vardate = new Date();
    var groupvalue = GroupValue;
    var strTtlObjObjId = TitleObjObjId;
    var strFileObjObjId = FileObjObjId;
    var strResult = funGetHtmlFromJQuery("Xmlhttp.aspx", "TtlObjObjId=" + strTtlObjObjId + "~" + vardate + "&FileId=" + strFileObjObjId + "&GroupValue=" + groupvalue + "&ParamArray=" + strParams + "&Type=TtlDetClick&Mode=" + strMode + "&GAClick=N");
    var strHTMLText = strResult.split('~^~^')[0];
    if (Trim(strHTMLText) != "") {
        window.document.getElementById("detailsWrappper").innerHTML = strHTMLText;
        if (document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId")) {
            document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAsstActConDlgCartId").value = strResult.split('~^~^')[1];
        }
    }
    else {
        toggleVis("divTitDetClick");
    }

    //The below method had been called for applying checkbox styles after asynchronous postback in the popUp.
    $().cssCartCheckbox();
    return false;
}
