$(document).ready(function(){
	
   //submission scripts
  $('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('e-mail');
		if (!filter.test(email.value)) {
			$('.email-missing').show();			
		} else {$('.email-missing').hide();}
		
		if (document.cform.name.value === "") {
			$('.name-missing').show();			
		} else {$('.name-missing').hide();}	
		
		if (document.cform.company.value === "") {
		$('.company-missing').show();			
		} else {$('.company-missing').hide();}
		
		if (document.cform.telephone.value === "") {
		$('.telephone-missing').show();			
		} else {$('.telephone-missing').hide();}
		
		if (document.cform.message.value === "") {
		$('.message-missing').show();			
		} else {$('.message-missing').hide();}
		
		if ((document.cform.name.value === "") || (!filter.test(email.value)) || (document.cform.company.value === "") || (document.cform.telephone.value === "") || (document.cform.message.value === "")){
			return false;
		} 
		
		if ((document.cform.name.value !== "") && (filter.test(email.value)) && (document.cform.company.value !== "") && (document.cform.telephone.value !== "") && (document.cform.message.value !== "")) {
			//hide the form
			//$('#contact-message').hide();
			//$('#contact-message').slideUp("slow");
		
			//show the loading bar
			$('.loading').css({display:'block'});
		
			//send the ajax request
			$.post('contactform/contactform.php',
				{name:$('#name').val(),
				company:$('#company').val(),
				email:$('#e-mail').val(),
				message:$('#message').val(),
				telephone:$('#telephone').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $('#contact-message').slideUp("slow");
			  $('.loading').css({display:'none'});
			  $('.loader').append(data);
			});
			
			//waits 2000, then closes the form and fades out
			//setTimeout('$("#emailform").fadeOut("slow"); $("#emailform").slideUp("slow")', 2000);
			
			
			//stay on the page
			return false;
		} 
  });
	//only need force for IE6  
	$("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  
});

