//  document "on_load.js" : called at the footer of the body.


/**  Remove focus from select boxes on change  **/


//  Attach event on load
Event.observe(window, 'load', function(e) {
	
	//  Get elements
	var aElements = document.getElementsByTagName('select');
	
	//  Loop elements
	for (var i = 0; i < aElements.length; i++) {

		//  Observe element
		Event.observe(aElements[i], 'change', function(e) {
		
			//  Remove focus
			window.focus();
		});
	}

});



//*
if ($('lead_submission')) {
	
	var bLeadFormSubmitted = false;

	//  Function to hide submit button on click
	Event.observe('lead_submission', 'submit', function (e) {

		//  If form has already been submitted
		if (bLeadFormSubmitted) {
			
			//  Stop the über clicking user from doing it again
			Event.stop(e);
			
		} else {
			
			//  Remember that the form's been submitted
			bLeadFormSubmitted = true;
			
			//  Remove the submit button
			$('lead_form_submit').update('Please wait...');
			
			//  Check the form
			var bFormValid = validate_form($('lead_submission'));
			
			//  If the form isn't valid
			if (!bFormValid) {
				
				//  Put the submit button back because the form will need re-submitting
				$('lead_form_submit').update('<input type="image" src="/sites/www.annuity-specialists.co.uk/assets/images/submit.gif" id="lead_form_submit_button" />');
				
				//  Shtop!  Shtop!  This form is not ready yet!
				Event.stop(e);
			
			}

			//  We're no longer checking the form
			bLeadFormSubmitted = false;

			//  Return the form validity status
			return bFormValid;
				
		}

	});

}
//*/