$(document).ready(function()
{ 
 $('a.comments').click(function()
   {
     $("form#comm").slideToggle("slow");
     if ($('a.comments').text() == "dodaj wpis")
     $('a.comments').text("nie dodawaj wpisu");
   else $('a.comments').text("dodaj wpis");
   return false;
   });
   var ok_chars = '.,()@?!ęóąśłżźćńĘÓĄŚŁŻŹĆŃ\ []:;\"-_';
   $("form#comm #name").validation(
   { 
    type: 'alphaInt',
    add: ok_chars
   });
 $("form#comm #message").validation(
   { 
    type: "alphaInt", 
    add: ok_chars
   });
 $("form#comm #send").click(function(e)
	 {
      var usernameValue = $('#name').fieldValue(); 
      var passwordValue = $('#message').fieldValue(); 
      
      // usernameValue and passwordValue are arrays but we can do simple 
      // "not" tests to see if the arrays are empty 
      if (!usernameValue[0] || !passwordValue[0]) 
      { 
        //alert('Please enter a value for both Username and Password'); 
        if (!usernameValue[0])
        {
          $('#name').css('border','1px solid red');
          $('#nameerror').show('fast');
        }
        else
        {
          $('#name').css('border','1px solid black');
          $('#nameerror').hide('fast');
        }
        if (!passwordValue[0])
        { 
          $('#message').css('border','1px solid red');
          $('#messageerror').show('fast');
        }
        else
        {
          $('#message').css('border','1px solid black');
          $('#messageerror').hide('fast');
        }
        return false; 
      }
      else
      {
        var response_html = $.ajax({
          type: "POST",
          url: "comment.php",
          data: "name="+$("#name").val()+"&message="+$("#message").val()+"&id_article="+$("#id_article").val(),
          async: false
         }).responseText;
       $("form#comm").slideToggle("slow");
       $("#comment").html(response_html);	
       return false;
     }
   });
});

