<!--
var reInteger = /^\d+$/
function isWhitespace(s)
{   
	return ((s == null) || (s.length == 0))
}
function isNum(s)
{   
	if (reInteger.test(s))
		return false;
	else
		return true;
}
function isEqual(s1,s2)
{   
	if (s1!=s2)
		return false;
	else
		return true;
}
function isChked(s)
{
	for(i=0;i<s.length;i++){
	if(s[i].checked)
	break;
	}
	return (i==s.length);
}

function isEmail(s)
{  
    var uch = /[A-Za-z0-9][A-Za-z0-9-_.]{0,252}/i;
    var dch = /[A-Za-z0-9][A-Za-z0-9-]{0,252}/i;
    var och = /[A-Za-z]{2,4}/i;
    var i = 1;
    var nm = -1;
    var dnms = new Array(1);
	var sLength = s.length - 1;
    while(i < sLength && s.charAt(i) != '@'){
 	i++;
    }
    if(i== sLength){
	 return false;
    }
	else atset = i;
    // look for .
    while (i < sLength-1){
	i++;
	if(s.charAt(i) == '.'){
	    nm++;
	    dnms[nm]=i;
	}
    }
    if(s.substr(0,atset) != s.substr(0,atset).match(uch) || s.substr(dnms[nm]+1) != 
s.substr(dnms[nm]+1).match(och) || s.substring(atset+1,dnms[0]) != 
s.substring(atset+1,dnms[0]).match(dch)){
	return false;
    }else
    {
	for(;nm>0;nm--){
	    if(s.substring(dnms[nm-1]+1,dnms[nm]) != 
s.substring(dnms[nm-1]+1,dnms[nm]).match(dch)){
			return false;
	    }
	}		
    }
return true;
}

function check(theForm)
{
	var password = theForm.password.value;
	var pass1 = theForm.pass1.value;
	var question = theForm.question.value;
	var answer  = theForm.answer.value;
	var trueName = theForm.trueName.value;
	var card = theForm.card.value;
	var cardtype = theForm.cardtype.value;
	var year=theForm.year.value;
	var month=theForm.month.value;
	var day=theForm.day.value;
  var telephone=theForm.telephone.value;
  var mobile=theForm.mobile.value;
	var email=theForm.email.value;
	var sex = theForm.sex;
	var address = theForm.address.value;
	var postcode = theForm.postcode.value;
	var province = theForm.province.value;
	var tempd = month;
	var ins = theForm.hobbies.length;
//	var mag = theForm.maginfo.length;
	if (isWhitespace(password)) 
	{
		alert("密码不能为空!");
		theForm.password.focus();
		return false;
	}
	if (isWhitespace(pass1)) 
	{
		alert("请确认密码!");
		theForm.pass1.focus();
		return false;
	}
  	if (!isEqual(pass1,password)) 
	{
		alert("密码确认未通过校验!");
		theForm.pass1.focus();
		return false;
	}
	if (isWhitespace(question)) 
	{
		alert("密码提示问题不能为空!");
		theForm.question.focus();
		return false;
	}
	if (question.length>240) 
	{
		alert("密码提示问题不能多于240个字符!");
		theForm.question.focus();
		return false;
	}
	if (isWhitespace(answer) || (answer.length>240) ) 
	{
		alert("提示问题答案不能为空且不能多于240个字符");
		theForm.answer.focus();
		return false;
	}
	if (isWhitespace(trueName)) 
	{
		alert("请填写真实姓名");
		theForm.trueName.focus();
		return false;
	}
	if(isChked(sex))
	{
		alert("请选择性别");
		return false;
	}

	if (isNum(year) || year.length != 4|| parseInt(year) < 1930 || year > "1992")
	{
		alert("年份必需为正确的4位数字!");
		theForm.year.focus();
		return false;
	}

	if (isWhitespace(day))
	{
		alert("生日日期不能为空!");
		theForm.day.focus();
		return false;
	}
	if(isNum(day)){
		alert("生日日期格式不正确!");
		theForm.day.focus();
		return false;

	}
	td = new Date(year,eval(month-1),day);
		if(td.getDate()!=day)
		{
			alert("生日日期不正确,请重新填写");
			return false;
		}

	if(month.length==1)
		tempd = "0"+tempd;

	tempd = year.substring(2,2) + tempd;

	if(day.length==1)
		tempd = tempd+"0"+day;
	else
		tempd += day;

	if(cardtype == "身份证" && card.indexOf(tempd) < 0 ){
			alert("生日日期和身份证号码不符，请重新填写");
			theForm.card.focus();
			return false;
	}
	if (isWhitespace(card) || card.length < 6 || (cardtype == "身份证" && card.length != 15 && card.length != 18)) 
	{
		alert("请正确填写有效证件号码");
		theForm.card.focus();
		return false;
	}

	if (isWhitespace(telephone) || telephone.length < 8) 
	{
     	  alert("请填写电话号码");
	  theForm.telephone.focus();
     	  return false;
	}
  	if ( !isWhitespace(mobile) && mobile.length < 10 && isNum(mobile) ) {
	    alert("请正确填写手机号码");
	    theForm.mobile.focus();
	    return false;
	}
	if(!isEmail(email)){
     	 alert("请正确填写电子邮件地址");
	 theForm.email.focus();
         return false;
  	}
	if (isWhitespace(province) || province.length < 2) 
	{
		alert("请选择所在省份或地区");
		theForm.province.focus();
		return false;
	}
	if (isWhitespace(address) || address.length < 6) 
	{
		alert("请正确填写通讯地址");
		theForm.address.focus();
		return false;
	}
	if (isWhitespace(postcode) || postcode.length < 6 || isNum(postcode)) 
	{
		alert("请填写邮编");
		theForm.postcode.focus();
		return false;
	}

	theForm.birthday.value = year + "年" + month +"月"+ day+"日";
//	theForm.interest.value="";
//	theForm.mag_info.value="";

	for(i=0;i<ins;i++){
		if(theForm.hobbies[i].checked)
			theForm.interest.value += theForm.hobbies[i].value; 
	}
/*	for(i=0;i<mag;i++){
		if(theForm.maginfo[i].checked)
			theForm.mag_info.value = theForm.mag_info.value + theForm.maginfo[i].value + ":"; 
	}
*/
}
