﻿function loadSlide(w, h) {
	var 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>')
}
var ajax = new AJAX();
ajax.setcharset("GBK");

function reportErr(id){
	var w=openWin("/"+sitePath+"js/err.html?id="+id,400,220,350,250,0),tid=0;
	var s="出错地址: "+document.location.href,ff=function (){
		window.clearTimeout(tid);
		var ip=w.document.getElementById('m_errcontent');
		if(ip){ip.value+=s;}else{tid=window.setTimeout(ff,1000);}
	};
	tid=window.setTimeout(ff,1000);
}

function viewComment(id,page){
	var url;
	if (page.length==0){url=id;}else{url="/"+sitePath+"comment.asp?id="+id+"&page="+page;}
	ajax.get(url, function(obj) {
		if (obj.responseText=="err"){
			set($("comment_list"),"<font color='red'>载入评论发生错误</font>")	
		}else{
			var bdy=$("comment_list"),dc=document.createElement('div');dc.innerHTML=obj.responseText;dc.id="comment_list";
			bdy.parentNode.replaceChild(dc,bdy);
		}
	});
	removeReply();
	//var bdy=$("comment_list"),dc=document.createElement('div');dc.innerHTML='系统负荷过重，评论暂时关闭';dc.id="comment_list";
}

function replyComment(oj,i){
	var r=replyComment,dc = r.dc!==null ? r.dc : r.dc=document.createElement('div');
	if(r.oj!==oj){
		if(r.oj!==null){
			r.oj.parentNode.className='bar';
			r.oj.className='noclick';
		};
		dc.className='add_reply';
		dc.innerHTML='<div class="post-area-wapper"><span title="关闭回应" class="close" onclick="removeReply()"></span>\
							<div class="post-area">\
								<textarea name="m_content" id="m_content2" onKeyDown="if(event.ctrlKey && event.keyCode == 13 || event.altKey && event.keyCode == 83) {setReply();}"></textarea>\
								<div class="post-area-action clear">\
									<span class="aleft">昵称(必填)： <input type="text" name="m_author" id="m_author2" value="你你看网友" size="15" maxlength="20" tabindex="1" />&nbsp;&nbsp;[Ctrl+回车键]&nbsp;快速发表回应</span>\
									<span class="aright"><input type="button" value="发表回应" class="postbtn" onclick="setReply();"/></span>\
								</div>\
							</div>\
						</div>';
		oj.parentNode.appendChild(dc);
		oj.parentNode.className='bar parentClass';
		oj.className='click';
		replyComment.oj=oj;
		replyComment.qu=i;
	}else{
		dc.parentNode.removeChild(dc);
		oj.parentNode.className='bar';
		oj.className='noclick';
		replyComment.oj=replyComment.dc=null;
	}
}
replyComment.dc=null;
replyComment.oj=null;
replyComment.qu='';
function setReply(){
	if($("m_content2").value.replace(/(^\s*)|(\s*$)/,'').replace(/[^\w]/,'xx').length<3){alert('您评论的内容太短啦,请补充');return false;}
	var qu=replyComment.qu,dd=$('dd_'+qu),dt=$('dt_'+qu);
	qu=(dt.innerText || dt.textContent || '')+"[br]"+dd.innerHTML.replace(/<DIV.*?>[\s\S]*<\/DIV>/ig,'').replace(/<.+?>/g,'');
	$('m_author').value=$('m_author2').value;
	$('m_content').value='[quote]'+qu+'[/quote]'+$('m_content2').value;
	removeReply();
	$('pinglunbt').onclick();
}

function removeReply(){
	var dc=replyComment.dc,oj=replyComment.oj;
	if(dc!==null) dc.parentNode.removeChild(dc);
	if(oj!==null) oj.parentNode.className='bar',oj.className='noclick';
	replyComment.dc=null;
	replyComment.oj=null;
	replyComment.qu='';
}
function submitComment(id){
	if($("m_author").value.length<1){alert('请填写昵称');return false;}
	if($("m_content").value.length<1){alert('请填写内容');return false;}
	if($("m_content").value.replace(/(^\s*)|(\s*$)/,'').replace(/[^\w]/,'xx').length<3){alert('您评论的内容太短啦,请补充');return false;}
	if(/[\s\u4e00-\u9fa5]/i.test($("m_content").value) != true){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=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($("msgbody"),str)
}

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,currentTypeId){
	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='?currentTypeId='+currentTypeId+'&page='+pageNum+'&searchword='+searchword+'&searchtype='+searchtype;
}

function leaveWord(){
	if($("m_author").value.length<1){alert('昵称必须填写');return false;}
	if($("m_content").value.length<1){alert('内容必须填写');return false;}
	ajax.postf(
		$("f_leaveword"),
		function(obj){if(obj.responseText=="ok"){viewLeaveWordList(1);alert('留言成功，多谢支持！');$("m_content").value='';}else if(obj.responseText=="haveleave"){alert('你的操作太快了');}else{alert('发生错误');}}
	);
}

function viewLeaveWordList(page){
	view('leavewordlist');
	ajax.get(
		"/"+sitePath+"gbook/index.asp?action=list&page="+page,
		function(obj) {
			if (obj.responseText=="err"){
				set($("leavewordlist"),"<font color='red'>发生错误</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/index.asp?action=state",
		function (obj){
			set($('adminleaveword'),obj.responseText);
		}
	);			
}

function logOut(){
	ajax.get(
		"/"+sitePath+"gbook/index.asp?action=logout",
		function (obj){set($('adminleaveword'),'成功退出');}
	);
	setLoginState();viewLeaveWordList(1);
}

function delLeaveWord(id,page,type){
	ajax.get(
		"/"+sitePath+"gbook/index.asp?action=del&id="+id+"&type="+type,
		function (obj){
			if (obj.responseText=="ok"){viewLeaveWordList(page)}else if(obj.responseText=="err"){alert('发生错误')}else{viewLeaveWordList(page);}
		}
	);
}

function replyLeaveWord(id,page){
	alertFrontWin(101,400,160,50,"")
	set($("msgtitle"),"回复留言")
	set($("msgbody"),"<form id='replyleaveword'  action='/"+sitePath+"gbook/index.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/index.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){
if((new Date()).getTime() % 10 !=0) return set($('hit'),'12');
	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 getNewsHit(nid){
	ajax.get("/"+sitePath+"inc/ajax.asp?action=hitnews&id="+nid,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 += '[ps:' + id +']';
}

function openWin(url,w,h,left,top,resize){
	return 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 set(el,xh){
	var dc=el.cloneNode(false);
	dc.innerHTML=xh;
	window.setTimeout(function (){el.parentNode.replaceChild(dc,el);},1000);
}

function StrSlice(str,sStart,sEnd){
	var s=str.indexOf(sStart),e=str.indexOf(sEnd);
	return e!=-1 ? str.substring(s!=-1 ? s : 0,str.indexOf(sEnd)) : '';
}

function EnGougouLink(s){
	return 'http://www.gougou.com/search?search='+encodeURIComponent(s)+'&id=4092115&pattern=40000';
}

function printGougouLink(s){
	//document.write('<li><a href="'+EnGougouLink(s)+'" title="点击进入下载页面" class="link_4" target="_blank">点击进入下载页面</a></li>');
}
