﻿/* Script for Loading the Video PlayList for More Videos Page */
var player = null;
    function playerReady(thePlayer) 
    {
	    player = document.getElementById(thePlayer.id);
	    printPlaylistData();
    }
    // Gets the Data from the XML and binds the data to a HTML table as below
    // Initially the Current,Previous Page is set to 1 and Next page as 2
    
    function printPlaylistData() 
    {               
	    var plst = null;	    
	    plst = player.getPlaylist();
	    if (plst) 
	    {	  	    
		    var txt='<table cellPadding="8" width="100%" >'; 		    		    
		    for(var i = 0; i <=4; i++)
		    {
		        txt+='<tr><td align=left><table cellspacing="0" cellPadding="5" width="100%"   onclick="player.sendEvent(\'ITEM\',' + i + ');callme('+ i +');"';
 			    txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
 			    if(i%2 == 0)
 			    {
 			        txt+='<tr><td class="blue_text123" colspan="3">' + plst[i].description + '</td></tr>';
 			        txt+='<tr><td class="gray_text123" colspan="3"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			        txt+='<tr><td class="txtstyle">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';	
 			        
 			    }
 			    else
 			    {
 			        txt+='<tr><td class="blue_text123" colspan="3" bgcolor="#F2F9FF">' + plst[i].description + '</td></tr>';
 			        txt+='<tr><td class="gray_text123" colspan="3" bgcolor="#F2F9FF"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			        txt+='<tr><td class="txtstyle" bgcolor="#F2F9FF">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;" bgcolor="#F2F9FF"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';		
 			        
 			        
 			    }
			    txt+='</td></tr></table></td></tr>';	
			    if(i == 0)
			    {
			        document.getElementById('lblHeading').innerHTML = plst[i].title.split('###')[0];	
			        document.getElementById('lblDate').innerHTML = plst[i].description;
			        document.getElementById('lblDescription').innerHTML = plst[i].author;  
			    }
		    }		   
            txt+='<tr><td><a style="cursor:hand;text-decoration:none;display:none;">First</a><a style="cursor:hand;text-decoration:none;display:none;">Previous</a><a style="cursor:hand;text-decoration:none;" onclick="getNextPageList()">Next</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getLastPageList()">Last</a></td></tr>';
		    txt+='</table>'; //alert(txt);            
		    var tmp = document.getElementById("plstDat");
		    if (tmp) 
		    { 
		        tmp.innerHTML = txt;
		        var temp = 1;
		        document.getElementById('hdnPage').value = temp;
		        document.getElementById('hdnNext').value = temp+1;
		    }
	    } 
	    else 
	    {
		    setTimeout("printPlaylistData()",100);
	    }	
    }
    // End of function
      
    /* Function for Getting the List when user clicks on the Next Page 
    Three hidden fields in the page stores the Current,Previous,Next page values, ex data is
    Current  Page : 2       gets the records from 20 to 30 and fills in HTML table 
    Previous Page : 1       Formula :   Current Page Value * 10 (10 records will be displayed) to   
    Next Page     : 3                   Next Page value * 10 */
    function getNextPageList()
    {                    
        var plst = null;   
        var start = 0;
        var end = 4;         
        var CurrentPage = document.getElementById('hdnPage').value;
        var NextPage = document.getElementById('hdnNext').value;
        var PreviousPage = document.getElementById('hdnPrevious').value;
                
        start = CurrentPage * 4;
        end = NextPage * 4; 
                       
	    plst = player.getPlaylist();
	    if (plst) 
	    {	  	      
	        if(CurrentPage == Math.floor(plst.length / 4))
	        {
	            getLastPageList();
	        }
	        else
	        {
		        var txt='<table cellPadding="8" width="100%"  border="0">'; 		    		    
		        for(var i = start; i <=end; i++)
		        {
		            txt+='<tr><td align=left><table cellspacing="0" width="100%"  border="0" cellPadding="5" onclick="player.sendEvent(\'ITEM\',' + i + ');callme('+ i +');" ';
 			        txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
 			        if(i%2 == 0)
 			        {
 			            txt+='<tr><td class="blue_text123" colspan="3">' + plst[i].description + '</td></tr>';
 			            txt+='<tr><td class="gray_text123" colspan="3"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			            txt+='<tr><td class="txtstyle">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';			   
 			        }
 			        else
 			        {
 			            txt+='<tr><td class="blue_text123" colspan="3" bgcolor="#F2F9FF">' + plst[i].description + '</td></tr>';
 			            txt+='<tr><td class="gray_text123" colspan="3" bgcolor="#F2F9FF"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			            txt+='<tr><td class="txtstyle" bgcolor="#F2F9FF">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;" bgcolor="#F2F9FF"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';		
 			        }
			        txt+='</td></tr></table></td></tr>';			    
		        }		   
                txt+='<tr><td><a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getFirstPageList()">First</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getPreviousPage()">Previous</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getNextPageList()">Next</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getLastPageList()">Last</a></td></tr>';
		        txt+='</table>';

		        var tmp = document.getElementById("plstDat");
		        if (tmp) 
		        { 			            	    
		            tmp.innerHTML = txt;
		            var temp = document.getElementById('hdnPage').value;
		            document.getElementById('hdnPrevious').value = temp;
		            temp++;
		            document.getElementById('hdnPage').value = temp;
		            document.getElementById('hdnNext').value = temp + 1;    		        
		        }
		    }
	    } 
	    else 
	    {
		    setTimeout("getNextPageList()",100);
	    }
    }
    // End of function
    
    // AJAX function to save the details of the Video, End user computer information Like IP,Browser type etc
    function callme(i)
    {       
        var plst = null; 
        plst = player.getPlaylist();
	    if (plst) 
	    {	        
	        document.getElementById('lblHeading').innerHTML = plst[i].title.split('###')[0];	
			document.getElementById('lblDate').innerHTML = plst[i].description;
			document.getElementById('lblDescription').innerHTML = plst[i].author; 
			// AJAX Function For Saving the Video Views
			xmlHttp = GetXmlHttpObject(); 
            if (xmlHttp == null) 
            { 
                alert ("Browser does not support HTTP Request");
                return; 
            }
            //you can provide your page URL which will fetch you the values from your database
            var url = "ViewVideos.aspx"; 
            url = url + "?FLVid=" +plst[i].title.split('###')[2]+ "&ID="+plst[i].title.split('###')[1];
            //state change event-this will occur ass soon as response comes from the url
            xmlHttp.onreadystatechange = stateChanged; 
            xmlHttp.open("GET",url,true); 
            xmlHttp.send(null);   	    
	    }
	    else
	    {
	        setTimeout("callme("+i+")",100);
	    }        
    }
    // End of function
    
    /* Function for Getting the List when user clicks on the "Previous" Page 
    Three hidden fields in the page stores the Current,Previous,Next page values, ex data is
    Current  Page : 5       gets the records from 40 to 50 and fills in HTML table 
    Previous Page : 4       Formula :   Previous Page Value * 10 (10 records will be displayed) to   
    Next Page     : 6                   Current Page value * 10 */
    function getPreviousPage()
    {        
        var StartRecord;
        var EndRecord;
        var plst = null;            
        var CurrentPage = document.getElementById('hdnPage').value;
        var PreviousPage = document.getElementById('hdnPrevious').value;
        var NextPage = document.getElementById('hdnNext').value;        
        if(PreviousPage == 1)
        {
            StartRecord = 0;
            EndRecord   = 4;
        }
        else
        {
            StartRecord = PreviousPage*4;
            EndRecord   = CurrentPage*4;
        }
	    plst = player.getPlaylist();
	    if (plst) 
	    {		     
		    var txt='<table cellPadding="8" width="100%" border="0">'; 		    		    
		    for(var i = StartRecord; i <=EndRecord; i++)
		    {
		        txt+='<tr><td align=left><table cellspacing="0" width="100%"  border="0" cellPadding="5" onclick="player.sendEvent(\'ITEM\',' + i + ');callme('+ i +');" ';
 			    txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
 			    if(i%2 == 0)
 			    {
 			        txt+='<tr><td class="blue_text123" colspan="3">' + plst[i].description + '</td></tr>';
 			        txt+='<tr><td class="gray_text123" colspan="3"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			        txt+='<tr><td class="txtstyle">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';			   
 			    }
 			    else
 			    {
 			        txt+='<tr><td class="blue_text123" colspan="3" bgcolor="#F2F9FF">' + plst[i].description + '</td></tr>';
 			        txt+='<tr><td class="gray_text123" colspan="3" bgcolor="#F2F9FF"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
 			        txt+='<tr><td class="txtstyle" bgcolor="#F2F9FF">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;" bgcolor="#F2F9FF"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';		
 			    }
			    txt+='</td></tr></table></td></tr>';			    
		    }	
		    if(PreviousPage == 1)
		    {
		        txt+='<tr><td><a style="cursor:hand;text-decoration:none;display:none;">Previous</a><a style="cursor:hand;text-decoration:none;" onclick="getNextPageList()">Next</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getLastPageList()">Last</a></td></tr>';
		    }	
		    else
		    {   
                txt+='<tr><td><a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getFirstPageList()">First</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getPreviousPage()">Previous</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getNextPageList()">Next</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getLastPageList()">Last</a></td></tr>';
		    }
		    txt+='</table>';
    
		    var tmp = document.getElementById("plstDat");
		    if (tmp) 
		    { 		   		         
		        tmp.innerHTML = txt;
		        if(PreviousPage == 1)
		        {
		            var temp = PreviousPage;
		            temp++;
		            document.getElementById('hdnPage').value = PreviousPage;
		            document.getElementById('hdnPrevious').value = PreviousPage;
		            document.getElementById('hdnNext').value = temp;
		        }
		        else
		        {
                    CurrentPage = CurrentPage - 1;
                    PreviousPage = PreviousPage - 1;
                    NextPage = NextPage - 1;		            
		            document.getElementById('hdnPage').value = CurrentPage;
		            document.getElementById('hdnPrevious').value = PreviousPage	            		            
		            document.getElementById('hdnNext').value = NextPage;
		        }		       		        
		    }
	    } 
	    else 
	    {
		    setTimeout("getPreviousPage()",100);
	    }
    }
    // End of Function
     
    function createPlayer(theFile, theAutostart) 
    {
	    var flashvars = 
	    {
		    file:theFile,  
		    autostart:theAutostart, 
		    shuffle:false,
		    bufferlength:2,
		    smoothing:true,
		    stretching:"exactfit",
		    icons:false
		    //repeat:"list"
	    }

	    var params = 
	    {
		    allowfullscreen:"true", 
		    allowscriptaccess:"always",
		    wmode:"transparent"
	    }

	    var attributes = 
	    {
		    id:"player1",  
		    name:"player1"
	    }

	    swfobject.embedSWF("swf/Player_New.swf", "placeholder1", "420", "330", "9.0.115", false, flashvars, params, attributes);
    }


    function init() 
    {
	    createPlayer('xmldata/VideoDetails.xml', false); 
    }
    
