

/*** GLOBAL DEFINITIONS ***/

/** mandatory for JS Device lt IE7 **/
/* this array needs to be filled with the id's of the fixed elements */
/* add values from custom template only using push method */
// array of elements that are fixed in X position
var fixed_elementsX 	= new Array (  );
// array of elements that are fixed in Y position
var fixed_elementsY 	= new Array (  );
// check that fixed is loaded
var fixed_loaded = false;


/*** standard functions ***/

/* like setAttribute but for use on an object array and working in most browsers */
function setAttributeOnArray ( obj, attribut, value )
{
	for ( var i = 0; i < obj.length; i++ )
		eval ( "obj [ i ]." + attribut + " = value;" );
}

/* emulate window.attachEvent */
/* third and all other arguments (string!!!) are arguments for function functionCall */
function WindowAttachEvent ( eventName, functionCall )
{
	eval ( "var formerOnload = window." + eventName );
	var tempFunctionCall = "";
	var tempSeparator = "";
	tempFunctionCall+= "window." + eventName + " = function () { formerOnload ? formerOnload ():''; functionCall (";
	for ( var i = 2; i < arguments.length; i++ )
	{
		tempFunctionCall+= tempSeparator + "'" + arguments[ i ] + "'";
		tempSeparator = ",";
	}
	tempFunctionCall+= "); }";
	eval ( tempFunctionCall );
}

/* patch for IE lt 7 enabling css based DropDown in combination with select html-elements */
// array of selects we don't want to hide on TopNavigation Mouseover
sfHover_NoHide_selects = new Array ( 'SiteLocatorLinks' );

/* hides all tags in array TagList except for array NameExcludeList */
function hideTags ( TagList, NameExcludeList )
{
	for ( var i = 0; i < TagList.length; i++ )
		for ( var j = 0; j < document.getElementsByTagName ( TagList [ i ] ).length; j++ )
			if ( NameExcludeList.length > 0 )
			{	var found = false;
				for ( var k = 0; k < NameExcludeList.length; k++ )
					if ( document.getElementsByTagName ( TagList [ i ] ) [ j ].name == NameExcludeList [ k ] )
						found = true;
						if ( !found )

						document.getElementsByTagName ( TagList [ i ] ) [ j ].style.visibility = 'hidden';
			}
			else
				document.getElementsByTagName ( TagList [ i ] ) [ j ].style.visibility = 'hidden';
}

/* show all tags in array TagList except for array NameExcludeList */
function showTags ( TagList, NameExcludeList )
{
	for ( var i = 0; i < TagList.length; i++ )
		for ( var j = 0; j < document.getElementsByTagName ( TagList [ i ] ).length; j++ )
			if ( NameExcludeList.length > 0 )
						{	var found = false;
				for ( var k = 0; k < NameExcludeList.length; k++ )
					if ( document.getElementsByTagName ( TagList [ i ] ) [ j ].name == NameExcludeList [ k ] )
						found = true;
						if ( !found )

						document.getElementsByTagName ( TagList [ i ] ) [ j ].style.visibility = 'visible';
			}
			else
				document.getElementsByTagName ( TagList [ i ] ) [ j ].style.visibility = 'visible';
}

/* enhance string prototype */
String.prototype.leftTrim = function ()
{
	return ( this.replace ( /^\s+/, "" ) );
};
String.prototype.rightTrim = function ()
{
	return ( this.replace ( /\s+$/, "" ) );
};
// combines "leftTrim" and "rightTrim";
String.prototype.Trim = function ()
{
	return ( this.replace ( /\s+$/, "" ).replace ( /^\s+/, "" ) );
};
// makes space sequences to single spaces
String.prototype.superTrim = function ()
{
	return ( this.replace ( /\s+/g, " " ).replace ( /\s+$/, "" ).replace ( /^\s+/, "" ) );
};
// removes all spaces from a string
String.prototype.removeWhiteSpaces = function ()
{
	return ( this.replace ( /\s+/g, "" ) );
};

/* simulate obj.innerText / obj.textContent */
function getObjInnerText ( obj )
{
	if ( obj.innerText ) // IE;
		return obj.innerText;
	else if (obj.textContent)
		return obj.textContent;
	else
		return false;
}

