function AJAXRequest(n){var r=[],p=this,c=AJAXRequest.__pool__||(AJAXRequest.__pool__=[]);(function(v){var u=function(){};v=v?v:{};var w=["url","content","method","async","encode","timeout","ontimeout","onrequeststart","onrequestend","oncomplete","onexception"];var s=["","","GET",true,k("UTF-8"),3600000,u,u,u,u,u];var t=w.length;while(t--){p[w[t]]=h(v[w[t]],s[t])}if(!l()){return false}})(n);function h(s,t){return s!=undefined?s:t}function l(){var v,s=[window.XMLHttpRequest,"MSXML2.XMLHTTP","Microsoft.XMLHTTP"];var t;for(t=0;t<c.length;t+=1){if(c[t].readyState===0||c[t].readyState===4){return c[t]}}for(t=0;t<s.length;t+=1){try{v=(s[t]&&typeof(s[t])=="function"?new s[t]:new ActiveXObject(s[t]));break}catch(u){v=false;continue}}if(!v){throw"Cannot init XMLHttpRequest object!"}else{c[c.length]=v;return v}}function d(s){return document.getElementById(s)}function m(s){var t=s*1;return(isNaN(t)?0:t)}function b(s){return(typeof(s)=="string"?(s=d(s))?s:false:s)}function o(){return((new Date)*1)}function e(t,s){r[t+""]=s}function i(s){return(r[s+""])}function f(u,s,v){return(function t(x){x=u(x);for(var w=0,y=s.length;w<y;w+=1){x=x.replace(s[w],v[w])}return(x)})}function k(s){if(s.toUpperCase()=="UTF-8"){return(encodeURIComponent)}else{return(f(escape,[/\+/g],["%2B"]))}}function a(u,s){if(!u.nodeName){return}var v="|"+u.nodeName.toUpperCase()+"|";if("|INPUT|TEXTAREA|OPTION|".indexOf(v)>-1){u.value=s}else{try{u.innerHTML=s}catch(t){}}}function q(s){if(typeof(s)=="function"){return s}else{s=b(s);if(s){return(function(t){a(s,t.responseText)})}else{return p.oncomplete}}}function j(s,x,u){var t=0,w=[];while(t<s.length){w[t]=s[t]?(u[t]?u[t](s[t]):s[t]):x[t];t+=1}while(t<x.length){w[t]=x[t];t+=1}return w}function g(){var z,C=false,E=l();var v=j(arguments,[p.url,p.content,p.oncomplete,p.method,p.async,null],[null,null,q,null,null,null]);var u=v[0],A=v[1],D=v[2],t=v[3],x=v[4],w=v[5];var y=t.toUpperCase()=="POST"?true:false;if(!u){throw"url is null"}var B={url:encodeURI(u),content:A,method:t,params:w};if(!y){u+=(u.indexOf("?")>-1?"&":"?")+"timestamp="+o()}E.open(t,u,x);p.onrequeststart(B);if(y){E.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}E.setRequestHeader("X-Request-With","XMLHttpRequest");z=setTimeout(function(){C=true;E.abort()},p.timeout);var s=function(){if(C){p.ontimeout(B);p.onrequestend(B)}else{if(E.readyState==4){clearTimeout(z);B.status=E.status;try{if(E.status==200){setTimeout(function(){D(E,w)},0)}else{p.onexception(B)}}catch(F){p.onexception(B)}p.onrequestend(B)}}};E.onreadystatechange=s;if(y){E.send(A)}else{E.send("")}if(x===false){s()}return true}this.setcharset=function(s){p.encode=k(s)};this.get=function(t,u,s){return g(t,"",u,"GET",p.async,s)};this.update=function(z,w,u,y,s){u=m(u);y=m(y);if(u<1){y=1}else{if(y<1){y=Number.POSITIVE_INFINITY}}var t=function(){g(w,"",z,"GET",p.async,s)};var v=o();var x=function(A){t();A--;if(A>0){e(v,setTimeout(function(){x(A)},u))}};x(y);return v};this.stopupdate=function(s){clearTimeout(i(s))};this.post=function(t,u,v,s){return g(t,u,v,"POST",p.async,s)};this.postf=function(z,E,w){var v=[],y,C,D,B,x,F=arguments.length,u=arguments;z=z?b(z):false;if(!z||z.nodeName!="FORM"){return false}validfoo=z.getAttribute("onvalidate");validfoo=validfoo?(typeof(validfoo)=="string"?new Function(validfoo):validfoo):null;if(validfoo&&!validfoo()){return false}var t=z.getAttribute("action"),s=z.getAttribute("method");var A=p.formToStr(z);if(A.length===0){return false}if(s.toUpperCase()=="POST"){return g(t,A,E,"POST",true,w)}else{t+=(t.indexOf("?")>-1?"&":"?")+A;return g(t,"",E,"GET",true,w)}};this.formToStr=function(z){var u="",y="",t=z.elements,v,A;for(var x=0;x<t.length;++x){v=t[x];if(v.name!==""){A=undefined;switch(v.type){case"select-one":if(v.selectedIndex>-1){A=v.options[v.selectedIndex].value}else{A=""}break;case"select-multiple":var s=v.options;for(var w=0;w<s.length;++w){if(s[w].selected){u+=y+v.name+"="+p.encode(s[w].value);y="&"}}break;case"checkbox":case"radio":if(v.checked){A=v.value}break;default:A=v.value;break}if(A!=undefined){A=p.encode(A);u+=y+v.name+"="+A;y="&"}}}return u}};

