/**
 * Toggles the layer's visibility
 * 
 * @param layerId the id of the layer
 */

// toggleFunktion fuer den sitemapLayer
function toggleProductLayer(layerId)
{
	
	if(getLayerVisibility(layerId)){
		//schliessen des Layers
		eCrm.log({'pageId': 'coai0035','cDes': eCrmPageId});
	}
	else{
		//oeffnen Layer
		eCrm.log({'pageId': 'coai0034','cDes': eCrmPageId});
	}
	setLayerVisibility(layerId, !getLayerVisibility(layerId));
}



// allgemeine Toogle Funktion
function toggleLayer(layerId)
{
	setLayerVisibility(layerId, !getLayerVisibility(layerId));
}

/**
 * Toggles the layer's visibility
 * 
 * @param layerId the id of the layer
 */
function DivSetVisible(state)
  	{
	var div_popup = document.getElementById('PopupDiv');
	var iframe = document.getElementById('DivShim');
  	if(state)
   {
   		div_popup.style.display = "block";
		
	
		if(div_popup.offsetHeight > 0){
			iframe.style.display = "block";
			var left = parseInt(div_popup.offsetLeft)+1;
			var width = parseInt(div_popup.offsetWidth)-4;
			var hoehe = parseInt(div_popup.offsetHeight)-6; 
			var top = parseInt(div_popup.offsetTop);
			//Breite zuweisen
			iframe.width = width;
			//Hoehe zuweisen
			iframe.height = hoehe;
			//top weisen
			iframe.style.top = top;
			//left zuweisen
			iframe.style.left = left;
  		}
		else{
			iframe.width = 0;
			iframe.height = 0;
		}
		/* der versetze Schatten muss in der Ausrichtung des Iframes mit berechnet werden */
		iframe.style.top = parseInt(div_popup.offsetTop)+'px';	
		iframe.style.left = parseInt(div_popup.offsetLeft)-5+'px';
		iframe.style.zIndex = div_popup.style.zIndex - 1;
    		iframe.style.display = "block";
   }
   
   else
   {
   	div_popup.style.display = "none";
    	iframe.style.display = "none";
   }
};  


/**
 * Determines wether the layer with the given id is currently visible
 *
 * @param layerId The id of the layer
 * @return true if the layer is visible
 */
function getLayerVisibility(layerId)
{
	var obj = findLayer(layerId);	

	
	if (document.all || document.getElementById)
	{
		state = (obj.style.visibility == "visible");
		
	}
	else if (document.layers)
	{
		state = (obj.visibility == "show");
	}
	return state;
}

/**
 * Sets the visibility of the layer with the given id
 *
 * @param layerId The id of the layer
 * @param state The new visibility state; true == visible
 */
function setLayerVisibility(layerId, state)
{
	
	var obj = findLayer(layerId);

	if (state)
	{
		
		
		if (document.all || document.getElementById)
		{
			
			
				obj.style.visibility = "visible";
				obj.style.display = "block";
				
				
			
		}
		else if (document.layers)
		{
		
			obj.visibility = "show";			
		}
	}
	else
	{
		
		
		if (document.all || document.getElementById)
		{
			obj.style.visibility = "hidden";
			obj.style.display = "none";
			
			
			
			
		}
		else if (document.layers)
		{
			obj.visibility = "hide";
			
			
			
		}
	}
}


/**
 * Retrieves the y position of the layer with the given id.
 * The returned value is the y position in pixel calculated from
 * the beginning of the page/document.
 *
 * @param layerId The id of the layer
 * @return The absolute y position of the layer
 */
 function getLayerTop(layerId)
{
	var obj = findLayer(layerId);

	
	if (document.all)
	{
		return obj.style.pixelTop;
	}
	else if (document.getElementById)
	{
		return obj.style.top;
	}
	else if (document.layers)
	{
		return obj.top;
	}	
}

/**
 * Sets the y position of a layer. The value parameter must specify
 * the absolute position in pixel measured from the beginning of the page/document
 *
 * @param layerId The id of the layer
 * @param value The new absolute y position in pixel
 */
function setLayerTop(layerId, value)
{
	var obj = findLayer(layerId);

	
	if (document.all)
	{
		obj.style.pixelTop = value;
	}
	else if (document.getElementById)
	{
		obj.style.top = value + "px";		
	}
	else if (document.layers)
	{
	 	obj.top = value;
	}
}	

/**
 * Retrieves the x position of the layer with the given id.
 * The returned value is the x position in pixel calculated from
 * the left of the page/document.
 *
 * @param layerId The id of the layer
 * @return The absolute x position of the layer
 */
function getLayerLeft(layerId)
{
	var obj = findLayer(layerId);
	
	if (document.all)
	{
		return obj.style.pixelLeft;
	}
	else if (document.getElementById)
	{
		return obj.style.left;
	}
	else if (document.layers)
	{
		return obj.left;
	}		
}	
	

