/********************************************************************************/
/*
Ajax Object
*/
Ajax = {};
Ajax.getXML=function(url,callback){
	this.request = new ActiveXObject("Microsoft.XMLHTTP");
    this.request.onreadystatechange = function(){Ajax.stateHandler(callback)};
    this.request.open("post", url, true);
    this.request.send(url);
	Interface.setState("loading");
}
Ajax.stateHandler=function(callback){
	if(this.request.readyState==4){
		if(this.request.status>=200 && this.request.status<300){
			this.ResponseDoc=this.request.responseXML.documentElement;callback();
		}
		else
			Interface.alert("网络连接出现错误，请刷新后再试。");
		AjaxUpdater.unRegister();	
		AjaxUpdater.Next();
		Interface.setState("loaded");
	}
}

AjaxUpdater={
	Waiting:0,Stack:[],
	Register:function(){
		this.Waiting++;
	},
	unRegister:function(){
		this.Waiting--;
	}
}
AjaxUpdater.Next=function(){
	if(this.Waiting!=0){	
		Ajax.getXML(this.Stack[0].url,this.Stack[0].callback);
	}
}
AjaxUpdater.Update=function(url,callback){	
	if(this.Waiting==0){
		this.Register();
		Ajax.getXML(url,callback);
	}else{
		this.Register();
		AjaxUpdater.Push(url,callback);
	}
}
AjaxUpdater.Include=function(url){
	var found=false;
	for(Key in this.Stack){
		this.Stack[Key].url==url?found=true:null;
	}
	return found;
}
AjaxUpdater.Push=function(url,callback){
    !this.Include(url)?this.Stack.push({
		url:url,
		callback:callback
	}):null;
}

