﻿// JScript File

// some variables to save for JW PLAYER
var currentPosition = 0;
var currentBuffer = 0; 
var currentVolume = 80; 
var currentState = 'IDLE';
var currentLoad = 0;
var plyValue;
var plyVideo;
var sfileName;
var globalPayRate = 0;

function LogoutWindow()
{  
     if (document.getElementById("hidSyndicationID").value == "-1")
     {
        window.parent.location="../Logout.aspx?endUserID=" + document.getElementById("hidEndUserID").value;     
     }
     else
     {  
        window.location="../Logout.aspx?endUserID=" + document.getElementById("hidEndUserID").value;  
        window.location = window.location.href;       
     }
}

function PrivateAccess_PageLoad()
{  
    if (document.getElementById("hidLineUpAccess").value != "0" && document.getElementById("ctl06_hidLineUpID").value != "0")
    {
        // Un-Play the Selected Video (otherwise audio will play on background)
        LoadPlayer('','','');    
            
        // Hide the Player Div tag
        document.getElementById("divPlayerContainer").style.display = "none";
        
        var oWindow = window.radopen("Login_Private.aspx?accountID=" + document.getElementById("hidAccountID").value + "&LineUpID=" + document.getElementById("ctl06_hidLineUpID").value,"rwWindow");
        //Using the reference to the window its clientside methods can be called  
        oWindow.SetSize(700,500);
        oWindow.center();
        oWindow.add_close(OnLoginClose);
        return false;
    }
}

// --------------------------------- OVERALL TEMPLATE FUNCTIONS -------------------------------------------

function PageLoad()
{    
    
   // HIDE THE BUTTONS
   document.getElementById("ctl06_btnVideo").style.display = "none"; 
   document.getElementById("ctl06_btnRating").style.display = "none"; 
        
   if (document.getElementById("hidTemplateID").value > 2)
   {  
       document.getElementById("ctl08_btnGoPage").style.display = "none";   
   }
   
   if (document.getElementById("hidTemplateID").value > 1)
   {  
       document.getElementById("ctl04_btnLogin").style.display = "none"; 
        
       // Hide the loggedin infor div
       document.getElementById("divLoggedInInfo").style.display = "none";
       document.getElementById("lnkMyAccount").style.display = "none";  
       document.getElementById("lnkMyPayment").style.display = "none";  
       document.getElementById("divPreLogin").style.display = "block"; 
   }   
   
     // HIDE THE REGISTRATION PANELS
    if ((document.getElementById("hidLineUpAccess").value == "0") && (document.getElementById("hidRegistrationAccess").value == "False"))
    { 
        document.getElementById("divPreLogin").style.display = "none";  
        document.getElementById("lnkRegister").style.display = "none";   
    }
      
}

function ReloadVideoDesc(theTitle,theDesc,theTags,thePath,theStatus,thePayRate,thePayStatus,theRating,theViews,theDuration)
{

   // Load the selected video description
    var descObj = "<h1>" + theTitle + "</h1>"
                  + theDesc + "<br />"
       
    descObj += "<i>Tags: </i>" + theTags + "<br />"
    descObj += "Views: " + theViews  + "<br />"   
    
    // HIDE THE RATING FEATURE
    if (document.getElementById("hidEnableRating").value == "True")       
        descObj += "<div id='divRating' style='padding-top:6px'></div>" // this div will have the values for rating (DynamicRatingStars)
   
    document.getElementById("divVideoDesc").innerHTML = descObj;   
    
    // HIDE THE RATING FEATURE
    if (document.getElementById("hidEnableRating").value == "True")       
        DynamicRatingStars(theRating); // FOR ABOVE "DIVRATING" TAG..
    
    // Hide the buttons
   document.getElementById("ctl06_btnVideo").style.display = "none"; 
   document.getElementById("ctl06_btnRating").style.display = "none"; 
}

