var ajax = new AJAX();ajax.setcharset("GBK");

function viewNewsList(){
	set($("newslist"),"新闻加载中...")
	var handleUrl = "inc/ajax.asp?action=newslist";
	ajax.get(
		handleUrl,
		viewNewsListCallBack
	);	
}

function viewNewsListCallBack(obj){
	var resultText=obj.responseText
	if (resultText=="err"){
		set($("newslist"),"<li><font color='red'>发生错误...</font></li>")	
	}else if(resultText=="no"){
		set($("newslist"),"<li>没有数据</li>")	
	}else{
		set($("newslist"),resultText)		
	}
}

function viewNewsContent(id){
	if($("searchtype"))$("searchtype").style.display="none";
	alertFrontWin(101,700,400,20,"新闻内容加载中...")
	var handleUrl = "inc/ajax.asp?action=newscontent&id="+id;
	ajax.get(
		handleUrl,
		function(obj) {
			var resultText=obj.responseText
			if (resultText=="err"){
				set($("msgbody"),"<li><font color='red'>发生错误...</font></li>")	
			}else{
				var result=resultText.split('__maxcms2__')
				set($("msgtitle"),result[0]);set($("msgbody"),result[1])		
			}
		}
	);	
}

var alertwinflag=false;
function reportErr(id){
	alertFrontWin(101,400,150,50,"")
	set($("msgtitle"),"影片报错")
	set($("msgbody"),"<form id='reporterr' action='/"+sitePath+"inc/ajax.asp?action=reporterr' method='post'><input type='hidden' name='errid' value='"+id+"' /><div><input type='text' id='m_errauthor' name='m_errauthor' value='匿名' size='10'><br><textarea id='m_errcontent'  name='m_errcontent' style='width:375px;height:88px' rows=5 cols=40></textarea><br><input type='button' value='影片报错' onclick='submitErr()' class='btn'></div></form>")	
	alterMsgLocation(30,175)
}

function alterMsgLocation(t,l){
	$('msg').style.top=(parseInt(GetXYWH(Obj('ccplay')).split(",")[0])+parseInt(playerh))+t+"px";
	$('msg').style.left=parseInt(GetXYWH(Obj('ccplay')).split(",")[1])+l+"px";	
	if(!alertwinflag){document.documentElement.scrollTop+=200};
	alertwinflag=true;
}

function submitErr(){
	if($("m_errauthor").value.length<1){$("m_author").value='匿名';}
	if($("m_errcontent").value.length<1){alert('请填写报错内容');return false;}
	ajax.postf(
		$("reporterr"),
		function(obj){if(obj.responseText=="ok"){closeWin();alert('报错成功,感谢您的支持哟!');}else{alert('发生错误');}}
	);
}

function viewComment(id,page){
	ajax.get(
		"/"+sitePath+"comment.asp?id="+id+"&page="+page,
		function(obj) {
			if (obj.responseText=="err"){
				set($("comment"),"<font color='red'>发生错误</font>")	
			}else{
				set($("comment"),obj.responseText)	
			}
		}
	);		
}

function submitComment(id){
	if($("m_author").value.length<1||$("m_content").value.length<1){alert('请填写完整');return false;}
	ajax.postf(
		$("f_comment"),
		function(obj){if(obj.responseText=="ok"){viewComment(id,1);alert('小弟我感谢您的评论!');}else if(obj.responseText=="havecomment"){alert('小样儿你手也太快了，歇会儿再来评论吧！');}else{alert('发生错误');}}
	);
}