/* change the opacity to a specific value */
function moveCurrentOpacity ( id, opacEnd, millisec )
{
	if ( document.getElementById ( id ) )
	{
		//speed for each frame
		if ( !millisec )
			var millisec = 250;
		//standard opacity is 100
		var currentOpac = 100;

		//if the element has an opacity set, get it
		if ( document.getElementById ( id ).style.opacity < 100 )
			currentOpac = document.getElementById ( id ).style.opacity * 100;

		//call for the function that changes the opacity
		moveOpacity ( id, currentOpac, opacEnd, millisec );
	}
}

/* change the opacity step by step */
function moveOpacity ( id, opacStart, opacEnd, millisec )
{
	if ( document.getElementById ( id ) )
	{
		//speed for each frame
		if ( !millisec )
			var millisec = 1000;
		var speed = Math.round ( millisec / 100 );
		var timer = 0;

		//determine the direction for the blending, if start and end are the same nothing happens
		if ( opacStart > opacEnd )
		{
			for ( i = opacStart; i >= opacEnd; i-=5 )
			{
				setTimeout ( "changeOpacity ( '" + id + "', " + i + " )", ( timer * speed ) );
				timer++;
			}
		}
		else if ( opacStart < opacEnd )
		{
			for(i = opacStart; i <= opacEnd; i++)
			{
				setTimeout ( "changeOpacity ( '" + id + "', " + i + " )", ( timer * speed ) );
				timer++;
			}
		}
	}
}

/* change the opacity for different browsers */
function changeOpacity ( id, opacity )
{
	if ( document.getElementById ( id ) )
	{
		if ( window.XMLHttpRequest && window.ActiveXObject )
		{
			/* IE7 buggy */
		}
		else
		{
			var object 				= document.getElementById ( id ).style;
			object.opacity 			= ( opacity / 100 );
			object.MozOpacity 		= ( opacity / 100 );
			object.KhtmlOpacity 	= ( opacity / 100 );
			object.filter 			= "alpha(opacity=" + opacity + ")";
			if ( opacity == 100 )
				object.filter 			= "";
		}
	}
}

/* blend one image into an other by using a background layer and the opacity method */
function blendImage ( BackgroundDivId, ImageId, ImageFile, millisec )
{
	// speed for each frame
	if ( !millisec )
		var millisec = 1000;
	// try to get objects
	if ( !document.getElementById ( BackgroundDivId ) || !document.getElementById ( ImageId ) )
		return false;
	//set the current image as background
	document.getElementById ( BackgroundDivId ).style.backgroundImage = "url(" + document.getElementById ( ImageId ).src + ")";
	//make image transparent
	changeOpacity ( ImageId, 0 );
	//make new image
	document.getElementById ( ImageId ).src = ImageFile;
    //fade in image
	moveCurrentOpacity ( ImageId, 100, millisec );
	return true;
}

/* open and style function - for "new popup functionality" */
var openPopupLeft = 0;
var openPopupTop = 0;
var openPopupDefaultClass = '';
var PopupOpened = false;
function openPopup ( nofade )
{
	if ( PopupOpened )
	{
		noFade = true;
		closePopup (noFade);
	}
	PopupOpened = true;
	changeOpacity ( 'Popup', 0 );
	document.getElementById ( 'Popup' ).style.display = 'block';
	openPopupLeft = document.getElementById ( 'Popup' ).offsetLeft;
	openPopupTop = document.getElementById ( 'Popup' ).offsetTop;
	document.getElementById ( 'Popup' ).style.left = openPopupLeft + getScrollX () + "px";
	document.getElementById ( 'Popup' ).style.top = openPopupTop + getScrollY () + "px";
	if ( document.all )
	{
		// hide all input fields on IE
		hideTags ( new Array ( 'select' ), new Array () );
	}
	// gray out main container
	if ( !nofade )
	{
		moveCurrentOpacity ( 'Main', 30 );
		moveCurrentOpacity ( 'Popup', 100 );
	}
	else
		changeOpacity ( 'Popup', 100 );
}