// current
function getCookie(c_name) {// getcookie
	if (document.cookie.length > 0){
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1){
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1){
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null
}

function setCookie(c_name,value,expiredays) {// setcookie
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());// add "toGMTString()" for right time
}

function getbyid(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	} else {
		return null;
	}
}

function getPop(e,s,o,w) {// e 无效参数
	if (getbyid(o)) {document.body.removeChild(getbyid(o));}
	var divElement = document.createElement("DIV");
	document.body.appendChild(divElement);
	divElement.id = o;
	divElement.className = "";
	divElement.style.cssText = "position:absolute;z-index:11;border:3px solid #ccc;background:#fcfcfc;padding:12px;width:"+w+"px;";
	var userAgent = navigator.userAgent.toLowerCase();
	var is_opera = (userAgent.indexOf('opera') != -1);
	var clientHeight = scrollTop = 0; 
	if(is_opera) {
		clientHeight = document.body.clientHeight /2;
		scrollTop = document.body.scrollTop;
	} else {
		clientHeight = document.documentElement.clientHeight /2;
		scrollTop = document.documentElement.scrollTop;
	}
	divElement.innerHTML = s;
	divElement.style.left = (document.documentElement.clientWidth /2 +document.documentElement.scrollLeft - w/2)+"px";
	divElement.style.top = (clientHeight +　scrollTop - divElement.clientHeight/2)+"px";
}

function getTip(e,s,o,w) {
	if (getbyid(o)) {document.body.removeChild(getbyid(o));}
	var divElement = document.createElement("DIV");
	document.body.appendChild(divElement);
	divElement.id = o;
	divElement.className = "";
	divElement.style.cssText = "position:absolute;z-index:11;border:3px solid #ccc;background:#fcfcfc;padding:12px;width:"+w+"px;";
	divElement.innerHTML = s;
	var offX = 4; offY = 4; width = 0; height = 0; scrollX = 0; scrollY = 0; x = 0; y = 0;
	if (window.innerWidth) width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		width = document.body.clientWidth;
	if (window.innerHeight) height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		height = document.body.clientHeight;
	if (typeof window.pageXOffset == "number") scrollX = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scrollX = document.body.scrollLeft; 
	else if (window.scrollX) scrollX = window.scrollX;
	if (typeof window.pageYOffset == "number") scrollY = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scrollY = document.body.scrollTop; 
	else if (window.scrollY) scrollY = window.scrollY;
	x=e.pageX?e.pageX:e.clientX+scrollX;
	y=e.pageY?e.pageY:e.clientY+scrollY;
	if(x+divElement.offsetWidth+offX>width+scrollX){
		x=x-divElement.offsetWidth-offX;
		if(x<0)x=0;
	}else x=x+offX;
	if(y+divElement.offsetHeight+offY>height+scrollY){
		y=y-divElement.offsetHeight-offY;
		if(y<scrollY)y=height+scrollY-divElement.offsetHeight;
	}else y=y+offY;
	divElement.style.left = x+"px";
	divElement.style.top = y+"px";
}

function remove(div){ document.body.removeChild(getbyid(div)); }

