/*
 * Load Innofact Flash Layer for: NSA (NutzerStrukturAnalyse)
 * Precondition: Global Variables:
 *		NSAInnofact_herkunftsId 
 *		NSAInnofact_swfUrl
 *		NSAInnofact_swfInstallUrl
 */
	
function NSAInnofact (herkunftsId, swfUrl, swfInstallUrl) {
	if (herkunftsId) {  	/* HIER FÜR JEDEN EINBAU EINE NEUE ID EINTRAGEN (1-42) */
		if (herkunftsId.match(/paketschein/i)) 		{ this.herkunftsId = 21; }
		else if (herkunftsId.match(/sendungsstatus/i)) 	{ this.herkunftsId = 22; }
		else if (herkunftsId.match(/registrieren/i))	{ this.herkunftsId = 24; }
		else if (herkunftsId.match(/auftragsliste/i)) 	{ this.herkunftsId = 25; }
		else if (herkunftsId.match(/loginFailed/i)) 	{ this.herkunftsId = 26; }
		
		else if (herkunftsId.match(/Willkommen/i)) 		{ this.herkunftsId = 31; }
		else if (herkunftsId.match(/Leistungen/i)) 		{ this.herkunftsId = 32; }
		else if (herkunftsId.match(/Kontakt/i)) 		{ this.herkunftsId = 33; }
		else if (herkunftsId.match(/Hilfe/i)) 			{ this.herkunftsId = 34; }
		else if (herkunftsId.match(/FAQ/i)) 			{ this.herkunftsId = 35; }
	} else {
		this.herkunftsId = 	1 ;
	}  
	
	var _contentRes  = 	HermesGlobalData.get( "HERMES_CONTENTRES_LOCATION") ;
	if (! _contentRes) {
		_contentRes="/nowcm/prips_de_de/prips/resources/";
	}
		
	if (swfUrl) { this.swfUrl=		swfUrl;}
	else {
		// this.swfUrl ="/wps/themes/html/Hermes-Standard/NSA_Innofact/media/bannerHermes.swf";
		this.swfUrl = _contentRes + "NSA_Innofact/media/bannerHermes.swf";
	}
	
	if (swfInstallUrl) {this.swfInstallUrl= swfInstallUrl;} 
	else {
		// this.swfInstallUrl= "/wps/themes/html/Hermes-Standard/NSA_Innofact/media/expressinstall.swf";
		this.swfInstallUrl= _contentRes + "NSA_Innofact/media/expressinstall.swf";
	}
	
	this.nsaFeature = true;
	if (HermesGlobalData) {
		var features = HermesGlobalData.get("HERMES_FEATURES");
		if (features) {
			var nsaFeature=features.FEATURE_NSA_PRIPS;
			if (!nsaFeature) {
				this.nsaFeature = false;
			}
		}
	}
	
	this.t24h= 			0;        /* Platzhalter DER ABGELAUFENEN ZEIT SEIT DEM ERSTEN AUFRUF */
	this.tSperrZeit=	86400000; /* SPERRZEIT IN 1/1000 SEKUNDEN (86400000 entspricht 24 h) */
	
	this.countMax=		1;        /* MAX. ANZAHL AN AUFRUFEN */
	this.tDelCall=		10000;    /* VERZÖGERUNG AUFRUF 10000 */
	this.tDelay=		30000;    /* ANZEIGEZEIT:  30000 */
	this.filter=		0.05;      /* FILTER 100% ALLER BESUCHER ERHALTEN DEN Flash-Layer */
	
	/* NICHT ZU VERÄNDERNDE PARAMETER */
	this.tToday=		new Date();	/* SPEICHERN DER ZEIT VOM AUFRUF DER SEITE */
	this.tStart=		this.tToday.getTime();
	this.t24hflag=		0;         			/* FLAG FÜR DIE 24H ANZEIGE*/
	this.dat=			window.location.href; 	/* SPEICHERN DES NAMENS DER AUFRUFENDEN DATEI */
	
	this.dnr=			this.randomString();
	this.treffer=		Math.random();			/* ZUFALLSZAHL ZUM ZUFÄLLIGEN AUFRUF DES LAYERS */

	this.flashvars=	 	{
		  hid: 	this.herkunftsId,
		  host: this.dat,
		  uid: 	this.dnr
	};
	this.params=			{
		  menu: "false",
		  quality: "high",
		  salign: "t",
		  wmode: "transparent"
	};
	this.attributes=		{
		  id:   "Content1",
		  name: "Content2"
	};
	
	// Expiration time of cookies
	this.ablauf = new Date();
	var inEinemJahr = this.ablauf.getTime() + (365 * 24 * 60 * 60 * 1000);
	this.ablauf.setTime(inEinemJahr);
}
	
NSAInnofact.prototype.readCookie= 	function (name) {		/* FUNKTION ZUM AUSLESEN DES COOKIES */	
		  var vCookie = document.cookie;
		  var posName = vCookie.indexOf("; " + name + "=");
		  if (posName == -1) {
		    if (vCookie.indexOf(name + "=") == 0) posName = 0;
		    else return null;
		  }
		  var valStart = vCookie.indexOf("=", posName)+1;
		  var valCapper = vCookie.indexOf(";", posName+1);
		  if (valCapper == -1) valCapper = vCookie.length;
		
		  var val = vCookie.substring(valStart, valCapper);
		  return unescape(val);
};
	
NSAInnofact.prototype.showDivInno=	function () {		/* FUNKTION ZUM SICHTBARMACHEN DES LAYERS */
		  document.getElementById('NSA_Layer').style.visibility='visible';
		  var count = parseFloat(this.readCookie('countInnoHermes'))+1;
		  document.cookie = "countInnoHermes=" + count + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
};
	