/********************************************************************************/
/*
Interface Object
*/
function CDATAEncoding(str){
	str=str.replace(/\&amp;/g,"&");
	str=str.replace(/\&gt;/g,">");
	return str;
}
Interface={FontSize:3}
Interface.getDefaultHead=function(){return "skins/"+this.SkinFolder+"/defaulthead.gif";}
Interface.openActiveLayer=function(p){
	var Layer=document.getElementById("ActiveLayer");
	var shadow=document.getElementById("ShadowLayer");
	shadow.style.display="block";
	shadow.style.pixelWidth=document.body.offsetWidth;
	shadow.style.pixelHeight=document.body.offsetHeight;
	Layer.style.display="block";
	Layer.style.pixelTop=document.documentElement.scrollTop+110;
	Layer.style.pixelLeft=(document.body.offsetWidth-p.width)/2;
	Layer.style.pixelWidth=p.width;
	Layer.style.pixelHeight=p.height;
	Layer.innerHTML="<div class='ALayer_title'>"+p.caption+"</div><div id='ALayer_content'>"+p.html+"</div>";
}
Interface.closeActiveLayer=function(){document.getElementById("ActiveLayer").style.display="none";document.getElementById("ShadowLayer").style.display="none";}
Interface.displayUserControlBox=function(){
	this.openActiveLayer({
		caption:"修改注册信息",
		width:400,
		height:370,
		html:"<table align='center' style='text-align:left;'><tr><td align='right'><strong>原来的密码:</strong></td><td><input class='text' type='password' id='inputValue'size='16' /></td></tr><tr><td align='right' valign='top'><strong>新密码:</strong></td><td><input size='15' id='inputValue'  class='text' type='password' /><br />6～15个字符,不修改不要填写</td></tr><tr><td align='right'><strong>新密码重复:</strong></td><td><input class='text' size='15' type='password' id='inputValue' /></td></tr><tr><td align='right'><strong>Email:</strong></td><td><input size='18' class='text' type='text' id='inputValue' /></td></tr><tr><td align='right'><strong>主页:</strong></td><td><input class='text' type='text' size='20' id='inputValue' /></td></tr><tr><td align='right' valign='top'><strong>头像:</strong></td><td><input size='30' class='text' type='text' id='inputValue' /><br />将以48*48的大小显示</td></tr><tr><td valign='top' align='right'><strong>自我介绍:</strong><br />150个字以内</td><td><textarea id='inputValue' class='text'  cols='30' rows='5'></textarea></td></tr><tr><td colspan='2' align='center'><input class='button' type='button' onclick='User.ModifyUserInfo()' value='好了,修改吧' />&nbsp;<input class='button' type='button' onclick='Interface.closeActiveLayer()' value='取消' /></td></tr></table>"
	});
	AjaxUpdater.Update("system.asp?action=mluserinfo&username="+encodeURIComponent(User.username),function(){
		var Root=Ajax.ResponseDoc
		if(Root.childNodes[0].text=="0"){
			inputValue[3].value=CDATAEncoding(Root.childNodes[1].childNodes[0].text);
			inputValue[4].value=CDATAEncoding(Root.childNodes[1].childNodes[1].text);
			inputValue[5].value=CDATAEncoding(Root.childNodes[1].childNodes[2].text);
			inputValue[6].value=CDATAEncoding(Root.childNodes[1].childNodes[3].text);
		}else{
		}
	});
}
Interface.displayLoginBox=function(){
	this.openActiveLayer({
		caption:"登陆",
		width:270,
		height:130,
		html:"<table align='center'><tr><td align='right'><strong>帐号:</strong></td><td><input class='text' type='text' id='inputValue' /></td></tr><tr><td align='right' valign='top'><strong>密码:</strong></td><td><input class='text' type='password' id='inputValue' /></td></tr><tr><td colspan='2' align='center'><input class='button' type='button' onclick='User.Login()' value='登陆' />&nbsp;<input class='button' type='button' onclick='Interface.closeActiveLayer()' value='取消' /></td></tr></table>"
	})
}
Interface.displayRegBox=function(){
	this.openActiveLayer({
		caption:"注册成员",
		width:400,
		height:390,
		html:"<table align='center' style='text-align:left;'><tr><td align='right'><strong>你想要的名字:</strong></td><td><input class='text' type='text' id='inputValue' size='16' /><br />3～15个汉字、字母、数字组成的字符</td></tr><tr><td align='right' valign='top'><strong>密码:</strong></td><td><input size='15' id='inputValue'  class='text' type='password' /><br />6～15个字符</td></tr><tr><td align='right'><strong>密码重复:</strong></td><td><input class='text' size='15' type='password' id='inputValue' /></td></tr><tr><td align='right'><strong>Email:</strong></td><td><input size='18' class='text' type='text' id='inputValue' /></td></tr><tr><td align='right'><strong>主页:</strong></td><td><input class='text' type='text' size='20' id='inputValue' /></td></tr><tr><td align='right' valign='top'><strong>头像:</strong></td><td><input size='30' class='text' type='text' id='inputValue' /><br />将以48*48的大小显示</td></tr><tr><td valign='top' align='right'><strong>自我介绍:</strong><br />150个字以内</td><td><textarea id='inputValue' class='text'  cols='30' rows='5'></textarea></td></tr><tr><td colspan='2' align='center'><input class='button' type='button' onclick='User.Register()' value='好了,注册' />&nbsp;<input class='button' type='button' onclick='Interface.closeActiveLayer()' value='取消' /></td></tr></table>"
	})
}
Interface.displayUserPannel=function(){
	sidebar_UP.innerHTML="";
	sidebar_UP.innerHTML+="<img class='MemHead' width='48' src=\""+User.getHeadSrc()+"\" style='float:left' />"+(User.logined?"登陆名:"+User.username+"<br />":"");
	
	if(User.logined==true)
		sidebar_UP.innerHTML+=(User.username.toLowerCase()==Setting.Owner.toLowerCase()?"<a class='UPannelLink' href='mc_main.asp?c1=blog&c2=post' target='_blank'>发表日志</a>&nbsp;<a class='UPannelLink' href='mc_index.asp' target='_blank'>后台管理</a><br />":"")+"<a class='UPannelLink' href='javascript:void(0)' onclick='Interface.displayUserControlBox()'>修改注册信息</a>&nbsp;<a class='UPannelLink' href='javascript:void(0)' onclick='User.Logout()'>退出登陆</a>";
	else
		sidebar_UP.innerHTML+="<a class='UPannelLink' href='javascript:void(0)' onclick='Interface.displayLoginBox()'>登陆</a>&nbsp;"+(Setting.AllowReg==1?"<a class='UPannelLink' href='javascript:void(0)' onclick='Interface.displayRegBox()'>注册</a>":"");
}
Interface.alert=function(str,timer){
	var Layer=document.getElementById("AlertLayer");
	if(timer==undefined)timer=5000;
	Layer.style.display="block";
	Layer.style.pixelTop=document.documentElement.scrollTop+150;
	Layer.style.pixelLeft=(document.body.offsetWidth-Layer.offsetWidth)/2;
	Layer.innerHTML="<div class='alert_content'>"+str+"</div><input id='alert_button' type='button' value='OK' onclick=AlertLayer.style.display='none' />";
	setTimeout("alert_button.fireEvent('onclick')",timer);
}
Interface.SetBlogFontSize=function(size){
	Interface.FontSize=size;
	switch(size){
		case 1:
			LSExerptN.style.fontSize="16px";
			LSExerptN.style.lineHeight="24px";
			break;
		case 2:
			LSExerptN.style.fontSize="14px";
			LSExerptN.style.lineHeight="22px";
			break;
		case 3:
			LSExerptN.style.fontSize="12px";
			LSExerptN.style.lineHeight="20px";
			break;
	}
}
function setSLayer(){
	try{
	StateLayer.style.pixelTop=document.documentElement.scrollTop+10;
	StateLayer.style.pixelLeft=document.body.offsetWidth-100;
	}catch(e){;}
}
window.onscroll=setSLayer;
Interface.setState=function(state){
	try{
		if(state=="loading"){
		StateLayer.style.display="block";
		StateLayer.innerHTML='正在载入...';
		setSLayer();
		}else{
		setTimeout("StateLayer.style.display='none';",400);
		}
	}catch(e){;}
}
Interface.listSmiley=function(){
	var Smileys="";
	for(var i=0;i<=18;i++)
		Smileys+="<img onclick='CPContent.value+=\"[smiley"+i+"]\";Interface.closeActiveLayer();' style='cursor:hand;margin:2px;border:1px solid #CCCCCC;' width='48' src='images/smiley/"+i+".jpg' />";
	this.openActiveLayer({
		caption:"插入表情",
		width:390,
		height:210,
		html:Smileys
	})
}
Interface.GetCode=function(){
	return ("<img src='getcode.asp?random="+Math.random(1)+"' style='cursor:hand' onclick='this.src=\"getcode.asp?random="+Math.random(1)+"\"' />");
}
/********************************************************************************/
/*
User Object
*/
User={username:"",logined:false,headsrc:""}
User.getHeadSrc=function(){
	return (this.headsrc=="")?Interface.getDefaultHead():this.headsrc;
}
User.Logout=function(){
	AjaxUpdater.Update("system.asp?action=logout",function(){
		try{
		CPName.value="";
		CPName.disabled=false;
		}catch(e){}
		Interface.alert("成功退出！",2000);
		User.username="";
		User.logined=false;
		Interface.displayUserPannel();
	});
}
User.Login=function(){
	AjaxUpdater.Update("system.asp?action=login&username="+encodeURIComponent(inputValue[0].value)+"&password="+encodeURIComponent(inputValue[1].value),function(){
		var Root=Ajax.ResponseDoc;
		if(Root.childNodes[0].text=="0"){
			Interface.alert("登陆成功！<br />",2000);
			try{
			CPName.value=inputValue[0].value;
			CPName.disabled=true;
			}catch(e){}
			User.username=inputValue[0].value;
			User.logined=true;
			User.headsrc=(!Root.childNodes[1].text=="")?Root.childNodes[1].text:"";
			Interface.displayUserPannel();
			Interface.closeActiveLayer();
		}else{
			Interface.alert(Root.childNodes[0].text,5000);
		}
	});
}
User.ModifyUserInfo=function(){
	var errList="";
	if(inputValue[1].value!="" && (inputValue[1].value.length<6 || inputValue[1].value.length>15))errList+="<li>密码长度为6～15";
	if(inputValue[1].value!=inputValue[2].value)errList+="<li>两次输入的密码不一样.";
	if(!inputValue[3].value.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/))errList+="<li>Email格式错误";
	if(inputValue[6].innerHTML.length>200)errList+="<li>自我介绍最多为200个字.";
	if(errList==""){
		AjaxUpdater.Update("system.asp?action=modifyuser&username="+encodeURIComponent(User.username)+"&oldpw="+encodeURIComponent(inputValue[0].value)+"&password="+encodeURIComponent(inputValue[1].value)+"&email="+encodeURIComponent(inputValue[3].value)+"&homepage="+encodeURIComponent(inputValue[4].value)+"&headsrc="+encodeURIComponent(inputValue[5].value)+"&selfintro="+encodeURIComponent(inputValue[6].value),function(){
		if(Ajax.ResponseDoc.text=="0"){
			Interface.alert("修改成功！<br />",2000);
			User.headsrc=(!inputValue[5].value=="")?inputValue[5].value:"";
			Interface.displayUserPannel();
			Interface.closeActiveLayer();
		}else{
			Interface.alert(Ajax.ResponseDoc.text,5000);
		}
	})
	}else{Interface.alert(errList,5000);}

}
User.Register=function(){
	var errList="";
	if(!inputValue[0].value.match(/^(\w|[\u4E00-\u9FA5])*$/))errList+=("<li>用户名只允许为英文，数字和汉字");
	if(!inputValue[3].value.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/))errList+=("<li>Email格式错误");

	if(inputValue[0].value.length<3 || inputValue[0].value.length>15)	errList+="<li>注册的名字应是3～15个汉字、字母、数字组成的字符.";
	if(inputValue[1].value.length<6 || inputValue[1].value.length>15)	errList+="<li>密码长度为6～15";
	if(inputValue[1].value!=inputValue[2].value)errList+="<li>两次输入的密码不一样.";
	if(inputValue[6].innerHTML.length>200)errList+="<li>自我介绍最多为200个字.";
	if(errList==""){
		AjaxUpdater.Update("system.asp?action=registeruser&username="+encodeURIComponent(inputValue[0].value)+"&password="+encodeURIComponent(inputValue[1].value)+"&email="+encodeURIComponent(inputValue[3].value)+"&homepage="+encodeURIComponent(inputValue[4].value)+"&headsrc="+encodeURIComponent(inputValue[5].value)+"&selfintro="+encodeURIComponent(inputValue[6].value),function(){
		if(Ajax.ResponseDoc.text=="0"){
			Interface.alert("注册成功！<br />欢迎常来！",2000);
			User.username=inputValue[0].value;
			User.logined=true;
			User.headsrc=(!inputValue[5].value=="")?inputValue[5].value:"";
			Interface.displayUserPannel();
			Interface.closeActiveLayer();
		}else{
			Interface.alert(Ajax.ResponseDoc.text,5000);
		}
	})
	}else{Interface.alert(errList,5000);}
}
User.GetUserInfo=function(username){
	Interface.openActiveLayer({
		caption:"查看帐号资料",
		width:400,
		height:100,
		html:"<div style='text-align:center'>正在载入帐号资料...<p><input class='button' type='button' onclick='Interface.closeActiveLayer()' value='关闭' /></div>"
		})
	AjaxUpdater.Update("system.asp?action=userinfo&username="+encodeURIComponent(username),function(){
		var Root=Ajax.ResponseDoc.childNodes[0];
		if(Root.text=="0")
			ALayer_content.innerHTML="<div style='text-align:center'>没有找到这个帐号的资料<p><input class='button' type='button' onclick='Interface.closeActiveLayer()' value='关闭' /></div>";
		else{
			ActiveLayer.style.pixelHeight=320;
			ALayer_content.innerHTML="<img style='float:right;clear:both;z-index:99;margin-right:10;' class='MemHead' width='48' src=\""+(CDATAEncoding(Root.childNodes[0].text)==""?Interface.getDefaultHead():CDATAEncoding(Root.childNodes[0].text))+"\" /><table style='float:left;clear:both;text-align:left;z-index:0;' align='center' width='400'><tr><td align='right' width='100'><strong>帐号:</strong></td><td>"+username+"</td></tr><tr><td align='right'><strong>注册时间:</strong></td><td>"+Root.attributes[1].text+"</td></tr><tr><td align='right'><strong>Email:</strong></td><td>"+Root.attributes[0].text+"</td></tr><tr><td align='right'><strong>主页:</strong></td><td>"+CDATAEncoding(Root.childNodes[1].text)+"</td></tr><tr><td align='right'><strong>上次登陆:</strong></td><td>"+Root.attributes[4].text+"</td></tr><tr><td align='right' valign='top'><strong>自我介绍:</strong></td><td><textarea cols=40 rows=8>"+CDATAEncoding(Root.childNodes[2].text)+"</textarea></td></tr><tr><td colspan='2' align='center'>评论"+Root.attributes[2].text+"个&nbsp;&nbsp;留言"+Root.attributes[3].text+"个</td></tr><tr><td colspan='2' align='center'><input class='button' type='button' onclick='Interface.closeActiveLayer()' value='关闭' /></td></tr></table>";
		}
	})
}
/********************************************************************************/
/*
Blog Object
*/
Blog={BID:null,CID:null,BPT:null}
Blog.List=function(para){
			AjaxUpdater.Update("system.asp?action=list&key="+para[0]+"&value="+para[1]+"&page="+para[2],function(){
			if(Ajax.ResponseDoc.childNodes[0].text=="")
				descriptionSection.style.display="none";
			else{
				descriptionSection.style.display="block";
				descriptionSection.innerHTML=Ajax.ResponseDoc.childNodes[0].text;
			}
			var Root=Ajax.ResponseDoc.childNodes[1];
			var pageSwitch="<select onchange='Blog.List([\""+para[0]+"\",\""+para[1]+"\",this.value])'>";
			for(var i=1;i<=parseInt(Root.attributes[1].text);i++)
				pageSwitch+="<option value='"+i+"' "+(parseInt(Root.attributes[0].text)==i?" selected":"")+">"+i+"</option>";
			pageSwitch+="</select>";
			Blog.HTML="<div class='bodyer_listcontrol'>"+(para[0]!="cid"?"":"<a href='javascript:void(0)' onclick='URLManager.Goto([\"highlights\","+para[1]+",1])'>查看本类高亮日志</a>&nbsp;&nbsp;")+"<strong>列表方式:</strong><a href='javascript:void(0)' onclick='System.SetListMode(1)'>标准</a>&nbsp;<a href='javascript:void(0)' onclick='System.SetListMode(2)'>列表</a>&nbsp;"+pageSwitch+"</div>";
			if(Setting.DisMode==1){
				for(var i=0;i<Root.childNodes.length;i++)
					Blog.HTML+="<div class='"+(Root.childNodes[i].attributes[4].text!="True"?"SBNormal":"SBHLight")+"'><div class='SBTop'><div class='SBTitle'><a href='javascript:void(0)' onclick='Blog.Display("+Root.childNodes[i].attributes[0].text+")'>"+Root.childNodes[i].childNodes[0].text+"</a></div><div class='SBPostTime'>时间:"+Root.childNodes[i].attributes[1].text+"</div></div><div class='SBExcerpt'>"+Root.childNodes[i].childNodes[2].text+"</div><div class='SBInfo'>分类:<a href='javascript:void(0)' onclick='URLManager.Goto([\"cid\","+encodeURIComponent(Root.childNodes[i].attributes[5].text)+",1])'>"+Root.childNodes[i].childNodes[1].text+"</a>&nbsp;&nbsp;评论:"+Root.childNodes[i].attributes[3].text+"&nbsp;&nbsp;引用:"+Root.childNodes[i].attributes[6].text+"&nbsp;&nbsp;查看次数:"+Root.childNodes[i].attributes[2].text+"</div></div>";
			}else{
				for(var i=0;i<Root.childNodes.length;i++)
					Blog.HTML+="<div class='"+(Root.childNodes[i].attributes[4].text!="True"?"SBNormal":"SBHLight")+"'><div class='SBTop'><div class='SBTitle'><a href='javascript:void(0)' onclick='Blog.Display("+Root.childNodes[i].attributes[0].text+")'>"+Root.childNodes[i].childNodes[0].text+"</a><span>["+Root.childNodes[i].attributes[1].text+"]</span></div></div><div class='SBInfo'>分类:<a href='javascript:void(0)' onclick='URLManager.Goto([\"cid\","+encodeURIComponent(Root.childNodes[i].attributes[5].text)+",1])'>"+Root.childNodes[i].childNodes[1].text+"</a>&nbsp;&nbsp;评论:"+Root.childNodes[i].attributes[3].text+"&nbsp;&nbsp;引用:"+Root.childNodes[i].attributes[6].text+"&nbsp;&nbsp;查看次数:"+Root.childNodes[i].attributes[2].text+"</div></div>";
			}
			if(Root.childNodes.length==0)Blog.HTML="没有找到符合条件的日志";
			System.StyleOut();
			System.BackPara=para;
			switch(para[0]){
			case "cid":
				URLManager.SetQueryString((para[1]==1?"default":para[0]+"="+encodeURIComponent(para[1]))+"&page="+para[2]);
				break;
			default:
				URLManager.SetQueryString(para[0]+"="+para[1]+"&page="+para[2]);
			}
		});
}
Blog.Display=function(id){
	AjaxUpdater.Update("system.asp?action=blog&id="+id,function(){Blog.DisplayEx(Ajax.ResponseDoc,id);URLManager.SetQueryString("bid="+id);});
}	
Blog.DisplayEx=function(XML,id){
		descriptionSection.style.display="none";
		Blog.HTML="";
		if(XML.childNodes[0].text=="0"){
			var BlogRoot=XML.childNodes[1];
			var tags=BlogRoot.childNodes[3].text.split(",");
			var tagStr="";
			if(tags.length>1)
				tagStr="标签:";
				for(var i=0;i<tags.length-1;i++)tagStr+="<a href='javascript:void(0)' onclick='URLManager.Goto([\"tag\",encodeURIComponent(this.innerText),1]);'>"+tags[i]+"</a>&nbsp;&nbsp;";
			Blog.HTML+="<div class='"+(BlogRoot.attributes[3].text!="True"?"SBNormal":"SBHLight")+"'><div class='SBTop'><div class='SBTitle'>"+BlogRoot.childNodes[0].text+"</div><div class='SBPostTime'>时间:"+BlogRoot.attributes[0].text+"</div></div><div class='SBFontSize'><strong>字体大小:</strong><a href='javascript:void(0)' onclick='Interface.SetBlogFontSize(1)'>大</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='Interface.SetBlogFontSize(2)'>中</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='Interface.SetBlogFontSize(3)'>小</a></div><div id='LSExerptN' class='SBExcerpt'>"+BlogRoot.childNodes[2].text+"</div><div class='SBInfo'>"+tagStr+"分类:<a href='javascript:void(0)' onclick='URLManager.Goto([\"cid\","+encodeURIComponent(BlogRoot.attributes[4].text)+",1])'>"+BlogRoot.childNodes[1].text+"</a>&nbsp;&nbsp;评论:"+BlogRoot.attributes[2].text+"&nbsp;&nbsp;引用:"+BlogRoot.attributes[5].text+"&nbsp;&nbsp;查看次数:"+BlogRoot.attributes[1].text+"</div><div id='SBGetOther'><a href='javascript:void(0)' onclick='Comment.PageTo(1)'>察看日志评论["+BlogRoot.attributes[2].text+"]</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='Blog.GetTrackbacks()'>察看该引用["+BlogRoot.attributes[5].text+"]</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='Blog.GetTBAddress()'>获取Trackback地址</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='Blog.GetRelatedBlog()'>获取相关日志</a><div id='RelatedBlogSection' style='display:hidden'></div></div></div>";
			Blog.HTML+="<div id='cmtSection'></div>";
			Blog.HTML+=(BlogRoot.attributes[6].text=="False")?"<div id='CMTPostSec'><div class='CMTPostTitle'>发表评论</div><table align='center'><tr><td>名字:</td><td><input id='CPName' type='text' value='"+User.username+"' "+(User.username!=""?"disabled":"")+" /></td></tr><tr><td>验证码:</td><td><input id='CPCode' type='text' size='5' maxLength='4' />"+Interface.GetCode()+"<span style='font-weight:normal'>&nbsp;不区分大小写,长时间停留请刷新验证码</span></td></tr><tr><td valign='top'>内容:</td><td><a href='javascript:void(0)' onclick='CPContent.value+=\"[bold]内容[/bold]\"'><img src='images/ubb/bold.gif' /></a><a href='javascript:void(0)' onclick='CPContent.value+=\"[italic]内容[/italic]\"'><img src='images/ubb/italic.gif' /></a><a href='javascript:void(0)' onclick='CPContent.value+=\"[underline]内容[/underline]\"'><img src='images/ubb/underline.gif' /></a><img src='images/ubb/bar.gif' /><a href='javascript:void(0)' onclick='CPContent.value+=\"[img]地址[/img]\"'><img src='images/ubb/image.gif' /></a><a href='javascript:void(0)' onclick='Interface.listSmiley()'><img src='images/ubb/smiley.gif' /></a><br /><textarea cols='50' rows='8' id='CPContent'></textarea></td></tr><tr><td colspan='2' align='center'><input name='btnPost' type='button' value='发表' class='button' onclick='Comment.Post()' /></td></tr></table></div>":"<div class='CMTPostSec'><div class='CMTPostTitle'>本文取消了评论</div></div>";
			this.CID=parseInt(BlogRoot.attributes[4].text);
			this.BPT=BlogRoot.attributes[0].text;
		}else{
			Blog.HTML=Ajax.ResponseDoc.childNodes[0].text;
		}
		System.StyleOut();
		Interface.SetBlogFontSize(Interface.FontSize);
		this.BID=id;	
}
Blog.GetTBAddress=function(){
	Interface.openActiveLayer({
		caption:"获取Trackback地址",
		width:380,
		height:150,
		html:"<div id='AL_4TB' style='text-align:center;'>请输入验证码:<br /><input style='width:30px;' type='text' maxlength='4' id='securitycode' />&nbsp;"+Interface.GetCode()+"<br />为防止Trackback Spam而设计<br /><input type='button' class='button' onclick='Blog._GetTBAddress()' value='确认' />&nbsp;<input type='button' class='button' value='取消' onclick='Interface.closeActiveLayer()' /></div>"
	})
}
Blog._GetTBAddress=function(){
	AjaxUpdater.Update("system.asp?action=getTbAddress&code="+securitycode.value+"&bid="+Blog.BID,function(){
		if(Ajax.ResponseDoc.childNodes[0].text!="0")
			Interface.alert(Ajax.ResponseDoc.childNodes[0].text,2000);
		else
			AL_4TB.innerHTML="本文的Trackback地址:<br /><font style='font:bold 14px'>"+Ajax.ResponseDoc.childNodes[1].text+"</a><br /><input type='button' class='button' value='关闭' onclick='Interface.closeActiveLayer()' />";
	});
}
Blog.GetRelatedBlog=function(){
	if(RelatedBlogSection.innerHTML==""){
		RelatedBlogSection.innerHTML="正在载入...";
		AjaxUpdater.Update("system.asp?action=related&bid="+Blog.BID+"&cid="+Blog.CID+"&bpt="+Blog.BPT,function(){
			var Root=Ajax.ResponseDoc.childNodes[0];
			RelatedBlogSection.style.display="block";
			RelatedBlogSection.style.overflow="visible";
			RelatedBlogSection.innerHTML=Root.childNodes[0].attributes[0].text=="0"?"此分类中的没有更早一篇日志了.<br />":"此分类中的前一篇日志:<a href='javascript:void(0)' onclick='URLManager.Goto([\"bid\","+Root.childNodes[0].attributes[0].text+"])'>"+Root.childNodes[0].text+"</a><span>"+Root.childNodes[0].attributes[1].text+"</span><br />";
			RelatedBlogSection.innerHTML+=Root.childNodes[1].attributes[0].text=="0"?"此分类中的没有更迟一篇日志了.":"此分类中的后一篇日志:<a href='javascript:void(0)' onclick='URLManager.Goto([\"bid\","+Root.childNodes[1].attributes[0].text+"])'>"+Root.childNodes[1].text+"</a><span>["+Root.childNodes[1].attributes[1].text+"]</span>";
		});
	}
}
Blog.GetTrackbacks=function(){
	cmtSection.innerHTML="正在载入...";
	AjaxUpdater.Update("system.asp?action=gettbs&bid="+Blog.BID,function(){
		if(Ajax.ResponseDoc.childNodes[0].text=="1"){
			var Root=Ajax.ResponseDoc.childNodes[1];
			cmtSection.innerHTML="";
			for(var i=0;i<Root.childNodes.length;i++)
				cmtSection.innerHTML+="<div class='SingleComment'><div class='SCTop'><a target='_blank' href='"+Root.childNodes[i].childNodes[1].text+"'>"+Root.childNodes[i].childNodes[0].text+"</a><span>["+Root.childNodes[i].attributes[0].text+"]</span></div><div class='SCContent'>"+Root.childNodes[i].childNodes[2].text+"</div></div>";
		}else{
			cmtSection.innerHTML="这篇文章目前还没有引用";
		}
	});
}
/********************************************************************************/
/*
Comment Object
*/
Comment={}
Comment.Post=function(){
	var errList=""
	if(!CPName.value.match(/^(\w|[\u4E00-\u9FA5])*$/))errList+=("<li>用户名只允许为英文，数字和汉字");
	if(CPName.value.length<3 || CPName.value.length>15)errList="<li>名字的长度为3～15";
	if(CPCode.value.length!=4)errList+="<li>验证码为4个字符.";
	if(CPContent.value.length==0)errList+="<li>还没写评论呢！";
	if(CPContent.value.length>Setting.PWL)errList+="<li>评论的长度被限制在"+Setting.PWL+"以内.";
	if(errList==""){
	btnPost.disabled=true;
		AjaxUpdater.Update("system.asp?action=postcomment&bid="+Blog.BID+"&username="+encodeURIComponent(CPName.value)+"&code="+CPCode.value+"&content="+encodeURIComponent(CPContent.value),function(){
			if(Ajax.ResponseDoc.childNodes[0].text=="0"){
				Blog.DisplayEx(Ajax.ResponseDoc.childNodes[1],Blog.BID)
				Interface.alert("评论发表成功！",2000);
				Comment.PageTo(1,"intoView");
			}else{
				Interface.alert(Ajax.ResponseDoc.childNodes[0].text,2000);
			}
			btnPost.disabled=false;
		});
	}else{
		Interface.alert(errList,5000);
	}
}
Comment.Goto=function(cmtid,logid){
	AjaxUpdater.Update("system.asp?action=blog&cmt=1&id="+logid,function(){
		Blog.DisplayEx(Ajax.ResponseDoc,logid);
		Comment.DisplayEx(Ajax.ResponseDoc.childNodes[2])
		URLManager.SetQueryString("bid="+logid,"#cmt"+cmtid);
	});
}
Comment.DisplayEx=function(CommentRoot){
	var cmtStr="";
		for(var i=0;i<CommentRoot.childNodes.length;i++){
		cmtStr+="<a name='cmt"+CommentRoot.childNodes[i].attributes[0].text+"'></a><div class='"+(CommentRoot.childNodes[i].childNodes[0].text.toLowerCase()==Setting.Owner.toLowerCase()?"SingleCommentAdmin":"SingleComment")+"'><div class='SCTop'><a href='javascript:void(0);' onclick='User.GetUserInfo(this.innerText)'>"+CommentRoot.childNodes[i].childNodes[0].text+"</a><span>["+CommentRoot.childNodes[i].attributes[1].text+"]</span></div><div class='SCContent'><table><tr><td valign=top><img class='MemHead' width=48 src=\""+(CommentRoot.childNodes[i].childNodes[2].text!=""?CommentRoot.childNodes[i].childNodes[2].text:Interface.getDefaultHead())+"\" /></td><td valign=top align=left>"+CommentRoot.childNodes[i].childNodes[1].text+"</td></tr></table></div></div>"
		}
	var pageSwitch="<select onchange='Comment.PageTo(this.value,\"intoView\")'>";
		for(var i=1;i<=parseInt(CommentRoot.attributes[1].text);i++)
			pageSwitch+="<option value='"+i+"' "+(parseInt(CommentRoot.attributes[0].text)==i?" selected":"")+">"+i+"</option>";
	pageSwitch+="</select>"
	cmtStr+=parseInt(CommentRoot.attributes[1].text)>1?"<div class='pagecontrol'>"+pageSwitch+"</div>":"";
	cmtSection.innerHTML=(CommentRoot.childNodes.length==0?"目前还没有评论.":cmtStr);
}
Comment.PageTo=function(page,mode){
	if(cmtSection.innerHTML!="正在载入..."){
		cmtSection.innerHTML="正在载入...";
		AjaxUpdater.Update("system.asp?action=comment&bid="+Blog.BID+"&page="+page,function(){Comment.DisplayEx(Ajax.ResponseDoc.childNodes[0]);
		mode=="intoView"?SBGetOther.scrollIntoView():null;
		});
	}
}





