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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var ime = $("input#ime").val();
		if (ime == "") {
      $("label#ime_error").show();
      $("input#ime").focus();
      return false;
    }
		var surname = $("input#surname").val();
		if (surname == "") {
      $("label#surname_error").show();
      $("input#surname").focus();
      return false;
    }
	var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var rematch = email.match(re);
		if (!rematch)
	{
		$("label#email_error2").show();
		$("input#email").focus();
		return false;
	}
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }		
		var text = $("textarea#text").val();
		if (text == "") {
      $("label#text_error").show();
      $("input#text").focus();
      return false;
    }
		
		var dataString = 'ime='+ ime + '&surname=' + surname + '&email='+ email +'&phone=' + phone + '&text=' + text;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "process2.php",
      data: dataString,
      success: function() {
        $('#forma').html("<div id='message'></div>");
        $('#message').html("<h2 style=\"color:black;\">"+formata_ispratena+"</h2>")
        .append("<p style=\"color:black;\" >"+ke_ve_kontaktirame+"</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
	  }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#ime").select().focus();
});

