	var virtualRootNodeId = null;
	var logonWindow = null;
	var logonWindowHandler = null;
	var contentFrameName = null;
	var tStamp = 'TS';
	var treferer = 'REF';
	var protocol_current =  document.location.protocol + '//';
	var protocol_https ='https://';		
	var isPopUpBlockerOn = false;
	var contentItemId = null;
    var modemordsl = null;
	var permanentMSNCookie=null;
	var s_linkType;
	var s_linkName;	
	var logIt = false;	
	
	Today = new Date();
	timeStamp = Today.getTime();
	
	if (typeof(channelUrl)=='undefined') {
		channelUrl='';
	}
	
	if (typeof(isInternet)=='undefined') {
		isInternet=false;
	}
	
	// Wenn Menüpunkt geschützt, dann auf Logon URL des Mandanten umleiten
	userCookie=getCookie( COOKIE_NAME);	
	
	try { // to get MediaSite Permanent Cookie
	permanentMSNCookie=getCookie(MSN_COOKIE_NAME);	
	}
	catch ( Error ) {}
	
	// Nicht angemeldet, aber secure Pfad-> Redirect
	if ((userCookie==null) && (isSecure) && (!hasStartPage) && ( !isStaging ) ) {
			self.location.href=getLoginURL();
	}
	
	function log(logText) {
		if (logIt) {
			if (!window.console) {
				alert(logText);
			} else {
				console.log(logText);
			}
		}
	} 	

	// Angemeldet, aber nicht secure Pfad -> Cookie Löschen 
	// if ( userCookie!=null && window.location.href.indexOf(NOCACHE_TOKEN)<0 ) {
	//  deleteCookie(COOKIE_NAME);
	// }
			
    // for all JS-Links in C2C
	function openLink(oid,openType,linkType,windowOpenProps,statisticTag,anchorObject) {
		sendStatisticLink(oid,linkType,statisticTag,anchorObject);
		
		url = location.pathname;		

		first4=url.substr(0,4);
		posLastSlash = url.lastIndexOf('/');
		
  	    if (virtualRootNodeId != null && linkType!='fi' && linkType!='ex'  ) {
  	    	// set virtual root for ExpandedMenuNav to TABVIEW_ID
	  	    oid = setOid(oid, 6, virtualRootNodeId)
		}
		
		//alert('contentItemId: ' + contentItemId + ' linkType: ' + linkType + ' virtualRootNodeId: ' + virtualRootNodeId);
		if (contentItemId != null && linkType!='fi' && linkType!='ex'  ) {
	  	    oid = setOid(oid, 8, contentItemId)
		}
		
		var openLinkChannelUrl = channelUrl;
		// check anchorObject for attrib attribLinkUrl (available if link to other channel)
		try {		
			if (typeof(anchorObject)!= 'undefined' ) {
				var attribLinkUrl = anchorObject.getAttribute("LINKURL");
		 	   if ( typeof(attribLinkUrl)!='undefined' && attribLinkUrl!=null && attribLinkUrl!= "" && attribLinkUrl!='null') {
					openLinkChannelUrl = attribLinkUrl;
				}
			}
		} catch (error) {}

		if (posLastSlash>1) {
			if (first4==NOCACHE_TOKEN && posLastSlash>3 ) {						 
				url = openLinkChannelUrl!=''?NOCACHE_PATH+openLinkChannelUrl:url.substr(0,posLastSlash);
			} else if (first4!=NOCACHE_TOKEN) {
				url = openLinkChannelUrl!=''?openLinkChannelUrl:url.substr(0,posLastSlash); 
			}		
		} else {
			url = openLinkChannelUrl; // location.pathname => "/", Aufruf von HostnamechannelUrl
		}
		var noCache = 0;

		// Zusammenspiel /nc/ und CDA Cookie; URL entsprechend ändern ...
//		alert('urlvor: '+userCookie);
		if ( userCookie==null && noCache==0 && url.substr(0,4)==NOCACHE_TOKEN && permanentMSNCookie==null ) 	{
			url = url.substr(3,url.length);
		} else if (url.substr(0,4)!=NOCACHE_TOKEN && noCache!=0) {
			url =NOCACHE_PATH + url;
		} else if (url.substr(0,4)!=NOCACHE_TOKEN && userCookie!=null) {
			url =NOCACHE_PATH + url;
		}
//		alert('url: '+url);
		
		if (typeof(linkType)=='undefined' || linkType=='co' || linkType=='me' ) {
			oid=replaceMODEInOID(oid, isPortalChannel);
			oid=replaceChannelInOID(oid);
			oid=replaceNOCACHEInOID(oid);
			//kein hinzufuegen von location.search fuer MediaSite (Handling mit ServletHandler)
			//moegliche Alternative...  loeschen des parameter 	SERLVETID
			//url = url +   "/" + oid + ".html" + location.search;
			url = url +   "/" + oid + ".html";
		} else if (linkType=='ex') {
				
			url = getURLbyContChannelId(oid);
			// Bei externen Links, die aus Komponente createHeadLine4Menu ( MediaSite ) kommen
			// wird externer Link in angemeldetem Zustand dann auf /nc/... umgeschrieben
			// Nur für Urls die mit / beginnen
			 if (url.substr(0,4)!=NOCACHE_TOKEN && userCookie!=null && url.indexOf('/')==0 ) {
				url =NOCACHE_PATH + url;
			  }
				
			if ( url!=oid ) {
				if (openType=="2") {
					openType = "3";
				}
				windowOpenProps = getPropsbyContChannelId(oid);				
			}
		} else {
			url = oid;
		}

        // Wenn angemeldet , und NoCache Seite wird aufgerufen,  dann timestamp an URL hängen , wegen Proxy-Cache
	    url=addTimeStamp(url);
	    //url=addReferer( url );
		//openType==5 wird fuer MediaSite::VideoOrder verwendet - Link auf /nc/
	    if (openType=="5" && url.substr(0,4)!=NOCACHE_TOKEN) {
			url =NOCACHE_PATH + url;
	    }

		if (isC2Clogon()&&(!isStaging)) { // Mediasite Livesystem
			if (document.location.protocol=='https:')
			url = 'http://'+document.location.hostname+url;
		}
		
		// check anchorObject for attrib linkhost
		try {		
			if (typeof(anchorObject)!= 'undefined' ) {
				var attribHostname = anchorObject.getAttribute("LINKHOST");
			     if (typeof(attribHostname )!='undefined' && attribHostname !=null && attribHostname != "" && attribHostname !='null') {
					if (url.indexOf("/") == 0) {
						url = attribHostname + url;
					}
				}
			}
		} catch (error) {}

		switch (openType) {
			case "1": {
				location.href = url;
				break;
				}
			case "2": {
				newWindow = window.open(url);
                if (!newWindow.opener) {
                  newWindow.opener = window;
                }				
				try {
					newWindow.focus();
				} catch (error) {}
				break;
				}
			case "3": {
				title = getTitle(oid);
				newWindow = window.open(url,title,windowOpenProps);
				if (newWindow && !newWindow.opener) { 
				  // Bug.21314 - JS Fehler bei mailto (newWindow == null)
                  newWindow.opener = window;
                }
				if (!newWindow && url.indexOf('@')<0) isPopUpBlockerOn=true;
				try {
					newWindow.focus();
				} catch (error) {}
				break;
				}
			case "4": {
				frmContent = window.frames[contentFrameName];
				if (typeof(frmContent)=='undefined') {
					window.location.href = url;				
				} else {
					frmContent.location.href = url;
				}
				break;
				}
			case "5": { //Mediasite - VideoOrder 
				previewWindowName = 'newWindow' + contentItemId;
				  //wurde link in einem video bestellung in einm popup angeklickt, wird 
				  //das popup geschlossen (ausser preview vom video)
				if ((window.name.indexOf('previewWindow')==-1) && (window.name.indexOf('newWindow')!=-1)) {
			      window.opener.location.href= url;
			      window.close();
			    } else {
			      //link in keinem popup (oder in preview), wird er im aktuellen 
			      //fenster geoeffnet
			      location.href = url;
			    }
			}
			default : {
				location.href = url;
			}
		}
	}
	
