text: ﻿//验证文本
  var validatePrompt = {
      userName: {
          onFocus: "4-20位字符，由中文、英文、数字及“_”、“-”组成",
          succeed: "OK",
          isNull: "请输入用户名",
          error: "不可为空"
      },
      pwd: {
          onFocus: "6-16位字符，可由英文、数字及“_”、“-”组成",
          succeed: "OK",
          isNull: "请输入密码",
          error:  "密码长度只能在6-16位字符之间" 
      },
      pwd2: {
          onFocus: "请再次输入密码",
          succeed: "OK",
          isNull: "请输入密码",
          error:   "两次输入密码不一致"  
      },
      mail: {
          onFocus: "请输入常用的邮箱，将用来找回密码、接收订单通知等",
          succeed: "",
          isNull: "请输入邮箱",
          error: {
              beUsed: "该邮箱已被使用，请更换其它邮箱，或使用该邮箱<a href='http://passport.360buy.com/retrievepassword.aspx' class='flk13'>找回密码</a>",
              badFormat: "邮箱格式不正确",
              badLength: "您填写的邮箱过长，邮件地址只能在50个字符以内"
          }
      },
      authcode: {
          onFocus: "请输入图片中的字符，不区分大小写",
          succeed: "",
          isNull: "请输入验证码",
          error: "验证码错误"
      },
      protocol: {
          onFocus: "",
          succeed: "",
          isNull: "请先阅读并同意《京东商城用户协议》",
          error: ""
      },
      referrer: {
          onFocus: "如您注册并完成订单，推荐人有机会获得积分",
          succeed: "",
          isNull: "",
          error: ""
      },
      schoolinput: {
          onFocus: "您可以用简拼、全拼、中文进行校名模糊查找",
          succeed: "",
          isNull: "请填选学校名称",
          error: "请填选学校名称"
      },
      empty: {
          onFocus: "",
          succeed: "",
          isNull: "",
          error: ""
      },
      
     title: {
      onFocus: "",
      succeed: "",
      isNull: "不可为空",
      error: ""
     },
     money:
         {
             onFocus: "请输入具体金额,保留2位小数",
             succeed: "OK",
             isNull: "请输入具体金额,保留2位小数",
             error: "输入格式错误!" 
         }
      
  
  
  };
  
  ﻿var validateRegExp = {
      decmal: "^([+-]?)\\d*\\.\\d+$", //浮点数
      decmal1: "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$", //正浮点数
      decmal2: "^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$", //负浮点数
      decmal3: "^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$", //浮点数
      decmal4: "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$", //非负浮点数（正浮点数 + 0）
      decmal5: "^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$", //非正浮点数（负浮点数 + 0）
      intege: "^-?[1-9]\\d*$", //整数
      intege1: "^[1-9]\\d*$", //正整数
      intege2: "^-[1-9]\\d*$", //负整数
      num: "^([+-]?)\\d*\\.?\\d+$", //数字
      num1: "^[1-9]\\d*|0$", //正数（正整数 + 0）
      num2: "^-[1-9]\\d*|0$", //负数（负整数 + 0）		
      ascii: "^[\\x00-\\xFF]+$", //仅ACSII字符
      chinese: "^[\\u4e00-\\u9fa5]+$", //仅中文
      color: "^[a-fA-F0-9]{6}$", //颜色
      date: "^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$", //日期
      email: "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", //邮件
      idcard: "^[1-9]([0-9]{14}|[0-9]{17})$", //身份证
      ip4: "^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$", //ip地址
      letter: "^[A-Za-z]+$", //字母
      letter_l: "^[a-z]+$", //小写字母
      letter_u: "^[A-Z]+$", //大写字母
      mobile: "0?(13|15|18)[0-9]{9}$", //手机
      notempty: "^\\S+$", //非空
      password: "^[A-Za-z0-9_-]+$", //密码
      picture: "(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$", //图片
      qq: "^[1-9]*[1-9][0-9]*$", //QQ号码
      rar: "(.*)\\.(rar|zip|7zip|tgz)$", //压缩文件
      tel: "^[0-9\-()（）]{7,18}$", //电话号码的函数(包括验证国内区号,国际区号,分机号)
      url: "^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$", //url
      username: "^[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+$", //用户名
      deptname: "^[A-Za-z0-9_()（）\\-\\u4e00-\\u9fa5]+$", //单位名
      zipcode: "^\\d{6}$", //邮编
      realname: "^[A-Za-z0-9\\u4e00-\\u9fa5]+$",  // 真实姓名
      companyname: "^[A-Za-z0-9_()（）\\-\\u4e00-\\u9fa5]+$",
      companyaddr: "^[A-Za-z0-9_()（）\\#\\-\\u4e00-\\u9fa5]+$",
      companysite: "^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&#=]*)?$"
  };
  
  
  ﻿//验证规则
  var validateRules = {
      isNull: function (str) {
          return(!(str == "" || typeof str != "string"));
      },
      betweenLength: function (str, _min, _max) {
          return (str.length >= _min && str.length <= _max);
      },
      isUid: function (str) {
          return new RegExp(validateRegExp.username).test(str);
      },
      isPwd: function (str) {
          return new RegExp(validateRegExp.password).test(str);
      },
      isPwd2: function (str1, str2) {
          return (str1 == str2);
      },
      isEmail: function (str) {
          return new RegExp(validateRegExp.email).test(str);
      },
      isTel: function (str) {
          return new RegExp(validateRegExp.tel).test(str);
      },
      isMobile: function (str) {
          return new RegExp(validateRegExp.mobile).test(str);
      },
      checkType: function (element) {
          return (element.attr("type") == "checkbox" || element.attr("type") == "radio" || element.attr("rel") == "select");
      },
      isChinese: function (str) {
          return new RegExp(validateRegExp.chinese).test(str);
      },
      isRealName: function (str) {
          return new RegExp(validateRegExp.realname).test(str);
      },
      isDeptname: function (str) {
          return new RegExp(validateRegExp.deptname).test(str);
      },
      isCompanyname: function (str) {
          return new RegExp(validateRegExp.companyname).test(str);
      },
      isCompanyaddr: function (str) {
          return new RegExp(validateRegExp.companyaddr).test(str);
      },
      isCompanysite: function (str) {
          return new RegExp(validateRegExp.companysite).test(str);
      }
      ,
      isMoney: function (str) {
          return new RegExp(validateRegExp.num).test(str);
      }  ,
      isQty: function (str) {
          return new RegExp(validateRegExp.intege1).test(str);
      }
  
  
  
  
  
  };
  
  
  
    
  
  var easyconfig ={ 
  	rulesFlg : "rules",
  	msgFlg: "msg",
  	validateFlg :"jeValidate",
  	 rules : validateRules,
  	 msg :validatePrompt
  };
  
  
  
  var easyValidate = function() {
  	var rulesFlg=easyconfig.rulesFlg;
  	var msgFlg = easyconfig.msgFlg; 
  	
  	this.init = function() {
  		this.CreateErrorHtml(); 
  		$("." + easyconfig.validateFlg).each(function(index, dom) {
  			var e = new easyDom(dom);
  			e.setFocus();
  		    e.setBlur();
  		    
  
  		});
  
  	};
  
  ///提交的时候验证所传递 的全部控件
  this.Check=function(doms){
  	var b = true;
  	$(doms).each(function(index,d) {
  	        
  	        var id = $(d).attr("id") + "_error";
  	        var e = new easyDom(d);
  			if(!e.domCheck(d))
  			 b=false;
  			e.setDomClass(d,b);  
  	});
  	return b; 
  };
  
  this.CreateErrorHtml = function() {
  
  	$("." + easyconfig.validateFlg).each(function(index, d) {
  		var e = document.createElement("span");
  		var id = $(d).attr("id") + "_error";
  		e.setAttribute("id", id);
  		e.setAttribute("class", "jeMsg");
  		$(d).after($(e));
  	});
  };
  
  
  
  
  
  };
  
  var easyDom = function(d) {
  
  	var dom = d;
  	var rules = $(dom).attr(easyconfig.rulesFlg);
  	var msg = $(dom).attr(easyconfig.msgFlg);
      var errorID=$(dom).attr("id") + "_error";
      ///设置获取焦点时候方法
  	this.setFocus = function() {
  
  		switch($(dom).attr("type")) {
  		default:
  			$(dom).bind('focus', function(event) { 
  				$("#" + errorID).html(easyconfig.msg[msg].onFocus);
  			});
  			break;
  		};
  
  	};
  
  ///设置移开时的方法
  	this.setBlur = function() {
  		switch($(dom).attr("type")) {
  		default:
  		     var check =this.domCheck;
  		     var setClass = this.setDomClass;
  			$(dom).bind('blur', function(event) {
  				 
  				var b =check(dom);
  				setClass(dom, b);
  			});
  
  			break;
  		};
  	};
  
  
  
  ///对dom进行验证
  	this.domCheck = function(dom) {
  
  		switch($(dom).attr("type")) {
  		default:
  			var value = $(dom).val();
  			return easyconfig.rules[rules](value);
  			break;
  		};
  	};
  
  ///设置css
  	this.setDomClass = function(dom,b) {
  		var errorID =$(dom).attr("id") + "_error";
  		if (!b) {
  			$("#" + errorID).html(easyconfig.msg[msg].error).removeClass('succeed').addClass("error");
  
  		} else {
  			$("#" + errorID).html(easyconfig.msg[msg].succeed).removeClass('error').addClass('succeed');
  		}
  	};
  };
  
  
  
  
  
  
  
  
  
  
  