window.onloadListeners = [];

window.addOnloadListener = function(listener) {
    window.onloadListeners.push(listener);
}

window.onload = function() {
    for (var i = 0; i < window.onloadListeners.length; i++) {
        window.onloadListeners[i].call();
    }
}

function $(id) {
    return document.getElementById(id);
}

Object.prototype.$$ = function(tagName) {
    return this.getElementsByTagName(tagName);
}

if (!document.getElementsByClassName) {
    Object.prototype.getElementsByClassName = function(className) {
        var elems = this.$$("*");
        var result = [];
        for (var i = 0; i < elems.length; i++) {
            if (elems.getAttribute("class") == className) {
                result.push(elems[i]);
            }
        }
        return result;
    }
}
Array.prototype.clear = function() {
    this.length = 0;
}

function formatPrice(price) {
    price = price.toString().split("").reverse();
    var p = "";
    for (var i = 0; i < price.length; i++) {
        p = price[i] + p;
        if ((i+1) % 3 == 0) p = " " + p;
    }
    return p;
}

function removeHTMLEnc(txt) {
    txt = txt.replace(/&eacute;/g,"é");
    txt = txt.replace(/&aring;/g,"å").replace(/&Aring;/g,"Å");
    txt = txt.replace(/&auml;/g,"ä").replace(/&Auml;/g,"Ä");
    txt = txt.replace(/&ouml;/g,"ö").replace(/&Ouml;/g,"Ö");
    txt = txt.replace(/&uuml;/g,"ü").replace(/&Uuml;/g,"Ü");
    txt = txt.replace(/&amp;/g," & ");
    return txt;
}


