
	function SendConfirm(r) {
		if(!r) {
			var url = "account.php";
			var data = "&Operation=sendconfirm&Email=" + escape($('ConfirmEmail').value);
			var request = new Ajax.Request(url,{method: 'post', parameters: data, onComplete: SendConfirm});				
			ProgressButton('SendConfirmButton');
		}
		else if(r.responseText.indexOf("SUCCESS") >= 0) {
			alert("Confirmation Email Sent.\nPlease check your email.");
			$('SendConfirmButton').value = "Re-Send Confirmation Email";
		}
		else
			alert(r.responseText);
	}
	
	function CreateAccount(r) {
		if(!r) {
			var status = 0;
			for(var i = 0; i < document.forms['AccountForm'].Status.length; i++)
				if(document.forms['AccountForm'].Status[i].selected)
					status = document.forms['AccountForm'].Status[i].value;
			var year = 0;
			for(var i = 0; i < document.forms['AccountForm'].Year.length; i++)
				if(document.forms['AccountForm'].Year[i].selected)
					year = document.forms['AccountForm'].Year[i].value;
			if((document.forms['AccountForm'].Name.value.length < 2) || (document.forms['AccountForm'].Name.value.length > 30))
				alert("Please enter a valid Name");
			else if(document.forms['AccountForm'].Email.value != document.forms['AccountForm'].Email2.value)
				alert("Your Emails do not match.");
			else if((document.forms['AccountForm'].LastName.value.length < 2) || (document.forms['AccountForm'].LastName.value.length > 30))
				alert("Please enter a valid Last Name");
			else if((document.forms['AccountForm'].Password.value.length < 4) || (document.forms['AccountForm'].Password.value.length > 20))
				alert("Please enter a valid Password (4-20 characters).");
			else if(document.forms['AccountForm'].Password.value != document.forms['AccountForm'].Password2.value)
				alert("Your passwords do not match.");
			else if(status == 0)
				alert("Please select your Status as a student.");
			else if((year < 2000) || (year > 2025))
				alert("Please select your graduation Year.");
			else if((document.forms['AccountForm'].Email.value.indexOf(".edu") < 1) && (($('SchoolWebsite').value == "www.school.edu") || ($('SchoolWebsite').value == ""))) {
				$('SchoolWebsiteRow').style.visibility = "visible";
				alert("Please enter the website address for your school.");
			}
			else {
				$('CreateAccountButton').value = "Please Wait...";
				$('CreateAccountButton').disabled = true;
				var url = "account.php";
				var data = "&Operation=createaccount&Email=" + escape(document.forms['AccountForm'].Email.value);
				data += "&Name=" + escape(document.forms['AccountForm'].Name.value);
				data += "&LastName=" + escape(document.forms['AccountForm'].LastName.value);
				data += "&Year=" + escape(year);
				data += "&Status=" + escape(status);
				data += "&Password=" + escape(document.forms['AccountForm'].Password.value);
				data += "&SchoolWebsite=" + escape($('SchoolWebsite').value);
				var request = new Ajax.Request(url,{method: 'post', parameters: data, onComplete: CreateAccount});								
			}			
		}
		else if(r.responseText.indexOf("SUCCESS") >= 0) {
			$('CreateAccountButton').value = "Account Created. Please Wait...";
			window.location.href = "editschedule.php?NewAccount=1";
		}
		else {
			$('CreateAccountButton').value = "Create Account";
			$('CreateAccountButton').disabled = false;			
			alert(r.responseText);		
		}
	}
	
	function SignIn(r) {
		if(!r) {
			if((document.forms['AccountForm'].SignInEmail.value.length < 2) || (document.forms['AccountForm'].SignInEmail.value.length > 90) || (document.forms['AccountForm'].SignInEmail.value.indexOf("@") < 0))
				alert("Please enter a valid Email address");
			else if((document.forms['AccountForm'].SignInPassword.value.length < 4) || (document.forms['AccountForm'].SignInPassword.value.length > 20))
				alert("Please enter a valid Password.");
			else {
				$('SignInButton').value = "Please Wait...";
				$('SignInButton').disabled = true;
				var url = "account.php";
				var data = "&Operation=signin&Email=" + escape(document.forms['AccountForm'].SignInEmail.value);
				data += "&Password=" + escape(document.forms['AccountForm'].SignInPassword.value);
				var request = new Ajax.Request(url,{method: 'post', parameters: data, onComplete: SignIn});												
			}			
		}
		else if(r.responseText == "CONFIRM") {
			window.location.href = "account.php?Confirm=1&Email=" + escape(document.forms['AccountForm'].SignInEmail.value);
		}
		else if(r.responseText == "SUCCESS") {
			$('SignInButton').value = "Signed In.  Please wait...";
			window.location.href = "schedule.php";
		}
		else {
			$('SignInButton').value = "Login";
			$('SignInButton').disabled = false;			
			alert("Error:\n" + r.responseText);
		}
	}