//registerCode.js
//This javascript code helps us with registration, and deals with the register tab
//By: Max Sklar, Sunday, June 11th, 2006

function enterRegisterMode() {
	makeInvisible('map_table');
	doWithFile("registration.php", false, function(text) {
		document.getElementById('registration_container').innerHTML = text;
	});
}

function exitRegisterMode() {
	makeVisible('map_table');
	document.getElementById('registration_container').innerHTML = "";
}

function onSubmitRegisterForm() {
	var ourForm = document.forms["registerForm"];
	
	var password = ourForm.elements["password"].value;
	var confirm = ourForm.elements["confirmation"].value;
	
	if (confirm != password) {
		password = encrypt(password);
		confirm = -1;
	}
	else {
		password = encrypt(password);
		confirm = password;
	}
	
	var wantsUpdates;
	if (ourForm.elements["wantsUpdates"].checked) wantsUpdates = 1;
	else wantsUpdates = 0;
	
	var post = "username=" + ourForm.elements["username"].value;
	post += "&password=" + password;
	post += "&confirmation=" + confirm;
	post += "&email=" + ourForm.elements["email"].value;
	post += "&fname=" + ourForm.elements["fname"].value;
	post += "&mname=" + ourForm.elements["mname"].value;
	post += "&lname=" + ourForm.elements["lname"].value;
	post += "&address" + ourForm.elements["address"].value;
	post += "&city=" + ourForm.elements["city"].value;
	post += "&state=" + ourForm.elements["state"].value;
	post += "&zip=" + ourForm.elements["zip"].value;
	post += "&submitting=" + ourForm.elements["submitting"].value;
	post += "&wantsUpdates=" + wantsUpdates;
	
	postWithFile("registration.php", false, post, function(text) {
		document.getElementById('registration_container').innerHTML = text;
	});
}