
	document.observe('dom:loaded', function(){
		$('error_summary').hide();
	});
	
	var errors = [];
	var account_errors = '';
	
	// validates the create account form
	function checkForm() {
		
		// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// check the HCP box
		$$('#forms .contentBox')[0].style['background'] = '#F0F0EB'; // reset the form element
		if ($F('account_hcp') != 'on') {
			$$('#forms .contentBox')[0].style['background'] = '#E8D4D4';
			errors[0] = snippet('validationhcp');
		}
		
		// reset the email field
		if ($('account_email_message') != null) $('account_email_message').remove();
		$('account_email_error').removeClassName('error');
		
		// check the email field
		if ($F('account_email') == '' || $F('account_email').indexOf('@') < 0 || $F('account_email').indexOf('.') < 0) {
			$('account_email_error').addClassName('error');
			$('account_email_error').insert({top: '<p id="account_email_message"><span class="errorOn">'+snippet('validationemail')+'</span></p>'});
			errors[1] = snippet('validationemail');
		}
		
		// reset the email  confirmation field
		if ($('account_email_confirm_message') != null) $('account_email_confirm_message').remove();
		$('account_email_confirm_error').removeClassName('error');
		
		// check the email confirmation field
		if ($F('account_email_confirm') == '' || $F('account_email_confirm') != $F('account_email')) {
			$('account_email_confirm_error').addClassName('error');
			$('account_email_confirm_error').insert({top: '<p id="account_email_confirm_message"><span class="errorOn">'+snippet('validationemailconfirm')+'</span></p>'});
			errors[2] = snippet('validationemailconfirm');
		}
		
		// reset the password field
		if ($('account_password_message') != null) $('account_password_message').remove();
		$('account_password_error').removeClassName('error');
		
		// check the password field
		if ($F('account_password').length < 6 || $F('account_password').length > 12) {
			$('account_password_error').addClassName('error');
			$('account_password_error').insert({top: '<p id="account_password_message"><span class="errorOn">'+snippet('validationpassword')+'</span></p>'});
			errors[3] = snippet('validationpassword');
		}
		
		// reset the password confirmation field
		if ($('account_password_confirm_message') != null) $('account_password_confirm_message').remove();
		$('account_password_confirm_error').removeClassName('error');
		
		// check the password confirmation field
		if ($F('account_password').length < 6 || $F('account_password').length > 12 || $F('account_password_confirm') != $F('account_password')) {
			$('account_password_confirm_error').addClassName('error');
			$('account_password_confirm_error').insert({top: '<p id="account_password_confirm_message"><span class="errorOn">'+snippet('validationpassword')+'</span></p>'});
			errors[4] = snippet('validationpasswordconfirm');
		}
		
		// reset the firstname field
		if ($('account_firstname_message') != null) $('account_firstname_message').remove();
		$('account_firstname_error').removeClassName('error');
		
		// check the firstname field
		if ($F('account_firstname') == '') {
			$('account_firstname_error').addClassName('error');
			$('account_firstname_error').insert({top: '<p id="account_firstname_message"><span class="errorOn">'+snippet('validationfirst')+'</span></p>'});
			errors[5] = snippet('validationfirst');
		}
		
		// reset the lastname field
		if ($('account_lastname_message') != null) $('account_lastname_message').remove();
		$('account_lastname_error').removeClassName('error');
		
		// check the lastname field
		if ($F('account_lastname') == '') {
			$('account_lastname_error').addClassName('error');
			$('account_lastname_error').insert({top: '<p id="account_lastname_message"><span class="errorOn">'+snippet('validationlast')+'</span></p>'});
			errors[6] = snippet('validationlast');
		}
		
		// reset the speciality field
		if ($('account_speciality_message') != null) $('account_speciality_message').remove();
		$('account_speciality_error').removeClassName('error');
		
		// check the speciality field
		if ($F('account_speciality') == '' || $F('account_speciality') == snippet('validationpleaseselect')) {
			$('account_speciality_error').addClassName('error');
			$('account_speciality_error').insert({top: '<p id="account_speciality_message"><span class="errorOn">'+snippet('validationspeciality')+'</span></p>'});
			errors[7] = snippet('validationspeciality');
		}
		
		// highlight the errors at the top of the page
		if (errors.length > 0) {
			$('error_summary').show();
			account_errors = '<h3>'+snippet('validationfields')+':</h3>';
			account_errors += '<ul>';
			for (i = 0; i < errors.length; i++ ){
				if (errors[i] != null) {
					account_errors += '<li id="errorFields">' + errors[i] + '</li>';
				}
			}
			account_errors += '</ul>';
			$('error_summary').innerHTML = account_errors;
			return false;
		}
		
	}
	
	
	// validates the manage profile form
	function checkProfileForm() {
		
		// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// reset the email field
		if ($('account_email_message') != null) $('account_email_message').remove();
		$('account_email_error').removeClassName('error');
		
		// check the email field
		if ($F('account_email') == '' || $F('account_email').indexOf('@') < 0 || $F('account_email').indexOf('.') < 0) {
			$('account_email_error').addClassName('error');
			$('account_email_error').insert({top: '<p id="account_email_message"><span class="errorOn">'+snippet('validationemail')+'</span></p>'});
			errors[1] = snippet('validationemail');
		}
		
		// reset the email  confirmation field
		if ($('account_email_confirm_message') != null) $('account_email_confirm_message').remove();
		$('account_email_confirm_error').removeClassName('error');
		
		// check the email confirmation field
		if ($F('account_email_confirm') == '' || $F('account_email_confirm') != $F('account_email')) {
			$('account_email_confirm_error').addClassName('error');
			$('account_email_confirm_error').insert({top: '<p id="account_email_confirm_message"><span class="errorOn">'+snippet('validationemailconfirm')+'</span></p>'});
			errors[2] = snippet('validationemailconfirm');
		}
		
		// reset the password field
		if ($('account_password_message') != null) $('account_password_message').remove();
		$('account_password_error').removeClassName('error');
		
		// check the password field
		// form can be submitted with the password field empty
		if ($F('account_password').length > 0) {
			if ($F('account_password').length < 6 || $F('account_password').length > 12) {
				$('account_password_error').addClassName('error');
				$('account_password_error').insert({top: '<p id="account_password_message"><span class="errorOn">'+snippet('validationpassword')+'</span></p>'});
				errors[3] = snippet('validationpassword');
			}
		}
		
		// reset the password confirmation field
		if ($('account_password_confirm_message') != null) $('account_password_confirm_message').remove();
		$('account_password_confirm_error').removeClassName('error');
		
		// check the password confirmation field
		// form can be submitted with the password field empty
		if ($F('account_password').length > 0) {
			if ($F('account_password').length < 6 || $F('account_password').length > 12 || $F('account_password_confirm') != $F('account_password')) {
				$('account_password_confirm_error').addClassName('error');
				$('account_password_confirm_error').insert({top: '<p id="account_password_confirm_message"><span class="errorOn">'+snippet('validationpasswordconfirm')+'</span></p>'});
				errors[4] = snippet('validationpasswordconfirm');
			}
		}
		
		// reset the firstname field
		if ($('account_firstname_message') != null) $('account_firstname_message').remove();
		$('account_firstname_error').removeClassName('error');
		
		// check the firstname field
		if ($F('account_firstname') == '') {
			$('account_firstname_error').addClassName('error');
			$('account_firstname_error').insert({top: '<p id="account_firstname_message"><span class="errorOn">'+snippet('validationfirst')+'</span></p>'});
			errors[5] = snippet('validationfirst');
		}
		
		// reset the lastname field
		if ($('account_lastname_message') != null) $('account_lastname_message').remove();
		$('account_lastname_error').removeClassName('error');
		
		// check the lastname field
		if ($F('account_lastname') == '') {
			$('account_lastname_error').addClassName('error');
			$('account_lastname_error').insert({top: '<p id="account_lastname_message"><span class="errorOn">'+snippet('validationlast')+'</span></p>'});
			errors[6] = snippet('validationlast');
		}
		
		// reset the speciality field
		if ($('account_speciality_message') != null) $('account_speciality_message').remove();
		$('account_speciality_error').removeClassName('error');
		
		// check the speciality field
		if ($F('account_speciality') == '' || $F('account_speciality') == snippet('validationpleaseselect')) {
			$('account_speciality_error').addClassName('error');
			$('account_speciality_error').insert({top: '<p id="account_speciality_message"><span class="errorOn">'+snippet('validationspeciality')+'</span></p>'});
			errors[7] = snippet('validationspeciality');
		}
		
		// highlight the errors at the top of the page
		if (errors.length > 0) {
			$('error_summary').show();
			account_errors = '<h3>'+snippet('validationfields')+':</h3>';
			account_errors += '<ul>';
			for (i = 0; i < errors.length; i++ ){
				if (errors[i] != null) {
					account_errors += '<li id="errorFields">' + errors[i] + '</li>';
				}
			}
			account_errors += '</ul>';
			$('error_summary').innerHTML = account_errors;
			return false;
		}
		
	}
	
	// validates the login form
	function checkLoginForm() {
		
		// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// reset the email field
		if ($('account_email_message') != null) $('account_email_message').remove();
		$('account_email_error').removeClassName('error');
		
		// check the email field
		if ($F('credential_0') == '' || $F('credential_0').indexOf('@') < 0 || $F('credential_0').indexOf('.') < 0) {
			$('account_email_error').addClassName('error');
			$('account_email_error').insert({top: '<p id="account_email_message"><span class="errorOn">'+snippet('validationemail')+'</span></p>'});
			errors[1] = snippet('validationemail');
		}
		
		// reset the password field
		if ($('account_password_message') != null) $('account_password_message').remove();
		$('account_password_error').removeClassName('error');
		
		// check the password field
		if ($F('credential_1').length < 6 || $F('credential_1').length > 12) {
			$('account_password_error').addClassName('error');
			$('account_password_error').insert({top: '<p id="account_password_message"><span class="errorOn">'+snippet('validationpassword')+'</span></p>'});
			errors[3] = snippet('validationpassword');
		}
		
		// highlight the errors at the top of the page
		if (errors.length > 0) {
			$('error_summary').show();
			account_errors = '<h3>'+snippet('validationfields')+':</h3>';
			account_errors += '<ul>';
			for (i = 0; i < errors.length; i++ ){
				if (errors[i] != null) {
					account_errors += '<li id="errorFields">' + errors[i] + '</li>';
				}
			}
			account_errors += '</ul>';
			$('error_summary').innerHTML = account_errors;
			return false;
		}
		
	}
	
	// validates the manage login form
	function checkPasswordForm() {
		
		// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// reset the email field
		if ($('account_email_message') != null) $('account_email_message').remove();
		$('account_email_error').removeClassName('error');
		
		// check the email field
		if ($F('account_email') == '' || $F('account_email').indexOf('@') < 0 || $F('account_email').indexOf('.') < 0) {
			$('account_email_error').addClassName('error');
			$('account_email_error').insert({top: '<p id="account_email_message"><span class="errorOn">'+snippet('validationemail')+'</span></p>'});
			errors[1] = snippet('validationemail');
		}
		
		// highlight the errors at the top of the page
		if (errors.length > 0) {
			$('error_summary').show();
			account_errors = '<h3>'+snippet('validationfields')+':</h3>';
			account_errors += '<ul>';
			for (i = 0; i < errors.length; i++ ){
				if (errors[i] != null) {
					account_errors += '<li id="errorFields">' + errors[i] + '</li>';
				}
			}
			account_errors += '</ul>';
			$('error_summary').innerHTML = account_errors;
			return false;
		}
		
	}