function LoadVideoDesc(theTitle,theDesc,theTags,thePath,thePreRollPath,theRealPath,theStatus,thePayRate,thePayStatus,theRating,theViews,theDuration)
{               
    // Un-Play the Selected Video (otherwise audio will play on background)
    LoadPlayer('','','');    
      
   // THIS VIDEO DESCRIPTION IS NOT APPLICABLE FOR THUMBSIZE PLAYER
   if (document.getElementById("hidTemplateID").value == 0)
     document.getElementById("divVideoDesc").style.display = "none";
   else
   {  
       // Load the selected video description
        var descObj = "<h1>" + theTitle + "</h1>"
                      + theDesc + "<br />"
           
        descObj += "<i>Tags: </i>" + theTags + "<br />"
        descObj += "Views: " + theViews  + "<br />"   
        
        // HIDE THE RATING FEATURE
        if (document.getElementById("hidEnableRating").value == "True")     
            descObj += "<div id='divRating' style='padding-top:6px'></div>" // this div will have the values for rating (DynamicRatingStars)
       
        document.getElementById("divVideoDesc").innerHTML = descObj;   
        
        // HIDE THE RATING FEATURE
        if (document.getElementById("hidEnableRating").value == "True") 
            DynamicRatingStars(theRating); // FOR ABOVE "DIVRATING" TAG..
   }
   // ***** CODE STARTS FOR CHECK FOR THE VIDEO PAYMENT / FREE INFORMATION
   
    //// ******* FREE VIDEO *******///////
    if (thePayRate == '0.00')   
    {  
        // Hide the payment info Div tag
        document.getElementById("divVideo").style.display = "none";               
        // Play the Selected Video
        LoadPlayer(thePath,thePreRollPath,theRealPath);             
        return;           
    }
    //// ******* ALREADY PAID VIDEO *******///////    
    else if (theStatus == 'paid') 
    {                       
        // Hide the Player Div tag
        document.getElementById("divPlayerContainer").style.display = "none";        
        // Hide the payment info Div tag
        document.getElementById("divVideo").style.display = "block";
        
        // CHANGE THE IMAGE SIZE FOR THUMBSIZE PLAYER
        if (document.getElementById("hidTemplateID").value == 0)
            document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/smallPlayerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: x-small; color: Black; width: 234px; height: 192px;'><br /><br /><br /><br /><br />" + thePayStatus + "</div>";                 
        else            
        {
            if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageJW.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus + "</div>";                 
            }
            else if (document.getElementById("hidPlayerTypeID").value == 2)  // OPEN VIDEO PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus + "</div>";                 
            }
            else if (document.getElementById("hidPlayerTypeID").value == 3)  // WINDOWS MEDIA PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageWM.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus + "</div>";                 
            }
        }
        return;          
    }     
    //// ******* PAID VIDEO (BEFORE LOGIN) *******///////
    else if (thePayRate != '0.00' && document.getElementById("hidLoginStatus").value == 'Not-Logged-In')   // check for paid video + Not logged in 
    {   
     
    // *********************** CODE STARTS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
////////////////////        if (theStatus == 'archived')
////////////////////            PlaySampleVideo(theRealPath);    // play the first 10 seconds video
////////////////////        else if (theStatus == 'live')
////////////////////        {
////////////////////           // Hide the Player Div tag
////////////////////           document.getElementById("divPlayerContainer").style.display = "none";         
////////////////////           // Hide the payment info Div tag
////////////////////           document.getElementById("divVideo").style.display = "block";
////////////////////        } 
        
    // *********************** CODE ENDS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
    // ******************* CODE STARTS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
    
           // Hide the Player Div tag
           document.getElementById("divPlayerContainer").style.display = "none";         
           // Hide the payment info Div tag
           document.getElementById("divVideo").style.display = "block";
           
    // ******************* CODE ENDS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
                     
               
        // CHANGE THE IMAGE SIZE FOR THUMBSIZE PLAYER
        if (document.getElementById("hidTemplateID").value == 0)
        {
            if (theStatus == 'archived')
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/smallPlayerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: xx-small; color: Black; width: 234px; height: 192px;'><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
            if (theStatus == 'live')
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/smallPlayerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: xx-small; color: Black; width: 234px; height: 192px;'><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
        }   
        else
        {
            if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
            {
                if (theStatus == 'archived')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageJW.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
                if (theStatus == 'live')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageJW.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> LIVE VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
            }
            else if (document.getElementById("hidPlayerTypeID").value == 2)  // OPEN VIDEO PLAYER OBJECT
            {
                if (theStatus == 'archived')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
                if (theStatus == 'live')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> LIVE VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
            }
            else if (document.getElementById("hidPlayerTypeID").value == 3)  // WINDOWS MEDIA PLAYER OBJECT
            {
                if (theStatus == 'archived')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageWM.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
                if (theStatus == 'live')
                    document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageWM.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=\"color: White;\">THE <b><i>" + theTitle + "</i></b> LIVE VIDEO IS A PAY VIDEO.<br/><a href=\"javascript://\" onclick=\"OpenLoginWindow()\" style=\"color:White;\">Click Here</a> TO LOGIN & PROCEED</span></div>";               
            }
        }            
        return;
    }    
    //// ******* PAID VIDEO (AFTER LOGIN) *******///////
    else if (thePayRate != '0.00' && document.getElementById("hidLoginStatus").value == 'Logged-In')  // check for paid video + logged in Success
    {       
        
    // *********************** CODE STARTS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
////////////////////        if (theStatus == 'archived')
////////////////////            PlaySampleVideo(theRealPath);    // play the first 10 seconds video
////////////////////        else if (theStatus == 'live')
////////////////////        {
////////////////////           // Hide the Player Div tag
////////////////////           document.getElementById("divPlayerContainer").style.display = "none";         
////////////////////           // Hide the payment info Div tag
////////////////////           document.getElementById("divVideo").style.display = "block";
////////////////////        } 
        
    // *********************** CODE ENDS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
    // ******************* CODE STARTS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
    
           // Hide the Player Div tag
           document.getElementById("divPlayerContainer").style.display = "none";         
           // Hide the payment info Div tag
           document.getElementById("divVideo").style.display = "block";
           
    // ******************* CODE ENDS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
       
                
        // CHANGE THE IMAGE SIZE FOR THUMBSIZE PLAYER
        if (document.getElementById("hidTemplateID").value == 0)
            document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/smallPlayerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: x-small; color: Black; width: 234px; height: 192px;'><br /><br /><br /><br /><br />" + thePayStatus  + "</div>"; 
        else
        {
            if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageJW.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus  + "</div>";                 
            }
            else if (document.getElementById("hidPlayerTypeID").value == 2)  // OPEN VIDEO PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImage.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus  + "</div>"; 
            }
            else if (document.getElementById("hidPlayerTypeID").value == 3)  // WINDOWS MEDIA PLAYER OBJECT
            {
                document.getElementById("divVideo").innerHTML = "<div style='background: url(../images/Index_Custom/playerImageWM.jpg) repeat-x top left #101010; font-family: Verdana; font-size: smaller; color: Black; width: 450px; height: 350px;'><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />" + thePayStatus  + "</div>";                 
            }
        }            
        return;      
    }
}


// ****************CODE STARTS HERE TO PLAY THE FIRST 10 SECONDS VIDEO ON THE JW PLAYER **************


// PLAY VIDEO IN JW PLAYER (FOR FIRST 5 SECONDS)
function PlaySampleVideo(thePath) 
{   
   // Hide the Player Div tag
   document.getElementById("divPlayerContainer").style.display = "block";         
   // Hide the payment info Div tag
   document.getElementById("divVideo").style.display = "none";
   
   var heightValue = 350;
   var widthValue = 450;
   
   if (document.getElementById("hidTemplateID").value == 0)
   {        
       heightValue = 192;
       widthValue = 234;
   }
   
    //alert(thePath);
    var sCnt = document.getElementById("divPlayerContainer");
    var sSrc = '../wmvplayer.xaml';
    var sCfg = {
	    file: thePath,
	    autostart: 'true',
	    repeat: 'false',
	    height: heightValue,
	    width: widthValue,
	    backcolor:'000000',
	    frontcolor:'cccccc',
	    lightcolor:'660000',
	    shownavigation: 'false'
    };
	
    plyVideo = new jeroenwijering.Player(sCnt,sSrc,sCfg);
    
    addVideoListeners(); // play the sample video 
    
}
       
function addVideoListeners() 
{
	if(plyVideo.view) 
		plyVideo.addListener('TIME', setVideoDuration);
	else 
		setTimeout("addVideoListeners()",100);
}

function setVideoDuration(pos,dur) 
{ 
	currentPosition = pos;
	
//	if (parseInt(dur) < 50)
//	    currentPosition = parseInt(dur) / 2;
//	else
//	    currentPosition = pos;
	    
//	var tmp = document.getElementById("time"); 
//	if (tmp) 
//	{ tmp.innerHTML = "<b>Position:</b> "+pos+", <b>duration:</b> "+dur;  }

    if (pos == 10)
    {
       plyVideo.sendEvent('stop');
	   
       // Hide the Player Div tag
       document.getElementById("divPlayerContainer").style.display = "none";         
       // Hide the payment info Div tag
       document.getElementById("divVideo").style.display = "block";
       
       // Open Login Page
       if (document.getElementById("hidLoginStatus").value == "Not-Logged-In" && parseInt(globalPayRate) > 0)
       {   
            OpenLoginWindow();
       }
       
       // Open Payment Page
       if ((document.getElementById("hidLoginStatus").value == "Logged-In") && (document.getElementById("ctl06_hidPaymentStatus").value == "notpaid") && parseInt(globalPayRate) > 0)
       {   
            OpenPaymentWindow(globalPayRate);
       }
    }
}

