// JavaScript Document
var SITEWATCHIMAGES="http://im.in.com/active18/watchnow/";

function showtab_data(page,disptypes){
location.href="/videos/toprated-24hours-"+page+".html";
}

function delwatchfromfavourite(urlid,flagtype,divid)
{	//alert(urlid+'-'+flagtype+'-'+divid);
	$.post('/videos/watchdelfavourite.php', { urlid: urlid,flgtype:flagtype },
		function(data)
		{
			$('#watchmyfavdiv_'+divid).html(data);
			var t = setTimeout("clearALL('watchmyfavdiv_"+divid+"')",3000);
		});
		return false;
}

function read_rating(sclusterid,modetype,flagtype)
{	
  
    if(readCookie("ui")){
	$.post('/videos/watchrate_db.php', { clusterid: sclusterid,mode:modetype,flgtype:flagtype },
			function(data){
				
				var data1 = data.split('|');
				
				if(data1[0]==1){
					
				var msg = '<div style="background:#eee; position:absolute; left:0; padding:5px; border: 1px #999 solid;   z-index:1; font:10px arial; color:#333;  "><nobr>Thank you for your vote!</nobr></div>';	
					if(data1[1]!=''){
					$('#rt'+sclusterid).html(data1[1]);	
					}
					$('#divtabtype'+sclusterid).html(msg);
					$('#divtabtype'+sclusterid).show();
					var t=setTimeout("clearALL('divtabtype"+sclusterid+"')",3000);
					
				}else if(data1[0]==2){
				var msg = '<div style="background:#eee; position:absolute; left:0; padding:5px; border: 1px #999 solid;   z-index:1; font:10px arial; color:#333;  "><nobr>You have already voted on this video!</nobr></div>';	
					$('#divtabtype'+sclusterid).html(msg);
					$('#divtabtype'+sclusterid).show();
					var t=setTimeout("clearALL('divtabtype"+sclusterid+"')",3000);
					
				}
				
			});
	}else{
	   var msg = '<div style="background:#eee; position:absolute; left:0; padding:5px; border:1px #999 solid; z-index:1; font:11px arial; color:#333;"><nobr><a href="#" onclick=addsignin("","",4); class="bl_11">Login </a> or <a href="http://mail.in.com/mails/new_reg.php" class="bl_11">register</a> now to vote!</nobr><div>';
	   $('#divtabtype'+sclusterid).html(msg);
	   $('#divtabtype'+sclusterid).show();
	   var t=setTimeout("clearALL('divtabtype"+sclusterid+"')",3000);
	}
	return false;
}

function selfClose(divid){
	//document.getElementById(divid).style.display='none';
	$('#'+divid).hide();
}
function  clearALL(divid){
	selfClose(divid);
}

function watch_rate_display(urlid)
	{
		$.post('/videos/watchrate__display_db.php', { clusterid: urlid},
		function(data){
			$('#rt'+urlid).html(data);
			
		});
	return false;
}

function watch_ratenew_display(urlid)
	{
		$.post('/videos/watchratenew_display_db.php', { clusterid: urlid},
		function(data){
			$('#rt'+urlid).html(data);
			
			
		});
	return false;
}
//Function to remove the space & new line characters Starts	 
function trim(str){	
     var s = str.replace(/^(\s)*/, '');
     s = s.replace(/(\s)*$/, '');
     return s;
}	
//Function to remove the space & new line characters Ends
function post_commentsvalidate(){

				var commentvalue=trim(document.postcomments.comments1.value);
				if(commentvalue=="") {alert("Please enter your comments")
					document.postcomments.comments1.focus(); 
					return false;
				}
				else{
								var rstoryid=document.postcomments.storyid.value;
								var rcomments=document.postcomments.comments1.value;
									var wtitle=document.postcomments.title.value;
							$.post('/videos/postcommentsdb.php', {storyid:rstoryid,flagtype:'watch',comments:rcomments,via:'ur',title:wtitle},
							function(data){
								//alert(data)
								var array_dada=data.split('|');
								//alert(array_dada[1])
								$('#divcomments').html(array_dada[0]);
								$('#divcomments1').html(array_dada[1]);
								});		
								return false;
				}
	} 
