
function Trim(){
	return this.replace(/\s+$|^\s+/g,"");
}
String.prototype.Trim=Trim;

function getObjValues(id){
	if(getObjects(id).value!=undefined)
		return getObjects(id).value.Trim();
	else
		return "";
}
function getObjects(id) { 	
	if (document.getElementById) { 
		return document.getElementById(id); 
	} else if (document.all) { 
		return document.all[id]; 
	} else if (document.layers) { 
		return document.layers[id]; 
	} 
}


function createXMLHttpRequest(){
       	if (window.XMLHttpRequest) {//wwww.chshcms.com
		XMLHttpReq=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {//IE 浏览器
	     try {
			    XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
	     } catch (e) {
		        try{
					XMLHttpReq=new ActiveXObject("Micrsost.XMLHTTP");
				} catch(e){}
	     }
        }
}
var cache = new Array();
function getHttpObject() {
    var objType = false;
    try {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            objType = new XMLHttpRequest();
        }
    }
    return objType;
}

function gbookadd(usera,addurl){
  var txtcontent = document.getElementById('Content').value;
  if(txtcontent==''){
         document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能为空!</font>";
         return false;
  }
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", addurl+"?neir="+txtcontent+"&usera="+usera+"&random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
               var data=theHttpRequest.responseText;
               if(data=='10001'){ //未登入
                    document.getElementById('gbook_msg').innerHTML="<font color=red>您还没有登入或者已经超时!</font>";
                    location.href = location.href; 
               } else if(data=='10000'){ //对方会员名不能为空
                    document.getElementById('gbook_msg').innerHTML="<font color=red>接收会员名不能为空!</font>";
               } else if(data=='10002'){ //内容不能为空
                    document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能为空!</font>";
               } else if(data=='10003'){ //内容太长
                    document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能不能超过200个字!</font>";
               } else if(data=='10004'){ //间隔时间太短
                    document.getElementById('gbook_msg').innerHTML="<font color=red>休息一下，在来吧!</font>";
               } else if(data=='ok'){ //留言成功
                    location.href = gbooklink; 
               }

           } else {
           document.getElementById('gbook_msg').innerHTML="<font color=red>网络故障，连接失败!</font>";
                  }
           }
     }
}

function gbookhfadd(addurl,usera,id){
  var txtcontent = document.getElementById('hfContent_'+id).value;
  if(txtcontent==''){
         document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能为空!</font>";
         return false;
  }
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", addurl+"?neir="+txtcontent+"&usera="+usera+"&fid="+id+"&random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
               var data=theHttpRequest.responseText;
               if(data=='10001'){ //未登入
                    document.getElementById('gbook_msg').innerHTML="<font color=red>您还没有登入或者已经超时!</font>";
                    location.reload();
               } else if(data=='10000'){ //对方会员名不能为空
                    document.getElementById('gbook_msg').innerHTML="<font color=red>接收会员名不能为空!</font>";
               } else if(data=='10002'){ //内容不能为空
                    document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能为空!</font>";
               } else if(data=='10003'){ //内容太长
                    document.getElementById('gbook_msg').innerHTML="<font color=red>内容不能不能超过200个字!</font>";
               } else if(data=='10004'){ //间隔时间太短
                    document.getElementById('gbook_msg').innerHTML="<font color=red>休息一下，在来吧!</font>";
               } else if(data=='ok'){ //留言成功
                    location.href = gbooklink; 
               }

           } else {
           document.getElementById('gbook_msg').innerHTML="<font color=red>网络故障，连接失败!</font>";
                  }
           }
     }
}

function homegbook(_url){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", _url+"?random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("home_book").innerHTML = theHttpRequest.responseText;
           } else {
           document.getElementById("home_book").innerHTML = "您请求的页面出现异常错误";
                  }
           }
     }
}

function gbookdel(id){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", web_url+"index.php"+uym+"gbookdel?id="+id+"&random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
               var data=theHttpRequest.responseText;
               if(data=='10000'){ //ID为空
                    do_alert('参数错误,ID为空!');setTimeout('close_alert()', 2000);
               } else if(data=='10001'){ //未登入
                    do_alert('您还没有登入或者已经超时!');setTimeout('close_alert()', 2000);
                    location.reload();
               } else if(data=='10002'){ //不是本人数据
                    do_alert('您没有权限删除别人的留言!');setTimeout('close_alert()', 2000);
               } else if(data=='10003'){ //数据不存在
                    do_alert('数据不存在!');setTimeout('close_alert()', 2000);
               } else { //删除成功
                    location.reload();
               }

           } else {
           do_alert('网络故障，连接失败!');setTimeout('close_alert()', 2000);
                  }
           }
     }
}

