/**** Shoutbox ****/
// global reload timer
var maT;
  function checkInactivity () {
    
    var lNow = new Date();
    return ((lNow.getTime() - Start) / 1000);
  }
  function checkCR(action, idleTime, myevent) {
    if(myevent.keyCode == 13) {
      if (action == 'enter') {
        sendMessage(idleTime);
        loadPixel();
        hideSmileys();
      } else {
        GetObj('Box_m-043_WebTV_Shout').focus();
      }
    }
  }
  
  function showMessage(idleTime){
      if (maT) {
        clearTimeout(maT);
        //$('#Box_m-043_WebTV_Shouts').fadeOut();
         if (checkInactivity() >= idleTime) {
           GetObj('Box_m-043_WebTV_Shout_Box').style.display = 'none';
           GetObj('Box_m-043_WebTV_Shout_Box_Inactiv').style.display = 'block';
           return '';
         }
       }
    $.post("scripts/shoutboxAjax.php", {action : "getMessage"}, function(msg) {
       // format and output result
       var parts = msg.split('<:>');
       $('#Box_m-043_WebTV_Shouts').html('');
       $('#Box_m-043_WebTV_Shouts').fadeIn();
       
       if (parts[1]) {
         $('#Box_m-043_WebTV_Shouts').html(parts[1]);
       } else {
         $('#Box_m-043_WebTV_Shouts').html(msg);
       }
       $('#shoutboxUserOnline').html(parts[0]);
       timeout = 15000;
       maT = setTimeout('showMessage('+idleTime+')',timeout);
        }
      );
  }
  function sendMessage(idleTime) {
      GetObj('Box_m-043_WebTV_Error').style.display = 'none';
      if (GetObj('Box_m-043_WebTV_Shout').value && GetObj('Box_m-043_WebTV_Name').value) {
        $.post("scripts/shoutboxAjax.php", {action : "setMessage", name: GetObj('Box_m-043_WebTV_Name').value, message: GetObj('Box_m-043_WebTV_Shout').value },
                function(result) {
              GetObj('Box_m-043_WebTV_Shout').value = '';
          if (result == '1') {
          $('#Box_m-043_WebTV_Error').html('');
            $('#Box_m-043_WebTV_Error').html('Leider können wir diesen Shout nicht annehmen!');
            GetObj('Box_m-043_WebTV_Error').style.display = 'block';
          } else {
            showMessage(idleTime);
          }
          GetObj('Box_m-043_WebTV_Shout').focus();
        }
     );
      } else {
    $('#Box_m-043_WebTV_Error').html('');
    if (GetObj('Box_m-043_WebTV_Shout').value == '') {
      $('#Box_m-043_WebTV_Error').html('Bitte gebe einen Shout in das Eingabefeld ein!');
      GetObj('Box_m-043_WebTV_Shout').focus();
    } else {
      $('#Box_m-043_WebTV_Error').html('Bitte gebe Deinen Namen in das Eingabefeld ein!');
      GetObj('Box_m-043_WebTV_Name').focus();
    }
    GetObj('Box_m-043_WebTV_Error').style.display = 'block';
      }
   }
   function insertASC(img) {
     GetObj('Box_m-043_WebTV_Shout').value = GetObj('Box_m-043_WebTV_Shout').value + img.alt;
   }