function decode_utf8(utftext) {
    var plaintext = ""; var i=0; var c=c1=c2=0;
    // while-Schleife, weil einige Zeichen uebersprungen werden
    while(i<utftext.length) {
        c = utftext.charCodeAt(i);
        if (c<128) {
            plaintext += String.fromCharCode(c);
            i++;
        } else if((c>191) && (c<224)) {
            c2 = utftext.charCodeAt(i+1);
            plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
            i+=2;
        } else {
            c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
            plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
            i+=3;
        }
    }
    return plaintext;
}



function strip_tags($text){
    return $text.replace(/<\/?[^>]+>/gi, '');
}



function phpserialize (a) {
    // This converts a javascript array to a string in PHP serialized format.
    // This is useful for passing arrays to PHP. On the PHP side you can
    // unserialize this string from a cookie or request variable. For example,
    // assuming you used javascript to set a cookie called "php_array"
    // to the value of a javascript array then you can restore the cookie
    // from PHP like this:
    //    &lt;?php
    //    session_start();
    //    $my_array = unserialize(urldecode(stripslashes($_COOKIE['php_array'])));
    //    print_r ($my_array);
    //    ?&gt;
    // This automatically converts both keys and values to strings.
    // The return string is not URL escaped, so you must call the
    // Javascript "escape()" function before you pass this string to PHP.

    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
    // return a;
}






function initFlashHeads() {
    var flashHeads = $$( 'h2.flashh2', 'h2 span.flashh2', 'h3.flashh3', 'h3 span.flashh3', 'h4.flashh4', 'h4 span.flashh4' );

    for (i=0; i<flashHeads.length; i++) {
        mySwf       = "headline_big.swf";
        myObj       = flashHeads[i];
        myId        = myObj.id;
        myText2     = '';
        myType      = "1";
        myHeight    = "45";
        myWidth     = "500";
        myAlign     = "left";
        mySize      = "normal";
        
        myText      = myObj.innerHTML;
        
        if (myObj.hasClassName('flashh4')) {
            if (myText.search(/<span[^>]+>(.*)<\/span>/gi)>0) {
                myText2     = myText.replace (/(.*)<span[^>]+>/gi, '');
                myText2     = myText2.replace(/<\/span>(.*)/gi, '');
                // alert(myText2);
            }
            myHeight    = "32";
            // if (myObj.hasClassName('narrow'))   myWidth = "800";
        }
        
        myText      = myText.replace(/<span[^>]+>.*<\/span+>/gi, '');
        myText      = strip_tags(myText);
        
        // myX         = "500";
        
        if (myObj.hasClassName('flashh3'))  myType      = "0";
        if (myObj.hasClassName('flashh4'))  mySwf       = "headline_medium.swf";
        if (myObj.hasClassName('right'))    myAlign     = "right";
        if (myObj.hasClassName('full'))     mySize      = "full";
        // if (myObj.hasClassName('x315'))     myX         = "315";
        
        ///h   aguments swf object (swf, id, width, height, version, background-color [, quality, xiRedirectUrl, redirectUrl, detectKey])
        // var so = new SWFObject("fileadmin/davedolle/swf/headline_big.swf", myId, "629", myHeight, "8", "#d5d5c3", "BEST");
        var so = new SWFObject("fileadmin/davedolle/swf/"+mySwf, myId, myWidth, myHeight, "8", "#d5d5c3", "BEST");
        
        so.addVariable( "i_type",   myType );
        so.addVariable( "s_text",   myText );
        
        if (myText2)
            so.addVariable( "s_text_1", myText2 );
        
        so.addVariable( "s_align",  myAlign );
        // so.addVariable( "i_x",      myX );
        so.addVariable( "s_size",   mySize );
        so.addParam( "wmode", "transparent" );
        so.write( myId );
    }
}



function initFlashButtons() {
    var flashButtons    = $$( 'a.flash-button', 'a.download' );
    myScope         = 'tmp_'+ (Math.random()*10) +'_';
    myScope         = myScope.replace(/\./gi, '');
    
    for (i=0; i<flashButtons.length; i++) {
        // myWidth     = "629";
        // myHeight    = "27";
        // myWidth     = "625";
        // myHeight    = "32";
        myWidth     = "300";
        myHeight    = "32";
        mySwf       = "button_300_r.swf";
        myObj       = flashButtons[i];
        s_text      = strip_tags(myObj.innerHTML).toLowerCase();
        s_link      = myObj.readAttribute('href');
        s_window    = "_self";
        
        if (!myObj.hasAttribute('id')) {
            myObj.setAttribute('id', myScope+i );
        }
        
        myId        = myObj.id;
        
        var so = new SWFObject("fileadmin/davedolle/swf/"+mySwf, myId, myWidth, myHeight, "8", "#ffffff", "BEST");
        // alert(myObj.firstChild.data);
        so.addVariable( "s_text",   s_text );
        so.addVariable( "s_link",   s_link );
        so.addVariable( "s_align",  "right" );
        so.addVariable( "s_window",  s_window );
        so.addParam( "wmode", "transparent" );
        so.write( myId );
    }
}



function initFlashForms() {
    var flashLabels = $$( 'label' );
    mySwf           = "form.swf";
    myScope         = 'tmp_'+ (Math.random()*10) +'_';
    myScope         = myScope.replace(/\./gi, '');
    
    for (i=0; i<flashLabels.length; i++) {
        myWidth     = "100";
        myHeight    = "20";
        myObj       = flashLabels[i];
        s_text      = strip_tags(myObj.innerHTML).toLowerCase();
        
        if (!myObj.hasAttribute('id')) {
            myObj.setAttribute('id', myScope+i );
        }
        
        if (myObj.hasClassName('x315')) {
            // myWidth = "315";
            myWidth = "475";
        }
        
        myId        = myObj.id;
        
        var so = new SWFObject("fileadmin/davedolle/swf/"+mySwf, myId, myWidth, myHeight, "8", "#ffffff", "BEST");
        // alert(myObj.firstChild.data);
        so.addVariable( "s_text",   s_text );
        so.addParam( "wmode", "transparent" );
        so.write( myId );
    }
    
    // $$( 'input.submit' ).style.display='none';
}



function initNews( i_L, s_LANG ) {
    if ($('intro')) {
        var so = new SWFObject("fileadmin/davedolle/swf/news_080326.swf", "ddintro", "629", "314", "8", "#ffffff", "BEST");
        so.addParam( "wmode",           "transparent" );
        so.addVariable( "s_xmlURL",     escape("fileadmin/davedolle/inc/news_xml.php?L="+ i_L +"&"));
        // so.addVariable( "s_newsURL",    escape(""+ s_LANG +"/news/"));
        so.addVariable( "s_newsURL",    '');
        so.addVariable( "s_imagePath",  escape("fileadmin/Eigene_Dateien/News/"));
        so.write( "intro" );
    }
}

function initMenu( i_uid, i_L, i_trainer_id ) {
    var so = new SWFObject("fileadmin/davedolle/swf/menu.swf", "ddmenu", "129", "500", "8", "#ffffff", "BEST");
    so.addVariable( "s_uniqueID",   i_uid );
    // so.addVariable( "s_xmlPath",    escape("index.php?id=###UID###&L=###L###&type=100") );
    so.addVariable( "s_xmlPath",    escape("index.php?id="+ i_uid +"&L="+ i_L +"&type=100&trainer_id="+ i_trainer_id) );
    so.addParam( "wmode", "transparent" );
    so.write( "menu" );
}

