﻿XN.DOM.readyDo(function(){
	$('regEmail').setAttribute('rule','blank#regName');
	$('regEmail').setAttribute('tip','<p>重要！请填有效邮箱地址完成注册。</p>');
	$('pwd').setAttribute('rule','blank#length:6,20');
	$('pwd').setAttribute('tip','<p>请确保你的密码有效，便于下次正常登陆。密码由6-20个英文字母数字或特殊字符组成。<br/></p>');
	$('name').setAttribute('rule','blank#realName');
	$('name').setAttribute('tip','<p>请一定填写你的<b style="color:red">真实中文姓名</b></p>');
	$('birth_year').setAttribute('rule','blank');
	$('birth_year').setAttribute('error','请填写您的出生年份');
	$('birth_month').setAttribute('rule','blank');
	$('birth_month').setAttribute('error','请填写您的出生月份');
	$('birth_day').setAttribute('rule','blank');
	$('birth_day').setAttribute('error','请填写您的出生日期');
	$('homeprovince').setAttribute('rule','blank');
	$('homeprovince').setAttribute('error','请您选择省份');
	$('homecitycode').setAttribute('rule','blank');
	$('homecitycode').setAttribute('error','请您选择城市');
	$('icode').setAttribute('rule','blank#verifyCode');
	$('accept').setAttribute('rule','check');
	$('accept').setAttribute('error','请阅读开心网服务条款');
	$('ismsn').setAttribute('rule','custom:ismsnok');
	
	XN.ARRAY.each($('regform').gender,function(i,v){
		if(isElement(v)){
			v.setAttribute('rule','selectOne');
			v.setAttribute('error','您还没有选择性别');
		}
	});
	
	window.ismsnok = function(){
		$('waiting').style.display="block";
		var req = new XN.NET.xmlhttp({
			url:'/ajxmsnchk.do',
			data:'uAccount='+$('regEmail').value+'&importer=@hotmail.com&pwd=' + $('pwd').value,
			asynchronous:false
		});
		var msg = XN.STRING.trim(req.transport.responseText);
		
		/*if(msg == '<ret>0</ret>'){
			$('msnValid').value = '1';
			$('waiting').style.display="none";
			$('checkmsn_ok').style.display="none";
			return true;
		}else{
			$('waiting').style.display="none";
			$('checkmsn_ok').style.display="block";
			return false;
		}*/
		if(msg == '<ret>0</ret>')
		{
			$('msnValid').value = '1';
		}
		$('waiting').style.display="none";
		$('checkmsn_ok').style.display="none";
		return true;
	};
	
	check1 = new XN.FORM.autoChecker({
		id:'regform',
		alertMethod:'div',
		tipMethod:'tip'
		//submit:'reg_sub'
	});
	XN.FORM.checkPasswordStrength('pwd',function(r){
		if($('pwdScore'))$('pwdScore').style.backgroundPosition = '0 -' + ((5 - r.level) * 30) + 'px';
		if($('pwdStrength'))$('pwdStrength').innerHTML = r.strength;
	});
	
	window.refreshCode = function(){
		var el = $('verifyPic');
		if(XN.BROWSER.IE6){
			new Image().src = el.src + 'x';
		}
		el.src += 'x';
	}
	XN.event.addEvent('birth_month' , 'change' , function()	{
		chageDate();
	})
	window.chageDate = function() {
		var year = parseInt($('birth_year').value);
		var month = parseInt($('birth_month').value);
		var day = parseInt($('birth_day').value);
		var monthLength = 30;
		_o = parseFloat(year)/4;
		if (XN.array.include([1, 3, 5,  7, 8, 10, 12],month)) {
			monthLength = 31;
		} 
		else if (month == 2) {
			monthLength =  (_o == Math.ceil(_o)) ? 29 : 28;
		}
		$('birth_day').options.length = 0;
		
		$('birth_day').options[0] = new Option('--', '');
		for (var i = 0; i < monthLength; i++) {
			if ((i + 1) < 10){
			$('birth_day').options[i + 1] = new Option('0' + (i +1), '0' + (i +1));
			}
			else if ((i + 1) > 9){
			$('birth_day').options[i + 1] = new Option(i +1, i +1);
			}
			else
			if (i +1 == day) {
				$('birth_day').options[i + 1].selected = true;
			}
		}

	}
	document.onkeydown = function(e) {
		e = e || event;
		var c = e.keyCode || e.which;
		if(c == 13) $('regform').submit();
	}
});