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

function pladd(){
	 createXMLHttpRequest();
	 XMLHttpReq.open("GET", ""+cs_path+"public/pl.php?ac=add&did=" + getObjValues("did") + "&sid=" + getObjValues("sid") + "&content=" +getObjValues("cscms_content"),true);
	 XMLHttpReq.onreadystatechange= processResponses;
	 XMLHttpReq.send(null);
	 }

function processResponses() {
   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('内容不能为空！');
	           } else if(msg == "Err_102"){
	                     alert('内容过长,只能在200个字以内！');
	           } else if(msg == "Err_103"){
	                     alert('您才刚刚已经评论，请休息一下！');
	           } else if(msg == "Err_104"){
                             document.getElementById('cscms_content').innerText='';
                             getpllist(1,cs_did,cs_sid);
	           } else if(msg == "Err_105"){
	                     alert('对不起，留言失败！');
	           } else {
	                     alert(unescape(msg));
	           }
	 } else {
                   alert('您请求的页面出现异常错误！');
	 }
   }
}

function insertsmilie(sampleText) {
    var txtarea = document.getElementById('cscms_content').value;
    faceadd('biaoqing');
    document.getElementById('cscms_content').innerText = txtarea+sampleText;

}

function faceadd(s) {
    if (document.getElementById(s).style.display == 'none') {
        document.getElementById(s).style.display = 'block'
        document.getElementById('faces').innerHTML = '关闭表情';
    } else if (document.getElementById(s).style.display == 'block') {
        document.getElementById(s).style.display = 'none'
        document.getElementById('faces').innerHTML = '插入表情';
    }
}

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