// JavaScript Documentfunction 
var htmlstr='';
function showfeatured()
{ 

var Html='';
var Featured=$('#FeaturedTabs').val();

$('#'+Featured).html(Html);
    $.get("featured.php",{remove_cache:new Date().getTime()},function (xml) {
              $("start", xml).each(function () {
                    var start = $(this);
                        name = $(this).find('name').text();
                        description =  $(this).find('description').text();
                        id = $(this).find('id').text(); 
                        thumb = $(this).find('thumb').text();
                        title = $(this).find('title').text();
						
						var NewName="'"+name+"'";
						var NewID="'"+id+"'";
						
					var Html='<table><tr><td width="10%"><a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" width="80px" height="60px" class="border-img cursor" /></a></td><td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="newvideo('+NewName+','+NewID+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="newvideo('+NewName+','+NewID+')">...watch</a></td></tr></table><hr />';
						
					 $('#'+Featured).append(Html);
					    
                  });
            });
 
 //$('#LastClktabUpper').val(Featured);
}


function showmostviewed()
{ 
var Html='';
var MostViewed=$('#MostViewedTabs').val();
$('#'+MostViewed).html(Html);
    $.get("mostviewed.php",{remove_cache:new Date().getTime()},function (xml) {
              $("viewed", xml).each(function () {
                    var viewed = $(this);
                        name = $(this).find('name').text();
                        description =  $(this).find('description').text();
                        id = $(this).find('id').text(); 
                        thumb = $(this).find('thumb').text();
						
                        title = $(this).find('title').text();
						
						var NewName="'"+name+"'";
						var NewID="'"+id+"'";

					var Html='<table><tr><td width="10%"><a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" width="80px" height="60px" class="border-img cursor" /></a></td><td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="newvideo('+NewName+','+NewID+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="newvideo('+NewName+','+NewID+')">...watch</a></td></tr></table><hr />';

                     $('#'+MostViewed).append(Html);
					    
                  });
            });
			
	
  //$('#LastClktabUpper').val(MostViewed);

}


var InnerHtml='';
var Tr='';
var page_n='';
var page_l='';
var totalrec='';
var recperpage='';
var Maintitle='';
var MidInnerHtml='';
var LastCLickedTabbed='';

