$(function() {
  $('.error').hide();
  $('input.textinput').css({backgroundColor:"#ffffff"});
  $('input.textinput').focus(function(){
    $(this).css({backgroundColor:"#d1edf8"});
  });
  $('input.textinput').blur(function(){
    $(this).css({backgroundColor:"#ffffff"});
  });

  $(".formbutton").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	
	var tel = $("input#tel").val();
		if (tel == "") {
      $("label#tel_error").show();
      $("input#tel").focus();
      return false;
    }
	var time = $("select#time").val();
		if (time == "") {
      $("label#time_error").show();
      $("select#time").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(email))) {
      $("label#email_error2").show();
      $("input#email").focus();
      return false;
    }
		var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
		if (email.match(illegalChars)) {
      $("label#email_error2").show();
      $("input#email").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/bin/process.php",
      data: dataString,
      success: function() {
        $('#callback_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank you for your interest</h2>")
        .append("<p>We will call you back at the time selected.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
