/**
 * FOXFAST HTML BUILD - v3.0
 	- 11.5 added class switcher for playlist cart button in screening room
 */
// JavaScript Document


// ADD TO CART SWITCHER //
$(document).ready(function(){
        $(".plCart").click(function(){
                var $this = $(this);
                if( $this.is('.plCart_off') ) {
                        $this.removeClass('plCart_off');
                        $this.addClass('plCart_on');
                }
                else if( $this.is('.plCart_on') ) {
                        $this.removeClass('plCart_on');
                        $this.addClass('plCart_off');
                }
        });
});

$(document).ready(function(){
        $(".playListCart").click(function(){
                var $this = $(this);
                if( $this.is('.plCart_off') ) {
                        $this.removeClass('plCart_off');
                        $this.addClass('plCart_on');
                }
                else if( $this.is('.plCart_on') ) {
                        $this.removeClass('plCart_on');
                        $this.addClass('plCart_off');
                }
        });
});


// SCREENING ROOM ROW CLASS SWITCHER //

$(document).ready(function(){
$(".pl_off")
	.hover(
		function () {
			$(this).addClass('pl_hov');
		}, 
		function () {
			$(this).removeClass('pl_hov');
		}
	)
	.click(function(){
		$(this).addClass("pl_vis");
		$(".pl_on").each(function(){
			$(this).removeClass("pl_on");
		});
		$(this).addClass("pl_on");
		if ($("#screeningBody").is(":hidden")) {
			$("#screeningBody").slideDown("fast");
		}
		if ($("a.togglerMain").hasClass("togglerMain-opened")) {
			$('a.togglerMain').trigger('click');
		}
	});
$(".plRowCopy")
	.click(function(){
	    // Commented on 14-APR-2009: To avoid double call of click event in playlist for video playing. 
		//$(this).parent().trigger('click'); 
	});
});

// SORT OPTIONS SWITCHER //

function fauxRadios(id)
{
    var classSetting = document.getElementsByTagName("div");
        for (var i = 0; i < classSetting.length ; i++)
        {
			if (classSetting[i].id.indexOf("radioID") != -1) {
				classSetting[i].className="radio_off"; 
        	}
		}
    document.getElementById(id).className="radio_on";  
}

// STYLED RADIO BUTTONS SWITCHER //

function sortFauxRadios(id)
{
    var vardate = new Date();
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    var classSetting = document.getElementsByTagName("div");
        for (var i = 0; i < classSetting.length ; i++)
        {
			if (classSetting[i].id.indexOf("sortID") != -1) {
				classSetting[i].className="sortOptions_off"; 
        	}
		}
    document.getElementById(id).className="sortOptions_on";    
    if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnSortId"))
    {
        document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnSortId").value = id;

        if (pageName && (pageName.value == "BQAssetCart")) {
            if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnSortId")) {
                window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnSortId").value = id;
            }
        }
        else if (pageName && (pageName.value == "TitleDetailsList" || pageName.value == "AssetCart"))
        {
            // Updating the Userpreferences for this session.
            var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","Option="+ id + "~"+ vardate + "&Type=userprefupdate&AssetYN=Y");  
        }
        else
        {
            // Updating the Userpreferences for this session.
            var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","Option="+ id + "~"+ vardate + "&Type=userprefupdate");  
        }
        if (window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo") != null) 
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCurrentPageNo").value = "1";
        }
        // Doing Asyncronous PostBack for the TitleList Page.
        funTitleListAsyncronouPostBack('N');
    }
}
function sortFauxPlaylistRadios(id)
{
    var vardate = new Date();
    var classSetting = document.getElementsByTagName("div");
    for (var i = 0; i < classSetting.length ; i++)
    {
		if (classSetting[i].id.indexOf("sortPlaylistID") != -1) {
			classSetting[i].className="sortOptions_off"; 
    	}
	}
    document.getElementById(id).className="sortOptions_on";
    if(window.document.getElementById("ctl00_ctl00_Playlist1_hdnPlaylistSortBy"))
    {
        window.document.getElementById("ctl00_ctl00_Playlist1_hdnPlaylistSortBy").value = id;
        funBuildUserPlaylist(); 
    }
}
// VIEW OPTIONS SWITCHER

