
/* Start - Functions are load after page load */

DetectAllBrowser();

/* End - Functions are load after page load */

// ------------------------------------function to selected channel--------------------------------------------------------------------------------------------------------------------//
function getCategoryVal() {
    var selectedValue = $("select[id$=catList]").val();
    $("input[id$='hidjCarouselbtnClick']").val('');
    return selectedValue;
}

// ------------------------------------function to to post the page to server--------------------------------------------------------------------------------------------------------------------//
function PostVideoWithID(ID) {
    $("input[id$='_hidVideoID']").val(ID);
    $("input[id$='btnPost']").trigger("click");
}
// ------------------------------------function to select the videoid--------------------------------------------------------------------------------------------------------------------//
function GetSelectedID() {
    return $("input[id$='_hidVideoID']").val();
}

// ------------------------------------function to curent page number with class-------------------------------------------------------------------------------------------------------------------//
function SetPageClass(pageNumber) {
    $("#divPaging a").removeClass('current');
    if (pageNumber > 0)
        $("#dvPageNumber" + parseInt(pageNumber)).addClass("current");
}
// ------------------------------------function to get current player value-------------------------------------------------------------------------------------------------------------------//

function GetTIMEToRedirect(currentPlayer) {
    $("#" + hidPlayerSeekTime + "").val(currentPlayer.position);
}

// ------------------------------------function to set when no records found-------------------------------------------------------------------------------------------------------------------//

function SetNoResultFound() {
    searchText = $("#search").val(""); categoryID = $("#catList").val("-1")
    CallSearch($('#hidflag').val(), '');
}

// ------------------------------------function to handle keydown process-------------------------------------------------------------------------------------------------------------------//

function HandleKeyDown(event) {
    if ($("input[id$='hid_RowCount']").val() == 1) {
        $("input[id$='hid_ArrowVisibleCheck']").val(1)
    }
    var keyCode = "";
    if (window.event)
        keyCode = event.keyCode;
    else if (event.which)
        keyCode = event.which;
    if (keyCode == 13) CallSearch($('#hidflag').val(), '');
}
// ------------------------------------function to handle onloda  process-------------------------------------------------------------------------------------------------------------------//
function DialogAction(value) {
    var $IsEmbedModel = $("#embedValue").val();
    if (Validate(value)) return;
    if (value == "close") {
        $("#dialog").dialog(value);
        $("#dialog").hide();
        if ($IsEmbedModel == "True") {
            $('#hiddenTextBox').focus();
        }
        return;
    }
    $("#dialog").show();
    $('#dialog_link').trigger("click");
}
// ------------------------------------function to validate object-------------------------------------------------------------------------------------------------------------------//

function Validate(value) {
    if (value == null || value == undefined) return true;
    return false;
}

// ------------------------------------function to set page style-------------------------------------------------------------------------------------------------------------------//

function SetPageStyle() {
    $('.page').attr('href', '#');
    $('ul.thumbs li').mouseover(function() { $(this).addClass('thumb-mouseover'); }).mouseout(function() { $(this).removeClass('thumb-mouseover'); });
}

// ------------------------------------function to handle rating-------------------------------------------------------------------------------------------------------------------//
function HandleRating() {
    $('input.auto-submit-star').rating({
        callback: function(value, link) {
            Default.InsertRating($("#hidRatingVideoID").val(), value, function(isRated) {
                if (isRated.value) {
                    $("#divRatingMessage").html("Already rated").addClass("Red smallText");
                }
                else {
                    $("#hidRatedValue").val(value);
                    $("#divRatingMessage").removeClass("Red smallText");
                    $("#divRatingMessage").html("Thanks for rating").addClass("smallText");
                }
                SetRating(value);
            });
        }
    });
    $('input.auto-submit-star').rating({ curvalue: 3 });
}

// ------------------------------------function to set search box title-------------------------------------------------------------------------------------------------------------------//

function SetSearchBoxTitle() {
    $("#search").example(function() {
        return $(this).attr('title');
    }, { className: 'quite' });
}
// ------------------------------------function to LoadWaitingDialog-------------------------------------------------------------------------------------------------------------------//
function LoadWaitingDialog() {
    if ($IsEmbedModel == "True") {
        $('#dialog').dialog({ autoOpen: false, width: 300, modal: false, position: [350, 250] });
        $('#dialog_link').click(function() { $('#dialog').dialog('open'); return false; });
        $("#loading").hide();
    }
    else {
        $('#dialog').dialog({ autoOpen: false, width: 300, modal: false });
        $('#dialog_link').click(function() { $('#dialog').dialog('open'); return false; });
        $("#loading").hide();
    }
}

// ------------------------------------function to check password------------------------------------------------------------------------------------------------------------------//
function checkPassword() {
    if ($("input[id$='txtpassword']").val().length == 0) {
        alert('Please enter password');
        return false;
    }
    return true;
}
// ------------------------------------function to HideRating------------------------------------------------------------------------------------------------------------------//
function HideRating() {
    $("#divRatingWithViews").hide();
}

// ------------------------------------function to HideModalPopup------------------------------------------------------------------------------------------------------------------//
function HideModalPopup() {
    HideModalPopupForPasswordCheck();
    $("#divSchedule").hide();
    AssignDefaultPlayerBehaviour("#ctl00_mainContentPlaceHolder_hidDefaultVideo");
    testvariable = true;
}
// ------------------------------------function to HideModalPopupForPasswordCheck------------------------------------------------------------------------------------------------------------------//
function HideModalPopupForPasswordCheck() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    $("input[id$='txtpassword']").val('');
    setTimeout("StartPlayer()", 1000);
    var $modal = $find('ctl00_mainContentPlaceHolder_ModalPopupExtender1');
    $modal.hide();
    if ($isNarrowEmbedModel == "True") {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            FadeOutEnableLogos();
        }
    }
    ReduceMarginHeight();
    $("#hidIsLive").val("false");

}
// ------------------------------------function to ShowMoreInfo------------------------------------------------------------------------------------------------------------------//

function ShowMoreInfo() {
    $("#OverFlowDiv").show(); $("#divDescription").hide();
}

function ShowLongTitle() {
    $("#OverFlowTitle").show(); $("#divTitle").hide();
}

// ------------------------------------function to OpenEmailFriendWindow Embed------------------------------------------------------------------------------------------------------------------//

function OpenEmailFriendWindow() {
    var Path = document.location.href.toLowerCase().split('?')[0];
    var link = "?CloseWindow=true&ItemId=" + GetSelectedID() + "&AdditionalMessage=" + Path + "?ItemId=" + GetSelectedID() + "&emailfriend=true";
    window.open($("a[id$='virualPath']").attr("href") + "Comments.aspx" + link, '_blank', 'height=680,width=610,left=650,scrollbars=yes');
}

function CheckOpenEmailFriendWindow() {
    if ($IsEmbedModel == "True") {
        var Path = document.location.href.toLowerCase().split('?')[0];
        var link = "?CloseWindow=true&ItemId=" + GetSelectedID() + "&AdditionalMessage=" + Path + "?ItemId=" + GetSelectedID() + "&emailfriend=true";
        window.open($("a[id$='virualPath']").attr("href") + "Comments.aspx" + link, '_blank', 'height=715,width=310,left=460,scrollbars=yes');
    }
    else {
        OpenEmailFriendWindow();
    }
}