// ****************CODE ENDS HERE TO PLAY THE FIRST 10 SECONDS VIDEO ON THE JW PLAYER **************

function LoadPlayer(filePath,preRollPath,realPath)
{   
    // Show the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "block";
    
    // FOR THUMBSIZE PLAYER
    if (document.getElementById("hidTemplateID").value == 0)
    {            
        // Create a player object
        if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
        {    
            sfileName = 'empty-1';    
            sfileName = realPath; // Assign the file 
            
            // PLAY THE PRE ROLL VIDEO
            if (preRollPath == "")
                SetVideo(sfileName, 'true', 1, 192, 234);    // Loads the Player    
            else
                SetVideo(preRollPath, 'false', 0, 192, 234);    // Loads the JW Player    
        }
        else if (document.getElementById("hidPlayerTypeID").value == 2) // OPEN VIDEO PLAYER OBJECT
        {    
            var playerObj = "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='234px' height='192px' id='slp' style='z-index:-1' >"
                + "<param name='source' value='../OVP.xap'/>"
                + "<param name='minRuntimeVersion' value='2.0.30923.0' />"
                + "<param name='onerror' value='onSilverlightError' />"
                + "<param name='MaxFrameRate' value='30' />"
                + "<param name='Windowless' value='True' />"
                + "<param name='initparams' value='showstats=false, autoplay=true, showplaylist=false, muted=false, playlistoverlay=false, stretchmode=fit,"
                + "playlist=" + filePath + "' />"
                + "<a href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'>"
                + "<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"
                + "</object>";
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }
        else if (document.getElementById("hidPlayerTypeID").value == 3) // WINDOWS MEDIA PLAYER OBJECT
        {            
            var playerObj = '<OBJECT ID="WMPlayer"  CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="234" HEIGHT="192" showstatusbar="True">'
                +'<PARAM NAME="AutoStart" VALUE="True" >'
                +'<PARAM NAME="stretchToFit" VALUE="True">'
                +' <PARAM NAME="URL" VALUE="'+ realPath +'">'
                +'<PARAM NAME="enableContextMenu" VALUE="False">'                   
                 +'<EMBED TYPE="application/x-mplayer2" '
                +'SRC="'+ realPath +'" '
                +'NAME="WMPlayer"'
                +'WIDTH="234"'
                +'HEIGHT="192"'
                +'EnableContextMenu="False"'
                +'AUTOSTART="True" showstatusbar="True" stretchToFit="True" ' 
                +'SHOWCONTROLS="False">'
                +'</EMBED>'
                +'</OBJECT>'; 
                
            
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }         
    }
    else if (document.getElementById("hidTemplateID").value > 0)
    {        
        // Create a player object
        if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
        {    
            sfileName = 'empty-1';    
            sfileName = realPath; // Assign the file 
            
            // PLAY THE PRE ROLL VIDEO
            if (preRollPath == "")
                SetVideo(sfileName, 'true', 1, 350, 450);    // Loads the Player    
            else
                SetVideo(preRollPath, 'false', 0, 350, 450);    // Loads the JW Player   
        }
        else if (document.getElementById("hidPlayerTypeID").value == 2) // OPEN VIDEO PLAYER OBJECT
        {    
            var playerObj = "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='450px' height='350px' id='slp' style='z-index:-1' >"
                + "<param name='source' value='../OVP.xap'/>"
                + "<param name='minRuntimeVersion' value='2.0.30923.0' />"
                + "<param name='onerror' value='onSilverlightError' />"
                + "<param name='MaxFrameRate' value='30' />"
                + "<param name='Windowless' value='True' />"
                + "<param name='initparams' value='showstats=false, autoplay=true, showplaylist=false, muted=false, playlistoverlay=false, stretchmode=fit,"
                + "playlist=" + filePath + "' />"
                + "<a href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'>"
                + "<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"
                + "</object>";
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }
        else if (document.getElementById("hidPlayerTypeID").value == 3) // WINDOWS MEDIA PLAYER OBJECT
        {            
            var playerObj = '<OBJECT ID="WMPlayer"  CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="450" HEIGHT="350" showstatusbar="True">'
                +'<PARAM NAME="AutoStart" VALUE="True" >'
                +'<PARAM NAME="stretchToFit" VALUE="True">'
                +' <PARAM NAME="URL" VALUE="'+ realPath +'">'
                +'<PARAM NAME="enableContextMenu" VALUE="False">'                   
                 +'<EMBED TYPE="application/x-mplayer2" '
                +'SRC="'+ realPath +'" '
                +'NAME="WMPlayer"'
                +'WIDTH="450"'
                +'HEIGHT="350"'
                +'EnableContextMenu="False"'
                +'AUTOSTART="True" showstatusbar="True"' 
                +'SHOWCONTROLS="True">'
                +'</EMBED>'
                +'</OBJECT>'; 
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }                        
    }                     
            
    // HIDE THE btnVideo BUTTON
    document.getElementById("ctl06_btnVideo").style.display = "none";   
    document.getElementById("ctl06_btnRating").style.display = "none";         
}


/// Plays the mentioned playlist file.
function PlayIt(videoID, option, payRate)
{       
    document.getElementById("ctl06_hidClickedVideoID").value = videoID;    
    document.getElementById("ctl06_hidClickedVideoStatus").value = option;
        
    // DISPLAY THE btnVideo BUTTON
    document.getElementById("ctl06_btnVideo").style.display = "block";
    
    // CLICK THE btnVideo BUTTON
    document.frmIndexBasic.ctl06_btnVideo.click();
    
    
    // *********************** CODE STARTS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
//////////////////////    if ((option == 'live') || (option == 'fv_live'))
//////////////////////    {
//////////////////////        // Open Login Page
//////////////////////        if (document.getElementById("hidLoginStatus").value == "Not-Logged-In" && parseInt(payRate) > 0)
//////////////////////        {   
//////////////////////             OpenLoginWindow();
//////////////////////        }
//////////////////////    
//////////////////////        // Open Payment Page
//////////////////////        if ((document.getElementById("hidLoginStatus").value == "Logged-In") && (document.getElementById("ctl06_hidPaymentStatus").value == "notpaid") && parseInt(payRate) > 0)
//////////////////////        {   
//////////////////////             OpenPaymentWindow(payRate);
//////////////////////        }
//////////////////////    }
//////////////////////    else 
//////////////////////        globalPayRate = payRate;
        
    // *********************** CODE ENDS FOR PLAY THE FIRST 10 SECONDS VIDEO ********************************
    
    // ******************* CODE STARTS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
    
        // Open Login Page
        if (document.getElementById("hidLoginStatus").value == "Not-Logged-In" && parseInt(payRate) > 0)
        {   
             OpenLoginWindow();
        }
    
        // Open Payment Page
        if ((document.getElementById("hidLoginStatus").value == "Logged-In") && (document.getElementById("ctl06_hidPaymentStatus").value == "notpaid") && parseInt(payRate) > 0)
        {   
             OpenPaymentWindow(payRate);
        }
           
    // ******************* CODE ENDS NEEDS TO COMMENT, IF WE ARE GOING TO USE THE 10 SECONDS VIDEO ******************
       
} 

