﻿var req;
function CreateXmlDom(hand){
 var req1=null;
 if(window.XMLHttpRequest){
  req1=new XMLHttpRequest();
 }else if(window.ActiveXObject){ 
  try{ req1 = new ActiveXObject("Msxml2.HTTP");} catch (e){;}
  if(req1 == null) try { req1 = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {;}
 } 
 req1.onreadystatechange = hand;
 return req1;
}

function EvalResult(){ 
   if(req.readyState==4)
   {
    document.getElementById("img1").style.display="";
    if(req.status==200)
    {
         result=req.responseText;
         if(result=="-4")
         {
         window.alert("验证码有误！");
         document.getElementById("codeshow").innerHTML="";
         document.getElementById("codeshow").innerHTML="<img src=\"codepic.aspx?ran="+Math.random()+"\"/>";
         document.getElementById("Cnz").value="";
         }else if(result=="-3")
         {
         window.alert("已经发布了评论！");
         }
         else if(result=="-2")
         {
         window.alert("没有提交准确的数据信息！");
         }
         else if(result=="-5")
         {
         window.alert("没有发现数据！");
         }else if(result=="-1")
         {
         window.alert("内容解析失败！");
         }
         else if(result=="1")
         {
         window.alert("您的评论成功提交！");         
         document.getElementById("subt").style.display="none";
         }else
         {
         window.alert("发生异常！\n"+result);
         }
    }else
    {
    window.alert("可能因为网络故障，没有发送成功，请重试！");
    }
   }
   
 }
 
function SendMes()
{
t=document.getElementById("Ctitle").value;
c=document.getElementById("Ccontent").value;
n=document.getElementById("Cnc").value;
f=1;
for(i=1;i<=8;i++)
if(document.getElementById("xq"+i).checked)
{f=i;break;}
v=document.getElementById("Cnz").value;   
cid=document.getElementById("cnewsid").value;   
if(t.length>50||t.length<5)
{
window.alert("标题不能小于5个字符,且不能大于50个字符！");
return;
}
if(c.length>500||c.length<10)
{
window.alert("评论内容不能小于10个字符,且不能大于500个字符！");
return;
}
if(n.length>5||n.length<2)
{
window.alert("昵称不能小于2个字符,且不能大于5个字符！");
return;
}
if(f.length<1)
{
window.alert("没有选择心情图标！");
return;
}
if(v.length!=4)
{
window.alert("验证码为四位！");
return;
}
var s = '<?xml version="1.0"?><msg>';   
 s += '<title><![CDATA['  + HTMLEnCode(t) + ']]></title>';
  s += '<content><![CDATA['  + HTMLEnCode(c) + ']]></content>'; 
 s += '<name><![CDATA['  + HTMLEnCode(n) + ']]></name>'; 
 s += '<feel><![CDATA['  + HTMLEnCode(''+f) + ']]></feel>';
 s += '<cnewsid>'+cid+'</cnewsid>';
 s += '<code><![CDATA['  + HTMLEnCode(v) + ']]></code></msg>';
 req=CreateXmlDom(EvalResult);
 document.getElementById("img1").style.display="none";
 req.open("POST","jzss.html",true);
 req.setRequestHeader("Content-Type","text/xml");
 req.send(s);

}

function HTMLEnCode(s)
{ 
  s=s.replace(/</g,"&lt;");
  s=s.replace(/>/g,"&gt;");  
  return s;
}
function GetUrl(t,c,n,f,v)
{
return "ss_"+GetUrlString(t)+"_"+GetUrlString(c)+"_"+GetUrlString(n)+"_"+GetUrlString(f)+"_"+GetUrlString(v)+".html";
}
function GetUrlString(s)
{
s=s.replace(/\r\n/ig,"[Br]");
s=s.replace(/\_/ig," ");
return escape(s);
}
