function registerAccount() {
	
	var errors = "";
	var ereminder = 0;
	var brainstorm = 0;
	
	if ($("chkEReminder").checked) ereminder = 1;
	if ($("chkBrainstorm").checked) brainstorm = 1;
	
	if (!$("selType").value) errors += "Choose a Type\n";
	if ($("selType").value == 2) {
		if (!$("txtDegree").value) errors += "Degree\n";
		if (!$("txtSpecialty").value) errors += "Specialty\n";
		if (!$("txtHospital").value) errors += "Hospital Affiliation\n";
	}
	if (!$("txtEmail").value || !isValidEmail($("txtEmail").value)) errors += "E-mail Address\n";
	if (!$("txtForumName").value) errors += "Username / Forum Alias\n";
	if (!$("txtPassword1").value || !$("txtPassword2").value) errors += "Password\n";
	if ($("txtPassword1").value != $("txtPassword2").value) errors += "Passwords do not match\n";
	if (!$("txtFirstName").value) errors += "First Name\n";
	if (!$("txtLastName").value) errors += "Last Name\n";
	if (!$("txtCity").value) errors += "City\n";
	if (!$("selState").value && $("selCountry").value == "United States") errors += "State\n";
	if (!$("txtPostal").value && $("selCountry").value == "United States") errors += "Postal Code\n";
	if (!$("selCountry").value) errors += "Country\n";
	if (!$("chkAgree").checked) errors += "Agree to Terms & Conditions\n";
	
	if (errors.length > 0) alert("The following information was missing or invalid:\n\n" + errors);
	else {
		var url = "http://methodisthealth.or-live.com/vbtb/assets/ajax/register.cfm";
		new Ajax.Request(url, {
			method: "post",
			parameters: {
				type: $("selType").value,
				email: $("txtEmail").value,
				password: $("txtPassword1").value,
				fname: $("txtFirstName").value,
				lname: $("txtLastName").value,
				city: $("txtCity").value,
				state: $("selState").value,
				postal: $("txtPostal").value,
				country: $("selCountry").value,
				phone: $("txtPhone").value,
				forumName: $("txtForumName").value,
				degree: $("txtDegree").value,
				specialty: $("txtSpecialty").value,
				hospital: $("txtHospital").value,
				ereminder: ereminder,
				brainstorm: brainstorm
			},
			onSuccess: function(transport) {
				if (transport.responseText == "SUCCESS") {
					alert("Thank you for registering for the Virtual Brain Tumor Board!\nYou are now signed in.");
					window.location.reload();
				}
				else alert(transport.responseText);
			},
			onFailure: function(transport) {
				alert("Registration request failed. Please notify support.");
			}
		});
	}
	
}

