//#------------------------------------------------
//#Create by Tom 2008-10-30
//#------------------------------------------------
$(document).ready(function(){
	//初始化验证
	$.formValidator.initConfig({onError:function(msg){alert(msg)}});

	//#留言
	$("#content").css({"font-size":"13px"});

	//#信息
	//#身份证
	$("#cumster_id").formValidator({onshow:"",onfocus:"请输入您的身份证",oncorrect:"",onempty:"证件号码不能为空"})
	.InputValidator({min:1,onerror:"证件号码不能为空"});
	
	//姓名验证
	$("#username").formValidator({onshow:"",onfocus:"请输入名称",oncorrect:"输入正确",onempty:"名称不能为空"})
	.InputValidator({min:1,onerror:"名称不能为空,请确认"});

	//设置生日日期控件
	if(document.getElementById("birthday")){
		$("#birthday").datepicker({
			yearRange : "1908:2018",
			dateFormat: 'yy-mm-dd'
		});
	}

	//生日日期
//	$("#birthday").formValidator({onshow:"",onfocus:"请填写生日",oncorrect:"输入正确"})
//	.InputValidator({min:1,onerror:"生日不能为空,请确认"});
	
	//邮箱验证
	$("#email").formValidator({onshow:"",onfocus:"邮箱至少6个字符,最多100个字符",onempty:"",oncorrect:"输入正确"})
	.InputValidator({min:6,max:100,onerror:"邮箱格式错误,请确认"})
	.RegexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"邮箱格式错误"});

	//手机验证
	$("#phone_mobile").formValidator({empty:false,onshow:"",onfocus:"请正确输入手机号码！",onempty:"",oncorrect:"输入正确",	onempty:"手机号码不能为空"})
	.InputValidator({min:11,max:11,onerror:"手机号码必须是11位的,请确认"})
	.RegexValidator({regexp:"^[1][0-9]{10}$",onerror:"手机格式错误"});
});

//#表单验证
function checkform(){
	if(checkleave()){
//		alert("进行到验证表单");
		if($.formValidator.PageIsValid('1'))
		{
			if(checkid()){
//	      		alert("前台验证成功！");
				return true;
			}else{
				return false;
			}
	
		}else{
			return false;
		}	
	}
	return false;	
}

function checkleave(){	
		title=$("#askitems").val();
		content=$("#content").val();
		areaidval = $("select[@name='areaid'] option[@selected]").val(); 
		if(title=="" || title=="0" || content=="" || areaidval==""){
			alert("请先填写所在城市,留言主题和内容，谢谢！");
			return false;		
		}else{
			return true;
		}
}

function checkid(){
	
	var type = 1;
	var id   = $('#cumster_id').val();
	var flag;	
	if(type == "1"){
		if(isCardID(id) == true){
			return true;
		}else{
			alert(isCardID(id));
			$("#cumster_id").select();
			$("#cumster_id")[0].scrollIntoView();
			return false;
		}
	}
	return true;	
}


