﻿$(function() {
  $('.error').hide();
  $('input.text_field').css({backgroundColor:"#FFFFFF"});
  $('input.text_field').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text_field').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").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 email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	
		var phone = $("input#phone").val();
	/*
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	*/
	
    		var message = $("textarea#message").val();
		if (message == "") {
      $("label#message_error").show();
      $("input#message").focus();
      return false;
    }
		
		var dataString= 'name='+ name + '&email=' + email + '&phone=' + phone + '&message=' + message;
		//alert (dataString);return false;
		
		
	$.ajax({
      type: "POST",
      url: "js/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='otok'></div>");
        $('#otok').html("<p><b>Hvala za vaše sporočilo.</b></p>")
        /*.append("<p>Odgovorili vam bomo kakor hitro bo mo&#382;no.</p>")*/
        .hide()
        .fadeIn(1500, function() {
          $('#otok').append("<p><br /><br />Lepo vas pozdravljamo. <br />ortodontijams.si</p>");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

