﻿<!--
//var global zur Verfügung stellen
var giftwrapper = 0; // Geschenkpapier
var insurance 	= 0; // Versicherung
var coupon 			= 0; //	Gutschein
var shipping 		= 0; // Bearbeitungsgebühr
var ticketprice = 0; // Zwischensumme
var total       = 0; // Gesamtsumme
//warenkorbpositionen
var amount 			= 0;  // Zwischensumme mit Zusatzleistungen
var price 			= 0;  // Zwischensumme mit Zusatzleistungen, formatiert sprache/land
var price_formatted = 0; // Wärungszeichen, formatiert sprache/land
var currency_symbol = 0;
//anzahl merkzettelitems / events
var merkitems // Anzahl Items auf dem Merkzettel
//reservierungs-countdown
var jetzt = new Date(); //aktuelle Datum
var reservation_duration = 0; // Zeitpunkt in millisec
var reservierungs_restzeit_min = 0; // restzeit min
var reservierungs_restzeit_sec = 0; // restzeit sec
var affiliate="";

var warenkorbInfos = {
	show: function() {
		
		var label = "";
		var htmlString = "";
		
		try {
			//cookie holen
			encodedCookieValue = getCookie("webshop");
			//cookie value decodieren
			decodedCookieValue = decode64(encodedCookieValue);
			
			/* Zusätzliche Informationen werden aktuell nicht verwendet
			giftwrapper = getCookieParamByNameWithCookieValue("giftwrapper",decodedCookieValue);   // Geschenkpapier
			insurance 	= getCookieParamByNameWithCookieValue("insurance",decodedCookieValue);		 // Versicherung	
			coupon = getCookieParamByNameWithCookieValue("coupon",decodedCookieValue);				 //	Gutschein
			shipping = getCookieParamByNameWithCookieValue("shipping",decodedCookieValue);      // Bearbeitungsgebühr
			ticketprice = getCookieParamByNameWithCookieValue("ticketprice",decodedCookieValue);   // Zwischensumme
			total = getCookieParamByNameWithCookieValue("total",decodedCookieValue);         // Gesamtsumme
			*/
		
			//warenkorbpositionen
			amount = getCookieParamByNameWithCookieValue("amount",decodedCookieValue);        // Gesamt Ticktanzahl
	
			//price = getCookieParamByNameWithCookieValue("price",decodedCookieValue);         // Zwischensumme mit Zusatzleistungen		
			//price = price.replace(/\./g,",");
			//price_formatted = getCookieParamByNameWithCookieValue("price_formatted",decodedCookieValue); // Zwischensumme mit Zusatzleistungen, formatiert sprache/land
			//currency_symbol = getCookieParamByNameWithCookieValue("currency_symbol",decodedCookieValue); // Wärungszeichen, formatiert sprache/land
		
			//anzahl merkzettelitems / events
			merkitems = getCookieParamByNameWithCookieValue("merkitems",decodedCookieValue);        // Anzahl Items auf dem Merkzettel
			//alert(merkitems);
		
			//debug
			//document.write(amount + " Ticket(s) | " + price +"&#8364;");
			//document.write("<br>");
			//document.write(decodedCookieValue);
			
			//Gesamt Ticktanzahl
			if ( amount == 1 ) { label = " Ticket" } else { label = " Tickets" } 
			htmlString = amount + label;
			document.getElementById("ticketInfo").innerHTML = htmlString;
			
			//Zwischensumme mit Zusatzleistungen, formatiert sprache/land
			//htmlString = price_formatted + " " + unescape(currency_symbol);
			//document.getElementById("zwischensummeInfo").innerHTML = htmlString;
			
			//Anzahl Items auf dem Merkzettel
			if ( merkitems == 1 ) { label = " Event" } else { label = " Events" } 
			htmlString = merkitems + label;
			document.getElementById("merkzettelInfo").innerHTML = htmlString;
			
			//reservierungs-countdown
			reservation_duration = getCookieParamByNameWithCookieValue("reservation_duration",decodedCookieValue); // Zeitpunkt in millisec
			reservierungs_restzeit_min = (reservation_duration - jetzt.getTime()) / 60000; // restzeit min
			reservierungs_restzeit_sec = (reservation_duration - jetzt.getTime()) % 60000 / 1000; // restzeit sec

			if (reservierungs_restzeit_min > 0) {
				if (reservierungs_restzeit_min < 5) { 
					//status im header setzen
					document.getElementById("link_warenkorb").className = "link_warenkorb countdown";
				}
			}  else if (reservation_duration < 0) {
				//status im header setzen
				document.getElementById("link_warenkorb").className = "link_warenkorb abgelaufen";
			}
			
		} catch (e) {
	
			//fehlerfall bzw. kein cookie gefunden
			//document.write("Allgemeinster Fehler ;-) bzw. kein Cookie gefunden");
			document.getElementById('teil_zwei_rechts').style.display = "none";	 //sichtbarer warenkorb
			document.getElementById('teil_zwei_rechts_nsw').style.display = "block"; //nichtsichtbarer warenkorb
			
		}//end try
	}
}//end 