function UserLogin()
{    
    if (document.getElementById("ctl04_txtUserName").value == '')
    {
        alert("Enter Username");
        document.getElementById('ctl04_txtUserName').focus();
        return;
    }
    if (isEmail(document.getElementById('ctl04_txtUserName').value)==false)
    {
        alert("Please Enter a Valid Email ID and Continue !!");
        document.getElementById('ctl04_txtUserName').select();
        return;
    }           
    if (document.getElementById("ctl04_txtPassword").value == '')
    {
        alert("Enter Password");
        document.getElementById('ctl04_txtPassword').focus();
        return;
    }    
    document.getElementById("ctl04_btnLogin").style.display = "block";
    
    document.frmIndexBasic.ctl04_btnLogin.click();  
}

function LoginSuccess(endUserID, userName)
{       
    if (endUserID != '' && userName != '')
    {   
        document.getElementById("hidLoginStatus").value = "Logged-In";
    }
       
    // Hide the PreLogin Div tag
    document.getElementById("divPreLogin").style.display = "none";
    document.getElementById("lnkRegister").style.display = "none";  
                    
    // UnHide the loggedin infor div
    document.getElementById("divLoggedInInfo").style.display = "block";
    document.getElementById("lnkMyAccount").style.display = "block";  
    document.getElementById("lnkMyPayment").style.display = "block";     
      
    // Set the argument values
    document.getElementById("hidEndUserID").value = endUserID;    
    document.getElementById("ctl04_lblLoggedIn").innerHTML = userName;
        
    // Hide the dummy button
    document.getElementById("ctl04_btnLogin").style.display = "none"; 
    
    // Play the Selected File
    PlayIt(document.getElementById("ctl06_hidClickedVideoID").value, document.getElementById("ctl06_hidClickedVideoStatus").value, 0);
}

function LoginFailure(message)
{   
   // Hide the loggedin infor div
    document.getElementById("divLoggedInInfo").style.display = "none";
    document.getElementById("lnkMyAccount").style.display = "none";  
    document.getElementById("lnkMyPayment").style.display = "none";  
    document.getElementById("divPreLogin").style.display = "block";        
    document.getElementById("ctl04_btnLogin").style.display = "none";       
    document.getElementById("ctl04_txtUserName").focus();         
    alert(message);
}

function OpenLoginWindow()
{  		    
    // Hide the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "none";
        
    var oWindow = window.radopen("Login.aspx?accountID=" + document.getElementById("hidAccountID").value,"rwWindow");
    //Using the reference to the window its clientside methods can be called  
    oWindow.SetSize(450,600);
    oWindow.center();
    oWindow.add_close(OnLoginClose);
    return false;
}

function OnLoginClose(oWnd)
{    
    // Display the Player Div tag
    if (document.getElementById("divVideo").style.display == "none")
        document.getElementById("divPlayerContainer").style.display = "block";
        
    // Hide the payment info Div tag
    if (document.getElementById("divPlayerContainer").style.display == "block")
        document.getElementById("divVideo").style.display = "none";
        
    //get the transferred arguments
    var endUserID = oWnd.argument.endUserID;
    var userName = oWnd.argument.userName;
        
    if (endUserID > 0 && userName != '')
    {   
        document.getElementById("hidLoginStatus").value = "Logged-In";
        
        if (document.getElementById("hidTemplateID").value > 1)
        {
            // Hide the PreLogin Div tag
            document.getElementById("divPreLogin").style.display = "none";
            document.getElementById("lnkRegister").style.display = "none";  
                            
           // UnHide the loggedin infor div
           document.getElementById("divLoggedInInfo").style.display = "block";
           document.getElementById("lnkMyAccount").style.display = "block";  
           document.getElementById("lnkMyPayment").style.display = "block";     
        }
    }
    
    // Set the argument values
    document.getElementById("hidEndUserID").value = endUserID;
         
    if (document.getElementById("hidTemplateID").value > 1)
    {
        document.getElementById("ctl04_lblLoggedIn").innerHTML = userName;
    }    
    
    // Play the Selected File
    if (endUserID > 0)   
        PlayIt(document.getElementById("ctl06_hidClickedVideoID").value, document.getElementById("ctl06_hidClickedVideoStatus").value, 0);            
}

function OpenUserWindow(page)
{   
    // Hide the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "none";
            
    var oWindow = window.radopen("../" + page + ".aspx?UserID=" + document.getElementById("hidAccountID").value + "&endUserID=" + document.getElementById("hidEndUserID").value,"rwWindow");
    //Using the reference to the window its clientside methods can be called  
    oWindow.SetSize(650,500);
    oWindow.center();    
    oWindow.add_close(OnUserClose);
    return false;
}

function OnUserClose(oUserWnd)
{       
    // Display the Player Div tag
    if (document.getElementById("divVideo").style.display == "none")
        document.getElementById("divPlayerContainer").style.display = "block";
    // Hide the payment info Div tag
    if (document.getElementById("divPlayerContainer").style.display == "block")
        document.getElementById("divVideo").style.display = "none";
}

function OpenPaymentWindow(payRate)
{   
    var UpEventID;
    var VideoID = document.getElementById("ctl06_hidClickedVideoID").value;
    if ((document.getElementById("ctl06_hidClickedVideoStatus").value == 'playlist') || (document.getElementById("ctl06_hidClickedVideoStatus").value == 'fv_archived') || (document.getElementById("ctl06_hidClickedVideoStatus").value == 'archived'))
        UpEventID = '0';
    else
        UpEventID = document.getElementById("ctl06_hidClickedUpcomingEventID").value;
    
    var oWindow = window.radopen("paymentProcess.aspx?videoID="+ VideoID + "&upEventID="+ UpEventID + "&payRate=" + payRate + "&endUserID=" + document.getElementById("hidEndUserID").value + "&PlayerID=" + document.getElementById("hidPlayerID").value + "&SyndicationID=" + document.getElementById("hidSyndicationID").value,"rwWindow");
    //Using the reference to the window its clientside methods can be called  
    oWindow.SetSize(600,500);
    oWindow.center();
    oWindow.add_close(OnPaymentClose);
    return false;
}

