function open_blank(url) {
    // Generate a window name from the URL and open it in a new tab / window.
    window.open(url,url.replace(/[^\w]/g,"_"));
}

function open_anchor(anchor,section) {
    // Required so that links will not open up in the referer's frame.
    parent.location.href="../../?section="+section+"&anchor="+anchor;
}

// Look-up table for pseudo-base64 en- / decoding (data is not padded with "=").
// See http://www.robertgraham.com/tools/base64coder.html
var table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

function encode_base64(data) {
    var length=data.length,i=0;
    var index,buffer=0,bits=0;
    var result="";

    while (i<length) {
        index=data.charCodeAt(i++);
        if (index>255) break;
        // Append 8 bits to the buffer.
        buffer=(buffer<<8)|index;
        bits+=8;
        while (bits>=6) {
            // Read 6 bits from the buffer.
            bits-=6;
            result+=table.charAt((buffer>>bits)&0x3f);
        }
    }

    return result;
}

//window.document.write(encode_base64("theminikisscool@hotmail.com"));

function decode_base64(data) {
    var length=data.length,i=0;
    var index,buffer=0,bits=0;
    var result="";

    while (i<length) {
        index=table.indexOf(data.charAt(i++));
        if (index<0) break;
        // Append 6 bits to the buffer.
        buffer=(buffer<<6)|index;
        bits+=6;
        while (bits>=8) {
            // Read 8 bits from the buffer.
            bits-=8;
            result+=String.fromCharCode((buffer>>bits)&0xff);
        }
    }

    return result;
}

function open_mail(address) {
    // Open the default mail-client with the decoded address.
    window.location.href="mailto:"+decode_base64(address);
}

function get_left(e) {
    if (!e.offsetParent) return e.offsetLeft;
    return get_left(e.offsetParent)+e.offsetLeft;
}

function get_top(e) {
    if (!e.offsetParent) return e.offsetTop;
    return get_top(e.offsetParent)+e.offsetTop;
}

function set_links() {
    var anchors=window.document.getElementsByTagName("a");
    var indicator=window.document.getElementById("indicator");

    for (var a=0;a<anchors.length;++a) {
        // Skip non-hyperlink anchors or those with an "onclick" handler (e.g. Highslide links).
        if (!anchors[a].href || anchors[a].onclick) continue;

        anchors[a].onmouseover=function(e) {
            // IE does not pass the event object, so get it manually.
            if (!e) e=window.event;

            // Show the link indicator when the mouse pointer enters the link tag.
            if (e.target) {
                indicator.style.left=(get_left(e.target)-12)+"px";
                indicator.style.top=(get_top(e.target)-12)+"px";
            } else if (e.srcElement) {
                // IE path.
               indicator.style.left=get_left(e.srcElement)-12;
               indicator.style.top=get_top(e.srcElement)-12;
            }
            indicator.style.visibility="visible";
        }

        anchors[a].onmouseout=function(e) {
            // Hide the link indicator when the mouse pointer leaves the link tag.
            indicator.style.visibility="hidden";
        }
    }
}

