var ajax = new AJAX();
ajax.setcharset("GBK");
function reportErr(id){openWin("/"+sitePath+"js/err.html?id="+id,400,220,350,250,0)}

function viewComment(url,type){
  var url;
  url+='&type='+(type=='news' ? 2 : 1);
  ajax.get(url,function(obj){
		  if (obj.responseText=="err"){
			  set(S("comment_list"),"<font color='red'>发生错误</font>")	
		  }else{
			  set(S("comment_list"),obj.responseText)	
		  }
	  }
  );		
}

function submitComment(id){
	if(S("m_author").value.length<1){alert('请填写昵称');return false;}
	if(S("m_content").value.length<1){alert('请填写内容');return false;}
	ajax.postf(
		S("f_comment"),
		function(obj)
		{
			if(obj.responseText=="ok")
			{
				viewComment(id,1);
				//alert('小弟我感谢您的评论!');
			}
			else if(obj.responseText=="havecomment")
			{
				alert('歇会儿再来评论吧！');
			}
			else
			{
				alert('发生错误');
			}
		}
	);
}

function markscore0(vd,d,t,s,l,ac){
	var alt=['很差','较差','还行','推荐','力荐'],url=ac=='news' ? ["/"+sitePath+"inc/ajax.asp?id="+vd+"&action=newsscore","/"+sitePath+"inc/ajax.asp?id="+vd+"&action=scorenews&score="] : ["/"+sitePath+"inc/ajax.asp?id="+vd+"&action=videoscore","/"+sitePath+"inc/ajax.asp?id="+vd+"&action=score&score="],
	x=d+t,y=(Math.round(s / x * 100) / 100) || 0,id='BT'+(new Date()).getTime();
	document.write('<div style="padding:5px 10px;border:1px solid #CCC">\
			<div style="color:#000"><strong>我来评分(请您参与评分，体现您的观点)</strong></div>\
			<div>共 <strong style="font-size:14px;color:red" id="MARK_B1"> '+x+' </strong> 个人评分， 平均分 <strong style="font-size:14px;color:red" id="MARK_B2"> '+y+' </strong>， 总得分 <strong style="font-size:14px;color:red" id="MARK_B3"> '+s+' </strong></div>\
			<div>');
	for(var i=0;i<=l;i++)
	{
		/*document.write('<input type="radio" name="score" id="sint'+i+'" value="1" title="'+alt[parseInt(i/l*(alt.length-1))]+'"/><label for="sint'+i+'">'+i+'</label>');*/
	}
	document.write('&nbsp;<input type="button" value=" 评 分 " id="'+id+'" style="width:55px;height:21px"/></div></div>');
	S(id).onclick=function (){
		for(var i=0;i<=l;i++) if(S('sint'+i).checked)break;
		ajax.get(url[1]+i,function (obj){
			if((''+obj.responseText).indexOf("havescore")!=-1){
				alert('你已经评过分啦');
			}else{
				s+=i;
				S('MARK_B1').innerHTML=++x;
				S('MARK_B2').innerHTML=(parseInt(s / x * 100) / 100) || 0;
				S('MARK_B3').innerHTML=s;
				alert('感谢你的参与!');
			}
		});
		this.disabled=true;
	}
	if(new Date().toGMTString()!=new Date(document.lastModified).toGMTString()) return ajax.get(url[0],function (obj){
		var a=obj.responseText
		try{
			a.replace(/\[(\d+),(\d+),(\d+)\]/i,function ($0,d,t,s){
				var x=parseInt(d)+parseInt(t),y=(Math.round(parseInt(s) / x * 100) / 100) || 0;
				$('MARK_B1').innerHTML=x;
				$('MARK_B2').innerHTML=y;
				$('MARK_B3').innerHTML=s;
			});
		}catch(ig){}
	});
}