var reservierungsCountdown = {

	show: function() {
		var jetzt = new Date();
		var reservation_duration = 0;
		var reservierungs_restzeit_min = 0;
		var reservierungs_restzeit_sec = 0;
		
		try {
			//cookie holen
			encodedCookieValue = getCookie("webshop");
			//cookie value decodieren
			decodedCookieValue = decode64(encodedCookieValue);
			
			//Affiliate aus Cookie auslesen
			var id = getCookieParamByNameWithCookieValue("id",decodedCookieValue);
			affiliate = id.charAt(0) + id.charAt(1) + id.charAt(2);
				
			//reservierungs-countdown
			reservation_duration = getCookieParamByNameWithCookieValue("reservation_duration",decodedCookieValue); // Zeitpunkt in millisec
			//alert(reservation_duration);
			reservierungs_restzeit_min = (reservation_duration - jetzt.getTime()) / 60000; // restzeit min
			reservierungs_restzeit_sec = (reservation_duration - jetzt.getTime()) % 60000 / 1000; // restzeit sec
			//debug
			//alert(reservierungs_restzeit_min +":"+reservierungs_restzeit_sec+"|"+reservation_duration);
			var remain = Math.floor((reservation_duration - jetzt.getTime()) / 1000); 

			if(remain > 0) {
				// Neuer Reservierungszaehler.. ag
				var mini = document.getElementById("restreservierungszeit_mini");
				var resText = document.getElementById("restreservierungszeit_text");
				var resHead = document.getElementById("restreservierungszeit_headline");
				// Gesamte Restzeit in sec aus webshop Cookie
				// Zeit herunterzaehlen und bei unter 5min Farbe aendern, ab 0sec ist Restzeit ab
				var timer = setInterval( function () {
					mini.innerHTML = (Math.floor(remain/60) < 10 ? "0":"") + Math.floor(remain/60) + ":" + (remain%60 < 10 ? "0": "") + remain %60;
					resText.innerHTML = shoppingCartInfos.message.text;
					if (remain < 300) {if (mini.className != 'redCD') mini.className = 'redCD';}
					if (remain <= 0){
						resHead.innerHTML = shoppingCartInfos.message.headline2;
						resHead.className = "rot bold";
						resText.innerHTML = shoppingCartInfos.message.text2;
						//Affiliate anhängen
						var newHref = jQuery("#restreservierungszeit_text a").attr("href") + "&affiliate=" + affiliate;
						jQuery("#restreservierungszeit_text a").attr("href", newHref);
						
						//status im header setzen
						//document.getElementById("link_warenkorb").className = "link_warenkorb abgelaufen";
						window.setTimeout("generateReservierungsLayer()", 250);
					} if (--remain < 0 ) {clearInterval(timer);}
				},1000);
			}
			if (reservation_duration == 0 && document.getElementById("reservierungsgrafik")) { 
				document.getElementById("reservierungsgrafik").style.display = "none";
				document.getElementById("reservierungstext").style.display = "none";
			}
			
		} catch (e) {
			//fehlerfall bzw. kein cookie gefunden
			document.getElementById("reservierungsgrafik").style.display = "none";
			document.getElementById("reservierungstext").style.display = "none";
		}//end try
	},
	
	setTimeStamp: function(id) {
		var myDate = new Date();
		var microTime = myDate.getTime().toString();
		document.getElementById(id).value = microTime;
	},
	appendTimeStamp: function(obj) {
		var myDate = new Date();
		var microTime = myDate.getTime().toString();
		document.location.href = obj.href + "&timestamp=" + microTime;
	}
}//end

function generateReservierungsLayer() {
		//elemente
		var layer = document.createElement('div');
		var head = document.createElement('div');
		var content = document.createElement('div');
		var notice = document.createElement('span');
		var sub_notice = document.createElement('span');
		//var killer = document.createElement('a');
		//var shadow = document.createElement('div');
		var shadow = document.createElement('iframe');
		var closen = document.createElement('a');
		
		//eigenschaften
		layer.id = "reservierungszeit_layer"; 			
		head.className = "head";
		content.className ="content";
		notice.className = "notice";
		sub_notice.className = "sub_notice";
		shadow.id = "reservierungszeit_shadow";
		//IE 6 Workaround für unsichere Elementemeldung, benötigt die /staticsite/blank.htm
		shadow.src = "/staticsite/blank.htm";
		//killer.href = "tickets.html?fun=resetsession&doc=start";
		closen.className = "layerclose";
		closen.href = "tickets.html?fun=resetsession&doc=start&affiliate=" + affiliate;		
		
		//texte
		var t1 = document.createTextNode(shoppingCartInfos.message.t1);
		var t2 = document.createTextNode(shoppingCartInfos.message.t2);
		var t3 = document.createTextNode(shoppingCartInfos.message.t3);
		//var t4 = document.createTextNode(shoppingCartInfos.message.t4);
		var t5 = document.createTextNode(shoppingCartInfos.message.t5);
		var t6 = document.createTextNode(shoppingCartInfos.message.t6);
		
		//ineinander verschachteln
		layer.appendChild(head);
		head.appendChild(closen);
		closen.appendChild(t6);
		content.appendChild(t1);
		notice.appendChild(t2);
		content.appendChild(notice);
		content.appendChild(t3);
		//killer.appendChild(t4);
		//content.appendChild(killer);
		sub_notice.appendChild(t5)
		content.appendChild(sub_notice);
		layer.appendChild(content);
	try {
		//in DOM hängen
		document.body.appendChild(layer);
		document.body.appendChild(shadow);
	} catch (e) {
		//fehlerfall
	}//end try	
}