/* close (and clear) function - for "new popup functionality" */
function closePopup ( nofade )
{
	if ( PopupOpened )
 	{
		document.getElementById ( 'Popup' ).innerHTML = '';
		document.getElementById ( 'Popup' ).style.left = openPopupLeft + "px";
		document.getElementById ( 'Popup' ).style.top = openPopupTop + "px";
		document.getElementById ( 'Popup' ).style.display = 'none';
		if ( document.all )
		{
			// undo: hide all input fields on IE
			showTags ( new Array ( 'select' ), new Array () );
		}
		// undo: gray out main container
		if ( !nofade )
		{
			moveCurrentOpacity ( 'Main', 100 );
			moveCurrentOpacity ( 'Popup', 0 );
		}
	}
	PopupOpened = false;
}


/** ERROR HANDLING **/
var GlobalErrors = new Array ();

GlobalErrors [ "DE" ] = new Array ();
GlobalErrors [ "EN" ] = new Array ();
GlobalErrors [ "FR" ] = new Array ();
GlobalErrors [ "ES" ] = new Array ();

GlobalErrors [ "DE" ] [ "addBookmark" ] = "Bookmark setzen nicht möglich!";
GlobalErrors [ "EN" ] [ "addBookmark" ] = "Unable to create Bookmark";
GlobalErrors [ "FR" ] [ "addBookmark" ] = "Bookmark setzen nicht möglich!";
GlobalErrors [ "ES" ] [ "addBookmark" ] = "Bookmark setzen nicht möglich!";

/* return error string depending on browser language */
function getError ( error )
{
	if ( typeof ( navigator.language ) != "undefined" ) // netscape special
		var language = navigator.language.toUpperCase ();
	else if ( typeof ( navigator.browserLanguage ) != "undefined" )
		var language = navigator.browserLanguage.toUpperCase ();
	else
		var language = "EN";
	if ( language = "EN-US" )
		language = "EN";
	if ( GlobalErrors [ language ] )
		if ( GlobalErrors [ language ] [ error ] )
			return GlobalErrors [ language ] [ error ];
	return "Error (" + language + "): " + error;
}

/** LINK FUNCTIONS **/

/* opens a PDF file in a new window, but always the same */
function openPDF ( url, width, height, settings, target )
{
	if ( !settings )
		var settings = "dependent=yes,resizable=yes,status=yes";
	if ( !target )
		var target = "New_PDF_Window";
	openHTML ( url, width, height, settings, target );
}

/* opens a DOC file in a new window, but always the same */
function openDOC ( url, width, height, settings, target )
{
	if ( !settings )
		var settings = "dependent=yes,resizable=yes,status=yes";
	if ( !target )
		var target = "New_DOC_Window";
	openHTML ( url, width, height, settings, target );
}

/* opens a XLS file in a new window, but always the same */
function openXLS ( url, width, height, settings, target )
{
	if ( !settings )
		var settings = "dependent=yes,resizable=yes,status=yes";
	if ( !target )
		var target = "New_XLS_Window";
	openHTML ( url, width, height, settings, target );
}

/* opens an IMG with the new popup functionality (see MMP) */
function openIMG ( url, title )
{
	// Titel überprüfen
	if ( !title ) var title = url;

	document.getElementById ( 'Popup' ).innerHTML
		= '<div class="PopupIMG"><div class="CloseButton" onClick="closePopup()"><div class="PopupTitle">' + title + '</div></div>'
		+ '<div class="Image">'
		+ '  <img src="' + url + '" alt="[' + title + ']" onClick="closePopup()">'
		+ '</div></div>';
	openPopup ();
}

/* opens a HTML page in a separate window, but always the same */
function openHTML ( url, width, height, settings, target )
{
       if ( !settings )
               var settings = "dependent=yes,resizable=yes,status=yes,scrollbars=yes,menubar=yes,location=yes,toolbar=yes";
       if ( width > 0 )
               settings = settings + ",width=" + width;
       if ( height > 0 )
               settings = settings + ",height=" + height;
       if ( !target )
            var target = "New_HTML_Window";
       var New_HTML_Window = window.open ( "/icons/ecblank.gif", target, settings );
       New_HTML_Window.location.href = url;
       New_HTML_Window.focus ();
}