function getvideos(title,id,pagenum)
{  
   
   var Html='';
   var Trstart='';
   var i=1;
   var reguser = "";
   
    var uid = $('#userid').val();
	if(uid!="" && uid!="undefined")
	{
	  reguser = 1;
	}
	else
	{
		reguser = 0;
		uid = 0;
	}
	
	
    
   var TabStart='<center><table cellpadding="3" cellspacing="3" border="0" width="98%" align="center">';
  
   InnerHtml='';
   Tr='';
   Maintitle='';
   page_n='';
   page_l='';
   total_rec='';
   recperpage='';
   MidInnerHtml='';

$.get("fetchcatvideos.php",{title:title,id:id,pagenum:pagenum,remove_cache:new Date().getTime()}, function (xml) {
	      Trstart = '<tr>';
		 if(!$(xml).find("getvideo").size())
		 {
			InnerHtml+='<td align="center" class="margT50 txt-maroon bold" colspan="4" valign="middle"><br /><br />Sorry No Records Available</td>';
		 }
		 
		 else
		 {
		
          $("getvideo", xml).each(function () {
			 
			  var getvideo = $(this);
			  id = $(this).find('id').text(); 
              name = $(this).find('name').text(); 
              date =  $(this).find('date').text();
              get_title = $(this).find('title').text();
              description = $(this).find('description').text();
			  thumb = $(this).find('thumb').text();
			  is_free = $(this).find('is_free').text();
			  price = $(this).find('price').text();
			  is_cat = $(this).find('is_category').text();
			  
				var NewName = "'"+name+"'";
				var NewID = "'"+id+"'";	
			    Maintitle = "'"+title+"'";
				page_n = $(xml).find('pagenum').text();
				page_l = $(xml).find('pagelast').text();
				
									
				
				
			   if(is_cat==1)
			  {  
			    InnerHtml+='<td valign="top" align="right" width="60px"><a onclick="getvideos('+Maintitle+','+NewID+')"><img src="'+thumb+'" title="'+get_title+'" width="50px" height="38px" style="cursor:pointer;" align="absbottom" class="border-img cursor"/></a></td><td align="left"><a class="bold txtcolor-maroon lbl-left" title="'+get_title+'" onclick="getvideos('+Maintitle+','+NewID+')">'+get_title+'</a></td>';
			 }
						
			 if(is_cat==0)
			{   
			 
		  InnerHtml+='<td valign="top" align="right" width="60px">';
		  
		  if(is_free == '1')
		  {
		  MidInnerHtml='<a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" title="'+get_title+'" width="50px" height="38px" style="cursor:pointer;" align="bottom" class="border-img cursor"/></a></td><td class="bold" align="left"><a class="bold txtcolor-maroon lbl-left" title="'+get_title+'" onclick="newvideo('+NewName+','+NewID+')">'+get_title+':'+date+'</a><br/><a class="small" onclick="newvideo('+NewName+','+NewID+')">Watch</a> | <a class="bold txtcolor-maroon" onclick="download('+NewName+', '+NewID+')">Download</a></td>';
		  }
		  if(is_free == '0')
		  {
			    MidInnerHtml='<a><img src="'+thumb+'" title="'+get_title+'" width="50px" height="38px" style="cursor:pointer;" align="bottom" class="border-img cursor"/></a></td><td class="bold" align="left"><a class="bold txtcolor-maroon lbl-left" title="'+get_title+'">'+get_title+':'+date+'</a><br/><a class="bold txtcolor-maroon" onclick="purchase('+NewName+','+NewID+','+reguser+','+price+','+uid+')">Purchase</a></td>';
		  }
		  
		  InnerHtml+=MidInnerHtml;
		  
		  
		    }
			
			
			
									
			i++;
			
			j=i;
			if(i==5)
			{ 
			  InnerHtml+='</tr><tr>';
			  i=1;
			}	
					
					
		});
	}
			
			var prev='';
			var next='';
			var prepage='';
			var nextpage='';
			
			
			 if(page_n)
			 {
			if(page_n >1)
            {
              prepage = page_n - 1;
            }
			if (page_n != page_l)
            {
               nextpage = page_n + 1;
            } 
           
		    
		    if((page_n > 1) && (page_n < page_l))
			{  
			   
			   prev+='<a  class="info_description" onclick="getvideos('+Maintitle+',0,'+prepage+');">Prev |</a>';
			   next+='<a  class="info_description" onclick="getvideos('+Maintitle+',0,'+nextpage+');">Next</a>';
			}
		   
		    if((page_n == page_l) && (page_n!=1))
		   {  
				 
				 prev+='<a  class="info_description" onclick="getvideos('+Maintitle+',0,'+prepage+');">Prev |</a>';
				   
		  }
			
	       if(page_n==1 && page_n < page_l)
		  {  
				      
			  
			  next+='<a class="info_description" onclick="getvideos('+Maintitle+',0,'+nextpage+');">Next |</a>';
		   }
					
	  }

			 var endTr='</tr><tr><td align="right" colspan="7">'+prev+''+next+'</td></tr></table></center>';
			 var Str= TabStart+Trstart+InnerHtml+Tr+endTr;
			 
			title = title.replace(" ","");
			
			
			$('#'+title).html(Str);
					
						
            });
	
    title = title.replace(" ","");	
	
	LastCLickedTabbed=title;
   
   $('#LastClktab').val(LastCLickedTabbed);
   
}


function download(name,id)
{
	  window.open("download.php?name='"+name+"'&id="+id);
	 
}

function closepopup()
{
  mywindow.close();
}



function NcNLive(Divname){

 $('#LastClktabUpper').val(Divname);

}

function purchase(name,id,ustat,price,userid)
{
	if(ustat == '1')
	{
		var url = name+"&id="+id+"&price="+price+"userid="+userid;
		window.location.href = "paypal.php?name="+url;
	}
	
	if(ustat == '0')
   {
    window.open ("signupfree_cat.php","Signup","width=910,height=260,resizeable=1,titlebar=0,toolbar=0,menubar=0,alwaysRaised=1");
		//alert("Signup to purchase this show");
   }
}


