
$(function() {
    $('.error').hide();
    $(".button").click(function() {
      // validate and process form here

      $('.error').hide();
  	  var first_name = $("input#first_name").val();
  		if (first_name == "") {
        $("label#first_error").show();
        $("input#first_name").focus();
        return false;
      }
var last_name = $("input#last_name").val();
  		if (last_name == "") {
        $("label#last_error").show();
        $("input#last_name").focus();
        return false;
      }
  		var email = $("input#email").val();
  		if (email == "") {
        $("label#email_error").show();
        $("input#email").focus();
        return false;
      }
var em = email;
if (em) {
var pattern1 = /\s|(@.*@)|(\.\.)|(@\.)|(\.@)|(^www\.)|(^WWW\.)|(^\.)/;
var pattern2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
var m1 = pattern1.test(em);
var m2 = pattern2.test(em);
if ((m1 == true) || (m2 == false))
    { 
$("label#valid_email_error").show();
$("input#email").focus();
return (false);
} }
  	var submit = $("input#submit").val();
  		if (submit == "") {
        return false;
      }	


var dataString = 'first_name='+ first_name  + '&last_name=' + last_name + '&email=' + email + '&submit=' + submit;
  //alert (dataString);return false;
  $.ajax({
    type: "POST",
    url: "includes/nlmail.asp",
    data: dataString,
    success: function() {
      $('#contact_form').html("<div id='message'></div>");
      $('#message').html('<h2 style="text-align: center;">Newsletter Signup Submitted!</h2>')
      .append('<p style="text-align: center;">Thank you and keep recycling.</p>')
      .hide()
      .fadeIn(1500, function() { });
    },
    error: function() {
      $('#contact_form').html("<div id='message'></div>");
      $('#message').html('<h2 style="text-align: center;">There Has Been An Error!</h2>')
      .append('<p style="text-align: center;">Your information has not been submitted.</p>')
      .hide()
      .fadeIn(1500, function() { });
    }
  });
  return false;
});
});
$(document).ready(function(){
document.contact.first_name.value = "";
document.contact.last_name.value = "";
document.contact.email.value = "";
});