/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
var ajax = new AJAX();
ajax.setcharset("GBK");
var QRUN = (new Image());
    QRUN.src='/'+sitePath+'cron/index.php?t='+Math.random();
		
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($("comment_list"),"<font color='red'>发生错误</font>")
			}else{
				set($("comment_list"),obj.responseText)
			}
		}
	);		
}

function submitComment(id){
	if($("m_author").value.length<1){alert('请填写昵称');return false;}
	if($("m_content").value.length<1){alert('请填写内容');return false;}
	ajax.postf(
		$("f_comment"),function(obj){
			var x=obj.responseText;
			if(x=="ok"){
				viewComment(id,1);alert('小弟我感谢您的评论!');
			}else if(x=="havecomment"){
				alert('小样儿你手也太快了，歇会儿再来评论吧！');
			}else if(x=="cn"){
				alert('你必需输入中文才能发表');
			}else{
				alert('发生错误');
			}
	});
}

function diggVideo(id,div){
	ajax.get(
		"/"+sitePath+"inc/ajax.php?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.php?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 markscore0(vd,d,t,s,l,ac){
	var alt=['很差','较差','还行','推荐','力荐'],url=ac=='news' ? ["/"+sitePath+"inc/ajax.php?id="+vd+"&action=newsscore","/"+sitePath+"inc/ajax.php?id="+vd+"&action=scorenews&score="] : ["/"+sitePath+"inc/ajax.php?id="+vd+"&action=videoscore","/"+sitePath+"inc/ajax.php?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>');
	$(id).onclick=function (){
		for(var i=0;i<=l;i++) if($('sint'+i).checked)break;
		ajax.get(url[1]+i,function (obj){
			if((''+obj.responseText).indexOf("havescore")!=-1){
				alert('你已经评过分啦');
			}else{
				s+=i;
				$('MARK_B1').innerHTML=++x;
				$('MARK_B2').innerHTML=(parseInt(s / x * 100) / 100) || 0;
				$('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.php?id="+vd+"&action=newsscore","/"+sitePath+"inc/ajax.php?id="+vd+"&action=scorenews&score="] : ["/"+sitePath+"inc/ajax.php?id="+vd+"&action=videoscore","/"+sitePath+"inc/ajax.php?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 getVideoHit(vid){
	ajax.get("/"+sitePath+"inc/ajax.php?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.php?action=hitnews&id="+nid,function (obj){
			var result=obj.responseText
			if(result=="err"){set($('hit'),'发生错误')}else{set($('hit'),result);}
		}
	);		
}

function diggNews(id,div){
	ajax.get("/"+sitePath+"inc/ajax.php?id="+id+"&action=diggnews",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 treadNews(id,div){
	ajax.get("/"+sitePath+"inc/ajax.php?id="+id+"&action=treadnews",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 markNews(vd,d,t,s,l,c){
	window['markscore'+(c==1 ? 1 : 0)](vd,d,t,s,parseInt(l)<0 ? 5 : l,'news');
}

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,surl){
	var str,goUrl
	var url=location.href
	pageNum=getPageValue(pageDiv)
	if (pageNum.length==0||isNaN(pageNum)){alert('输入页码非法');return false;}
	if(pageNum>maxPage){pageNum=maxPage;}
	pageNum=pageNum<1 || pageNum==1 ? '' : pageNum;
	location.href=surl.replace('<page>',pageNum).replace('-.','.').replace('_.','.').replace(/\?\.\w+/i,'');
}

function goSearchPage(maxPage,pageDiv,surl){
	getPageGoUrl(maxPage,pageDiv,surl);
}

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){
		var x=obj.responseText;
		if(x=="ok"){
			viewLeaveWordList(1);alert('留言成功，多谢支持！');$("m_content").value='';
		}else if(x=="haveleave"){
			alert('小样儿你手也太快了，歇会儿再来留言吧！');
		}else if(x=="haveleave"){
			alert('小样儿你手也太快了，歇会儿再来留言吧！');
		}else if(x=="cn"){
			alert('你必需输入中文才能发表');
		}else{
			alert('发生错误');
		}
	});
}

function viewLeaveWordList(page){
	view('leavewordlist');
	ajax.get(
		"/"+sitePath+"gbook.php?action=list&page="+page+"&t="+(new Date()).getTime(),
		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.php?action=state",
		function (obj){
			set($('adminleaveword'),obj.responseText);
		}
	);			
}

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

function delLeaveWord(id,page,type){
	ajax.get(
		"/"+sitePath+"gbook.php?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.php?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.php?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 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);
}

