jQuery("document").ready(function(){

		jQuery(".numberInput").keypress(function(event) {
		
		var controlKeys = [8, 9, 13, 36, 37, 32, 43];
		var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
		if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
			(48 <= event.which && event.which <= 57) || // Always 1 through 9
			isControlKey) { // Opera assigns values for control keys.
			return;
		} 
		else {
			event.preventDefault();
			}
		}); 
		
		jQuery("#sumbitSmall").click(function(){
		
		jQuery("#formErrors").slideUp();
		jQuery("#contact-boxes label").css("color", "#444444");
		
		var name = jQuery("#name").val();
		var email = jQuery("#email").val();
		var number = jQuery("#contactNo").val();
		var enquiry = jQuery("#enquiry").val();
		var errorCount = 0;
		
		if (!name){
		jQuery("#name-label").css("color", "#E03A3E");
		errorCount++;
		}
		if (!email){
		jQuery("#email-label").css("color", "#E03A3E");
		errorCount++;
		}
		if (!number){
		jQuery("#contactNo-label").css("color", "#E03A3E");
		errorCount++;
		}
		if (!enquiry){
		jQuery("#enquiry-label").css("color", "#E03A3E");
		errorCount++;
		}
		if (errorCount > 0)
		{
		jQuery("#formErrors").html("Please ensure all fields are filled").slideDown();
		return false;
		}
		else {
			var atpos=email.indexOf("@");
			var dotpos=email.lastIndexOf(".");
			if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
			{
				jQuery("#formErrors").html("Please enter a valid e-mail address").slideDown();
				jQuery("#email-label").css("color", "#E03A3E");
				return false;
			} 
			else {
				sendMail(name, email, number, enquiry);
			}
		}
		
		

	});
	
	function sendMail (n, e, no, enq) {
	
	var params = "sendMail=true&name=" + n + "&email=" + e + "&phone=" + no + "&enquiry=" + enq;
	
	jQuery.getJSON("/jqemail/contact.php", params, function(data, textStatus){

				if (textStatus == "success"){
					jQuery("#contact-boxes").slideUp('slow', function(){
						jQuery("#thank-you").slideDown('slow');
					});
						jQuery("#name").val('');
						jQuery("#email").val('');
						jQuery("#contactNo").val('');
						jQuery("#enquiry").val('');
					setTimeout(
					function() 
						{
							jQuery("#contact-boxes").slideDown('slow', function(){
							jQuery("#thank-you").slideUp('slow');
								});
						}, 4000);
					return;
				}
				
				if (textStatus == "error"){
					alert("There was an error sending you email.", "Error");
					return;
				}
				if (data.result == "error"){
					alert("Sorry, an error occurred while sending your email  The error was: '" + data.message + "'");
					return;
				}
				
			});
		
	}
	
	
	
});
