﻿//添加对评论的支持人数
  function SupportAdd(commentid)
   {
    var root=document.getElementById("inputRootDirect").value;
    var url = root+"AjaxCommentAdd.aspx?value=1";
    var pars = "name=" + commentid;
    var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsNamePass});
   }
   function IsNamePass(result)
   {
     var val = result.responseText;
     var count=parseInt(document.getElementById("spanAddSupport"+val+"").innerText) + 1;
     document.getElementById("spanAddSupport"+val+"").innerText=count;  
     if(val=='false')
     {
         alert("失败");
     }
   }
//添加对评论的反对人数
   function OppositionAdd(commentid)
   {
    var root=document.getElementById("inputRootDirect").value;
    var url = root+"AjaxCommentAdd.aspx?value=2";
    var pars = "name=" + commentid;
    var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsAddPass});
   }
   function IsAddPass(result)
   {
     var val = result.responseText;
     var count=parseInt(document.getElementById("spanAddOppositon"+val+"").innerText) + 1;
     document.getElementById("spanAddOppositon"+val+"").innerText=count;  
     if(val=='false')
     {
         alert("失败");
     }
   }


//验证用户输入的用户名及密码的合法性
 function UserCheck()
 {
// debugger;
       var root=document.getElementById("inputRootDirect").value;
       var url=root+"AjaxUserCheck.aspx";
       var name=document.getElementById("inputUserName").value;
       var pass=document.getElementById("inputPassword").value;
       var pars="inputUserName="+name+"&inputPassword="+pass;
       var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsExit});   
 }
 
 function IsExit(result)
   {
//   debugger;
      var val = result.responseText;
      if(val=='Error')
      {
        alert("用户名或密码输入错误");
              
      }   
     if(val=='Exit'|| val=='null')
     {
         CommentSubmit();            
     }
   }




