
      function feedback()
      {
         if ($F('usname') == "")
         {
           alert("Ви не ввели iм'я!");
           $('usname').focus();
           $('usname').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else if ($F('email') == "")
         {
           alert("Ви не ввели свій Email!");
           $('email').focus();
           $('email').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else if ($F('text') == "")
         {
           alert("Ви не ввели текст повідомлення! Максимум 2000 символів.");
           $('text').focus();
           $('text').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else if ($F('vcode') == "")
         {
           alert("Веввдіть код перевірки!");
           $('vcode').focus();
           $('vcode').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else
         {

           var form = $('form');
           var fields = $('usname', 'phone', 'email', 'text', 'vcode');

           form.disable();
           $('loading').show();
           $('image').hide();

              new Ajax.Updater('message',
                               '/ajaxpage/feedback.php',
                               {
                                parameters:{phone: $F('phone'), usname: $F('usname'), email: $F('email'), text: $F('text'), vcode: $F('vcode')},
                                onComplete: function(transport)
                                {
                                  form.enable();
                                  reloadImage();
                                  clear('vcode');
                                    for(i=0; i<fields.length; i++){
                                        fields[i].setStyle({borderColor: '#5ba452'});
                                    }
                                     //$('countcomments').value = $('countcomments').value+1;
                               },
                               evalScripts: true
                               });

            return false;
         }

      }

      function guestbook()
      {
         if ($F('usname') == "")
         {
           alert("Ви не ввели iм'я!");
           $('usname').focus();
           $('usname').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else if ($F('text') == "")
         {
           alert("Ви не ввели текст повідомлення! Максимум 2000 символів.");
           $('text').focus();
           $('text').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else if ($F('vcode') == "")
         {
           alert("Веввдіть код перевірки!");
           $('vcode').focus();
           $('vcode').setStyle({
             borderColor: '#ff0000'
           });
           return false;
         }
         else
         {

           var form = $('form');
           var fields = $('usname', 'email', 'text', 'vcode');

           form.disable();
           $('loading').show();
           $('image').hide();

              new Ajax.Updater('message',
                               '/ajaxpage/guestbook.php',
                               {
                                parameters:{usname: $F('usname'), email: $F('email'), text: $F('text'), vcode: $F('vcode')},
                                onComplete: function(transport)
                                {
                                  form.enable();
                                  reloadImage();
                                  clear('vcode');
                                    for(i=0; i<fields.length; i++)
                                    {
                                        fields[i].setStyle({borderColor: '#5ba452'});
                                    }
                                     Effect.Pulsate('comments', {pulses: 1, duration: 1.9});
                                     new Effect.ScrollTo('top'); return false;
                               },
                               evalScripts: true
                               });

            return false;
         }

      }

      function inputLimit(input, maxlen, left)
      {
          inputstr = input.value;
          strlen = inputstr.length;
          if (strlen > maxlen)
                  input.value = inputstr.substring(0, maxlen);
          if (left)
                  left = $(left);
          if (left)
          {
                  if (left.tagName == 'INPUT')
                          left.value = 'Залишилось: '+(maxlen - input.value.length)+' симв.';
                  else
                          left.innerHTML = 'Залишилось: '+(maxlen - input.value.length)+' симв.';
          }
          return true;
     }

     function reloadImage()
     {
         $('loading').show();
         $('image').hide();
         new Ajax.Updater('image',
                          '/ajaxpage/image_ajax.php?reload=image',
                          {onComplete: function(){
                           $('loading').hide();
                           $('image').show();}});
     }

     function clear(field)
     {
          $(field).clear();
     }