//alert (document.URL + " " + top [this]);

function isDefined (n)
  {
    return (typeof (n) != "undefined");
  }
  
function stopPropagation (event)
  {
    if (isDefined (window.event))
      {
        event.cancelBubble = true;
        return;
      }
    event.stopPropagation (); 
  }

function getEvent ()
  {
    if (isDefined (window.event))
      {
        return (window.event);
      }
    return (getEvent.caller.arguments [0]); 
  }

function getSource (event)
  {
    if (isDefined (event.srcElement))
      {
        return (event.srcElement);
      }
    return (event.target);
  }

function clearSelection ()
  {
    if (! isDefined (document.selection))
      {
        getSelection ().removeAllRanges ();
        return;
      }
    document.selection.empty ();
  }

function windowWidth ()
  {
    if (isDefined (window.innerWidth))
      {
        return (window.innerWidth);
      }
    if (document.documentElement.clientWidth == 0)
      {
        // older version of IE
        return (document.body.clientWidth);
      }
    return (document.documentElement.clientWidth);
  }

function windowHeight ()
  {
    if (isDefined (window.innerHeight))
      {
        return (window.innerHeight);
      }
    if (document.documentElement.clientHeight == 0)
      {
        // older version of IE
        return (document.body.clientHeight);
      }
    return (document.documentElement.clientHeight);
  }

function setWindowWidth (n)
  {
    if (isDefined (window.innerWidth))
      {
        window.innerWidth = n;
        return;
      }
    if (document.documentElement.clientWidth == 0)
      {
        // older version of IE
        document.body.clientWidth = n;
        return;
      }
    document.documentElement.clientWidth = n;
  }

function setWindowHeight ()
  {
    if (isDefined (window.innerHeight))
      {
        window.innerHeight = n;
        return;
      }
    if (document.documentElement.clientHeight == 0)
      {
        // older version of IE
        document.body.clientHeight = n;
        return;
      }
    document.documentElement.clientHeight = n;
  }
  
function resizeWindow (width, height)
  {
    var h = height;
    var w = width;

    w -= document.body.offsetWidth;
    h -= document.body.offsetHeight;
    window.resizeBy (w, h);
    //setWindowWidth (w);
    //setWindowHeight (h);
  }

function checkLoad (frames)
  {
    if (! top [document.URL])
      {
        top [document.URL] = true;
      }
    else
      {
        for (var i = 0; i < frames.length; i ++)
          {
            if (! frames [i])
              {
                continue;
              }
            top [frames [i].document.URL] = false;
            frames [i].document.location.reload ();
          }
      }
  }

function el (id)
  {
    if (id == null)
      {
        return (null);
      }
    return (document.getElementById (id));
  }

function rand (n)
  {
    return (Math.floor (Math.random () * 100000) % n);
  }

function removeElement (el)
  {
    el.parentNode.removeChild (el);
  }
  
function setElement (el, newEl)
  {
    el.parentNode.replaceChild (newEl, el);
  }
  
function insertBefore (existingEl, el)
  {
    existingEl.parentNode.insertBefore (el, existingEl);
  }
  
function insertAfter (existingEl, el)
  {
    existingEl.parentNode.insertBefore (el, existingEl.nextSibling);
  }
  
function setElementById (id, newEl)
  {
    setElement (el (id), newEl);
  }
  
function setElementText (el, text)
  {
    el.childNodes.item (0).data = text;
  }
  
function setTitle (title)
  {
    setElementText (el ("title"), title);
  }

function copyAttributes (to, from)
  {
    var attrs = from.attributes;
    
    for (var i = 0; i < attrs.length; i ++)
      {
        attr = attrs.item (i);
        if (attr.nodeValue && attr.nodeValue != null)
          {
            to.setAttribute (attr.nodeName, attr.nodeValue);
          }
      }
  }
  
function selectOption (sel, index)
  {
    // usual bugs in NN
    sel.options [index].selected = true;
    sel.options.selectedIndex = index;
    sel.selectedIndex = index;
  }
  
function waitLoad (img, action)
  {
    if (! img.complete)
      {
        setTimeout (function () { waitLoad (img, action); }, 10);
      }
    else
      {
        //alert (action);
        action ();
      }
  }