function markscore1(vd,d,t,s,l,ac){
	var alt=['很差','较差','还行','推荐','力荐'],src=['/'+sitePath+'pic/star0.gif','/'+sitePath+'pic/star1.gif'],url=ac=='news' ? ["/"+sitePath+"inc/ajax.asp?id="+vd+"&action=newsscore","/"+sitePath+"inc/ajax.asp?id="+vd+"&action=scorenews&score="] : ["/"+sitePath+"inc/ajax.asp?id="+vd+"&action=videoscore","/"+sitePath+"inc/ajax.asp?id="+vd+"&action=score&score="],
	x=d+t,y=(Math.round(s / x * 100) / 100) || 0,id='STAR'+(new Date()).getTime();
	document.write('<span id="'+id+'" style="padding:5px">');
	for(var i=1;i<=l;i++){
		document.write('<img id="'+i+'" src="'+src[i<=y ? 0 : 1]+'" title="'+alt[parseInt(i/l*(alt.length-1))]+'" style="cursor:pointer">');
	}
	document.write('&nbsp;<strong style="font-size:14px;color:red" id="MARK_B2"></strong>(<span style="color:blue" id="MARK_B3"></span>)</span>');
	var dc=$(id),im=dc.getElementsByTagName('img');
	for(var i=0;i<im.length;i++){
		im[i].onclick=function (){
			var x=parseInt(this.id);
			ajax.get(url[1]+x,function (obj){
				if((''+obj.responseText).indexOf("havescore")!=-1){
					alert('你已经评过分啦');
				}else{
					alert('感谢你的参与!');
					y=x;dc.onmouseout();
				}
			});
		}
		im[i].onmouseover=function (){
			var x=parseInt(this.id)
			for(var i=0;i<im.length;i++) im[i].src=src[x>=parseInt(im[i].id) ? 0 : 1];
		}
	}
	dc.onmouseout=function (){
		for(var i=0;i<im.length;i++) im[i].src=src[y>=parseInt(im[i].id) ? 0 : 1];
		$('MARK_B2').innerHTML=y;$('MARK_B3').innerHTML=y>0 ? alt[parseInt(y/l*(alt.length-1))] : '暂无' ;
	}
	if(new Date().toGMTString()!=new Date(document.lastModified).toGMTString()) return ajax.get(url[0],function (obj){
		var a=obj.responseText
		try{
			a.replace(/\[(\d+),(\d+),(\d+)\]/i,function ($0,d,t,s){
				var x=parseInt(d)+parseInt(t);y=(Math.round(parseInt(s) / x * 100) / 100) || 0;
				dc.onmouseout();
			});
		}catch(ig){}
	});
	dc.onmouseout();
}

function markVideo(vd,d,t,s,l,c){
	window['markscore'+(c==1 ? 1 : 0)](vd,d,t,s,parseInt(l)<0 ? 5 : l);
}

function diggVideo(id,div){
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?id="+id+"&action=digg",
		function (obj){
			var returnValue=Number(obj.responseText)
			if (!isNaN(returnValue))
			{
				set($(div),returnValue);
				//alert('(*^__^*) 嘻嘻……，顶得我真舒服！');
			}
			else if(obj.responseText=="err")
			{
				alert('顶失败')
			}
			else if(obj.responseText=="havescore")
			{
				alert('您已经顶过了！')
			}	
		}
	);	
}

function treadVideo(id,div){
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?id="+id+"&action=tread",
		function (obj){
			var returnValue=Number(obj.responseText)
			if(!isNaN(returnValue))
			{
				set($(div),returnValue);
				//alert('小样儿，居然敢踩我！');
			}
			else if(obj.responseText=="err")
			{
				alert('踩失败')
			}	
			else if(obj.responseText=="havescore")
			{
				alert('您已经踩过了!')
			}	
		}
	);	
}

function alertFrontWin(zindex,width,height,alpha,str){
	openWindow(zindex,width,height,alpha)
	set(S("msgbody"),str)
}

function getAspParas(suffix)//以"-"为分隔符,将文件名建立数组.(a)文件类型
{
	//a=".html"
	var cur_url=location.href;//="http://rendie/play/?2-0-0.html"
	var urlParas=location.search;//="?79-0-0.html"
	if (cur_url.indexOf("?")>0)//=true
	{	
	return urlParas.substring(1,urlParas.indexOf(suffix)).split('-')//="79,0,0"
	//substring 方法		返回位于 String 对象中指定位置的子字符串。
	}
	else
	{
		return cur_url.substring(cur_url.lastIndexOf("/")+1,cur_url.indexOf(suffix)).split('-')	
	}
}

function getHtmlParas(suffix){
	var urlParas=location.search;
		urlParas=urlParas.substring(1,urlParas.length-suffix.length).split('-')
	return urlParas
}

