

domain_bits = document.location.hostname.split(".");
if (!(domain_bits.length==4 && !isNaN(domain_bits[3]))) {
    document.domain = domain_bits.slice(-2).join(".");
}
//"www.jarmuschek.de";
window.settings = {
    root_dir: "/",
    media_url: "/media/5363/",
    jetson_media_url: "/jetson-media/5363/",
    css_url: "/media/5363/css/default/",
    img_url: "/media/5363/img/default/",
    UPLOADS_URL: "/uploads/",
    FILEBROWSER_ROOT_DIR: "",
    website_url: "http://www.jarmuschek.de/",
    website_ssl_url: "https://www.jarmuschek.de/",
    URL_ID_PERSON: "artist",
    URL_ID_PEOPLE: "artists",
    URL_ID_INSTITUTION: "institution",
    URL_ID_INSTITUTIONS: "institutions",
    URL_ID_EVENT: "event",
    URL_ID_EVENTS: "events",
    URL_ID_DOCUMENT: "document",
    URL_ID_DOCUMENTS: "documents",
    URL_ID_PERSONGROUP: "group",
    URL_ID_PERSONGROUPS: "groups",
    URL_ID_PORTFOLIO: "works",
    lang: "en",
    languages: { 'de': 'Deutsch','en': 'English' }
};

window.website = {
    path: document.location.href.replace(
        settings.website_url,
        "/"
    )
};



window.cancelEvent = function(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    e.returnValue = false;
    if (e.stopPropagation) e.stopPropagation();
    if (e.preventDefault) e.preventDefault();
};



window.getCausingElement = function(e) {
    if (!e) var e = window.event;
    return e.target || e.srcElement;
};



window.open_new_window = function(e) {
    oLink = window.getCausingElement(e);
    while(oLink && oLink.tagName!="A") {
        oLink = oLink.parentNode;
    }
    window.open(oLink.href, '_blank', 'scrollbars=1,menubar=1,toolbar=1,location=1,resizable=1,status=1');
    window.cancelEvent(e);
};


window.redirect = function(sURL) {
    document.location.href = sURL;
};


window.submit_form = function(sFormId) {
    document.getElementById(sFormId).submit();
};


window.dyn_css_rule = function(sSelector, sCssText) {
    try {
        var aSS = document.styleSheets;
        var i;
        for (i=aSS.length-1; i>=0; i--) {
            var oCss = document.styleSheets[i];
            var sMedia = (typeof(oCss.media) == "string")?
                oCss.media:
                oCss.media.mediaText;
            if (!sMedia
                || sMedia.indexOf("screen") != -1
                || sMedia.indexOf("all") != -1
            ) {
                break;
            }
        }
        if (oCss.insertRule) {
            oCss.insertRule(sSelector + " {" + sCssText + "}", oCss.cssRules.length);
        } else if (oCss.addRule) {
            oCss.addRule(sSelector, sCssText);
        }
    } catch(err) {
        var tag = document.createElement('style');
        tag.type = 'text/css'; 
        try {
            tag.innerHTML = sSelector + " {" + sCssText + "}";
        } catch(err) {
            tag.innerText = sSelector + " {" + sCssText + "}";
        }
        document.getElementsByTagName('head')[0].appendChild(tag);
    }
    return sSelector + "{" + sCssText + "}";
};


window.append_to_get = function(oDict) {
    var oLoc = document.location;
    var oParams = {};
    var aPairs = oLoc.search.slice(1).split("&");
    var iLen = aPairs.length;
    for (i=0; i<iLen; i++) {
        aPair = aPairs[i].split("=");
        if (aPair[1]) {
            oParams[aPair[0]] = aPair[1];
        }
    }
    for (sKey in oDict) {
        oParams[sKey] = oDict[sKey];
    }
    var aParams = []
    for (sKey in oParams) {
        if (oParams[sKey]) {
            aParams.push(sKey + "=" + oParams[sKey]);
        }
    }
    if (aParams) {
        oLoc.href = oLoc.pathname + "?" + aParams.join("&");
    } else {
        oLoc.href = oLoc.pathname;
    }
}


