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);

}



$(document).ready(function() {



	/* Using custom settings 

	

	$("#button").fancybox({

		'hideOnContentClick': true,

		'autoDimensions': false,

		'width': 560,

		'height': 260

	});

	*/

});





$(function() {



	$("input#name").focus(function() {

		if( this.value == this.defaultValue ) {

			this.value = "";

		}

	}).blur(function() {

		if( !this.value.length ) {

			this.value = this.defaultValue;

		}

	});

	$("input#email").focus(function() {

		if( this.value == this.defaultValue ) {

			this.value = "";

		}

	}).blur(function() {

		if( !this.value.length ) {

			this.value = this.defaultValue;

		}

	});

	/*$("textarea#comments").focus(function() {

		if( this.value == this.defaultValue ) {

			this.value = "";

		}

	}).blur(function() {

		if( !this.value.length ) {

			this.value = this.defaultValue;

		}

	});	*/

	

	

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

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

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

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

  });

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

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

  });



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

		// validate and process form

		// first hide any error messages

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

		

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

		if (name == "name:" || name == "") {

      //$("label#name_error").show();

		alert("Field 'name' required.");

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

      return false;

    }

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

		/*if (email == "" || email == "email:") {*/

		if(!isValidEmailAddress(email)) {

      //$("label#email_error").show();

		alert("Field 'email' invalid.");

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

      return false;

    }

		

		

		var dataString = 'name='+ name + '&email=' + email;

		//alert (dataString);return false;

		

		$.ajax({

      type: "POST",

      url: "/contact/bin/process.php",

      data: dataString,

      success: function() {

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

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

        .append("<p>Your information has been submitted successfully.</p>")

        .hide()

        .fadeIn(1500, function() {

          //$('#message').append("<img id='checkmark' src='contact/images/check.png' />");

        });

      }

     });

    return false;

	});

});

runOnLoad(function(){

  //$("input#name").select().focus();

});


