/*
** Blätterkatalog Integration Script
** *********************************
** 
** 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, quan, commi){
		try{
            // Test, ob Zugriff auf opener erlaubt ist
            teststring = opener.name;
        } catch (Exception) {
            if( opener && !opener.closed ) {
                // opener existiert noch, hat aber offensichtlich ein anderes Protokoll (http vs. https)
                alert(protocolErrorMessage);
                return;
            }
        }
    
		var shopURLPostfix_2  = "&Add.x=1";
		var shopURLQuantity   = "&ProductQuantity_1=" + quan;
		var shopURLCommission = "&Commission_1=" + commi;
		    
	   var destinationURL = shopBase + shopURL + shopSessionIDParameterName + shopsessionid + shopArticleIDParameterName + artno + shopURLQuantity + shopURLCommission + shopURLPostfix_2 + shopURLTracking;
	   
	   if (shopDebug) alert("ShopSessionID: "+shopsessionid+"\nArtikel "+artno+" in Detailansicht Shop aufrufen\n\nSHOP URL: "+destinationURL);	
		
	   
	   if (!shopDebug) gotoURL(destinationURL);
	}

  function updateCart(orderdata)
  {
     var myURL = "/save.cart?data="+orderdata;
     window.open( myURL, "order", "" );
  }
  
  function flushCart(orderdata)
  {
     var myURL = "/order?data="+orderdata;
     window.open( myURL, "order", "" );
  }

	/**
	*  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 ) 
	{
    if (myURL.indexOf("http://")!=0 && myURL.indexOf("https://")!=0 && myURL.indexOf("mailto:")!=0)
    {
      myURL = "http://"+myURL;
    }  	

		try {
			if ( typeof( opener ) == "undefined" || typeof( opener ) == "unknown" ||
			    	typeof( opener.name ) == "undefined" || typeof( opener.name ) == "unknown" )
			{
				if ( shopFenster.closed )	
				{
					shopFenster = window.open( myURL, "shop", "" );
					//KB eroom 333:  shopFenster.focus();
					window.focus();
				 	alert(addToBasketMessage)
				}
				else 
				{
					shopFenster.location.href=myURL;
					//KB eroom 333:  shopFenster.focus();	
					window.focus();
				 	alert(addToBasketMessage)
				}
			} 
			else 
			{
				opener.location.href = myURL;
				opener.blatterkatalogPopup = window;
				//KB eroom 333:  opener.focus();
				window.focus();
			 	alert(addToBasketMessage)
			}
		} 
		catch ( Exception )
		{
			if( opener && !opener.closed )
			{
				opener.location.href = myURL;
				//KB eroom 333:  opener.focus();
				window.focus();
			 	alert(addToBasketMessage)
			}
			else 
			{
				try {
					if ( shopFenster.closed )	
					{
						shopFenster = window.open( myURL, "shop", "" );
						//KB eroom 333:  shopFenster.focus();
						window.focus();
					 	alert(addToBasketMessage)
					}
					else 
					{
						shopFenster.location.href = myURL;
						//KB eroom 333:  shopFenster.focus();	
						window.focus();
					 	alert(addToBasketMessage)
					}
				} 
				catch ( Exception )
				{
						shopFenster = window.open( myURL, "shop", "" );
						//KB eroom 333:  shopFenster.focus();
						window.focus();
					 	alert(addToBasketMessage)
				}
			}
		}
	}

	/**
	 * 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;
	}
	
	function getCatalogName(){
		var bkpath =  window.location.pathname;
		var lastSlash =bkpath.lastIndexOf("/");
		bkpath = bkpath.substring(0,lastSlash);
		var  newLastSlash = bkpath.lastIndexOf("/");
		bkpath = bkpath.substring(newLastSlash+1);
		return bkpath;
	}