var ThePage; 								//This Var is the number of page for the pageing of 'Live Now'
var Showurl = "/Ajax/Live_GetLiveShow.asp";  	//This var is the url of the pageing of 'Live Now'
var ThePopVodsPage							//This Var is the number of page for the pageing of 'Popluar Videos'
var Popurl = "/Ajax/Channel_GetPopVods.asp";	//This var is the url of the pageing of 'Popluar Videos'
var TheEditVodsPage							//This Var is the number of page for the pageing of 'Editor pick'
var EditVodsurl = "/Ajax/Channel_GetEditVods.asp";	//This var is the url of the pageing of 'Editor pick'

//This function is for the ajax of the pagenig of 'Live Now'
function batchRsChange()
{    
	MinShowsNum=0;
	MaxShowsNum=0;
	if (ChannelobjXML && ChannelobjXML.readyState==4)
	{
        if (ChannelobjXML.responseXML)
		{                     
			var PageBtn;
			if(UpTabNum=='shows')
			{
				PageBtn = "NEXT ";
			}
			else
			{
				PageBtn = "NEXT";
			}
            var Str = ChannelobjXML.responseXML.getElementsByTagName("Str");
			if (Str[0].firstChild.data!='False')
			{
	            var TotalShowsNum = ChannelobjXML.responseXML.getElementsByTagName("TotalShowsNum");
	                TotalShowsNum = TotalShowsNum[0].firstChild.data;
	            var ShowsNum = ChannelobjXML.responseXML.getElementsByTagName("ShowsNum");
	                ShowsNum = (parseInt(ShowsNum[0].firstChild.data));
	                MinShowsNum = (parseInt(ThePage*ShowNumInPage)+1);
	                MaxShowsNum = (parseInt(MinShowsNum + ShowsNum)-1);
	                if(MinShowsNum==0)
	                    MinShowsNum = 1;            
	            document.getElementById("LiveShowDiv").innerHTML = Str[0].firstChild.data;
				
	            //Next And Previous Pages
	            //-----------------------
	            var LastPageStr = "<img onclick='Pageing("+ThePage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='Pageing("+ThePage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>&nbsp;" +
	                              "<a onclick='Pageing("+ThePage+",0)' class='PagingAct' title='PREVIOUS' id='PreviousPage'>PREVIOUS</a>";   
	            var FirstPageStr = "<a onclick='Pageing("+ThePage+",1)' class='PagingAct' title='"+PageBtn+"' id='NextPage'>"+PageBtn+"</a>&nbsp;" + 
	                               "<img onclick='Pageing("+ThePage+",1)' class='PagingAct' title='"+PageBtn+"' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='Pageing("+ThePage+",1)' class='PagingAct' title='"+PageBtn+"' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
	            
	            //Check If Is the Last Page
	            var MaxPages =(parseInt(TotalShowsNum/ShowNumInPage)-1);              
	            if (ThePage == MaxPages&&(TotalShowsNum%ShowNumInPage==0)||(ThePage > MaxPages))
	            {                
	                FirstPageStr = "<font class='PagingDis' id='NEXT'>"+PageBtn+"</font>&nbsp;" +
	                "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
	            }
	            
	            if (ThePage == 0)
	            {
	                LastPageStr = "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' alt='' width='4' height='5' border='0' align='absmiddle'>&nbsp;" +
	                "<font class='PagingDis' id='PreviousPage'> PREVIOUS</font>";
	            }
	            document.getElementById("amountOfItemsShows").innerHTML = MinShowsNum + "-" + MaxShowsNum;
	            document.getElementById("TotalamountOfItemsShows").innerHTML =TotalShowsNum;
				document.getElementById("PreviousPageTd").innerHTML = LastPageStr;
	            document.getElementById("NextPageTd").innerHTML = FirstPageStr;            
	            //-----------------------      
			}
			else
			{
				document.getElementById("LiveShowDiv").innerHTML ="<table width='100%' height='185' align='center' cellpadding='0' cellspacing='0' border='0'></table>";
                FirstPageStr = "<font class='PagingDis' id='MORE LIVE NOW'>"+PageBtn+"</font>&nbsp;" +
                "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
                LastPageStr = "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' alt='' width='4' height='5' border='0' align='absmiddle'>&nbsp;" +
                "<font class='PagingDis' id='PreviousPage'> PREVIOUS</font>";																  
	            document.getElementById("amountOfItemsShows").innerHTML =MinShowsNum + "-" + MaxShowsNum;
				document.getElementById("TotalamountOfItemsShows").innerHTML ="0";
	            document.getElementById("PreviousPageTd").innerHTML = LastPageStr;
	            document.getElementById("NextPageTd").innerHTML = FirstPageStr;            																  
			}     
		}
    }    
}

