// JavaScript Document
var app_path = "";
var root_path = 'http://'+window.location.hostname+"/"+app_path+"";
//ajax 单值验证
function check(value,fun,type,resultId){
	var v = value;
	var result = $(resultId);
	result.empty();
	result.html('<img src="reg_files/loading.gif" alt="loading..." />');
	$.post('action/mc_register.php',{'ajaxValue':v,'type':type,'ajax':1,'fun':fun},function(data){
		if(parseInt(data)===1){
			result.empty();
			result.html('<img src="reg_files/right.gif" alt="right" />');
		}else{
			result.empty();
			result.html(data);
		}																				 
	});
}

//check username
$('#username').blur(function(){
	check($(this).val(),'check','username','#result1');						  
});

//check pwd
$('#pwd').blur(function(){
	check($(this).val(),'check','pwd','#result2');						  
});

//confirm pwd
$('#confirmPwd').blur(function(){
	if(	($('#confirmPwd').val().replace(/(^\s*)|(\s*$)/g, "")!='') && ($('#confirmPwd').val() == $('#pwd').val()) )
	{
		$('#result3').empty();
		$('#result3').html('<img src="reg_files/right.gif" alt="right" />');
	}
	else
	{
		$('#result3').empty();
		$('#result3').html('两次密码不一致');	
	}				  
});

//check email
$('#email').blur(function(){
	check($(this).val(),'check','email','#result4');						  
});

//ajax 整个表单验证
$('#form1').submit(function(){
	//alert($('#promotion').val());
	$('#errorMess').html('<img src="reg_files/loading.gif" alt="loading..." align="absmiddle" />请稍候');
	$('#submit_button').attr('disabled','disabled');
	
		$.post('action/mc_register.php',$(this).serialize(),function(data){
		if(data != "1"){
			$('#errorMess').empty();
			$('#errorMess').html(data);	
			$('#errorMess').attr('style','display:yes');
			$('#errorMess').addClass('errorMess');
			$('#submit_button').removeAttr('disabled','disabled');
		}
		else{
	  		alert('注册成功！欢迎加入爱上游戏网！');
	  		window.location.href='http://www.23game.net';
	  	}
	   });
	
	return false;
});