/*
>--------------------------------------------------------------------------------<
| CREDITS INFORMATION															 |
>--------------------------------------------------------------------------------<
| Created By: Benny McLennan													 |
| File Name: registerAJAX.js													 |
| File Location: javascripts/ajax												 |
| Generic Description: All registering AJAX methods for the BMF Generic Framework|
| Date Created: May 20th 2009													 |
| Date Edited: N/A																 |
| Copyright: © Army Roster 2008 - 2009											 |
>--------------------------------------------------------------------------------<
| Website: http://www.armyroster.com											 |
| Website Restriction: Level 0 													 |
| Important Notes: Required on every page of the website. Website runs off AJAX  |
| Date Installed: May 27th 2009	 												 |
| Date Modified: N/A															 |
|																				 |
| Notes: If you wish to use this script, please feel free. No permission is 	 |
|        required. We would, however, like a brief email notifying us of your use|
| 		 of our script(s). 														 |
| 						 														 |
|		 Thank you,																 |
|		 Benny																	 |
>--------------------------------------------------------------------------------<
*/
var Agreement = 2;

function agreement(action) {
	if (action == 'check') {
		Agreement = 1;
		document.getElementById('Agreement').onclick = function() {agreement('uncheck')};
	}
	if (action == 'uncheck') {
		Agreement = 2;
		document.getElementById('Agreement').onclick = function() {agreement('check')};
	}	
}