//This function is for the ajax of the pagenig of 'Popular Videos'
function batchPopVodsRsChange()
{    
	MinPopVods=0;
	MaxPopVods=0;
	if (ChannelobjXML && ChannelobjXML.readyState==4)
	{
        if (ChannelobjXML.responseXML)
		{                          
            var Str = ChannelobjXML.responseXML.getElementsByTagName("Str");
            var TotalPopVodsNum = ChannelobjXML.responseXML.getElementsByTagName("TotalPopVodsNum");
                TotalPopVodsNum = TotalPopVodsNum[0].firstChild.data;
            var PopVodsNum = ChannelobjXML.responseXML.getElementsByTagName("PopVodsNum");
                PopVodsNum = (parseInt(PopVodsNum[0].firstChild.data));
                MinPopVods = (parseInt(ThePopVodsPage*PopNumInPage)+1);
                MaxPopVods = (parseInt(MinPopVods + PopVodsNum)-1);
                if(MinPopVods==0)
                    MinPopVods = 1;            
            document.getElementById("PopVodsDiv").innerHTML = Str[0].firstChild.data;
			
            //Next And Previous Pages
            //-----------------------
            var LastPageStr = "<img onclick='PopVodsPageing("+ThePopVodsPage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='PopVodsPageing("+ThePopVodsPage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>&nbsp;" +
                              "<a onclick='PopVodsPageing("+ThePopVodsPage+",0)' class='PagingAct' title='PREVIOUS' id='PreviousPage'>PREVIOUS</a>";   
            var FirstPageStr = "<a onclick='PopVodsPageing("+ThePopVodsPage+",1)' class='PagingAct' title='NEXT' id='NextPage'>NEXT</a>&nbsp;" + 
                               "<img onclick='PopVodsPageing("+ThePopVodsPage+",1)' class='PagingAct' title='NEXT' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='PopVodsPageing("+ThePopVodsPage+",1)' class='PagingAct' title='NEXT' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
            
            //Check If Is the Last Page
            var MaxPages =(parseInt(TotalPopVodsNum/PopNumInPage)-1);              
            if (ThePopVodsPage == MaxPages&&(TotalPopVodsNum%PopNumInPage==0)||(ThePopVodsPage > MaxPages))
            {                
                FirstPageStr = "<font class='PagingDis' id='MORE POPULAR VIDEOS'>NEXT</font>&nbsp;" +
                "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
            }
            
            if (ThePopVodsPage == 0)
            {
                LastPageStr = "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' alt='' width='4' height='5' border='0' align='absmiddle'>&nbsp;" +
                "<font class='PagingDis' id='PreviousPage'> PREVIOUS</font>";
            }
            document.getElementById("amountOfItemsPop").innerHTML = MinPopVods + "-" + MaxPopVods;
            document.getElementById("PreviousPopTd").innerHTML = LastPageStr;
            document.getElementById("NextPopTd").innerHTML = FirstPageStr;            
            //-----------------------           
		}
    }    
}