// ------------------------------------function to OpenCommentWindow Standalone------------------------------------------------------------------------------------------------------------------//
function OpenAbuseWindow() {
    var Path = document.location.href.toLowerCase().split('?')[0];
    var link = "?CloseWindow=true&ItemId=" + GetSelectedID() + "&abusereport=true&AdditionalMessage=" + Path + "?ItemId=" + GetSelectedID();
    window.open($("a[id$='virualPath']").attr("href") + "Comments.aspx" + link, '_blank', 'height=680,width=610,left=650,scrollbars=yes');
}

function CheckAbuseWindows() {
    if ($IsEmbedModel == "True") {
        var Path = document.location.href.toLowerCase().split('?')[0];
        var link = "?CloseWindow=true&ItemId=" + GetSelectedID() + "&abusereport=true&AdditionalMessage=" + Path + "?ItemId=" + GetSelectedID();
        window.open($("a[id$='virualPath']").attr("href") + "Comments.aspx" + link, '_blank', 'height=500,width=310,left=460,scrollbars=yes');
    }
    else {
        OpenAbuseWindow();
    }
}

// ------------------------------------function to HideInvite------------------------------------------------------------------------------------------------------------------//

function HideInvite() {

    if ($('#hidRatingVideoID').val() == "") $('#divEmailFriends').attr("class", "home-suggest-report hide")

    else $('#divEmailFriends').attr("class", "home-suggest-report")
}
// ------------------------------------function to HideDIV------------------------------------------------------------------------------------------------------------------//
function HideDIV() {
    if ($("a[id$='alive']").length == 0) $("#divLive").hide();
    if ($("a[id$='acontact']").length == 0) $("#divContact").hide();
    if ($("a[id$='aschoolhome']").length == 0) $("#divVisit").hide();
}

// ------------------------------------function to FindHWCDNURL------------------------------------------------------------------------------------------------------------------//
function FindURL(filename) {
    if (filename == "") {
        ClientServices.GetVideoUrl('default', oncomplete, ontimeout, onerror);
    }
    else {
        ClientServices.GetVideoUrl(filename, oncomplete, ontimeout, onerror);
    }
}
// ------------------------------------function to getSearchString------------------------------------------------------------------------------------------------------------------//

function getSearchString() {
    var searchTitle = "enter search term here"
    var searchText = $("#search").val().replace('/\s/', '').toLowerCase();
    $("input[id$='hidjCarouselbtnClick']").val('');
    if (searchText == searchTitle) {
        searchText = "";
    }
    return searchText;
}
// ------------------------------------function to CheckNoData------------------------------------------------------------------------------------------------------------------//

function CheckNoData(value) {
    if (value == '' && typeof (value) == 'string') {
        $("#fillJson").html("<a href='javascript:SetNoResultFound();';>No titles matched your search term(s), please select a different channel and/or search term(s).</a>");
        $("#divPaging").html('');
        if (trim($("select").text()) == "All Channels (0)") {
            $("#fillJson a").removeAttr("href");
            $("select,input[id$='search'],a[id$='searchLnk'],a[id$='lnkAdvanced'],div[id$='lnkRecent'],div[id$='lnkViewed'],img[id$='btnSearch']")
            .attr("disabled", "true")
            .removeAttr("onclick")
            .removeAttr("href");
            $("#searchLnk")
            .removeAttr("href").removeAttr("onclick");
        }
        if (AdvanceSearch.toLocaleLowerCase().length > 0) return;
        return;
    }
    if (value == 0 && typeof (value) == 'number') {
        $("#fillJson").html("<a href='javascript:SetNoResultFound();';>There are currently no videos approved for viewing at this site. Please contact the Site Administrator to request videos be uploaded and approved for viewing.</a>");
        $("#divPaging").html('');
        return;
    }
    if (value == null && typeof (value) == 'object') {
        $("#fillJson").html("<a href='javascript:SetNoResultFound();';>No videos found for your search.</a>");
        $("#divPaging").html('');
        return;
    }
}
// ------------------------------------function to set style for most new videos------------------------------------------------------------------------------------------------------------------//
function SetStyleForNewVideos() {
    $('.most-viewed, .new-videos').hover(function() { $(this).addClass("elevate"); }, function() { $(this).removeClass("elevate"); });
    $('.most-viewed').click(function() {
        $(this).addClass("current sorted");
        $(".new-videos").removeClass("current");
    });
    $('.new-videos').click(function() {
        $(this).addClass("current sorted");
        $(".most-viewed").removeClass("current");
    });
}

//-----------------------------------function to set pager------------------------------------------------
function fnSetPager() {
    $("input:text[id$='txtShow']").val($(".pagesize").val())
}

//-----------------------------------function to SetPasswordForDefault------------------------------------------------
function SetPasswordForDefault(source, args) {
    var passwordValue = document.getElementById('ctl00_mainContentPlaceHolder_txtPassword').value;
    if (document.getElementById('ctl00_mainContentPlaceHolder_chkDefault')) {
        if (document.getElementById('ctl00_mainContentPlaceHolder_chkDefault').checked == true && passwordValue.length > 0) {
            args.IsValid = false;
            return false;
        }
    }
    args.IsValid = true;
}
//-----------------------------------function to SetPasswordForSiteDefault------------------------------------------------
function SetPasswordForSiteDefault(source, args) {
    var passwordValue = document.getElementById('ctl00_mainContentPlaceHolder_txtPassword').value;
    if (document.getElementById('ctl00_mainContentPlaceHolder_chkSiteDefault')) {
        if (document.getElementById('ctl00_mainContentPlaceHolder_chkSiteDefault').checked == true && passwordValue.length > 0) {
            args.IsValid = false;
            return false;
        }
    }
    args.IsValid = true;
}
//-----------------------------------function to default Rating------------------------------------------------ 
function SetDefaultRating() {
    $("div.home-video-rating").live("mouseout", function() {
        SetRating($currentRate);
    });

}
//-----------------------------------function to set value to controls------------------------------------------------ 
function SetRating($currentRate) {
    $currentRate = $("#hidRatedValue").val().length > 0 ? $("#hidRatedValue").val() : $currentRate;
    $("div.star-rating-on").removeClass("star-rating-on");
    $("div.star-rating").each(function(i) {
        if (i <= $currentRate - 1) $(this).addClass("star-rating-on");
    });
}
//-----------------------------------function to Change JDLad's------------------------------------------------   

function ChangeJDLImg(src, ID) {
    $("#" + ID).attr('src', src);
}

var hidFlagValue;
//-----------------------------------function to Call Search------------------------------------------------

