var PL_xml_Http;
var pinglun_a_h;
var Pl_numb_x=200
pinglun_a_h="&bdcolor="+pinglun_border_color+"&alink="+pinglun_alink_color+"&numb="+pinglun_numb+"&bgcolor="+pinglun_bg_color
function PL_cx_hr()
{
	if (window.ActiveXObject)
	{
		PL_xml_Http=new ActiveXObject("Microsoft.XMLHTTP");		
	}
	else if (window.XMLHttpRequest)
	{
		PL_xml_Http=new XMLHttpRequest();		
	}	
}

function insertface(smileface)
{
	$("n_content").value+=smileface;
}
function $(o){
	return document.getElementById(o)
}
function textCounter(sElement,maxlimit,o) { 
	field = sElement;
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit); 
		
	} else{
		
		$(o).innerHTML = "字数还剩"+(maxlimit - field.value.length)+"字";
	}
	if (field.value.length == maxlimit){
		alert("请将字符限制在"+maxlimit+"个以内");
	}
}

function newverifypic()
{
	var timenow = new Date().getTime();
	url=pinglun_dir+"p_inc/pinglun/code.asp";
	url=url+"?"+timenow;
	//document.getElementById("verifypic").src=url;
}


function bytes(str){
	if(typeof(str)!='string'){
		str = str.value;
	}
	var len = 0;
	for(var i = 0; i < str.length; i++){
		if(str.charCodeAt(i) > 127){
			len++;
		}
		len++;
	}
	return len;
}
function chkstr(str){
	if(typeof(str)!='string'){
		str = str.value;
	}
	for(var i = 0; i < str.length; i++){
		if (str.charCodeAt(i) < 127 && !str.substr(i,1).match(/^\w+$/ig)){
			return false;
		}
	}
	return true;
}
function setCookie(name, value) {
    var expdate = new Date();
    var argv = setCookie.arguments;//获得数组
    var argc = setCookie.arguments.length;//获得数组的长度
    var expires = (argc > 2) ? argv[2] : 1;//可伸长变量
    var path = (argc > 3) ? argv[3] : "/";
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null){
        expdate.setTime(expdate.getTime() + ( expires*24*60*60*1000 )); //把传过来得变量变成天数
	}
    document.cookie = name + "=" + escape (value)
    +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path))
    +((domain == null) ? "" : ("; domain=" + domain))
    +((secure == true) ? "; secure" : "");
} 

function qingtiandy_gbook_n_t(){

var Flag=false;
var u=$("n_name").value;
var u1=$("n_name_1");
var c=$("n_content");
var c1=$("n_content_1");

	if (u=="")
		u1.innerHTML="<font color=red>请填写您的昵称！</font>";
	else if (bytes(u) > 14)
		u1.innerHTML="<font color=red>您的昵称最长不得超过7个汉字，或14个字节(数字，字母和下划线)！</font>";
	else if (!chkstr(u))
		u1.innerHTML="<font color=red>您的昵称仅可使用汉字、数字、字母和下划线！</font>";
	else if (bytes(c.value)<1)
		c1.innerHTML="<font color=red>您评论的内容不能为空！</font>";	
	//else if (bytes($("verifycodenext").value)!=4)
	//	c1.innerHTML="<font color=red>验证码有误！</font>";		
	else if (bytes(c) > Pl_numb_x)
		c1.innerHTML="<font color=red>您评论的内容不能超过"+Pl_numb_x+"个字节！</font>";	
	else {
		u1.innerHTML="";
		Flag=true;
	}
	return Flag;

}

function qingtiandy_gbook_t(id)
{
	
//if ($("n_name").value!=""){
	if(qingtiandy_gbook_n_t()){
		$("b_b").disabled="true";	
		PL_cx_hr();
		
		var url=pinglun_dir+"p_inc/pinglun/save.asp";
		var t_post="n_name="+escape(document.getElementById("n_name").value)+"&n_content="+escape(document.getElementById("n_content").value)+"&t_id="+escape(id)+pinglun_a_h;
		PL_xml_Http.open("POST",url,true);
		PL_xml_Http.onreadystatechange=gbook_hsc_read_ok;
		PL_xml_Http.setRequestHeader("Content-Length",t_post.length);
		PL_xml_Http.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		PL_xml_Http.send(t_post);
	}
//}
}
function gbook_hsc_read_ok()
{
	if(PL_xml_Http.readyState==4)
	{	
		if (PL_xml_Http.status==200)
		{
			$("gbook_book").innerHTML=PL_xml_Http.responseText;
			
			$("b_b").disabled=false;
			//$("n_name").value=""
			$("n_content").value=""
			newverifypic();
			setCookie("q_i_n_g_t_i_a_n_d_y",$("n_name").value);
			$("n_content_1").innerHTML = "评论字数还剩"+Pl_numb_x+"字";
		}
	}
}

function qingtiandy_gbook_x(id)
{
	$("gbook_book").innerHTML="正在加载......";
	PL_cx_hr();	
	var url=pinglun_dir+"p_inc/pinglun/save.asp";
	var t_post="t_id="+id+pinglun_a_h;
	PL_xml_Http.open("POST",url,true);
	PL_xml_Http.onreadystatechange=gbook_hsc_read_ok;
	PL_xml_Http.setRequestHeader("Content-Length",t_post.length);
	PL_xml_Http.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	PL_xml_Http.send(t_post);
}

