$(document).ready(function(){


	
	
	$("#summary").hide();
	
	/*submit the form */
	
	$("#submit").click(function(){	
	
	$("#quoteform").validate({
		rules: {
    		email: {
      			required: true,
      			email: true
   			}
  		}
		/* Remove the error message */
		,showErrors: function() {
				for ( var i = 0; this.errorList[i]; i++ ) {
                        this.settings.highlight.call( this, this.errorList[i].element, this.settings.errorClass );
                }
                if (this.settings.unhighlight) {
                        for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
                                this.settings.unhighlight.call( this, elements[i], this.settings.errorClass );
                        }
						$("#summary").show();
                }
				
        } 
	
	}); 
				
		
		if($("#quoteform").valid()) {
			
			$("#summary").hide();
			
			var nameVal = $("#name").val();
			var emailVal = $("#email").val();
			var telVal = $("#tel").val();
			var typeVal = $("#ins-life").val()+$("#ins-life").val()+$("#ins-life").val()+$("#ins-life").val();
			
			var typeVal = ''; 
			$("input[@type='checkbox'][@name='type']").each( 
				function() 
				{ 
					if (this.checked) 
					{ 
						typeVal += this.value + ", "; 
					} 
				}); 
			
			
			
			if ($('#amount-no').attr('checked') )
			
				{ 
					var amountVal = $("#amount-no").val();
					
				} else {
					
					var amountVal = $("#amount").val()+" $";
				}
			
			
			var sexVal = $("#sex").val();
			var smokerVal = $("#smoker").val();
			var birthdayVal = $("#birth-day").val();
			var birthmonthVal = $("#birth-month").val();
			var birthyearVal = $("#birth-year").val();
			var messageVal = $("#message").val();
		
			$(this).hide();
			$("#submit-button").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("sendform.php",
   				{ name: nameVal, email: emailVal, tel: telVal, type: typeVal, amount: amountVal, sex: sexVal, smoker: smokerVal, birthday: birthdayVal, birthmonth: birthmonthVal, birthyear: birthyearVal, message: messageVal },
   					function(data){
						$("#quoteform").slideUp("normal", function() {		   
							
							$("#quoteform").before('<p class="success">Thank you very much for submitting your request. We will contact you soon with your personalized quote.</p>');
							
						});
   					}
				 );
		}
		
		return false;
	});					
});