function CallSearch(flag, IsadvancedClick) {
    if (flag == "") {
        $("input[id$='hidflag']").val(4);
    }
    if ($("input[id$='hidflag']").val() == 4 && $("input[id$='hid_RowCount']").val() == 1) {
        hidFlagValue = $("input[id$='hidflag']").val();
        $("input[id$='hidflag']").val("");
        flag = "";
    }
    if (flag == 1) {
        $("input[id$='hid_IsNewandMostViewed']").val(1);
        $("input[id$='hid_ArrowVisibleCheck']").val(1);
        $("#lnkRecent").parent(".tab").addClass("current");
        $("#lnkViewed").parent(".tab").removeClass("current");
        $("input[id$='hidjCarouselbtnClick']").val('');
    } else if (flag == 2) {
        $("input[id$='hid_IsNewandMostViewed']").val(1);
        $("input[id$='hid_ArrowVisibleCheck']").val(1);
        $("#lnkViewed").parent(".tab").addClass("current");
        $("#lnkRecent").parent(".tab").removeClass("current");
        $("input[id$='hidjCarouselbtnClick']").val('');
    }
    DialogAction("click");
    if (flag != "") $("#hidflag").val(flag);
    Default.SearchVideos(getSearchString(), getCategoryVal(), flag, IsadvancedClick, GetResult, 0);
    currentPageNumber = 0;
}

//-----------------------------------function to check pagenumbers------------------------------------------------       
function CheckPageNumbers() {
    if ($("#divPaging a").length == 1) $("#divPaging").html('');
}
//-----------------------------------function to get selected pagenumber------------------------------------------------   
function GetSelectPageItem(PageNo) {
    var selectedValue = $("select[id$=catList]").val();
    if (selectedValue.indexOf(".aspx") > 0)
        $("select[id$=catList]").val("-1");
    $("#hidCurPgNo").val(PageNo);
}

//-----------------------------------function to get GetCurrentPageItems------------------------------------------------   

function GetCurrentPageItems(pageNumber) {
    var SelectPage = $("#hidCurPgNo").val();
    currentPageNumber = SelectPage;
    DialogAction("click");
    Default.GetCurrentPageItems(SelectPage, getSearchString(), getCategoryVal(), $('#hidflag').val(), pageNumber, GetResult);
    SetPageClass(SelectPage);
}



//------------------------------------------------------------------ SHOW MODEL POPUP ----------------------------------------------------------------------------------//  

function ShowModalpopup($IsLive) {
    $("#divPassword").removeClass("hide defaultPasswordModalPopup").addClass("show defaultPasswordModalPopup");
    $("#divLiveEvent").hide();
    var isLive = ($IsLive == '' ? IsLive : "False");
    if (isLive == "True") $("#divLiveEvent").show();
    var $modal = $find('ctl00_mainContentPlaceHolder_ModalPopupExtender1');
    $modal.show();
    NarrowEmbedShowModelPopup();
    $("input[id$='txtpassword']").focus();
    $('#flashbanner').html('');
}

//--------------------------------------------------------------------  REDIRECT PPV -----------------------------------------------------------------------------------//
function RedirectPPV($VideoID) {
    if ($VideoID == "") $VideoID = 0;
    DialogAction("click");
    ReduceMarginHeight();
    Default.RedirectPPV($VideoID, function(resultObj) {
        var result = resultObj.value;
        if (Validate(result)) {
            DialogAction("close");
            RedirectPPV($VideoID)
            return;
        }
        if (result.length > 0) {
            DialogAction("close");
            var serializer = Sys.Serialization.JavaScriptSerializer;
            var data = serializer.deserialize(result);
            $("input[id$='hidVideoDetails']").val(data.SelectedVideoDetails);
              
            if (data.TerritorySiteUrl != "") {
                StopPlayer();
                window.open(data.TerritorySiteUrl, 'blank', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=1,scrollbars=1,menubar=1,location=1,status=1,titlebar=1', true);
                return;
            }
            
            if (data.AssociatedFiles != "") {
                $("#divAssociatedFiles").removeClass("hide").addClass("show");
                var associatedFilesLink = data.AssociatedFiles;
                $("#lblDownload").val(associatedFilesLink);
            }
            else {
                $("#divAssociatedFiles").removeClass("show").addClass("hide");
            }
            if (data.IsPreviewed) {

                SetMetaDataDetails($VideoID);
                var $PaymentUrl = data.PreviewdUrl;
                var $IsLiveCancelCheck = data.IsLiveCancelCheck;
                StopPlayer();
                VideoAlreadyPreviewed($PaymentUrl, $IsLiveCancelCheck);
            }
            if (data.IsFreeVideo) {

                SetMetaDataDetails($VideoID);
                $("#divSchedule").hide();
                var $Url = data.VideoFileName;
                FindURL($Url);
                PostVideoWithID($VideoID);
            }
            if (data.HasPassword) {
                $("input[id$='_hidVideoID']").val($VideoID);
                StopPlayer();
                setTimeout("ShowModalpopup('F')", 500);
            }
            $("#hidIsDefaultVideo").val("False");
            GetShareLink($VideoID, data.VideoFileName, data.ShareURL);
        }
    })
};

//---------------------------------------------------------------- ASSIGN PLAYER FOR LIVE -------------------------------------------------------------------------------------------//  
function AssignPlayerForLive(FileName, VT, VD, isHavePw) {
    ShowBaseDiv();
    $("#ctl00_mainContentPlaceHolder_sharelink").hide();
    $("#ctl00_mainContentPlaceHolder_divEmailFriends").removeClass('show').addClass('hidden');
    $("#divRatingWithViews").hide();
    $("#divSchedule").show();
    $("#divTitle").html(VT);
    $('#OverFlowDivContent').html(VD);
    $('#OverFlowTitleContent').html(VT);
    $("#divDescription").html(VD);

    if(VT!=undefined)
    {
        if (VT.length > 30) 
        {
            if (VT.length <= 200)
                $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + VT + '</div>');
            else
                $("#divTitle").html('<div style="height:55px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + VT + '</div>'); //Included wordWrap                   
        }
        else $("#divTitle").html(VT.replace("//", "\\").substr(0, 30));
    }

    if(VD!=undefined)
    {
        if (VD.length > 30) 
        {
            if (VD.length <= 213)
                $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + VD + '</div>');
            else
                $("#divDescription").html('<div style="height:60px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + VD + '</div>'); //Included wordWrap   
        }
        else $("#divDescription").html(VD.replace("//", "\\").substr(0, 30));
    }
    
    if ($IsEmbedModel == "True") {
        if (VD.length > 30) {
            if (VD.length <= 213)
                $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + VD + '</div>');
            else
                $("#divDescription").html('<div style="height:43px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + VD + '</div>'); //Included wordWrap   
        }
        else $("#divDescription").html(VD.replace("//", "\\").substr(0, 30));
    }

    HideRating();
    ReduceMarginHeightForLive();

    if (isHavePw == "true") {
        $("#hidIsLive").val(true);
        setTimeout("ShowModalpopup('')", 2500);
        StopPlayer();
        return;
    }
    var autoStart = true;
    if (IsPlayable.toLocaleLowerCase() == "true") autoStart = false;

    if ($isNarrowEmbedModel == "True") 
    {
        var aPlayer = new LiveGamePlayer(502, 287, autoStart, '', FileName);
    }
    else 
    {
        var aPlayer = new LiveGamePlayer(582, 327, autoStart, '', FileName);
    }
    aPlayer.GetPlayer();
}

//---------------------------------------------------------------- EVENT HANDLER FUNCTION -------------------------------------------------------------------------------------------------------//

function AddClickEventHandler(obj, _longTitle, $view) {
    $(obj).click(function() {
        RedirectPPV($(obj).find('div._ID').html());
        $("#divRatingMessage").html("");
        $("#divRatingWithViews").show();
    });
}

//----------------------------------------------------------------- CALLED WHEN USER CLICKS OK --------------------------------------------------------------------------------------------------------//   

function onOk(id) {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if ($("input[id$='txtpassword']").val().length == 0) {
        if ($isNarrowEmbedModel == "True") {
            if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
                FadeOutEnableLogos();
            }
        }
        alert('Enter the password');
        ReduceMarginHeight();
        AssignDefaultPlayerBehaviour("#ctl00_mainContentPlaceHolder_hidDefaultVideo");
        $("#divSchedule").hide();     // This line is must when live video is played in default page with password or without password //
        return;
    }

    var isLive = $("#hidIsLive").val() == "false" ? "False" : IsLive;

    var resultObj = Default.CheckPassword($("input[id$='txtpassword']").val(), isLive, $("input[id$='hidLiveDetails']").val(), $("input[id$='hidVideoDetails']").val());
    var result = resultObj.value;
    if (result.length > 0) {
        if ($isNarrowEmbedModel == "True") {
            if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
                FadeOutEnableLogos();
            }
        }
        var serializer = Sys.Serialization.JavaScriptSerializer;
        var data = serializer.deserialize(result);

        if (data.HasPassword) {
            $filename = data.VideoFileName;
            $videoid = data.VideoID;
            SetMetaDataDetails($videoid);
            $("#divSchedule").hide();
            FindURL($filename);
            HideModalPopupForPasswordCheck();
        }
        if (data.Live) {
            if(data.StreamingUrl==undefined){
                data.StreamingUrl=data.VideoFileName.split("*#*")[0];
            }
            AssignPlayerForLive(data.StreamingUrl, data.LiveTitle, data.LiveDescription, "false");
            HideModalPopupForPasswordCheck();
        }
    }
    else {
        if ($isNarrowEmbedModel == "True") {
            if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
                FadeOutEnableLogos();
            }
        }
        alert('You have entered an incorrect password');
        ReduceMarginHeight();
        $("input[id$='txtpassword']").val('');
        AssignDefaultPlayerBehaviour("#ctl00_mainContentPlaceHolder_hidDefaultVideo");
        $("#divSchedule").hide();     // This line is must when live video is played in default page with password or without password //
        setTimeout("StartPlayer()", 1000);
    }
    return true;
}

