﻿// JScript 文件
// JScript 文件
// *********************************************************
// 给字符串变量增加去除头尾空格的方法“trim()”.
// *********************************************************
String.prototype.trim=function() 
{ 
    return this.replace(/(\s*$)|(^\s*)/g, ""); 
} 
String.prototype.lenB   =   function(){return   this.replace(/[^\x00-\xff]/g,"**").length;}

var xmlReq = false;

function createXMLHttpRequest() 
{
     if(window.XMLHttpRequest)
    {
        xmlReq = new XMLHttpRequest();
        if(xmlReq.overrideMimeType)  xmlReq.overrideMimeType('text/xml');
    }
    else if(window.ActiveXObject)
    { 
       try
       {
            xmlReq = new ActiveXObject('Msxml2.XMLHTTP');
       }
       catch(e)
       {
          try
          {
              xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
          }
          catch(e){}
        }
    }
}




//help and nohelp ajax for reviewlist new

function cust_vote_help_add_newReviewlist(review_id,vote_type,product_id,itemindex)
{
    createXMLHttpRequest();
    var url = 'http://comm.dangdang.com/cust_review_vote_help_add.aspx?review_id='+review_id+'&vote_type='+vote_type+'&product_id='+ product_id+'&time='+ new Date();
    xmlReq.open("GET",url,false);
    
    xmlReq.send(null);
		
    var result=xmlReq.responseText;
    if(result=="0")
    {     
          var helpcount = parseInt(document.getElementById(itemindex.toString()+"help").innerHTML);
          var totalcount = parseInt(document.getElementById(itemindex.toString()+"total").innerHTML);
          var nohelpcount = totalcount - helpcount;
          if(vote_type==1)
          {
              helpcount = helpcount+1;
              if(nohelpcount ==0)
              {
                 document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用。";    
              }
              else
              {
                 document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用，"+nohelpcount+"人认为此评论没用。";
              }
              document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票,<a href='http://comm.dangdang.com/myreview/useful_review.aspx' target ='_blank'>查看所有您觉得有用的评论</a>";
          }
          else
          {
              nohelpcount = nohelpcount+1;
              if(helpcount>0)
              {
                  document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用，"+nohelpcount+"人认为此评论没用。"; 
              }
              else
              {
                  document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有"+nohelpcount+"人认为此评论没用。";
              }
              document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票";
          }             
    }
    else
    {
        switch(result)
        {
            case "5":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/VerifyEmail.aspx' target='_blank'>邮箱验证</a>";
            break;
        
            case "4":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/register.aspx' target='_blank'>邮箱验证</a>";
            break;
            //未验证邮箱的帐户，点击“有用”“没用”，提示：请先完成邮箱验证。“邮箱验证”加链接，链接到相应的“被动验证”和“主动验证”页。 
            //5为被动验证  4为主动验证
            
            case "3":         
            window.location.href="https://login.dangdang.com/signin.aspx?returnURL="+escape(window.location.href);
                //未登陆

                break;
            case "2":
            alert("提交失败");
                //提交失败
                break;
            case "1":
            //alert("对不起，你只能投票一次！");
                //已经投标过                document.getElementById(itemindex.toString()+"alreadySent").innerHTML="您已经投过票了";
                 


                break;
            default:
                break;
        }
    }    
}


