function js_isIE() {
    return (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
}
if (!js_isIE()) document.captureEvents(Event.MOUSEMOVE);

var isFirefox = document.getElementById && !document.all

var js_mouseActions = {
    onmousedown : function(e) {},
    onmousemove : function(e) {},
    onmouseup : function(e) {}
}

document.onmousedown = function(e) {
    js_mouseActions.onmousedown(e);
}

document.onmousemove = function(e) {
    js_getMousePos(e);
    js_mouseActions.onmousemove(e);   
}

document.onmouseup = function(e) {
    js_onmouseup_popup(e);
    js_mouseActions.onmouseup(e);   
}

var js_bodyActions = {
    onload : function() {},
    onunload : function() {}
}

// Number parsing:

var numbers = new Array();
numbers["0"] = 0;
numbers["1"] = 1;
numbers["2"] = 2;
numbers["3"] = 3;
numbers["4"] = 4;
numbers["5"] = 5;
numbers["6"] = 6;
numbers["7"] = 7;
numbers["8"] = 8;
numbers["9"] = 9;

function js_intFromString(string) {
    var number = 0;
    try {
        var multi = 1;
        for (var i = string.length; i > 0; i--) {
            number += numbers[string.substring(i - 1, i)] * multi;
            multi = multi * 10;
        }
    } catch (error) { }
    return number;
}

function isNumber(string) {
    for (var i = 0; i < string.length; i++) {
        if ('1234567890'.indexOf(string.charAt(i)) == -1) {
            return false;
        }     
    }	
    return true;
}

// String manipulation:

function js_trim(text) {
    if (text == null) {
	return text;
    }
    while ((text.substring(0,1) == ' ') || 
	   (text.substring(0,1) == '\n') || 
	   (text.substring(0,1) == '\r')) {
	text = text.substring(1, text.length);
    }    
    while ((text.substring(text.length - 1, text.length) == ' ') || 
	   (text.substring(text.length - 1, text.length) == '\n') || 
	   (text.substring(text.length - 1, text.length) == '\r')) {
	text = text.substring(0, text.length - 1);
    }
    return text;
}

function js_split(text, split) {
    var texts = new js_list();
    if (text == null) {
	return texts;
    }
    var index = text.indexOf(split);
    while (index != -1) {
	var tmp = trim(text.substr(0, index));
	text = trim(text.substr(index + 1, text.length));
	if (tmp != "") {
	    texts.addElement(tmp);
	}
	index = text.indexOf(split);
    }
    if (trim(text) != "") {
	texts.addElement(trim(text));
    }
    return texts;
}

function js_replace(text, oldText, newText) {
    var index = text.indexOf(oldText);
    while (index != -1) {
	text = text.substring(0, index) + newText + text.substring(index + oldText.length, text.length);
	index = text.indexOf(oldText);
    }
    return text;
}

// HTML update stuff:

function js_rewrite(id, html) {
    element = eval(document.getElementById(id));
    element.innerHTML = html;
}

function js_append(id, html) {
    element = eval(document.getElementById(id));
    element.innerHTML += html;
}

// Go to stuff:

function js_goToTop() {
    window.location.href = '\#';
}

function js_goToUrl(url) {
    if (js_busy) return;
    self.location = url;
}

// Key code stuff:

function js_getKeyCode(event) {    
    if (!event) {
        event = window.event;
    }
    var code;
    if (event.keyCode) {
        code = event.keyCode;
    } else if (event.which) {
        code = event.which;
    }
    return code;
}

function js_enter(event) {
    return (js_getKeyCode(event) == '13');
}

// Sort stuff:

function js_sortStrings(a, b) {
    var x = a.toLowerCase();
    var y = b.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));    
}

function js_sortNumbers(a, b) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));    
}

// Switch mouse selection on/off:

var js_selectionMode_off = new Array(); // Ids of objects whose selection mode should be turned off in Mozilla...
function js_selectionMode(on) {
    // Mozilla:
    for (var i = 0; i < js_selectionMode_off.length; i++) {
        if (document.getElementById(js_selectionMode_off[i]) != null) {
            var className = document.getElementById(js_selectionMode_off[i]).className;
            if ((className == null) || (className == "")) {
                className = on ? "" : "unselectable";
            } else {
                if (!on && (className.indexOf("unselectable") == -1)) {
                    className += " unselectable";
                } else if (on && (className.indexOf("unselectable") != -1)) {
                    className = className.substring(0, className.indexOf("unselectable"));
                }
            }
            document.getElementById(js_selectionMode_off[i]).className = className;
        }
    }
    // IE:
    var theBody = document.getElementById("the_body");
    if (on) {
        theBody.onselectstart = function(e) { return true; }
        theBody.unselectable = "off";
    } else {
        theBody.onselectstart = function(e) { return false; }
        theBody.unselectable = "on";
    }
}

/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this header
*/
var js_mousePos = null;
function js_getMousePos(e) {
    try {
        var x = -1;
        var y = -1;
        if (js_isIE()) {
            x = event.clientX + document.getElementById("the_body").scrollLeft;
            y = event.clientY + document.getElementById("the_body").scrollTop;
        } else {  
            x = e.pageX;
            y = e.pageY;
        }  
        if ((x > 0) && (y > 0)) {
            js_mousePos = new Array(x, y);
        } else {
            js_mousePos = null;
        }
    } catch (error) {
        js_mousePos = null;
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return new Array(curleft, curtop);
}

function js_getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    try {
        if (typeof(window.pageYOffset) == "number") {
            // Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            // DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            // IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
    } catch (error) {}
    return new Array(scrOfX, scrOfY);
}

function js_getPageSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
        // Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        // IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        // IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return new Array(myWidth, myHeight);
}

function getPageSizeWithScroll(){
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // All but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // Works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    return new Array(xWithScroll, yWithScroll);
}

// Busyness:

var js_busy = false;

function js_busyness(take) {
    if (take && js_busy) {
        return false;
    }

    if (take) {
        js_busy = true;
        js_glassPane(true);
    } else {
        js_glassPane(false);
        js_busy = false;
    }        

    return true;
}

function js_glassPane(show) {
    var glassPane = document.getElementById("glass_pane");
    if (show) {
        var body = document.getElementById("the_body");
        var xy = getPageSizeWithScroll();
        glassPane.style.width = xy[0] + "px";
        glassPane.style.height = xy[1] + "px";
        glassPane.style.display = "block";
    } else {
        glassPane.style.display = "none";
    }
}

// Error handling:

var js_errorMethod = null;

function js_setDwrErrorHandler(handler) {
    js_errorMethod = handler;
    try {
        DWREngine.setErrorHandler(js_error);    
    } catch (error) { }
}

function js_error(error) {
    js_errorMethod(error);
}

// Mailto:
function js_otliam(email, subject) {
    document.location.href = "mailto:" + email + "?subject=" + subject;
}

function js_validEmailAddr(addr) {
    addr = trim(addr);
    if (addr.indexOf("@") == -1) {
	return false;
    }
    if (addr.indexOf(" ") != -1) {
	return false;
    }
    return true;
}