/*
** Blätterkatalog Integration Script
** *********************************
**
** 1)     addToCart(artno, shopsessionid)
**    Wird bei Linktyp "Artikel in Warenkorb legen"
**    aufgerufen.
**
** 
** 2)     blaetterkatalogflip(newPage)
**    Blättert auf die gegebene Seite
**    Wird bei Linktyp "Gehe zu Seite" verwendet.
**
**    TODO: Kann optional verwendet werden
**          um mittels 
**    
**    <a href="javascript:blaetterkatalogflip(5)">Gehe zu Seite 5</a>
**
**    den Blätterkatalog umzublättern.
**    (Beispiel: Auf Kapitel-Startseite blättern)
**
** 3)   gotoURL(myURL)
**       Wird bei Linktyp "Externer Link" und
**    von addToCart aufgerufen
**
*/

    /**
    */
    function addToCart(artno, shopsessionid)
    {
             if(artno=="pp")
            {                        
         InfoWin = window.open("/catalog/artikel_noch_nicht_verfuegbar.php","Message1","height=220 ,width=325,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizeable=no,copyhistory=no,menubar=no");
         InfoWin.focus();
            }
            
      else if (artno=="offline")
            {         
         InfoWin = window.open("/catalog/artikel_nicht_mehr_verfuegbar.php","Message1","height=220 ,width=325,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizeable=no,copyhistory=no,menubar=no");
         InfoWin.focus();
            }
     
        else{ 
            gotoURL(artno);
            }
     }

    /**
    *  blättert auf die entsprechende seite um
    *  setzt voraus, dass der blätterkatalog in
    *  dem fenster noch geladen ist
    */
    function blaetterkatalogflip(newPage)
    {
        flashCommand('jump_to_id', newPage)
    }
    
    /**
    * sprint zu einer URL
    * Ziel: Shop-Fenster
    */ 
    function gotoURL( myURL ) 
    {
    
    
        try {
            
      var sitelink = "/site/de/product_redirect.php?sku="+myURL;
                        
            if ( typeof( opener ) == "undefined" || typeof( opener ) == "unknown" ||
                    typeof( opener.name ) == "undefined" || typeof( opener.name ) == "unknown" )
            {
                if ( shopFenster.closed )    
                {                
                    shopFenster = window.open( sitelink, "shop", "" );
                    shopFenster.focus();
                    
                }
                else 
                {
                  
                    shopFenster.location.href=sitelink;
                    shopFenster.focus();    
                    
                }
            } 
            else 
            {
            /*in diesem Teil wird sitelink aufgerufen*/        
                
        opener.location.href = sitelink;
                opener.blatterkatalogPopup = window;
                opener.focus();
            }
      
        } 
        catch ( Exception )
        {
            if( opener && !opener.closed )
            {
                opener.location.href = sitelink;
                opener.focus();
            }
            else 
            {
                try {
                    if ( shopFenster.closed )    
                    {
                    
                        shopFenster = window.open( sitelink, "shop", "" );
                        shopFenster.focus();
                    }
                    else 
                    {
                    
                        shopFenster.location.href = sitelink;
                        shopFenster.focus();    
                    }
                } 
                catch ( Exception )
                {
                
                        shopFenster = window.open( sitelink, "shop", "" );
                        shopFenster.focus();
                }
            }
        }
    }

    /**
     * getFlashPath() ermittelt das Flash-Objekt
     */
    function getFlashPath() 
    {
        if ( document.all ) 
        {
            //ie
            return document.bkflash;
        }
        else 
        {
            //safari
            var ffilm = document.getElementById( "bkflash" );
            try 
            {
                flashfilm.SetVariable( "tst", "1" );
               } 
               catch ( Exception ) 
               {
                //firefox
                ffilm = document.embeds["bkflash"];
            }
            return ffilm;
        }
    }
    
    
    /////////////////////////////////////
    // Funktion zum externen Aufruf der Flash-Commands
    // id => 'jump_to_id'
    // par => pageid
    // aufruf mit z.b. flashCommand('jump_to_id', 5)
    /////////////////////////////////////
    function flashCommand( id, par ) 
    {
        try
        {
            var movie = getFlashPath();
               movie.SetVariable( "jscommand", id + "|" + par );
        }   
        catch( Exception )
        {
              document.getElementById("bkflash").SetVariable( "jscommand", id + "|" + par );        
        }    
    }
    
    
    function getURLParam( strParamName ) 
    {
    var strReturn = " ";
    var strHref = window.location.href;
    
    var i = strHref.indexOf( strParamName );
    
    if ( i > 0 )
    {
        var j = strHref.indexOf( "=", i + 1 );
        if ( j > 0 )
        {
            var endPos = strHref.length;
            var k = strHref.indexOf( "?", j + 1 );
            var l = strHref.indexOf( "&", j + 1 );
            if ( k > 0 && l > 0 )
            {
                   if ( k < l ) 
                   {
                       endPos = k;
                   }    
                else 
                {
                    endPos = l;
                }    
            } 
            else if ( k > 0 )
            {
              endPos = k;
            } 
            else if ( l > 0 )
            {
              endPos = l;
            }
            
            strReturn = strHref.substring( j + 1 , endPos );
        }    
    }
    return strReturn;
    }    
    window.onerror = stoperror;
    function stoperror( a )
    {
      return false;
    }
