// ---------------------------------------------------------------
//
// Reiter umschalten
//
// ---------------------------------------------------------------

    function header_navi_aktivierung(id,gewaehlter_navigationspunkt) {
        
        var anzahl_elements = 6;
        var position_string = '';

        for (var k = 1; k <= anzahl_elements; k++)
           {
            
                    if (k == '1') {
                        position_string = 'links';
                    } else if (k == anzahl_elements) {
                        position_string = 'rechts';
                    } else {
                        position_string = 'mitte';
                    };

    
                    if (k == gewaehlter_navigationspunkt){
                        document.getElementById('header_navi' + k ).className = 'header_navi_' + position_string + '_ausgewaehlt';
                        document.getElementById('header_navi' + k + '_innen').className = 'header_navi_innen_aktiv';
                    } else if (k == id) {
                        document.getElementById('header_navi' + k ).className = 'header_navi_' + position_string + '_aktiv';
                        document.getElementById('header_navi' + k + '_innen').className = 'header_navi_innen_aktiv';
                        document.getElementById('header_navi' + k ).style.cursor='hand';
                    } else {
                        document.getElementById('header_navi' + k  ).className = 'header_navi_' + position_string + '_deaktiv';
                        document.getElementById('header_navi' + k + '_innen').className = 'header_navi_innen_deaktiv';
                    } 

           }


            return true;        
        }

// ---------------------------------------------------------------
//
// startet einen flv Film im Flash Player
//
// ---------------------------------------------------------------
function startMovie(selMovie,myDiv)
{
        flashembed(myDiv, 
        {
            src:'/cms/upload/flowplayer/swf/FlowPlayerLight.swf',
            width: 468, 
            height: 300
        },
        {config:
            {
                videoFile: '/cms/upload/flowplayer/movies/'+selMovie,
//              configFileName:'',
                autoPlay:true,
                showOnLoadBegin:true,
                autoBuffering:true,
                startingBufferLength: 5,
                bufferLength: 30,
                controlBarGloss:'high',
                usePlayOverlay:true,
                controlBarBackgroundColor:'0x567890',
                loop: false,
//              videoHeight: 120,
//              controlsWidth: 480,
//              fullScreenScriptURL:'fullscreen.js',
                initialScale:'scale',
                useHwScaling:true,
                showMenu:true,
                menuItems:[true, true, true, true, true, false,false],
                useNativeFullScreen:'true',
                showPlayListButtons: false,
                showFullScreenButton:true 
            }
        } 
    );
}

// ---------------------------------------------------------------
//
// Prueft, ob eine Variante gewewchselt wurde
//
// ---------------------------------------------------------------
function checkProductVariant(ProdForm,sessName,sessID)
{
    option_data_id  =   ProdForm.value;
    if(option_data_id.indexOf(":") != -1 )
    {
        var option_value = option_data_id.split (':');
        var productID   =   option_value[1];
        location.href='/product_info.php?products_id='+productID+'&'+sessName+'='+sessID;
    }
}

// ---------------------------------------------------------------
//
//  Felder für Shop-Login auf Startseite
//
// ---------------------------------------------------------------

function PrepareForInput(fieldname,fieldtext) {
        var str = escape(document.getElementById(fieldname).value);
        if (str == escape(fieldtext)) {
            document.getElementById(fieldname).value = '';
            if (fieldtext == 'Passwort') {
                document.getElementById(fieldname).type = 'password'
            }
        }
}

function RestoreIfEmpty(fieldname,fieldtext) {
        var str = escape(document.getElementById(fieldname).value);
        if (str == escape('')) {
            document.getElementById(fieldname).value = fieldtext;
        }
}

// ---------------------------------------------------------------
//
// Newsletterregistrierung
//
// ---------------------------------------------------------------
function checkNewsletterRegForm(oForm,fName,fEmail,oErrName,oErremail)
{
/*
    alert(oForm.emailname.value);
    alert(oForm.email.value);
    alert(oForm.action.value);
*/
    if(oForm.action.value == "subscribe")
    {
        // Pruefen, ob Name angegeben
        if( trim(oForm.emailname.value) == "" || oForm.emailname.value == fName)
        {
            alert(oErrName);
            oForm.emailname.focus();
            return false;
        }
        // Pruefen, ob E-Mail korrekt
        if( trim(oForm.email.value) == "" || oForm.email.value == fEmail || !DoCheckemailConform(trim(oForm.email.value)))
        {
            alert(oErremail);
            oForm.email.focus();
            return false;
        }
    }
    if(oForm.action.value == "delete")
    {
        // Pruefen, ob E-Mail korrekt
        if( trim(oForm.email.value) == "" || oForm.email.value == fEmail || !DoCheckemailConform(trim(oForm.email.value)))
        {
            alert(oErremail);
            oForm.email.focus();
            return false;
        }
    }
    return true;
}

// ---------------------------------------------------------------
//
//  DoCheckemail
//  @Die Funktion DoCheckemail prueft einen String auf eine 
//  gueltige Email Adresse   
//
// ---------------------------------------------------------------