function showTooltip(e) {	
			var string = null; 
			var shadowSize = 3;
			var tooltipMaxWidth = 350;
			try {	
				//elemente erzeugen
				if (!document.getElementById("tooltip")) {	
					tooltip = document.createElement('div');
					tooltip.id = 'tooltip';
					tooltipShadow = document.createElement('div');
					tooltipShadow.id = 'tooltipShadow';
					
					tooltip.style.display='none';	
					tooltipShadow.style.display='block';
					document.body.appendChild(tooltip);
					document.body.appendChild(tooltipShadow);	
				}//end if
				
				if (reservierungs_restzeit_min > 0) {
					
					string =  shoppingCartInfos.message.tooltip_part1 + " " + Math.floor(reservierungs_restzeit_min) + " " + shoppingCartInfos.message.tooltip_part1;
					if (reservierungs_restzeit_min < 5) { string = shoppingCartInfos.message.headline }
					
				} else if (reservierungs_restzeit_min < 0 && reservation_duration != 0) {
					string = shoppingCartInfos.message.headline2;
				}
				
				if (string != null) {
					tooltip.style.display='block';
					tooltipShadow.style.display='block';
		
					tooltip.style.width = null;	
					tooltip.innerHTML = "<span>" + string + "</span>";
					
					//tooltip postion
					if (navigator.appName=="Microsoft Internet Explorer"){		// nur für den IE
						tooltip.style.left = e.clientX + 10 + 'px';
						tooltip.style.top = e.clientY + 10 + 'px';					
						tooltipShadow.style.left = e.clientX + 10 + shadowSize + 'px';
						tooltipShadow.style.top = e.clientY + 10 + shadowSize + 'px';
					} else {			
						tooltip.style.left = e.pageX + 10 + 'px';
						tooltip.style.top = e.pageY + 10 + 'px';					
						tooltipShadow.style.left = e.pageX + 10 + shadowSize + 'px';
						tooltipShadow.style.top = e.pageY + 10 + shadowSize + 'px';
					}
					
					if (tooltip.offsetWidth>tooltipMaxWidth) { tooltip.style.width = tooltipMaxWidth + 'px' }		
					tooltipShadow.style.width = tooltip.offsetWidth + 'px';
					tooltipShadow.style.height = tooltip.offsetHeight + 'px';
				}
				
		} catch (e) {
			//fehlerfall bzw. kein cookie gefunden
		}//end try
}//end function

function hideTooltip() {	
	document.getElementById("tooltip").style.display='none';
	document.getElementById("tooltipShadow").style.display='none';		
}//end function


jQuery(function() {
	//encodedCookieValue = getCookie("webshop");
	//decodedCookieValue = decode64(encodedCookieValue);
	
	//jQuery("span#shoppingCart").append(getCookieParamByNameWithCookieValue("amount",decodedCookieValue));
	//jQuery("span#notice").append(getCookieParamByNameWithCookieValue("merkitems",decodedCookieValue));	
});

function getCookie(name) {
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0;
	while (i < clen) { 
		var j = i + alen;	
		if (document.cookie.substring(i, j) == arg) 		
			return getCookieValue(j); 
			i = document.cookie.indexOf(" ", i) + 1;		
			if (i == 0) break; 
	}//end while
	return null;
}//end function

function getCookieValue(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));	
}//end function

function getCookieParamByNameWithCookieValue(name,cookieValue) {
	var params = cookieValue.split("&");
	var param_pair;				
	for (var i=0; i < params.length; i++) {		
		param_pair = params[i].split("=");	
		if (param_pair[0].toString() == name) {		
				return decodeURIComponent(param_pair[1]); 			
		}//end if
	}//end for
}//end function

// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

function decode64(input) {
	 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));
      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;
      output = output + String.fromCharCode(chr1);
      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);
   return output;
}//end function

function encode64(input) {
	 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;
      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }
      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   return output;
}
//-->
