
//闰年检测
function leapYear (theyear) {
	if (((theyear % 4)==0) && ((theyear % 100)!=0) ||
		((theyear % 400)==0)) return true;
    else return false;
}

function setMonthday(theyear, themonth, theday) {
	//_y = f.year; _m = f.month; _d = f.day;
	var monthday = new Array(31, (leapYear(theyear)? 29:28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	_d.options.length = themonth-1;
	theday = (theday > monthday[themonth-1])? monthday[themonth-1] : theday;
	_d.options[0] = new Option("日 ","");
	for(i=1;i<=monthday[themonth-1];i++) {
		eval("_d.options[i] = new Option(\"" + i + "\", \"" + ((i<10)?'0'+i:i) + "\", false, (theday==i)?true:false)");
	}
	_d.options[theday].selected = true;
}
function changeit() {
	//_y = f.year; _m = f.month; _d = f.day;
	_theyear  = (_y.options[_y.selectedIndex].value!='')? _y.options[_y.selectedIndex].value : _y.options[1].value;
	_themonth = (_m.options[_m.selectedIndex].value!='')? _m.options[_m.selectedIndex].value : _m.options[1].value;
	_theday   = _d.selectedIndex;
	setMonthday(_theyear, _themonth, _theday);
}

/*
注册相关
*/
function validatePhone(obj){
	var str = obj.value;
	if(!checkByteLength(str,7,11)) return 1;
	var patn = /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[0-9]\d{6,8}(\-\d{1,4})?$/;
	if(!patn.test(str)){
	   return 1;//incorrect format
	}
	return 0;
}

function checkByteLength(str,minlen,maxlen) {
	if (str == null) return false;
	var l = str.length;
	var blen = 0;
	for(i=0; i<l; i++) {
		if ((str.charCodeAt(i) & 0xff00) != 0) {
			blen ++;
		}
		blen ++;
	}
	if (blen > maxlen || blen < minlen) {
		return false;
	}
		return true;
}

function checkUsername(){
      $('#usernametip').html("")	   
      if($('#username').val().length>2){
		 $.ajax({
				 url:'?action=chkuser&t='+Math.random(),
				 type:'GET',
				 data:'username='+encodeURIComponent($('#username').val()),
				beforeSend: function(XMLHttpRequest){
					$('#usernametip').html("正在查询中...");
				},
				 success:function(data, textStatus){
					 $('#usernametip').html(data);
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('用户名数据查询错误');
				 }
		  });
	  } else {
		$('#usernametip').html("<font color='red'>可以包括数字、字母(不分大小写)、汉字, 长度为3～12位</font>");
	  }
}

function checkEmail(){
      if($('#email').val().length>2){
		 $.ajax({
				 url:'?action=chkemail',
				 type:'GET',
				 data:'email='+$('#email').val(),
				beforeSend: function(XMLHttpRequest){
					$('#emailtip').html("正在查询中...");
				},
				 success:function(data, textStatus){
					 $('#emailtip').html(data);
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('邮箱数据查询错误');
				 }
		  });
	  }
}

function checkMobile(){
      if($('#mobile').val().length>2){
		 $.ajax({
				 url:'?action=chkmobile',
				 type:'GET',
				 data:'mobile='+$('#mobile').val(),
				beforeSend: function(XMLHttpRequest){
					$('#mobiletip').html("正在查询中...");
				},
				 success:function(data, textStatus){
					 $('#mobiletip').html(data);
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('手机数据查询错误');
				 }
		  });
	  }
}

function checkIdCard(){
      if($('#idcard').val().length>2){
		 $.ajax({
				 url:'?action=chkidcard',
				 type:'GET',
				 data:'idcard='+$('#idcard').val(),
				beforeSend: function(XMLHttpRequest){
					$('#idcardtip').html("正在查询中...");
				},
				 success:function(data, textStatus){
					 $('#idcardtip').html(data);
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('身份证数据查询错误');
				 }
		  });
	  }
}

function sendSmsToPhone(){
      
      if($('#mobile').val().length>7){
		 $.ajax({
				 url:'ajaxcomm.asp?action=SendSmsRegCode',
				 type:'POST',
				 data:'mobile='+$('#mobile').val() + "&t=" + Math.random(),
				beforeSend: function(XMLHttpRequest){
					
				},
				 success:function(data, textStatus){
                       eval(data);
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('手机验证码发送错误');
				 }
		  });
	  } else {
        alert("请填写您的手机号!");
	  }
}

function sendSmsToEmail(){
      
      if($('#email').val().length>0){
		 $.ajax({
				 url:'sendmails.asp?action=SendSmsRegCode',
				 type:'POST',
				 data:'email='+$('#email').val() + "&t=" + Math.random(),
				beforeSend: function(XMLHttpRequest){
					
				},
				 success:function(data, textStatus){
				 },
				complete: function(XMLHttpRequest, textStatus){
				},
				 error:function(){
					 alert('邮箱验证码发送错误');
				 }
		  });
	  } else {
        alert("请填写您的电子邮箱!");
	  }
}

function checkPassword(){
      $('#pwdtip').html("")	   
      if($('#pwd').val().length<6||$('#pwd').val().length>12){
         $('#pwdtip').html("<font color='red'>密码长度限定在6-12位</font>")
	  } else {
         $('#pwdtip').html("<font color='green'>密码设置正确</font>")
	     if($('#repwd').val().length>0) checkRePassword();
	  }
}
function checkRePassword(){
      $('#repwdtip').html("")
      if($('#pwd').val().length>0){		  
		  if($('#repwd').val()!=$('#pwd').val()){
			 $('#repwdtip').html("<font color='red'>两次密码输入不一致请检查</font>")
		  } else {
			 $('#repwdtip').html("<font color='green'>两次密码输入一致</font>")
		  }
	  }
}

function openWin(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
}