function showmask(){// no use
	if (getbyid("mask")) {document.body.removeChild(getbyid("mask"));}
	var divElement=document.createElement("DIV");
	document.body.appendChild(divElement);
	divElement.id="mask";
	divElement.style.cssText="position:absolute;z-index:10;left:0px;top:0px;background:#000;filter:Alpha(opacity=60);opacity:0.6";
	divElement.style.width=document.documentElement.scrollWidth+"px";
	divElement.style.height=document.documentElement.scrollHeight+"px";
}

function postDigg(event,ftype,aid) {// for digg
	var saveid = getCookie('diggid');
	if(saveid != null){
		var saveids = saveid.split(',');
		var hasid = false;
		saveid = '';
		j = 1;
		for(i=saveids.length-1;i>=0;i--){
			if(saveids[i]==aid && hasid) continue;
			else {
				if(saveids[i]==aid && !hasid) hasid = true;
				saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
				j++;
				if((j==20 && hasid)||(j==19 && !hasid)) { getTip(event,'请不要一次表态太多','ckalert',''); setTimeout('getbyid("ckalert").style.display="none";',1000); return; };//j==20 j==19 id数量，超出无效
			}
		}
		if(hasid) { getTip(event,'您已经表过态了','diggalert',''); setTimeout('getbyid("diggalert").style.display="none";',1000); return; }
		else saveid += ','+aid;
		setCookie('diggid',saveid,1);
	}else{
		setCookie('diggid',aid,1);
	}

	getTip(event,'正在表态','diggpop','');
	var ajax=new AJAXRequest;
	ajax.get("ajax_digg.asp?act="+ftype+"&id="+aid,
    function (obj){getbyid('newdigg').innerHTML=obj.responseText; getbyid('diggpop').innerHTML='参与表态完成了'; setTimeout('document.body.removeChild(getbyid("diggpop"));',1000); });

}

function relative(tags,pages) {// for articles.asp relative articles
	var ajax=new AJAXRequest;
	ajax.get("ajax_relative.asp?tags="+tags+"&page="+pages,
    function (obj){getbyid('articles').innerHTML=obj.responseText;});
}

function tagsPop(event, div, url) {// for articles.asp tagspop
	if (getbyid(div)) {getbyid(div).parentNode.removeChild(getbyid(div));}
	getPop(event,'加载中...',div,'360');
	var ajax=new AJAXRequest;
	ajax.get(url, function (obj){getbyid(div).innerHTML='<span style=\"float:right;font-weight:bold;cursor:pointer;padding:12px;font-size:10px;\" onclick=\"remove(\''+div+'\');\">Close</span>';getbyid(div).innerHTML+=obj.responseText;
	});	
}

function tagsTip(event, div, url) {// for tags.asp tagstip
	if (getbyid(div)) {getbyid(div).parentNode.removeChild(getbyid(div));}
	getTip(event,'加载中...',div,'360');
	var ajax=new AJAXRequest;
	ajax.get(url, function (obj){getbyid(div).innerHTML='<span style=\"float:right;font-weight:bold;cursor:pointer;padding:12px;font-size:10px;\" onclick=\"remove(\''+div+'\');\">Close</span>';getbyid(div).innerHTML+=obj.responseText;});
}

function loginer(form) {// for login
	getbyid('logining').innerHTML="<div style='width:100%;height:100%;background:url(styles/index/loading.gif) 50% 50% no-repeat'></div>";
	var ajax=new AJAXRequest;
	ajax.postf(form,
    function (obj){
		if(obj.responseText.indexOf("h5")>0){
			getbyid('panelUser').innerHTML=obj.responseText;
			getbyid('logoutli').style.display="";
			getbyid('loginli').style.display="none";
		}else{
			getbyid('logining').innerHTML=obj.responseText;
		}
	});
}

function logouter() {// for logout
	getbyid('logining').innerHTML="<div style='width:100%;height:100%;background:url(styles/index/loading.gif) 50% 50% no-repeat'></div>";
	var ajax=new AJAXRequest;
	ajax.get("ajax_login.asp?act=logout",
    function (obj){
		if(obj.responseText.indexOf("h5")>0){
			getbyid('panelUser').innerHTML=obj.responseText;
			getbyid('loginli').style.display="";
			getbyid('logoutli').style.display="none";
		}else{
			getbyid('logining').innerHTML=obj.responseText;
		}
	});
}