<!--
String.prototype.replaceAll  = function(s1,s2){       
	return this.replace(new RegExp(s1,"gm"),s2);       
}
String.prototype.toHtml  = function(){
	var strs="";
	strs=this.replaceAll("&amp;","&");
	strs=strs.replaceAll("&","&amp;");
	strs=strs.replaceAll("<","&lt;");
	strs=strs.replaceAll(">","&gt;");
	strs=strs.replaceAll("'","&acute;");			
	strs=strs.replaceAll("\"","&quot;");
	return strs=strs.replaceAll("\n","<br/>");
}

function ajaxSubmit(post_to,data){
	var xmlhttp;
	var responseText = "";
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			xmlhttp = new XMLHttpRequest();					
		}
	}	
	xmlhttp.onreadystatechange = function(){
		if (4==xmlhttp.readyState || 0==xmlhttp.readyState){
			if (200==xmlhttp.status){
				responseText = xmlhttp.responseText;
				addToList(responseText);
			}
		}
	}
	//打开连接，true表示异步提交
	xmlhttp.open("post",post_to, true);
	//当方法为post时需要如下设置http头
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
}

function addToList(data){
	var msg = data.split("$$$");
	if (data.indexOf("Suc")==-1){	
		var sText = "";
		for (var i=0;i<msg.length;i++){
			sText += "\n"+msg[i];
		}
		alert(sText);
		j$("showAjaxMsg").innerHTML = "";
	}
	else{
		var commentlist = j$("commentlist");
				
		if (j$("noComment")){//移除没有评论标识
			commentlist.removeChild(j$("noComment"));
		}
		
		var comment=document.createElement("li");//创建新评论
		var commentHTML = '<cite><img alt="" src="images/gravatar.jpg" class="avatar" height="40" width="40" /><a href="_Email">_Author</a> : <br />';
			commentHTML += '<span class="comment-data">_PostTime</span></cite><div class="comment-text"><p>_Content</p></div>';

		//comment.className = "listp";
		comment.style.backgroundColor = "#EEFFF7";		
		commentlist.appendChild(comment);
		
		var emot="\\[em([0-9]*)\\]";
		var emotImg="<img src=\"images/emot/em$1.gif\" alt=\"em$1\" />";
				
		commentHTML = commentHTML.replaceAll("_Author",msg[2]);
		commentHTML = commentHTML.replaceAll("_PostTime",msg[3]);
		commentHTML = commentHTML.replaceAll("_Content",msg[4].toHtml().replaceAll(emot,emotImg));
		commentHTML = commentHTML.replaceAll("_Email",msg[5]);				
		comment.innerHTML = commentHTML;
		
		j$("showAjaxMsg").innerHTML = '<img src="images/ok.png" alt="" /> <font color="#339900">Thk,你的评论已经成功提交。</font>';
		
		j$("_author").value="";
		j$("_email").value="";
		j$("_content").value="";
		
		ajaxReset();
	}	
}

function ajaxReset(){
	j$("_submit").disabled="";
	j$("_submit").value=" 提 交 ";
	if (j$("postCode")){
		j$("postCode").value = "";
		j$("sysCode").src = "SysCode.jwind" + "?random="+Math.random();
	}
}

function postComment(t){
	var post_url = "AjaxPost.jspx?action=Comment_Post";
	var sid = "id";
	
	j$("_submit").disabled='true';
	j$("_submit").value='正在提交,请稍候...';

	var post=true;
	var id,postCode="",_sex="boy";
	id = j$("id").value;

	var _author = j$("_author").value.trim();
	var _email = j$("_email").value.trim();
	var _content = j$("_content").value.trim();
	var ipAddress = j$("ipAddress").value.trim();
	if (j$("postCode")){
		postCode = j$("postCode").value.trim();		
		if (postCode==''){
			alert("请输入验证码！");
			post=false;
		}
	}
	
	if (_author=='' ){
		alert("请输入你的用户名或昵称！");
		j$("_author").focus();
		post=false;
	}
	else if (_content=='' ){
		alert("请输入评论内容呀，不说话怎么提交？");
		j$("_content").focus();
		post=false;
	}

	if (post){
		j$("showAjaxMsg").innerHTML = '<img src="images/loading.gif" alt="" /> 正在提交数据，请稍后...'
		ajaxSubmit(post_url,"_author="+encodeURIComponent(_author)+"&_sex="+_sex+"&_email="+encodeURIComponent(_email)+"&_content="+encodeURIComponent(_content)+"&ipAddress="+(ipAddress)+"&postCode="+postCode+"&"+sid+"="+id);
	}else
		ajaxReset();	
}

var show=0;
function reloadImage(src){
	j$("sysCode").src = src +"?random="+Math.random();
}

function showSysCode(t){
	if (t==1){
		if (j$("SysCode_div").style.display=="none" && show==0){
			j$("sysCode").src = "SysCode.jwind" + "?random="+Math.random();
			j$("SysCode_div").style.display = "";
			show=1;			
		}
	}	
}

function insert_emot(em){
	if (em != null)	{
		em = "[em"+em+"]";
		j$("Content").value += em;
		j$("Content").focus();
	}
}

function RunCode(objId)  {
	var codeStr=j$(objId).innerText;
	var newwin=window.open('','','');
	newwin.opener = null;
	newwin.document.write(codeStr);
	newwin.document.close();
}
/*运行脚本代码*/
function CopyCode(objId) {
	var codeObj=j$(objId);
	if (document.all){
		var JW_code = document.body.createTextRange();
		JW_code.moveToElementText(codeObj);
		JW_code.scrollIntoView();
		JW_code.select();
		JW_code.execCommand("Copy");
		JW_code.collapse(false);
		alert("代码已经复制到剪切板");
	}else{
		alert("此功能只能在IE上有效\n\n请在用鼠标选择再复制");
	}  
}
//复制代码
function SaveCode(objId) {
	var codeStr=j$(objId).innerText;
	var JW_code = window.open("","_blank","top=10000");
	JW_code.document.open("text/html","replace");
	JW_code.document.write(codeStr);
	JW_code.document.execCommand("saveas","","JW_code.htm");
	JW_code.close();
}
//另存为代码
//-->