// for new window
	function getTitle(oid) {
		try {
			arrOid = oid.split('-');
			// oid can also be one single id (contChannelId)
			var uniqueIdPos = arrOid.length>4 ? 4 : arrOid.length-1;
			var uniqueId = arrOid[uniqueIdPos];
			if (isNaN(uniqueId)) { // oid can also be a file-path
				return 'newWindow' + Number(new Date());
			} else {
				return 'newWindow' + uniqueId;
			}
		} catch ( error ) {
			return 'newWindow' + Number(new Date());
		}
	}

// for Conttype PopUp
	function openPopUp(contChannelId,callType) {
		try {
			//for Menu and ContenItem PopUps
			if (callType=='puOpen') {
				popUpArray = POPUPIDS.split(',');
				for (i=0;i<popUpArray.length;i++) {
					singlePopUp="POPUP" + popUpArray[i];
					singlePopUpValue=eval(singlePopUp);
					popUpProps = singlePopUpValue.split('|');
					
					openLink(popUpProps[0],"3",'co',popUpProps[1]);
					if (isPopUpBlockerOn && isRedirectPUBlockerOn) {
						openLink(channelUrl + '/popup?o=' + getOidFromUrl(location.pathname) + '&p=' + singlePopUpValue,'1','ex');
					}
				}
			} else if (callType=='puClose') {
				//only open popup if no opener exists
				if (!window.opener && (event.clientY < 0)) {
					singlePopUp="CLOSE_POPUP_PROPS" + CLOSE_POPUP_ID;
					singlePopUpValue=eval(singlePopUp);
					popUpProps = singlePopUpValue.split('|');
					
					openLink(popUpProps[0],"3",'co',popUpProps[1]);
				}
			} else if (callType=='pu') {
				popUpArray = DE_POPUP_IDS.split(',');
				for (i=0;i<popUpArray.length;i++) {
					if (popUpArray[i]==contChannelId) {
						singlePopUp="DE_POPUP_PROPS" + popUpArray[i];
						singlePopUpValue=eval(singlePopUp);
						popUpProps = singlePopUpValue.split('|');
						
						openLink(popUpProps[0],"3",'co',popUpProps[1]);
					}
				}
			}
		} catch ( error ) {  }
	}
	
	function openPopAndBack() {
		htmlString = location.search;
		oriIdEnd=htmlString.indexOf('&')-1;
		if (oriIdEnd < 0)
			oriIdEnd = htmlString.length;
		oriId = setOid(htmlString.substr(3,oriIdEnd-2),18,1);
		
		singlePopUpValue = htmlString.substr(oriIdEnd+4);
		popUpProps = singlePopUpValue.split('|');
		var neww = openLink(popUpProps[0],"3",'co',popUpProps[1]);
		backNoPop();
		if (window.focus ) { 
			neww.focus();
		}
		openLink(oriId,1,'co');
	}
	
	function backNoPop() {
		pIdEnd=location.search.indexOf('&')-1;
		if (pIdEnd < 0) 
			pIdEnd = location.search.length;
		if (location.search.substr(3,pIdEnd-2).length > 0) {
			pId = setOid(location.search.substr(3,pIdEnd-2),18,1);
			linktype = 'co';
		} else {
			pId = channelUrl + '?sp=off';
			linktype = 'ex';
		}
		openLink(pId,1,linktype);
	}
	
	
