// JavaScript Document
var xmlHttp;
var rating = 0;
var total_rating =0;
var count_rating =0;
var yellow_star = '';
var white_srar = '';
function createXMLHttpRequest()
{
	
	 if(window.ActiveXObject)
	 {
	  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  
	 }
	 else if(window.XMLHttpRequest)
	 {
	  xmlHttp = new XMLHttpRequest();
	 }
}
function check_login()
{
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	var bad = 0;
	var user_value = document.user_login.elements[0].value;//get user name
	var pass_value = document.user_login.elements[1].value;//get password
	if(user_value =='')
	{
		username.innerHTML = "Username Incorrect";
		username.style.color = 'red';
		bad =1;
		return false;
	}
	if(pass_value =='')
	{
		password.innerHTML = "Password Incorrect";
		password.style.color = 'red';
		bad = 1;
		return false;
	}
}
function confirmReset()
{
	
	if(window.confirm('Click Enter To Reset All'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function check_search_request()//check search char length
{
	var search_request = document.search_result.elements[0].value;
	if(search_request.length < 4)
	{
		var ss = document.getElementById('search_tips')
		ss.style.color = 'red';
		ss.style.display = 'block';
		ss.innerHTML = 'Keyword No Less Than 4 Characters !';
		return false;
	}
}

function checkRegisterField()
{
	for(var i=0;i<5;i++)
	{
		if(document.register.elements[i].value==0)
		{
			alert('Please Fill In All Filed');
			return false;
		}
	}
}
var checkFiled = '';
function checkFormFiled(filed)//check username and email format
{
	createXMLHttpRequest();
	var filedValue = '';
	filedValue = document.register.elements[filed].value;
	if(filedValue=='')//if input is null return flase
	{
		return false;
	}
	if(filed=='newusername')
	{
		checkFiled = 'newusername';
		var flag = checkUserNameFormat(filedValue);
		if(!flag)//username format invalid
		{
			document.getElementById(checkFiled).style.display = 'block';
			document.getElementById(checkFiled).style.color = 'red';
			document.getElementById(checkFiled).innerHTML = 'Username Format Invalid Or Less Than 5 Characters';
			document.register.elements[checkFiled].value = '';
			//document.register.elements[checkFiled].style.background = 'yellow';
			setTimeout(function (){document.register.elements[checkFiled].focus();},500);
			return false;
		}
	}
	else if(filed=='email')
	{
		checkFiled = 'email';
		var flag = checkEmailFormat(filedValue);
		if(!flag)//email format invalid
		{
			document.getElementById(checkFiled).style.display = 'block';
			document.getElementById(checkFiled).style.color = 'red';
			document.getElementById(checkFiled).innerHTML = 'Email Format Invalid';
			document.register.elements[checkFiled].value = '';
			//document.register.elements[checkFiled].style.background = 'yellow';
			setTimeout(function (){document.register.elements[checkFiled].focus();},500);//set focus
			return false;
		}
	}
	var url = "/checkregister.php?filed="+filed+"&value="+filedValue;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = handleRegisterStateChange;
	xmlHttp.send(null);
}

function  handleRegisterStateChange()
{	
	  if(xmlHttp.readyState == 4)
	  {
		 if(xmlHttp.status == 200)
		   {
			 	var response = '';
	 	  		response = xmlHttp.responseText;
				var showTips = document.getElementById(checkFiled);
				showTips.style.display = 'block';
				if(response=='good')
				{
					showTips.style.color = '#88D9F3';
					if(checkFiled=='newusername')
					{
						showTips.innerHTML = 'This User Valid';
					}
					else
					{
						showTips.innerHTML = 'This E-mail Valid';
					}
				}
				else
				{
					showTips.style.color = 'red';
					if(checkFiled=='newusername')
					{
						showTips.innerHTML = 'This User Already Exist';
						document.register.elements[checkFiled].value = '';
						document.register.elements[checkFiled].focus();
					}
					else
					{
						showTips.innerHTML = 'This E-mail Already Exist';
						document.register.elements[checkFiled].value = '';
						document.register.elements[checkFiled].focus();
					}	
				}
		   }
		   
	  }
	 
}

function checkUserNameFormat(str)
{
	var objReg = new RegExp("^[a-zA-Z0-9_]+$","gi");
	var rightFormat = objReg.test(str);
	/* ��֤�û������Ƿ��зǷ��ַ������?1��ʾ������ */
	var errorChar = new RegExp("[^a-zA-Z0-9_]","gi");
	var rightChar = (str.search(errorChar)==-1);
	var namelength = (str.length>4);
	return (rightFormat && rightChar && namelength);
}

function checkEmailFormat(strMail)
{
	/* ��֤�ʼ���ַ�ĸ�ʽ�Ƿ�Ϸ�����? abc@def.com/net�� */
	var objReg = new RegExp("[a-z0-9_]+@[a-z0-9]*[\.]?[a-z0-9]+[\.]{1}(com|net|bta|cn|org|edu|mil|us|uk|tw|jp|hk|eu|cc|info|asia)","gi");
	var IsRightFmt = objReg.test(strMail);
	
	/* ��֤�ʼ���ַ���Ƿ��зǷ��ַ������?1��ʾ������ */
	var objRegErrChar = new RegExp("[^a-z0-9-._@]","ig");
	var IsRightChar = (strMail.search(objRegErrChar)==-1);
	
	/* �ʼ���ַ��󳤶��?0�ַ� */
	var IsRightLength = strMail.length <= 60;
	
	/* �ж��ַ�'@'��'.'��λ�ã�����Ϊ��һ��������һ�� */
	var IsRightPos = (strMail.indexOf("@",0) != 0 && strMail.indexOf(".",0) != 0 && strMail.lastIndexOf("@")+1 != strMail.length && strMail.lastIndexOf(".")+1 != strMail.length);
	
	/* �ж��ַ�'@'�Ƿ�Ψһ */
	var IsNoDupChar = (strMail.indexOf("@",0) == strMail.lastIndexOf("@"));
	
	/* ��'��ʽ'��'�ַ�'��'����'��'@Ψһ'�������롱������һ��������㶼�����ؼ�?*/
	return (IsRightFmt && IsRightChar && IsRightLength && IsRightPos && IsNoDupChar) ;
}

function checkPassword()
{
	var pass = document.register.elements['newpassword'].value;
	var confirmpass = document.register.elements['confirmPassword'].value;
	if(pass.length<6)//check passowrd length
	{
		document.getElementById('newpassword').innerHTML = 'Password Length No Less Than Six Characters';
		document.getElementById('confirmPassword').style.display = 'block';
		document.getElementById('newpassword').style.color = 'red';
		document.register.elements['newpassword'].focus();
		return false;
	}
	else if(pass != confirmpass)//confirm password
	{
		document.getElementById('confirmPassword').innerHTML = 'Password Confirm Error,Please Check Again';
		document.getElementById('confirmPassword').style.color = 'red';
		document.getElementById('confirmPassword').style.display = 'block';
		document.register.elements['confirmPassword'].value = '';
		document.register.elements['newpassword'].focus();
		//setTimeout(function (){document.register.elements['newpassword'].focus();},500);
		return false;
	}
	else
	{
		document.getElementById('confirmPassword').innerHTML = '';
		document.getElementById('newpassword').innerHTML = '';
		document.getElementById('confirmPassword').style.display = 'none';
		document.getElementById('confirmPassword').style.display = 'none';
		return true;
	}
}

function checkEmail()
{
	var email = document.register.elements['email'].value;
	var confirmemail = document.register.elements['confirmemail'].value;
	if(email != confirmemail)
	{
		document.getElementById('confirmemail').innerHTML = 'E-mail Confirm Error,Please Check Again';
		document.getElementById('confirmemail').style.color = 'red';
		document.getElementById('confirmemail').style.display = 'block';
		document.register.elements['confirmemail'].value = '';
		document.register.elements['email'].focus();
		return false;
	}
	else
	{
		document.getElementById('confirmemail').innerHTML = '';
		document.getElementById('confirmemail').style.display = 'none';
		return true;
	}
}

var work = 0;
var bad = 0;
var divName = '';
var percent = 0;
function appraise(videoid,flag,divKey,workcount,deadcount)
{
	createXMLHttpRequest();
	divName =divKey;//need to show appraise div name
	work = workcount;
	bad = deadcount;
	switch(flag)
	{
		case 'work':
			work = work+1;
			percent = (work/(bad+work))*100;
			percent = String(percent).substr(0,2);
		break;
		case 'bad':
			bad = bad+1;
			percent = (work/(bad+work))*100;
			percent = String(percent).substr(0,2);
		break;
	}
	
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("="+videoid);//find the moviename in cookies
	if(cookieflag ==-1)//if cookie not exist allow to rating
	{
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =videoid+"="+videoid+";expires="+availdate.toGMTString()+";path=/";
		var url = "/report.php?videoid="+videoid+'&flag='+flag+'&percent='+percent;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = reportHandle;
		xmlHttp.send(null);
	}
}

function reportHandle()
{
	if(xmlHttp.readyState == 4)
 	{
		 if(xmlHttp.status == 200 || xmlHttp.status ==0)
		 {
			 if(Number(percent)<50)
			 {
				 percent = 100-percent;
				 var boxId = document.getElementById(divName);
				 boxId.innerHTML= percent+'% said bad';
				  boxId.style.color = 'red';
			 }
			 else
			 {
				 var boxId = document.getElementById(divName);
				 boxId.innerHTML= percent+'% said good';
				 boxId.style.color = '#3399FF';
			 }
			 percent=0;
			 work = 0;
			 bad = 0;
			 divName = '';
		 }
 	}
}

function showAppraise(count,idName)
{
	if(count<50)
	{
		count = 100-count;
		 var boxId = document.getElementById(idName);
		 boxId.innerHTML= count+'% said bad';
		 boxId.style.color = 'red';
	}
	else
	{
		 var boxId = document.getElementById(idName);
		 boxId.innerHTML= count+'% said good';
		 boxId.style.color = '#3399FF';
	}
}

//count = now rating, videoid = video name, total = total rating, rating_count = total votes,yellow_star=yellow star url
//user and title rating with user playlist
function submitrating(count,videoid,total,rating_count,star_yellow,star_white,user,title)
{	
	createXMLHttpRequest();
	rating = count;
	total_rating = total+count;
	count_rating = rating_count+1;
	yellow_star = star_yellow;
	white_star = star_white;
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("="+videoid);//find the moviename in cookies
	if(cookieflag ==-1)//if cookie not exist allow to rating
	{
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =videoid+"="+videoid+";expires="+availdate.toGMTString()+";path=/";
		//var url = '/rate/'+total_rating+'/'+count_rating+'/'+videoid+'/';
		if(user != '' && title !='')
		{
			var url='/rate.php?rate='+total_rating+'&vote='+count_rating+'&videoid='+videoid+'&user='+user+'&title='+title;
		}
		else
		{
			var url='/rate.php?rate='+total_rating+'&vote='+count_rating+'&videoid='+videoid;
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}
var img_src = new Array();//save the default image url to array for restore
function  handleStateChange()
{
	  if(xmlHttp.readyState == 4)
	  {
		  if(xmlHttp.status == 200 || xmlHttp.status ==0)
		   {
			   	var imageaver = total_rating/count_rating;
				var aver = imageaver*2;
				if(aver != parseInt(aver))
				{
					aver = aver.toString();
					aver = aver.substr(0,3);
				}
				var imageaver = parseInt(imageaver);
				var rating_obj = document.getElementById('currnet_rate');
				rating_obj.innerHTML = 'current rating: '+aver+'/10 ('+count_rating+' votes)';
			    document.getElementById('rate_pec').innerHTML = (aver*10)+'%';
				var hover_image = document.getElementById("hover_image");
			    var child = hover_image.getElementsByTagName("img");
			    var star_pec = document.getElementById("star_pec");
			    var small_star = star_pec.getElementsByTagName("img");
			    for(var i=0;i<5;i++)
			    {
					if(i<imageaver) star = yellow_star;
					else star = white_star;
					child[i].src = star;
					small_star[i].src = star;
					img_src[i] = star;
 			    }
			   
		   }
	  }
}


function mouseOver(key,star_hover,star_leave)
{
	var hover_image = document.getElementById("hover_image");
	var child = hover_image.getElementsByTagName("img");
	for(var i=0;i<key;i++)
	{
		img_src[i] = child[i].src;
		child[i].src = star_hover;
	}
	for(var i=key;i<5;i++)
	{
		img_src[i] = child[i].src;
		child[i].src = star_leave;
	}
	
}

function mouseOut(key)
{
	var hover_image = document.getElementById("hover_image");
	var child = hover_image.getElementsByTagName("img");
	for(var i=0;i<5;i++)
	{
		child[i].src = img_src[i];
	}
}


function checkComment()
{
	if(document.formComment.elements['comment_title'].value =='')
	{
		alert('Comment Title is Null');
		return false;
	}
	var text = document.formComment.elements['comment_text'];
	if( text.value=='')
	{
		alert('Comment  is Null');
		return false;
	}
	else
	{
		alert('Your comment has been submitted. Comments are moderated, and will not appear until the author has approved them.');
		document.formComment.elements['comment_title'].value='';
		text.value='';
		return false;
		//return true;
	}
}

function postReportBad(divname,comment_id)
{
	createXMLHttpRequest();
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("com="+comment_id);//find the comment id in cookies
	if(cookieflag ==-1)//if cookie not exist allow to report
	{
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =comment_id+"com="+comment_id+";expires="+availdate.toGMTString()+";path=/";
		var report_bad = document.getElementById(divname);
		report_bad.innerHTML = 'Thank You';
		report_bad.style.color = '#FF6600';
		var url = "/report_comment.php?id="+comment_id;
		xmlHttp.open("GET",url,true);
		//xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function subPostReportBad(divname,comment_id,forum_cat)
{
	createXMLHttpRequest();
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("com="+comment_id);//find the comment id in cookies
	if(cookieflag ==-1)//if cookie not exist allow to report
	{
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =comment_id+"com="+comment_id+";expires="+availdate.toGMTString()+";path=/";
		var report_bad = document.getElementById(divname);
		report_bad.innerHTML = 'Thank You';
		report_bad.style.color = '#FF6600';
		var url = "/report_comment.php?id="+comment_id+'&cat='+forum_cat;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}

function checkForm(contact)
{
	alert(document.form[contact].name);
	return false;
	if(document.form[contact].name == '' || document.form[contact].message == '')
	{
		return false;
	}
	
}

function checkComment_admin(nameKey,flag,id,user,comment,comment_status,com_cat)
{
	createXMLHttpRequest();
	switch(flag)
	{
		case 'd':
			document.getElementById(nameKey).style.color='red';
		break;
		case 'u':
			document.getElementById(nameKey).style.color='#0099FF';
		break;
		case 'b':
			document.getElementById(nameKey).style.color='red';
		break;
	}
	var url = '/approve_comment.php?flag='+flag+'&id='+id+'&user='+user+'&t='+comment+'&st='+comment_status+'&ct='+com_cat;
	xmlHttp.open("GET",url,true);
	//xmlHttp.onreadystatechange = commentStateChange;
	xmlHttp.send(null);
}

function reportWork(id,appraise)
{
	createXMLHttpRequest();
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("flag="+id);//find the comment id in cookies
	if(cookieflag ==-1)//if cookie not exist allow to report
	{
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =id+"flag="+id+";expires="+availdate.toGMTString()+";path=/";
		var flag = document.getElementById('flag'+id);
		flag.innerHTML = 'Thank You !';
		var url = "/report.php?flagid="+id+'&app='+appraise;
		xmlHttp.open("GET",url,true);
		//xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.send(null);
	}
}
var season_number='';
var epidetail = '';
var epititle = '';
var sea_name = '';
var video = '';
var ikey='';
function showSeason(sn,divName,videoName,title,ik)
{//season number,episode title,videoname,episode link,
		if(document.getElementById(divName).style.display=='block')
		{
			document.getElementById(divName).style.display='none';
		}
		else
		{
			createXMLHttpRequest();
			document.getElementById('season_loading'+ik).style.display='block';
			season_number = sn;//season number
			sea_name = divName;//episode title
			epititle = title;//episode title(episode 1,2,3)
			video = videoName;//video name
			arr = '';
			ikey = ik;//i key value
			var url='/combine_epi_tv.php?name='+videoName+'&sn='+sn+'&sflag=sea';
			xmlHttp.open("GET",url,true);
			xmlHttp.onreadystatechange = handleEipsode;
			xmlHttp.send(null);
		}
}

function handleEipsode()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200 || xmlHttp.status ==0)
	    {
			var arr = new Array();
			arr = xmlHttp.responseText.split('@');
			var detail = '';
			var tempsn = '';
			tempsn = season_number+'';
			var arrlenght = arr.length;
			for(i=0;i<arrlenght;i++)
			{
				arr[i] = arr[i]+'';
				detail += '<div class="episode_n"><a href="#episode'+(arr.length+1-i)+'" style="text-decoration:none;font-size:13px;"';
				detail += ' onclick="getLink('+arr[i]+')" >Episode '+arr[i]+'</a><img id="episode_loading'+(i+1)+'" src="/images/working.gif" style="margin:-20px 0 0 95px;display:none;" />';
				detail += '<div id="episode_detail'+tempsn+arr[i]+'"></div></div>';
			}
			document.getElementById(epititle).innerHTML = detail;
			document.getElementById(sea_name).style.display='block';
			document.getElementById(epititle).style.display='block';
			document.getElementById('season_loading'+ikey).style.display='none';
			
	    }
	}
}
var episode_number = 0;
function getLink(ep)//episode number
{
	episode_number = ep;
	ep = ep+'';
	var tempsn = '';
	tempsn = season_number+'';
	if(document.getElementById('episode_detail'+tempsn+ep).style.display=='block')
	{
		document.getElementById('episode_detail'+tempsn+ep).style.display='none';
	}
	else
	{
		createXMLHttpRequest();
		var url='/combine_epi_tv.php?name='+video+'&sn='+season_number+'&ep='+ep+'&sflag=sea';
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleGetLink;
		xmlHttp.send(null);
	}
}

function handleGetLink()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200 || xmlHttp.status ==0)
	    {
			var arr = new Array();
			arr = xmlHttp.responseText.split('@');
			var cou = arr.length;
			var linkDetail = '';
			linkDetail += '<ul>'; 
			for(i=0;i<cou;i++)
			{
				var links = arr[i].split(',');//0=id 1=manualepisodename 2=host 3=score 4=embed_status
				var animeid=links[0];
				
				/*var randnuma=get_scope_rand(60,80);
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;float:left;cursor:pointer;" onclick="window.open(\'http://www.flixstra.com/?main=login\');" target="_blank">Complete Series DVD [FLIXSTRA]</a>';
				linkDetail += '<a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></div><p id="appraise'+animeid+'">';
				linkDetail += '<span id="appraise_flaga'+animeid+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnuma+'</span>';
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+animeid+',\'good\','+randnuma+',\'appraise_flaga\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+animeid+',\'bad\','+randnuma+',\'\appraise_flaga\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';*/
				
				var randnumb=get_scope_rand(60,80);
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;float:left;cursor:pointer;" onclick="window.open(\'/watch-hd.php?animeid='+animeid+'\');" target="_blank">Watch Full Episode[HD]</a>';
				linkDetail += '<a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></div><p id="appraise'+animeid+'">';
				linkDetail += '<span id="appraise_flagb'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumb+'</span>';
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumb+',\'appraise_flagb\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumb+',\'appraise_flagb\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';		

				var randnumc=get_scope_rand(60,80);
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;float:left;cursor:pointer;" onclick="window.open(\'/xvid-movie.php?animeid='+animeid+'\');" target="_blank">Watch Full Episode[XVID]</a>';
				linkDetail += '<a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></div><p id="appraise'+links[0]+'">';
				linkDetail += '<span id="appraise_flagc'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumc+'</span>';
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumc+',\'appraise_flagc\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumc+',\'appraise_flagc\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';		


				var randnumd=get_scope_rand(60,80);
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;float:left;cursor:pointer;" onclick="window.open(\'http://www.affbuzzads.com/affiliate/index?ref=54151\');" target="_blank">Watch Full Episode[FREE]</a>';
				linkDetail += '<a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></div><p id="appraise'+links[0]+'">';
				linkDetail += '<span id="appraise_flagd'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumd+'</span>';
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumd+',\'appraise_flagd\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumd+',\'appraise_flagd\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';	
				
			}
			
			linkDetail += '</ul>'; 
			var tempsn = '';
			tempsn = season_number.toString();
			document.getElementById('episode_detail'+tempsn+episode_number).innerHTML = linkDetail;
			document.getElementById('episode_detail'+tempsn+episode_number).style.display='block';
		}
	}
}
var loadgif='';
function showEpisode(epiNumber,divName,videoName,ik,seaFlag)
{//episode number,episode title,videoname,episode link,
		if(document.getElementById(divName).style.display=='block')
		{
			document.getElementById(divName).style.display='none';
		}
		else
		{
			createXMLHttpRequest();
			epititle = divName;//episode title(episode 1,2,3)
			video = videoName;//video name
			arr = '';
			switch(seaFlag)
			{
				case 'epi':
					loadgif='outepi_loading'+ik;
					var url='/combine_epi_tv.php?name='+videoName+'&ep='+epiNumber+'&sflag=epi';
				break;
				case 'ova':
					loadgif='outova_loading';
					var url='/combine_epi_tv.php?name='+videoName+'&sflag=ova';
				break;
				case 'un':
					loadgif='outunsort_loading';
					var url='/combine_epi_tv.php?name='+videoName+'&sflag=un';
				break;
			}
			document.getElementById(loadgif).style.display='block';
			xmlHttp.open("GET",url,true);
			xmlHttp.onreadystatechange = handleOutEipsode;
			xmlHttp.send(null);
		}
}
function handleOutEipsode()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200 || xmlHttp.status ==0)
	    {
			var arr = new Array();
			arr = xmlHttp.responseText.split('@');
			var cou = arr.length;
			var linkDetail = '';
			linkDetail += '<ul>'; 
			for(i=0;i<cou;i++)
			{
				var links = arr[i].split(',');//0=id 1=manualepisodename 2=host 3=score 4=embed_status
				/*var movie_link = unescape(links[5]);
				linkDetail += '<li><div style="width:400px;float:left;display:inline"><a  style="text-decoration:none;cursor:pointer;" onclick="window.open(\''+movie_link+'\');" target="_blank">'+links[1]+'  ['+links[2]+']</a>';
				linkDetail += '<span><a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></sapn></div><p id="appraise'+links[0]+'">';
				
				if(parseInt(links[3])>=0)
				{
					linkDetail += '<span id="appraise_flaga'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+links[3]+'</span>';
				}
				else
				{
					linkDetail += '<span id="appraise_flaga'+links[0]+'" style="color:red;margin-right:10px;">Score: '+links[3]+'</span>';
				}
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+links[3]+',\'appraise_flaga\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+links[3]+',\'appraise_flaga\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';*/
	//hd		
	            randnumb=get_scope_rand(60,80);
	            movie_link="/watch-hd.php?animeid="+links[0];
				linkDetail += '<li><div style="width:400px;float:left;display:inline; "><a  style="text-decoration:none;cursor:pointer;" onclick="window.open(\''+movie_link+'\');" target="_blank">Watch Full Movie [HD]</a>';
				linkDetail += '<span><a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></sapn></div><p id="appraise'+links[0]+'">';
				
				if(parseInt(randnumb)>=0)
				{
					linkDetail += '<span id="appraise_flagb'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumb+'</span>';
				}
				else
				{
					linkDetail += '<span id="appraise_flagb'+links[0]+'" style="color:red;margin-right:10px;">Score: '+randnumb+'</span>';
				}
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumb+',\'appraise_flagb\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumb+',\'appraise_flagb\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';	
//hd end


	//sv		
				randnumc=get_scope_rand(60,80);
	            movie_link="/xvid-movie.php?animeid="+links[0];
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;cursor:pointer;" onclick="window.open(\''+movie_link+'\');" target="_blank">Watch Full Movie [XVID]</a>';
				linkDetail += '<span><a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></sapn></div><p id="appraise'+links[0]+'">';
				
				if(parseInt(randnumc)>=0)
				{
					linkDetail += '<span id="appraise_flagc'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumc+'</span>';
				}
				else
				{
					linkDetail += '<span id="appraise_flagc'+links[0]+'" style="color:red;margin-right:10px;">Score: '+randnumc+'</span>';
				}
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumc+',\'appraise_flagc\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumc+',\'appraise_flagc\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';	
//xv end

	//GRABOID		
	             randnumd=get_scope_rand(60,80);
	             movie_link="http://www.affbuzzads.com/affiliate/index?ref=54151";
				linkDetail += '<li><div style="width:400px;float:left;display:inline;"><a  style="text-decoration:none;cursor:pointer;" onclick="window.open(\''+movie_link+'\');" target="_blank">Watch Full Movie [FREE]</a>';
				linkDetail += '<span><a style="margin-left:5px; text-decoration:none;font-size:11px;color:#576039;" href="/downloads.php?id='+video+'" target="_blank">Download this Episode</a></sapn></div><p id="appraise'+links[0]+'">';
				
				if(parseInt(randnumd)>=0)
				{
					linkDetail += '<span id="appraise_flagd'+links[0]+'" style="color:#3399FF;margin-right:10px;">Score: +'+randnumd+'</span>';
				}
				else
				{
					linkDetail += '<span id="appraise_flagd'+links[0]+'" style="color:red;margin-right:10px;">Score: '+randnumd+'</span>';
				}
				linkDetail += '<img src="/images/good.gif" onclick="appraise_tv('+links[0]+',\'good\','+randnumd+',\'appraise_flagd\')" style="cursor:pointer;" title="Good"/>';
				linkDetail += '<img src="/images/bad.gif"  onclick="appraise_tv('+links[0]+',\'bad\','+randnumd+',\'appraise_flagd\')" style="cursor:pointer;" title="Bad"/>';
				linkDetail += '<img src="/images/dead.gif" onclick="this.src=\'/images/rebad.gif\'" style="cursor:pointer;" title="Report Dead"/>';
				linkDetail += '</p></li>';
			}
			
			linkDetail += '</ul>'; 
			document.getElementById(epititle).innerHTML = linkDetail;
			document.getElementById(epititle).style.display='block';
			document.getElementById(loadgif).style.display='none';
		}
	}
}


var divName = '';
function appraise_tv(videoid,flag,old_score,pre_divName)
{
	createXMLHttpRequest();
	divName = pre_divName+videoid;
	var cookieflag = '';
	var cookies = document.cookie;//get the cookie contents
	cookieflag = cookies.indexOf("=app"+videoid) && cookies.indexOf("=app"+divName);//find the moviename in cookies
	//cookieflag =-1
	if(cookieflag ==-1)//if cookie not exist allow to rating
	{
		switch(flag)
		{
			case 'good':
				old_score = old_score+1;
				if(Number(old_score)>=0)
				 {
					 var boxId = document.getElementById(divName);
					 boxId.innerHTML= 'Score: +'+old_score;
					 boxId.style.color = '#3399FF';
				 }
			break;
			case 'bad':
				old_score = old_score-1;
				if(Number(old_score)<0)
				 {
					 var boxId = document.getElementById(divName);
					 boxId.innerHTML= 'Score: '+old_score;
					 boxId.style.color = 'red';
				 }else
				 {
					 var boxId = document.getElementById(divName);
					 boxId.innerHTML= 'Score: +'+old_score;
					 boxId.style.color = '#3399FF';
				 }
			break;
		}
		var availdate = new Date();
		availdate.setDate(availdate.getDate()+parseInt(1));//set the cookie availtime
		document.cookie =videoid+"=app"+videoid+"=app"+divName+";expires="+availdate.toGMTString()+";path=/";
		var url='/report_tv.php?id='+videoid+'&flag='+flag;
		xmlHttp.open("GET",url,true);
		//xmlHttp.onreadystatechange = reportHandleTv;
		xmlHttp.send(null);
	}
}

function get_scope_rand($min_num,max_num)
{
return parseInt(Math.random()*(max_num-$min_num+1)+$min_num); 	
}
