

var LASTMESSAGEID="";
	function ajaxServlet(prarmStr,servletUrl,callback){
			   $.ajax({
		       type:"POST",
		       url:contextPath+servletUrl,
		       data:prarmStr,
		       timeout: 60000,
		       async: true,
		       dataType:"text",
		       chache:false,
		       success:function(msgInfo){
		       
		          callback.onSuccess(msgInfo);
	                     },
	        error:function(){
	    	       callback.onFail();
	                    }
	         });
  }
  
function getCode(ID){
       this.ajaxServlet("","/imageCodeServlet",{
           onSuccess:function(msgInfo){
              $("#"+ID).attr("src",msgInfo);
                             },
           onFail:function(){return ;}
                    });
}

function changeCode(ID)
{
   $("#"+ID).html("<img src='"+contextPath+"/imageCodeServlet?"+Math.random()+"' align='absmiddle'/>");
}

function checkCode(code)
{
       this.ajaxServlet("imageCode="+code,"/CheckCodeServlet",{
           onSuccess:function(msgInfo){
              return msgInfo=="1"?true:false;
                             },
           onFail:function(){return ;}
                    });
}

function checkRegister(){

    if(!document.getElementById("ruleCondition").checked){
   	 alert("请确认是否同意优问服务条款?");
   	 return;
    }
    
     var userName=$("#userName").val();
     if(userName==""||userName==null || userName.length<4){
          alert("用户名至少要输入4个字符！");
          $("#userName").val("");
          $("#userName").focus();
          return; 
               }
  //   var userNameReg = new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
  //   if(!userNameReg.test(userName)){
  //       alert("用户名输入有误！用户名只能包括汉字、字母、数字、下划线!请重新输入!");
  //        $("#userName").val("");
  //        $("#userName").focus();
  //        return; 
      //        }
     var petName=$("#petName").val();
     if(petName==""||petName==null){
          alert("昵称不能为空，请输入昵称！");
          $("#petName").val("");
          $("#petName").focus();
          return; 
               }
              
     var password=$("#password").val();
     if(password==""||password==null){
          alert("密码不能为空，请输入密码！");
          $("#password").val("");
          $("#password").focus();
          return; 
               }
               
     if(password.length<6){
          alert("密码不能小于6个字符!");
          $("#password").val("");
          $("#passwordAagin").val("");
          $("#password").focus();
          return; 
               }
     var passwordReg=new RegExp("^\s*[^ ]*\s*$");
     if(!passwordReg.test(password)){
          alert("密码输入有误！不能包含空格！请重新输入！");
          $("#password").val("");
          $("#passwordAagin").val("");
          $("#password").focus();
          return; 
             }
     var passwordAagin=$("#passwordAagin").val();
     if(passwordAagin==""||passwordAagin==null){
          alert("确认密码不能为空，请输入确认密码！");
          $("#passwordAagin").val("");
          $("#passwordAagin").focus();
          return; 
               }
               
     if(password!=passwordAagin){
          alert("您两次输入的密码不一致！請重新输入！");
          $("#password").val("");
          $("#passwordAagin").val("");
          $("#password").focus();
          return; 
               }
               
     var email=$("#email").val();
     if(email==""||email==null){
          alert("电子邮箱不能为空,请输入电子邮箱！");
          $("#email").val("");
          $("#email").focus();
          return; 
               }
               
      var emailAgian=$("#emailAgian").val();
      if(emailAgian==""||emailAgian==null){
          alert("确认邮箱不能为空,请输入确认邮箱！");
          $("#emailAgian").val("");
          $("#emailAgian").focus();
          return; 
               }
               
      if(email!=emailAgian){
          alert("您两次输入的邮箱不一致！請重新输入！");
          $("#email").val("");
          $("#emailAgian").val("");
          $("#email").focus();
          return; 
               }
               
      var reg = new RegExp("^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
      if(!reg.test(email)){
          alert("电子邮箱输入有误,请重新输入电子邮箱！");
          $("#email").val("");
          $("#email").focus();
          return;
               }
               
               
     var registCode=$("#registCode").val();
     if(registCode==""||registCode==null){
          alert("验证码不能为空,请输入验证码！");
          $("#registCode").val("");
          $("#registCode").focus();
          return; 
               }
     
     
     
     this.ajaxServlet("imageCode="+registCode,"/CheckCodeServlet",{
           onSuccess:function(msgInfo){
              if(msgInfo!="1")
						              {
						          alert("验证码输入有误！请重新输入！");
						          changeCode("imgCode");
						          $("#registCode").val("");
						          $("#registCode").focus();
						          return; 
						              }
						    record.registerCheck(userName,password,email,petName);
						    
                             },
           onFail:function(){return ;}
              });
}

	function f_userLogon()
	{        
	    var userName=$("#logonUserName").val();
     if(userName==""||userName==null){
          alert("用户名不能为空，请输入用户名！");
          $("#logonUserName").val("");
          $("#logonUserName").focus();
          return; 
               }
              
     var password=$("#logonPassword").val();
     if(password==""||password==null){
          alert("密码不能为空，请输入用户名！");
          $("#logonPassword").val("");
          $("#logonPassword").focus();
          return; 
               }
               
     var registCode=$("#logonRegistCode").val();
     if(registCode==""||registCode==null){
          alert("验证码不能为空,请输入验证码！");
          $("#logonRegistCode").val("");
          $("#logonRegistCode").focus();
          return; 
               }
     var instance=this; 
    
     this.ajaxServlet("imageCode="+registCode,"/CheckCodeServlet",{
           onSuccess:function(msgInfo){
              if(msgInfo!="1")
						              {
						          alert("验证码输入有误！请重新输入！");
						          instance.changeCode("logonImgCode");
						          $("#logonRegistCode").val("");
						          $("#logonRegistCode").focus();
						          return; 
						              }
						     record.passwordCheck(userName,password);
                             },
           onFail:function(){return ;}
              });
              
    
    }


function f_updatePwd()
{
      var  oldPassword=$("#oldPassword").val();
      var  newPassword=$("#newPassword").val();
      var  againPassword=$("#againPassword").val();
      var  modifyPwdCode=$("#modifyPwdCode").val();
      var  username=$("#usernamePageScope").val();
      
      if(oldPassword==""||oldPassword==null){
          alert("原密码不能为空，请输入原密码！");
          $("#oldPassword").val("");
          $("#oldPassword").focus();
          return; 
               }
               
      var passwordReg=new RegExp("^\s*[^ ]*\s*$");
      if(!passwordReg.test(oldPassword)){
	          alert("原密码输入有误！不能包含空格！请重新输入！");
	          $("#oldPassword").val("");
	          $("#oldPassword").focus();
	          return; 
	             }
	             
      if(newPassword==""||newPassword==null){
          alert("新密码不能为空，请输入新密码！");
          $("#newPassword").val("");
          $("#newPassword").focus();
          return; 
               }
       
       if(newPassword.length<6){
          alert("密码不能小于6个字符!请重新输入!");
          $("#newPassword").val("");
          $("#againPassword").val("");
          $("#newPassword").focus();
          return; 
                }
                
	     
	     if(!passwordReg.test(newPassword)){
	          alert("新密码输入有误！不能包含空格！请重新输入！");
	          $("#newPassword").val("");
	          $("#againPassword").val("");
	          $("#newPassword").focus();
	          return; 
	             }
             
      if(againPassword==""||againPassword==null){
          alert("确认密码不能为空，请输入确认密码！");
          $("#againPassword").val("");
          $("#againPassword").focus();
          return; 
               }
               
      if(newPassword!=againPassword){
          alert("您两次输入的密码不一致！請重新输入！");
          $("#newPassword").val("");
          $("#againPassword").val("");
          $("#newPassword").focus();
          return; 
               }
               
               
      var modifyPwdCode=$("#modifyPwdCode").val();
      if(modifyPwdCode==""||modifyPwdCode==null){
          alert("验证码不能为空,请输入验证码！");
          $("#modifyPwdCode").val("");
          $("#modifyPwdCode").focus();
          return; 
               }
       var instance=this; 
       this.ajaxServlet("imageCode="+modifyPwdCode,"/CheckCodeServlet",{
           onSuccess:function(msgInfo){
              if(msgInfo!="1")
						              {
						          alert("验证码输入有误！请重新输入！");
						          instance.changeCode("modifyPwdImgCode");
						          $("#modifyPwdCode").val("");
						          $("#modifyPwdCode").focus();
						          return; 
						              }
						     else{
						       record.updatePasswordCheck(username,oldPassword,newPassword);
						              }
						              
                             },
           onFail:function(){return ;}
              });
      
}

 
function addOrder(action){
     
     var nickName=$("#nickName").val();
     var companyName=$("#companyName").val();
     var companyDescription=$("#companyDescription").val();
     var contactPeople=$("#contactPeople").val();
     var telephone=$("#telephone").val();
     var fax=$("#fax").val();
     var address=$("#address").val();
     var email=$("#email").val();
     var webSite=$("#webSite").val();
     var robotType=$("#robotType").val();
     var effectiveTime=$("#effectiveTime").val();
     
      if(nickName==""||nickName==null){
          alert("机器人昵称不能为空，请输入机器人昵称！");
          $("#nickName").val("");
          $("#nickName").focus();
          return; 
               }
      if(nickName.length<3){
          alert("机器人昵称不能小于3个字符!请重新输入!");
          $("#nickName").val("");
          $("#nickName").focus();
          return; 
                }
      var nickNameReg=new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
      if(!nickNameReg.test(nickName))
			     {
			     alert("机器人昵称只能包括汉字、字母、数字、下划线!请重新输入!");
          $("#nickName").val("");
          $("#nickName").focus();
          return; 
			     }
      if(companyName==""||companyName==null){
          alert("公司名称不能为空，请输入公司名称！");
          $("#companyName").val("");
          $("#companyName").focus();
          return; 
               }
      if(contactPeople==""||contactPeople==null){
          alert("联系人不能为空，请输入联系人！");
          $("#contactPeople").val("");
          $("#contactPeople").focus();
          return; 
               }
       if(telephone==""||telephone==null){
          alert("联系电话不能为空，请输入联系电话！");
          $("#telephone").val("");
          $("#telephone").focus();
          return; 
               }
      var numberReg=new RegExp("^[0-9\-]+$"); 
      if(!numberReg.test(telephone)){
          alert("联系电话输入有误！请重新输入！");
          $("#telephone").val("");
          $("#telephone").focus();
          return; 
                }
      if((fax!="" && fax!=null)&&!numberReg.test(fax)){
          alert("传真输入有误！请重新输入！");
          $("#fax").val("");
          $("#fax").focus();
          return; 
                }
      if(address==""||address==null){
          alert("地址不能为空，请输入地址！");
          $("#address").val("");
          $("#address").focus();
          return; 
               }
      if(email==""||email==null){
          alert("Email不能为空，请输入Email！");
          $("#email").val("");
          $("#email").focus();
          return; 
               }
      var reg = new RegExp("^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
      if(!reg.test(email)){
          alert("电子邮箱输入有误,请重新输入电子邮箱！");
          $("#email").val("");
          $("#email").focus();
          return;
               }
      if(robotType==""||robotType==null){
          alert("版本不能为空，请选择版本！");
          $("#robotType").val("");
          $("#robotType").focus();
          return; 
               }
      if(effectiveTime==""||effectiveTime==null){
          alert("订购有效期不能为空，请选择订购有效期！");
          $("#effectiveTime").val("");
          $("#effectiveTime").focus();
          return; 
               }
      if($("#ruleCondition").attr("checked")){
         record.orderCompanyNameCheck(companyName,action);
      }else{
        alert("您还未勾选服务条款，请您勾选！");
        $("#ruleCondition").focus();
        return; 
              }
      
            
}


function f_clearUpdatePwdDiv()
{
       $("#oldPassword").val("");
       $("#newPassword").val("");
       $("#againPassword").val("");
       $("#modifyPwdCode").val("");
       $("#oldPassword").focus();
       changeCode("modifyPwdImgCode");
}

function f_clearRegisterDiv(){
        $("#userName").val("");
        $("#petName").val("");
        $("#password").val("");
        $("#passwordAagin").val("");
        $("#email").val("");
        $("#registCode").val("");
        $("#userName").focus();
        changeCode("imgCode");
}

function f_clearLogonDiv()
{
        $("#logonUserName").val("");
        $("#logonPassword").val("");
        $("#logonRegistCode").val("");
        $("#logonUserName").focus();
        changeCode("logonImgCode");
}