NSAInnofact.prototype.hideDivInno=	function () { 		/* FUNKTION ZUM VERSTECKEN DES LAYERS */
	  document.getElementById('NSA_Layer').style.visibility='hidden';
	 
};
	
NSAInnofact.prototype.calledLayer=	function () { 		/* FUNKTION ZUM SETZEN DES FLAGS, DASS AUF LAYER GEKLICKT WURDE */
	  document.cookie = "calledInnoHermes=1; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
	  document.getElementById('NSA_Layer').style.visibility='hidden';
	 
};

NSAInnofact.prototype.randomString=	function () {		/* GENERIERUNG EINER ZUFALLSNUMMER FÜR DEN LINK */
		var l1,l2,l3,a,b,c,d;
		var r='abcdefghijklmnopqrstuvwxyz';
		l1 = Math.round(Math.random() * 26);
		l2 = Math.round(Math.random() * 26);
		l3 = Math.round(Math.random() * 26);
		a  = Math.round(Math.random() * 1000);
		b  = Math.round(Math.random() * 1000);
		c  = Math.round(Math.random() * 1000);
		d  = Math.round(Math.random() * 1000);
		return (r.charAt(l1)+''+r.charAt(l2)+''+r.charAt(l3)+''+a+''+b+''+c+''+d);
};

NSAInnofact.prototype.doIt= function() {	
	if ( ! this.nsaFeature ) { return; }
	/* Die brauchen die CallBacks global */
	window.showDivInno= this.showDivInno;
	window.calledLayer= this.calledLayer;
	window.hideDivInno= this.hideDivInno; 

 	if ( this.readCookie("cStartInnoHermes") == null ) {			/* ERSTER AUFRUF DES COOKIES */
		  var cToday   = new Date();//START TIME
		  var cHours   = cToday.getHours();
		  var cMinutes = cToday.getMinutes();
		  var cSeconds = cToday.getSeconds();
		  /* SETZEN DER ZEIT VOM ERSTEN AUFRUF */
		  document.cookie = "cStartCountInnoHermes=" + cToday.getTime() + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
		  document.cookie = "countInnoHermes=0; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
		  document.cookie = "cStartInnoHermes=" + cHours + ':' + cMinutes + ':'+cSeconds + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
 	}

 	if ( this.readCookie("tInnoHermesAufruf") != null ) {			/* COOKIE AUSLESEN - ABFRAGE SPERRZEIT DES COOKIES */
		this.t24h = this.readCookie('tInnoHermesAufruf') - this.tStart;	
	 	if ( this.t24h < this.tSperrZeit && parseFloat(this.readCookie("countInnoHermes")) >= this.countMax) {
	  		this.t24hflag = 1;
	  	}
 	}

 	swfobject.embedSWF ( this.swfUrl , "NSA_FlashObjectId", "400", "400", "7.0.0", 
		this.swfInstallUrl , this.flashvars, this.params, this.attributes);
		
	 /* WENN FILTER ZUM AUFRUF PASST, LAYER ANZEIGEN. */
	 if(this.treffer >= 0.0 && this.treffer <= this.filter) {
	   if(parseFloat( this.readCookie("countInnoHermes"))< this.countMax && this.t24hflag == 0 ) {
	      setTimeout(this.showDivInno.bind(this), this.tDelCall);
	      setTimeout(this.hideDivInno.bind(this), (this.tDelay + this.tDelCall));
	      var cToday   = new Date(); 
	      var cHours   = cToday.getHours();
	      var cMinutes = cToday.getMinutes();
	      var cSeconds = cToday.getSeconds();
	      document.cookie = "tInnoHermesAufruf=" + cToday.getTime() + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
	      document.cookie = "cStartCountInnoHermes=" + cToday.getTime() + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
	      document.cookie = "cStartInnoHermes=" + cHours + ':' + cMinutes + ':'+cSeconds + "; path=/;" + " expires=" + this.ablauf.toGMTString() + ";";
	   }
	 }
};


NSAInnofact.prototype.writeLayerDiv= function() {	
	 if ( ! this.nsaFeature ) { return; }
	 //  Write the flash div
	 var NSA_LayerStyle="position:absolute; top:290px; left:350px; width:410px; height:410px; visibility:hidden;";
	  
	 document.write('<div id="NSA_Layer" style="' + NSA_LayerStyle + '"> <div>');
	 document.write('<object id="NSA_FlashObjectId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="400">');
	 document.write('<param name="movie" value="' + this.swfUrl + '" />');
	 document.write('<!--[if !IE]>-->');
	 document.write('<object type="application/x-shockwave-flash" data="' + this.swfUrl + '" width="400" height="400">');
	 document.write('<!--<![endif]-->');
			
	 var errDivStr = ' "<div> <div id="error"> <strong>Sie benötigen hier den aktuellen Flashplayer </strong><br />'
		+ 'Klicken Sie bitte <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW">hier</a>,'
		+ 'um zum Downloadlink auf der Herstellerseite zu gelangen. '
		+ 'Download und Installation benötigen max. 3 Minuten (Modem 56K)<br /><br /><br />'
		+ '<center> <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW" '
		+ 'title="Get Adobe Flash Player">'
		+ '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" border="0" alt="Get Adobe Flash Player">'
		+ '</a> </center> </div> </div>';
	 document.write(errDivStr);
	 document.write('<!--[if !IE]>-->');
	 document.write('</object>');
	 document.write('<!--<![endif]-->');
	 document.write('</object>');
	 document.write(' </div>  </div>');

};

NSAInnofact.prototype.doAllTheWork = function() {	
	this.writeLayerDiv();
	this.doIt();
};
