$(document).ready(function(){
	//--日历
	$("#txtTimeBegin").datepicker();
	$("#txtTimeEnd").datepicker();
	$("#ddlSuitType").change(function(){
		var suittype=$(this).val();
		switch(suittype){
			case '所有':
				$("#suittypename").hide();
				$("#tbSuitValue").val('all').hide();
				break;
			case '类别':
				$("#suittypename").html('类别编号').show();
				$("#tbSuitValue").show();
				break;
			case '品牌':
				$("#suittypename").html('品牌ID').show();
				$("#tbSuitValue").show();
				break;
			case '商品':
				$("#suittypename").html('商品ID').show();
				$("#tbSuitValue").show();
				break;
		}
	});
	$("#ddlSuitType").change();
	$.validator.methods.strlen= function(value,element,param){
       var  str =$(element).val();
       var  len =0;
       for(var i=0;i<str.length;i++){
          if(str.charCodeAt(i)>255){
             len +=2;
          }
          else{
             len +=1;
          }
       }
       return (len -param)<=0;
	}
	$("#Form1").validate({
		event: "keyup",
		rules: {
			txtCouponName: {
				required: true,
				strlen:100
			},
			txtCouponValue: {
				required: true,
				number:true,
				range: [0,999999]
			},
			txtOrderMoneyFrom: {
				required: true,
				number:true,
				range: [0,999999]
			},
			txtTimeBegin: {
				required: true
			},
			txtTimeEnd: {
				required: true
			},
			txtDescription: {
				strlen:100
			}
		},
		
		messages: {
			txtCouponName: {
				required: "请输入优惠券名称",
				strlen: "最大长度只能在50个汉字(100个字符)以内"
			},
			txtCouponValue: {
				required: "请输入优惠券面值",
				range: "请输入合法的优惠券面值(1-999999)"
			},
			txtOrderMoneyFrom: {
				required: "请输入优惠券面值",
				range: "请输入合法的优惠券面值(1-999999)"
			},
			txtTimeBegin: {
				required: "请选择优惠券开始时间"
			},
			txtTimeEnd: {
				required: "请选择优惠券结束时间"
			},
            txtDescription: {
				strlen: "最大长度只能在50个汉字(100个字符)以内"
			}
		},
		debug:"false",
		submitHandler:function(form){
			//$(form).ajaxSubmit();
			form.submit();
		}
	});
});//end document.ready