function cust_vote_help_add_wonderful(review_id,vote_type,product_id,itemindex)
{
    
    createXMLHttpRequest();
    var url = 'http://comm.dangdang.com/cust_review_vote_help_add.aspx?review_id='+review_id+'&vote_type='+vote_type+'&product_id='+ product_id+'&time='+ new Date();
    xmlReq.open("GET",url,false);
    
    xmlReq.send(null);
		
    var result=xmlReq.responseText;
    
    if(result=="0")
    { 
          var helpcount = parseInt(document.getElementById(itemindex.toString()+"help").innerHTML);
          var totalcount = parseInt(document.getElementById(itemindex.toString()+"total").innerHTML);
          var nohelpcount = totalcount - helpcount;
          if(vote_type==1)
          {
              helpcount = helpcount+1;
              if(nohelpcount ==0)
              {
                 document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用。";    
              }
              else
              {
                 document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用，"+nohelpcount+"人认为此评论没用。";
              }
              document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票,<a href='http://comm.dangdang.com/myreview/useful_review.aspx' target ='_blank'>查看所有您觉得有用的评论</a>";
          }
          else
          {
              nohelpcount = nohelpcount+1;
              if(helpcount>0)
              {
                  document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有<span class='red_nostrong'>"+helpcount+"</span>人认为此评论有用，"+nohelpcount+"人认为此评论没用。"; 
              }
              else
              {
                  document.getElementById(itemindex.toString()+"helpinfo").innerHTML="有"+nohelpcount+"人认为此评论没用。";
              }
              document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票";
          }
    }
    else
    {
        switch(result)
        {
            case "5":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/VerifyEmail.aspx' target='_blank'>邮箱验证</a>";
            break;
        
            case "4":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/register.aspx' target='_blank'>邮箱验证</a>";
            break;
            //未验证邮箱的帐户，点击“有用”“没用”，提示：请先完成邮箱验证。“邮箱验证”加链接，链接到相应的“被动验证”和“主动验证”页。 
            //5为被动验证  4为主动验证
            
            case "3":         
            window.location.href="https://login.dangdang.com/signin.aspx?returnURL="+escape(window.location.href);
                //未登陆

                break;
            case "2":
            alert("提交失败");
                //提交失败
                break;
            case "1":
           // alert("对不起，你只能投票一次！");
           document.getElementById(itemindex.toString()+"alreadySent").innerHTML="您已经投过票了";
                //已经投标过

                break;
            default:
                break;
        }
    }        
}

function cust_vote_help_add_newReviewlist_id(review_id,vote_type,product_id,itemindex){
    createXMLHttpRequest();
    var url = 'http://comm.dangdang.com/cust_review_vote_help_add.aspx?review_id='+review_id+'&vote_type='+vote_type+'&product_id='+ product_id+'&time='+ new Date();
    xmlReq.open("GET",url,false);
    
    xmlReq.send(null);
		
    var result=xmlReq.responseText;
    if(result=="0")
    {
    
    //String str = "<span id=\"" + e.Item.ItemIndex.ToString() + "begin_info\">{5}</span><span class=\"red\" id=\"" + e.Item.ItemIndex.ToString() + "help\">{0}</span><span id=\"" + e.Item.ItemIndex.ToString() + "help_info\">{1}</span><span id=\"" + e.Item.ItemIndex.ToString() + "total\">{2}</span><span id=\"" + e.Item.ItemIndex.ToString() + "total_info\">{3}</span><span id=\"" + e.Item.ItemIndex.ToString() + "end_info\">{4}</span>";
        if(vote_type==1)//有用票
        {//******************************* total 在此不代表所有投票数量,而代表反对投票数量**********************************************
            var help_num = document.getElementById(itemindex.toString()+"help").innerHTML;
            if (help_num=="")
                help_num="0";
            document.getElementById(itemindex.toString()+"begin_info").innerHTML="有";
            document.getElementById(itemindex.toString()+"none").innerHTML="";
            document.getElementById(itemindex.toString()+"help").innerHTML=parseInt(help_num)+1;
            document.getElementById(itemindex.toString()+"help_info").innerHTML="人认为此评论有用，";
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票,<a href='http://comm.dangdang.com/myreview/useful_review.aspx' target='_blank'>查看所有您觉得有用的评论</a>";
        }
        else//无用票
        {
            var total = document.getElementById(itemindex.toString()+"total").innerHTML;
            if (total=="")
                total="0";
            document.getElementById(itemindex.toString()+"begin_info").innerHTML="有";
            document.getElementById(itemindex.toString()+"none").innerHTML="";
            document.getElementById(itemindex.toString()+"total").innerHTML=parseInt(total)+1;
            document.getElementById(itemindex.toString()+"total_info").innerHTML="人认为没用，";
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="感谢您的投票";
        } 
    }
    else
    {
        switch(result)
        {
            case "5":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/VerifyEmail.aspx' target='_blank'>邮箱验证</a>";
            break;
        
            case "4":
            document.getElementById(itemindex.toString()+"alreadySent").innerHTML="请先完成<a href='https://login.dangdang.com/register.aspx' target='_blank'>邮箱验证</a>";
            break;
            //未验证邮箱的帐户，点击“有用”“没用”，提示：请先完成邮箱验证。“邮箱验证”加链接，链接到相应的“被动验证”和“主动验证”页。 
            //5为被动验证  4为主动验证
            case "3":         
            window.location.href="https://login.dangdang.com/signin.aspx?returnURL="+escape(window.location.href);
                break;
            case "2":
            alert("提交失败");
                break;
            case "1":                document.getElementById(itemindex.toString()+"alreadySent").innerHTML="您已经投过票了";
                break;
            default:
                break;
        }
    }    
}