function viewFauxRadios(id)
{
    var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
    var divShowHierarchy = document.getElementById("ctl00_ctl00_BodyContent_Views1_divShowHierarchy")
    var vardate = new Date();
    var classSetting = document.getElementsByTagName("div");
    for (var i = 0; i < classSetting.length ; i++)
    {
		if (classSetting[i].id.indexOf("viewID") != -1) {
			classSetting[i].className="viewOptions_off"; 
    	}
	}
    document.getElementById(id).className="viewOptions_on";  
    
    document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnViewId").value = id;
    
    if(id == "viewID3")
    {
        var chkCount = 0;
        var hdnSeriesLinkIds = document.getElementById("ctl00_ctl00_BodyContent_Views1_hdnSeriesLinkIds")
        var hdnTitleMenuItem = document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleMenuItem");
        var pageName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnPageName");
        var hdnCategories = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnCategories");
        var hdnShowHierarchy = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnShowHierarchy");
        
        if(hdnShowHierarchy)
        {
            hdnShowHierarchy.value = "Y";
        }
    }
    else if(divShowHierarchy)
    {
        if(hdnShowHierarchy)
        {
            hdnShowHierarchy.value = "N";
        }
    }
    
    if(pageName && (pageName.value == "TitleCart" || pageName.value == "AssetCart" || pageName.value == "BQAssetCart"))
    {
        if(window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleViewId"))
        {
            window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnTitleViewId").value = id;
        }
    }
    else if(pageName && pageName.value == "TitleDetailsList")
    {
        // Updating the Userpreferences for this session.
        var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","Option="+ id + "~"+ vardate + "&Type=userprefupdate&AssetYN=Y");  
    }
    else
    {
        // Updating the Userpreferences for this session.
        var strResult =  funGetHtmlFromJQuery("Xmlhttp.aspx","Option="+ id + "~"+ vardate + "&Type=userprefupdate");  
    }
   
    // Doing Asyncronous PostBack for the TitleList Page.
    funTitleListAsyncronouPostBack('N');
}

// ADD TO FAVORITES SWITCHER //
$(document).ready(function(){
        $(".favSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titleFav_off') ) {
                        $this.removeClass('titleFav_off');
                        $this.addClass('titleFav_on');
                }
                else if( $this.is('.titleFav_on') ) {
                        $this.removeClass('titleFav_on');
                        $this.addClass('titleFav_off');
                }
        });
});

// ADD TO CART SWITCHER //
$(document).ready(function(){
        $(".cartSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titleCart_off') ) {
                        $this.removeClass('titleCart_off');
                        $this.addClass('titleCart_on');
                }
                else if( $this.is('.titleCart_on') ) {
                        $this.removeClass('titleCart_on');
                        $this.addClass('titleCart_off');
                }
        });
});

// ADD TO PLAYLIST SWITCHER //
$(document).ready(function(){
        $(".playlistSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titlePlaylist_add') ) {
                        $this.removeClass('titlePlaylist_add');
                        $this.addClass('titlePlaylist_remove');
                }
                else if( $this.is('.titlePlaylist_remove') ) {
                        $this.removeClass('titlePlaylist_remove');
                        $this.addClass('titlePlaylist_add');
                }
        });
});

// HOVER PLAYLIST SWITCHER //
$(document).ready(function(){
        $(".vidHovPlaylist").click(function(){
                var $this = $(this);
                if( $this.is('.hovplaylist_add') ) {
                        $this.removeClass('hovplaylist_add');
                        $this.addClass('hovplaylist_remove');
                }
                else if( $this.is('.hovplaylist_remove') ) {
                        $this.removeClass('hovplaylist_remove');
                        $this.addClass('hovplaylist_add');
                }
        });
});

// TOGGLE VIIBILITY FOR DIALOG BOXES //
function toggleVis(obj, funName) {
        var el = document.getElementById(obj);
        if ( el.style.display != 'none' )
        {
            el.style.display = 'none';
        }
        else
        {
            el.style.display = '';
            
            if(funName && document.getElementById("hdnfunName") != null)
            {
                var SavedSearchId = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdvSrchSaveSearch");
                var hdnAdvSrchSearchName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdvSrchSearchName");
                
                if(SavedSearchId != null)
                {
                    if(funName == "funCopyAsNewSearch" || funName == "funRenameSavedSearch")
                    {
                        if(SavedSearchId.value == "")
                        {
                            el.style.display = 'none';
                            if(funName == "funCopyAsNewSearch")
                            {
                                funBuildAlterMsg("Please select a Title Search to Save.", "OK");
                            }
                            else
                            {
                                funBuildAlterMsg("Please select a Title Search to Rename.", "OK")
                            }
                            toggleVis('saveSearchDialog');
                        }
                        else
                        {
                            if(hdnAdvSrchSearchName && hdnAdvSrchSearchName.value == "")
                            {
                                el.style.display = 'none';
                                if(funName == "funCopyAsNewSearch")
                                {
                                    funBuildAlterMsg("Please select a Title Search to Save.", "OK");
                                }
                                else
                                {
                                    funBuildAlterMsg("Please select a Title Search to Rename.", "OK")
                                }
                                toggleVis('saveSearchDialog');
                            }
                            else
                            {
                                window.document.getElementById("titleSearchTitle").value = "";
                                document.getElementById("hdnfunName").value = funName;
                            }
                        }
                    }
                    else
                    {
                        window.document.getElementById("titleSearchTitle").value = "";
                        var AdvSrchSearchName = window.document.getElementById("ctl00_ctl00_BodyContent_SubBodyContent_hdnAdvSrchSearchName").value; 
                        document.getElementById("hdnfunName").value = funName;
                        if(SavedSearchId.value != "" && AdvSrchSearchName != "")
                        {
                            el.style.display = 'none';
                            funSaveSearch(AdvSrchSearchName);
                        }
                    }
                }
            }
        }
                
    }
	