function Friendadd(type){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", web_url+"index.php"+uym+"friendadd?user="+username+"&type="+type, true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
               var data=theHttpRequest.responseText;
               if(data=='10000'){ //对象为空
                    do_alert('参数错误,对象为空!');setTimeout('close_alert()', 2000);
               } else if(data=='10001'){ //未登入
                    do_alert('您还没有登入或者已经超时!');setTimeout('close_alert()', 2000);
                    location.reload();
               } else if(data=='10003'){ //会员不存在
                    do_alert('对象会员不存在!');setTimeout('close_alert()', 2000);
               } else if(data=='10004'){ //不能关注自己
                    do_alert('不能关注自己!');setTimeout('close_alert()', 2000);
               } else if(data=='10005'){ //已经关注
                      do_alert('已经关注!');setTimeout('close_alert()', 2000);
                     // document.getElementById('friendgz').innerHTML="<a href='###' onclick=\"javascript:Friendadd('qx')\">取消关注</a>";
               } else { //成功
                    if(type=='add'){
                         document.getElementById('friendgz').innerHTML="<a href='###' onclick=\"javascript:Friendadd('qx')\">取消关注</a>";
                    }else{
                         document.getElementById('friendgz').innerHTML="<a href='###' onclick=\"javascript:Friendadd('add')\">+&nbsp;关注</a>";
                    }
               }

           } else {
           do_alert('网络故障，连接失败!');setTimeout('close_alert()', 2000);
                  }
           }
     }
}

function facesinfo(){
    var face=document.getElementById('facelist').style.display;
    if(face=='none'){
         document.getElementById('facelist').style.display='';
    }else{
        document.getElementById('facelist').style.display='none';
    }
}

function gbookhf(_id){
    var bookhf=document.getElementById('textarea_'+_id).style.display;
    if(bookhf=='none'){
         document.getElementById('textarea_'+_id).style.display='';
    }else{
        document.getElementById('textarea_'+_id).style.display='none';
    }
}

function facesadd(text) {
    var txtarea = document.getElementById('Content').value;
    document.getElementById('Content').innerText = txtarea+text;
}


function CSCMS_Login(){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", cscms_loginlink+"?random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("cscms_login").innerHTML = theHttpRequest.responseText;
           } else {
           document.getElementById("cscms_login").innerHTML = "您请求的页面出现异常错误";
                  }
           }
     }
}

function CSCMS_Logadd(){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", cscms_loginaddlink+"?username="+getObjValues("cscms_name")+"&userpass="+getObjValues("cscms_pass")+"&random="+Math.random(), true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
               var data=theHttpRequest.responseText;
               if(data=='10001'){ //用户名为空
                    do_alert('帐号不能为空!');setTimeout('close_alert()', 2000);
               } else if(data=='10002'){ //密码为空
                    do_alert('密码不能为空!');setTimeout('close_alert()', 2000);
               } else if(data=='10003'){ //帐号不存在
                    do_alert('您的帐号不存在!');setTimeout('close_alert()', 2000);
               } else if(data=='10004'){ //密码错误
                    do_alert('您的密码错误!');setTimeout('close_alert()', 2000);
               } else if(data=='10005'){ //帐号被锁定
                    do_alert('您的帐号被锁定!');setTimeout('close_alert()', 2000);
               } else if(data=='10006'){ //登入成功
                    CSCMS_Login();
               } else if(data=='10007'){ //邮件未激活
                    do_alert('您的帐号未激活，请去邮箱激活!');setTimeout('close_alert()', 2000);
               } else { 
                   alert(data);
               }

           } else {
           do_alert('网络故障，连接失败!');setTimeout('close_alert()', 2000);
                  }
           }
     }
}

function CSCMS_Logout(){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", cscms_logoutlink, true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
                  CSCMS_Login();
           } else {
           do_alert('网络故障，连接失败!');setTimeout('close_alert()', 2000);
                  }
           }
     }
}

document.writeln("<style>#alert {display:block; color:#fff;padding-top:9px; width:280px; height:80px;line-height:80px; font-size:14px; padding:1px; background:#000; }</style>");
function do_alert( msg ){
    var n=0;
    x=(document.body.scrollTop||document.documentElement.scrollTop)+n;
    var _height = document.documentElement.clientHeight||document.body.clientHeight;
    var _top = (_height) ? (_height - 39)/2 + x : 0;
    var msgObj=document.createElement('div');
    msgObj.setAttribute('id', 'msgInfo');
    msgObj.setAttribute('align', 'center');
    msgObj.style.position = 'absolute';
    msgObj.style.top = _top + 'px';
    msgObj.style.left = '0';
    msgObj.style.width = '100%';
    msgObj.style.height = '33px';
    msgObj.style.zIndex = '999';
    msgObj.innerHTML = '<span id="alert">'+ msg +'</span>';
    document.body.appendChild(msgObj);
};

function close_alert(){
    document.body.removeChild(document.getElementById('msgInfo'));
};