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){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", ""+cs_path+"index.php/discuss/lists/"+cs_sid+"/"+cs_did+"/"+_pages, true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("cscms_pl").innerHTML = theHttpRequest.responseText;
           } else {
           document.getElementById("cscms_pl").innerHTML = theHttpRequest.responseText;
                  }
           }
     }
}

function pladd(){
	 createXMLHttpRequest();
         var parm="sid=" + cs_sid + "&did=" + cs_did + "&neir=" +getObjValues("cscms_content");//构造URL参数 

         XMLHttpReq.open("POST", cs_path+"index.php/discuss/add/", true);  //调用  
         XMLHttpReq.setRequestHeader("cache-control","no-cache"); 
         XMLHttpReq.setRequestHeader("contentType","text/html;charset=gb2312") //指定发送的编码
         XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");   //设置请求头信息
         XMLHttpReq.onreadystatechange = processResponses;    //判断URL调用的状态值并处理
         XMLHttpReq.send(parm); //设置为发送给服务器数据
}

function processResponses() {
   if (XMLHttpReq.readyState==4){
	 if(XMLHttpReq.status==200){
	           var msg=XMLHttpReq.responseText;
	           if(msg == "Err_000"){
	                     do_alert('参数错误，请联系站长！');setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_100"){
	                     do_alert('您还没有登入，请先登入！');setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_101"){
	                     do_alert('内容不能为空！');setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_102"){
	                     do_alert('内容过长,只能在500个字以内！');setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_103"){
	                     do_alert('您才刚刚已经评论，请休息一下！');setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_104"){
                             document.getElementById('cscms_content').innerText='';
                             getpllist(1,cs_did,cs_sid);
	           } else if(msg == "Err_105"){
	                     do_alert('对不起，留言失败！');setTimeout('close_alert()', 2000);
	           } else {
	                     do_alert(unescape(msg));setTimeout('close_alert()', 2000);
	           }
	 } else {
                   do_alert('您请求的页面出现异常错误！');setTimeout('close_alert()', 2000);
	 }
   }
}

function insertsmilie(sampleText) {
    var txtarea = document.getElementById('cscms_content').value;
    faceadd('biaoqing');
    document.getElementById('cscms_content').value = 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').value = text+txtarea;
}

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'));
};