$(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 name = $("input#name").val();
                if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

                var theme = $("input#theme").val();
                if (theme == "") {
      $("label#theme_error").show();
      $("input#theme").focus();
      return false;
    }

                var ftext = $("textarea#ftext").val();
                if (ftext == "") {
      $("label#ftext_error").show();
      $("input#ftext").focus();
      return false;
    }

     var art = $("input#art").val();
                
     var dataString = 'name='+ name +  '&theme=' + theme + '&ftext=' + ftext + '&art=' + art;
     //alert (dataString);return false;
     
     $.ajax({
      type: "POST",
      url: "/cgi-bin/form.pl",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<font class='pt2'>Ваш комментарий принят!</font>")
        .append("<p>После проверки модератором, он появится на сайте</p>")
      }
     });
    return false;
  });
});