function OnPaymentClose(oPaymentWnd)
{             
    // Display the Player Div tag
    if (document.getElementById("divVideo").style.display == "none")
        document.getElementById("divPlayerContainer").style.display = "block";
        
    // Hide the payment info Div tag
    if (document.getElementById("divPlayerContainer").style.display == "block")
        document.getElementById("divVideo").style.display = "none";
        
    //get the transferred arguments
    var videoID = oPaymentWnd.argument.videoID;
    var strEndUserID = oPaymentWnd.argument.strEndUserID;
    
    // Set the argument values
    document.getElementById("hidEndUserID").value = strEndUserID;
    
    // Play the selected video after successful payment
    PlayIt(videoID, document.getElementById("ctl06_hidClickedVideoStatus").value, 0);
}

function Done(theFile)
{ 
    // Hide the payment info Div tag
    document.getElementById("divVideo").style.display = "none";
        
    // Show the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "block";
    
    if (document.getElementById("hidTemplateID").value == 0)
    {
         // Create a player object
        if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
        {    
            SetVideo(theFile, 'true', 1, 192, 234);    // Loads the Player  
        }
        else if (document.getElementById("hidPlayerTypeID").value == 2) // OPEN VIDEO PLAYER OBJECT
        {    
            var playerObj = "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='234px' height='192px' id='slp' style='z-index:-1' >"
                + "<param name='source' value='../OVP.xap'/>"
                + "<param name='minRuntimeVersion' value='2.0.30923.0' />"
                + "<param name='onerror' value='onSilverlightError' />"
                + "<param name='MaxFrameRate' value='30' />"
                + "<param name='Windowless' value='True' />"
                + "<param name='initparams' value='showstats=false, autoplay=true, showplaylist=false, muted=false, playlistoverlay=false, stretchmode=fit,"
                + "mediasource=" + theFile + "' />"
                + "<a href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'>"
                + "<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"
                + "</object>";
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }
        else if (document.getElementById("hidPlayerTypeID").value == 3) // WINDOWS MEDIA PLAYER OBJECT
        {            
            var playerObj = '<OBJECT ID="WMPlayer"  CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="234" HEIGHT="192" showstatusbar="True">'
                +'<PARAM NAME="AutoStart" VALUE="True" >'
                +'<PARAM NAME="stretchToFit" VALUE="True">'
                +' <PARAM NAME="URL" VALUE="'+ theFile +'">'
                +'<PARAM NAME="enableContextMenu" VALUE="False">'                   
                 +'<EMBED TYPE="application/x-mplayer2" '
                +'SRC="'+ theFile +'" '
                +'NAME="WMPlayer"'
                +'WIDTH="234"'
                +'HEIGHT="192"'
                +'EnableContextMenu="False"'
                +'AUTOSTART="True" showstatusbar="True" stretchToFit="True"' 
                +'SHOWCONTROLS="True">'
                +'</EMBED>'
                +'</OBJECT>'; 
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }    
    }
    else if (document.getElementById("hidTemplateID").value > 0)
    {        
        // Create a player object
        if (document.getElementById("hidPlayerTypeID").value == 1)  // JW PLAYER OBJECT
        {    
            SetVideo(theFile, 'true', 1, 350, 450);    // Loads the Player  
        }
        else if (document.getElementById("hidPlayerTypeID").value == 2) // OPEN VIDEO PLAYER OBJECT
        {    
            var playerObj = "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='450px' height='350px' id='slp' style='z-index:-1' >"
                + "<param name='source' value='../OVP.xap'/>"
                + "<param name='minRuntimeVersion' value='2.0.30923.0' />"
                + "<param name='onerror' value='onSilverlightError' />"
                + "<param name='MaxFrameRate' value='30' />"
                + "<param name='Windowless' value='True' />"
                + "<param name='initparams' value='showstats=false, autoplay=true, showplaylist=false, muted=false, playlistoverlay=false, stretchmode=fit,"
                + "mediasource=" + theFile + "' />"
                + "<a href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'>"
                + "<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"
                + "</object>";
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }
        else if (document.getElementById("hidPlayerTypeID").value == 3) // WINDOWS MEDIA PLAYER OBJECT
        {            
            var playerObj = '<OBJECT ID="WMPlayer"  CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="450" HEIGHT="350" showstatusbar="True">'
                +'<PARAM NAME="AutoStart" VALUE="True" >'
                +'<PARAM NAME="stretchToFit" VALUE="True">'
                +' <PARAM NAME="URL" VALUE="'+ theFile +'">'
                +'<PARAM NAME="enableContextMenu" VALUE="False">'                   
                 +'<EMBED TYPE="application/x-mplayer2" '
                +'SRC="'+ theFile +'" '
                +'NAME="WMPlayer"'
                +'WIDTH="450"'
                +'HEIGHT="350"'
                +'EnableContextMenu="False"'
                +'AUTOSTART="True" showstatusbar="True" stretchToFit="True"' 
                +'SHOWCONTROLS="True">'
                +'</EMBED>'
                +'</OBJECT>'; 
                
            // Place the object in div tag
            document.getElementById("divPlayerContainer").innerHTML = playerObj; 
        }                        
    }

    // HIDE THE btnVideo BUTTON
    document.getElementById("ctl06_btnVideo").style.display = "none"; 
    
}

function ShowRequest()
{ 
    // Hide the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "none";
    
    var VideoLineUpID = document.getElementById("ctl06_hidLineUpID").value;
    
    var oWindow = window.radopen("../syndicationRequest.aspx?UserID=" + document.getElementById("hidAccountID").value + "&PlayerID=" + document.getElementById("hidPlayerID").value + "&VideoLineUpID=" + VideoLineUpID,"rwWindow");
    //Using the reference to the window its clientside methods can be called  
    oWindow.SetSize(500,400);
    oWindow.center();
    oWindow.add_close(OnSyndicateClose);
    return false;
}


function OnSyndicateClose(oWnd)
{           
    // Display the Player Div tag
    if (document.getElementById("divVideo").style.display == "none")
        document.getElementById("divPlayerContainer").style.display = "block";
        
    // Hide the payment info Div tag
    if (document.getElementById("divPlayerContainer").style.display == "block")
        document.getElementById("divVideo").style.display = "none";
}

