$(function() {

    $('.error').hide();

	$('input.text-input').css({backgroundColor:"#FFFFFF"});

	$('input.text-input').focus(function(){

		$(this).css({backgroundColor:"#FFDDAA"});

	});

	$('input.text-input').blur(function(){

		$(this).css({backgroundColor:"#FFFFFF"});

	});

    $("#submit").click(function() {



    	// validate and process form here

      	$('.error').hide();

  	  	var name = $("input#custname").val();

  		if (name == "") {

        	alert('Please input a name.')

        	$("input#custname").focus();

        	return false;

      	}

      	

      	var company = $("input#company").val();

  		if (company == "") {

        	alert('Please input your company name.')

        	$("input#company").focus();

        	return false;

      	}

    

		/*

var email = $("input#email").val();

  		if (email == "") {

        	alert('Please input a contact email.')

        	$("input#email").focus();

        	return false;

      	}

*/



		$(function(){



			var email = $("input#email").val();

			if (email == "") {

	        	alert('Please input a contact email.')

	        	$("input#email").focus();

	        	return false;

	      	}

		

			if(!isValidEmailAddress(email)) {

				alert('Please input a correct email address.')

        		$("input#email").focus();

				return false;

			}

		});

		

		function isValidEmailAddress(emailAddress) {

			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

			return pattern.test(emailAddress);

		}



  		var phone = $("input#phone").val();

  		if (phone == "") {

        	alert('Please input a contact number.')

        	$("input#phone").focus();

        	return false;

		}

		

		var comment = $("textarea#comment").val();

  		if (comment == "") {

        	alert('Please leave a brief description of what you are looking for.')

        	$("textarea#comment").focus();

        	return false;

		}

		

		//check for checkboxes

		if (!isCheckedById("selector")) 

        { 

            alert ("Please select a method for us to direct your message."); 

            return false; 

        }

		

		function isCheckedById(id) 

	    { 

	        var checked = $("input[@id="+id+"]:checked").length; 

	        if (checked == 0) 

	        { 

	            return false; 

	        }

	        else { 

	        	return true;

	        }

	    } 

		

		//var dataString = 'name='+ name + '&company=' + company + '&email=' + email + '&phone=' + phone + '&comment=' + comment;

		var dataString = $("#contact_form form").serialize();

	

  		$.ajax({

		    type: "POST",

		    url: "contact-script.php",

		    data: dataString,

		    success: function() {

				$('#contact_form').html("<div id='message'></div>");

				$('#message').html("<h2>Contact Form Submitted!</h2>")

				.append("<p>We will get back to you as soon as possible.</p>")

				.append("<p>In the meantime, take a look at our <a href='websites.php'>work</a>.</p>")

				.hide()

				.fadeIn(1500);

		    }

		});

	

 	 	return false;

  

	});

});