function showlive()
{
	/*var Html='';
    var Live=$('#LiveTabs').val();
$('#'+Live).html(Html);
    $.get("ncnlive.php",{remove_cache:new Date().getTime()},function (xml) {
              $("start", xml).each(function () {
                    var viewed = $(this);
                        name = $(this).find('name').text();
                        description =  $(this).find('description').text();
                        id = $(this).find('id').text(); 
                        thumb = $(this).find('thumb').text();
						
                        title = $(this).find('title').text();
						
						var NewName="'"+name+"'";
						var NewID="'"+id+"'";

					var Html='<table><tr><td width="10%"><a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" width="80px" height="60px" class="border-img cursor" /></a></td><td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="newvideo('+NewName+','+NewID+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="newvideo('+NewName+','+NewID+')">...watch</a></td></tr></table><hr />';

                     $('#'+Live).append(Html);
					    
                  });
            });*/
			
	
 // $('#LastClktabUpper').val(Live);
 
 
 
}


function get_exclusives(gettabname)
{
	var Html;
	var Exclusives = $('#ExclusivesTabs').val();
	var reguser = "";
   
    var uid = $('#userid').val();
	reguser = 1;
	Html='';
	
	var check_affiliation = $('#is_affiliated_member').val();
	/*if(check_affiliation > 0)
	{*/
	
	$('#'+Exclusives).html(Html);
    $.get("exclusives.php",{remove_cache:new Date().getTime()},function (xml) {
              $("exclusives", xml).each(function () {
                    var start = $(this);
                        name = $(this).find('name').text();
                        description =  $(this).find('description').text();
                        id = $(this).find('id').text(); 
                        thumb = $(this).find('thumb').text();
                        title = $(this).find('title').text();
						video_price = $(this).find('price').text();
						
						var NewName="'"+name+"'";
						var NewID="'"+id+"'";
						
					var Html='<table><tr><td width="10%"><a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" width="80px" height="60px" class="border-img cursor" /></a></td>';
					if(video_price==0)
					{
						Html+='<td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="newvideo('+NewName+','+NewID+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="newvideo('+NewName+','+NewID+')">...watch</a></td>';
					}
					else
					{
						Html+='<td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="purchase('+NewName+','+NewID+','+reguser+','+price+','+uid+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="purchase('+NewName+','+NewID+','+reguser+','+price+','+uid+')">...Purchase</a></td>';
						
					}
						Html+='</tr></table><hr />';
						
					 $('#'+Exclusives).append(Html);
					    
                  });
            });
 
 //$('#LastClktabUpper').val(Exclusives);
	
 /*}
 else
 {
 }*/
 
}


function show_exclusives(gettabname)
{
  var url = "checkexclusive.php";
  var sitename = $('#site_name').val();
  var chkvalid = $('#is_affiliated_member').val();
  /*if(chkvalid > 0)
  {*/
    get_exclusives(gettabname);
  /*}*/
  /*else
  { 
    window.open(url,sitename,"height=200,width=500");
  }*/
}



function get_partners(gettabname)
{
	var Html;
	var Partner = $('#PartnerTabs').val();
	var reguser = "";
   
   
	Html='';
	
	$('#'+Partner).html(Html);
    $.get("fetchpartnervideos.php",{remove_cache:new Date().getTime()},function (xml) {
              $("partners", xml).each(function () {
                    var start = $(this);
                        name = $(this).find('name').text();
                        description =  $(this).find('description').text();
                        id = $(this).find('id').text(); 
                        thumb = $(this).find('thumb').text();
                        title = $(this).find('title').text();
						video_price = $(this).find('price').text();
						
						var NewName="'"+name+"'";
						var NewID="'"+id+"'";
						
					var Html='<table><tr><td width="10%"><a onclick="newvideo('+NewName+','+NewID+')"><img src="'+thumb+'" width="80px" height="60px" class="border-img cursor" /></a></td><td class="margL10 info_title"><a onclick="newvideo('+NewName+','+NewID+')">'+title+'</a><br /><a class="info_description" onclick="newvideo('+NewName+','+NewID+')">'+description+'.</a></td></tr><tr><td></td><td class="right watch"><a onclick="newvideo('+NewName+','+NewID+')">...watch</a></td>';
					
						Html+='</tr></table><hr />';
						
					 $('#'+Partner).append(Html);
					    
                  });
            });
 
 //$('#LastClktabUpper').val(Partner);
	
}



function show_partner()
{
   var url = "partner_login.php";
   var sitename = $('#site_name').val();
   var chkpartner = $('#partner').val();
   
   if(chkpartner == 0)
   {
     window.open(url,sitename,"height=200,width=500");
   }
   else
   {
	    get_partners();
   }
}