function add_member()
{
	var username = textToEntities(document.all["username"].value);
	var password = textToEntities(document.all["password"].value);
	var security_code = document.all["security_code"].value;
	var save = document.all["save"].value;
	var url = "Register/Add_Member.php";
	
	if (web_req == null){web_req = Inint_AJAX();}
	web_req.abort();

	web_req.onreadystatechange = function(){
		if (web_req.readyState == 4) 
		{
			if (web_req.status == 200) 
			{
				var data = web_req.responseText.split("#");
				
				switch (data[1])
				{
					case "1" : { 
							     document.getElementById("msg").style.display = "";
								 document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Security code incorrect</div></div>";
							  	 top.location.href = "#error";								 
								 break; 
							   }
					case "2" : { top.location.href="index.php";break; }
					case "3" : { 
								 document.getElementById("msg").style.display = "";
								 document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>This username is already in use by another member.</div></div>";
							     top.location.href = "#error";								 
								 break; 
							   }
					case "4" : { 
								 document.getElementById("msg").style.display = "";
								 document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>This password is already in use by another member.</div></div>";
								 top.location.href = "#error";								 
								 break; 
							   }

					default	 : {
								 top.location.href = "index.php";
								 //document.getElementById("register").innerHTML= "<div id='box_border'><div class='msgbox'>Registration successful</div></div>";
								 //load_stats(); 
							   	 break;
							   }
				}
			}
		}
	};
	web_req.open("POST", url, true);
	web_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
	web_req.send("username=" + username + "&password=" + password + "&security_code=" + security_code + "&save=" + save);
}

function valid_action_register()
{
	document.all["username"].value = trim(document.all["username"].value);
	document.all["password"].value = trim(document.all["password"].value);
	document.all["verify_password"].value = trim(document.all["verify_password"].value);
	document.all["security_code"].value = trim(document.all["security_code"].value);

	var username = document.all["username"].value;
	var password = document.all["password"].value;
	var verify_password = document.all["verify_password"].value;
	var security_code = document.all["security_code"].value;

	if (username.length == 0)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Please enter a username</div></div>";
		top.location.href = "#error";
		return;
	}

	if (username.length < 5)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Username low - 5 character minimum</div></div>";
		top.location.href = "#error";		
		return;
	}

	if (password.length == 0)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Please enter a password</div></div>";
		top.location.href = "#error";		
		return;
	}
	
	if (password.length < 5)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Password low - 5 character minimum</div></div>";
		top.location.href = "#error";		
		return;
	}

	if (verify_password.length == 0)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Please enter a verify password</div></div>";
		top.location.href = "#error";		
		return;
	}

	if (password != verify_password)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Verify password incorrect</div></div>";
		top.location.href = "#error";		
		return;
	}

	if (security_code.length == 0)
	{
		document.getElementById("msg").style.display = "";
		document.getElementById("msg").innerHTML= "<div id='box_border'><div class='msgbox'>Please enter a security code</div></div>";
		top.location.href = "#error";		
		return;
	}

	add_member();
}
