var color = 84;
var colorPrice = 28.0;
var lastSelect, currLang, currStyle, iPrintType, currPrint, iPrnt;
var currBrowser = {agent: '', version: ''};

var enws = {
	msgs: {
		de: {
			checkData: "Bitte warten, Daten werden geprüft.",
			maxOrder:  "Die maximale Bestellmenge wurde überschritten.",
			noPopup :  "Ihr Browser scheint Popups zu blockieren, bitte erlauben Sie Popus für diese Seiten um die Zahlung auzuführen."
		},
		en: {
			checkData: "Please wait while data is checked.",
			maxOrder:  "The maximum order amount is exceeded.",
			noPopup:   "Your browser seems to block pop-ups, please allow pop-ups for this site to ensure that your payment can be processed correctly."
		}
	},
	currForm: false,

	PD: {
		link: function (item, KuNr, Name, UT) {
			if(UT) this.track();
			return Bad.linkToPdPortal(item, KuNr, Name);
			//return false;
		},
		track: function () {
			var url = '/index.php?mod=Ajax&action=gotoPD'
			new Ajax.Request(url, { method: "get"} );
		}
	},

	browserCheck : function () {
		if (!window.RegExp) return false;
		var AGENTS = ["opera","msie","safari","firefox","netscape","mozilla"];
		var agent  = navigator.userAgent.toLowerCase();
		var browser = navigator.appName.toLowerCase();
		for (var i = 0; i < AGENTS.length; i++) {
			var agentStr = AGENTS[i];
			if (agent.indexOf(agentStr) != -1) {
				var versionExpr = new RegExp(agentStr + "[ \/]?([0-9]+(\.[0-9]+)?)");
				var version = 0;
				if (versionExpr.exec(agent) != null) {
					version = parseFloat(RegExp.$1);
				};

				//alert("Browser: "+ agentStr +" Version: "+ version +" Name: "+ navigator.appName +" Code: "+ navigator.appCodeName);
				currBrowser.agent = agentStr;
				currBrowser.version = version;

				if (agentStr == "opera") return version >= 8;
				if (agentStr == "safari") return version >= 522;
				if (agentStr == "msie") return (version >= 5.5 && agent.indexOf("powerpc") == -1);
				if (agentStr == "netscape") return version > 6;
				if (agentStr == "firefox") return version >= 1.5;
				if (browser  == "konqueror") return version >= 5.5;
			};
		};
		return !!document.getElementById;
	},

	flashCheck:function () {
		var max = 50;
		var version = 0;

		if(typeof(navigator.plugins["Shockwave Flash"]) == "object") {
			var description = navigator.plugins["Shockwave Flash"].description;
			version = description.substr(16, (description.indexOf(".", 16) - 16));
		} else if(typeof(ActiveXObject) == "function") {
			for(var i = 2; i < (max + 1); i ++) {
				try {
					if(typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i)) == "object") version = i;
				} catch(error) {}
			}
		}
		return (version>0 ? 'flash' : 'none') +':'+  version;
	},

	getBrowserInfo: function() {
		if($('use_bw')) $('use_bw').value = currBrowser.agent +':'+ currBrowser.version;
		if($('use_fl')) $('use_fl').value = enws.flashCheck();
	},

	toggleAddress:function (name) {
		var items = $(name+'_chBox');
		var layer = $(name+'_Layer');
		if(items.checked){
			var eff = new Effect.BlindDown(layer, {duration:.45});
		} else {
			var eff = new Effect.BlindUp(layer, {duration:.45});
		}
	},

	checkOut: {
		Url: false,
		payCard: false,
		currPayMod: false,

		init: function (cForm) {
			this.start();
			var url="/index.php?mod=Ajax&lang="+ jsLANG +"&action=checkout";
			new Ajax.Request(url, {
				parameters: $('enwsCheckOutForm').serialize(true),
				method: 'post',
				onComplete: function(e){
					enws.checkOut.onSend(e);
				}
			});
			return false;
		},
		start: function (){
			var arrayPageSize = getPageSize();
			var arrayPageScroll = getPageScroll();
			var loadingTop = arrayPageScroll[1] + (arrayPageSize[3] / 2 - 40);
			var loadingLeft = arrayPageSize[0] / 2 - 150;

			var objOverlay = $('overlay');
			objOverlay.onclick = function(){ return false; };
			var objLoadingDiv = '<div id="loadingInfo" style="font-size:16px; color:#fff; border:1px #fff solid; width:350px; padding:20px; background-color:#333; position:absolute; top:'+ loadingTop +'px; left:'+ loadingLeft +'px;"><img src="'+ fileLoadingImage +'" width="20" height="20" align="absmiddle" /> &nbsp; '+ enws.msgs[jsLANG].checkData +'</div>';
			objOverlay.innerHTML = objLoadingDiv;
			Element.setWidth('overlay', arrayPageSize[0]);
			Element.setHeight('overlay', arrayPageSize[1]);
			new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
		},

		terminalCheck: function(){
			if(this.payCard) return;
			if (payTerminal.closed == true) {
				alert("Zahlung wurde nicht abgeschlossen.");
				new Effect.Fade('overlay', { duration: overlayDuration});
			} else {
				window.setTimeout('enws.checkOut.terminalCheck()', 1000);
			}
		},

		onSend: function (e) {
			//alert(e.responseText);
			eval("var data = "+e.responseText+";");
			if(data.status == 'OK') {
				this.Url = data.nextUrl;
				switch(data.paymethod) {
					case 'card': enws.checkOut.payMethod(data.paymethod); break;
					default: location.href = this.Url; break;
				}
			} else {
				var objOverlay = $('overlay');
				objOverlay.innerHTML = '';
				alert(data.mgs);
				new Effect.Fade('overlay', { duration: overlayDuration});
			}
		},

		payMethodSelect: function(mod) {
			//alert(mod);
			var duration = 0.1;
			if(this.currPayMod == mod) return;

			if(this.currPayMod && $('payMethodRow_'+ this.currPayMod)) $('payMethodRow_'+ this.currPayMod).removeClassName('selected');
			if($('payMethodRow_'+ mod)) $('payMethodRow_'+ mod).addClassName('selected');

			if(this.currPayMod && $('payMethodInfo_'+ this.currPayMod)) new Effect.BlindUp('payMethodInfo_'+ this.currPayMod, { duration: duration, queue: 'end'});

			if($('payMethodInfo_'+ mod)) {
				new Effect.BlindDown('payMethodInfo_'+mod, {duration: duration});
			}
			this.currPayMod = mod;

		},

		payMethod: function(cPM, url) {
			//alert("PayMethod: "+ cPM);
			var objOverlay = $('overlay');
			objOverlay.innerHTML = '';
			//new Effect.Fade('overlay', { duration: overlayDuration});
			switch (cPM) {
				case 'card': saferpayTerminal.openPopupTerminal(); break;
				case 'OK': location.href = this.Url; break;
			}
			return false;
		}
	},

	scrollToAnchor: function(anchorId) {
		if(currBrowser.agent == 'msie' && currBrowser.version < 7) { return true; }
		new Effect.ScrollTo(anchorId,  { duration: .5, offset:-50} );
		return false;
	},

	boxToggle: function(item) {
		var box = item.parentNode;
		var boxContent = box.getElementsByTagName("div")[1];//item.nextSibling;
		//var boxContent = item.nextSibling;
		var view = boxContent.style.display;

  		if(enws.hasClass(item, "mfDw") ) {
  			new Effect.BlindUp( boxContent, { duration: .45});
  			enws.addClass(boxContent, "mfIsOpen");
  			enws.addClass(item, "mfUp");
  			enws.removeClass(item, "mfDw");
 		} else {
   			new Effect.BlindDown( boxContent, { duration: .45} );
  			enws.removeClass(boxContent, "mfIsOpen");
  			enws.addClass(item, "mfDw");
  			enws.removeClass(item, "mfUp");
  		}
		//new Effect.BlindUp( boxContent, { duration: duration, queue: 'end', afterFinish: function(){ enws.layout.blindIn(panel_in, speed); } });
	},

	langToggle: function () {
		var box = $('mfLanguageSwitcherSelect');
  		if(enws.hasClass(box, "mfUp") ) {
  			enws.addClass(box, "mfDw");
  			enws.removeClass(box, "mfUp");
   			new Effect.BlindDown( box, { scaleX:true, duration:.5});
  		} else {
  			enws.addClass(box, "mfUp");
  			enws.removeClass(box, "mfDw");
  			new Effect.BlindUp( box, { scaleX:true, duration:.5});
 		}
	},

	designSwitch : function(design, img, style) {
		currLang = false;
		currStyle = style;
		if(iPrintType == 'imag' || iPrintType == 'ecard') this.iPrintInit(iPrintType)

		var Langs = document.getElementsByName('language');
		var fixLangs = document.getElementsByName('iFixLang');

		if(Langs.length > 0) {
			//alert("Lang is Set !!!");
			for(var i=0; i < Langs.length; i++) {
				if(Langs[i].checked) var currLang = Langs[i].value;
			}
			var newImg = enws.designLangSwitch(design.toLowerCase(), currLang ? currLang : jsLANG);
			if(newImg) img = newImg;

		}else if(fixLangs.length > 0) {
			//alert("fixLang is Set !!!");
			if(fixLangs.length == 1){
				var currLang = fixLangs[0].value;
			} else {
				for(var i=0; i < fixLangs.length; i++) {
					if(fixLangs[i].checked) var currLang = fixLangs[i].value;
				}
			}
			var newImg = enws.designLangSwitch(design.toLowerCase(), currLang ? currLang : jsLANG);
			if(newImg) img = newImg;
		}

		if(!img) return;
		var prodImg = document.getElementById('prodImg');
		prodImg.src = img;
	},

	langSwitch : function (lang, img) {
		currLang = lang;
		var currDesign = false;
		var Designs = document.getElementsByName('design')
		if( Designs ) {
			for(var i=0; i < Designs.length; i++) {
				if(Designs[i].checked) var currDesign = Designs[i].value;
			}
			var newImg = enws.designLangSwitch(currDesign ? currDesign.toLowerCase(): false, lang);
			if(newImg) img = newImg;
		}
		if(iPrnt && currPrint) {
			if(iPrnt[currPrint] && iPrnt[currPrint][lang]) enws.iPrintInit(iPrintType);
		}
		if(!img) return;
		var prodImg = $('prodImg');
		prodImg.src = img;

	},

	designLangSwitch: function (design, lang) {
		if(!DesignLangs) return false;
		if(!DesignLangs[design]) return false;
		if(!DesignLangs[design][lang]) return false;
		return DesignLangs[design][lang];
	},

 	layout:{
 		change: function(type) {
 			if(lastSelect == type) return;
 			var resizeSpeed = 9;
 			if(type == 'self') {
 				if(document.getElementById('layout_select').style.display == 'none') this.blindIn('layout_self', 7);
 				else this.blindUp('layout_select', 'layout_self', 7);
 			}
 			if(type == 'select') {
 				if(document.getElementById('layout_self').style.display == 'none') this.blindIn('layout_select', 7);
 				else this.blindUp('layout_self', 'layout_select', 7);
 			}
 			lastSelect = type;

 		},
 		blindUp: function(panel_up,panel_in, speed) {
  			var duration = (11 - speed) * 0.15;
			new Effect.BlindUp( panel_up, { duration: duration, queue: 'end', afterFinish: function(){ enws.layout.blindIn(panel_in, speed); } });
 		},
 		blindIn: function(panel, speed) {
  			var duration = (11 - speed) * 0.15;
			new Effect.BlindDown( panel, { duration: duration} );
 		}
 	},

  	iPrintInit: function (art) {
  		iPrintType = art;
 		var tmp = document.getElementsByName('iprint');
 		for(var i=0; i < tmp.length; i++) {
 			if(tmp[i].checked) {
 				var item = tmp[i];
 				enws.iPrint(item, art);
 				break;
 			}
 		}
 	},

	iPrint: function (item, art) {
 		if(!item.getAttribute('param')) return;
 		var field = $('tdiPrint');
 		var table = $('tbiPrint');
 		var inText = "";

 		eval("var data = {"+ item.getAttribute('param') +"};");
 		this.data = data;
 		this.art  = art;
 		this.pos  = data['cord'].split(',');
		currPrint = data['type'];

		if(art != 'ecard') {
 			table.style.left   = this.pos[0] +"px";
 			table.style.top    = this.pos[1] +"px";
	 		table.style.width  = this.pos[2] +"px";
	 		field.style.width  = this.pos[2] +"px";
 			field.style.height = this.pos[3] +"px";
		}

		var cType = data['type'].split('_');
		enws.iFreeLogoRefresh(cType[0]);

 		if((data['type'] == 'freetext' || data['type'] == 'logo_freetext') && document.getElementById('iPrint_freetext')) {
 			var iText = new Array();
 			var freeTextDiv = document.getElementById('iPrint_freetext');
 			var freeTextInputs = freeTextDiv.getElementsByTagName('input');
 			var aStyle = $('iPrintStyleLink') ? ' style="'+ $F('iPrintStyleLink')+'"' : '';

 			if(art == 'ecard') {
 				var zeile = 0;
				for(var i=0; i < freeTextInputs.length; i++) {
					freeTextInputs[i].disabled = false;
					if(freeTextInputs[i].value) {
						if(i < 5)  iText[zeile] = freeTextInputs[i].value;
						if(i == 0) iText[zeile] = freeTextInputs[i].value +"<br/>";
						if(i == 5) iText[zeile] = '<a href="mailto:'+ freeTextInputs[i].value +'"'+ aStyle +'>'+ freeTextInputs[i].value +'</a>';
						if(i == 6) iText[zeile] = '<a href="http://'+ freeTextInputs[i].value +'"'+ aStyle +'>'+ freeTextInputs[i].value +'</a>';
						if(iOpts['ZEILE'+zeile] && iOpts['ZEILE'+zeile] != '') iText[zeile] = '<font style="'+ iOpts['ZEILE'+zeile] +'">'+ iText[zeile] +'</font>';
						zeile++;
					}
				}
				inText = iText.join("<br/>");

 			} else {
				for(var i=0; i < freeTextInputs.length; i++) {
					freeTextInputs[i].disabled = false;
					iText[i] = freeTextInputs[i].value;
				}
				inText = iText.join("<br/>");
 			}

 		} else if(document.getElementById('iPrint_freetext')) {
 			var freeTextDiv = document.getElementById('iPrint_freetext');
			var freeTextInputs = freeTextDiv.getElementsByTagName('input');
			for(var i=0; i < freeTextInputs.length; i++) {
				freeTextInputs[i].disabled = true;
			}
			if(currLang && iPrnt) {
				if(iPrnt[data['type']] && iPrnt[data['type']][currLang]) inText = iPrnt[data['type']][currLang];
			} else {
				inText = data['value'];
			}
 		}


 		if(this.art == 'imag') {
 			var iUrl = "/index.php?mod=iText&w="+this.pos[2]+"&h="+this.pos[3]+"&text="+ escape(inText);
 			var optDataStyle = this.data['style'].split(';');

 			var itemDataStyle;
 			for(var o=0; o < optDataStyle.length; o++) {
 				itemDataStyle = optDataStyle[o].split("=");
 				var itemCurrStyle = this.iPrintCurrStyleObj(itemDataStyle[0]);
 				if(itemCurrStyle) iUrl += '&'+ itemDataStyle[0] +"="+ itemCurrStyle;
 				else iUrl += '&'+ optDataStyle[o];
 			}
 			var time = new Date();
 			iUrl += '&d='+ time.getTime();
 			inText = '<img src="'+ iUrl+'" width="'+this.pos[2]+'" height="'+this.pos[3]+'" border="0" alt="iPrint"/>';
 		} else {
	 		this.iStyle(field, data['style']);
 		}
 		field.innerHTML = inText;
 	},

	iPrintCurrStyleObj: function (str) {
 		if(!currStyle) return false;
		var optStyle = currStyle.split(';');
		for(var i=0; i < optStyle.length; i++) {
 			var itemStyle = optStyle[i].split("=");
 			if(itemStyle[0] == str) return itemStyle[1];
		}
		return false;
 	},

	iFreeLogo: function (f, w, h) {
		if(!this.data) return;
		document.getElementById('logo_file').value = f;
		document.getElementById('logo_width').value = w;
		document.getElementById('logo_height').value = h;
		var cType = this.data['type'].split('_');
		enws.iFreeLogoRefresh(cType[0]);
	},

	iFreeLogoRefresh: function (cType) {
		var now = new Date();

 		if(document.getElementById('iPrint_logo') && document.getElementById('imgiPrint')) {
			if(cType == 'logo') {
				document.getElementById('imgiPrint').src    = document.getElementById('logo_file').value +"?d="+ now.getTime();
				document.getElementById('imgiPrint').width  = document.getElementById('logo_width').value;
				document.getElementById('imgiPrint').height = document.getElementById('logo_height').value;
			} else {
				document.getElementById('imgiPrint').src    = "/images/spacer.gif";
				document.getElementById('imgiPrint').width  = "10";
				document.getElementById('imgiPrint').height = "10";
			}
 		}
	},

 	iFreeText: function () {
 		var field = document.getElementById('tdiPrint');
 		if(document.getElementById('iPrint_freetext')) {

			var iText = new Array();
			var freeTextDiv = document.getElementById('iPrint_freetext');
			var freeTextInputs = freeTextDiv.getElementsByTagName('input');
			var aStyle = $('iPrintStyleLink') ? ' style="'+ $F('iPrintStyleLink')+'"' : '';

			if(iPrintType == 'ecard') {
				var zeile = 0;
				for(var i=0; i < freeTextInputs.length; i++) {
					if(freeTextInputs[i].value) {
						if(i < 5)  iText[zeile] = freeTextInputs[i].value;
						if(i == 0) iText[zeile] = freeTextInputs[i].value +"<br/>";
						if(i == 5) iText[zeile] = '<a href="mailto:'+ freeTextInputs[i].value +'"'+ aStyle+'>'+ freeTextInputs[i].value +'</a>';
						if(i == 6) iText[zeile] = '<a href="http://'+ freeTextInputs[i].value +'"'+ aStyle+'>'+ freeTextInputs[i].value +'</a>';
						if(iOpts['ZEILE'+zeile] && iOpts['ZEILE'+zeile] != '') iText[zeile] = '<font style="'+ iOpts['ZEILE'+zeile] +'">'+ iText[zeile] +'</font>';
						zeile++;
					}
				}
				var inText = iText.join("<br/>");
			} else {
				for(var i=0; i < freeTextInputs.length; i++) {
					iText[i] = freeTextInputs[i].value;
				}
				var inText = iText.join("<br/>");
			}

	 		if(iPrintType == 'imag') {
	 			var iUrl = "/index.php?mod=iText&w="+this.pos[2]+"&h="+this.pos[3]+"&text="+ escape(inText);
 				var optDataStyle = this.data['style'].split(';');

 				var itemDataStyle;
 				for(var o=0; o < optDataStyle.length; o++) {
 					itemDataStyle = optDataStyle[o].split("=");
 					var itemCurrStyle = this.iPrintCurrStyleObj(itemDataStyle[0]);
 					if(itemCurrStyle) iUrl += '&'+ itemDataStyle[0] +"="+ itemCurrStyle;
 					else iUrl += '&'+ optDataStyle[o];
 				}
 				var time = new Date();
	 			iUrl += '&d='+ time.getTime();
 				inText = '<img src="'+ iUrl+'" width="'+this.pos[2]+'" height="'+this.pos[3]+'" border="0" alt="iPrint"/>';
 			}
			field.innerHTML = inText;
 		}
 	},

 	iStyle: function (field, style) {
 		var aStyle = style.split(';');

 		for(var s=0; s < aStyle.length; s++) {
 			if(aStyle[s] == '') continue;
 			this.iStyleSet(field, aStyle[s].split(':'));
 		}
 	},

 	iStyleSet: function (field, style) {
 		var setSytle = '';

 		switch (style[0]) {
 			case 'font-family'	: setStyle = "fontFamily"; break;
 			case 'font-size'	: setStyle = "fontSize"; break;
 			case 'text-align'	: setStyle = "textAlign"; break;
 			case 'line-height'  : setStyle = "lineHeight"; break;
 			default				: setStyle = style[0]; break;
 		};
 		//alert(setStyle +" : " + style[1]);
 		field.style[setStyle] = style[1];
 	},

 	freeorder : {
 		check: function(text, free) {
 			if(free) return;
 			if(!document.getElementById('order')) return;
 			if(document.getElementById('order').value == '') return;
 			var msg = false;

 			switch (this.currColor()) {
 				case '1':
					if(colorsVa[1]['ist'] >= colorsVa[1]['free']) msg = true;
					if(colorsVa[7]['ist'] > 0) msg = true;
					break;
 				case '7':
 					if(colorsVa[7]['ist'] >= colorsVa[7]['free']) msg = true;
  					if(colorsVa[1]['ist'] > 0) msg = true;
 					break;
 			}
 			if(msg == true) alert(text);
 		},

 		currColor: function () {
 			if(!document.getElementsByName('color')) return false;
 			var fields = document.getElementsByName('color');
 			for(var f=0; f < fields.length; f++ ){
 				if(fields[f].checked == true) return fields[f].value;
 			}
 		}
 	},
	price:{
		ccalc: function(value) {
			switch(value) {
				case '1': color = 0.0; break;
				case '2': case '3': color = 1*colorPrice; break;
				case '4': case '5': color = 2*colorPrice; break;
				case '6': case '7': color = 3*colorPrice; break;
			}
		},
		color: function(value){
			this.ccalc(value);
			this.calc();
		},
		calc: function () {
			if(!document.getElementById('priceCalc')) return;
			var items = document.getElementById('priceCalc').childNodes;
			var calc = 0, last = 0, currPrice=0, extraPrice=0;

			if(value < 1){
				document.getElementById('product_price').innerHTML = '0,00';
				return;
			};

			for(var tr=0; tr < items.length; tr++){
				var value = $('order').value;
				if(items[tr].nodeName=='TR') {
					//alert(items[tr].getAttribute('value'));
					eval("var calc = {"+ items[tr].getAttribute('value') +"};");
					if(calc.to == 'single'){
						currPrice = value * calc.price;
					} else if (calc.to == 'max' && value > calc.qua) {
						alert(enws.msgs[jsLANG].maxOrder);
						$('order').value = calc.qua;
					} else if(calc.to == 'under'){
						if(value <= calc.qua && currPrice == 0) currPrice = calc.price;
					} else if(calc.to == 'plus' && value > last.qua) {
						currPrice = last.price + (Math.ceil((value - last.qua)/calc.qua)*calc.price);
					} else if (calc.to == 'over' && value > calc.qua) {
						currPrice = calc.price;
					} else if (calc.to == 'extra') {
						extraPrice = calc.price;
					};
					last = calc;
				};
			};
			//alert (currPrice +" + "+ extraPrice + " + " + color);
			document.getElementById('product_price').innerHTML = this.numberFormat(currPrice+extraPrice+color,2,',','.');
		},

		numberFormat : function (number, laenge, sep, th_sep ) {
			number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
			str_number = number+"";
			arr_int = str_number.split(".");
			if(!arr_int[0]) arr_int[0] = "0";
			if(!arr_int[1]) arr_int[1] = "";
			if(arr_int[1].length < laenge){
				nachkomma = arr_int[1];
				for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
				arr_int[1] = nachkomma;
			};
			if(th_sep != "" && arr_int[0].length > 3){
				Begriff = arr_int[0];
				arr_int[0] = "";
				for(j = 3; j < Begriff.length ; j+=3){
					Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
					arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
				}
				str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
				arr_int[0] = str_first + arr_int[0];
			}
			return arr_int[0]+sep+arr_int[1];
		}
	},

	cartChange: function (id){
		var aktu = false;
		if(change[id]) change[id]=false;
		else{change[id]=true;};

		for(var i=0; i < change.length; i++) {
			if(change[i]) aktu=true;
		};
		if(aktu) document.getElementById('imgRecalc').src=imgb;
		else document.getElementById('imgRecalc').src=imgn;
	},

	cartDelete: function (text, entry) {
		if(text != '') var check=confirm(text);
		if(!check) return false;
		document.getElementById('cartEntryDelete').value = entry;
		return true;
	},

	checkChange: function (text){
		var aktu = false;
		for(var i=0; i < change.length; i++) { if(change[i]) aktu=true; };
		if(aktu) { alert(text); return false; };
		return true;
	},

	infoBox : {
		move : function(an, box) {
			var cleft = 0;
			var ctop = 0;
			var obj = an;
			while (obj.offsetParent) {
				cleft += obj.offsetLeft;
				ctop += obj.offsetTop;
				obj = obj.offsetParent;
			}
			box.style.left = cleft + 'px';
			ctop += an.offsetHeight + 4;
			if (document.body.currentStyle && document.body.currentStyle['marginTop']) {
				ctop += parseInt(document.body.currentStyle['marginTop']);
			}
			box.style.top = ctop + 'px';
		},

		hide : function (iName) {
			var boxdiv = document.getElementById(iName);
			if (boxdiv != null) {
				boxdiv.style.display='none';
				document.body.removeChild(boxdiv);
			}
		},

		init: function (an, iName, text, width) {
			var boxdiv = document.getElementById(iName);
			if (boxdiv != null) {
				if (boxdiv.style.display=='none') {
					this.move(an, boxdiv);
					boxdiv.style.display='block';
				} else {
					boxdiv.style.display='none';
				};
				return false;
			};
			boxdiv = document.createElement('div');
			boxdiv.innerHTML = '<div style="height:30px; text-align:right;">' +
									'<img src="/images/icons/close.gif" onclick="enws.infoBox.hide(\''+ iName +'\');" style="cursor:pointer;"/>' +
								'</div>' + text;

			boxdiv.className = "info";
			boxdiv.setAttribute('id', iName);
			boxdiv.style.display = 'block';
			boxdiv.style.position = 'absolute';
			boxdiv.style.width = width + 'px';
			//boxdiv.style.border = borderStyle;
			//boxdiv.style.backgroundColor = '#ddd';
			/*
			var contents = document.createElement('iframe');
			contents.scrolling = 'no';
			contents.frameBorder = '0';
			contents.style.width = width + 'px';
			contents.style.height = height + 'px';
			contents.src = href +"&pB=on";
			boxdiv.appendChild(contents);
			*/

			document.body.appendChild(boxdiv);
			this.move(an, boxdiv);
			return false;
		}
	},

	textSuggest : {
		activeBox: false,

		start : function() {
			hideSelectBoxes();
			hideFlash();

			// stretch overlay to fill page and fade in
			var arrayPageSize = getPageSize();
			Element.setWidth('overlay', arrayPageSize[0]);
			Element.setHeight('overlay', arrayPageSize[1]);

			new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });

			var arrayPageScroll = getPageScroll();
			var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
			var lightboxLeft = arrayPageScroll[0];

			Element.setTop('framebox', lightboxTop);
			Element.setLeft('framebox', lightboxLeft);

			Element.show('framebox');

		},

		hide : function (nodeId) {
			var boxdiv = $('framebox');
			var objBody = document.getElementsByTagName("body").item(0);

			if (boxdiv != null) {
				boxdiv.style.display='none';
				objBody.removeChild(boxdiv);
				objBody.removeChild($('overlay'));
			};
			this.activeBox = false;
		},

		init: function (node, nodeId, textNode, width, alertText, btnText) {
			if(this.activeBox) return;

			//alert( "W=" + Element.getWidth(textNode) + ", H="+ Element.getHeight(textNode) );
			var objBody = document.getElementsByTagName("body").item(0);
			if(!$('overlay')) {
				var objOverlay = document.createElement("div");
				objOverlay.setAttribute('id','overlay');
				objOverlay.style.display = 'none';
				objBody.appendChild(objOverlay);
			}

			var objFramebox = document.createElement("div");
			objFramebox.setAttribute('id','framebox');
			objFramebox.style.display = 'none';
			objFramebox.innerHTML = '<div id="outerImageContainer" style="width:'+ width +'px;">'+
									' <div class="suggestBox" id="'+ nodeId +'">'+
									'  <div class="head">'+
									'   <div class="button" onclick="enws.textSuggest.setText(\''+ nodeId +'\', \''+ textNode + '\', \''+ alertText + '\')" style="cursor:pointer;float:left;"><span>'+ btnText +'</span></div>'+
									'   <img src="/images/icons/close.gif" onclick="enws.textSuggest.hide(\''+ nodeId +'\');" style="cursor:pointer; float:right;"/>'+
									'   <div class="clear"><img src="/images/spacer.gif" height="1" width="1" border="0" alt="space" /></div>'+
									'  </div>'+
									'  <div class="text">'+ $(textNode).innerHTML +'</div>'+
									' </div>'+
									'</div>';

			objBody.appendChild(objFramebox);

			//boxdiv.className = "suggestBox";
			//boxdiv.setAttribute('id', nodeId);
			//boxdiv.style.display = 'block';
			//boxdiv.style.position = 'absolute';
			//objFramebox.style.height = 400 + 'px';

			//document.body.appendChild(boxdiv);
			//$('mfContentMainParsys').appendChild(boxdiv);
			this.start();
			this.activeBox = nodeId;
			return false;
		},

		setText: function(nodeId, textNode, alertText) {

			var check = true;
			var oldText = tinyMCE.activeEditor.getContent();
			var newText = $(textNode).innerHTML;

			if(oldText.length > 0) check = confirm(alertText);
			if(check) tinyMCE.activeEditor.setContent(newText);

			this.hide(nodeId);
		}
	},

	hasClass: function(node, classStr){
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		return ((" "+$(node).className+" ").indexOf(" "+classStr+" ") >= 0);
	},

	addClass: function(node, classStr){
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		node = $(node);
		var cls = node.className;
		if((" "+cls+" ").indexOf(" "+classStr+" ") < 0){
			node.className = cls + (cls ? ' ' : '') + classStr;
		}
	},

	removeClass: function(node, classStr) {
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		var t = enws.trim((" " + node.className + " ").replace(" " + classStr + " ", " "));
		if(node.className != t){ node.className = t; }
	},

	trim: function(str){
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	// String
	}


};