function register (){
	if ((document.getElementById("SubmitRegister").RegUsername.value=="") || (document.getElementById("SubmitRegister").RegUsername.value=="Username") || (document.getElementById("SubmitRegister").RegUsername.value=="Please enter your username")) {
		noErrors = false;
		var usernameError = "Please enter your username<br />";
		document.getElementById("SubmitRegister").RegUsername.style.color = "#ff0000";
		document.getElementById("SubmitRegister").RegUsername.value = "Please enter your username";
	} else {
		var usernameError = "";
		var username = document.getElementById("SubmitRegister").RegUsername.value;
	}
	
	if ((document.getElementById("SubmitRegister").RegPassword.value=="") || (document.getElementById("SubmitRegister").RegPassword.value=="Password") || (document.getElementById("SubmitRegister").RegPassword.value=="Please enter your password")) {
		noErrors = false;
		var passwordError = "Please enter your password<br />";
	}  else {
		var passwordError = "";
		var password = document.getElementById("SubmitRegister").RegPassword.value;
	}
	
	if ((document.getElementById("SubmitRegister").ConfirmRegPassword.value=="") || (document.getElementById("SubmitRegister").ConfirmRegPassword.value=="Confirm Password") || (document.getElementById("SubmitRegister").ConfirmRegPassword.value=="Please confirm your password")) {
		noErrors = false;
		var confirmPasswordError = "Please confirm your password<br />";
	}  else {
		var confirmPasswordError = "";
		var confirmPassword = document.getElementById("SubmitRegister").ConfirmRegPassword.value;
	}
	
	if ((document.getElementById("SubmitRegister").EmailAddress.value=="") || (document.getElementById("SubmitRegister").EmailAddress.value=="Email Address") || (document.getElementById("SubmitRegister").EmailAddress.value=="Please enter your email address")) {
		noErrors = false;
		var emailError = "Please enter your email address<br />";
		document.getElementById("SubmitRegister").EmailAddress.style.color = "#ff0000";
		document.getElementById("SubmitRegister").EmailAddress.value = "Please enter your email address";
	}  else {
		var emailError = "";
		var email = document.getElementById("SubmitRegister").EmailAddress.value;
	}
	
	if ((document.getElementById("SubmitRegister").ConfirmEmailAddress.value=="") || (document.getElementById("SubmitRegister").ConfirmEmailAddress.value=="Confirm Email Address") || (document.getElementById("SubmitRegister").ConfirmEmailAddress.value=="Please confirm your email address")) {
		noErrors = false;
		var confirmEmailError = "Please confirm your email address<br />";
		document.getElementById("SubmitRegister").ConfirmEmailAddress.style.color = "#ff0000";
		document.getElementById("SubmitRegister").ConfirmEmailAddress.value = "Please confirm your email address";
	}  else {
		var confirmEmailError = "";
		var confirmEmail = document.getElementById("SubmitRegister").ConfirmEmailAddress.value;
	}

	if ((document.getElementById("SubmitRegister").ImageVerification.value=="") || (document.getElementById("SubmitRegister").ImageVerification.value=="Verification Code") || (document.getElementById("SubmitRegister").ImageVerification.value=="Please verify the image")) {
		noErrors = false;
		var veriImageError = "Please verify the image<br />";
		document.getElementById("SubmitRegister").ImageVerification.style.color = "#ff0000";
		document.getElementById("SubmitRegister").ImageVerification.value = "Please verify the image";
	}  else {
		var veriImageError = "";
		var veriImage = (document.getElementById("SubmitRegister").ImageVerification.value.toUpperCase());
	}

	if (Agreement == 2) {
		noErrors = false;
		var agreementError = "You must agree to our \"Legal Agreement\" before continuing with your registration";
	} else {
		var agreementError = "";
	}
	if (noErrors == true) {
		if ((document.getElementById("SubmitRegister").FirstName.value=="") || (document.getElementById("SubmitRegister").FirstName.value=="First Name")) {
			var firstName = "";
		} else {
			var firstName = document.getElementById("SubmitRegister").FirstName.value;
		}
		if ((document.getElementById("SubmitRegister").LastName.value=="") || (document.getElementById("SubmitRegister").LastName.value=="Last Name")) {
			var lastName = "";
		} else {
			var lastName = document.getElementById("SubmitRegister").LastName.value;
		}
		var day = document.getElementById("SubmitRegister").BirthDay.value;
		var month = document.getElementById("SubmitRegister").BirthMonth.value;
		var year = document.getElementById("SubmitRegister").BirthYear.value;
	
		$.ajax({
		beforeSend: loadingScript(),
		type: "POST",
		url: "validatescripts/register/ajax/register.inc.php",
		data: "FirstName=" + encodeURIComponent(firstName) + "&LastName=" + encodeURIComponent(lastName) + "&BirthDay=" + encodeURIComponent(day) + "&BirtMonth=" + encodeURIComponent(month) + "&BirthYear=" + encodeURIComponent(year) + "&Username=" + encodeURIComponent(username) + "&Password=" + encodeURIComponent(password) + "&ConfirmPassword=" + encodeURIComponent(confirmPassword) + "&EmailAddress=" + encodeURIComponent(email) + "&ConfirmEmailAddress=" + encodeURIComponent(confirmEmail) + "&VeriImage=" + encodeURIComponent(veriImage),
		success: function (responseText) 
			{
				if (responseText == 69) {
					javascript:document.getElementById("ContentMain").innerHTML = "<div id=\"SectionHeader\">Registration Success</div><div id=\"scroll\">Scroll</div><div id=\"scrollAnchor\">ContentMain</div><div id=\"MainHeader\"><div id=\"RegistrationHeader\"></div></div><div class=\"MainBody\"><table class=\"Table\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"CellTitle\" colspan=\"2\"><span class=\"whitetitletext\">Your registration has been successful</span></td></tr><tr><td class=\"CellEven\">Thank you for registering with Army Roster. You should be recieving an activation email shortly. Please follow the link in the email to complete your account registration.<br /><br />Start your time on Army Roster by checking out the <a href=\"home.php#action=forums\" onclick=\"newhash('action=forums'); return false;\" title=\"Sponsor\">forums</a> and meeting our awesome community.<br /><br />If you find yourself visiting Army Roster frequently then we would kindly ask you to consider a <a href=\"home.php#action=subscribe\" onclick=\"newhash('action=subscribe'); return false;\" title=\"Sponsor\">Sponsor Membership</a>.<br /><br />Along with the feeling of support for your community, you will also recieve tons of amazing bonuses and features on the website. As well as getting all of the past and current issues of our E-Magazine <a href=\"home.php#action=documents&doc=thepowderkeg\" onclick=\"newhash('action=documents&doc=thepowderkeg'); return false;\" title=\"The Powder Keg\">The Power Keg\</a>.<br /><br />To see a full list of all of the benefits you will recieve from Sponsoring, <a href=\"home.php#action=subscribe\" onclick=\"newhash('action=subscribe'); return false;\" title=\"Sponsor\">click here</a><br /><br />Thank you again for signing up to Army Roster!<br /><br />Regards,<br />Benny and the Army Roster Crew!</td><td class=\"CellOdd\"><img src=\"images/statusicons/RegistrationComplete.gif\" alt=\"Registration Complete\" /></td></tr><tr><td class=\"CellFooter\" colspan=\"2\"></td></tr></table></div></div><div class=\"MainFooter\"></div>";
					loadedScript();
				} else {
					javascript:document.getElementById("RegisterError").innerHTML = "<br /><span class=\"redtext\">The following errors occurred:</span><span class=\"yellowtext\"><br />" + responseText + "</span>";
					loadedScript();
				}
			}
		});		
	} else {
		javascript:document.getElementById("RegisterError").innerHTML = "<br /><span class=\"redtext\">The following errors occurred:</span><span class=\"yellowtext\"><br />".concat(usernameError,passwordError,confirmPasswordError,emailError,confirmEmailError,veriImageError,agreementError) + "</span>";
		noErrors = true;
	}
}

