$(document).ready(function(){
   //submission scripts for QuoteForm//
  $('.quoteForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var phoneFilter = /^[0-9]+$/;
		var yearFilter = /^[0-9]+$/;
		
		myOption = -1;
		for (i=document.qform.windowType.length-1; i > -1; i--) {
			if (document.qform.windowType[i].checked) {
			myOption = i; i = -1;
			}
		}
		if (myOption == -1) {
			$('.quote_window-missing').slideDown("slow");
			/*$('html, body').animate({scrollTop:600}, 'slow');*/
		} else {$('.quote_window-missing').hide();}
		
		/*var checkBtn = $("input[name='windowType']:checked").map(function() {return this.value;}).get();*/
// Use this code to get the values of all checked checkboxes
//var checkBtn = $('input:checkbox[name="windowType"]:checked').val();
var checkBtn = $("input[name='windowType']:checked").val();
/*alert(checkBtn);*/
                /*var checked = $('input[name=windowType]:checked').map(function() {
                    return this.value;
                }).get();
                alert(checked);*/
		
		

		var year = document.getElementById('quote_year');
		if (!yearFilter.test(year.value)) {
			$('.quote_year-missing').slideDown("slow");
		} else {$('.quote_year-missing').hide();}	
				
		if (document.qform.make.value == "") {
			$('.quote_make-missing').slideDown("slow");
		} else {$('.quote_make-missing').hide();}
		
		if (document.qform.model.value == "") {
			$('.quote_model-missing').slideDown("slow");
		} else {$('.quote_model-missing').hide();}
							
		var phone = document.getElementById('quote_phone');
		if (!phoneFilter.test(phone.value)) {
			$('.quote_phone-missing').slideDown("slow");
		} else {$('.quote_phone-missing').hide();}	
		
		var email = document.getElementById('quote_e-mail');
		if (!filter.test(email.value)) {
			$('.quote_email-missing').slideDown("slow");
		} else {$('.quote_email-missing').hide();}
		
		if (document.qform.quotename.value == "") {
			$('.quote_name-missing').slideDown("slow");
		} else {$('.quote_name-missing').hide();}	
				
		
		if ((document.qform.model.value == "") || (document.qform.make.value == "") || (!filter.test(email.value)) || (!phoneFilter.test(phone.value)) || (!yearFilter.test(year.value)) || (myOption == -1) || (document.qform.quotename.value == "")){
			return false;
		} 
		
		if ((document.qform.model.value != "") && (document.qform.make.value != "") && (filter.test(email.value)) && (phoneFilter.test(phone.value)) && (yearFilter.test(year.value)) && (myOption != -1) && (document.qform.quotename.value != "")) {

		
			//show the loading bar
			$('.loader').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.post('quote.php',{
				   			year:$('#quote_year').val(),
							windowType:(checkBtn),
							make:$('#quote_make').val(),
							model:$('#quote_model').val(),
							quoteName:$('#quote_name').val(),
							quoteEmail:$('#quote_e-mail').val(),
							quotePhone:$('#quote_phone').val(),
							quoteMessage:$('#quote_message').val()
							  },
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loader').append(data);
			  $("#quote_response").slideDown("slow");
			  
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('$(".quoteForm").slideUp("slow")', 500);
			setTimeout("animateBody()",900);
			
			//stay on the page
			return false;
		} 
  });//END OF QUOTE FORM//   
});//END

  function animateBody(){
	  $('html, body').animate({scrollTop:600}, 'slow');
	  $("#quoteForm").animate({"height": "-=400px"},'slow');

  };
