
// When the DOM is ready...
$(function(){
	
	// Hide stuff with the JavaScript. If JS is disabled, the form will still be useable.
	// NOTE:
	// Sometimes using the .hide(); function isn't as ideal as it uses display: none; 
	// which has problems with some screen readers. Applying a CSS class to kick it off the
	// screen is usually prefered, but since we will be UNhiding these as well, this works.
		
		
		// Keep things hidden till we need them
		$("#QuickQuote").hide();
		
		$("#name_wrap").hide();
		$("#business_wrap").hide();
		$("#telephone_wrap").hide();
		$("#email_wrap").hide();
		
		$("#work_wrap").hide();
		$("#information_wrap").hide();
		$("#where_seen_wrap").hide();
		$("#recaptcha_wrap").hide();
		//error and message hide till end
		$("#error").hide();
		$("#message").hide();
		// Reset form elements back to default values	
		$("#submit_button").attr("disabled",true);
		$("#where_seen").val('Please Choose');
		
	// When the button is pressed, get things moving!	
	$("#quotebutton a").click(function() {
        
		$("#quotebutton").hide();
		$("#trustmark").hide();
		$("#detailsbutton").hide();
		$("#suppliers").hide();
		
		$("#QuickQuote").slideDown();
		$("#name_wrap").slideDown();
		$("#business_wrap").slideDown();				
		$("#telephone_wrap").slideDown();
		$("#email_wrap").slideDown();
		
		$("#work_wrap").slideDown();
		$("#information_wrap").slideDown();
		$("#where_seen_wrap").slideDown();
		
		$("input#yourname").focus();		
      });
		
		// When a dropdown selection is made enable submit button IF all else done as well
	$("#where_seen").change(function() {
				$("#recaptcha_wrap").slideDown();
				$("#submit_button").attr("disabled",false);
				$("input#vercode").focus();
	});

$(document).ready(function(){
$("form").submit(function(){

var str = $("form").serialize();

   $.ajax({
   type: "POST",
   url: "mailer.php",
   data: str,
   success: function(msg){
    
		$("#recaptcha_wrap").ajaxComplete(function(event, request, settings){

		if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
	{
		$("#captchasubmit").hide();
		$("#error").hide();
		$("#message").slideDown();
	//	result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
	}
	else
	{
		$("#error").slideDown();
		$("input#vercode").focus();
	}
	
	//$(this).html(result);
	
	});
	
	}
	
	 });
	
	return false;
	
	});

});

	
});