//--------------------------------------------------------------------- function to load data into html elements -----------------------------------------------------------//
function GetResult(response) {
    var myArray1 = new Array();
    if ($("input[id$='hid_RowCount']").val() == 1) {
        if (response.value == null) return;
        myArray1.length = response.value.split('_ID').length;
        if (myArray1.length > 8) {
            var len = response.value.lastIndexOf('_ID');
            var last = response.value.lastIndexOf(']');
            var sentence = response.value.slice(len - 4, last);
            response.value = response.value.replace(sentence, "");
        }
    }
    DialogAction("close");
    if (response.value == null) return;
    var jsondata = (response.value.split('!|*#$')[0]);
    var CPageNo = (response.value.split('!|*#$')[1]);
    $("#divPaging").html(CPageNo);
    $("#divPaging a").addClass('page');
    CheckPageNumbers();
    CheckNoData(jsondata);
    if (Validate(jsondata)) return;
    if (response.value == "") return;

    var myJsonObject = JSON.parse((response.value.replace("	", "").split('!|*#$')[0]));
    if ($("input[id$='hid_RowCount']").val() == 1) {
        $("#fillJson").html("<div class='jcarousel-container jcarousel-container-horizontal'><ul id='mycarousel'class='thumbs clearfix11 jcarousel-skin-tango'><li class='_items'><div class='_thumbnailFileName'></div><div class='_title'></div><div class='_longtitle' style='display: none;'></div><div class='_isHavingPassword' style='display: none;'></div><div class='_description' style='display: none;'></div><div class='_videoFileName' style='display: none;'></div><div class='_ID' style='display: none;'></div><div class='_viewCount'></div><div class='_uploadedDate' style='display: none;'></div><div class='_rating'></div><div class='_price' style='display: none;'></div><div class='_freeViewingDuration' style='display: none;'></div><div class='_isGsVideo' style='display: none;'></div><div class='_SchoolId' style='display: none;'></div><div class='_isSiteDefault' style='display: none;'></div><div class='_isDefault' style='display: none;'></div></li></ul></div>");
        RatingDisplay();
        ViewCountDisplay();
        ReduceMarginHeight();
    }
    else {
        $("#fillJson").html("<ul class='thumbs clearfix11'><li class=_items><div class=_thumbnailFileName></div><div class=_title></div><div class=_longtitle style=display:none;></div> <div class=_isHavingPassword style=display:none;></div><div class=_description style=display:none;></div><div class=_videoFileName style=display:none;></div><div class=_ID style=display:none;></div><div class=_viewCount></div><div class=_uploadedDate style=display:none;></div><div class=_rating></div><div class=_price style=display:none;></div><div class=_SchoolId style=display:none;></div><div class='_freeViewingDuration' style='display: none;'></div><div class='_isGsVideo' style='display: none;'></div><div class=_isSiteDefault style=display:none;></div><div class=_isDefault style=display:none;></div></li></ul>");
        RatingDisplay();
        ViewCountDisplay();
    }
    FillData(myJsonObject);
    BindJcarousel("mycarousel");
    if ($("input[id$='hidjCarouselbtnClick']").val() == -1) {
        mycarousel_prevbtnhidden();
        mycarousel_nextbtnVisible();
    }
    else {
        mycarousel_nextbtnVisible();
        mycarousel_prevbtnVisible();
    }
    if ($("input[id$='hid_RowCount']").val() == 1) {
        if (myArray1.length < 9) {
            mycarousel_nextbtnhidden();
        }
    }
    if (($("input[id$='hid_RowCount']").val() == 1 && $("input[id$='hid_ArrowVisibleCheck']").val() == 1) && $("input[id$='IsEZSearch']").val() != 1) {

        mycarousel_prevbtnhidden();
        $("input[id$='hid_ArrowVisibleCheck']").val(0);
    }

    if (($("input[id$='hid_RowCount']").val() == 1 && $("input[id$='hid_ArrowVisibleCheck']").val() == 1) && $("input[id$='IsEZSearch']").val() == 1 || $("input[id$='hid_IsNewandMostViewed']").val() == 1) {
        mycarousel_prevbtnhidden();

        $("input[id$='hid_ArrowVisibleCheck']").val(0);
        $("input[id$='hid_IsNewandMostViewed']").val(0);
    }

    if (($("input[id$='hid_RowCount']").val() == 1 && hidFlagValue == 4)) {
        hidFlagValue = "";

        mycarousel_prevbtnhidden();
    }
    setTimeout("SetPageClass(" + currentPageNumber + ")", 1000);
}

//------------------------------------------------------------------------ FILL WITH DATA -----------------------------------------------------------------------------------------------------------------------------------------------------------//