/**
 * Sets the x position of a layer. The value parameter must specify
 * the absolute position in pixel measured from the left of the page/document
 *
 * @param layerId The id of the layer
 * @param value The new x position in pixel
 */
function setLayerLeft(layerId, value)
{
	var obj = findLayer(layerId);
	
		
	if (document.all)
	{
		obj.style.pixelLeft = value;		
	}
	else if (document.getElementById)
	{
		obj.style.left = value + "px";			
	}
	else if (document.layers)
	{
		obj.left = value;		
	}
}		
	
/**
 * Retrieves the height of a layer
 *
 * @param layerId The id of the layer
 * @return The height of the layer in pixel
 */
function getLayerHeight(layerId)
{
	var obj = findLayer(layerId);
	
	
	if (document.all || document.getElementById)
	{
		return obj.offsetHeight;
	}
	else if (document.layers)
	{
		return obj.clip.height;
	}
}

function setLayerHeight(layerId, height)
{
	var obj = findLayer(layerId);
	
	
	if (document.all)
	{
		
		return obj.style.height = height + "px";
	}
	else if (document.getElementById)
	{

		return obj.style.height = height + "px";
	}
	else if (document.layers)
	{
		return obj.clip.height = height;
	}
}

/**
 * Retrieves the width of a layer
 *
 * @param layerId The id of the layer
 * @return The width of the layer in pixel
 */
function getLayerWidth( layerId )
{
	var obj = findLayer(layerId);
	
	
	if (document.all || document.getElementById)
	{
		return obj.offsetWidth;
	}
	else if (document.layers)
	{
		return obj.clip.width;
	}
}	
	
function setLayerWidth(layerId, width)
{
	var obj = findLayer(layerId);
	
	
	if (document.all)
	{
		return obj.style.width = width + "px";
	}
	else if (document.getElementById)
	{
		return obj.style.width = width + "px";
	}
	else if (document.layers)
	{
		return obj.clip.width = width;
	}
}
/**
 * Retrieves a layer object by its id. This method is capable of finding nested layers as well
 * by recursivly looking through the different document levels.
 * If the layer is not found, null is returned. This method will not throw an error message since
 * a catching-mechanism is not available in all browsers.
 * It's up to the calling function to deal with a null value.
 *
 * @param layerId The id of the Layer to look for
 * @param parentObject The object to start from. This parameter is mainly used during recursion
 * 			and can be omitted most of the time. When looking for a layer in a document
 *			this parameter is not applicable
 * @return The layer object for the given id or null if the layer cannot be resolved
 */
function findLayer(layerId, parentObject)
{
	if (parentObject == null)
	{
		parentObject = document;
	}

	if (document.getElementById)
	{
		return (document.getElementById(layerId));
	}
	else if (document.all)
	{
		return (document.all[layerId]);
	}
	else if (document.layers)
	{
		if (parentObject.layers.length > 0)
		{
			for (var i=0; i<parentObject.layers.length; i++)
			{
				if (parentObject.layers[i].id == layerId)
				{
					return parentObject.layers[i];
				}
				
				var tempLayer = findLayer(layerId, parentObject.layers[i].document);
				if (tempLayer != null)
				{
					return tempLayer;
				}
			}
			return null;
		}
		return null;
	}
}

/**
 * Changes a layer's content
 * 
 * @param layerId The id of the layer to change
 * @param content The new content as String.
 */
function setContent(layerId, content)
{
	var obj = findLayer(layerId);
	
	
	if (document.all || document.getElementById)
	{
		obj.innerHTML = content;
	}
	else if (document.layers)
	{
		obj.document.open();
		obj.document.clear();
		obj.document.write(content);
		obj.document.close();
	}
}


/**
 * Close the layer
 * if user clicks beside the layer, the layer shuts down
 * 
 * 
 */

 function Mausklick (Ereignis) {
	
 	if (!Ereignis)
    	Ereignis = window.event;
	if (findLayer('sitemapBlock')!=null) {
   		if(getLayerVisibility('sitemapBlock')){
			// Get the position
			var Popup = document.getElementById('PopupDiv');
			var left = parseInt(Popup.offsetLeft);
			var width = parseInt(Popup.offsetWidth);
	
			// Get right corner
			right = left + width;
			var hoehe = parseInt(Popup.offsetHeight);
			var top = parseInt(Popup.offsetTop);
		
			// Get bottom line
			var bottom = top + hoehe;
			if(!(Ereignis.clientX > left && Ereignis.clientX < right && Ereignis.clientY > top && Ereignis.clientY < bottom)){
  				toggleProductLayer('sitemapBlock');
				toggleLayer('sitemap_btn_inactiv'); 
				toggleLayer('sitemap_btn_activ');
				DivSetVisible('DivShim');
			}
 	 	}
	  }
}