function resetpassword (){
	if ((document.getElementById("SubmitReset").EmailAddress.value=="") || (document.getElementById("SubmitReset").EmailAddress.value=="Email Address") || (document.getElementById("SubmitReset").EmailAddress.value=="Please enter your email address")) {
		noErrors = false;
		var emailError = "Please enter your email address<br />";
		document.getElementById("SubmitReset").EmailAddress.style.color = "#ff0000";
		document.getElementById("SubmitReset").EmailAddress.value = "Please enter your email address";
	}  else {
		var emailError = "";
		var email = document.getElementById("SubmitReset").EmailAddress.value;
	}
	
	if ((document.getElementById("SubmitReset").ImageVerification.value=="") || (document.getElementById("SubmitReset").ImageVerification.value=="Verification Code") || (document.getElementById("SubmitReset").ImageVerification.value=="Please verify the image")) {
		noErrors = false;
		var veriImageError = "Please verify the image<br />";
		document.getElementById("SubmitReset").ImageVerification.style.color = "#ff0000";
		document.getElementById("SubmitReset").ImageVerification.value = "Please verify the image";
	}  else {
		var veriImageError = "";
		var veriImage = (document.getElementById("SubmitReset").ImageVerification.value.toUpperCase());
	}

	if (noErrors == true) {
		$.ajax({
		beforeSend: loadingScript(),
		type: "POST",
		url: "validatescripts/register/ajax/resetpassword.inc.php",
		data: "EmailAddress=" + encodeURIComponent(email) + "&VeriImage=" + encodeURIComponent(veriImage),
		success: function (responseText) 
			{
				if (responseText == 69) {
					javascript:document.getElementById("ContentMain").innerHTML = "<div id=\"SectionHeader\">Registration Success</div><div id=\"scroll\">Scroll</div><div id=\"scrollAnchor\">ContentMain</div><div id=\"MainHeader\"><div id=\"RegistrationHeader\"></div></div><div class=\"MainBody\"><table class=\"Table\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"CellTitle\"><span class=\"whitetitletext\">Password reset request has been sent</span></td></tr><tr><td class=\"CellEven\">If you have suddenly remembered your password then just ignore the email we sent you.<br /><br />Once you have followed the reset link in the email we have sent you, you can change your password in your Profile Control</td></tr><tr><td class=\"CellFooter\"></td></tr></table></div></div><div class=\"MainFooter\"></div>";
					loadedScript();
				} else {
					javascript:document.getElementById("ResetError").innerHTML = "<br /><span class=\"redtext\">The following errors occurred:</span><span class=\"yellowtext\"><br />" + responseText + "</span>";
					loadedScript();
				}
			}
		});
	} else {
		javascript:document.getElementById("ResetError").innerHTML = "<br /><span class=\"redtext\">The following errors occurred:</span><span class=\"yellowtext\"><br />".concat(emailError,veriImageError) + "</span>";
		noErrors = true;
	}
}

