$(function() {
  $('.error').hide();
    $('.twirl').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#fcfcff"});
  });
  
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea#comment').focus(function(){
    $(this).css({backgroundColor:"#fcfcff"});
  });

  $('textarea#comment').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.button').hide();
	$('.error').hide();
	$('.twirl').show();
		
	  var name = $("input#name").val();
	  var comment = $("textarea#comment").val();	
//		if (name == "") {
//          name = "not given";
//      return true;
//    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
	  $('input#email').css({backgroundColor:"#FF0000"});
      $("input#email").focus();
	  $('.button').show();
	  $('.twirl').hide();
      return false;
    }
//		var comment = $("textarea#comment").val();	
	
//		var phone = $("input#phone").val();
//		if (phone == "") {
//		  phone = "no comment";
//      return true;
//    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment;

//var dataString = 'name='+ name + '&email=' + email;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "mailform/bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank You</h2>")
        .append("<p>We will reply ASAP</p>")
        .hide()
        .fadeIn(500, function() {
          $('#message').append("<a href='index.html'><img id='checkmark' src='images/check.png' /></a>");
        });
      }
     });
    return false;
	});
});

runOnLoad(function(){
//  $("input#email").select().focus();
});
