$(function() {
 
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".sendform").click(function() {
		// validate and process form
		// first hide any error messages
      if($('#email').val() == ""){
      	alert('Vyplňte prosím email');
      	return false;
          }
          
      var email = $("input#email").val();    
      var regex = new RegExp('(.+)@([^@]+)');		
      if (email.match(regex) == null) {
        alert('Vyplňte prosím správný email');
      return false;
      }
      
      var subject = $("input#subject").val();  
        if($('#subject').val() == ""){
    	alert('Vyplňte prosím subjekt');
    	return false;
        }
      
      var message = $("textarea#message").val();   
        if($('#message').val() == ""){
    	alert('Napište zprávu');
    	return false;
        }
		
	 
		
		var dataString = 'subject='+ subject + '&email=' + email + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "js/process.php",
      data: dataString,
      success: function() {
        document.getElementsByName("email")[0].value = '';
        document.getElementsByName("subject")[0].value = '';
        document.getElementsByName("message")[0].value = '';
        alert('Kontakt přijat!');
        $('#contact_form').html("<div class='message-send'></div>");
        $('#message').html("Kontakt přijat!")
        .append("<p>Ozveme se vám v nejbližší době.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/obr/ikony/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