function handleParas(para1,para2)//播放哪播放器的哪一集？(a)播放器(b)哪一集
{
	//para1=0		para2=2
	var i,fromArray,len1,len2,urlArray,j,dataStr,dataArray
	if (isNaN(para1) || isNaN(para2)){return false}//=False
	fromArray=VideoListJson
	para1--;para2--
	len1=fromArray.length//=1
	if(para1>len1-1)//false
	{
		para1=len1-1
	}
	for (i=0;i<len1;i++)
	{
		if (para1==i)//true  选播放器
		{
			urlArray=fromArray[i][1]
			len2=urlArray.length;//=21
			if(para2>len2-1)//false
			{para2=len2-1};
			for (j=0;j<len2;j++)
			{
				if (para2==j){dataStr=urlArray[j];}
				if(para2+1==j)
				{
				urlinfo=urlinfo.replace("<from>",para1+1)
				urlinfo=urlinfo.replace("<pos>",j+1)
				dataStr=dataStr+"$"+urlArray[j]+"$"+urlinfo
				}
			}
		}
	}
	dataStr=dataStr+"$$$$"
	dataArray=dataStr.split('$');//="稻香"
	return dataArray
}
function regexpSplice(url,pattern,spanstr) {
   pattern.exec(url);
   return (RegExp.$1+spanstr+ RegExp.$2);
}

function getPageValue(pageGoName){
	var pageGoArray,i,len,pageValue
	pageGoArray=getElementsByName('input',pageGoName);len=pageGoArray.length
	for(i=0;i<len;i++){
		pageValue=pageGoArray[i].value;
		if(pageValue.length>0){return pageValue;}
	}
	return ""
}