function ShowFeedback()
{ 
    // Hide the Player Div tag
    document.getElementById("divPlayerContainer").style.display = "none";
        
    var oWindow = window.radopen("../feedback.aspx?UserID=" + document.getElementById("hidAccountID").value,"rwWindow");
    //Using the reference to the window its clientside methods can be called  
    oWindow.SetSize(500,450);
    oWindow.center();
    oWindow.add_close(OnFeedbackClose);
    return false;
}


function OnFeedbackClose(oWnd)
{           
    // Display the Player Div tag
    if (document.getElementById("divVideo").style.display == "none")
        document.getElementById("divPlayerContainer").style.display = "block";
        
    // Hide the payment info Div tag
    if (document.getElementById("divPlayerContainer").style.display == "block")
        document.getElementById("divVideo").style.display = "none";
}


function RateVideo(starValue)
{
    if (document.getElementById("hidEndUserID").value <= 0)
    {
        alert('Login to rate the video');
        if (document.getElementById("hidTemplateID").value > 1)
        {
            document.getElementById('ctl04_txtUserName').focus();
        } 
        return;
    }
    else
    {
        document.getElementById("ctl06_hidHiddenStars").value = starValue;    
        document.getElementById("ctl06_btnRating").style.display = "block";       
        document.frmIndexBasic.ctl06_btnRating.click();     
    }    
}

function CreateDynamicPagingControls(totalPage, endPage, pageDesc)
{    
  if (totalPage == 0)
  {  
     document.getElementById("divPageDesc").innerHTML = '&nbsp;&nbsp;&nbsp;';   
     return;
  }
  var divParent = document.getElementById('divPagingValues');
    
  document.getElementById("divPageDesc").innerHTML = '(' + pageDesc + ')'; 
     
  if (totalPage == 1)
  {        
     divParent.innerHTML = "Page: 1";
     return;
  }
  
  var startPage = (parseInt(endPage)-2);
  var endingPage = parseInt(endPage);  
    
  if (totalPage == 2)
  {        
     startPage = 1;
  }
  
  if (parseInt(startPage)>1)
  {     
     // document.getElementById("hidPageDisplay_4").value = (parseInt(endingPage)+3);
      // create div for next 3 button
      var newdiv = document.createElement('div_'+ (parseInt(startPage)-1));
      var divIdName = 'my_'+(parseInt(startPage)-1)+'+Div';
      newdiv.setAttribute('id',divIdName);
      
      // create link with href tag
      var value = 0;// for prev button
      newdiv.innerHTML = '<a href=\'javascript://\' onclick=\'GoPage('+ (parseInt(startPage)-1) +','+ value +')\'>Prev</a>' + '&nbsp';
      
      divParent.appendChild(newdiv);
    
  }
  
  for (var i=startPage; i<=endingPage; i++) 
  {    
//      if (i==startPage)
//      {        
//         divParent.innerHTML = "Page: ";
//      }
      
      var newdiv = document.createElement('div_'+ i);
      var divIdName = 'my_'+i+'+Div';
      newdiv.setAttribute('id',divIdName);
      
      // check for current page 
      var currentPage = document.getElementById("ctl08_hidCurrentPageNo").value;        
      if (currentPage == i)
      {  
        // create link without href tag
        newdiv.innerHTML = i + '&nbsp';      
      }
      else
      {
        // create link with href tag
        var value = 1;// for paging button
        newdiv.innerHTML = '<a href=\'javascript://\' onclick=\'GoPage('+ i +','+ value +')\'>' + i + '</a>' + '&nbsp';      
      }
      
      divParent.appendChild(newdiv);
  }
  if (parseInt(totalPage)>parseInt(endPage))
  {     
     // document.getElementById("hidPageDisplay_4").value = (parseInt(endingPage)+3);
      // create div for next 3 button
      var newdiv = document.createElement('div_'+ (parseInt(endPage)+1));
      var divIdName = 'my_'+(parseInt(endPage)+1)+'+Div';
      newdiv.setAttribute('id',divIdName);
      
      // create link with href tag
      var value = 2; // for next button
      newdiv.innerHTML = '<a href=\'javascript://\' onclick=\'GoPage('+ (parseInt(endPage)+1) +','+ value +')\'>Next</a>';
      
      divParent.appendChild(newdiv);
    
  }
  
  document.getElementById("ctl08_btnGoPage").style.display = "none";
}

function RemoveDynamicPagingControls(totalPage, endPage)
{  
  if (totalPage == 0)
     return;
        
  // Remove the existing Dynamic Paging COntrols
  var startPage = (parseInt(endPage)-2);
  var endingPage = parseInt(endPage);  
  var divParent = document.getElementById("divPagingValues");
  var olddiv;
        
  if (totalPage == 2)
  {        
     startPage = 1;
  }
  
    // Remove the prev button
  if (parseInt(startPage)>1)
  {           
      olddiv = document.getElementById('my_'+(parseInt(startPage)-1)+'+Div');
      divParent.removeChild(olddiv);    
  }
  // Remove the paging
  for (var i=startPage; i<=endingPage; i++) 
  {   
      olddiv = document.getElementById('my_'+i+'+Div');
      divParent.removeChild(olddiv);
  }
  // remove for next 3 pages  
  if (parseInt(totalPage)>parseInt(endPage))
  {    
      olddiv = document.getElementById('my_'+(parseInt(endingPage)+1)+'+Div');
      divParent.removeChild(olddiv);
  }
}

function GoPage(selectedPage, selectedPageStatus)
{    
    document.getElementById("ctl08_hidClickedPageNo").value = selectedPage;
            
    document.getElementById("ctl08_hidPageClickedStatus").value = selectedPageStatus;
        
    document.getElementById("ctl08_btnGoPage").style.display = "block";
     
    document.frmIndexBasic.ctl08_btnGoPage.click();      
}

function CreateDynamicSchedulerPagingControls(totalPage, pageDesc)
{  
  if (totalPage == 0)
  {
     //document.getElementById("divPageDesc").innerHTML = '&nbsp;No Video Available';   
     document.getElementById("div_SchPageDesc").innerHTML = '&nbsp;&nbsp;&nbsp;'; 
     return;
  }
  var divParent = document.getElementById('divSch_PagingValues');
    
  document.getElementById("div_SchPageDesc").innerHTML = '&nbsp;(' + pageDesc + ')'; 
     
  for (var i=1; i<=totalPage; i++) 
  { 
      var newdiv = document.createElement('div_'+ i);
      var divIdName = 'mySch_'+i+'+Div';
      newdiv.setAttribute('id',divIdName);
      
      // check for current page 
      var schCurrentPage = document.getElementById("ctl10_hidSch_CurrentPageNo").value; 
                
      if (schCurrentPage == i)
      {  
        // create link without href tag
        newdiv.innerHTML = i + '&nbsp';      
      }
      else
      {
        // create link with href tag
        newdiv.innerHTML = '<a href=\'javascript://\' onclick=\'GoSchedulerPage('+ i +')\'>' + i + '</a>' + '&nbsp';      
      }
      
      divParent.appendChild(newdiv);
  }
      
  document.getElementById("ctl10_btnSch_GoPage").style.display = "none";
    
}