function DoCheckemailConform( str )
{
    // Feld darf nicht leer sein
    if( trim(str) == '' )
    {
        return(false);
    }
    // Auf Zeichen @
    if( str.indexOf("@") == -1 )
    {
        return(false);
    }
    // Auf Zeichen -.-
    if( str.indexOf(".") == -1 )
    {
        return(false);
    }
    return(true);
}

// ---------------------------------------------------------------
//
// Zum Seitenanfang
//
// ---------------------------------------------------------------
function goPageTop()
{
    pUrl    =   location.pathname + location.search + '#Top';
    location.href=pUrl;
}


// ---------------------------------------------------------------
//
// Öffnet ein Fenster
//
// ---------------------------------------------------------------
    function oNewPopupWin()
    {

        winPara = new Array(6);
        winPara[0]  =   '';     //  URL
        winPara[1]  =   'myPopup';      //  Fenstername
        winPara[2]  =   '500';  //  Breite
        winPara[3]  =   '500';  //  Höhe
        winPara[4]  =   'no';   //  Scrollbars
        winPara[5]  =   'no';   //  Toolbars
        winPara[6]  =   'yes';  //  resizable
        for (var i=0; i<oNewPopupWin.arguments.length; i++)
        {
            winPara[i]  =   oNewPopupWin.arguments[i];
        }
        if(winPara[0] != '')
        {
            WindowName  =   window.open('/cms/upload/popup/' + winPara[0],winPara[1],'width='+winPara[2]+',height='+winPara[3]+',dependent=yes,scrollbars='+winPara[4]+',toolbar='+winPara[5]+',resizable='+winPara[6]);
            WindowName.focus();
        }
    }

// ---------------------------------------------------------------
//
// Führt einen exec Befehl aus
//
// ---------------------------------------------------------------
function doExecCommand(c)
{
    document.execCommand(c);
}

// ---------------------------------------------------------------
//
// Druckvorschau
//
// ---------------------------------------------------------------

/*
    des isch net so eifach ...
*/


// ---------------------------------------------------------------
//
// Funktion zum zeilenweise Umschalten von Tabellenhintergründen, 
// wenn die Maus über eine Tabellenzeile fährt. Jede Tabellenzeile 
// benötigt zum korrekten Funktionieren eine eindeutige ID.
//
// ---------------------------------------------------------------

function rowRollover(myId,BackgroundColorStandard,BackgroundColorMouseOver,isInRow) {
  // myId is our own integer id, not the DOM id
  // isInRow is 1 for onmouseover, 0 for onmouseout
  var row = document.getElementById(myId);
  rowWithMouse = (isInRow) ? row : null;
  row.style.backgroundColor = (row == rowWithMouse) ? BackgroundColorMouseOver : BackgroundColorStandard;
}



// ---------------------------------------------------------------
//
// Zahl runden
//
// ---------------------------------------------------------------
    function runde(x, n)
    {
        if (n < 1 || n > 14) return false;
        var e = Math.pow(10, n);
        var k = (Math.round(x * e) / e).toString();
        if (k.indexOf('.') == -1) k += '.';
        k += e.toString().substring(1);
        return k.substring(0, k.indexOf('.') + n+1);
    }


// ---------------------------------------------------------------
//
// Filter auf numerische Werte.
//
// ---------------------------------------------------------------
function cashFilter(nCash)
{
    nCash=runde(nCash,2);
    nCash   =   ''+nCash;
    nCash   =   nCash.replace('.',',');
    fCash   =   '';
    // Filter anwenden
    numPos      =   -1;
    setPoint    =   0;
    for( i = (nCash.length-1); i >= 0; i -- )
    {
        if( nCash.charAt( i ) == ",")
        {
            setPoint = 1;
        }
        if(numPos==3)
        {
            // Punkt einfuegen
            fCash='.' + fCash;
            numPos=0;
        }
        if(setPoint == 1)
        {
            numPos++;
        }
        fCash=nCash.charAt( i ) + fCash;
    }
    // wenn setPoint immer noch == 0, dann gibt es keine Nachkommastellen
    numPos      =   0;
    if(setPoint==0)
    {
        // Wert initialisieren
        fCash='';
        for( i = (nCash.length-1); i >= 0; i-- )
        {
            if(numPos==3)
            {
                // Punkt einfuegen
                fCash='.' + fCash;
                numPos=0;
            }
            numPos++;
            fCash=nCash.charAt( i ) + fCash;
        }
    }
    return fCash;

}

