﻿function ValidateData()
{
     if($("#chkAnonymity").attr("checked")==undefined)
     {
         if($("#txtUserName").val()=="")
         {
              alert("请填写您的昵称！");
              $("#txtUserName").focus();
              return false;
         }
         if($("#txtComeFrom").val()=="")
         {
             alert("您忘记了填写您从哪里来，请您填写!");
             $("#txtComeFrom").focus();
             return false;
         }
                
         if($("#txtValidateCode").val()=="")
         {
             alert("请填写验证码！");
             $("#txtValidateCode").focus();
             return false;
         }
                
         if($("#txtContent").val()=="")
         {
             alert("请填写评论内容！");
             $("#txtContent").focus();
             return false;
         }
         else
         {
              if($("#txtContent").val().length>2500)
              {
                   alert('评论内容长度不能超过2500个汉字！');
                   return false;
              }
         }
    }
          return true;
}
        
        
        
        
        var sMax;	// 最大数量的星星即最大评分值
        var holder; // 鼠标停留的评分控件
        var preSet; // 保存了评分值（通过单击来进行评分）
        var rated; //是否评分过，并保存了结果（注意此值一旦设为空，就不能再评分）

        // 鼠标停留事件
        function rating(num){
	        sMax = 0;	// 默认值为0
	        for(n=0; n<num.parentNode.childNodes.length; n++){
		        if(num.parentNode.childNodes[n].nodeName == "A"){
			        sMax++;	
		        }
	        }
        	
	        if(!rated){
		        s = num.id.replace("_", ''); // 获取选中的星星的索引，这里使用_1,_2,_3,_4,_5来做为评分控件的ID，当然也有其他的方式。
		        a = 0;
		        for(i=1; i<=sMax; i++){		
			        if(i<=s){
				        document.getElementById("_"+i).className = "on";
				        holder = a+1;
				        a++;
			        }else{
				        document.getElementById("_"+i).className = "";
			        }
		        }
	        }
        }

        // 离开事件
        function off(me){
	        if(!rated){
		        if(!preSet){	
			        for(i=1; i<=sMax; i++){		
				        document.getElementById("_"+i).className = "";
			        }
		        }else{
			        rating(preSet);
		        }
	        }
        }

        // 点击进行评分
        function rateIt(me){
	        if(!rated){
		        preSet = me;
		        rated=1;  //设为1以后，就变成了最终结果，不能再修改评分结果
		        sendRate(me);
		        rating(me);
	        }
	        else
	        {
	            alert('对不起，您不能再次评价！');
	            return false;
	        }
        }

        //处理评分结果 
        function sendRate(sel){
	        if(FJTS.SetGrade(sel.id.substr(1,2),$("#hlBookID").val()).value>0)
	        {
	            alert('评价成功！');
	        }
	            var bookid = $("#hlBookID").val();
                var strStars = FJTS.GetGrade(bookid).value;
                var arrStars = strStars.split('|');
                $("#star5").attr("innerHTML",arrStars[4]);
                $("#star4").attr("innerHTML",arrStars[3]);
                $("#star3").attr("innerHTML",arrStars[2]);
                $("#star2").attr("innerHTML",arrStars[1]);
                $("#star1").attr("innerHTML",arrStars[0]);
        }
        
        function SearchBook()
	    {
	        if($("#keyword").val()=="")
	        {
	            alert('请填写搜索关键字！');
	            $("#keyword").focus();
	        }
	        else
	        {
	            window.location.href = "BookSearch.aspx?bookType="+$("#bookType").val()+"&keyword="+encodeURI($("#keyword").val());
	        }
	    }
	    