// for openLink used by external links	
	function getURLbyContChannelId(oid) {
		try {
			props = "DE_EX_PROPS" + oid;
			propvalues = eval(props);			
			if ( typeof(propvalues)=='undefined' ) {
			 return oid;
			} else {
			 propArray = propvalues.split('|');
			 return propArray[0];
			}
		} catch ( error ) { return oid; }
	}
	
	function getPropsbyContChannelId(oid) {
		try {
			props = "DE_EX_PROPS" + oid;
			propvalues = eval(props);
			propArray = propvalues.split('|');
			return propArray[2];
		} catch ( error ) {  }
	}
	
// for Instadia and Omniture Statistics
	function sendStatisticLink(oid,linkType,statisticTag,anchorObject) {
		try {
			if (typeof(s_account)!='undefined' && typeof(s_co)!='undefined'  && ( linkType=='fi' )) {
				s_linkType="d";
				s_linkName=oid;
				s_lnk=s_co(anchorObject);
				s_gs(s_account);		
			}
		}
		catch ( Error ) {	}
		
		if (typeof(instadiaId)!='undefined') {
			if (typeof(statisticTag)=='undefined') { statisticTag=''; }
			if (isC2Clogon()) {
				try {
					sendMSStatisticLink(oid,linkType,statisticTag,anchorObject);
				} catch ( instadiaError ) {}
			} else
			if (linkType=='ex' || linkType=='fi' || (linkType=='co' && statisticTag!='')) {
				filename='';
				instadiaLinkDesc=instadiaDesc;
				if (linkType=='ex') {
					instadiaLinkDesc += 'user_linked_to_';
					filename = getFilenameForInstadia(oid, anchorObject);
				} else if (linkType=='fi') {
					instadiaLinkDesc += 'user_download_';
					startpos = oid.indexOf('/Projects/c2c/channel/');
					if (startpos!=-1) {
						filename = oid.substr(oid.lastIndexOf('/')+1,oid.length) + "/";
					}
				} else {
					instadiaLinkDesc += 'user_linked_to_';
					filename = getFilenameForInstadia(oid, anchorObject);
				}

				// call the Instadia JavaScript in c2c_start , is the parent c2c_start or is no parent ?				
				instadiaLinkDesc += filename + statisticTag;				
				if (instadiaId=='test') {
					alert('Linkdescription: ' + getCorrectInstadiaDesc(instadiaLinkDesc,200));
					return;
				}
				try {
					Instadia_sendInfo(instadiaId,getCorrectInstadiaDesc(instadiaLinkDesc,200),getCorrectInstadiaDesc(instadiaLinkDesc,250));
				} catch ( instadiaError ) {}		
			}
		}		
	}
	
	function getFilenameForInstadia(oid, anchorObject) {
		if (typeof(anchorObject) == 'undefined') {
			try {
				props = "DE_EX_PROPS" + oid;
				propvalues = eval(props);			
				if ( typeof(propvalues) == 'undefined' ) {
					return oid;
				} else {
					propArray = propvalues.split('|');
					return propArray[3] + "/";
				}
			} catch ( error ) { return oid; }
		} else {
			try {
				return anchorObject.innerText + "/";
			} catch ( error ) { return ""; }
		}
	}

	function getCorrectInstadiaDesc(descr, descMaxLength) {
		if (descr.length>descMaxLength) {
			additional = descr.substring(descr.lastIndexOf('/#'));
			pathinfo = descr.substring(0,descMaxLength-additional.length);
			descr=pathinfo+additional;
		}
		return descr;
	}
	
// returns Oid from url
	function getOidFromUrl( url ) {
		posBeginHtml= url.lastIndexOf('.html');
		posBeginOid = url.lastIndexOf('/') + 1;
		
		if (posBeginHtml>1) {
			url = url.substr(0,posBeginHtml);
			url = url.substr(posBeginOid);
		} else {
			url = '';
		}
		return url;
	}