function logintoadd(redirectpath){
	if(!readCookie("ui")){
		addsignin('home',redirectpath,1);
	}
}



function echeck(str){
	var at="@"
	var dot="."
	var space=" ";
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	}

	return true
}


function addtoshare(urlid,flagtype){
	if(readCookie("ui")){
		show_shar_form('share')
	}else{
	 var msg = '<div style="background:#eee; position:absolute; left:200; padding:5px; border:1px #999 solid; z-index:1; font:11px arial; color:#333;"><nobr><a href="#" onclick=addsignin("","",2); class="bl_11">Login </a> or <a href="http://mail.in.com/mails/new_reg.php" class="bl_11">register</a> now to Share!</nobr><div>';
	   $('#divtabshare').html(msg);
	   $('#divtabshare').show();
	   var t=setTimeout("clearALL('divtabshare')",3000);
	}
	return false;
}

function addtofavourite(urlid,flagtype){
	if(readCookie("ui")){
	$.post('/videos/watchaddfavourite.php', { urlid: urlid,flgtype:flagtype },
	function(data){
		$('#divtabfavi').html(data);
		$('#divtabfavi').show();
		var t=setTimeout("clearALL('divtabfavi')",3000);
		});
	}else{
		var msg = '<div style="background:#eee; position:absolute; left:100; padding:5px; border: 1px #999 solid;   z-index:1; font:10px arial; color:#333;"><nobr><a href="#" onclick=addsignin("","",3); class="bl_11">Login </a> or <a href="http://mail.in.com/mails/new_reg.php" class="bl_11">register</a> now to add as Favourite!</nobr><div>';
		$('#divtabfavi').html(msg);
		$('#divtabfavi').show();
		var t=setTimeout("clearALL('divtabfavi')",3000);
	}
	return false;
}
function addwatchabugcnt(urlid)
	{	
		$.get('/videos/watchabugcnt.php', { urlid: urlid},
			function(data)
			{
				
				$('#divtabbug').html(data);
				var t=setTimeout("clearALL('divtabbug')",3000);
				});
		
			return false;
	}




function addwatchreportabuse(urlid)
	{	
		$.get('/videos/watchreportabusecnt.php', { urlid: urlid},
			function(data)
			{
				
				$('#divtabreport').html(data);
				var t=setTimeout("clearALL('divtabreport')",3000);
				});
		
			return false;
	}

function disable_share(){
	var t=setTimeout("clearALL('sharedoc')",3000)
}