function getPageGoUrl(maxPage,pageDiv,type,listpagename){
	var str,goUrl
	var url=location.href
	pageNum=getPageValue(pageDiv)
	if (pageNum.length==0||isNaN(pageNum)){alert('输入页码非法');return false;}
	if(pageNum>maxPage){pageNum=maxPage;}
	if(pageNum<1){pageNum=1;}
	switch (type){
		case 1 :
			//dynamic
			//http://127.0.0.1/xxxx/?1.html ; http://127.0.0.1/xxxx/?1-2.html
			str=(pageNum==1)?'':"-"+pageNum;
			goUrl=regexpSplice(url,/(http:\/\/\S+\?\d+)[-]{0,1}\d*(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			break;
		case 2 :
			//dir1
			//http://127.0.0.1/xxxx/xxxx.html ; http://127.0.0.1/xxxx/xxxx2.html
			if(url.lastIndexOf("/")==(url.length-1)){url+=listpagename}
			str=(pageNum==1)?'':pageNum;
			goUrl=regexpSplice(url,/(http:\/\/\S+?)[\d]*(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			break;
		case 3 :
			//dir2
			//http://127.0.0.1/xxxx/1.html ; http://127.0.0.1/xxxx/1_2.html
			str=(pageNum==1)?'':"_"+pageNum;
			goUrl=(url.split('_').length<2)?regexpSplice(url,/(http:\/\/\S+\d+?)(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str):regexpSplice(url,/(http:\/\/\S+\d+?)_\d+(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			if(goUrl.indexOf('http://')==-1){goUrl=regexpSplice(url,/(http:\/\/\S+_\d+?)(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);}
			break;
		case 4 :
			//news
			//http://127.0.0.1/xxxx/xxxx.html ; http://127.0.0.1/xxxx/xxxx_2.html
			//http://127.0.0.1/xxxx/?xxxx.html ; //http://127.0.0.1/xxxx/?xxxx_2.html
			if(url.lastIndexOf("/")==(url.length-1)){url+=listpagename}
			str=(pageNum==1)?'':'_'+pageNum;
			url = url.replace("_","")
			goUrl=regexpSplice(url,/(http:\/\/\S+?)[\d]*(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			break;
		case 5 :
			//zt
			//http://127.0.0.1/zt/?5.html ; http://127.0.0.1/zt/?5-2.html
			//http://127.0.0.1/zt/xxx.html ; http://127.0.0.1/zt/xxx-2.html
			str=(pageNum==1)?'':"-"+pageNum;
			goUrl=(url.split('-').length<2)?regexpSplice(url,/(http:\/\/\S+\d+?)(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str):regexpSplice(url,/(http:\/\/\S+\d+?)-\d+(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			if(goUrl.indexOf('http://')==-1){goUrl=regexpSplice(url,/(http:\/\/\S+\d+?)(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);}
			break;
		case 6 :
			//forged
			str=(pageNum==1)?'':"-"+pageNum;
			goUrl=regexpSplice(url,/(http:\/\/\S+?)[-]{0,1}[\d]{0,1}(\.html|\.htm|\.shtml|\.shtm|\.asp)/,str);
			break;
		
			}
	location.href=goUrl;
}

function goSearchPage(maxPage,pageDiv,searchtype,searchword){
	var pageNum=getPageValue(pageDiv)
	if (pageNum.length==0||isNaN(pageNum)){alert('输入页码非法');return false;}
	if(pageNum>maxPage){pageNum=maxPage;}
	if(pageNum<1){pageNum=1;}
	location.href='?page='+pageNum+'&searchword='+searchword+'&searchtype='+searchtype;
}

function leaveWord()
{
	if(S("m_author").value.length<1)
	{
		alert('昵称必须填写');
		return false;
	}
	if(S("m_content").value.length<1)
	{
		alert('内容必须填写');
		return false;
	}
	ajax.postf(
		S("f_leaveword"),
		function(obj)
		{
			if(obj.responseText=="ok")
			{
				viewLeaveWordList("/"+sitePath+"gbook.asp?list.html");
				alert('留言成功，多谢支持！');
				$("m_content").value='';
			}
			else if(obj.responseText=="haveleave")
			{
				alert('你手也太快了，歇会儿再来留言吧！');
			}
			else
			{
				alert('必须有一个中文！');
			}
		}
	);
}

function viewLeaveWordList(page)//转到("/"+sitePath+"gbook.asp?action=list&page="+page,)页面.
{//page=1
	view('leavewordlist');
	ajax.get(page,
		function(obj) {
			if (obj.responseText=="err"){
				set(S("leavewordlist"),"<font color='red'>发生错误</font>")	
			}else{
				set(S("leavewordlist"),obj.responseText)	
			}
		}
	);	
}

function loginLeaveWord(){
	if(S("m_username").value.length<1||S("m_pwd").value.length<1){alert('用户名密码不能为空');return false;}
	ajax.postf(
		S("f_loginleaveword"),
		function(obj){if(obj.responseText=="ok"){closeWin();alert('登陆成功');setLoginState();viewLeaveWordList("/"+sitePath+"gbook.asp?list.html");}else if(obj.responseText=="no"){alert('用户名或密码不正确');}else if(obj.responseText=="err"){alert('发生错误');}else{setLoginState();}}
	);
}

function setLoginState()//转到("/"+sitePath+"gbook.asp?action=state")页面.
{
	ajax.get(
		"/"+sitePath+"gbook.asp?state.html",
		function (obj){
			set(S('adminleaveword'),obj.responseText);
		}
	);			
}

function logOut(){
	ajax.get(
		"/"+sitePath+"gbook.asp?logout.html",
		function (obj){set(S('adminleaveword'),'成功退出');}
	);
	setLoginState();viewLeaveWordList("/"+sitePath+"gbook.asp?list.html");
}

function delLeaveWord(id,page,type){
	ajax.get(
		"/"+sitePath+"gbook.asp?del-"+id+"-"+type+".html",
		function (obj){
			if (obj.responseText=="ok"){
				viewLeaveWordList("/"+sitePath+"gbook.asp?list--"+page+".html")
				}else if(obj.responseText=="err"){alert('发生错误')}else{viewLeaveWordList("/"+sitePath+"gbook.asp?list.html");}
		}
	);
}
function replyLeaveWord(id,page){
	alertFrontWin(101,400,160,50,"")
	set(S("msgtitle"),"回复留言")
	set(S("msgbody"),"<form id='replyleaveword'  action='/"+sitePath+"gbook.asp?reply-"+id+".html' method='post'><div><textarea id='m_replycontent'  name='m_replycontent' rows=7 cols=50></textarea><br><input type='button' value='回  复' onclick='submitReply("+page+")' class='btn' /> &nbsp;<span style='background-color:#CCCCCC;cursor:pointer;' onclick=S('m_replycontent').value+='[URL][/URL]'><b>[URL]</b></span></div></form>")	
}

function viewLoginState(){
	alertFrontWin(101,300,100,50,"")
	set(S("msgtitle"),"登陆留言板")
	set(S("msgbody"),"<form id='f_loginleaveword'  action='/"+sitePath+"gbook.asp?login.html' method='post'  ><table style='color:#000'><tr><td>用户名：</td><td><input type='input'  name='m_username' id='m_username' size=10 value=''/></td></tr><tr><td><input type='hidden' value='ok' name='m_login' />密码：</td><td><input type='password' id='m_pwd' name='m_pwd' size=10 value=''/></td></tr><tr><td><input type='submit' value='登  陆' class='btn'  onclick='loginLeaveWord();return false;'  /></td></tr></table></form>")
}
function submitReply(page){
	if(S("m_replycontent").value.length<1){alert('回复不能为空');return false;}
	ajax.postf(
		S("replyleaveword"),
		function(obj){if(obj.responseText=="ok"){closeWin();viewLeaveWordList("/"+sitePath+"gbook.asp?list.html")}else if(obj.responseText=="err"){alert('发生错误4');}else{viewLeaveWordList("/"+sitePath+"gbook.asp?list.html");}}
	);
}
function getVideoHit(vid)
{
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?action=hit&id="+vid,
		function (obj){
			var result=obj.responseText
			if(result=="err"){set(S('hit'),'发生错误')}else{set(S('hit'),result);}
		}
	);				
}
function getNewsHit(nid)//"影视资讯"点击数
{
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?action=hitnews&id="+nid,
		function (obj){
			var result=obj.responseText
			if(result=="err"){set(S('hit'),'发生错误')}else{set(S('hit'),result);}
		}
	);		
}
function getProductHit(nid)//"影视资讯"点击数
{
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?action=hitproduct&id="+nid,
		function (obj){
			var result=obj.responseText
			if(result=="err"){set(S('hit'),'发生错误')}else{set(S('hit'),result);}
		}
	);		
}

function addFavorite(sURL, sTitle){
	try{ window.external.addFavorite(sURL, sTitle);}
		catch (e){
			try{window.sidebar.addPanel(sTitle, sURL, "");}
			catch (e)
				{alert("加入收藏失败，请使用Ctrl+D进行添加");}
		}
}

function setHome(obj,vrl,url){
    try{obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	this.style.behavior='url(#default#homepage)';this.setHomePage(url);}
        catch(e){
            if(window.netscape){
                try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}  
                   catch (e){alert("此操作被浏览器拒绝！请手动设置");}
                   var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                   prefs.setCharPref('browser.startup.homepage',vrl);
             }
      }
}

function addFace(id) {
	$('m_content').value += '[ps:' + id +']';
}

function openWin(url,w,h,left,top,resize){
	window.open(url,'New_Win','toolbars=0, scrollbars=0, location=0, statusbars=0,menubars=0, resizable='+(resize)+',width='+w+',height='+h+',left='+left+',top='+top);
}

function loadSlide(w,h)//幻灯片右侧列表
{
	var type=1   //type=0不显示幻灯片右侧列表；type=1显示幻灯片右侧列表
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+w+'" height="'+h+'"><param name="movie" value="/'+sitePath+'pic/slide/slide.swf" /><param name="quality" value="high"><param   name="wmode"   value="transparent"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="true"><param name="flashvars" value="type='+type+'&domain=/'+sitePath+'pic/slide/"><embed src="/'+sitePath+'pic/slide/slide.swf" flashvars="type='+type+'&domain=/'+sitePath+'pic/slide/" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" allowfullscreen="true" width="'+w+'" height="'+h+'"></embed></object>');
}




function autoCheckWrong(id,from,vid,errinfo)//将字符串传给ajax.asp
{//id=27435139		from="youku"	vid=79	errinfo="第1组来源中的数据:第1集$27435139$youku"
	ajax.get("/"+sitePath+"inc/ajax.asp?action=autocheck&from="+from+"&id="+id.replace(/&/g,'%26')+'&vid='+vid+'&err='+errinfo,
		function (obj){}	);	
	//		/move/inc/ajax.asp?action=autocheck&from=youku&id=27435139&vid=79&err="第1组来源中的数据:第1集$27435139$youku"
}

function autoSubmitErr(urlAndFrom,para2)//提取(a)中的字符串传给autoCheckWrong函数
{//urlAndFrom="第1集$27435139$youku"
//para2=0
	if (urlAndFrom[2]=='youku' || urlAndFrom[2]=='iask' || urlAndFrom[2]=='tudou')
	{
		autoCheckWrong(urlAndFrom[1],urlAndFrom[2],play_vid,'第'+(parseInt(para2)+1)+'组来源中的数据:'+urlAndFrom[0]+'$'+urlAndFrom[1].replace(/&/g,'%26')+'$'+urlAndFrom[2]);
	}
	//autoCheckWrong(27435139,"youku",79,"第1组来源中的数据:第1集$27435139$youku")
}

function addRemoteFavor(FPublicID){
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?action=favorAjax&favorVal="+FPublicID+"&faction=add",
		function (obj){alert(obj.responseText)}
	);
}
