function ajax()
{
	var C=null;
	try{
		C=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			C=new ActiveXObject("Microsoft.XMLHTTP");
		}catch(sc){
			C=null;
		}
	}
	if(!C&&typeof XMLHttpRequest!="undefined"){
		C=new XMLHttpRequest();
	}
	return C;
}



function logthis(obj) {
   var msg;
   url = './?action=goto&go='+obj.href;
       var l = ajax();
		l.open("POST",url,true);
		//alert(url);
		l.onreadystatechange=function(){
			if(l.readyState==4&&l.responseText){
				msg = l.responseText;
			}
		}
		l.setRequestHeader("If-Modified-Since","0");

		l.send(null);
    }
function ajax_get(url,obj1){
	var msg;
	if (url.trim() != '')
	{
		var l = ajax();
		l.open("POST",url,true);
		//alert(url);
		l.onreadystatechange=function(){
			//if(l.readyState==1)msg="更新中.";
			//if(l.readyState==2)msg="更新中..";
			if(l.readyState<=3)msg="<img src='images/load.gif' border=0>";
			if(l.readyState==4&&l.responseText){
				msg = l.responseText;
			}
			obj1.innerHTML=msg;
		}
		l.setRequestHeader("If-Modified-Since","0");
		//l.setRequestHeader('content-type:text/html;charset=utf-8');
		l.send(null);
	}
	else{
		msg='';
	}
}

function chskin(tpl) {
    var url = './?action=skin&style=' + tpl;
    var l = ajax();
    l.open("get",url,true);
    l.onreadystatechange=function(){
        if(l.readyState==4){
            window.location.reload(); 
        }
    }

    l.setRequestHeader("If-Modified-Since","0");
    l.send(null);
}

function getpr(idx) {
    
	var _msg = '';;
    var url = './tool.php?url=' + encodeURIComponent(getid('url_' + idx).href);
    var _parent = getid('td_' + idx);
    if (url.trim() != '')
	{
		var l = ajax();
		l.open("get",url,true);
		l.onreadystatechange=function(){
			if(l.readyState<=3)_msg="<img src='/images/load.gif' border=0>";
			if(l.readyState==4&&l.responseText){
				_msg = l.responseText;
			}
            _parent.innerHTML = _msg;
		}
        
		l.setRequestHeader("If-Modified-Since","0");
		l.send(null);
	}
	else{
		_msg='';
	}
}

function get_pr(obj) {
    
	var _msg = '';
    if (obj.value.trim() == '' || obj.value.trim() == 'http://') {
        return;
    }

    var url = './tool.php?url=' + encodeURIComponent(obj.value.trim());
    var info = getid('info');
    if (url.trim() != '')
	{
		var l = ajax();
		l.open("get",url,true);
		l.onreadystatechange=function(){
			if(l.readyState<=3)_msg="<img src='/images/load.gif' border=0>";
			if(l.readyState==4&&l.responseText){
				_msg = 'PR=' + l.responseText;
			}
            info.innerHTML = _msg;
		}
        
		l.setRequestHeader("If-Modified-Since","0");
		l.send(null);
	}
	else{
		_msg='';
	}
}