//发表新评论
 function CommentSubmit()
 {
// debugger;
       var root=document.getElementById("inputRootDirect").value;
       var url=root+"AjaxPassComment.aspx";
       var productid=document.getElementById("inputProductID").value;
       var producttypeid=document.getElementById("inputProductTypeID").value;
       var content=document.getElementById("txtcontent").value;
       var name=document.getElementById("inputUserName").value;
       var pass=document.getElementById("inputPassword").value;
       var pars="inputUserName="+name+"&txtcontent="+content+"&inputPassword="+pass+"&cid="+productid+"&type="+producttypeid;
       var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsAddComment});   
 }
 
 function IsAddComment(result)
   {
//   debugger;
      var val = result.responseText;
      if(val!='login' & val!='audit' & val!='Unsafe')
      {
        document.getElementById("divComment").innerHTML=val;
        document.getElementById("txtcontent").value="";
        document.getElementById("inputUserName").value="";
        document.getElementById("inputPassword").value="";
        document.getElementById("inputCode").value="";
        document.getElementById("CommentNum").innerHTML=parseInt(document.getElementById("CommentNum").innerHTML)+1;    
      }   
     if(val=='login')
     {
         alert("对不起，请登录后才能发表评论");            
     }
     if(val=='audit')
     {
          alert("您发表的评论已被提交审批"); 
     }
     if(val=='Error')
     {
         alert("用户名或密码输入错误");            
     }
     if(val=='Unsafe')
     {
         alert("信息不全不能发表评论");
     }
      GetCode(); 
   }
   
   //验证验证码输入的正确与否
 function VerifyCode()
 { 
// debugger;
       var root=document.getElementById("inputRootDirect").value;
       var url=root+"AjaxVerifyCode.aspx";
       var code=document.getElementById("inputCode").value;
       var pars="inputCode="+code;
       var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsCodePass });   
 }
 
 function IsCodePass(result)
   {
//   debugger;
      var val = result.responseText;
      if(val=='CodeNull')
      {
          alert("请输入验证码"); 
      }
      if(val=='CodeError')
      { 
          alert("验证码输入错误"); 
      }
      if(val=='true')
      {
          UserCheck();  
      }
   }
   
   
   
   //获取已发表的评论数量
   function GetCommentNum()
   {
//   debugger;
    var root=document.getElementById("inputRootDirect").value;
    var Commentid=document.getElementById("inputProductID").value;
    var Commenttypeid=document.getElementById("inputProductTypeID").value;
    var url = root+"AjaxGetCommentNum.aspx";
    var pars = "productID=" + Commentid+"&productTypeID="+Commenttypeid;
    var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsNumPass});
   }
   function IsNumPass(result)
   {
//   debugger;
     var val = result.responseText;
     document.getElementById("CommentNum").innerHTML=val; 
     
   }
   
   //获取验证码
   function GetCode()
   {
//   debugger;
//    var Commentid=document.getElementById("CommentInfo_inputProductID").value;
    var root=document.getElementById("inputRootDirect").value;
     var Commentid=document.getElementById("inputProductID").value;
    document.getElementById("imgcode").style.display='block';
    var url = root+"GetVerificationCode.aspx?id="+(new Date()).getTime();
    document.getElementById("imgcode").src=url;
           
   }
  
  //判断当前用户留言板功能是否打开
   function JudgeCommentDiv()
   {
//   debugger;
    var root=document.getElementById("inputRootDirect").value;
    var url=root+"AjaxCommentShow.aspx"
    var Commentid=document.getElementById("inputProductID").value;
    var Commenttypeid=document.getElementById("inputProductTypeID").value;
    var pars = "cid=" + Commentid+"&productTypeID="+Commenttypeid;
    var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: IsDivPass});
   }
   function IsDivPass(result)
   {
     var val = result.responseText;
     if(val=='open')
     {
         document.getElementById("divContent").style.display='block';
        
         GetCommentNum();
         
     }
     if(val=='close')
     {
         document.getElementById("divContent").style.display='none';
     }
   }
   
   
  //检测用户输入的合法性
   function JsCheck()
   {
//   debugger;
       var content=document.getElementById("txtcontent").value;
       var username=document.getElementById("inputUserName").value;
       var code=document.getElementById("inputCode").value;
       if(Trim(code)=="")
       {
         alert("验证码不能为空！")
         return false;
       }
       if(isName(code))
       {
           alert("验证码输入不能含有脚本字符！")
           return false;
       }
       if(Trim(content)=="")
       {
           alert("用户评论不能为空！")
           return false;
       }
       if(isName(content))
       {
           alert("评论内容输入不能含有脚本字符！")
           return false;
       }
       if(isName(username))
       {
           alert("用户名输入输入不能含有脚本字符！")
           return false;
       }
       else
       {
           VerifyCode();
           
       }   
   }
function isName(s)  
{  
    var patrn=/(<(.)+>)/i;  
    if (!patrn.exec(s)) {return false;}  
    return true;  
}
function Trim(value)
{
	return  value.replace(/(^\s*)  |(\s*$)/g,  "");
}


//动态发表评论的过程中检测发表的评论内容的合法性

   function CommentCheck()
   {
       var content=document.getElementById("txtcontent").value;
       var verification=document.getElementById("txtVerification").value;
       var username=document.getElementById("txtUserName").value;
       if(Trim(verification)=="")
       {
         alert("验证码不能为空！")
         return false;
       }
       if(isName(verification))
       {
           alert("验证码输入不能含有脚本字符！")
           return false;
       }
       if(Trim(content)=="")
       {
           alert("用户评论不能为空！")
           return false;
       }
       if(isName(content))
       {
           alert("评论内容输入不能含有脚本字符！")
           return false;
       }
       if(isName(username))
       {
           alert("用户名输入输入不能含有脚本字符！")
           return false;
       }
       else
       {
           return true;
       }
      
   }
function isName(s)  
{  
    var patrn=/(<(.)+>)/i;  
    if (!patrn.exec(s)) {return false;}  
    return true;  
}
function Trim(value)
{
	return  value.replace(/(^\s*)  |(\s*$)/g,  "");
}

//点击我要评论，评论框获取焦点
function PublishComment()
{
//debugger;
  $("txtcontent").focus();
}