// for search	
	function isValidDate(datestring) {
		var day;
		var month;
		var year;
		var hour;
		var minute;
		var fieldOk = true;
		cal = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
		if (datestring != "") {
			day = datestring.substring(0,2);
			month = datestring.substring(3,5);
			year = datestring.substring(6,datestring.length);
			point1 = datestring.substring(2,3);
			point2 = datestring.substring(5,6);
			if (point1 != '.' || point2 != '.') {
				fieldOk=false;
			}
			if (datestring.length != 10) {
				fieldOk=false;
			} else {
				if (year > 1899 && year < 2101 && month < 13 && month > 0 && day < 32 && day > 0) {
					if (cal[eval(month)-1] < day && eval(month)!=2) {
						fieldOk=false;
					} else {
						if (year%4 && day > 28 && eval(month)==2) {
							fieldOk=false;
						} else {
							if (day > 29 && eval(month)==2) {
								fieldOk=false;
							}
						}
					}
				} else {
					fieldOk=false;
				}
			}
		} else {
			fieldOk=true;
		}
		return fieldOk;
	}

	// for replacing values in OID	
	function setOid(OID, location, newValue) {
		//alert('OID=' + OID + ', location=' + location + ', newValue=' + newValue);
		arrayOID = OID.split('/');
		if (arrayOID.length < 2) {
		    // keine GO-URL vor der OID
			arrayOID = OID.split('-');
			if (arrayOID.length >= location) {
				arrayOID[location] = newValue;
			}
			OID = arrayOID.join('-');
		} else {
		    // GO-URL vor der OID wird weggefiltert
			arrayOIDwithoutGoUrl = arrayOID[2].split('-');
			if (arrayOIDwithoutGoUrl.length > location) {
				arrayOIDwithoutGoUrl[location] = newValue;
			}
			arrayOID[2] = arrayOIDwithoutGoUrl.join("-"); 
			OID = arrayOID.join('/');
		}
		return OID;
	}

// for replacing values in OID	
	function getOid(OID, location) {
		value = -1;
		arrayOID = OID.split('/');
		if (arrayOID.length < 2) {
		    // keine GO-URL vor der OID
			arrayOID = OID.split('-');
			if (arrayOID.length >= location) {
				value = arrayOID[location];
			}
		} else {
		    // GO-URL vor der OID wird weggefiltert
			arrayOIDwithoutGoUrl = arrayOID[2].split('-');
			if (arrayOIDwithoutGoUrl.length > location) {
				value = arrayOIDwithoutGoUrl[location];
			}
		}
		return value;
	}

// for header
	function replaceMODEInOID(OID, isPortalChannel) {																		
		if( isPortalChannel ) {
			strOID=setOid(OID, 10, 1);
		} else {
			strOID=setOid(OID, 10, 1);
		}
		return strOID;
	}
	
// for contentreference to mainchannel
	function replaceChannelInOID(OID) {
		if (parentChannelId > 0 && parentChannelId!=channelId) {
			return (setOid(OID, 1, channelId));
		}
		return OID;
	}
	
// for secure sites
	function replaceNOCACHEInOID(OID) {																		
		userCookie=getCookie(COOKIE_NAME);
		if ( userCookie!= null  ) {
			strOID=setOid(OID, 16, 31);
		} else {
			strOID=OID;
		}
		return strOID;
	}

	function replaceNoCacheInTemplateAndOid(source) {
		 userCookie=getCookie( COOKIE_NAME);
		 if (( userCookie!= null ) && (source.indexOf('/nc')==-1) && (source.indexOf(channelUrl)>=0)) {
			source =NOCACHE_PATH + source;
		}
		return source;
	}
	
	function getNoCacheFlagOfOid(pOid) {
		arrayOID=pOid.split('-');
		if (arrayOID.length>5) {
			return getOid(pOid, 16);
		} else {
			return -1;
		}
	}
	
	// deprecated use "getOid(OID, location)"
	function getValueFromOid(pOid,pos) {
		arrayOID=pOid.split('-');
		if (arrayOID.length>5) {
			return arrayOID[pos];
		} else {
			return -1;
		}
	}
	
	function addTimeStamp( aURL ) {		
		try {	
			hasTimeStamp = (aURL.indexOf(tStamp+'=')>-1);	 
			if ( hasTimeStamp ) {
				return aURL;
			}	  
			bNocacheUrl = (aURL.indexOf(NOCACHE_TOKEN)>-1);	 
			if ( (userCookie!=null && bNocacheUrl) || isC2Clogon() ) {	 
				qmInUrl = (aURL.indexOf('?')>-1);
				if ( qmInUrl  ) { 
					url=aURL+'&' + tStamp + '='+timeStamp;
				} else {
					url=aURL+'?' + tStamp + '='+timeStamp;
				}	  
			} else {
				url=aURL;
			}
		} catch ( error ) { url=aURL; }
		return url;
	}

