function Browser() {
    var ua, s, i;

    this.isIE    = false;  // Internet Explorer
    this.isNS    = false;  // Netscape
    this.version = null;

    ua = navigator.userAgent;
    s = "MSIE";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    // Treat any other "Gecko" browser as NS 6.1.
    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = 6.1;
        return;
    }
}

var browser = new Browser();

function getEventTarget(event) {
    if (browser.isIE) {
        return window.event.srcElement;
    } else {
        return event.currentTarget;
    }
}

function getContainerWith(node, tagName, className) {
    // Starting with the given node, find the nearest containing element
    // with the specified tag name and style class.
    while (node != null) {
        if (node.tagName != null && node.tagName == tagName && hasClassName(node, className)) {
            return node;
        }
        node = node.parentNode;
    }
    return node;
}

function getPageOffsetLeft(el) {
    var x;

    // Return the x coordinate of an element relative to the page.
    x = el.offsetLeft;
    if (el.offsetParent != null) {
        x += getPageOffsetLeft(el.offsetParent);
    }
    return x;
}

function getPageOffsetTop(el) {
    var y;
    // Return the x coordinate of an element relative to the page.
    y = el.offsetTop;
    if (el.offsetParent != null) {
        y += getPageOffsetTop(el.offsetParent);
    }
    return y;
}

function hasClassName(el, name) {
    var i, list;
    // Return true if the given element currently has the given class name.
    list = el.className.split(" " );

    for (i = 0; i < list.length; i++) {
        if (list[i] == name) {
            return true;
        }
        return false;
    }
}

function popup(page, name, width, height, scrollbars) {
  var x = (screen.width - width) / 2;
  var y = (screen.height - height) / 2;
  newWindow = window.open(page,name,'width='+width+',height='+height+',left='+x+',top='+y+',scrollbars='+scrollbars+',resizable,menubar=no');
  if (parseInt(navigator.appVersion) >= 4) {
    newWindow.window.focus();
  }
  return false;
}

function isEmpty(field,message) {
    if (field == null) {
        alert("Field not found: "+message);
        return "";
    }
    if (field.value.length == 0) {
        return message+"\n";
    }
    return "";
}

function isSelected(select,message) {
    if (select.selectedIndex == 0) {
        return message+"\n";
    }
    return "";
}

function loadImg(imageName)
{
  i = new Image();
  i.src = imageName;
  return i;
}