function qingtiandy_gbook_f(n,id)
{
	$("gbook_book").innerHTML="正在加载......";
	PL_cx_hr();
	var url=pinglun_dir+"p_inc/pinglun/save.asp";
	var t_post="page="+n+"&t_id="+id+pinglun_a_h;;
	PL_xml_Http.open("POST",url,true);
	PL_xml_Http.onreadystatechange=gbook_hsc_read_ok;
	PL_xml_Http.setRequestHeader("Content-Length",t_post.length);
	PL_xml_Http.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	PL_xml_Http.send(t_post);
}
PP_plstr1=PP_plstr2=PP_plstr3=PP_plstr4=""
PP_plstr1+="<DIV id=\"pinglun_qingtiandy\">";
PP_plstr1+="	<DIV id=pinglun_2>						";
PP_plstr1+="		<TABLE cellSpacing=3 cellPadding=0 width=\"100%\" border=0>								  ";
PP_plstr1+="		  <TBODY>				  ";
PP_plstr1+="		  <tr>";
PP_plstr1+="			<TD width=40>昵称：<\/TD>";
PP_plstr1+="			<td><input type=\"text\" maxlength=\"14\" id=\"n_name\" onChange=\"qingtiandy_gbook_n_t()\" name=\"n_name\" style='border:#"+pinglun_border_color+" solid 1px;' value='匿名'> <span id=\"n_name_1\" >不超过7个汉字，或14个字节(数字，字母和下划线)<\/span><\/td>";
PP_plstr1+="		  <\/tr>";
PP_plstr1+="		  <TR>";
PP_plstr1+="			<TD width=40>内容：<\/TD>";
PP_plstr1+="			<TD><TEXTAREA id=\"n_content\" style=\"WIDTH: 100%; border:#"+pinglun_border_color+" solid 1px;\" name=\"n_content\" rows=8 wrap=virtual onKeyUp=\"textCounter(this,"+Pl_numb_x+",\'n_content_1\')\"><\/TEXTAREA><\/TD>";
PP_plstr1+="		  <TR>";
PP_plstr1+="			<TD width=40><\/TD>";
PP_plstr1+="			<TD>";
PP_plstr1+="			";
			for (var i=1;i<=12;i++){
				PP_plstr1+="<IMG onClick=\"insertface('[face0"+i+"]')\" src=\""+pinglun_dir+"p_inc/pinglun/images/face/0"+i+".gif\" border=0> "
			}
PP_plstr1+="			<\/TD>				";
//document.writeln("		  <tr>");
//document.writeln("			<TD width=40>验证：<\/TD>");
//document.writeln("			<td><INPUT style=\"WIDTH: 85px;border:#"+pinglun_border_color+" solid 1px;\" maxLength=4 name=verifycode id=verifycodenext > ");
//document.writeln("			<IMG id=verifypic src=\""+pinglun_dir+"p_inc\/pinglun\/code.asp\" border=0 width=\"60px\" height=\"20px\">");
//document.writeln("			<a href=\"javascript:newverifypic();\" title=\"看不清左边的字符\">看不清?<\/a>");
//document.writeln("			<\/td>");
//document.writeln("		  <\/tr>	");
//document.writeln("						");
PP_plstr1+="		  <TR>";
PP_plstr1+="			<TD align=left colSpan=3 style=\"padding-left:50px\">";
PP_plstr1+="			<INPUT type=\"button\"value=\" 提交 \" onClick=\"qingtiandy_gbook_t("+pinglun_id+");\" id=\"b_b\"> ";
PP_plstr1+="			";
PP_plstr1+="			<span id=\"n_content_1\">字数<span id=\"max_m_contentlength\">"+Pl_numb_x+"<\/span>字以内<\/span>";
PP_plstr1+="			<\/TD><\/TR>					";
PP_plstr1+="		<\/TBODY><\/TABLE>				";
PP_plstr1+="	<\/DIV>	";

PP_plstr2+="	<div style=\"MARGIN-TOP: 5px; \" id=\"gbook_book\" >";
PP_plstr2+="						";
PP_plstr2+="									";
PP_plstr2+="	<\/div>";
PP_plstr2+="<\/div>";
PP_plstr2+="";

PP_plstr3+="	<div style=\"MARGIN-TOP: 5px; \" id=\"gbook_book\" >";
PP_plstr3+="	评论暂时关闭					";
PP_plstr3+="									";
PP_plstr3+="	<\/div>";
PP_plstr3+="";

PP_plstr4+="	<div style=\"MARGIN-TOP: 5px; \" id=\"gbook_book\" >";
PP_plstr4+="	匿名用户评论暂时关闭。<br>请先<span style='color:red;cursor:pointer' onclick='aUserLogin()'>登陆</span>后再评论，没有帐号，请先<span style='color:red;cursor:pointer' onclick='aUserReg()'>注册</span>					";
PP_plstr4+="									";
PP_plstr4+="	<\/div>";
PP_plstr4+="";
document.write(PP_plstr1+PP_plstr2)

function x_t_x(){qingtiandy_gbook_x(pinglun_id);}
function ff(n){qingtiandy_gbook_f(n,pinglun_id)}
function dl_f(){f(parseInt($('p').value)+1,pinglun_id)}

x_t_x();

$("n_name").value="匿名"