// JavaScript Document
<!-- hide from none JavaScript Browsers

function findTarget(e, nodeName) {
    var target;
    nodeName = nodeName.toLowerCase();

    if (window.event && window.event.srcElement) {
        target = window.event.srcElement;
    } else if (e && e.target) {
        target = e.target;
    }
    if (!target) {
       return null;
    }

    while (target != document.body &&
           target.nodeName.toLowerCase() != nodeName) {
        target = target.parentNode;
    }

    if (target.nodeName.toLowerCase() != nodeName) {
        return null;
    }

    return target;
}

// Cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko 
// By Scott Andrew
function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = fn;
    }
}

function removeEvent( elm, evType, fn )
{
    if (elm.removeEventListener)
	elm.removeEventListener( evType, fn, false );
    else if (elm.detachEvent) {
	elm.detachEvent( "on"+evType, elm[evType+fn] );
	elm[evType+fn] = null;
	elm["e"+evType+fn] = null;
    }
}

function basename(f) {
    return (f.match(/[\/|\\]([^\\\/]+)$/))[1];
}

function removeAllChildNodes(el) {
    if (el.hasChildNodes()) {
        while (el.childNodes.length >= 1) {
            el.removeChild(el.firstChild);
        } 
    }
}

function hCentre(el) {
    var offset = (el.parentNode.clientWidth - el.clientWidth) / 2;
    el.style.position = "relative";
    el.style.left = offset + "px";
}

// supplant() does variable substitution on the string. It scans through the
// string looking for expressions enclosed in { } braces. If an expression is
// found, use it as a key on the object, and if the key has a string value or
// number value, it is substituted for the bracket expression and it repeats.
// This is useful for automatically fixing URLs.
String.prototype.supplant = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};

//The trim() method removes whitespace characters from the beginning and end of the string.
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}; 

// - stop hiding -->
