/* Allow multiple things to hook into the Window.load function
 * 2007-8 Tim Igoe (tim@jellymedia.com
 *
 *--------------------------------------------------------------------------*/

var event = new Object();

event.observe = function (element, name, tocall)
{
  if (element.addEventListener)
    element.addEventListener(name, tocall, false);
  else if (element.attachEvent)
    element.attachEvent('on' + name, tocall);
}

/*  AJAX Callback
 *  2006-8 Tim Igoe (tim@jellymedia.com)
 *
/*--------------------------------------------------------------------------*/

var net = new Object();

net.getContent = function (url, onload, onerror)
{
  if (url.indexOf("?") >= 0)
    url = url + "&renderer=xml";
  else
    url = url + "?renderer=xml";
  this.url = url;
  this.onload = onload;
  this.onerror = (onerror) ? onerror : null;
  this.loadXML(url);
}

net.getContent.prototype.loadXML = function (url)
{
  if (window.XMLHttpRequest)         // Mozilla, Safari, ...
    this.req = new XMLHttpRequest();
  else if (window.ActiveXObject)     // IE
    this.req = new ActiveXObject("Microsoft.XMLHTTP");

  if (this.req)
  { // Try sending the message
    var self = this;
    this.req.onreadystatechange = function ()
    {
      net.getContent.onReadyProcess.call(self);
    }
    this.req.open('GET', url, true);
    this.req.send(null);
  }
}

net.getContent.onReadyProcess = function ()
{
  var req = this.req;
  if (req.readyState == 4)
  {
    if (req.status == 200 || req.status == 0)
    {
      this.onload.call(this);
    }
		else if (req.status == 404)
		  if (this.onerror)
		    this.onerrror.call(this);
  }
}


/* Generic Useful Functions */

function showDiv(divName)
{
  if (document.layers)
    document.layers[divName].display = "block";
  else
    document.getElementById(divName).style.display = "block";
}

function hideDiv(divName)
{
  if (document.layers)
    document.layers[divName].display = "none";
  else
    document.getElementById(divName).style.display = "none";
}

function selectBox(element, grouping)
{
  if (grouping == null)
  {
    grouping = 'tableGroup';
  }

  elementGroup = document.getElementById(grouping);

  selects = elementGroup.getElementsByTagName('input');

  for (var i = 0; i < selects.length; i++)
  {
    if (selects[i].getAttribute('type') == 'checkbox')
	  {
	    if (element.checked)
        selects[i].checked = true;
      else
        selects[i].checked = false;
	  }
  }
}