function fitImage (img, maxWidth, maxHeight)
  {
    var newWidth;
    var newHeight;

    //alert (maxWidth);
    //alert (maxHeight);
    if (! img.origWidth || img.origWidth == null)
      {
        img.origWidth = img.width;
        //alert (img.origWidth);
      }
    if (! img.origHeight || img.origHeight == null)
      {
        img.origHeight = img.height;
        //alert (img.origHeight);
      }
    if (maxWidth >= 0 && maxWidth < img.origWidth)
      {
        newHeight = img.origHeight * (maxWidth / img.origWidth);
        newWidth = maxWidth;
      }
    else
      {
        newWidth = img.origWidth;
        newHeight = img.origHeight;
      }
    if (maxHeight >= 0 && maxHeight < newHeight)
      {
        newWidth = newWidth * (maxHeight / newHeight);
        newHeight = maxHeight;
      }
    //alert (newWidth);
    //alert (newHeight);
    img.style.width = Math.floor (newWidth) + "px";
    img.style.height = Math.floor (newHeight) + "px";
  }

function getPagePrefix ()
  {
    var l = document.location;
    var s = "";

    if (l.protocol.indexOf (':') >= 0)
      {
        s += l.protocol.substring (0, l.protocol.indexOf (':'));
      }
    else
      {
        s += l.protocol;
      }
    s += "://" + l.host;
    if (l.pathname && l.pathname != null && l.pathname != "")
      {
        s += l.pathname.substring (0, l.pathname.lastIndexOf ('/'));
      }
    return (s);
  }

function getPage ()
  {
    var l = document.location;
    var s = "";

    if (l.protocol.indexOf (':') >= 0)
      {
        s += l.protocol.substring (0, l.protocol.indexOf (':'));
      }
    else
      {
        s += l.protocol;
      }
    s += "://" + l.host;
    if (isDefined (l.pathname) && l.pathname != null && l.pathname != "")
      {
        s += l.pathname;
      }
    return (s);
  }

function popupWindow (name, url, parameters)
  {
    var pars;

    pars = "directories=no," +
           "hotkeys=no," +
           "location=no," +
           "menubar=no," +
           "scrollbars=no," +
           "titlebar=no," +
           "toolbar=no";
    if (parameters != null)
      {
        pars += "," + parameters;
      }
    window.open (url, name, pars);
  }
  
function removeAllChildren (node)
  {
    var len = node.childNodes.length;
    
    for (var i = len - 1; i >= 0; i --)
      {
        node.removeChild (node.childNodes.item (i));
      }
    //alert (node.childNodes.length);
  }
  
function appendChildren (node, nodes)
  {
    for (var i = 0; i < nodes.length; i ++)
      {
        node.appendChild (nodes [i]);
      }
    //alert (node.childNodes.length);
  }
  
function textToNodes (text)
  {
    var s = "";
    var nodes = new Array ();
    var node;
    var lastspace = true;
    var c;
    
    for (var i = 0; i < text.length; i ++)
      {
        c = text.charAt (i);
        if (c == '\r')
          {
            continue;
          }
        if (c == '\n')
          {
            node = document.createTextNode (s);
            nodes.push (node);
            node = document.createElement ("br");
            nodes.push (node);
            s = "";
            lastspace = true;
            continue;
          }
        if (c == ' ' && lastspace)
          {
            c = '\xA0';
          }
        s += c;
        lastspace = (c == ' ');
      }
    node = document.createTextNode (s);
    nodes.push (node);
    return (nodes);
  }

var __onLoadTasks = new Array ();
var __onClickTasks = new Array ();

function __onLoad (event)
  {
    for (var i = 0; i < __onLoadTasks.length; i ++)
      {
        __onLoadTasks [i] (event);
      }
  }

function __onClick (event)
  {
    for (var i = 0; i < __onClickTasks.length; i ++)
      {
        __onClickTasks [i] (event);
      }
  }

function addOnLoadTask (f)
  {
    __onLoadTasks.push (f);
  }

function addOnClickTask (f)
  {
    __onClickTasks.push (f);
  }