/* create browser bookmark ( FF, IE and Opera ready ) */
function addBookmark ( title )
{
	if ( !title || title == "" )
		var title = window.title;
	var url = location.href;

    if ( window.sidebar ) // Mozilla Firefox Bookmark
		window.sidebar.addPanel ( title, url, "" );
    else if ( window.opera && window.print ) // Opera Hotlist
    {
		var temp = document.createElement ( 'a' );
		temp.setAttribute ( 'rel', 'sidebar' );
		temp.setAttribute ( 'href', url );
		temp.setAttribute ( 'title', title );
		temp.click ();
    }
    else if ( document.all ) // IE Favorite
		window.external.AddFavorite( url, title );
	else
		alert ( getError ( "addBookmark" ) );
}

/* get scrolling postion */
function getScrollX ()
{
	if ( document.all )
	{
		if ( document.documentElement && document.documentElement.scrollTop ) // IE 6 strict
			return document.documentElement.scrollLeft;
		else if ( document.body ) // other IE versions
			return document.body.scrollLeft;
		else
			return false;
	}
	else
		return window.pageXOffset;
}
function getScrollY ()
{
	if ( document.all )
	{
		if ( document.documentElement && document.documentElement.scrollTop ) // IE 6 strict
			return document.documentElement.scrollTop;
		else if ( document.body ) // other IE versions
			return document.body.scrollTop;
		else
			return false;
	}
	else
		return window.pageYOffset;
}

/*** Script for handling cookies ***/
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

/**  Function allowing instant forwarding, e.g. in Items - used in Content Element Direct Forward  **/

function directFWD (url)  
{
    window.location.replace(url);
}



/** URL Function **/

function getUrlParameter( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
		if( results == null )
	return "";
		else
	return results[1];
}



/*** Script for Handling Design Switch ('%' and 'em' based)***/

function switchDesign ( design )
{
	setCookie ( 'currentDesign', design );
	self.location.reload();
}
function flippDesign ()
{
	if ( getCookie ( 'currentDesign' ) != 'em' )
	  setCookie ( 'currentDesign', 'em');
   else
	  setCookie ( 'currentDesign', '');

	self.location.reload();
}



/*** TTA RELICT ***/

/*!!Do not delete this function!!.
You need this function to use the validation of the formulargenerator.*/

function getFieldValue ( theField, vType){
	//this function will return the field value (or value list) based on the element type
	theValue="";
	sep=";";
	hits=0;
	vType=vType.toLowerCase();
	//text is the user-entered value as a string
	if(vType=="text" ) return(theField.value);
	//textarea is the user-entered value as a string array of one element
	if(vType=="textarea" ) return(theField.value);
	//select is an array of selection pointers to an array of strings representing the choices
	if(vType=="select"){
		for ( i=0; i<theField.options.length; i++){
			if(theField.options[i].selected){
				hits++;
				if(theField.options[i].value==""){
					e=theField.options[i].text;
				}else{
					e=theField.options[i].value;
				}
				if(hits==1){
					theValue=e;
				}else{
					theValue+= sep+e;
				}
			}
		}
		return(theValue);
	}
	if(vType=="dropdown"){
		if(theField.options[0].selected){
			return("");
		}
		return("True");
	}
	// check Emailaddress
	if(vType=="mail"){
		var mail=theField.value;
		if(mail==""){
			return ("");
		}else{
			var erg =mail.search(/.+@..+\...+/);
			if(erg==-1){
				return ("");
			}
			var erg=mail.search(/\s/);
			if(erg!=-1){
				return ("");
			}
		}
		return (mail);
	}
	//checkboxes & radio buttons
	if(vType=="checkbox"||vType=="radiobutton"){
		if(theField.value==null){
			//if we're here, we are validating a radio button or a nn multi-element checkbox
			for ( i=0; i<theField.length; i++){
				if(theField[i].checked){
					hits++;
					if(hits==1){
						theValue=theField[i].value;
					}else{
						theValue+= sep+theField[i].value;
					}
				}
			}
		}
                else{
                      if (theField.checked){
                                theValue=theField.value;
                      }
                }
                 return theValue;
	}else{
		return(theField.value);
	}
}


/*** END :: TTA RELICT ***/