// *********************************************************
// 回复问题的脚本验证  for reviewdetail.aspx
// *********************************************************
function checkAnswerReview(  )
{       
    var controlB=document.getElementById("txtBody");
    if(controlB==null)
    {
      return false;
    }
    else
    {
      var controlBValue=controlB.value.trim();      
       
       if(controlBValue=="")
       {         
            alert("正文不能为空！"); 
            controlB.focus();
            return false;      
       }
        if(controlBValue.length>3000)
       {      
            alert("正文不能超过3000字！");
            controlB.focus();
            return false;       
       }      
       if(!validateCode())
       {                  
           return false;
       }       
       document.getElementById("btnPostback").click();       
    }      
}

function validateCode()
{
    var code= document.getElementById("validNum").value;
    var url = 'http://comm.dangdang.com/ValidateCode.aspx?code='+code;
    if(code.lenB()!=4)
    {
       document.getElementById("errorMessage").innerHTML="*请输入两个汉字*"; 
       return false;
    }
    createXMLHttpRequest();
    xmlReq.open("GET",url,false);
    
    xmlReq.send(null);
		
    var result=xmlReq.responseText;   
    
     if(result=="2")
     {        
         //alert("wrong code");    
         document.getElementById("errorMessage").innerHTML="*您输入的验证码有误*";          
         changeImage();
         return false;
     }   
     else
     {
        return true;
     }
}


function ValidateCustomerPostReviewRight(product_id,product_name)
{
  
    createXMLHttpRequest();
    var url = 'http://comm.dangdang.com/cust_validate_check.aspx?product_id='+ product_id+'&time='+ new Date();
    xmlReq.open("GET",url,false);
    
    xmlReq.send(null);
		
    var result=xmlReq.responseText;
    
    
    switch(result)
    {
        case "5":
            document.getElementById("postnotice").innerHTML="(<span class='red_space'>*</span>请先完成<a href='https://login.dangdang.com/VerifyEmail.aspx' target='_blank'>邮箱验证</a>)";
            break;
                                                            
        case "4":
            document.getElementById("postnotice").innerHTML="(<span class='red_space'>*</span>请先完成<a href='https://login.dangdang.com/register.aspx' target='_blank'>邮箱验证</a>)";
            break;
        //未验证邮箱的帐户，，提示：请先完成邮箱验证。“邮箱验证”加链接，链接到相应的“被动验证”和“主动验证”页。 
        //5为被动验证  4为主动验证
        case "3":         
            window.location.href="https://login.dangdang.com/signin.aspx?returnURL="+escape(window.location.href);
            break;
        case "0":            window.location.href="http://comm.dangdang.com/ReviewPost.aspx?product_id="+product_id+"&product_name="+product_name;
            break;
        default:
            break;
    }
}