	$(document.body).ready(
		function()
		{
			//Phone
			$('#phone').bind('keyup', function(e) {

							var inputElement = $(this);
							var input = $(this).val();

							var keyCode = e.keyCode;

							if (keyCode >= 48 && keyCode <= 57 || keyCode >= 98 && keyCode <= 105) {
								if (input.length == 3) {
									inputElement.val(input+'-');
								} else if (input.length == 7) {
									inputElement.val(input+'-');
								} else if (input.length > 12) {
									inputElement.val(input.slice(0, 12));
								}
							} else if (keyCode == 13 || keyCode == 8 || keyCode == 46) {
								return;							
							} else if (keyCode >= 65 && keyCode <= 90) {
								inputElement.val(input.slice(0, input.length-1));
								alert('Number Only.');
							} else {
								return;
							}

						 });

		$('#contact_form').submit(
			function(e)
			{
				e.preventDefault();

				var formData = $('#contact_form').serialize();

				var options = {};

				options.url = siteUrl+'contact/submit';
				options.data = formData;
				options.dataType = 'json';
				options.type = 'post';
				options.success = function processData(data) 
				{

					$('.error').empty();

					if (data.state == 'error') {
						//display the errors
						$.each(data.errors, function (name, value){
							$('#error_'+name).html(value);
						});
					}

					if (data.state == 'ok') {
						//then thank them 
						$('#contact_form').html('<p class="thank_you">'+data.msg+'</p>');					

					}
					//reset form
				}

				$.ajax(options);

			}
		);					
		}
	);