/* not used anymore	
	function addReferer( aURL ) {
		if (typeof(instadiaId)!='undefined' && isC2Clogon()) {
			statRefDesc = escape(instadiaDesc);
			statRefDesc = statRefDesc.replace(/\//g, "%2F");
			statRefDesc = statRefDesc.replace(/\+/g, "%2B");
			statRefDesc = statRefDesc.replace(/%u((\d|[a-f]){4})/ig, "%$1%7c");
			try {	
				hasReferer = (aURL.indexOf(treferer+'=')>-1);
				if ( hasReferer ) {
					qmInUrl = (aURL.indexOf('&')>-1);
					if ( qmInUrl  ) {
						url=aURL+'&' + treferer + '='+statRefDesc;
					} else {
						aURL=aURL.substring(0,aURL.indexOf('?'));
						url=aURL+'?' + treferer + '='+statRefDesc;
					}	  
					return url;
				}	  
				qmInUrl = (aURL.indexOf('?')>-1);
				if ( qmInUrl  ) { 
					url=aURL+'&' + treferer + '='+statRefDesc;
				} else {
					url=aURL+'?' + treferer + '='+statRefDesc;
				}	  
			} catch ( error ) { url=aURL; }
		}
		return url;
	}
*/	
	function getCookie(sName) {
	  // cookies are separated by semicolons
	  var aCookie = document.cookie.split("; ");
	  for (var i=0; i < aCookie.length; i++) {
	    // a name/value pair (a crumb) is separated by an equal sign
	    var aCrumb = aCookie[i].split("=");
	    if (sName == aCrumb[0])	    
	      return unescape(aCrumb[1]);
	  }
	
	  // a cookie with the requested name does not exist
	  return null;
	}

	function showLogon(objLogonPanel, strLogonText, strLogoffText) {				
		
		if ( objLogonPanel!=null ) {
			var strUser =  getCookie(COOKIE_NAME);
			if ( strUser!=null ) {				
				objLogonPanel.innerText=strLogoffText;
				objLogonPanel.title=strLogoffText;
			} else  {				
				objLogonPanel.innerText=strLogonText;
				objLogonPanel.title=strLogonText;
			}		
		}
	}
	
	
	/** Benutzer An/Abmeldung 
	*	Wenn  Benutzer angemeldet, erfolgt Abmeldung und vice versa.
	* Bei Anmeldung wird geprüft, ob internal/confidential
	* und daraufhin auf die richtigen URLS umgeleitet
	**/
	function logOnOff() { 		
		// get needed info first
		var redirectURL = "";
		if ( userCookie == null  && permanentMSNCookie==null ) {
		 // Not logged on yet, so do a logon by reloading the page with /nc/ and the according Security token in host.				
		 redirectURL =getLoginURL();
		} else {
		  // User is Logged On; So Logoff: Delete the cookie by setting its expiry date to be sometime in the past
		  // and call the appropriate Siteminder Logoff URI
		  deleteCookie(COOKIE_NAME);		 
		 // delete MediaSite Permanent Cookie if there
		  deleteCookie(MSN_COOKIE_NAME);		  
		  redirectURL =getLogoutURL();	  		  
		}
		
	window.location.href=redirectURL;	
  }

	function isC2Clogon() {
		try { 
			return c2cLogin;
		} catch ( error ) {
			return false;
		}
	}

	function getLoginURL() {
		CDA_LOGON_URL='';
		currentPath=  window.location.pathname;		// Channel path
		if (currentPath=='' || currentPath=='/'  || currentPath.length <2 ) { // Call via Hostname of Channel or invalid Pathname
			currentPath=destJsp; // then set to destJsp
		}
		isNoCache  = (currentPath.indexOf(NOCACHE_TOKEN)>-1);  // nocache Token in Path ?
		if (!isNoCache) {
			// Add /nc/ to the path
			currentPath=NOCACHE_PATH + currentPath;
		}
		if (isConfidential) {
			// Confidential Security, always https
			CDA_LOGON_URL = protocol_https + CDA_LOGON_URL_CONFIDENTIAL;
		} else if (!isC2Clogon()) {
			// Internal Security  
			// if Internet -> https
			// if Intranet -> http
			if (isInternet==true) {
			CDA_LOGON_URL = protocol_https + CDA_LOGON_URL_INTERNAL;	
			} else {
			CDA_LOGON_URL = protocol_current + CDA_LOGON_URL_INTERNAL;							
			}
		}
		
		//set MODE to 0
		try {
			var orig_oid = getOidFromUrl(currentPath)
			var new_oid  = setOid(orig_oid, 10, 0);
			currentPath = ReplaceAll(currentPath, orig_oid, new_oid);
		} catch (error) {alert(error);}

		return CDA_LOGON_URL + currentPath;				
	}
 
	function getLogoutURL() {
		LOGOFF_URL = '';
		if (isConfidential) {
			LOGOFF_URL = SM_LOGOUT_LINK_CONFIDENTIAL;
		} else if (isC2Clogon()) {
			LOGOFF_URL = channelUrl;
		} else {
			LOGOFF_URL = SM_LOGOUT_LINK_INTERNAL;
		}
		return LOGOFF_URL;
	}

 function deleteCookie(cookie_name) {
   var now = new Date();
   var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
   document.cookie = escape(cookie_name) + '=' + '; EXPIRES=' + yesterday.toGMTString() + '; PATH=/;';
   document.cookie = escape(cookie_name) + '=' + '; EXPIRES=' + yesterday.toGMTString() + '; PATH=/; domain=' + getLevel1Domain() + ';';
    try { 
    // try to toggle Logon / Off Text if Logon Component present
    toggleLogonText();
    }
    catch ( Error ) {}    	
 }	

