var DomainUrl = top.location.hostname;
var AuthUrl = top.location.hostname;

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 getbooklist(_pages){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", ""+cs_path+"public/gbook.php?pages="+_pages, true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("csdjcms_book").innerHTML = theHttpRequest.responseText;
           } else {
           document.getElementById("csdjcms_book").innerHTML = "您请求的页面出现异常错误";
                  }
           }
     }
}

function bookadd(){
	 createXMLHttpRequest();
	 XMLHttpReq.open("GET", ""+cs_path+"public/gbook.php?ac=add&name=" + getObjValues("names") + "&content=" +getObjValues("content"),true);
	 XMLHttpReq.onreadystatechange= processResponsee;
	 XMLHttpReq.send(null);
	 }

function processResponsee() {
   if (XMLHttpReq.readyState==4){
	 if(XMLHttpReq.status==200){
	           var msg=XMLHttpReq.responseText;
	           if(msg == "Err_000"){
	                     alert('站长已经关闭留言！');
	           } else if(msg == "Err_100"){
	                     alert('网名不允许为空！');
	           } else if(msg == "Err_101"){
	                     alert('用户名过长,只能在20个字以内！');
	           } else if(msg == "Err_102"){
	                     alert('内容不能为空！');
	           } else if(msg == "Err_103"){
	                     alert('内容过长,只能在200个字以内！！');
	           } else if(msg == "Err_104"){
	                     alert('您刚刚留过言，请休息一下！');
	           } else if(msg == "Err_105"){
                             document.getElementById('content').innerText='';
                             getbooklist(1);
	           } else if(msg == "Err_106"){
	                     alert('对不起，留言失败！');
	           } else {
	                     alert(msg);
	           }
	 } else {
                   alert('您请求的页面出现异常错误！');
	 }
   }
}