function diggVideo(id,div){
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?id="+id+"&action=digg",
		function (obj){
			var returnValue=obj.responseText
			if (!isNaN(returnValue)){alert('(*^__^*) 嘻嘻……，顶得我真舒服！');set($(div),'[ <em>共'+returnValue+'次</em> ]');}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=obj.responseText
			if(!isNaN(returnValue)){alert('小样儿，居然敢踩我！');set($(div),'[ <em >共'+returnValue+'次</em> ]');}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($("msgbody"),str)
}

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


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

function handleParas(para1,para2){
	var i,fromArray,len1,len2,urlArray,j,dataStr,dataArray
	if (isNaN(para1) || isNaN(para2)){return false}
	fromArray=VideoInfoList.split('$$$')
	len1=fromArray.length;if(para2>len1-1){para2=len1-1}
	for (i=0;i<len1;i++){if (para2==i){urlArray=fromArray[i].split('$$')[1].split('#');len2=urlArray.length;if(para1>len2-1){para1=len2-1};for (j=0;j<len2;j++){if (para1==j){dataStr=urlArray[j];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){
	var str,goUrl
	var url=location.href
	pageNum=getPageValue(pageDiv)
	//alert(pageNum)
	if (pageNum.length==0||isNaN(pageNum)){alert('输入页码非法');return false;}
	if(pageNum>maxPage){pageNum=maxPage;}
	if(pageNum<1){pageNum=1;}
	switch (type){
		case 1 :
			str=(pageNum==1)?'':"-"+pageNum;
			goUrl=regexpSplice(url,/(http:\/\/\S+\?\d+)[-]{0,1}\d*(.html)/,str);
			break;
		case 2 :
			if(url.lastIndexOf("/")==(url.length-1)){url+="index.html"}
			str=(pageNum==1)?'':pageNum;
			goUrl=regexpSplice(url,/(http:\/\/\S+?)[\d]*(.html)/,str);
			break;
		case 3 :
			str=(pageNum==1)?'':"_"+pageNum;
			goUrl=(url.split('_').length<2)?regexpSplice(url,/(http:\/\/\S+\d+?)(.html)/,str):regexpSplice(url,/(http:\/\/\S+\d+?)_\d+(.html)/,str);
			if(goUrl.indexOf('http://')==-1){goUrl=regexpSplice(url,/(http:\/\/\S+_\d+?)(.html)/,str);}
			break;
	}
	top.location.href=goUrl;
}

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

function leaveWord(){
	if($("m_author").value.length<1||$("m_content").value.length<1){alert('昵称和内容必须填写');return false;}
	if($("m_qq").value.length>0){if(!checkInput($("m_qq").value,"num")){return false;}};
	if($("m_mail").value.length>0){if(!checkInput($("m_mail").value,"mail")){return false;}};
	ajax.postf(
		$("f_leaveword"),
		function(obj){if(obj.responseText=="ok"){viewLeaveWordList(1);}else if(obj.responseText=="haveleave"){alert('小样儿你手也太快了，歇会儿再来留言吧！');}else{alert('发生错误');}}
	);
}

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

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

function setLoginState(){
	ajax.get(
		"/"+sitePath+"gbook.asp?action=state",
		function (obj){
			set($('adminleaveword'),obj.responseText);
		}
	);			
}

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

function delLeaveWord(id,page,type){
	ajax.get(
		"/"+sitePath+"gbook.asp?action=del&id="+id+"&type="+type,
		function (obj){
			if (obj.responseText=="ok"){viewLeaveWordList(page)}else if(obj.responseText=="err"){alert('发生错误3')}else{viewLeaveWordList(page);}
		}
	);
}

function replyLeaveWord(id,page){
	alertFrontWin(101,400,160,50,"")
	set($("msgtitle"),"回复留言")
	set($("msgbody"),"<form id='replyleaveword'  action='/"+sitePath+"gbook.asp?action=reply&id="+id+"' 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=$('m_replycontent').value+='[URL][/URL]'><b>[URL]</b></span></div></form>")	
}

function viewLoginState(){
	alertFrontWin(101,300,100,50,"")
	set($("msgtitle"),"登陆留言板")
	set($("msgbody"),"<form id='f_loginleaveword'  action='/"+sitePath+"gbook.asp?action=login' method='post'  ><table><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($("m_replycontent").value.length<1){alert('回复不能为空');return false;}
	ajax.postf(
		$("replyleaveword"),
		function(obj){if(obj.responseText=="ok"){closeWin();viewLeaveWordList(page)}else if(obj.responseText=="err"){alert('发生错误4');}else{viewLeaveWordList(page);}}
	);
}

function getVideoHit(vid){
	ajax.get(
		"/"+sitePath+"inc/ajax.asp?action=hit&id="+vid,
		function (obj){
			var result=obj.responseText
			if(result=="err"){set($('hit'),'发生错误')}else{set($('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 += '[maxcms:' + id +']';
}

function openWin(url,w,h){
	var winObj=showModalDialog(url,'window','dialogWidth:'+(w+10)+'px;dialogHeight:'+(h+55)+'px;dialogtop:100px;dialogleft:200px;help:0;scroll:0;status:0;resizable:1;')
}