var xmlHttp;
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function stateChanged() 
{ 
    //for a succesful event ready state  value of the xmlhttp object must contain these values
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
        //Display contents 
        var xmlResponse = xmlHttp.responseText; 
        if (xmlResponse!='') 
        { 
                              
        } 
        else 
        { 

        } 
    } 
}

// Function for getting the Records for "First" Button click
function getFirstPageList()
{                
    var plst = null;                
    plst = player.getPlaylist();
    if (plst) 
    {	    
	    var txt='<table cellPadding="8" width="100%"  >'; 		    		    
	    for(var i = 0; i <=4; i++)
	    {
	        txt+='<tr><td align=left><table cellspacing="0" width="100%" cellPadding="5"  onclick="player.sendEvent(\'ITEM\',' + i + ');callme('+ i +');" ';
		    txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
		    if(i%2 == 0)
		    {
		        txt+='<tr><td class="blue_text123" colspan="3">' + plst[i].description + '</td></tr>';
		        txt+='<tr><td class="gray_text123" colspan="3"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
		        txt+='<tr><td class="txtstyle">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';
 			    
		        
		    }
		    else
		    {
		        txt+='<tr><td class="blue_text123" colspan="3" bgcolor="#F2F9FF">' + plst[i].description + '</td></tr>';
		        txt+='<tr><td class="gray_text123" colspan="3" bgcolor="#F2F9FF"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
		        txt+='<tr><td class="txtstyle" bgcolor="#F2F9FF">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;" bgcolor="#F2F9FF"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';
 			    
		    }
		    txt+='</td></tr></table></td></tr>';			    
	    }		   
        txt+='<tr><td><a style="cursor:hand;text-decoration:none;display:none;" onclick="getPreviousPage()">Previous</a><a style="cursor:hand;text-decoration:none;" onclick="getNextPageList()">Next</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;" onclick="getLastPageList()">Last</a></td></tr>';
	    txt+='</table>';

	    var tmp = document.getElementById("plstDat");
	    if (tmp) 
	    { 		    
	        tmp.innerHTML = txt;
	        document.getElementById('hdnPage').value = 1;
	        document.getElementById('hdnPrevious').value = 1;	       
	        document.getElementById('hdnNext').value = 2;
	    }
    } 
    else 
    {
	    setTimeout("getFirstPageList()",100);
    }
}
// End of Function