// GROUP ASSETS BY CATEGORY FAUX CHECKBOX SWITCHER //

$(document).ready(function(){
						   
        $(".groupCheckbox").click(function(){
                var $this = $(this);
                if( $this.is('.group_off') ) {
                        $this.removeClass('group_off');
                        $this.addClass('group_on');
                }
                else if( $this.is('.group_on') ) {
                        $this.removeClass('group_on');
                        $this.addClass('group_off');
                }
        });
		
});



/*For applying styles for favourite and add to cart.*/

// ADD TO FAVORITES SWITCHER //
function SetFavoritesYN()
{
        $(".favSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titleFav_off') ) {
                        $this.removeClass('titleFav_off');
                        $this.addClass('titleFav_on');
                }
                else if( $this.is('.titleFav_on') ) {
                        $this.removeClass('titleFav_on');
                        $this.addClass('titleFav_off');
                }
        });
}

// ADD TO CART SWITCHER //
function SetAddtoCartYN()
{
        $(".cartSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titleCart_off') ) {
                        $this.removeClass('titleCart_off');
                        $this.addClass('titleCart_on');
                }
                else if( $this.is('.titleCart_on') ) {
                        $this.removeClass('titleCart_on');
                        $this.addClass('titleCart_off');
                }
        });
        //Added by Anil on 12.12.2008 for Text view in TitleDetailslist.
        $(".plCart").click(function(){
            var $this = $(this);
            if( $this.is('.plCart_off') ) {
                    $this.removeClass('plCart_off');
                    $this.addClass('plCart_on');
            }
            else if( $this.is('.plCart_on') ) {
                    $this.removeClass('plCart_on');
                    $this.addClass('plCart_off');
            }
        });
}
//Added by Anil on 13.Jan.2009 for PlaylistYN on asyn postback.
function SetPlaylistYN()
{
    $(document).ready(function(){
        $(".playlistSwitch").click(function(){
                var $this = $(this);
                if( $this.is('.titlePlaylist_add') ) {
                        $this.removeClass('titlePlaylist_add');
                        $this.addClass('titlePlaylist_remove');
                }
                else if( $this.is('.titlePlaylist_remove') ) {
                        $this.removeClass('titlePlaylist_remove');
                        $this.addClass('titlePlaylist_add');
                }
        });
    });
}
//Added by Anil on 20.Jan.2008 for PlaylistRow Hover on asyn postback.
function funSetPlaylistRowHover()
{
    $(document).ready(function(){
    $(".pl_off")
	    .hover(
		    function () {
			    $(this).addClass('pl_hov');
		    }, 
		    function () {
			    $(this).removeClass('pl_hov');
		    }
	    )
	    .click(function(){
		    $(this).addClass("pl_vis");
		    $(".pl_on").each(function(){
			    $(this).removeClass("pl_on");
		    });
		    $(this).addClass("pl_on");
		    if ($("#screeningBody").is(":hidden")) {
			    $("#screeningBody").slideDown("fast");
		    }
		    if ($("a.togglerMain").hasClass("togglerMain-opened")) {
			    $('a.togglerMain').trigger('click');
		    }
	    });
    $(".plRowCopy")
	    .click(function(){
	    // Commented on 14-APR-2009: To avoid double call of click event in playlist for video playing. 
		//    $(this).parent().trigger('click');
	    });
    });
}
function funSetPlaylistCartYN()
{
    //Added by Anil on 12.12.2008 for Text view in TitleDetailslist.
        $(".playListCart").click(function(){
            var $this = $(this);
            if( $this.is('.plCart_off') ) {
                    $this.removeClass('plCart_off');
                    $this.addClass('plCart_on');
            }
            else if( $this.is('.plCart_on') ) {
                    $this.removeClass('plCart_on');
                    $this.addClass('plCart_off');
            }
        });
}


function SetCartOnOff(obj)
{
    if( obj.className.indexOf('titleCart_off') > -1) 
    {
        $("#"+obj.id).removeClass('titleCart_off');
        $("#"+obj.id).addClass('titleCart_on');
    }
    else 
    {
        $("#"+obj.id).removeClass('titleCart_on');
        $("#"+obj.id).addClass('titleCart_off');
    }
}

function SetFavOnOff(obj)
{
    if(  obj.className.indexOf('titleFav_off') > -1) 
    {
            $("#"+obj.id).removeClass('titleFav_off');
            $("#"+obj.id).addClass('titleFav_on');
    }
    else
    {
            $("#"+obj.id).removeClass('titleFav_on');
            $("#"+obj.id).addClass('titleFav_off');
    }
}