/********************************************************************************/
/*
System Object
*/
System={FirstTime:true}
System.SetListMode=function(mode){
	Setting.DisMode=mode;
	URLManager.AnalyzeURL();
}
System.ListTags=function(){
	AjaxUpdater.Update("system.asp?action=tags",function(){
		descriptionSection.style.display="none";
		var tags="<div class='tagClouds'>";
		var Root=Ajax.ResponseDoc.childNodes;
		for(var i=0;i<Root.length;i++)
		tags+="<a href='javascript:void(0)' onclick='URLManager.Goto([\"tag\",encodeURIComponent(this.innerText),1])' style='"+Root[i].attributes[0].text+"' title='有"+Root[i].attributes[1].text+"篇日志'>"+Root[i].text+"</a>";
		tags+="</div>"
		Blog.HTML=tags;
		System.StyleOut();
		URLManager.SetQueryString("tags");
	});
}
System.GuestbookPage=1;
System.Guestbook=function(){
	descriptionSection.style.display="none";
		AjaxUpdater.Update("system.asp?action=guestbook&page="+this.GuestbookPage,function(){
			System.GuestbookEx(Ajax.ResponseDoc.childNodes[0]);
		});
}
System.GuestbookEx=function(Root){
	try{
			var pageSwitch="<div class='bodyer_listcontrol'><select onchange='System.GuestbookPage=this.value;System.Guestbook()'>";
			for(var i=1;i<=parseInt(Root.attributes[1].text);i++)
				pageSwitch+="<option value='"+i+"' "+(parseInt(Root.attributes[0].text)==i?" selected":"")+">"+i+"</option>";
			pageSwitch+="</select></div>";
			Blog.HTML=pageSwitch;
			for(var i=0;i<Root.childNodes.length;i++)
				Blog.HTML+="<div class='SingleComment'><div class='SCTop'><a href='javascript:void(0);' onclick='User.GetUserInfo(this.innerText)'>"+Root.childNodes[i].childNodes[0].text+"</a><span>["+Root.childNodes[i].attributes[0].text+"]</span></div><div class='SCContent'>"+Root.childNodes[i].childNodes[1].text+"</div>"+(Root.childNodes[i].childNodes[2].text!=""?"<div class='SingleCommentAdmin'><div class='SCTop'><strong>回复:</strong>&nbsp;&nbsp;<span>["+Root.childNodes[i].childNodes[2].attributes[0].text+"]</span></div><div class='SCContent'>"+Root.childNodes[i].childNodes[2].text+"</div></div>":"")+"</div>";
	}catch(e){
		Blog.HTML="现在还没有留言.";
	}
	Blog.HTML+="<div id='CMTPostSec'><div class='CMTPostTitle'>发表留言</div><table align='center'><tr><td>名字:</td><td><input id='CPName' type='text' value='"+User.username+"' "+(User.username!=""?"disabled":"")+" /></td></tr><tr><td>验证码:</td><td><input id='CPCode' type='text' maxlength='4' size='5' />"+Interface.GetCode()+"<span style='font-weight:normal'>不区分大小写,长时间停留请刷新验证码</span></td></tr><tr><td valign='top'>内容:</td><td><a href='javascript:void(0)' onclick='CPContent.value+=\"[bold]内容[/bold]\"'><img src='images/ubb/bold.gif' /></a><a href='javascript:void(0)' onclick='CPContent.value+=\"[italic]内容[/italic]\"'><img src='images/ubb/italic.gif' /></a><a href='javascript:void(0)' onclick='CPContent.value+=\"[underline]内容[/underline]\"'><img src='images/ubb/underline.gif' /></a><img src='images/ubb/bar.gif' /><a href='javascript:void(0)' onclick='CPContent.value+=\"[img]地址[/img]\"'><img src='images/ubb/image.gif' /></a><a href='javascript:void(0)' onclick='Interface.listSmiley()'><img src='images/ubb/smiley.gif' /></a><br /><textarea id='CPContent' cols='60' rows='5'></textarea></td></tr><tr><td colspan='2' align='center'><input name='btnPost' type='button' value='发表' class='button' onclick='System.GuestbookPost()' /></td></tr></table></div>";
	System.StyleOut();
	URLManager.SetQueryString("guestbook&page="+System.GuestbookPage);
}
System.GuestbookPost=function(){
	var errList=""
	if(!CPName.value.match(/^(\w|[\u4E00-\u9FA5])*$/))errList+=("<li>用户名只允许为英文，数字和汉字");
	if(CPName.value.length<3 || CPName.value.length>15)errList="<li>名字的长度为3～15";
	if(CPCode.value.length!=4)errList+="<li>验证码为4个字符.";
	if(CPContent.value.length==0)errList+="<li>还没写留言呢！";
	if(errList==""){
		btnPost.disabled=true;
		AjaxUpdater.Update("system.asp?action=postmessage&username="+encodeURIComponent(CPName.value)+"&code="+CPCode.value+"&page=1&content="+encodeURIComponent(CPContent.value),function(){
			if(Ajax.ResponseDoc.childNodes[0].text=="0"){
				Interface.alert("留言发表成功！",2000);
				System.GuestbookEx(Ajax.ResponseDoc.childNodes[1]);
				bodyer_content.scrollIntoView();
			}else{
				Interface.alert(Ajax.ResponseDoc.childNodes[0].text,2000);
			}
			btnPost.disabled=false;
		});
	}else{
		Interface.alert(errList,5000);
	}
}
System.StyleOut=function(){
	bodyer_content.innerHTML=Blog.HTML;
}
/*-------------------------------------------------------------------------------*/
Sidebar={}
Sidebar.Toggle=function(){
	var TargetProperty=event.srcElement.parentElement.childNodes[1].style.display;
	if(TargetProperty!="none")
		TargetProperty="none";
	else
		TargetProperty="block";
	event.srcElement.parentElement.childNodes[1].style.display=TargetProperty;
}
/********************************************************************************/
/*
URLManager Object
*/
URLManager={}
URLManager.SetQueryString=function(qs,to){
	if(to==undefined)to="#";
	location.replace(to);
	location.replace("#"+qs);
}
URLManager.Goto=function(para){
	switch(para[0]){
	case "bid":
		Blog.Display(para[1]);
		break;
	case "guestbook":
		System.Guestbook();
		break;
	case "tags":
		System.ListTags();
		break;
	default:
		Blog.List(para);
	}
}
URLManager.AnalyzeURL=function(QueryString){
	if(location.href.split("#")[0]==location.href){
		URLManager.Goto(["cid",1,1]);
	}else{
		if(QueryString==undefined)QueryString=location.href.split("#")[1];
		if(QueryString.indexOf("default")==-1 && QueryString.indexOf("guestbook")==-1 && QueryString.indexOf("tags")==-1){
			var t=QueryString.split("&");
			if(QueryString.indexOf("bid")==-1){
				URLManager.Goto([t[0].split("=")[0],t[0].split("=")[1],t[1].split("=")[1]]);
			}else
				URLManager.Goto([t[0].split("=")[0],t[0].split("=")[1]]);
		}else{
			if(QueryString.indexOf("default")!=-1){
				URLManager.Goto(["cid",1,QueryString.split("&")[1].split("=")[1]]);
			}else if(QueryString.indexOf("guestbook")!=-1){
				System.GuestbookPage=QueryString.split("&")[1].split("=")[1];
				URLManager.Goto(["guestbook"]);
			}else if(QueryString.indexOf("tags")!=-1){
				URLManager.Goto(["tags"]);
			}
		}
	}
}
URLManager.Test=function(str){
	QueryString=location.href.split("#")[1];
		if(QueryString.indexOf(str)!=-1)
			return true;
		else
			return false;
}
/********************************************************************************/
/*
Key Actions
*/
document.onkeyup=function(){
	if(event.srcElement.tagName!="INPUT" && event.srcElement.tagName!="TEXTAREA"){
		if(URLManager.Test("bid")){
			if(event.shiftLeft && event.keyCode==67){
				Comment.PageTo(1,"intoView");
			}
			if(event.shiftLeft && event.keyCode==84){	
				Blog.GetTrackbacks();
				SBGetOther.scrollIntoView();
			}
			if(event.shiftLeft && event.keyCode==107){
				CMTPostSec.scrollIntoView();
				CPCode.focus();
			}
			if(event.shiftLeft && event.keyCode==27){
				if(System.BackPara!=undefined){
					Interface.alert("正在后退...",1000);
					Blog.List(System.BackPara)
					System.BackPara=null;
				}
			}
		}
	}
}