function RemoveDynamicSchedulerPagingControls(totalPage)
{ 
  if (totalPage == 0)
     return;
        
  // Remove the existing Dynamic Paging COntrols
  var divParent = document.getElementById("divSch_PagingValues");
  for (var i=1; i<=totalPage; i++) 
  { 
      var olddiv = document.getElementById('mySch_'+i+'+Div');
      divParent.removeChild(olddiv);
  }
  
}

/// Plays the mentioned file from the live event for PUBLISHER
function LiveEventPlayIt(selectedUserID, selectedVideoID, option)
{      
    if (selectedUserID > 0)
    {
        document.getElementById("ctl10_hidClickedLiveEventChannelID").value = selectedUserID;
        document.getElementById("ctl06_hidClickedScheduleChannelID").value = document.getElementById("ctl10_hidClickedLiveEventChannelID").value;
        // Call the play it function    
        PlayIt(selectedVideoID, option, 0);
    }
    else
        alert('Live Stream Not Available');
}

function GoSchedulerPage(selectedPage)
{   
    document.getElementById("ctl10_hidSch_ClickedPageNo").value = selectedPage;
            
    document.getElementById("ctl10_btnSch_GoPage").style.display = "block";
    
    document.frmIndexBasic.ctl10_btnSch_GoPage.click(); 
}

function DynamicRatingStars(totalRating)
{  
  var myStars=new Array("Poor","Good","VeryGood","Excellent","Awesome");
    
  var divRatingParent = document.getElementById('divRating');
              
  divRatingParent.innerHTML += "Total Rating: ";
      
  // LOOP FOR TOTAL RATING DISPLAY  
  for (var i=1; i<=totalRating; i++) 
  { 
      var alreadyRatingdiv = document.createElement('div_'+ i);
      var divIdName = 'myExistingRating_'+i+'+Div';
      alreadyRatingdiv.setAttribute('id',divIdName);          
      //newRatingdiv.setAttribute('class','stars');
                 
      var imgExistingStars = "imgExistingStars" + i; 
      
      // create stars
      alreadyRatingdiv.innerHTML = "<img src=\"../Images/Index_Custom_1/star_r.png\" border=\"0\" alt=\"" + myStars[totalRating-1] + "\" name=\"" + imgExistingStars + "\">";
      divRatingParent.appendChild(alreadyRatingdiv);
  }   
  
  // CHECK FOR USER LOGGED IN OR NOT
  if (document.getElementById("hidEndUserID").value != 0)
  { 
      divRatingParent.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rate this video: ";
          
      // LOOP FOR CURRENT RATING DISPLAY  
      for (var j=1; j<=5; j++) 
      { 
          var newRatingdiv = document.createElement('div_'+ j);
          var divIdName = 'myNewRating_'+j+'+Div';
          newRatingdiv.setAttribute('id',divIdName);          
          //newRatingdiv.setAttribute('class','stars');
                     
          var imgNewStars = "imgNewStars" + j; 
          
          // create stars
          newRatingdiv.innerHTML = "<a href=\"javascript://\" onclick=\"RateVideo(" + j + ")\" onmouseover=\"document." + imgNewStars + ".src='../Images/Index_Custom_1/star_g.png'\" onmouseout=\"document." + imgNewStars + ".src='../Images/Index_Custom_1/star_w.png'\"><img src=\"../Images/Index_Custom_1/star_w.png\" border=\"0\" alt=\"" + myStars[j-1] +"\" name=\"" + imgNewStars + "\"></a>";
          divRatingParent.appendChild(newRatingdiv);
      }   
  }
  else
  {
    divRatingParent.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript://' onclick='OpenLoginWindow();'>Login to rate this video</a>";
  }
     
}

function AlreadyRated(rating,totalRating)
{    
  var divRatingParent = document.getElementById('divRating');
              
  divRatingParent.innerHTML = "Total Rating: ";
      
  // rating    
  for (var i=1; i<=totalRating; i++) 
  { 
      var newRatingdiv = document.createElement('div_'+ i);
      var divIdName = 'myrating_'+i+'+Div';
      newRatingdiv.setAttribute('id',divIdName);          
      //newRatingdiv.setAttribute('class','stars');
                 
      var imgRatedStars = "imgRatedStars" + i; 
      
      // create stars
      newRatingdiv.innerHTML = "<img src=\"../Images/Index_Custom_1/star_r.png\" border=\"0\" alt=\"You have already rated " + rating + " stars to this video\" name=\"" + imgRatedStars + "\">";
      divRatingParent.appendChild(newRatingdiv);
  }        
  
  
  divRatingParent.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>You have already rated this video</b>";
}


// PLAY THE VIDEO IN JW PLAYER
function SetVideo(fileValue, showNav, flag, pHeight, pWidth) 
{   
   //alert(fileValue);
    var cnt = document.getElementById("divPlayerContainer");
    var src = '../wmvplayer.xaml';
    var cfg = {
	    file: fileValue,
	    autostart: 'true',
	    repeat: 'false',
	    height: pHeight,
	    width: pWidth,
	    backcolor:'000000',
	    frontcolor:'cccccc',
	    lightcolor:'660000',
	    shownavigation: showNav
    };
	
    plyValue = new jeroenwijering.Player(cnt,src,cfg);
    
    if (flag == 0) // 0 refers PRE-ROLL , 1 refers SELECTED VIDEO
    {
        addListeners(); // Check for the pre roll duration (to start the real file)
    }	
    
}


// ****************CODE STARTS HERE TO CHECK THE JW PLAYER EVENTS**************

function addListeners() 
{
	if(plyValue.view) 
	{
		plyValue.addListener('TIME',timeUpdate);
		//plyValue.addListener('VOLUME',volumeUpdate);
		//plyValue.addListener('LOAD',loadUpdate);
		plyValue.addListener('STATE',stateUpdate);
		//plyValue.addListener('BUFFER',bufferUpdate);
	} 
	else 
	{
		setTimeout("addListeners()",1000);
	}
}
// These are the event listeners

function timeUpdate(pos,dur) { 
	currentPosition = pos;
	//var tmp = document.getElementById("time"); 
	//if (tmp) { tmp.innerHTML = "<b>Position:</b> "+pos+", <b>duration:</b> "+dur; } 
}

