$(document).ready(function(){
    setInterval(function(){
        if(getQueryStringRegExp('from') != 'list'){
		        $('div.sub_container_content').css('height',$(window.parent.frames.right).height()-$(".sub_container_title").height()-10); //设置内容区域的高度
        }else{//从列表页面链接过来修改
		        var windowHeight = $('#frmHeight',window.parent.document).val();
		        $('div.sub_container_content').css('height',windowHeight-$(".sub_container_title").height()-10); //设置内容区域的高度
	        }
        },1000);
    $('#btnShowTxt').toggle(function(){
        $('#modify').show();
        $(this).val('取消');
    },function(){
        $('#modify').hide();
        $('#txtChangeScore').val('0');
        $(this).val('修改积分');
    });				

    $('#btnShowTxtS').toggle(function(){
        $('#modifyS').show();
        $(this).val('取消');
    },function(){
        $('#modifyS').hide();
        $('#txtChangeSpending').val('0');
        $(this).val('修改积分');
    });				

    if('<%=Request.QueryString["from"] %>' == 'list'){
        $('#btnCancel').click(function(){
            $('#frmModify',window.parent.document).hide().siblings(':not("#loadingContainer")').show();
            window.parent.BindList();
            return false;
        });
    };

    function CheckMoney(obj){
	    var dot = 0;//小数点个数
	    var tmp = obj.val();
	    while(tmp.indexOf('.') != -1){
		    dot += 1;
		    tmp = tmp.replace('.','_');
	    };
	    var reg = new RegExp(/[^\d\.]/g);
        if(parseInt($(obj).val().Trim())>2147483647){
            alert("消费金额太大");
            obj.focus();
            return false;
        }
	    if(reg.test(obj.val()) || obj.val().Trim() == '' || dot > 1){
		    alert('消费金额填写错误');
		    obj.focus();
		    return false;
	    };
    }

    function checkLoginStatus(data){
        var result = true;
        if(data.indexOf('<!DOCTYPE') != -1){
            result = false;
            alert('身份已过期,请重新登陆!');
        };
        return result;
    };

    $('#ddlTopAreas').change(function(){
        $('#ddlSubAreas').remove();$('#ddlThirdAreas').remove();
        if($(this).val() == '0'){return false;};
        var areas = $('#hideAddressIDs').val().split(',');
        $.ajax({
            url:'Actions.aspx?Nocopyright=1&Action=GetSubArea&ParentID=' + $('#ddlTopAreas').val(),
            cache:false,
            success:function(data){
                if(!checkLoginStatus(data)){return false;}//是否要重新登陆
                var objSubArea = $('<select id="ddlSubAreas" name="ddlSubAreas" class="searchvalue"></select>');
                objSubArea.html(data);
                objSubArea.insertAfter($('#ddlTopAreas'));
                if(areas[1]){objSubArea.val(areas[1])};
                objSubArea.change(function(){
                    $('#ddlThirdAreas').remove();
                    if($(this).val() == '0'){return false;};
                    $.ajax({
                        url:'Actions.aspx?Nocopyright=1&Action=GetSubArea&ParentID=' + $('#ddlSubAreas').val(),
                        cache:false,
                        success:function(data){
                            if(!checkLoginStatus(data)){return false;}//是否要重新登陆
                            var objthirdarea = $('<select id="ddlThirdAreas" name="ddlThirdAreas" class="searchvalue"></select>');
                            objthirdarea.html(data).insertAfter($('#ddlSubAreas'));
                            if(areas[2]){objthirdarea.val(areas[2])};
                        },error:function(){}
                    });
                }).change();
            },error:function(){alert('get address error');}
        });//end ajax
    }).change();//end change
    
    $.validator.methods.scorerange= function(value,element,param){
        var mode=$(":radio[name='rbMode']:checked").val();
        if(mode=="0"){
            var  changescore =$(element).val();
            var  score =$("#txtScore").val();
            return changescore<=score;
        }else{
            return true;
        }
	}
                
	$("#Form1").validate({
        event: "keyup",
        rules: {
	        txtName: {
		        required: true,
		        maxlength:100
	        },
	        txtPassword: {
	            required:true,
                rangelength:[6,16]
            },
            
	        txtPassword2: {
		        required: true,
                equalTo:"#txtPassword"
	        },
	        txtEmail: {
	            required:true,
	            email:true
	        },
	        txtChangeScore:{
	            digits:true,
	            scorerange:true
	        },
	        txtChangeSpending:{
	            number:true	            
	        },
	        txtBirthday:{
	            dateISO:true
	        }
        },
        messages: {
	        txtName: {
		        required: "会员名称必填",
		        maxlength: "最大长度只能在(100个字符)以内"
	        },
	        txtPassword: {
                required: "用户密码必填",
                range: jQuery.validator.format("请输入{0}和{1}之间的字符串")                
	        },
	        txtPassword2: {
		        required: "确认密码必填",
                equalTo:"两次输入的密码不一致"

	        },
	        txtEmail: {
                required:"电子邮箱地址必填",
		        email: "请输入合法的邮箱地址"
	        },
	        txtChangeScore:{
	            digits:"积分必须是整数",
	            scorerange:"减少积分不能大于当前积分"
	        },
	        txtChangeSpending:{
	            number:"消费金额必须是数字"
	        },
	        txtBirthday:{
	            dateISO:"日期格式不合法"
	        }
        },
        debug:"false",
        submitHandler:function(form){
	        form.submit();
        }
    });           
});//end ready