// Bookmark:
var bookmarkurl     = "http://www.schneiderei-edith.at/";
var bookmarktitle   = unescape(escape_iso(
    "Maß- und Änderungsschneiderei Edith"));

function
addbookmark() { 
    if(document.all) {
        window.external.AddFavorite(bookmarkurl,bookmarktitle);
    }
} 


// Certain textparts will get replaced with images. But instead of simply
// overwriting the text with the image, the text will get enclosed in a span tag
// that hides the text. This is done so the text can get printed.
function
hideBlock(id, alt_text) {
if(!document.getElementById(id)) { window.alert(id); }
    document.getElementById(id).innerHTML =
        alt_text +
        "<span class='noscr'>" +
        document.getElementById(id).innerHTML +
        "</span>";
}

//
// Initializes extern links and links to mail-addresses which were "crypted" in
// the html code.
// Derived from the lightbox-script: 
//      http://www.huddletogether.com
//
function
initExLinks() {
    if(!document.getElementsByTagName) {
        return ;
    }

    var anchors = document.getElementsByTagName("a");

    // Loop through all anchor tags
    for(var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];

        // Oeffnen von neuen Browserfenstern:
        if(anchor.getAttribute("href")  &&
           anchor.getAttribute("rel")   == "newwin")
        {
            anchor.href = "javascript:newwin('"+anchor.getAttribute("href")+"');";
        } else if(anchor.getAttribute("href")   &&
                  anchor.getAttribute("rel")    == "mehl")
        {
            // Um eMail-Adressen vor Sammel-Bots zu verstecken, werden diese
            // nicht in der ueblichen Weise angeschrieben, sondern es werden
            // einige Zeichen ausgetauscht bzw. weggelassen.
            // Die Adresse mail@mail.com muesste im HTML-Quelltext
            // folgendermassen angeschrieben werden: mail, mail com
            // D.h.:
            //  - Punkte muessen durch Leerzeichen ersetzt werden
            //  - Das @-Symbol muss durch die Zeichenkette ", " ersetzt werden

            // Die verschluesselte Mail-Adresse befindet sich innerhalb des
            // Anchortags:
            var mailad  = anchor.innerHTML;

            // Erster Schritt ist das Ersetzen der ", "-Zeichenkette mit dem
            // @-Symbol:
            mailad      = mailad.replace(/, /, "@");

            // Naechster Schritt ist das Ersetzen der Leerzeichen gegen Punkte:
            mailad      = mailad.replace(/ /g, ".");

            // Nachdem die im HTML-Quelltext verschluesselte Mailadresse
            // aufgeloest wurde, kann diese aufgeloeste Version in den
            // href-Parameter des anchor-Tags geschrieben werden:
            anchor.href         = "mailto:" + mailad;

            // Damit kein Besucher die verschluesselte Mailadresse sehen muss -
            // gemeint ist die Beschreibung innerhalb des Anchortags - wird
            // diese nun ebenfalls "schoen" aufbereitet:
            anchor.innerHTML    = mailad;
        } else if(anchor.getAttribute("href")   &&
                  anchor.getAttribute("rel")    == "foto")
        {
            // Link zu einem Fotos soll sich in einem Popup oeffen:
            anchor.href = "javascript:popupPic('" + anchor.getAttribute("href") 
                + "', '" + anchor.getAttribute("title") + "');";
        } else ;
    }
}

function
newwin(url) {
    window.open(url);
}

//
// Adds an event to window.onload without overwriting currently
// assigned onload functions.
// Function found at Simon Willison's weblog - 
//      http://simon.incutio.com/ 
//
function
addLoadEvent(func) {
    var old_onload  = window.onload;

    if(typeof window.onload != 'function') {
        window.onload   = func;
    } else {
        window.onload   = function() {
            old_onload();
            func();
        }
    }
}

/* Converts latin-1 text to utf-8 encoded text. This function has been copied
 * from the selfhtml.org website. */
function
encode_utf8(rawtxt) {
    rawtxt = rawtxt.replace(/\r\n/g,"\n");  /* normalize linebreaks */

    var utftext = "";   /* init buffer to hold the encoded txt */

    for(var n=0; n<rawtxt.length; n++) {    /* loop through the chars */
        var c = rawtxt.charCodeAt(n);       /* get uni-code of cur char */

        if(c<128) { /* all chars from 0 to 127 do not need special encoding. */
            utftext += String.fromCharCode(c);  /* 1 byte */
        } else if((c>127) && (c<2048)) {    /* chars between 127 and 2047: 2b */
            utftext += String.fromCharCode((c>>6)|192);
            utftext += String.fromCharCode((c&63)|128);
        } else {    /* all chars from  2048 to 66536: 3b(yte) */
            utftext += String.fromCharCode((c>>12)|224);
            utftext += String.fromCharCode(((c>>6)&63)|128);
            utftext += String.fromCharCode((c&63)|128);
        }
    }

    return utftext;
}

/* Escapes some special characters so they are shown correctly in the browser's
 * status bar, message-boxes etc.
 * The function simulates the escape() function run in an iso-8859-1 html doc,
 * but since this doc is utf-8 encoded, using the escape function won't work
 * properly. Switching the document's charset to iso using Javascript, escaping
 * the string and switching the charset back to utf-8 won't work, so the
 * characters have to get encoded "manually".
 * The program was taken from:
 * http://www.javarea.de/forum/showthread.php3?threadid=10949
 */
function
escape_iso(txt) {
    /* Create array with chars to replace: */
    var badchars = new Array("Ö",   "ö",   "Ä",   "ä",   "Ü",   "ü",   "ß");
    var encchars = new Array("%D6", "%F6", "%C4", "%E4", "%DC", "%FC", "%DF");

    /* Loop through passed txt and replace smut: */
    for(var i=0; i<badchars.length; i++) {
        myregexp = new RegExp(badchars[i], "g");
        txt      = txt.replace(myregexp, encchars[i]);
    }

    return txt;
}

window.defaultStatus = unescape(escape_iso("Änderungen, Filzmode, " +
    "Maßanfertigungen, Hochzeitsmode"));

