$(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"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var to_name = $("input#to_name").val();
		if (to_name == "") {
      $("label#to_name_error").show();
      $("input#to_name").focus();
      return false;
    }
		var to_email = $("input#to_email").val();
		if (to_email == "") {
      $("label#to_email_error").show();
      $("input#to_email").focus();
      return false;
    }
		var from_name = $("input#from_name").val();
		if (from_name == "") {
      $("label#from_name_error").show();
      $("input#from_name").focus();
      return false;
    }
		var from_mail = $("input#from_mail").val();
		if (from_mail == "") {
      $("label#from_mail_error").show();
      $("input#from_mail").focus();
      return false;
    }	

		var dataString = 'to_name='+ to_name + '&to_email=' + to_email + '&from_name=' + from_name + '&from_mail=' + from_mail;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h1><img id='checkmark' src='images/check.png' align='left' />&nbsp;Bericht verstuurd!</h1><p>&nbsp;Bedankt voor het aanbevelen van Kluscasa.nl!</p><p><input name='Sluiten' type='button' value='Sluiten' onclick = \"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\"/></p>")
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#to_name").select().focus();
});
