﻿// JScript File



$(function(){ 
    HandlePager();
})

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//   

function trim(stringToTrim)
{
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}   

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//


function SetDefaultCategory()
{
    //document.getElementById(""+catList+"").value="-1";
    //document.getElementById(""+txtSearch+"").value="";
    $("select[id$='catList']").val("-1");
    $("input[id$='txtSearch']").val('');
    $("input[id$='btnSearch']").trigger("click");
}


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//   


//
//function used to clear the value and used to raise the click the event
//
function CallSearch(){
    document.getElementById('txtSearch').value="";
    document.getElementById('btnSearch').click();
}

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//
//function use to assign no image 
//LoadUploadImage
function LoadUploadImage(obj,path)
{
    obj.src=path;
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//      

//
// function for checking all the check boxes
// 
function CheckAllDataGridCheckBoxes(gvID,ChkID, checkVal)
{
    ClearMessage();
    for(var i=2;;i++)
    {
        if(i <= 9)
        var chkApprove = gvID + "_ctl0" + i + "_" + ChkID;
        else
        var chkApprove = gvID + "_ctl" + i + "_" + ChkID;
        var CtrlChkApproveID = document.getElementById(chkApprove);
        if(CtrlChkApproveID == null)
        break;
        else
        {
            if(!CtrlChkApproveID.disabled)
            CtrlChkApproveID.checked = checkVal;
        }  
    }
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

//
//function used to clear the message
//
function ClearMessage()
{ 
    if(document.getElementById(""+Message+""))
    document.getElementById(""+Message+"").className = "notice hide";  
}


function ClearMessageinSchoolEdit()
{
    if(document.getElementById(""+Message1+""))
    document.getElementById(""+Message1+"").className = "success hide"; 
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                  


//
//function used to check the password
//
function CheckPassword()
{           
    if(document.getElementById('ctl00_mainContentPlaceHolder_txtOldpassword').value.length !=0)
    {
        if(document.getElementById('ctl00_mainContentPlaceHolder_txtNewpassword').value.length ==0)
        {
            document.getElementById("ctl00_mainContentPlaceHolder_LabelNewPassword").innerHTML="<span class='mandatory small'>New Password is required</span>"
            document.getElementById("ctl00_mainContentPlaceHolder_txtNewpassword").focus();   
            return false;         
        }
        if(document.getElementById('ctl00_mainContentPlaceHolder_txtConfirmnewpassword').value.length ==0)
        {
            document.getElementById("ctl00_mainContentPlaceHolder_LabelConfirmNewPassword").innerHTML="<span class='mandatory small'>Confirm Password is required</span>"
            document.getElementById("ctl00_mainContentPlaceHolder_txtConfirmnewpassword").focus();
            return false;             
        }           
        if(document.getElementById('ctl00_mainContentPlaceHolder_txtNewpassword').value.length !=0  && document.getElementById('ctl00_mainContentPlaceHolder_txtConfirmnewpassword').value.length !=0) 
        {
            return true;
        }         
    }
    return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                         

//
//
//function used to assign the category when it is not selected
function chkCategory()
{  
    var ApprovalChkBox=document.getElementById('lblApproval').innerHTML.split(';')  

    for(i = 0; i < ApprovalChkBox.length-1; i++)
    {   
        var chkApproval=document.getElementById(ApprovalChkBox[i].split(',')[0]).checked;       
        var Category=document.getElementById(ApprovalChkBox[i].split(',')[0].replace("chkApproval","lblCategory")).innerHTML;
        var Title=document.getElementById(ApprovalChkBox[i].split(',')[0].replace("chkApproval","lblTitle")).innerHTML;       
        if(chkApproval && Category.indexOf("Category is not")>0)
        {
            alert("Assign the category for " + Title);
            document.getElementById(ApprovalChkBox[i].split(',')[0]).checked = false;
            return false;
            }    

    }
    return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                     


//
//function used in LiveGameSchedule.aspx for clear the textbox values when search
//
function SetDefaultinSchedule()
{
    if( document.getElementById(""+txtSearch+""))
        document.getElementById(""+txtSearch+"").value="";

    if( document.getElementById(""+txtStartDate+""))
        document.getElementById(""+txtStartDate+"").value="";

    if( document.getElementById(""+txtEndDate+""))
        document.getElementById(""+txtEndDate+"").value="";  

    document.getElementById(""+btnSearch+"").click();

}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                     

//
//function used in ViewUsers.aspx for clear the textbox values when search
//
function SetDefaultinUser()
{
    if( document.getElementById(""+textSearch+""))
        document.getElementById(""+textSearch+"").value="";

    if( document.getElementById(""+ddlStatus+""))
        document.getElementById(""+ddlStatus+"").value="-1";

    if( document.getElementById(""+ddlRole+""))
        document.getElementById(""+ddlRole+"").value="-1";  

        document.getElementById(""+btnSearch+"").click();

}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                     


function SetDefaultinGroup()
{
    $("input[id$='txtSearch']").val("");
    $("select[id$='ddlGroups']").val("0")
    $("input[id$='btnSearch']").click();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                     



function Loadarrow(obj){
    document.getElementById(obj).src="../Images/arrowRight.gif"
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   



function ValidateKeyPress(e)
{
    if((navigator.appName == 'Netscape' || navigator.appName =='Mozilla Firefox' || navigator.appName =='Opera' || navigator.appName =='Safari'))
    {
        if (parseInt(e.which) < 44 || parseInt(e.which)> 58 )
        {
            switch(parseInt(e.which))
            {
                case 32:
                case 40:
                case 41:
                case 0:
                case 8:
                break;
                default:
                e.preventDefault();
                break;
            }
         }
      }
        else if (window.event.keyCode < 44 || window.event.keyCode > 58 ) 
        {
            switch(window.event.keyCode)
            {
                case 32:
                case 40:
                case 41:
                break;
                default:
                window.event.keyCode = 0;
                break;
            }
        }

}

// Function to allow the alphabet value only

function ValidateAlphabet(e)
{
    if((navigator.appName == 'Netscape' || navigator.appName =='Mozilla Firefox'))
    {  
        if (parseInt(e.which) >47 && parseInt(e.which)< 58)
        {
        e.preventDefault();
        }
    }
    else
    {
        if(event.keyCode > 47 && event.keyCode < 58)
        event.keyCode=0;
    }

}

// Function to allow the numeric value only
function ValidateNumber(e)
{
    if((navigator.appName == 'Netscape' || navigator.appName =='Mozilla Firefox'))
    {   
        if (parseInt(e.which) < 47 || parseInt(e.which)> 58)
        {
        e.which=0;
        }
    }
    else
    {
        if(event.keyCode<47 || event.keyCode>58)
        event.keyCode=0;
    }

}

function CheckNumeric(e)
{
    var key;
    if (window.event)
    key = event.keyCode;
    else
    key = e.which;

    // Was key that was pressed a alphabetic character or backspace (8)?
    if ( key < 44 && key > 58 || key == 8 || key==0)
    return;
    else // otherwise, discard character

    if (window.event) //IE
    window.event.returnValue = null;                
    else
    e.preventDefault();

//Firefox
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function CheckSameVideos(chk,obj,currentobj)
{
    var CurrentVideoID = document.getElementById(obj.replace(currentobj,"lblId")).innerHTML;
    for(var i=2;;i++)
    {
        if(i <= 9)
        {
            var chkApprove = "VideoApprovalGrid_ctl0" + i + "_chkApproval";
            var chkActivate = "VideoApprovalGrid_ctl0" + i + "_chkActivate";
            var _VideoID = "VideoApprovalGrid_ctl0" + i + "_lblId";
        }
        else
        {
            var chkApprove = "VideoApprovalGrid_ctl" + i + "_chkApproval";
            var chkActivate = "VideoApprovalGrid_ctl" + i + "_chkActivate";
            var _VideoID = "VideoApprovalGrid_ctl" + i + "_lblId";
        }

        var CtrlChkApproveID = document.getElementById(chkApprove);
        var CtrlChkActivateID = document.getElementById(chkActivate);
        var CtrlVideoID = document.getElementById(_VideoID);

        if(CtrlChkApproveID == null)
            break;
        else
        {
            if(CtrlVideoID.innerHTML == CurrentVideoID)
            {
                if(currentobj == "chkApproval")
                    CtrlChkApproveID.checked = chk;
                else
                {
                    CtrlChkActivateID.checked = chk;
                    if(CtrlChkApproveID.disabled == false)
                    CtrlChkApproveID.checked = chk;
                }
            }
        }
    }
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function Logout(){

    $("#"+btnLogout+"").trigger("click");
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   
function fnLoadArrowImage(img){

if($("#"+img)){
    $("#"+img).attr("src","../Images/arrowRight.gif")
}

}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   
function WriteArrowImage(id){
    //$("#div"+id).html("<img id='img"+id+"arrow'  src='Images/arrowRight.gif' width='10' height='10' onerror='fnLoadArrowImage(this.id)'/>");
    //var img="<img id='img"+id+"arrow'  src='Images/arrowRight.gif' width='10' height='10' onerror='fnLoadArrowImage(this.id)'/>";
    var homePath=document.getElementById(""+virualPath+"").href
    var img="<img id='img"+id+"arrow'  src="+homePath+"Images/modern/arrowRight.gif width='10' height='10' />";
    document.write(img);
}



//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function WriteFooter()  {
    //    var mailid= document.getElementById(SuperAdminMail).value;
    //    
    //    var tomailid ='Mail To Admin'
    var currentpath= document.location.pathname.toLowerCase();
    var footer = "Copyright &copy 2008."+"<a href='http://www.jdlhorizons.com' target='_blank'>JDL Horizons, LLC.</a>"+ "All rights reserved.   |  " +"<a href='Privacy.aspx' target='_blank'>Privacy Policy</a>   |" + "<a href='Terms.aspx' target='_blank'>Terms &amp; Conditions </a>      |"
    +  "<a  href='javascript:openwindow()' >Supports/Suggestions </a>"   ;
    var adminfooter = "Copyright &copy  2008."+ "<a href='http://www.jdlhorizons.com' target='_blank'>JDL Horizons, LLC.</a> "+ "All rights reserved.   |  " +  "<a href='../Privacy.aspx' target='_blank'>Privacy Policy</a>   | " + "<a href='../Terms.aspx' target='_blank'>Terms &amp; Conditions </a>     | " +  "<a href='javascript:openwindow()' >Supports/Suggestions </a>" ;
    if(currentpath.indexOf('admin/')>0) {        
        document.write(adminfooter);
    } else
        document.write(footer);

}


function openwindow()
{
    window.open(document.getElementById(""+virualPath+"").href+'Feedback.aspx','FeedBack','height=550,width=280');
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function Adminmail ( SuperAdminMail )
{
    $("#divMail").html( 'Contact'.link ("mailto:" + $("#"+SuperAdminMail).val() ) );
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function writeMandatory(classname)
{
    document.write("<span class='" + classname + " small'>* = required field</span>");
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   

function CurrentUserName(CurrentName)
{
    $("#divCurrentUserName").html(( ( "Welcome "+( $( "#"+ CurrentName ).val().length==0 ? "Guest":$ ( "#"+CurrentName ).val() ) ).bold() ));
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   
//
//when press enter key in textbox. fire the search event
//
function keyPress(evt)
{
    if(evt.which || evt.keyCode)
    {
        if((evt.which == 13) || (evt.keyCode == 13))
        {
            document.getElementById(""+btnSearch+"").click();
            return false;   
        }
        return true;
    }
}

function ClearNewPWError()
{
    if(document.getElementById("ctl00_mainContentPlaceHolder_LabelNewPassword").innerHTML != "")
    document.getElementById("ctl00_mainContentPlaceHolder_LabelNewPassword").innerHTML = "";
}


function ClearCNewPWError()
{                         
    if(document.getElementById("ctl00_mainContentPlaceHolder_LabelConfirmNewPassword").innerHTML != "")
    document.getElementById("ctl00_mainContentPlaceHolder_LabelConfirmNewPassword").innerHTML = "";
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   


function AdminBackLink()
{
    if($("#adminssu")){
        if($("#hidssulink").val().toLowerCase()=="true"){
            $("#adminssu").html("Back To Approval");
        }
    }
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//                   


function fnCheckManageScheduleLink(isLive)
{

    if(document.getElementById("lstFormanageSchedule") && isLive.toLowerCase()=='false')
    {
        document.getElementById("lstFormanageSchedule").style.display='none'
    }
    if(document.getElementById("lstwatchmenu") && isLive.toLowerCase()=='false')
    {
        document.getElementById("lstwatchmenu").style.display='none'
    }

}

//-----------------------------------------------------------------------------------------------------------------------------------------

    var checkLinks=function(from){  
    var currentLocation= document.location.pathname.toLowerCase();
    var location=from;

    if(!(from))
    location=currentLocation.split('/')[currentLocation.split('/').length-1].replace(".aspx",'');
    $(document).ready(function(){
        if($("#"+location) != null) {
        $("#"+location).removeAttr("href");
        $("#"+location).addClass("current");
        }      
    });

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------//


function ShowOthersOption(page)
{
    var lblError = document.getElementById(""+labelError+"");

    var lblSchoolAvail = document.getElementById(""+labelAvail+"");

    if(document.getElementById(""+ddlStateValue+"").value == "0")
    {
        document.getElementById(""+divState+"").className = "buttons show";
    } 
    else
    {
        document.getElementById(""+ddlStateValue+"").className = "hide";

        lblError.innerHTML = "";

        lblSchoolAvail.innerHTML = "";
    }

    if(page = "SM")
    {
        var StateValue = document.getElementById(""+hiddenStateValue+"").value;

        if(document.getElementById(""+ddlStateValue+"").value == StateValue)

        document.getElementById(""+divState+"").className = "buttons show";
    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------//

function CheckStates()
{

    var ddlValue = document.getElementById(""+ddlStateValue+"");

    var StateName = document.getElementById(""+txtStateName+"");

    var Abbreviation = document.getElementById(""+txtCountryName+"");

    var lblError = document.getElementById(""+labelError+"");

    if(ddlValue.value == "0" && (trim(StateName.value).length == 0 || trim(Abbreviation.value).length == 0))
    {
        lblError.innerHTML = "Please enter the state/country";
        return false;
    }

    return true; 
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------//


function CheckStateIsEmpty(source, args)
{

    var ddlValue = document.getElementById(""+ddlStateValue+"");

    var StateName = document.getElementById(""+txtStateName+"");

    var Abbreviation = document.getElementById(""+txtCountryName+"");

    var lblError = document.getElementById(""+labelError+"");

    if(ddlValue.value == "0" && (trim (StateName.value).length == 0 ||  trim (Abbreviation.value).length == 0))
    {
        args.IsValid = false;
        return false;
    }

    args.IsValid = true;
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

// handled in the page itself using jQuery - rajakvk 4.5.2009
function ClearStateDELETE()
{

    var lblError = document.getElementById(""+labelError+"");

    if(lblError)
    lblError.innerHTML = "";

}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

function CheckDistrictId(source, args)
{

    var districtvalue = document.getElementById(""+txtDistrict +"") .value;

    if (parseInt(districtvalue)==0)
    { 
        args.IsValid =false ;
        return false;

    }
        args.IsValid =true  ;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//


function customcheck(source,args)
{
    if ( document.getElementById('ctl00_mainContentPlaceHolder_chkDistrictSchool').checked  && trim(document.getElementById(""+txturl +"").value).length==0)
    {
        args.IsValid =false ;
        return false;

    }
        args.IsValid =true  ;
}

//------------------------------------------------------------------------------------------------------------------------------------ 

function CheckIsDistrictSchool(source,args)
{
    var districtvalue = document.getElementById(""+txtDistrict +"") .value;
    if(document.getElementById('ctl00_mainContentPlaceHolder_chkDistrictSchool').checked && parseInt(districtvalue)==0  ||document.getElementById('ctl00_mainContentPlaceHolder_chkDistrictSchool').checked && trim(districtvalue).length==0   )
    {
        args.IsValid =false ;
        return false;
    }
        args.IsValid =true  ;
}
//---------------------------------------------------------------------------------------------------------------------------
function fncheckppv(source,args)
{
    if (document.getElementById('ctl00_mainContentPlaceHolder_txtprice'))
    {
        var pricevalue= document.getElementById('ctl00_mainContentPlaceHolder_txtprice').value;
        var classvalue = document.getElementById ('divprice').className;
        if( trim(pricevalue).length==0 && classvalue.toLowerCase()=="show"  ) 
        {
            args.IsValid=false ;
            return false; 
        } 
        else if(parseFloat(pricevalue)< 5 && classvalue.toLowerCase()=="show" )
        {
            args.IsValid=false ;
            return false; 
        } 
            args.IsValid=true  ;
    }
}
//--------------------------------------------------------------------------------------------------------------------------------

function ValidatePrice( source,args)
{
    if (document.getElementById('ctl00_mainContentPlaceHolder_txtprice'))
    { 
        var pricevalue= document.getElementById('ctl00_mainContentPlaceHolder_txtprice').value;
        var classvalue = document.getElementById ('divprice').className;
        pricevalue = alltrim(pricevalue);
        var result  = /^(?=.*[0-9].*$)\d{0,7}(?:\.\d{0,2})?$/.test(pricevalue);
    if(alltrim(pricevalue).length >0 && classvalue.toLowerCase()=="show" &&  !result   )
    {
        args.IsValid=false ;
        return false ; 
    }
    args.IsValid=true ;
    }
}

//--------------------------------------------------------------------------------------------------------------------------------

function alltrim(str) 
{
    return str.replace(/^\s+|\s+$/g, '');
}
//--------------------------------------------------------------------------------------------------------------------------------



function VaildatePlayTime(source,args)
{
    if( document.getElementById('ctl00_mainContentPlaceHolder_txtvideoplaytime'))
    {
        var playtime=document.getElementById('ctl00_mainContentPlaceHolder_txtvideoplaytime').value;
        if( trim(playtime).length==0 ) 
        {
            args.IsValid=false ;
            return false ;
        }
        else if(Math.ceil(playtime)==0)
        {
            args.IsValid=false ;
            return false; 
        } 
    }
    args.IsValid=true; 
}

//--------------------------------------------------------------------------------------------------------------------------------

function Validateplaytimevalue( source,args)
{
    if( document.getElementById('ctl00_mainContentPlaceHolder_txtvideoplaytime'))
    {
        var pricevalue= document.getElementById('ctl00_mainContentPlaceHolder_txtvideoplaytime').value;
        pricevalue = alltrim(pricevalue);
        var result  = /^[-+]?[0-9]+(\.[0-9]+)?$/.test(pricevalue);

    if(alltrim(pricevalue).length >0 &&  !result )
    {

        args.IsValid=false ;
        return false ; 
    }
        args.IsValid=true ;
    }
}

//------------------------------------------------------function to validate PPV---------------------------------------------------------------------------

function SetPPVForDefault(source,args)
{

    if( document.getElementById('ctl00_mainContentPlaceHolder_chkDefault') &&  document.getElementById ('ctl00_mainContentPlaceHolder_chkppv'))
    {
        if(document.getElementById('ctl00_mainContentPlaceHolder_chkDefault').checked == true &&  document.getElementById ('ctl00_mainContentPlaceHolder_chkppv').checked==true)
        {
            args.IsValid=false ;
            return false ;
        }
    }
    args.IsValid=true  ;
}

function SetPPVForSiteDefault(source,args)
{

    if( document.getElementById('ctl00_mainContentPlaceHolder_chkSiteDefault') &&  document.getElementById ('ctl00_mainContentPlaceHolder_chkppv'))
    {
        if(document.getElementById('ctl00_mainContentPlaceHolder_chkSiteDefault').checked == true &&  document.getElementById ('ctl00_mainContentPlaceHolder_chkppv').checked==true)
        {
            args.IsValid=false ;
            return false ;
        }
    }
    args.IsValid=true  ;
}
//-----------------------------------------------------------------function to clear browse button in firefox-----------------------------------------------------------------------------

function chkFileTypes(control){
    control=$("input[id$='"+control+"']").attr("id");
    if((navigator.appName == 'Netscape' || navigator.appName =='Mozilla Firefox'))
    {
        $('#'+control).val("");
    }
    else
    {
        clearfileinie(control)
    }
}
//-------------------------------------------------------------------------function to validate----------------------------------------------------------------------

function checkValidDate(source,args)
{
    if( trim( $("input[id$='txtStartDate']").val())!="" && trim( $("input[id$='txtEndDate']").val()).length==0)
    {
        args.IsValid=false ;
        return false ;
    }
    if( trim( $("input[id$='txtStartDate']").val())=="" && trim($("input[id$='txtEndDate']").val())!="")
    {
        args.IsValid=false ;
        return false ;
    }
    if( $("input[id$='labelStartDate']").val()!="" &&trim( $("input[id$='txtEndDate']").val()).length==0 && document.getElementById ('ctl00_mainContentPlaceHolder_divLabelStartDate').className=="show"  )
    {
        args.IsValid=false ;
        return false ;
    }
        args.IsValid=true  ;
}  

// --------------------------------------------------------function to clear browse button in ie------------------------------------------------------------------------------------------------------------------------------------

function clearfileinie(control){
    var who=document.getElementsByName(control)[0];
    var who2= who.cloneNode(false);
    who2.onchange= who.onchange;
    who.parentNode.replaceChild(who2,who);
}

// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function ValidateToAddress( source,args)
{
    if (document.getElementById('txtToEmai'))
    {
        var toaddress= document.getElementById('txtToEmai').value;
        toaddress = alltrim(toaddress);
        var result  = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]+([,.][a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]+)*$/.test(toaddress);
        if(!result && toaddress.length>0)
        {
            args.IsValid=false ;
            return false ; 
        }
        args.IsValid=true ;
    }
}

// ------------------------------------function to handle pager--------------------------------------------------------------------------------------------------------------------//
function HandlePager(){
    if($(".tablesorter")!=null || $(".tablesorter")!=undefined){
        $(".pagedisplay").attr("disabled","disabled");
        
        $(".tablesorter").each(function(i){ 
            this.rows.length>11?
            $($(".pager")[i]).show():
            $($(".pager")[i]).hide();
        });
    }
    
}

// ------------------------------------function to selected channel--------------------------------------------------------------------------------------------------------------------//
function getCategoryVal() {
    var selectedValue=$("select[id$=catList]").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 check page numbers--------------------------------------------------------------------------------------------------------------------//
//    function CheckPageNumbers(){
//       if($("#divPaging a").length==1) $("#divPaging").html('');
//    }
//// ------------------------------------function to check page numbers--------------------------------------------------------------------------------------------------------------------//
//    function GeneratePageNumbers(){
//        Default.CreatePageNumbers(getSearchString(),getCategoryVal(),
//        function(result){
//            $("#divPaging").html(result.value);
//            $("#divPaging a").addClass('page');
//            CheckPageNumbers();
//        });
//    }
// ------------------------------------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){
        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){
        if(Validate(value))return;
        if(value=="close"){
            $("#dialog").dialog(value);
            $("#dialog").hide();
            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($("#hidValue").val(),value,function(isRated){
                $("#hidRatedValue").val(value);
                    if(isRated.value) $("#divRatingMessage").html("Already rated").addClass("Red smallText");
                else $("#divRatingMessage").html("Thanks for rating").addClass("smallText");;
                });
            }
         });
        $('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(){
        $('#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(){
        $("input[id$='txtpassword']").val('');
        setTimeout("StartPlayer()",1000); 
        var $modal  = $find('ctl00_mainContentPlaceHolder_ModalPopupExtender1');
        $modal.hide();
        $("#hidIsLive").val("false");
    }
// ------------------------------------function to ShowMoreInfo------------------------------------------------------------------------------------------------------------------//

    function ShowMoreInfo(){
        $("#OverFlowDiv").show();$("#divDescription").hide();
    }
    
// ------------------------------------function to IsFirefox2------------------------------------------------------------------------------------------------------------------//

    function IsFirefox2(){
         return ($.browser.mozilla && $.browser.version == "1.8.1.20");
    }
    
// ------------------------------------function to OpenEmailFriendWindow------------------------------------------------------------------------------------------------------------------//

    function OpenEmailFriendWindow() {
        var Path = document.location.href.toLowerCase().split('?')[0];
        var link="?CloseWindow=true&ItemId="+ GetSelectedID()+"&AdditionalMessage="+Path+"?ItemId="+ GetSelectedID()+"&emailfriend=true" ;
        window.open($("#"+virualPath+"").attr("href")+"Email.aspx"+link,'_blank','height=750,width=315');
    } 
    
// ------------------------------------function to OpenAbuseWindow------------------------------------------------------------------------------------------------------------------//
    function OpenAbuseWindow() {
        var Path = document.location.href.toLowerCase().split('?')[0];
        var link="?CloseWindow=true&ItemId="+ GetSelectedID()+"&abusereport=true&AdditionalMessage=" +Path+"?ItemId="+ GetSelectedID();
        window.open($("#"+virualPath+"").attr("href")+"Email.aspx"+link,'_blank','height=600,width=300');
    }
    
    
// ------------------------------------function to HideInvite------------------------------------------------------------------------------------------------------------------//
   
    function HideInvite() {

        if( $('#hidValue').val() =="") $('#divEmailFriends').attr("class","home-suggest-report hide") 
        
        else $('#divEmailFriends').attr("class","home-suggest-report") 
    } 
// ------------------------------------function to HideDIV------------------------------------------------------------------------------------------------------------------//
    function HideDIV(){

        if($("a[id$='lnkLive']").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();
    if(searchText==searchTitle){
        searchText="";
    }
    return searchText;    
}
// ------------------------------------function to CheckNoData------------------------------------------------------------------------------------------------------------------//

    function CheckNoData(value){     
        if(value==0) {
            $("#fillJson").html("<a href='javascript:SetNoResultFound();';>No Videos Available.</a>");
             $("#divPaging").html('');
            if("<%=AdvancedSearchValue %>".toLocaleLowerCase().length>0) return;
            $("select,input[id$='search'],a[id$='searchLnk'],div[id$='lnkRecent'],div[id$='lnkViewed'],img[id$='btnSearch']")
            .attr("disabled","true")
            .removeAttr("onclick");
            $("#searchLnk")
            .removeAttr("href").removeAttr("onclick");   
            return;    
         }
        if(value==null){
            $("#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 set ppv------------------------------------------------
 function fnsetppv() {
    if( document.getElementById ('ctl00_mainContentPlaceHolder_chkppv')) {
        if( document.getElementById ('ctl00_mainContentPlaceHolder_chkppv').checked==true ) {
            document.getElementById('divprice').className ="show";
            $("#divPopup").hide();
            }
        else {
            document.getElementById('divprice').className ="hide";
            $("#divPopup").show();}
        }
    }
    //-----------------------------------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 Change the jdlad------------------------------------------------
    function ChangeJDLAD(src){
        $("#jdlAd").attr("src",src);
    }