String.prototype.trim= function() //去空格函数
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function getid(id){
	return document.getElementById(id);
}
function get_name(name){
	return document.getElementsByName(name);
}
function gettagname(tagname){
	return document.getElementsByTagName(name);
}
function ajax_getcity(obj2){
	ajax_get("index.php?action=ajax&do=getcity&areacode="+obj2,getid('selcity'));
}
function ajax_checkuser(a){
	getid('userstatus').innerHTML="";
	if(a.trim()!=''){
		if(a.length<6)getid('userstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>用户名长度必须6个字符以上</font>";
		else if(!RegExp("^[A-Za-z0-9]+$","i").test(a)){
			getid('userstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>用户名不合法，只能由字母数字下划线组成</font>";
		}
		else{
			var res=ajax_get("index.php?action=ajax&do=checkuser&username="+a,getid('userstatus'));
		}
	}
}
function checkpassword(a){
	getid('f2').innerHTML="";
	if(a!='')
	if(a.length<6)getid('f2').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>密码长度必须6个字符以上</font>";
	else getid('f2').innerHTML="<img src='images/check_right.gif'>";
}
function checkrepassword(){
	getid('f3').innerHTML="";
	var a=form1.password.value;
	var b=form1.repassword.value;
	if(b!='')
	if(b.length<6)getid('f3').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>密码长度必须6个字符以上</font>";
	else if(a!==b)getid('f3').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>两次输入密码不一致</font>";
	else getid('f3').innerHTML="<img src='images/check_right.gif'>";
}
function checkquesiton(a){
	getid('f4').innerHTML="";
	if(a.trim()!='')getid('f4').innerHTML="<img src='images/check_right.gif'>";
	else getid('f4').innerHTML="";
}
function checkanswer(a){
	getid('f5').innerHTML="";
	if(a.trim()!='')getid('f5').innerHTML="<img src='images/check_right.gif'>";
	else getid('f5').innerHTML="";
}
function checkemail(a){
	getid('f6').innerHTML="";
	if(a.trim()!=''){
		var re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(!a.match(re)){
			getid('f6').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>邮件地址格式不正确</font>";
		}
		else{
			var res=ajax_get("index.php?action=ajax&do=checkemail&email="+a,getid('f6'));
		}
	}
}
function ajax_checkhost(a){
	getid('hoststatus').innerHTML="";
	if(a.trim()!=''){
		var res=ajax_get("index.php?action=ajax&do=checkhost&idcname="+a,getid('hoststatus'));
	}
	else getid('hoststatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>主机商名称不能为空</font>";

}
function checkhostemail(a){
	getid('hostemailstatus').innerHTML="";
	if(a.trim()!=''){
		var re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(!a.match(re)){
			getid('hostemailstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>邮件地址格式不正确</font>";
		}
		else{
			var res=ajax_get("index.php?action=ajax&do=checkhostemail&email="+a,getid('hostemailstatus'));
		}
	}else getid('hostemailstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>邮件地址不能为空</font>";
}
function checkidcurl(a){
	getid('idcurlstatus').innerHTML="";
	if(a.trim()!=''){
		var re=/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
		if(!a.match(re)){
			getid('idcurlstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>URL地址格式不正确</font>";
		}
		else{
			var res=ajax_get("index.php?action=ajax&do=checkidcurl&idcurl="+a,getid('idcurlstatus'));
		}
	}else getid('idcurlstatus').innerHTML="<img src='images/check_error.gif'>&nbsp;<font color='red'>URL地址不能为空</font>";
}
function gourl(url){
	window.location.href=url;
}
function goback(){
	history.back(-1);
}
function checksinput(){
	var res=true;
	var msg=new Array(7);
	var resmsg='';
	for(var i=0;i<msg.length;i++)msg[i]='';
	if(document.form1.content.value.trim()==''){
		res=false;
		msg[0]="请输入昵称\n";
	}
	if(document.form1.proj1.value==0){
		res=false;
		msg[1]="请给访问速度评分\n";
	}
	if(document.form1.proj2.value==0){
		res=false;
		msg[2]="请给性价比评分\n";
	}
	if(document.form1.proj3.value==0){
		res=false;
		msg[3]="请给服务质量评分\n";
	}
	if(document.form1.proj4.value==0){
		res=false;
		msg[4]="请给安全性评分\n";
	}
	if(document.form1.title.value.trim()==''){
		res=false;
		msg[5]="请输入标题\n";
	}
	if(document.form1.content.value.trim()==''){
		res=false;
		msg[6]="请输入内容\n";
	}
	var j=1;
	for(var i=0;i<msg.length;i++){
		if(msg[i]!=''){
			resmsg+=j+'.'+msg[i];
			j++;
		}
	}
	if(resmsg!='')alert(resmsg);
	return res;
}
function guest(){
	if(document.form1.guestpost.checked==true){
		document.form1.usrname.value="匿名";
	}else{
		document.form1.usrname.value="";
	}
}

function enjoy() {

}

function edit(pid, syncode) {
	var http = ajax();	
	http.open('GET', './?action=admin&do=getinfo&pid=' + pid + '&syncode=' + syncode);
	http.onreadystatechange=function(){
		if(http.readyState==4&&http.responseText) {
			var info = http.responseText;
			try {
				eval('info=' + info);
			} catch(e) {
				alert('获取信息失败');
				return;
			}
			
			if (info.res == 0) {
				alert('获取信息失败');
				return;
			}
			
			var pop = new popWindow();
			pop.create(400, 300);
			var html = '<form name="editform"><table border=0 style="line-height:25px;">';
			html += '<tr><td align=right width=80px;>管理密码：</td><td><input name="password" type="password" value=""></td></tr>';
			html += '<tr><td align=right>昵称：</td><td><input name="nickname" type="text" value=""></td></tr>';
			html += '<tr><td align=right>标题：</td><td><input name="title" type="text" value=""></td></tr>';
			html += '<tr><td align=right>评分：</td><td>速度<select name="s1"></select> 性价比<select name="s2"></select> 服务<select name="s3"></select> 安全性<select name="s4"></select> </td></tr>';
			html += '<tr><td align=right>内容：</td><td><textarea name="content" style="width:280px;height:80px;"></textarea></td></tr>';
			html += '<tr><td align="center" colspan="2" width=100%><input type="submit" value=" 确 定 " style="height:28px;"></td></tr>';
			html += '</table>';
			pop.setHtml('编辑评论', html);

			var f = document['editform'];
			info = info.data;
			f.nickname.value = info.author;
			f.title.value = info.title;
			f.content.value = info.content;
			
			function setSelect (obj, selectValue) {
				var op;
				for (var i=1; i<=5; i++) {
					op = document.createElement('OPTION');
					op.value = i;
					op.text = i;
					if (i == selectValue) {
						op.selected = true;
					}

					if (document.all) {
						obj.add(op);
					} else {
						obj.add(op, null);
					}
				}
			}

			setSelect(f.s1, info.proj1);
			setSelect(f.s2, info.proj2);
			setSelect(f.s3, info.proj3);
			setSelect(f.s4, info.proj4);

			f.onsubmit = function() {
				if (f.password.value == '') {
					alert('请输入管理密码');
					return false;
				}

				if (f.title.value == '' || f.content.value == '') {
					alert('标题或内容不能为空');
					return false;
				}

				var newinfo = '';
				newinfo = 'password=' + encodeURIComponent(f.password.value);
				newinfo += '&title=' + encodeURIComponent(f.title.value);
				newinfo += '&content=' + encodeURIComponent(f.content.value);
				newinfo += '&proj1=' + encodeURIComponent(f.s1.options[f.s1.options.selectedIndex].value);
				newinfo += '&proj2=' + encodeURIComponent(f.s2.options[f.s2.options.selectedIndex].value);
				newinfo += '&proj3=' + encodeURIComponent(f.s3.options[f.s3.options.selectedIndex].value);
				newinfo += '&proj4=' + encodeURIComponent(f.s4.options[f.s4.options.selectedIndex].value);
				var l = ajax();	
				l.open('GET', './?action=admin&do=updateinfo&pid=' + pid + '&syncode=' + syncode+ '&' + newinfo);
				l.onreadystatechange=function(){
					if(l.readyState==4&&l.responseText) {

						var res = l.responseText;
						try {
							eval('res=' + res);
						} catch(e) {
							alert('更新信息失败');
							return;
						}

						if (res.res == 0) {
							if (res.error != '') {
								alert(res.error);
							} else {
								alert('更新信息失败');
							}
							return false;
						}

						alert('更新信息成功，页面重新加载..');
						window.location.reload(true);
						return false;
					}
				}
				l.send(null);
				return false;
			}
		}
	}

	http.send(null);
}

function popWindow()
{
	this.width = 400;
	this.height = 300;
	this.name = 'pop';
	this.divObj = null;
	this.divBackground = null;
	__this = this;

	this.create = function(w, h)
	{
		this.width = w ? w : this.width;
		this.height = h ? h : this.height;
		this.divObj = document.createElement('DIV');
		this.divObj.id = this.name + (new Date()).getTime();
		this.divObj.style.border = "1px solid #cad9ea";
		this.divObj.style.width = this.width + 'px';
		this.divObj.style.height = this.height + 'px';
		this.divObj.style.position = 'absolute';
		document.body.appendChild(this.divObj);
		this.divObj.style.left = (document.documentElement.clientWidth-this.divObj.offsetWidth)/2  + document.documentElement.scrollLeft+ 'px';
		this.divObj.style.top = (document.documentElement.clientHeight-this.divObj.offsetHeight)/2 + document.documentElement.scrollTop + 'px';
		if (!window._index) {
			window._index = 1000;
		}

		this.divObj.style.zIndex = window._index + 2;
		
		this.divBackground = document.createElement('DIV');
		this.divBackground.id = this.divObj.id  + '_2';
		this.divBackground.style.position = 'absolute';
		document.body.appendChild(this.divBackground);
		//this.divBackground.style.width = document.documentElement.scrollWidth + 'px';
		this.divBackground.style.width = '100%';
		
		this.divBackground.style.height = document.documentElement.scrollHeight + 'px';
		this.divBackground.style.top = 0;
		this.divBackground.style.left = 0;
		this.divBackground.style.background = '#333333';
		this.divBackground.style.zIndex = window._index + 1;
		if (!document.all) {
			this.divBackground.style.opacity = 0.4;
		} else {
			this.divBackground.style.filter = "alpha(opacity=40)";
		}

		window._index = window._index + 2;
	}

	this.setHtml = function(title, html)
	{
		this.divObj.innerHTML = "<div style='width:100%;height:30px;line-height:30px;background:#f1f7fb'><span style='font-size:14px;padding-left:5px;font-weight: bold;float:left;'>" + title 
			+ "</span><span style='float:right;font-size:12px;cursor:pointer;padding-right:5px;'>关闭</span></div>" +
			"<div style='width:100%;height:" + (this.height-30) + "px;overflow:auto;background:#ffffff;'><div style='margin:5px;'>" + html + "</div></div>";
		this.divObj.childNodes[0].childNodes[1].onclick = function() {__this.close()};
	}

	this.close = function()
	{
		document.body.removeChild(this.divObj);
		document.body.removeChild(this.divBackground);
	}
}