function FillData(Data) {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    var isFilled = false;
    $("#fillJson").fill(Data);
    if ($isNarrowEmbedModel == "True" && $("#hidIsLive").val().toLowerCase() == "true") {
        // $("#fillJson").css({ marginTop: "2px" });            // Don't Delete this //
        // $(".jcarousel-container").css({ height: "145px" });  // Don't Delete this //
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "155px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
        else {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "155px" });
        }
    }
    else {
        ReduceMarginHeight();
    }
    $('ul.thumbs li._items').each(function() {
        var _title = $(this).find('div._title').html().replace("//", "\\");
        if (_title.length > 0) isFilled = true;
        var _longTitle = _title.replace("//", "\\");
        $(this).find('div._longtitle').html(_longTitle);
        var _shortTitle;
        var _price = "";
        var _password = "";
        var _freeViewingDuration = "";
        if (_title.length > 9) _shortTitle = _title.substring(0, 9) + "...";
        var $view = $(this).find('div._viewCount').html();
        var $rate = $(this).find('div._rating').html();
        var $desc = $(this).find('div._description').html();
        var $Price = $(this).find('div._price').html();
        var $FreeViewingDuration = $(this).find('div._freeViewingDuration').html();
        var $IsGsVideo = $(this).find('div._isGsVideo').html();
        var $ID = $(this).find('div._ID').html();
        if (PaymentSchool.toLowerCase() == "true") {
            if ($Price != 0) {
                _price = "Price - $" + $Price;
            }
            else {
                _price = "";
            }
        }
        if ($(this).find('div._isHavingPassword').html() == "true" && (PaymentUser.toLowerCase() == "false" || PaymentUser.toLowerCase() == "true")) {
            _password = "Password Required";
        }
        else {
            _password = "";
        }
        if ($FreeViewingDuration != "") {
            _freeViewingDuration = "Watch free for next " + $FreeViewingDuration;
        }
        else {
            _freeViewingDuration = "";
        }
        $(this).find('div._title').html(_shortTitle);
        $(this).find("div._viewCount").html("Views: " + $view);
        $(this).find("._rating").prepend("Rating: ");
        $(this).find('div._thumbnailFileName').replaceWith("<img onerror=LoadUploadImage(this,'Images/modern/No-Image.jpg') src='" + $(this).find('div._thumbnailFileName').html() + "' width='100%' height='80px' border='none' />");
        AddClickEventHandler(this, _longTitle, $view);
        $(this).tooltip({
            showURL: false,
            track: true,
            fixPNG: true,
            bodyHandler: function() {
                var description = $(this).children("._description").html();
                description = description.length > 500 ? description.replace("//", "\\").substr(0, 500) : description.replace("//", "\\").replace('<br/>', '/r');
                return GenerateToolTip(_longTitle, description, _price, _password, _freeViewingDuration, $IsGsVideo);
            }
        });
        showImageHover();
    });
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------//

