/************
	File:		general_func.js
	Descrip.:	OSRAM JavaScript basic file

	date        who         what
    01.03.07	cwa			windup, clearFlash, getContentHeight, flashClickTrack
	14.03.07    cbrandel    ecat, catalogue, catalogue_hierarchie, fenster, fenster2
	29.03.07    cbrandel    catalogue2
*/

/************
	popup infrastructure
	- adress: url
	- refname: name of the window
	- w: width
	- h: height
	- posLeft: left margin to screen
	- posTop: top margin to screen
*/

function windup (adress, refname, w, h, posLeft, posTop)
{
	if (posLeft == '' && posTop == '')
	{
		var posLeft = (screen.availWidth - w) / 2;
		var posTop = (screen.availHeight - h) / 2;
	}

	win = window.open(adress, refname, "width="+w+",height="+h+",innerWidth="+w+",innerHeight="+h+",left="+posLeft+",top="+posTop+",scrollbars=no,resizable=no");
	win.focus();
}


/************
	remove grey activex border in ie
*/

function clearFlash ()
{
	o = document.getElementsByTagName("object");  
	for(i=0; i<o.length; i++) {  
		o[i].outerHTML = o[i].outerHTML;  
	}
}


/************
	set content height for popups
	- check browser version
	- read inner height / width for popup body
	- calculating new height (-header, -footer, -padding)
	- set new heigth to content div
*/

function getContentHeight ()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
		NewContentHeight = y-122;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
		NewContentHeight = y-122;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
		NewContentHeight = y-90;
	}

	document.getElementById('content').style.height = NewContentHeight+'px';
	document.getElementById('close').style.position = 'absolute';
}


/************
	Wiredmindes flash clicktracking
*/

function flashClickTrack(flashArgs,dLink)
{
	var CT = "http://ctsde15.wiredminds.de/click_track/ctin.php?" + flashArgs;
	var CT_container = new Image();
	CT_container.src=CT;
}

/************
	call the ecatalog
	new function ecat() 
	- ean: the product number(s)
	- country: which country's catalog
	- lang: language for the catalog
	- text: title for the link
	- exiturl: where the catalog should jump back to when the user hits "logout"
*/
function ecat(ean, title, lang, country, exiturl, level)
{
	var url = "http://catalog.myosram.com/";
	var cssclass = "class=\"catalog_link\"";
	var target = "target=\"_blank\"";

	if (lang != "")
	{
		lang = "~language=" + lang;
	}
	else
	{
		lang = "~language=" + "DE";
	}
	if (country != "")
	{
		country = "&~country=" + country;
	}
	else
	{
		country = "&~country=" + "DE";
	}
	if (exiturl != "")
	{
		/* the Escape() is absolutely necessary, because of http: a http%3a generate, only this can be
		handled by a Browser via URL */
		exiturl = "&~exiturl=" + escape(exiturl);
	}
	if (level != "")
	{
		level = "&level=" + level;
		document.write("<a href=\""+url+"?" + lang + country + level + exiturl + ean + "\" "+
			cssclass + " " + target + ">" + title + "</a>");
	}
	else
	{
		document.write("<a href=\""+url+"?" + lang + country + exiturl + ean + "\" "+
			cssclass + " " + target + ">" + title + "</a>");
	}
}


/************************************
    Everything below here are
    function wrappers for backwards compatibility
*************************************/

/************
	open a popup window
*/
function fenster(adress, refname, width, height)
{
    windup(adress, refname, width, height, '', '');
}

/************
	open a popup window
*/
function fenster2(adress, refname, width, height)
{
    windup(adress, refname, width, height, '', '');
}

/************
	call the ecatalog
*/
function catalogue(ean, lang, country, text, exiturl, cssclass)
{
	ecat(ean, text, lang, country, exiturl, "");
}

/************
	call the ecatalog with a default country
*/
function catalogue2(ean, lang, text, exiturl)
{
    country = "DE"
    if (lang == "")
    {
        lang = "EN";
    }
    ecat(ean, text, lang, country, exiturl, "");
}

/************
	call the ecatalog with a hierarchy
*/
function catalogue_hierarchie(ean, level, lang, country, text, exiturl, cssclass)
{
	ecat(ean, text, lang, country, exiturl, level);
}

/************
  close the popup window on some flash poopups
*/
function waittoclose()
{
    setTimeout("window.top.close()",250);
} 