/********************************************************************************/
/*
Calendar Object
*/
Calendar={}
Calendar.GetCalendar=function(y,m){
	var d=new Date(y,m,1);
	_y=d.getFullYear();
	_m=d.getMonth();
	var space=d.getDay();
	this.Year=d.getFullYear();
	this.Month=d.getMonth();
	var strCalendar="";
	var arrDate=new Array(11);
	arrDate[0]=31;arrDate[2]=31;arrDate[4]=31;arrDate[6]=31;arrDate[7]=31;arrDate[9]=31;arrDate[11]=31;
	arrDate[3]=30;arrDate[5]=30;arrDate[8]=30;arrDate[10]=30;
	if ((_y%400==0) || (_y%4==0 && _y%1000!=0))arrDate[1]=29;else arrDate[1]=28
	strCalendar="<table cellspacing='0' cellpadding='0'><tr><td colspan=7><a href='javascript:void(0)' onclick='Calendar.GetCalendar("+_y+","+(_m-1)+")'>&lt;</a>&nbsp;<input id='inpCalendar' class='year' type='text' value='"+_y+"' onkeyup='Calendar.KeyPress()' />&nbsp;年&nbsp;<input id='inpCalendar' class='month' type='text' value='"+(_m+1)+"' onkeydown='Calendar.KeyPress()' />月&nbsp;<a href='javascript:void(0)' onclick='Calendar.GetCalendar("+_y+","+(_m+1)+")'>&gt;</a></td></tr><tr>";
	strCalendar+="<td width='14%'>Sun</td><td width='14%'>Mon</td><td width='14%'>Tue</td><td width='14%'>Wed</td><td width='14%'>Thu</td><td width='14%'>Fri</td><td width='14%'>Sat</td></tr><tr>";
	for(var i=0;i<space;i++)strCalendar+="<td>&nbsp;</td>";
	for(var i=1;i<=arrDate[_m];i++){
		if((i+space)%7==0)
			strCalendar+="<td><span id='tdDate' attached='false'>"+i+"</span></td></tr><tr>";
		else
			strCalendar+="<td><span id='tdDate' attached='false'>"+i+"</span></td>";
	}
	strCalendar+="</tr></table>";
	CalendarSec.innerHTML=strCalendar;	
	if(!System.FirstTime){
		AjaxUpdater.Update("system.asp?action=calendar&value="+_y+","+(_m+1),function(){		
			Calendar.SetPostDay(Ajax.ResponseDoc.text);
		})
	}
}
Calendar.KeyPress=function(){
	event.keyCode==13?Calendar.GetCalendar(inpCalendar[0].value,parseInt(inpCalendar[1].value)-1):null;
}
Calendar.SetPostDay=function(daylist){
	arrDay=daylist.split(",");
	for(var i=0;i<arrDay.length-1;i++){
			tdDate[arrDay[i]].title=tdDate[arrDay[i]].title==""?1:parseInt(tdDate[arrDay[i]].title)+1;
			tdDate[arrDay[i]].title=tdDate[arrDay[i]].title+"篇日志";
			tdDate[arrDay[i]].className="tdDate";
			if(tdDate[arrDay[i]].attached=="false"){
				tdDate[arrDay[i]].attached="true";
				tdDate[arrDay[i]].attachEvent("onclick",function(){
					Blog.List(["date",Calendar.Year+","+(Calendar.Month+1)+","+parseInt(event.srcElement.innerText),1]);
				});
			}
	}
}