function validate_share_data()
{
	var emailID=document.share_mail_form.share_emailid.value;
	var form_comment=document.share_mail_form.share_comment.value;
	var default_comment="Hey! check this awesome video out on ";
	var link_url='<a href="http://www.in.com/?utm_source=in.com&utm_medium=sharewithfriend" style="font:bold 12px/16px Arial; color:#0066CC; text-decoration:underline;" title="IN.com">IN.com</a>';
	var comment=default_comment+link_url;
	if((emailID==null)||(emailID==""))
	{
		alert("Please Enter your Email ID");
		document.share_mail_form.share_emailid.focus();
		return false;
	}
	if(form_comment=="" || form_comment=="Hey! check this awesome video out on IN.com")
		form_comment=comment;
	else
		form_comment = form_comment;
		
	var url = document.share_mail_form.url.value;
	var user_name = document.share_mail_form.user_name.value;
	var video_name= document.share_mail_form.video_name.value;
	var email_id=emailID.split(",");
	for(var i = 0; i < email_id.length; i++)
		{
			if(email_id[i].length>1)
			{
				if (!echeck(email_id[i],1,0))
				{
					document.share_mail_form.share_emailid.focus();
					return false;
				}
			}
		}
	

	var f_subject = 'Hey check this out!';
	//var f_body = '<?=$msg?>';
	var f_body ='<div style="font:12px/16px Arial; color:#333; text-decoration:none;">'+form_comment+'.<br><br>Click here to watch the video: <a href="'+url+'" style="font:bold 12px/16px Arial; color:#0066CC; text-decoration:underline;" title='+video_name+'>'+video_name+'</a><br><br><a href="http://www.in.com/?utm_source=in.com&utm_medium=sharewithfriend" style="font:bold 12px/16px Arial; color:#0066CC; text-decoration:underline;" title="IN.com">IN.com</a> is your gateway to the web.<br><br>Get the latest <a href="http://www.in.com/news/?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="News"><b>News</b></a>, <a href="http://www.in.com/listen/?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="the coolest Music"><b>the coolest Music</b></a>, <a href="http://www.in.com/videos/?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="Videos"><b>Videos</b></a> and <a href="http://www.in.com/games/?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="Games"><b>Games</b></a>, from more than 16,000 websites, and search for the best prices on <a href="http://www.in.com/active18/classifieds/travel/travelwego.php?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="Flights"><b>Flights</b></a>, <a href="http://www.in.com/active18/classifieds/hotel/hotelwego.php?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="Hotels"><b>Hotels</b></a> and <a href="http://www.in.com/active18/productsearch/search/?utm_source=in.com&utm_medium=sharewithfriend" class="bl_3_12" title="Products"><b>Products</b></a>. Enjoy the web\'s shortest mail address <span class="bl_3_12" style="text-decoration: none;"><a href="http://www.in.com/?utm_source=in.com&utm_medium=sharewithfriend" title="@in.com" ><b>@in.com</b></a></span><br><br><b>Are you IN? yet</b><br><br>See you IN there!<br>'+user_name+'</div>';
	//alert(f_body);
	//alert(video_name);
	
	for(var i = 0; i < email_id.length; i++)
		{
			if(email_id[i].length>1)
			{
				if (echeck(email_id[i],1,0)!=false)
				{	
					$.post("active18/mails/sendmail_invite.php", {"f_to": email_id[i], "f_subject": f_subject, "f_body": f_body}, function(data) {
						//alert(data);
					});
				}
			}
		}  
	
					$.unblockUI();
					show_shar_form1();
}


function page_redirect_rated(disptype)
{

	location.href="watchrated.php?disptype="+disptype;

}
function page_redirect_latest(disptype)
{

	location.href="watchlatest.php";

}
function clearInput(e){
if(e.value=='Search within Watch')e.value="";
}
<!-- Functions to enable/disable the text on Textboxes -->
function removetext(fieldname,fieldvalue){
	if(fieldname.value==fieldvalue){
		fieldname.value='';	
	}
}
function showtext(fieldname,fieldvalue){
	if(fieldname.value==''){
		fieldname.value=fieldvalue;	
	}
}
	function displayuserview(){		//alert("dd");
		
		$('#d_ht2_1').load("/videos/usersview.html", {}, function(data) {});	
	}
	function displaymyhistory(){			//alert(pg);
		
	   // pageTracker._trackPageview("/videos/trackmyhistory.html" );
		$('#d_ht2_2').load("/videos/myhistory.php", {}, function(data) {});	
	}

	function displaymyfavourites(){
		
		//pageTracker._trackPageview("/videos/trackmyfavourite.html" );
		$.post("/videos/myfavourite.php", {}, function(data) {	//alert(data);
				$('#d_ht2_3').html(data);
			});
	}
// functions copied from leftside
function displaypopularmusic(){
	
			$('#most_d1').load("/videos/LHSpopularalbum.html", {}, function(data) {});	
		}
	function displaypopularnews(){
		
		$('#most_d2').load("/videos/LHSpopularnews_v.php?urmurljs=videos", {}, function(data) {});	
		}
	function displaypopulargames(){
		
			$('#most_d3').load("/videos/LHSpopularplay.html", {}, function(data) {});	
		}	
		
//function to preload Ads before Video streaming Starts
function loadvideo(){
		var videostoryid=document.postcomments.storyid.value;	//alert(videostoryid);	
			$.post("/videos/getlivetvembedcode.php", {'id':videostoryid}, function(data) {	//alert(data);
				$('#videostream').html(data);
				document.getElementById('videoAD').style.display='none';
				document.getElementById('videostream').style.display='block';
			});	
	}
//function to preload Ads before Video streaming Ends