function stateUpdate(ost,nst) {
	currentState = nst;
	//var tmp = document.getElementById("state");
	//if (tmp) { tmp.innerHTML = "<b>Old state:</b> "+ost+", <b>new state:</b> "+nst; }
	if (ost == 'Completed')
	    {
	       if (document.getElementById("hidTemplateID").value == 0)
           { 
	         // Loads the Player
	         SetVideo(sfileName, 'true', 1, 192, 234);    // PLAYS THE REAL SELECTED FILE..
	       }
	       else if (document.getElementById("hidTemplateID").value > 0)
           { 
	         // Loads the Player
	         SetVideo(sfileName, 'true', 1, 350, 450);    // PLAYS THE REAL SELECTED FILE..
	       }
	    }
} 
function bufferUpdate(pct) {
	currentBuffer = pct;
	var tmp = document.getElementById("buffer"); 
	if (tmp) { tmp.innerHTML = "<b>Buffer:</b> "+pct; }
}
function volumeUpdate(vol) {
	currentVolume = vol;
	var tmp = document.getElementById("volume"); 
	if (tmp) { tmp.innerHTML = "<b>Volume:</b> " + vol; } 
}
function loadUpdate(ldd) { 
	currentLoad = ldd;
	var tmp = document.getElementById("load"); 
	if (tmp) { tmp.innerHTML = "<b>Load:</b> " + ldd; } 
}
function printConfig() {
	var cfg = player.getConfig();
	var txt = '';
	for(var itm in cfg) { 
		txt += '<li>'+itm+': '+cfg[itm]+'</li>';
	}
	var tmp = document.getElementById("config");
	if (tmp) { tmp.innerHTML = txt; }
	
}
// ****************CODE ENDS HERE TO CHECK THE JW PLAYER EVENTS**************






/// -------------------------------------------------------------------------------------------------------------


// GENERAL SCRIPT FOR TEXTBOX VALIDATION, EMAIL, WHITESPACE...

     ////****************************************************************/

        // isEmail (STRING s [, BOOLEAN emptyOK])
        // 
        // Email address must be of form a@b.c ... in other words:
        // * there must be at least one character before the @
        // * there must be at least one character before and after the .
        // * the characters @ and . are both required
        //
        // For explanation of optional argument emptyOK,
        // see comments of function isInteger.
        // ***************************************************************/


        function isEmail (ls_str)
        {   if (isEmpty(ls_str)) 
               if (isEmail.arguments.length == 1) return defaultEmptyOK;
               else return (isEmail.arguments[1] == true);
           
            // is s whitespace?
            if (isWhitespace(ls_str)) return false;
            
            // there must be >= 1 character before @, so we
            // start looking at character position 1 
            // (i.e. second character)
            var li_Cnt = 1;
            var sLength = ls_str.length;

            // look for @
            while ((li_Cnt < sLength) && (ls_str.charAt(li_Cnt) != "@"))
            { li_Cnt++
            }

            if ((li_Cnt >= sLength) || (ls_str.charAt(li_Cnt) != "@")) return false;
            else li_Cnt += 2;

            // look for .
            while ((li_Cnt < sLength) && (ls_str.charAt(li_Cnt) != "."))
            { li_Cnt++
            }

            // there must be at least one character after the .
            if ((li_Cnt >= sLength - 1) || (ls_str.charAt(li_Cnt) != ".")) return false;
            else return true;
        }



        /****************************************************************/

        // Check whether string s is empty.

        function isEmpty(ls_str)
        {   return ((ls_str == null) || (ls_str.length == 0))
        }


        // DEFINE VARIABLES

        // whitespace characters
        var whitespace = " \t\n\r";

        /****************************************************************/

        // Returns true if string s is empty or 
        // whitespace characters only.

        function isWhitespace (ls_str)

        {   var li_cnt;

            // Is ls_str empty?
            if (isEmpty(ls_str)) return true;

            // Search through string's characters one by one
            // until we find a non-whitespace character.
            // When we do, return false; if we don't, return true.

            for (li_cnt = 0; li_cnt < ls_str.length; li_cnt++)
            {   
	        // Check that current character isn't whitespace.
	        var ls_chr = ls_str.charAt(li_cnt);

	        if (whitespace.indexOf(ls_chr) == -1) return false;
            }

            // All characters are whitespace.
            return true;
        }
        
        /****************/
	 function TextBoxValidation(strfield)
    {
	    var intCt;
	    var strkey;
	    var strtext;
	    strkey=strfield.value;
	   
	    for (intCt = 0; intCt < strkey.length; intCt++)
	    {
    	
		    if (strkey.charAt(0)==" ")
		    {
    			
			    strtext = strkey.substring(1,strkey.length);	
			    strfield.value = strtext;
		    }
    		
    		if(strkey.charAt(0) == ".")
    		{
    		    strtext = strkey.substring(1,strkey.length);	
			    strfield.value = strtext;
			    
    		}
    		
    		
    		
		    if (strkey.charAt(intCt)=="'")
		    {
			    strtext = strkey.substring(0,intCt);
			    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
			    strfield.value = strtext;							
		    }
		    else if (strkey.charAt(intCt) == " ")

			    {				
				    if (strkey.charAt(intCt -1 ) == " ")
				    {				
				    strtext = strkey.substring(0,intCt);
				    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
				    strfield.value = strtext;				
				    }
			    }	
			    
			    else if (strkey.charAt(intCt)==";")
		    {
			    strtext = strkey.substring(0,intCt);
			    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
			    strfield.value = strtext;				
		    }    
			else if (strkey.charAt(intCt)==":")
		    {
			    strtext = strkey.substring(0,intCt);
			    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
			    strfield.value = strtext;				
		    } 
			    
		    else if (strkey.charAt(intCt)=="<")
		    {
			    strtext = strkey.substring(0,intCt);
			    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
			    strfield.value = strtext;				
		    }
		    else if (strkey.charAt(intCt)==">")
		    {
			    strtext = strkey.substring(0,intCt);
			    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
			    strfield.value = strtext;				
		    }		
		    else if (strkey.charAt(intCt) == "@")

			    {				
				    if (strkey.charAt(intCt -1 ) == "@")
				    {				
				    strtext = strkey.substring(0,intCt);
				    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
				    strfield.value = strtext;	
				    }
			    }	
		    else if (strkey.charAt(intCt) == ".")

			    {				
				    if (strkey.charAt(intCt -1 ) == ".")
				    {				
				    strtext = strkey.substring(0,intCt);
				    strtext = strtext + strkey.substring(intCt + 1,strkey.length);	
				    strfield.value = strtext;				
				    }
			    }
	    }
    }