var Bad = {
	plainShopUserId: "plainShopUserId",
	plainShopUserName: "plainShopUserName",
	shopUserId: "shopUserId",
	shopUserName: "shopUserName",

	jumpToPdPortal: function(formObject){
		if(formObject){
			var userId =   formObject[Bad.plainShopUserId].value;
			var userName = formObject[Bad.plainShopUserName].value;
			formObject[Bad.shopUserId].value = Bad.encryptAndEncode(userId);
			formObject[Bad.shopUserName].value = Bad.encryptAndEncode(userName);
			formObject.submit();
		} else {
			alert("No form given!");
		}
	},
	linkToPdPortal: function(link, userId, userName){
		var form = Bad.createForm(link);
		form[Bad.shopUserId].value = Bad.encryptAndEncode(userId);
		form[Bad.shopUserName].value = Bad.encryptAndEncode(userName);
		document.body.appendChild(form);
		form.submit();
		document.body.removeChild(form);
		return false;
	},
	createForm: function(link){
		var form = document.createElement('form');
		form.method="post";
		form.action = link.href;
		form.target = "_blank";
		var html = "<input type='hidden' name='" + Bad.shopUserId + "'><input type='hidden' name='" + Bad.shopUserName + "'>";
		form.innerHTML = html;
		return form;
	},
	encryptAndEncode: function(value){
		var encrypted = Bad.Tea.encrypt(value);
		return  Bad.Base64.encode(encrypted);
	},

	Tea: {
		defaultPassphrase : "dWDLFcAs0KB5eCyO",
		encrypt : function (plaintext, password) { if(!password) password = this.defaultPassphrase; var v = new Array(2), k = new Array(4), s = "", i; plaintext = escape(plaintext); for (i=0; i<4; i++) k[i] = this.Str4ToLong(password.slice(i*4,(i+1)*4)); for (i=0; i<plaintext.length; i+=8) { v[0] = this.Str4ToLong(plaintext.slice(i,i+4)); v[1] = this.Str4ToLong(plaintext.slice(i+4,i+8)); this.code(v, k); s += this.LongToStr4(v[0]) + this.LongToStr4(v[1]); } return this.escCtrlCh(s); },
		decrypt: function (ciphertext, password) { if(!password) password = this.defaultPassphrase; var v = new Array(2), k = new Array(4), s = "", i; for (i=0; i<4; i++) k[i] = this.Str4ToLong(password.slice(i*4,(i+1)*4)); ciphertext = this.unescCtrlCh(ciphertext); for (i=0; i<ciphertext.length; i+=8) { v[0] = this.Str4ToLong(ciphertext.slice(i,i+4)); v[1] = this.Str4ToLong(ciphertext.slice(i+4,i+8)); this.decode(v, k); s += this.LongToStr4(v[0]) + this.LongToStr4(v[1]); } s = s.replace(/\0+$/, ''); return unescape(s); },
		code: function (v, k) { var y = v[0], z = v[1], delta = 0x9E3779B9, limit = delta*32, sum = 0; while (sum != limit) { y += (z<<4 ^ z>>>5)+z ^ sum+k[sum & 3]; sum += delta; z += (y<<4 ^ y>>>5)+y ^ sum+k[sum>>>11 & 3]; } v[0] = y; v[1] = z; },
		decode: function (v, k) { var y = v[0], z = v[1], delta = 0x9E3779B9, sum = delta*32; while (sum != 0) { z -= (y<<4 ^ y>>>5)+y ^ sum+k[sum>>>11 & 3]; sum -= delta; y -= (z<<4 ^ z>>>5)+z ^ sum+k[sum & 3]; } v[0] = y; v[1] = z; },
		Str4ToLong: function (s) { var v = 0; for (var i=0; i<4; i++) v |= s.charCodeAt(i) << i*8; return isNaN(v) ? 0 : v; },
		LongToStr4: function (v) { var s = String.fromCharCode(v & 0xFF, v>>8 & 0xFF, v>>16 & 0xFF, v>>24 & 0xFF); return s; },
		escCtrlCh: function (str) { return str.replace(/[\0\t\n\v\f\r\xa0'"!]/g, function(c) { return '!' + c.charCodeAt(0) + '!'; }); },
		unescCtrlCh: function (str) { return str.replace(/!\d\d?\d?!/g, function(c) { return String.fromCharCode(c.slice(1,-1)); }); }
	},

	Base64: {
		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
		encodeUtf8: function (input){ input = this._utf8_encode(input); return this.encode(input); },
		encode: function (input) { var output = "", chr1, chr2, chr3, enc1, enc2, enc3, enc4, 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 + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } while (i < input.length); return output; },
		decodeUtf8: function (input){ output =  this.decode(input); return this._utf8_decode(output); },
		decode : function (input) { var output = "", chr1, chr2, chr3,enc1, enc2, enc3, enc4, i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._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); } return output; },
		_utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); }} return utftext; },
		_utf8_decode : function (utftext) { var string = "", i = 0, c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3;}} return string; }
	}
};

var payTerminal = false;
var saferpayTerminal = {
	openPopupTerminal: function () {
		payTerminal = window.open("/"+ jsLANG +"/saferpay/start.html", "payTerminal", "width=600,height=400");
		window.setTimeout('saferpayTerminal.checkPopup()', 500);
	},

	closePopupTerminal: function(pay, close) {
		enws.checkOut.payCard = pay;
		payTerminal.close();
		if(pay) enws.checkOut.payMethod('OK');
	},
	checkPopup: function() {
		if(!payTerminal) { alert(enws.msgs[jsLANG].noPopup); new Effect.Fade('overlay', { duration: overlayDuration});}
		else window.setTimeout('enws.checkOut.terminalCheck()', 1000);
	}

};