//This function is for the ajax of the pagenig of 'Popular Videos'
function batchEditVodsRsChange()
{    
	MinEditVods=0;
	MaxEditVods=0;
	if (ChannelobjXML && ChannelobjXML.readyState==4)
	{
        if (ChannelobjXML.responseXML)
		{                          
            var Str = ChannelobjXML.responseXML.getElementsByTagName("Str");
            var TotalEditVodsNum = ChannelobjXML.responseXML.getElementsByTagName("TotalEditVodsNum");
                TotalEditVodsNum = TotalEditVodsNum[0].firstChild.data;
            var EditVodsNum = ChannelobjXML.responseXML.getElementsByTagName("EditVodsNum");
                EditVodsNum = (parseInt(EditVodsNum[0].firstChild.data));
                MinEditVods = (parseInt(TheEditVodsPage*EditNumInPage)+1);
                MaxEditVods = (parseInt(MinEditVods + EditVodsNum)-1);
                if(MinEditVods==0)
                    MinEditVods = 1;            
            document.getElementById("EditVodsDiv").innerHTML = Str[0].firstChild.data;
			
            //Next And Previous Pages
            //-----------------------
            var LastPageStr = "<img onclick='EditVodsPageing("+TheEditVodsPage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='EditVodsPageing("+TheEditVodsPage+",0)' class='PagingAct' title='PREVIOUS' src='"+IMG_SERVER_URL+"icon_small_arrow_green2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>&nbsp;" +
                              "<a onclick='EditVodsPageing("+TheEditVodsPage+",0)' class='PagingAct' title='PREVIOUS' id='PreviousPage'>PREVIOUS</a>";   
            var FirstPageStr = "<a onclick='EditVodsPageing("+TheEditVodsPage+",1)' class='PagingAct' title='NEXT' id='NextPage'>NEXT</a>&nbsp;" + 
                               "<img onclick='EditVodsPageing("+TheEditVodsPage+",1)' class='PagingAct' title='NEXT' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img  onclick='EditVodsPageing("+TheEditVodsPage+",1)' class='PagingAct' title='NEXT' src='"+IMG_SERVER_URL+"icon_small_arrow_green.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
            
            //Check If Is the Last Page
            var MaxPages =(parseInt(TotalEditVodsNum/EditNumInPage)-1);              
            if (TheEditVodsPage == MaxPages&&(TotalEditVodsNum%EditNumInPage==0)||(TheEditVodsPage > MaxPages))
            {                
                FirstPageStr = "<font class='PagingDis' id='MORE VIDEOS'>NEXT</font>&nbsp;" +
                "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey2.gif' width='4' height='5' alt='' border='0' align='absmiddle'>";
            }
            
            if (TheEditVodsPage == 0)
            {
                LastPageStr = "<img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' width='4' height='5' alt='' border='0' align='absmiddle'><img src='"+IMG_SERVER_URL+"icon_small_arrow_grey.gif' alt='' width='4' height='5' border='0' align='absmiddle'>&nbsp;" +
                "<font class='PagingDis' id='PreviousPage'> PREVIOUS</font>";
            }
            document.getElementById("amountOfItemsEdit").innerHTML = MinEditVods + "-" + MaxEditVods;
            document.getElementById("PreviousEditVodsTd").innerHTML = LastPageStr;
            document.getElementById("NextEditVodsTd").innerHTML = FirstPageStr;            
            //-----------------------           
		}
    }    
}

//This function is for pageing in ajax for 'All Live'
function Pageing(Page,Directions)
{   
    if(Directions==0 && Page > 0)
    {
        ThePage = Page - 1;
    }
    else if(Directions==1)
    {
        ThePage = Page + 1;
    }        
	else
	{
		ThePage = Page;
	}
	
	str="Page="+ThePage+"&Amount="+ShowNumInPage+"&S="+ShowSortBy+"&D="+ShowDir+"&Ctype="+channelType+"&EditFlag="+EditFlag;
	callAjax(Showurl,str,"batchRsChange");             	             
}

//This function is for pageing in ajax for 'Popular Videos'
function PopVodsPageing(Page,Directions)
{   
    if(Directions==0 && Page > 0)
    {
        ThePopVodsPage = Page - 1;
    }
    else if(Directions!=0)
    {
        ThePopVodsPage = Page + 1;
    }        
	str="Page="+ThePopVodsPage+"&Amount="+PopNumInPage+"&S="+PopSortBy+"&D="+PopDir+"&Ctype="+channelType;
	callAjax(Popurl,str,"batchPopVodsRsChange");             	             
}

//This function is for pageing in ajax for 'Editor Picks'
function EditVodsPageing(Page,Directions)
{   
    if(Directions==0 && Page > 0)
    {
        TheEditVodsPage = Page - 1;
    }
    else if(Directions!=0)
    {
        TheEditVodsPage = Page + 1;
    }        
	str="Page="+TheEditVodsPage+"&Amount="+EditNumInPage+"&S="+EditSortBy+"&D="+EditDir+"&Ctype="+channelType;
	callAjax(EditVodsurl,str,"batchEditVodsRsChange");             	             
}

function callAjax(Turl,str,batchfunc)
{   
	ChannelobjXML = CreateObjXML();
    ChannelobjXML.open("POST", Turl ,true); 
    ChannelobjXML.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	if(batchfunc=="batchRsChange")     //for 'Live Now'
	{
		ChannelobjXML.onreadystatechange=batchRsChange;
	}	
	else if(batchfunc=="batchPopVodsRsChange")     //for 'Popular Videos'
	{
		ChannelobjXML.onreadystatechange=batchPopVodsRsChange;
	}
	else if(batchfunc=="batchEditVodsRsChange")     //for 'Editors picks'
	{
		ChannelobjXML.onreadystatechange=batchEditVodsRsChange;
	}
    ChannelobjXML.send(str);
}

function MyLiveSortBy(status)
{	
    if(status!="")
    {
        VodSortBy = status;
        Pageing(0,2);        
    }
}