/* library of js functions */

/* URL Object */
var qs = location.search.substring(1);
var nv = qs.split('&');
var url = new Object();
for(i = 0; i < nv.length; i++)
{
  eq = nv[i].indexOf('=');
  url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
}
/* URL Object */

/* CGI Object */
var cgi = new Object();
    cgi.http_host = location.host;
    cgi.http_user_agent = navigator.userAgent;
    cgi.http_cookie = document.cookie;
    cgi.https = (location.protocol == 'https:\/\/') ? 'on' : 'off';
    cgi.path_info = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
    cgi.query_string = (location.search) ? ((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
    cgi.script_name = cgi.path_info;
/* CGI Object */

/* Cookie Object */
var dc = document.cookie;
var nv = dc.split('; ');
var cookie = new Object();
for(i = 0; i < nv.length; i++)
{
  eq = nv[i].indexOf('=');
  cookie[nv[i].substring(0, eq)] = unescape(nv[i].substring(eq + 1));
}
/* Cookie Object */

var toggledDisplay = new Object();

function toggleDisplay(bDisplayed)
{
  if(!document.getElementById || toggleDisplay.arguments.length < 2) return;
  var displayed = new Object();
      displayed['true'] = 'block';
      displayed['false'] = 'none';
  for(var i = 1; i < toggleDisplay.arguments.length; i++)
  {
    oDisplay = document.getElementById(toggleDisplay.arguments[i]);
    if(oDisplay)
    {
      oDisplay.style.display = displayed[bDisplayed];
      if(bDisplayed)
      {
        oImages = oDisplay.getElementsByTagName('IMG');
        for(var j = 0; j < oImages.length; j++)
        {
          if(!oImages[j].readyState || (oImages[j].readyState && oImages[j].readyState != 'complete'))
            oImages[j].src = oImages[j].src;
        }
      }
      if(typeof toggledDisplay[toggleDisplay.arguments[i]] != 'undefined')
        toggledDisplay[toggleDisplay.arguments[i]] = !bDisplayed;
    }
  }
}

function newWindow(href, target, width, height)
{
  var returnValue = false;
  var features = (width != null && height != null) ? ((arguments.length == 4 || arguments[4] != null) ? 'scrollbars,status,width=' + width + ',height=' + height : ((arguments[4]) ? arguments[4] + ',width=' + width + ',height=' + height : 'width=' + width + ',height=' + height)) : ((arguments.length > 4 && arguments[4] != null) ? arguments[4] : null);
  var caller = (arguments.length >= 6) ? arguments[5] : null;
  if(width != null && height != null && window.screen)
  {
    var pxLeft = ((screen.availWidth - width - 10) * .5);
    var pxTop = ((screen.availHeight - height - 30) * .5);
    features += ',left=' + pxLeft + ',top=' + pxTop + ',x=' + pxLeft + ',y=' + pxTop;
  }
  if(!window.open)
    returnValue = true;
  else
  {
    if(features != null)
      self[target + 'Win'] = window.open(href, target, features);
    else
      self[target + 'Win'] = window.open(href, target);
    if(!self[target + 'Win'])
      alert('You appear to be using pop-up blocking software.\n\nYou are trying to use a feature of this site that uses a pop-up window.\n\nPlease disable your pop-up blocker or enable pop-ups for this site.');
    else if(self[target + 'Win'].focus)
      self[target + 'Win'].focus();
    if(caller)
      returnValue = self[target + 'Win'];
  }
  return returnValue;
}

var openWin = null;
  
function openWindow(title, href, target, width, height)
{
  var openWinHTML = '<html><head><title>' + title + '</title></head><body marginheight="0" marginwidth="0" style="margin: 0px"><a href="JavaScript://" onclick="self.close(); return false"><img src="' + href + '" height="' + height + '" width="' + width + '" border="0" galleryimg="no" alt="' + title + ' (Click to close)"></a></body></html>';
  openWin = newWindow('', target, width, height, null, true);
  if(openWin)
  {
    openWin.document.open();
    openWin.document.write(openWinHTML);
    openWin.document.close();
    if(openWin.focus)
      openWin.focus();
  }
  return false;
}

function convertBookmarklets()
{
  if(document.getElementsByTagName)
  {
    var oPre = document.getElementsByTagName('PRE');
    for(var i = 0; i < oPre.length; i++)
    {
      oA = document.createElement('A');
      oA.innerText = oPre[i].getAttribute('title');
      oA.setAttribute('title', 'Right-click and select "Add to Favorites/Bookmarks..."');
      oA.setAttribute('href', oPre[i].innerText);
      oPre[i].replaceNode(oA);
    }
  }
}

function addEvent(oObject, sEvent, sFunction)
{
  var returnValue = null;
  var bCapture = false;
  if(addEvent.arguments.length == 4)
    bCapture = addEvent.arguments[3];
  if(oObject.addEventListener)
  {
    returnValue = oObject.addEventListener(sEvent, sFunction, bCapture);
    return true;
  }
  else if(oObject.attachEvent)
  {
    returnValue = oObject.attachEvent('on' + sEvent, sFunction);
    return returnValue;
  }
  return returnValue;
} 

function removeEvent(oObject, sEvent, sFunction)
{
  var returnValue = null;
  var bCapture = false;
  if(addEvent.arguments.length == 4)
    bCapture = addEvent.arguments[3];
  if(oObject.removeEventListener)
  {
    oObject.removeEventListener(sEvent, sFunction, bCapture);
    return true;
  }
  else if (oObject.detachEvent)
  {
    returnValue = oObject.detachEvent('on' + sEvent, sFunction);
    return returnValue;
  }
  return returnValue;
}

function createCookie(name, value, days)
{
  var expires = '';
  if(days)
  {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = '; expires=' + date.toGMTString();
  }
  document.cookie = name.toUpperCase() + '=' + value + expires + '; path=/';
//  alert(document.cookie);
}


