jQuery.validator.setDefaults({
	success: "valid"
});;

$.validator.addMethod("validurl", function(value) {
	if (value.indexOf('.') > 0) {
		return true;
	} else {
		return false
	};
}, '请输入网站地址');

$.validator.addMethod("validurlwww", function(value) {
	if (value.substring(0, 7).toLowerCase() == 'http://') {
		return false;
	};
	
	if (value.substring(0, 3).toLowerCase() == 'www') {
		return false;
	};
	
	return true;
}, '请输入网站地址');

$(document).ready(function() {
	$('a#show_agreement').click(function() {
		if ($('div.signup_agreement_div').is(':hidden')) {
			$('div.signup_agreement_div').slideDown('slow');
		} else {
			$('div.signup_agreement_div').hide();
		}
	});
	
	$('#reload_pic').click(function() {
		var t = new Date().getTime();
		$('#SecurityImages').attr('src', '/Others/SecurityImages/' + t);
	});
	
	$('#cs').change(function() {
		// window.alert(this.value);
		if (this.value && this.value > 0) {
			set_cs($('#cs').val());
			$('#cs_tip').slideDown('slow');
		} else {
			$('#cs_tip').hide();
		};
	});
	
	$('#signup_form').validate({
		rules: {
			email: {
				required: true,
				email: true,
				remote: "/Others/ValidateEmail/"
			},
			password: {
				required: true,
				minLength: 6,
				maxLength: 18
			},
			cs: {
				minValue: 10
			},
			web_title: "required",
			web_url: {
				required: true,
				validurlwww: true,
				validurl: true
			},
			web_rank: {
				required: true,
				digits: true,
				rangeValue: [1, 1000000]
			},
			bank_branch: "required",
			bank_account: "required",
			bank_cardnum: {
				required: true,
				digits: true
			},
			realname: "required",
			idcard: {
				required: true,
				minLength: 15,
				maxLength: 18
			},
			phone: "required",
			mobile: {
				required: true,
				digits: true,
				minLength: 11,
				maxLength: 11
			},
			qq: {
				required: true,
				digits: true,
				minLength: 5,
				maxLength: 12
			},
			address: {
				required: true,
				minLength: 10
			},
			postcode: {
				required: true,
				digits: true,
				rangeValue: [00000, 999999]
			},
	//		validate_code: "required",
			agree: "required"
		},
		messages: {
			email: {
				required: "请输入E-Mail地址",
				email: "E-Mail地址不合法",
				remote: "E-Mail地址已经有人使用"
			},
			password: {
				required: "请输入密码",
				minLength: "密码必须要6位以上",
				maxLength: "密码不能超过18位"
			},
			cs: "请选择业务联系人员",
			web_title: "请输入网站标题",
			web_url: {
				required: "请输入网站地址",
				validurlwww: "网站地址不需要添加www或http://",
				validurl: "网站地址非法"
			},
			web_rank: {
				required: "请输入网站排名",
				digits: "排名只接受数字",
				rangeValue: "网站排名必须要在100万名以内"
			},
			bank_branch: "请输入开户行",
			bank_account: "请输入户名",
			bank_cardnum: {
				required: "请输入卡号",
				digits: "卡号只接受数字"
			},
			realname: "请输入真实姓名",
			idcard: {
				required: "请输入身份证号码",
				digits: "身份证号码只接受数字",
				minLength: "身份证号码少于15位",
				maxLength: "身份证号码大于18位"
			},
			phone: "请输入联系电话",
			mobile: {
				required: "请输入手机号码",
				digits: "手机号码只接受数字",
				minLength: "手机号码非法",
				maxLength: "手机号码非法"
			},
			qq: {
				required: "请输入QQ号码",
				digits: "QQ号码只接受数字",
				minLength: "QQ号码少于5位",
				maxLength: "QQ号码大于12位"
			},
			address: {
				required: "请输入联系地址",
				minLength: "联系地址长度不对"
			},
			postcode: {
				required: "请输入邮政编码",
				digits: "邮政编码只接受数字",
				rangeValue: "邮政编码非法"
			},
	//		validate_code: "请输入验证码",
			agree: " "
		},
        success: function(label) { 
            // set   as text for IE 
            label.html(" ").addClass("valid"); 
        }
	});
	
	if ($('#cs').val() && $('#cs').val() > 0) {
		set_cs($('#cs').val());
		$('#cs_tip').slideDown('slow');
	};
});

function set_cs(value) {
	$('#cs_tip').html('你所选择的业务人员联系QQ是 '+ value +' <a target="qqchat" href="tencent://message/?uin='+ value +'&Site=满意广告&Menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=1:'+ value +':5" alt="点击这里给我发消息"></a>');
}