function showImageHover() {
    if ($("input[id$='hid_RowCount']").val() != 1) {
        $("ul.thumbs li div._title").css({ marginTop: "85px" });
        $("ul > li._items img").hoverpulse({
            size: 20,
            speed: 400
        });
    }
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------//

function GenerateToolTip(_longTitle, description, _price, _password, _freeViewingDuration, $IsGsVideo) {
  
    var toolTip;
    if ($IsGsVideo == "true") {
        toolTip = "<div class='gstitle'><h3>" + _longTitle + "</h3></div> <div class='gsdesc'>" + description + "</div>";
        if (_password != "" || _freeViewingDuration != "" || _price != "") {
            toolTip = toolTip + "<div class='gsprice'><div>" + _password + "</div><div>" + _price + "</div><div>" + _freeViewingDuration + "</div></div>";
        }
        toolTip = "<div style='padding:1px;'>" + toolTip + "</div>";
    }
    else {
        toolTip = "<div class='evtitle'><h3>" + _longTitle + "</h3></div> <div class='evdesc'>" + description + "</div>";
        if (_password != "" || _price != "") {
            toolTip = toolTip + "<div class='evprice'><div>"
                + _password + "</div><div>" + _price + "</div></div>";
        }
        toolTip = "<div style='padding:1px;'>" + toolTip + "</div>";
    }
    return toolTip;
}


//--------------------------------------------------------------- HANDLE DEFAULT VIDEO -----------------------------------------------------------------------------------------------------------------//    

function HandleVideo() {
    var isLive;

    if (window.location.href.split('?').length == 2) isLive = "False";
    isLive = (IsLive == "false" ? "False" : IsLive);
    if (isLive == "False") {

        AssignDefaultPlayerBehaviour("#ctl00_mainContentPlaceHolder_hidVideoObject");
        CheckDefaultPlayerVideo($("input[id$='_hidVideoID']").val());
    }
}
//----------------------------------------------------------------Handle Streaming Video-------------------------------------------------------------------------------------------------------------------//

function AssignDefaultPlayerBehaviour(valueToGetFrom) {

    var videoObject = $(valueToGetFrom).val();
    if (videoObject.length > 0) SetVideoDetails(videoObject);
    else
        GetBaseVideo();
}
//-------------------------------------------------------------- SET META DATA DETAILS ----------------------------------------------------------------------------------//  

function SetMetaDataDetails($VideoID) {
    $("#livePlayerDiv").removeClass('flashbanner').addClass('hide');
    $("#OverFlowDiv").hide();
    $("#divDescription").show();
    $("#OverFlowTitle").hide();
    $("#divTitle").show();
    ShowBaseDiv();
    $('ul.thumbs li._items').each(function() {
        if ($(this).find('div._ID').html() == $VideoID) {
            $("#hidRatingVideoID").val($(this).find('div._ID').html());
            $title = $(this).find('div._longtitle').html();
            $desc = $(this).find('div._description').html();
            $view = $(this).find('div._viewCount').html().split(':')[1];
            $rating = $(this).find('div._rating').html();
            $("#divTitle").html($title);
            HideInvite();
            $('#OverFlowDivContent').html($desc);
            $('#OverFlowTitleContent').html($title);
            if (($IsEmbedModel != "True") && ($isNarrowEmbedModel != "True")) {
                if ($title.length > 20) {
                    $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
                    var divTitleHeight = document.getElementById('divTitle').offsetHeight;
                    if (divTitleHeight > 52) {
                        $("#divTitle").html('<div style="height:60px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));
                if ($desc.length > 20) {
                    $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
                    var divDescriptionHeight = document.getElementById('divDescription').offsetHeight;
                    if (divDescriptionHeight > 52) {
                        $("#divDescription").html('<div style="height:60px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));
            }

            if ($IsEmbedModel == "True") {
                if ($title.length > 20) {
                    $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
                    var divTitleHeight = document.getElementById('divTitle').offsetHeight;
                    if (divTitleHeight > 39) {
                        $("#divTitle").html('<div style="height:43px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));

                if ($desc.length > 20) {
                    $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
                    var divDescriptionHeight = document.getElementById('divDescription').offsetHeight;
                    if (divDescriptionHeight > 39) {
                        $("#divDescription").html('<div style="height:43px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));
            }

            if ($isNarrowEmbedModel == "True") {
                if ($title.length > 20) {
                    $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
                    var divTitleHeight = document.getElementById('divTitle').offsetHeight;
                    if (divTitleHeight > 26) {
                        $("#divTitle").html('<div style="height:35px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));

                if ($desc.length > 20) {
                    $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
                    var divDescriptionHeight = document.getElementById('divDescription').offsetHeight;
                    if (divDescriptionHeight > 26) {
                        $("#divDescription").html('<div style="height:35px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
                    }
                }
                else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));
            }

            if ($view > 75) {
                $("#divShowViewCount").addClass('show').removeClass('hide');
                $("#divViewCount").html($view);
            } else {
                $("#divShowViewCount").addClass('hide').removeClass('show');
            }


            if ($isNarrowEmbedModel == "True") {
                if ($view > 75) {
                    $("#divShowViewCount").addClass('show narrowviewcount').removeClass('hide');
                    $("#divViewCount").html($view);
                } else {
                    $("#divShowViewCount").addClass('hide').removeClass('show narrowviewcount');
                }
            }


            $("#divRating").html($(this).find('div._rating').html());
            $currentRate = parseInt($(this).find('div._rating').html().split(':')[1]);
            $("#hidRatedValue").val('');
            SetRating($currentRate);
        }
    })
};

//-------------------------------------------------------- ASSIGN VIDEO META DATA  ---------------------------------------------------------------------------------------------------------//

function SetVideoDetails(result) {
    var desc;
    ShowBaseDiv();
    //$("#divEmailFriends").show();
    $("#divRatingWithViews").show();
    var serializer = Sys.Serialization.JavaScriptSerializer;
    var data = serializer.deserialize(result);
    if (data.IsSiteDefault == "True" || data.IsSystemDefault == "True") {
        $("#hidIsDefaultVideo").val("True");
    }
    if (data.IsSystemDefault == "True" || data.IsPrivate == "True" || data.IsSiteDefault == "True" || data.IsQueryString == "True") {
        if ($("#ctl00_mainContentPlaceHolder_hidAssociated").val() != "") {
            $("#divAssociatedFiles").removeClass("hide").addClass("show");
            var associatedFilesLink = "DownloadSupportingFiles.aspx?q=" + data.Video.split('*#*')[0];
            $("#lblDownload").val(associatedFilesLink);
        }
        else {
            $("#divAssociatedFiles").removeClass("show").addClass("hide");
        }
        $("input[id$='_hidVideoID']").val(data.Video.split('*#*')[0]);
        $("#divTitle").html(data.Video.split('*#*')[1]);
        $("#hidRatingVideoID").val($("input[id$='_hidVideoID']").val());
        var VideoID = $("input[id$='_hidVideoID']").val();
        $title = data.Video.split('*#*')[1];
        $desc = data.Video.split('*#*')[2];
        desc = data.Video.split('*#*')[2];
        var VideoFileName = data.Video.split('*#*')[5];
        $('#OverFlowDivContent').html(desc);
        $('#OverFlowTitleContent').html($title);
        if ($title.length > 30) {
            if ($title.length <= 200)
                $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
            else
                $("#divTitle").html('<div style="height:60px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
        }
        else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));
        if ($desc.length > 30) {
            if ($desc.length <= 200)
                $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
            else
                $("#divDescription").html('<div style="height:60px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
        }
        else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));

        if ($IsEmbedModel == "True") {
            if ($title.length > 30) {
                if ($title.length <= 100)
                    $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
                else
                    $("#divTitle").html('<div style="height:43px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
            }
            else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));
            if ($desc.length > 30) {
                if ($desc.length <= 200)
                    $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
                else
                    $("#divDescription").html('<div style="height:43px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
            }
            else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));
        }

        if ($isNarrowEmbedModel == "True") {
            if ($title.length > 30) {
                if ($title.length <= 100)
                    $("#divTitle").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $title + '</div>');
                else
                    $("#divTitle").html('<div style="height:35px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $title + '</div>'); //Included wordWrap   
            }
            else $("#divTitle").html($title.replace("//", "\\").substr(0, 30));

            if ($desc.length > 30) {
                if ($desc.length <= 100)
                    $("#divDescription").html('<div style="width:100%;overflow-x:hidden;overflow-y:hidden;word-wrap:break-word;">' + $desc + '</div>');
                else
                    $("#divDescription").html('<div style="height:35px;width:100%;overflow-x:hidden;overflow-y:scroll;word-wrap:break-word;">' + $desc + '</div>'); //Included wordWrap   
            }
            else $("#divDescription").html($desc.replace("//", "\\").substr(0, 30));
        }

        if (data.Video.split('*#*')[4] > 75) {
            $("#divShowViewCount").addClass('show').removeClass('hide');
            $("#divViewCount").html(data.Video.split('*#*')[4]);
        } else {
            $("#divShowViewCount").addClass('hide').removeClass('show');
        }

        if ($isNarrowEmbedModel == "True") {
            if (data.Video.split('*#*')[4] > 75) {
                $("#divShowViewCount").addClass('show narrowviewcount').removeClass('hide');
                $("#divViewCount").html(data.Video.split('*#*')[4]);
            } else {
                $("#divShowViewCount").addClass('hide').removeClass('show narrowviewcount');
            }
        }

        $("#divRating").html(data.Video.split('*#*')[3]);
        var $currentRate = data.Video.split('*#*')[3];
        $("#hidRatedValue").val($currentRate);
        $("div.star-rating-on").removeClass("star-rating-on");
        $("div.star-rating").each(function(i) {
            if (i <= $currentRate - 1) $(this).addClass("star-rating-on");
        });
        FindURL(data.Video.split('*#*')[5]);
        GetShareLink(VideoID,VideoFileName,data.ShareURL);      
     }
}

//-------------------------------------------------------------------- Assign Base Values ------------------------------------------------------------------------------------------------------------------------------------------------------------//

function AssingnValuesForBaseVideo() {
    $("#divTitle").html("eSN-SVN Behind the Scenes, Extended Version");
    $("#divDescription").html("See Teachers, Students and a Principal share their perspectives regarding this hands-on approach to learning.");
}

function ShowBaseDiv() {
    $("#ctl00_mainContentPlaceHolder_playerHeader").addClass("player-stat clearfix");
    $("#ctl00_mainContentPlaceHolder_playerHeader").show();
    $("# divRatingWithViews").show();
    $("#ctl00_mainContentPlaceHolder_sharelink").show();
//    $("#ctl00_mainContentPlaceHolder_divEmailFriends").removeClass('hidden').addClass('show');
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function CheckDefaultPlayerVideo($VideoID) {
    DialogAction("click");
     Default.RedirectPPV($VideoID, function(resultObj) {
        var result = resultObj.value;
        if (Validate(result)) {
            DialogAction("close");
            return;
        }
        if (result.length > 0) {
            DialogAction("close");
            var serializer = Sys.Serialization.JavaScriptSerializer;
            var data = serializer.deserialize(result);
            $("input[id$='hidVideoDetails']").val(data.SelectedVideoDetails);
            if (data.IsPreviewed) {
                SetMetaDataDetails($VideoID);
                var $PaymentUrl = data.PreviewdUrl;
                var $IsLiveCancelCheck = data.IsLiveCancelCheck;
                StopPlayer();
                VideoAlreadyPreviewed($PaymentUrl, $IsLiveCancelCheck);
                FindURL('');
                return;
            }

            if (data.IsFreeVideo) {
                SetMetaDataDetails($VideoID);
                $("#divSchedule").hide();
                var $Url = data.VideoFileName;
                FindURL($Url);
                PostVideoWithID($VideoID);
                return;
            }
            if (data.HasPassword) {
                $("input[id$='_hidVideoID']").val($VideoID);
                if ($.browser.msie)
                    setTimeout("FindURL('')", 2500);
                else
                    FindURL('');
                if ($.browser.msie)
                    setTimeout("StopPlayer()", 2500);
                else
                    setTimeout("StopPlayer()", 2500);
                setTimeout("ShowModalpopup('F')", 500);
            }            
        }
    })
};
//-------------------------------------------------  BaseVideo-------------------------------------
function GetBaseVideo() {
    AssingnValuesForBaseVideo();
    ShowBaseDiv();
    $("#divRatingWithViews").show();
    $("#divShowViewCount").addClass('show').removeClass('hide');
    $("#divViewCount").html("168");
    $("#ctl00_mainContentPlaceHolder_sharelink").hide();
    $("#ctl00_mainContentPlaceHolder_divEmailFriends").removeClass('show').addClass('hidden'); 
    SetRating(0);
    FindURL('');
}

//-------------------------------------- JCarousel Function - Binds Videos on Button click ----------------------------------

function BindJcarousel(carouselId) {
    $('#' + carouselId).jcarousel({
        buttonNextCallback: Nextbtntrigger,
        buttonPrevCallback: Prevbtntrigger
    });
}

function Nextbtntrigger() {
    var defaultSearchTitle = "enter search term here";
    $(".jcarousel-next").bind('click', function() {
        var nextclickevent = $("input[id$='hidjCarouselbtnClick']").val();
        var sortbyflag = $("#hidflag").val();
        var selectedCategory = $("select[id$=catList]").val();
        var searchText = $("#search").val().replace('/\s/', '').toLowerCase();
        if (searchText == defaultSearchTitle) { searchText = ""; }
        if (nextclickevent == "") {
            nextclickevent = 0;
            $("input[id$='hidjCarouselbtnClick']").val(nextclickevent);
        }
        else {
            nextclickevent++;
            $("input[id$='hidjCarouselbtnClick']").val(nextclickevent);
        }
        Default.GetJCarouselVideosForNextbtn(nextclickevent, sortbyflag, searchText, selectedCategory, GetResult);
    });
}

function Prevbtntrigger() {
    var defaultSearchTitle = "enter search term here";
    $(".jcarousel-prev").bind('click', function() {
        var prevclickevent = $("input[id$='hidjCarouselbtnClick']").val();
        var sortbyflag = $("#hidflag").val();
        var selectedCategory = $("select[id$=catList]").val();
        var searchText = $("#search").val().replace('/\s/', '').toLowerCase();
        if (searchText == defaultSearchTitle) { searchText = ""; }
        Default.GetJCarouselVideosForPrevbtn(prevclickevent, sortbyflag, searchText, selectedCategory, GetResult);
        prevclickevent--;
        $("input[id$='hidjCarouselbtnClick']").val(prevclickevent);
    });
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------SetChannelInDropDown-------------------------

function SetChannelInDropDown(channelid) {
    if (channelid.trim().length > 0) {
        $("#ctl00_mainContentPlaceHolder_catList").val(channelid);
        $("#ctl00_mainContentPlaceHolder_catList").trigger("change");
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------SetHeight-----------------------------------

function getIframeHeight() {
    var viewportwidth;
    var viewportheight;
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
            viewportheight = window.innerHeight
    }

    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
            viewportheight = document.documentElement.clientHeight
    }

    if (viewportwidth == 856 && viewportheight == 596) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportwidth == 870 && viewportheight == 786) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportwidth == 870 && viewportheight == 936) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportwidth == 870 && viewportheight == 1086) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportwidth == 870 && viewportheight == 1236) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportwidth == 870 && viewportheight == 1486) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 610 && viewportwidth == 853) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "8") {
            $('#OverFlowTitleContent').css({ "height": "30px" });
            $("#divPassword").css({ marginTop: '-100px', marginLeft: '50px' });
        }
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
    }

    if (viewportheight == 593 && viewportwidth == 853) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $('#OverFlowTitleContent').css({ "height": "30px" });
            $("#divPassword").css({ marginTop: '-100px', marginLeft: '50px' });
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 783 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 933 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 1083 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 1233 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 1483 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }

    if (viewportheight == 610 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-200px', marginLeft: '50px' });
    }

    if (viewportheight == 800 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-200px', marginLeft: '50px' });
    }

    if (viewportheight == 950 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-300px', marginLeft: '50px' });
    }

    if (viewportheight == 1100 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-350px', marginLeft: '50px' });
    }

    if (viewportheight == 1250 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-450px', marginLeft: '50px' });
    }

    if (viewportheight == 1500 && viewportwidth == 870) {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#ctl00_divEmbedHeader.embed-header-container").css({ top: "0px", height: "0px" });
        }
        $('#OverFlowTitleContent').css({ "height": "30px" });
        $("#divPassword").css({ marginTop: '-550px', marginLeft: '50px' });
    }
}

function SetHeight() {
    if ($IsEmbedModel == "True") {
        getIframeHeight();
    }
    else {
        $('#OverFlowDivContent').css({ "height": "125px" });
        $('#OverFlowTitleContent').css({ "height": "50px" });
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------SetNarrowEmbedHeight------------------------------

function SetNarrowEmbedHeight() {
    if ($isNarrowEmbedModel == "True") {
        $('#OverFlowTitleContent').css({ height: '40px', width: '100%' });
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------SetPaging----------------------------------------
function SetPaging() {
    $("#divPaging").html($("#ctl00_mainContentPlaceHolder_divPager").html());
    $("#divPaging a").addClass('page');
    CheckPageNumbers();
    $("a[class='page']").each(function() {
        this.href = 'javascript:void(0);';
    }
        )
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------ShowPasswordWindow--------------------------------
function ShowPasswordWindow() {
    if ($IsEmbedModel == "True")
        EmbedPasswordWindow();
    else
        DefaultPasswordWindow();
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------DefaultPasswordWindow--------------------------------

function DefaultPasswordWindow() {
    var divpasswordHolder = document.getElementById('passwordHolder');
    var defaultheader = document.getElementById('ctl00_divDefaultHeader');
    if (divpasswordHolder && defaultheader)
        defaultheader.appendChild(divpasswordHolder);
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------EmbedPasswordWindow--------------------------------

function EmbedPasswordWindow() {
    var divpasswordHolder = document.getElementById('passwordHolder');
    var embedheader = document.getElementById('ctl00_divEmbedHeader');
    if (divpasswordHolder && embedheader)
        embedheader.appendChild(divpasswordHolder);
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------RatingDisplay--------------------------------

function RatingDisplay() {
    if (rating == "False") {
        $('.home-video-rating').hide();
        $('._rating').hide();
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------ViewCountDisplay--------------------------------

function ViewCountDisplay() {
    if (viewcount == "False") {
        $('.home-video-views').hide();
        $('._viewCount').hide();
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------DisableControlOnNoVideosFound--------------------------------

function DisableControlOnNoVideosFound() {
    if (parseInt($('#ctl00_mainContentPlaceHolder_catList :selected').text().split('(')[1].replace(')', '')) == 0) {
        $("#fillJson a").removeAttr("href");
        $("select,input[id$='search'],a[id$='searchLnk'],a[id$='lnkAdvanced'],div[id$='lnkRecent'],div[id$='lnkViewed'],img[id$='btnSearch']")
            .attr("disabled", "true")
            .removeAttr("onclick")
            .removeAttr("href");
        $("#searchLnk")
            .removeAttr("href").removeAttr("onclick");
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------DisableEZsearchWhenNoVideosInEZ--------------------------------

function DisableEZsearchWhenNoVideosInEZ() {
    if ($("input[id$='hid_isEzSearch']").val() == "true") {
        $("#lnkAdvanced").hide();
    }
    else {
        $("#lnkAdvanced").show();
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------SetNarrowEmbedHeightdefault--------------------------------


function SetNarrowEmbedHeightdefault() {
    if ($isNarrowEmbedModel == "True") {
        $("#divEmailFriends").css({ float: 'right', marginTop: '5px', padding: '0 10px 10px', textAlign: 'right' });
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------GetSelectedChannelID--------------------------------

var catlistValue = 0;

function GetSelectedChannelID() {
    if ($("#ctl00_mainContentPlaceHolder_catList").val() == "-1") {
        catlistValue = -1;
    }
    if ($("#ctl00_mainContentPlaceHolder_catList").val() == "0") {
        catlistValue = 0;
    }
    else {
        catlistValue = $("#ctl00_mainContentPlaceHolder_catList").val();
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------ChangeItemHeight--------------------------------

function ChangeItemHeight() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if (BrowserOS == "Mac" && BrowserName == "Firefox" && BrowserVersion == "3.6") {
        $("#fillJson div.jcarousel-skin-tango .jcarousel-clip-horizontal");
        $("#fillJson div.jcarousel-skin-tango .jcarousel-item-horizontal");
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------DetectAllBrowser--------------------------------

function DetectAllBrowser() {
    var $isNarrowEmbedModel = '<%=ApplicationUtilities.IsNarrowEmbedModel()%>';
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if ($isNarrowEmbedModel == "True") {
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            $("#fillJson").css({ marginLeft: '6px', marginTop: '3px' });
        }
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------Reduce Margin Height in Narrow Embed Model--------------------------------
function ReduceMarginHeight() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
        if ($isNarrowEmbedModel == "True") {
            // $("#fillJson").css({marginTop:"2px"});                 // Don't Delete this //
            // $(".jcarousel-container").css({ height: "135px" });   // Don't Delete this //
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "145px" });
            $("ul > li._items").hover(function() {
                $("html").css({ overflow: "hidden" });
            });
            $("html").css({ overflow: "hidden" });
        }
    }
    if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "8") {
        if ($isNarrowEmbedModel == "True") {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "150px" });
        }
    }
    if (BrowserOS == "Mac" && BrowserName == "Firefox" && BrowserVersion == "3.6") {
        if ($isNarrowEmbedModel == "True") {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "150px" });
        }
    }
    if (BrowserOS == "Mac" && BrowserName == "Safari") {
        if ($isNarrowEmbedModel == "True") {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "150px" });
        }
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------Show Narrow Embed Model Popup Password --------------------------------

function NarrowEmbedShowModelPopup() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if ($isNarrowEmbedModel == "True") {
        $("#divPassword").removeClass("hide defaultPasswordModelPopup").addClass("show NarrowEmbedPasswordModelPopup");
        if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
            FadeToDisableLogos();
        }
    }
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------FadeTo & Disabled GS Logo and Login button in Narrow Embed Model Popup Password --------------------------------

function FadeToDisableLogos() {
    $("#NarrowEmbedLogo").fadeTo("slow", 0.3);
    $("#NarrowEmbedLogo a").removeAttr("href");
    $("#narrowlogin").fadeTo("slow", 0.1).removeAttr("href");
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------FadeOut & Enabled GS Logo and Login button in Narrow Embed Model Popup Password --------------------------------

function FadeOutEnableLogos() {
    $("#NarrowEmbedLogo").fadeTo("slow", 0.9);
    $("#NarrowEmbedLogo a").attr("href", true);
    $("#narrowlogin").fadeTo("slow", 0.9).attr("href", true);
}

//-- -- -- -- -- -- -- -- -- -- -- -- ----------------Reduce Margin Height when Video Live and Password Model Popup show in Narrow Embed Model --------------------------------

function ReduceMarginHeightForLive() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
        if ($isNarrowEmbedModel == "True" && $("#hidIsLive").val().toLowerCase() == "true") {
            $("#fillJson").css({ marginTop: "2px" });
            $(".jcarousel-container").css({ height: "145px" });
        }
    }
}

function mycarousel_nextbtnhidden() {
    $(".jcarousel-next").attr({ disabled: true });
    $(".jcarousel-next").removeClass("jcarousel-next-horizontal");
    $(".jcarousel-next").addClass("jcarousel-next-disabled");
    $(".jcarousel-next").addClass("jcarousel-next-disabled-horizontal");
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

function GetShareLink($VideoID, VideoFileName, ShareURL) {
    $('ul.thumbs li._items').each(function() {
        if ($(this).find('div._ID').html() == $VideoID) {
            $title = $(this).find('div._longtitle').html();
        }
    })
     Addthis_Config($title, VideoFileName, ShareURL);
  }
function Addthis_Config(shareTitle, shareVideoFileName, ShareURL) {
if (shareTitle.length >= 30) {
        shareTitle = shareTitle.substring(0, 27) + "...";
    }  
    $("#toolbox").attr('addthis:services_compact', 'facebook,twitter,wordpress,gmail,google,linkedin,hotmail,live,digg,delicious,');
    $("#toolbox").attr('addthis:title', shareTitle);
    $("#toolbox").attr('addthis:url', ShareURL);
//    $("#toolbox").attr('addthis:swfurl', "http://cdn.octoshape.net/resources/player/jwflvplayer/5/jwplayer-octoshape-mediaprovider2.swf");
//    $("#toolbox").attr('addthis:swfurl', "http://eduvision.tv/includes/Swf/player-licensed-viral.swf?file=octoshape://streams.octoshape.net/jdl/IA_Johnston_AEA11_AEA11_385 / design_differentiated_fcbec69d53324d9c8ddad772d6b015e0_converted.flv");
    $("#toolbox").attr('addthis:width', "560");
    $("#toolbox").attr('addthis:height', "340");     
    $("#toolbox").attr('addthis:screenshot', "http://i2.ytimg.com/vi/1F7DKyFt5pY/default.jpg");
    addthis.toolbox("#toolbox");         
}
   


function AlignRatingWithViewss() {
    var BrowserName = BrowserDetect.browser
    var BrowserVersion = BrowserDetect.version
    var BrowserOS = BrowserDetect.OS
    if (BrowserOS == "Windows" && BrowserName == "Explorer" && BrowserVersion == "7") {
        $("#divRatingWithViews").css({ float: "left",width:"175px",position:"relative" });
    }
}

      
    

  