// ---------------------------------------------------------------
//
// Numerische Eingabe (,) korrigieren.
//
// ---------------------------------------------------------------
function toDBNumber(valField)
{
    sValue  =   valField;
    if(trim(sValue) == '')
    {
        return 0;
    }
    
    sTmpValue=sValue;
    for( i = 0; i < sTmpValue.length; i ++ )
    {
        if( sTmpValue.charAt( i ) == ".")
        {
            sValue  =   sValue.replace('.','');
        }
    }
    nValue  =   sValue.replace(',','.');
    // Jeden Char prüfen
    for( var i = 0; i < nValue.length; i++ )
    {
        // Char aus dem String holen
        FieldChar = nValue.charAt(i);
        // Optionales Vorzeichen handeln
        if( (i==0) && (FieldChar == "+") && (FieldChar == "-") )
        { continue; }
        // testen, ob der Char im gueltigen Bereich liegt
        if( (FieldChar != "." ) && ((FieldChar < "0") || (FieldChar > "9")) )
        {
            return 0;
        }
    }
    return parseFloat(nValue);
}


/*
function click(e){if (document.all) if (event.button == 2) return false;if
(document.layers) if (e.which == 3) return false;}
function click2(){event.returnValue=false;return false;}if (document.layers)
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;
*/


nn4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function CheckEnterPressed(Ereignis) {
 if (nn4) var taste=Ereignis.which
 if (ie4) var taste=event.keyCode
 if (taste==13) {return true;}
 return false;
}

    function checkEnterForSearch(e)
    {
        var characterCode;

        if(e && e.which)
        {
            e = e;
            characterCode = e.which
        }
        else
        {
            e = event;
            characterCode = e.keyCode;
        }

        if(characterCode == 13)
        {
            search();
        }
    }

    function submitt(aktion,toAnchor)
    {
        if(toAnchor)
        {
            document.form1.action = document.form1.action + '#' + toAnchor;
        }
                
        document.form1.aktion.value=aktion;
        document.form1.submit();
    }



    function openAdminWin()
    {
        var adminWin;
        adminWin = window.open('/intranet/admin/user/user.php','adminWin','width=700,height=275,dependent=yes,scrollbars=no,statusbar=no,toolbar=no,resizable=no');
        adminWin.focus();
    }


    function StartOpenNewWindow(paurl,pawidth,paheight,pascrollbars,patoolbar,WindowName)
    {
        WindowName  =   window.open( paurl,WindowName,'width='+pawidth+',height='+paheight+',dependent=yes,scrollbars='+pascrollbars+',toolbar='+patoolbar+',resizable=yes');
        WindowName.focus();
    }


// ---------------------------------------------------------------
//
//  trim
//  @Die Funktion trim uebernimmt einen String entfernt
//   ggf. vorausstehende sowie anhaengende Blanks und 
//   gibt den (modifizierten) String wieder zurueck.   
//
// ---------------------------------------------------------------

function trim( str )
{
    var n;
    var i;

    // initialisieren der Blanks vor dem String i entspricht dem ersten Index        
    for( i = 0; i < str.length; i ++ )
    {
        if( str.charAt( i ) != " ") { break; }
    }
    
    // initialisieren der Blanks nach dem String n entspricht dem zweiten Index 
    for( n = str.length-1; n >= i; n -- )
    {
        if( str.charAt( n ) != " " ) { break; }
    }

    // Ausschneiden des Stringabschnittes   
    str=str.substring( i, n+1 );

    // Rueckgabe des modifizierten Strings   
    return(str);
    
} // trim


// ---------------------------------------------------------------
//
//  stringToTime
//  @Uhrzeiteingabe im Format <HH:mm>
//  @<datum>: zu wandelnder String
//
// ---------------------------------------------------------------

function stringToTime( patime ,errorMsg_a,errorMsg_b,errorMsg_c)
{
    var i, j, str, ch;
    var anzPunkte = 0;

    // ---
    // Konsitenzpuefungen
    // ---
    if( patime.length != 5 )
    {
        errorMsg_a  =   errorMsg_a.replace('%a',patime);
        alert( errorMsg_a );
        return( null );
    }
    for( i = 0; i < patime.length; i ++ )
    {
        ch = patime.charAt( i );
        if( ch == ':' )
        { 
            anzPunkte ++;
        }
        else
        {
            if( ch < '0' || ch > '9' )
            {
                errorMsg_b  =   errorMsg_b.replace('%a',patime);
                errorMsg_b  =   errorMsg_b.replace('%b',ch);
                alert( errorMsg_b );
                return( null );
            }
        }
    }
    if( anzPunkte != 1 )
    {
        errorMsg_c  =   errorMsg_c.replace('%a',patime);
        alert( errorMsg_c );
        return( null );
    }

    // Alles OK
    return(true);
    
} // stringToTime

// ---------------------------------------------------------------
// Browser Detection
// you can query three properties of the BrowserDetect object:
// Browser name: BrowserDetect.browser 
// Browser version: BrowserDetect.version 
// OS name: BrowserDetect.OS 
// ---------------------------------------------------------------

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {   string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari"
        },
        {
            prop: window.opera,
            identity: "Opera"
        },
        {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        },
        {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        },
        {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        },
        {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        },
        {       // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        },
        {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
        },
        {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        },
        {       // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }
    ]

};
BrowserDetect.init();