//WITHOUT lightbox
function registerAccount2() {

	var errors = "";
	var ereminder = 0;
	var brainstorm = 0;
	
	if ($("chkEReminder").checked) ereminder = 1;
	if ($("chkBrainstorm").checked) brainstorm = 1;
	
	if (!$("selType").value) errors += "Choose a Type\n";
	if ($("selType").value == 2) {
		if (!$("txtDegree").value) errors += "Degree\n";
		if (!$("txtSpecialty").value) errors += "Specialty\n";
		if (!$("txtHospital").value) errors += "Hospital Affiliation\n";
	}
	if (!$("txtEmail").value || !isValidEmail($("txtEmail").value)) errors += "E-mail Address\n";
	if (!$("txtForumName").value) errors += "Username / Forum Alias\n";
	if (!$("txtPassword1").value || !$("txtPassword2").value) errors += "Password\n";
	if ($("txtPassword1").value != $("txtPassword2").value) errors += "Passwords do not match\n";
	if (!$("txtFirstName").value) errors += "First Name\n";
	if (!$("txtLastName").value) errors += "Last Name\n";
	if (!$("txtCity").value) errors += "City\n";
	if (!$("selState").value && $("selCountry").value == "United States") errors += "State\n";
	if (!$("txtPostal").value && $("selCountry").value == "United States") errors += "Postal Code\n";
	if (!$("selCountry").value) errors += "Country\n";
	if (!$("chkAgree").checked) errors += "Agree to Terms & Conditions\n";
	
	if (errors.length > 0) alert("The following information was missing or invalid:\n\n" + errors);
	else {

		var url = "./assets/ajax/register.cfm";
		new Ajax.Request(url, {
			method: "post",
			parameters: {
				type: $("selType").value,
				email: $("txtEmail").value,
				password: $("txtPassword1").value,
				fname: $("txtFirstName").value,
				lname: $("txtLastName").value,
				city: $("txtCity").value,
				state: $("selState").value,
				postal: $("txtPostal").value,
				country: $("selCountry").value,
				phone: $("txtPhone").value,
				forumName: $("txtForumName").value,
				degree: $("txtDegree").value,
				specialty: $("txtSpecialty").value,
				hospital: $("txtHospital").value,
				ereminder: ereminder,
				brainstorm: brainstorm
			},
			onSuccess: function(transport) {
				if (transport.responseText == "SUCCESS") {
					alert("Thank you for registering for the Virtual Brain Tumor Board!\nYou are now signed in.");
					//window.location.reload();
					window.location.href= "http://www.or-live.com/channels/methodist/vbtb";
				}
				else alert(transport.responseText);
			},
			onFailure: function(transport) {
				alert("Registration request failed. Please notify support.");
			}
		});
	}
	
}

function setType(id) {
	if (id == 1) setNonPhysician();
	if (id == 2) setPhysician();
}

function setPhysician() {
	$("trRegRow1").show();
	$("trRegRow2").show();
	$("trRegRow3").show();
	$("trRegRow4").show();
}

function setNonPhysician() {
	$("trRegRow1").hide();
	$("trRegRow2").hide();
	$("trRegRow3").hide();
	$("trRegRow4").hide();
	$("txtDegree").clear();
	$("txtSpecialty").clear();
	$("txtHospital").clear();
}

function isValidEmail(email) {
	var at = email.indexOf("@");
	if (at < 1) return false;
	var afterat = email.substring(at + 1);
	var dot = afterat.indexOf(".");
	if (dot < 1 || dot >= afterat.length - 2) return false;
	return true;
}

function showTermsConditions() {
	window.open("http://methodisthealth.or-live.com/vbtb/terms.html", "winTerms", "width=420,height=310,status=0,toolbar=0,scrollbars=0,menubar=0,location=0,resizable=1");
}

function showTermsConditions2() {
	window.open("http://methodisthealth.or-live.com/vbtb/terms2.html", "winTerms", "width=420,height=310,status=0,toolbar=0,scrollbars=0,menubar=0,location=0,resizable=1");
}

function resetPassword() {
	
	var errors = "";
	
	if (!$("txtForgotEmail").value || !isValidEmail($("txtForgotEmail").value)) errors += "E-mail Address\n";
	if (!$("txtForgotCity").value) errors += "City\n";
	if (!$("txtForgotPassword1").value || !$("txtForgotPassword2").value) errors += "Password\n";
	if ($("txtForgotPassword1").value != $("txtForgotPassword2").value) errors += "Passwords do not match\n";
	
	if (errors.length) alert("The following information was missing or invalid:\n\n" + errors);
	else {
		var url = "http://methodisthealth.or-live.com/vbtb/assets/ajax/reset_pw.cfm";
		new Ajax.Request(url, {
			method: "post",
			parameters: {
				email: $("txtForgotEmail").value,
				city: $("txtForgotCity").value,
				password: $("txtForgotPassword1").value
			},
			onSuccess: function(transport) {
				if (transport.responseText == "SUCCESS") {
					alert("Your password has been updated successfully! Please sign in with your e-mail address and the new password.");
					window.location.reload();
				}
				else alert(transport.responseText);
			},
			onFailure: function(transport) {
				alert("Reset password request failed. Please notify support.");
			}
		});
	}
}