function Register()
{
	var gender = $("#rdoSexBoy")[0].checked ? "0" : "1";
	var name = $("#txtName")[0].value;
	if(name =="")
	{
			alert("Name can't be empty.");
			return;
	}
	var birthDay = $("#txtBirthDay")[0].value;
	if(birthDay =="")
	{
				alert("BirthDay can't be empty.");
			return;
	}
	var addr = $("#txtAddr")[0].value;
	if(addr =="")
	{
			alert("Address can't be empty.");
			return;
	}
	var postCode = $("#txtPostCode")[0].value;
	if(postCode =="")
	{
			alert("PostCode can't be empty.");
			return;
	}
	var city = $("#txtCity")[0].value;
	if(city =="")
	{
			alert("City can't be empty.");
			return;
	}
	var province = $("#txtProvince")[0].value;
	if(province =="")
	{
			alert("Province can't be empty.");
			return;
	}
	var telPhone = $("#txtPhone")[0].value;
	if(telPhone =="")
	{
			alert("Phone can't be empty.");
			return;
	}
	var icq = $("#txtICQ")[0].value;
	var country = $("#txtCountry")[0].value;
	if(country =="")
	{
			alert("Country can't be empty.");
			return;
	}
	var introducer = $("#txtIntroduce")[0].value;
	var guid = "";
    var joinNews = $("#rdoJoinNews")[0].checked ? "0" : "1";
	var email = $("#txtRegEmail")[0].value;
	if(email =="")
	{
			alert("Name can't be empty.");
			return;
	}
	else
	{
		var re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(!re.test(email))
		{
			alert("Email format error.");				
			return;
		}				
	}	
	var account = $("#txtAccount")[0].value;
	if(account =="")
	{
			alert("AccountName can't be empty.");
			return;
	}
	var password = $("#txtPassword1")[0].value;
	if(password =="")
	{
			alert("Account Password not empty.");
			return;
	}
	var repassword = $("#txtPassword2")[0].value;
	if(repassword =="")
	{
			alert("Re-Type Password not empty.");
			return;
	}
	if(password != repassword)
	{
		alert("The confirming password doesn't match. ");
		return;
	}
	
	var result = game.register.Register(gender, name, birthDay, addr, postCode, city, province, telPhone, icq, country, introducer, guid, email, account, password);
	if(result != null && result.value == "1")
	{
		window.location = "/";
	}
	else
	{
		alert("register faild!");
	}
}

function CheckEmail(ref)
{
	if(ref.value == "")
	{
		return;
	}
	else
	{
		var result = game.register.CheckEmail(ref.value);
		if(result != null && result.value == "1")
		{
			alert("Email has exits!");
			ref.value = "";
		}
	}
}

function CheckAccount(ref)
{
	if(ref.value == "")
	{
		return;
	}
	else
	{
		var result = game.register.CheckCustomerID(ref.value);
		if(result != null && result.value == "1")
		{
			alert("AccountName has exits!");
			ref.value = "";
		}
	}
}

function CheckIntroduce(ref)
{
	if(ref.value == "")
	{
		return;
	}
	else
	{
		var result = game.register.CheckIntroducerID(ref.value);
		if(result == null || result.value == "0")
		{
			alert("Introduce not exits!");
			ref.value = "";
		}
	}
}

function CheckGuid(ref)
{
	if(ref.value == "")
	{
		return;
	}
	else
	{
		var result = game.register.CheckGuildID(ref.value);
		if(result == null || result.value == "0")
		{
			alert("Guid not exits!");
			ref.value = "";
		}
	}
}

function ii_Changed(me)
{
	var fa = me.value;
	if(fa == "0")
	{
		$('#i1').css("display", "block");
		$('#i2').css("display", "none");
	}
	else
	{
		$('#i1').css("display", "none");
		$('#i2').css("display", "block");
	}
}
