
	document.observe('dom:loaded', function(){
		if ($('error_summary')) $('error_summary').hide();
	});
	
	var errors = [];
	var account_errors = '';

	function validateSignup() {

	// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// reset the fields
		resetErrorField(['signup_email', 'signup_country']);
		
		
		if ($F('fld_email') == '' || $F('fld_email').indexOf('@') < 0 || $F('fld_email').indexOf('.') < 0) {
			$('signup_email_error').addClassName('error');
			$('signup_email_error').insert({top: '<p id="signup_email_message" class="errorOn">'+snippet('validationemail')+'</p>'});
			errors[1] = snippet('validationemail');
		}
		// check the country field
		if ($('fld_country').selectedIndex==0) {
			$('signup_country_error').addClassName('error');
			$('signup_country_error').insert({top: '<p id="signup_country_message" class="errorOn">'+snippet('validationcountry')+'</p>'});
			errors[2] = snippet('validationcountry');
		}
		
		// 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;
			} else return true;
	}
	
	function resetErrorField(arr) {
		for (var i=0;i<arr.length;i++) {
			if ($(arr[i]+'_message') != null) $(arr[i]+'_message').remove();
			$(arr[i]+'_error').removeClassName('error');
		}
	}

	function validateContactform() {
			
		// hide the error summary
		$('error_summary').hide();
		
		// reset all the fields prior to re-validation
		account_errors = '';
		errors = [];
		
		// reset the fields
		resetErrorField(['contact_title', 'contact_firstname', 'contact_lastname', 'contact_message', 'contact_country', 'contact_email']);
		
		// check the title field
		if ($F('fld_title') == '') {
			$('contact_title_error').addClassName('error');
			$('contact_title_error').insert({top: '<p id="contact_title_message" class="errorOn">'+snippet('validationtitle')+'</p>'});
			errors[1] = snippet('validationtitle');
		}	
		
		// check the firstname field
		if ($F('fld_firstname') == '') {
			$('contact_firstname_error').addClassName('error');
			$('contact_firstname_error').insert({top: '<p id="contact_firstname_message" class="errorOn">'+snippet('validationfirstname')+'</p>'});
			errors[2] = snippet('validationfirstname');
		}
		
		
		// check the lastname field
		if ($F('fld_lastname') == '') {
			$('contact_lastname_error').addClassName('error');
			$('contact_lastname_error').insert({top: '<p id="contact_lastname_message" class="errorOn">'+snippet('validationlastname')+'</p>'});
			errors[3] = snippet('validationlastname');
		}
		
		// check the message field
		if ($F('fld_message') == '' || $F('fld_message').length>1000) {
			$('contact_message_error').addClassName('error');
			$('contact_message_error').insert({top: '<p id="contact_message_message" class="errorOn">'+snippet('validationmessage')+'</p>'});
			errors[4] = snippet('validationmessage');
		}
		
		// check the country field
		if ($('fld_country').selectedIndex==0) {
			$('contact_country_error').addClassName('error');
			$('contact_country_error').insert({top: '<p id="contact_country_message" class="errorOn">'+snippet('validationcountry')+'</p>'});
			errors[5] = snippet('validationcountry');
		}	


		if ($F('fld_email') == '' || $F('fld_email').indexOf('@') < 0 || $F('fld_email').indexOf('.') < 0) {
			$('contact_email_error').addClassName('error');
			$('contact_email_error').insert({top: '<p id="contact_email_message" class="errorOn">'+snippet('validationemail')+'</p>'});
			errors[6] = 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;
		}
		else
		{
			return true; 
		}
	}
	
	// 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) { 
			$('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');
		}
		
		if ($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('validationpasswordnotsame')+'</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');
		}

		// reset the occupationgroup field
		if ($('account_occupationgroup_message') != null) $('account_occupationgroup_message').remove();
		$('account_occupationgroup_error').removeClassName('error');		
		
		// check the speciality field
		if ($F('account_occupationgroup') == '' || $F('account_occupationgroup') == snippet('validationpleaseselect')) {
			$('account_occupationgroup_error').addClassName('error');
			$('account_occupationgroup_error').insert({top: '<p id="account_occupationgroup_message"><span class="errorOn">'+snippet('validationoccupationgroup')+'</span></p>'});
			errors[8] = snippet('validationoccupationgroup');
		}
		
		// reset the street field
		if ($('account_street_message') != null) $('account_street_message').remove();
		$('account_street_error').removeClassName('error');
		
		// check the street field
		if ($F('account_street') == '') {
			$('account_street_error').addClassName('error');
			$('account_street_error').insert({top: '<p id="account_street_message"><span class="errorOn">'+snippet('validationstreet')+'</span></p>'});
			errors[9] = snippet('validationstreet');
		}

		// reset the postcode field
		if ($('account_postcode_message') != null) $('account_postcode_message').remove();
		$('account_postcode_error').removeClassName('error');
		
		// check the postcode field
		if ($F('account_postcode') == '' || ($F('account_postcode').length > 5 || $F('account_postcode').length < 5)) {
			$('account_postcode_error').addClassName('error');
			$('account_postcode_error').insert({top: '<p id="account_postcode_message"><span class="errorOn">'+snippet('validationpostcode')+'</span></p>'});
			errors[10] = snippet('validationpostcode');
		}

		// reset the city field
		if ($('account_city_message') != null) $('account_city_message').remove();
		$('account_city_error').removeClassName('error');
		
		// check the city field
		if ($F('account_city') == '') {
			$('account_city_error').addClassName('error');
			$('account_city_error').insert({top: '<p id="account_city_message"><span class="errorOn">'+snippet('validationcity')+'</span></p>'});
			errors[11] = snippet('validationcity');
		}	
		
		// 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');
		}
		
		// reset the occupationgroup field
		if ($('account_occupationgroup_message') != null) $('account_occupationgroup_message').remove();
		$('account_occupationgroup_error').removeClassName('error');		
		
		// check the speciality field
		if ($F('account_occupationgroup') == '' || $F('account_occupationgroup') == snippet('validationpleaseselect')) {
			$('account_occupationgroup_error').addClassName('error');
			$('account_occupationgroup_error').insert({top: '<p id="account_occupationgroup_message"><span class="errorOn">'+snippet('validationoccupationgroup')+'</span></p>'});
			errors[8] = snippet('validationoccupationgroup');
		}
		
		// reset the street field
		if ($('account_street_message') != null) $('account_street_message').remove();
		$('account_street_error').removeClassName('error');
		
		// check the street field
		if ($F('account_street') == '') {
			$('account_street_error').addClassName('error');
			$('account_street_error').insert({top: '<p id="account_street_message"><span class="errorOn">'+snippet('validationstreet')+'</span></p>'});
			errors[9] = snippet('validationstreet');
		}

		// reset the postcode field
		if ($('account_postcode_message') != null) $('account_postcode_message').remove();
		$('account_postcode_error').removeClassName('error');
		
		// check the postcode field
		if ($F('account_postcode') == '') {
			$('account_postcode_error').addClassName('error');
			$('account_postcode_error').insert({top: '<p id="account_postcode_message"><span class="errorOn">'+snippet('validationpostcode')+'</span></p>'});
			errors[10] = snippet('validationpostcode');
		}

		// reset the city field
		if ($('account_city_message') != null) $('account_city_message').remove();
		$('account_city_error').removeClassName('error');
		
		// check the city field
		if ($F('account_city') == '') {
			$('account_city_error').addClassName('error');
			$('account_city_error').insert({top: '<p id="account_city_message"><span class="errorOn">'+snippet('validationcity')+'</span></p>'});
			errors[11] = snippet('validationcity');
		}
		
		// 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;
		}
		
	}	