// get the 1st level domain out of the full hostname
function getLevel1Domain() {
 currentDomain = ".daimler.com"; // default domain;
 
 try {
 currentDomain=window.location.hostname;
 var domain_parts = currentDomain.split(".");
 numParts= domain_parts.length;
 currentDomain = "." + domain_parts[numParts-2] + "." + domain_parts[numParts-1];
 } catch ( Error ) {}
  return currentDomain;
}
	
// image swapping
	function swapImgRestore() { //v3.0
		var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.p) d.p=new Array();
		var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
	}
	
	function findObj(n, d) { //v4.0
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
		if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
	
	function swapImage() { //v3.0
		var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
// for magnifiying glass
	function imgPreview(DUMMY_DEPRECATED,id) {	
		if ( id==null || id=='undefined' ) { id=DUMMY_DEPRECATED; }
		var prevURL =window.location.protocol+"//"+window.location.host + PREVIEW_FILE_JSP + '?FILETYPE=IMAGE&FILE_ID=' + id + '&LANG=' + langId + '&CHANNEL='+ channelId;
	 	pv=0;	 	
	 	window.open (prevURL,'prev',"width=450,height=380,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
		return false;
	}
	
// check if Flash is Available
	b = navigator.userAgent.toLowerCase();
	if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
		document.writeln('<script language="VBscript">');
		document.writeln('Function detectActiveXControl(activeXControlName)');
		document.writeln('  on error resume next');
		document.writeln('  detectActiveXControl = False');
		document.writeln('  detectActiveXControl = IsObject(CreateObject(activeXControlName))');
		document.writeln('End Function');
		document.writeln('</scr' + 'ipt>');
	}
	function getFlashVersion(){
		var installedVersion = 0;
		if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
			for (var i=3; i<10; i++){
				if(detectActiveXControl("ShockwaveFlash.ShockwaveFlash."+i) == true) installedVersion = i;
			}
		} else {
			if (navigator.plugins["Shockwave Flash"]) {
				var pluginDesc = navigator.plugins["Shockwave Flash"].description;
				installedVersion = parseInt( pluginDesc.charAt( pluginDesc.indexOf(".")-1 ) );
			}
			if(b.indexOf("webtv") != -1) installedVersion = 3;  
		}
		return installedVersion;
	}

	function checkFlashPlayer() {
	
		 flashInst = getFlashVersion();
		 if(!flashInst){

			var elemEmbed;
			var altImg;
			coll = document.getElementsByTagName("EMBED");
			for (i=0;i<coll.length;i++) {
				elemEmbed = coll[i];
				altImg = elemEmbed.getAttribute("altImage");
				if(altImg!=null && altImg.length>0) {
					elemEmbed.parentNode.innerHTML="<img src='"+altImg+"'>";
				}
			}
		} 
	}
	
// DivSwap IndexLists
	function popUpSwapDivTagByCaller(strShow,strHide) {
	
		var objShow = document.getElementById(strShow);
		var objHide = document.getElementById(strHide);
		
	    if (objShow!=null) {
		    if (objShow.style.display == "none" || objShow.style.display=="") {
		        objShow.style.display = "block" ;
		    } else {
		        objShow.style.display = "none" ;
		    }
	    }
	    if (objHide != null) {
	       objHide.style.display = "none" ;
	    }
	}

// Overview Steps
	function showMore(obj, divId) {
	   var divObj = document.getElementById(divId);
	   var divElements = divObj.getElementsByTagName('DIV');
	   for (i=0;i < divElements.length;i++) {
	       divElements(i).style.display = 'block';
	   }
	   obj.style.display = "none" ;
	}
	
// for Selector
	function verifyDayOptions(obj) {
		var prefix = obj.name.substring(0, 3);
		
		var diff = 0;
		var anzTage = 0;
	
		eval("var dayBox ="+ obj.form.name+"."+prefix+"day");
		eval("var monthBox ="+ obj.form.name+"."+prefix+"month");
		eval("var yearValue ="+ obj.form.name+"."+prefix+"year.value;");
		
		var monat = monthBox.value;
		var boxLength = dayBox.length;
		
		switch(monat) {
			case "02":
				anzTage = 28;
				var leapYear = (yearValue - 2000);
				if (leapYear>0 && (leapYear%4)==0) {
					anzTage = 29;
				}		
				break;
	
			case "01":
			case "03":
			case "05":
			case "07":
			case "08":	
			case "10":
			case "12":
					anzTage = 31;
				break;
			default:
				anzTage = 30;
				break;
		}
		diff = anzTage - boxLength;	
		if (diff > 0) {
			for (i = 1; i <= diff; i++) {
				var val = boxLength + i; 
				var oOption = document.createElement("OPTION");
				dayBox.options.add(oOption);
				oOption.innerText = ""+val;
				oOption.value = ""+val;
			}	
		} else {
			diff *= -1;
			for (i = 0; i < diff; i++) { 
				dayBox.options.remove(dayBox.length-1);
			}
		}		
	}
	
// body default jscalls
	function doOnUnLoadDefault() {
		try {	
			openPopUp(0,'puClose');
			doBeforeUnLoad();
		} catch ( error ) {  }
	}
	
	function doOnLoadDefault() {
		try {
			if (location.search.indexOf('sp=off') < 1)
			openPopUp(0,'puOpen');
			checkFlashPlayer();
			doBeforeLoad();
			if (modemordsl != null) {
			    setAvailablePlayer(modemordsl);
			}
		} catch ( error ) {  }
	}
	function doOnUnLoadSplashDefault() {
		try {
			doBeforeUnLoadSplash();
		} catch ( error ) {  }
	}
	function doOnLoadSplashDefault() {
		try {
			checkFlashPlayer();
			doBeforeLoadSplash();
		} catch ( error ) {  }
	}

	function setLanguage (aURL) {
	// default Language Switch for intra.com
	if ( aURL==null || aURL == '' ) return aURL;
	 var clientLang = "";
	 var isPortalURL = aURL.toLowerCase().indexOf('header_portal')>-1; 
		if (document.all) {
			clientLang = navigator.userLanguage;
		} else {
			clientLang = navigator.language;
		}
		if (clientLang.toLowerCase().indexOf("en")>-1) {
			// English Browser Language
			if ( isPortalURL) {
			 aURL = aURL.replace('_49','_1');  
			} else {
			 if (location.pathname == '/intra') {
			 	aURL = "/intra/0-8-57268-1-0-0-0-0-0-0-1-0-57213-0-0-0-0-0-0-0.html";
			 } else {
			 	aURL = aURL;
			 }
			}
 			document.title = "Daimler Employee Portal";
		}		
	 return aURL;
	}

// returns Value from given parameter in htmlQueryString	
	function getParamFromQueryString(paramName) {
		htmlString = location.search;
		if (htmlString.indexOf(paramName)<0)
			return null;
		paramValue=(htmlString.substr(htmlString.indexOf(paramName)+paramName.length+1));
		valueLength = paramValue.indexOf('&');
		if (valueLength<0)
			valueLength=paramValue.length;
		return (paramValue.substr(0,valueLength));
	}
	
	// returns true is pressed key is enterkey
	function isEnter(e) {
		var keycode;
		if (window.event) {
			keycode = window.event.keyCode;
		} else if (e) {
			keycode = e.which;
		} else {
		return false;
		}
	
		if (keycode == 13)
		   return true;
		else
		   return false;
	}
	
//Cookie-Handling
//
    function readCookie(name) {
    	var result = ""; 
    	var myCookie = " " + document.cookie + ";";
    	var searchName = " " + name + "=";
    	var startOfCookie = myCookie.indexOf(searchName); 
    	var endOfCookie; 

        if (startOfCookie != -1) {
            startOfCookie += searchName.length; 
            endOfCookie = myCookie.indexOf(";", startOfCookie); 
            result = unescape(myCookie.substring(startOfCookie, endOfCookie)); 
        }
        return result; 
    }

    function setCookie(cname, value) {
        document.cookie = cname +"="+ value + "; path=/";
    }

    function existsCookie(cname) {
	  var aCookie = document.cookie.split("; ");
	  for (var i=0; i < aCookie.length; i++) {
	    // a name/value pair (a crumb) is separated by an equal sign
	    var aCrumb = aCookie[i].split("=");
	    if (cname == aCrumb[0])	    
	      return true;
	  }
	  // a cookie with the requested name does not exist
	  return false;
    }
    
    //get multi value cookie value e.g. Pers
    //     on=name=amit&age=25;School=10th
    function getCookieMultiValue(cookiename,cookiekey) {
        var cookievalue=readCookie(cookiename);
        if ( cookievalue == "") {
            return "";
        }
        cookievaluesep=cookievalue.split("&");
	
        for (c=0;c<cookievaluesep.length;c++) {
            cookienamevalue=cookievaluesep[c].split("=");
            if (cookienamevalue.length > 1) { //it has multi valued cookie
                if ( cookienamevalue[0] == cookiekey )			
                    return cookienamevalue[1].toString();			
            } else {	
                return null;
            }
        }
        return null;
    }


    //set multi value cookie value e.g. Pers
    //     on=name=amit&age=25;Age=35
    function setCookieMultiValue(cookiename,cookiekey,cookiekeyvalue) {
        //cookiekeyvalue darf nicht '' sein, sonst wird cookiekey gesetzt
        //obwohl er vielleicht schonv orhanden ist.

        var cookievalue=readCookie(cookiename);
        if ( (cookievalue==null) || (cookievalue.trim() == "") )	{
            setCookie(cookiename,cookiekey+"="+cookiekeyvalue);
            return;
        }		
                    	
        //check if cookie already exist
        getcookiekeyvalue=getCookieMultiValue(cookiename,cookiekey);
        newCookieValue=cookievalue.trim();
        if ( getcookiekeyvalue == "") {	//key cookie never exist		
            newCookieValue += "&" + cookiekey + "=" + cookiekeyvalue;
        } else {
            if ( newCookieValue.substr(0,cookiekey.length+1) == (cookiekey + "=") ) //Check if at first location . no beginning with &
            {
                //pick rest keys = keylength+equalsign+cookiekeyvalue+nextampesand
                tmpCookieVal = getCookieMultiValue(cookiename,cookiekey);
                if (tmpCookieVal==null) tmpCookieVal = "";
                totalcookiekeylength=cookiekey.length+1+tmpCookieVal.length+1;
                newCookieValue = newCookieValue.substr(totalcookiekeylength);
                if (newCookieValue.trim() == "")			
                    newCookieValue = cookiekey + "=" + cookiekeyvalue;
                else
                    newCookieValue += "&" + cookiekey + "=" + cookiekeyvalue;
            } else {
                fullcookiekey="&"+cookiekey+"="+getcookiekeyvalue;
                if ( newCookieValue.indexOf(fullcookiekey) != -1 ) //cookie key inside the cookie value
                {
                    newCookieValue = ReplaceAll(newCookieValue, fullcookiekey, "");
                    if (newCookieValue.trim() == "")			
                        newCookieValue = cookiekey + "=" + cookiekeyvalue;
                    else
                        newCookieValue += "&" + cookiekey + "=" + cookiekeyvalue;
                }
            }
        }
        setCookie(cookiename,newCookieValue);
    }

    //Replace all given string from a string
    //     
    function ReplaceAll(varb, replaceThis, replaceBy) {	
        newvarbarray=varb.split(replaceThis);
        newvarb=newvarbarray.join(replaceBy);	
        return newvarb;
    }

    // function called trim as a method of t
    //     he prototype 
    // object of the String constructor.
    String.prototype.trim = function() {
        // Use a regular expression to replace l
        // eading and trailing spaces with the empty string
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    
	function log(logText) {
		if (logIt) {
			if (!window.console) {
				alert(logText);
			} else {
				console.log(logText);
			}
		}
	}

//<ANF.415 - gveit>
//
	try {
		dojo.addOnLoad(setReferrer);
	} catch (error) {
		log('ERROR dojo.addOnLoad not available: ' + error);
	}
	function setReferrer() {
		//set referrer only if its not a sitecatalyst channel
		var isSiteCatalyst = false;

		try {		
			if (typeof(s_prop33) != "undefined") {
				isSiteCatalyst = true;
			}
			
			if ( (typeof(s) != "undefined") && (typeof(s.prop33) != "undefined") ) {
				isSiteCatalyst = true;
			}
		} catch (e) {
			log('Error: '+ e);
			isSiteCatalyst = false;
		}
		
		if (!isSiteCatalyst) {
			//gibt es cookie noch nicht, generiere ihn und setze referrer; sonst
			//ueberschreibe nur referrer.
		   	var sitename = '';
			if (document.title) {
				sitename = document.title;
			}
			log('setReferrer::set referrer to: '+ sitename);			
			setCookieMultiValue('CWSTATS', 'referrer', sitename);	        
		}
	}

    function omnitureProcessSiteCallBeforeScript() {
        if (existsCookie('CWSTATS')) {
        	//cookie exists
        	
        	//part1 - clicks_after_login
        	//
        	var clicks = null;
        	if (getCookieMultiValue('CWSTATS','clicks_after_login')!=null) {
        		//clicks after login muss im cookie vorhanden sein!! - darf von 
        		//C2C nicht initial gesetzt werden.
	        	try {
		            clicks = parseInt(getCookieMultiValue('CWSTATS','clicks_after_login'));
		            if(isNaN(clicks)) {
		                clicks = 1;
		            } else {
		                clicks ++;
		            }
					log('omnitureProcessSiteCallBeforeScript::set clicks_after_login to: '+ clicks);   		
		            setCookieMultiValue('CWSTATS', 'clicks_after_login', clicks);
				} catch (e) {
					log('Error: '+ e);
				}
			}
			if (typeof(s_prop32) != "undefined") {
				s_prop32 = clicks;
				log('omnitureProcessSiteCallBeforeScript::prop32: '+ s_prop32);   		
			}
			if ( (typeof(s) != "undefined") && (typeof(s.prop32) != "undefined") ) {
				s.prop32 = clicks;
				log('omnitureProcessSiteCallBeforeScript::prop32: '+ s.prop32);   						
			}            
        } else {
        	//prop32 auf null setzen
			if (typeof(s_prop32) != "undefined") {
				s_prop32 = null;
				log('omnitureProcessSiteCallBeforeScript::prop32: '+ s_prop32);   		
			}
			if ( (typeof(s) != "undefined") && (typeof(s.prop32) != "undefined") ) {
				s.prop32 = null;
				log('omnitureProcessSiteCallBeforeScript::prop32: '+ s.prop32);   						
			}         
        	//cookie existiert nicht
        	//part 2 - 1.1
        	setCookieMultiValue('CWSTATS', 'referrer', 'typed/bookmarked');
        }
        //part2 - 2.
        try {
	        var ref = getCookieMultiValue('CWSTATS','referrer');
			if (typeof(s_prop33) != "undefined") {
				s_prop33 = ref;
		   		log('omnitureProcessSiteCallBeforeScript::prop33: '+ s_prop33);
			}
	
			if ( (typeof(s) != "undefined") && (typeof(s.prop33) != "undefined") ) {
				s.prop33 = ref;
		   		log('omnitureProcessSiteCallBeforeScript::prop33: '+ s.prop33);			
			}
		} catch (e) {
			log('Error: '+ e);
		}
    }

    function omnitureProcessSiteCallAfterScript() {
    	//part2 - 4.
    	var sitename = '';
		if (document.title) {
			sitename = document.title;
		}
		log('omnitureProcessSiteCallAfterScript::set referrer to: '+ sitename);
		setCookieMultiValue('CWSTATS', 'referrer', sitename);
    }	
//</ANF.415>