// Function for getting the Records for "Last" Button click
function getLastPageList()
{       
    var LastStart;             
    var plst = null;                
    plst = player.getPlaylist();
    if (plst) 
    {	            
        var TotalRecords = plst.length;
        // If records divided by 10 gives a round no 
        if(TotalRecords % 4 == 0)
        {
            var Result          = TotalRecords / 4;
            var CurrentPage     = Result;
            var NextPage        = Result+1;
            var PreviousPage    = Result-1;
            LastStart           = PreviousPage*4;            
            //alert(" Total Records : " + TotalRecords + "\n Current Page : "+ CurrentPage + "\n Previous Page : " + PreviousPage + "\n Next Page : "+ NextPage);
        }
        else
        {
            var Result          = Math.floor(TotalRecords / 4);
            var CurrentPage     = Result;
            var NextPage        = Result+1;
            var PreviousPage    = Result-1;
            LastStart           = CurrentPage*4;            
            //alert(" Total Records : " + TotalRecords + "\n Current Page : "+ CurrentPage + "\n Previous Page : " + PreviousPage + "\n Next Page : "+ NextPage);
        }        
	    var txt='<table cellPadding="8" cellspacing="0" width="100%">'; 		    		    
	    for(var i = LastStart; i <TotalRecords; i++)
	    {
	        txt+='<tr><td align=left><table cellspacing="0" cellPadding="5" width="100%" border="0" onclick="player.sendEvent(\'ITEM\',' + i + ');callme('+ i +');" ';
		    txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
		    if(i%2 == 0)
		    {
		        txt+='<tr><td class="blue_text123" colspan="3">' + plst[i].description + '</td></tr>';
		        txt+='<tr><td class="gray_text123" colspan="3"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
		        txt+='<tr><td class="txtstyle">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';			   
		    }
		    else
		    {
		        txt+='<tr><td class="blue_text123" colspan="3" bgcolor="#F2F9FF">' + plst[i].description + '</td></tr>';
		        txt+='<tr><td class="gray_text123" colspan="3" bgcolor="#F2F9FF"><img alt="" src="images/bullet.gif" /><a href="#" style="cursor:hand;text-decoration:none;">' + plst[i].title.split('###')[0] + '</a></td></tr>';
		        txt+='<tr><td class="txtstyle" bgcolor="#F2F9FF">' + plst[i].author + '</td><td class="txtstyle" style="width: 100px; text-align: left;" bgcolor="#F2F9FF"><img alt="" src="images/view_video.jpg" style="cursor: hand" /><a href="#" style="cursor:hand;text-decoration:none;"> View Video</a></td></tr>';		
		    }
		    txt+='</td></tr></table></td></tr>';			    
	    }		   
        txt+='<tr><td><a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getFirstPageList()">First</a>&nbsp;&nbsp;<a style="cursor:hand;text-decoration:none;visibility:visible;" onclick="getPreviousPage()">Previous</a></td></tr>';
	    txt+='</table>';        
	    var tmp = document.getElementById("plstDat");
	    if (tmp) 
	    { 		    
	        tmp.innerHTML = txt;
	        document.getElementById('hdnPage').value = CurrentPage;
	        document.getElementById('hdnPrevious').value = PreviousPage;	       
	        document.getElementById('hdnNext').value = NextPage;
	    }
    } 
    else 
    {
	    setTimeout("getLastPageList()",100);
    }
}
// End of Function

function Detailnews_popup(aspx_page)
{
    window.open (aspx_page,"mywindow","menubar=0,resizable=0,width=628,status=0,location=0,directories=0,scrollbars=1,height=300,left=180,top=180");
}
