function showOrHide(eId) {
  if (e = document.getElementById(eId)) {
    if (e.style.display == 'none') {
      e.style.display = '';
      document.cookie = eId + '=1';
      if (eimg = document.getElementById(eId + 'img')) eimg.src = imagedir + 'collapse.gif';
    }
    else {
      e.style.display = 'none';
      document.cookie = eId + '=0';
      if (eimg = document.getElementById(eId + 'img')) eimg.src = imagedir + 'expand.gif';
    }
  }
}


function get_cookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + '=');
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(';',c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return '';
}


function expandaccordingtocookies() {
  for (i=1; i<=10; i++)  {
    var x = get_cookie('wc' + i);
    if (x == 1) showOrHide('wc' + i);
  }
}


// Shoutbox

function clearText(thefield) {
  if (thefield.defaultValue == thefield.value) thefield.value = '';
}

var ajax = new Array();
var ajaxindex = 0;

function addShout() {  eNick = document.getElementById('shoutnick');  eUrl = document.getElementById('shouturl');  eShout = document.getElementById('shouttext');
  eSend = document.getElementById('send');
  eNick.disabled = true;
  eUrl.disabled = true;
  eShout.disabled = true;
  eSend.disabled = true;
  ajaxindex = ajax.length;
  ajax[ajaxindex] = new sack();
  ajax[ajaxindex].requestFile = htmlrootpath + 'addshout.php?nick=' + escape(eNick.value) + '&url=' + escape(eUrl.value) + '&shout=' + escape(eShout.value);
  ajax[ajaxindex].onCompletion = function(){ showAddedShout() };
  ajax[ajaxindex].runAJAX();
}

function showAddedShout() {
  eval(ajax[ajaxindex].response);
/*
  eNick = document.getElementById('shoutnick');  eUrl = document.getElementById('shouturl');  eShout = document.getElementById('shouttext');
  eSend = document.getElementById('send');
*/  eNick.disabled = false;
  eUrl.disabled = false;
  eShout.disabled = false;
  eSend.disabled = false;
  var objDiv = document.getElementById('shoutboxsurround');
  objDiv.scrollTop = objDiv.scrollHeight;
}


function deleteShout(timestamp) {
  ajaxindex = ajax.length;
  ajax[ajaxindex] = new sack();
  ajax[ajaxindex].requestFile = htmlrootpath + 'addshout.php?action=delete&timestamp=' + timestamp;
  ajax[ajaxindex].onCompletion = function(){ showShoutBeenDeleted() };
  ajax[ajaxindex].runAJAX();
}


function showShoutBeenDeleted() {
  eval(ajax[ajaxindex].response);
  var objDiv = document.getElementById('shoutboxsurround');
  objDiv.scrollTop = objDiv.scrollHeight;
}
