function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

// laurin
function clearLrnTitle(lrnTitle) {
	aSEARCH = new Array('\\xa0','\\xae','&reg;','%','®','\\.','Ä','Ö','Ü','ä','ö','ü','ß','`','´','&nbsp;','&', '\\x3f','<i>','<\\/i>','<b>','<\\/b>','<I>','<\\/I>','<B>','<\\/B>', '\\/', '<br>', '<BR>','  ', ' ', '___', '__','\\xa0','\\(','\\)');
	aREPLACE = new Array('','','','','','','Ae','Oe','Ue','ae','oe','ue','ss','','','_','_', '', '', '', '', '', '','','','','_','_','_','_','_','_','_','_','_','_');

	for (a=0; a<aSEARCH.length; a++) {
		eval('lrnTitle = lrnTitle.replace(/'+aSEARCH[a]+'/g, "'+aREPLACE[a]+'");');
	}
	return lrnTitle;
}

function elwin(elwinID,elwinW,elwinH,elwinURL,elwinOptions) {
	o = new Array();
	// DEFINE DEFAULTS
	o['r'] = 'no'; // resizable = no
	o['s'] = 'no'; // scrollbars = no
	if (elwinOptions == 's') {
		for (c=0; c<elwinOptions.length; c++) {
			o[elwinOptions.charAt(c)] = 'yes';
		}
	}
	elWindow=window.open(elwinURL,'elwindow'+elwinID,'width='+elwinW+',height='+elwinH+',resizable='+o['r']+',scrollbars='+o['s']);
	elWindow.focus();
}

function scaleup(scaleupID,scaleupW,scaleupH,scaleupURL,scaleupOptions) {
	o = new Array();
	// DEFINE DEFAULTS
	o['r'] = 'yes'; // resizable = no
	o['s'] = 'no'; // scrollbars = no
	if (scaleupOptions == 's') {
		for (c=0; c<scaleupOptions.length; c++) {
			o[scaleupOptions.charAt(c)] = 'yes';
		}
	}
	scaleupWindow=window.open(scaleupURL,'scaleupwindow'+scaleupID,'width='+scaleupW+',height='+scaleupH+',resizable='+o['r']+',scrollbars='+o['s']);
	scaleupWindow.focus();
}

function slideInElwin(elwinID,elwinW,elwinH,elwinURL) {
	elWindow=window.open(elwinURL,'elwindow'+elwinID,'width='+elwinW+',height='+elwinH+',resizable=yes,scrollbars=no');
	elWindow.focus();
}

function printPage(printUrl) {
	window.print();
}

function tellafriend(id) {
	mailWin=window.open('/index.php?fuseaction=tellafriend&pid='+id,'mailWindow','width=480, height=480,resizable=yes,scrollbars=yes');
}

function glossary(showHide,gURL) {
	gwin=window.open(gURL,'gwin','width=480, height=360,resizable=yes,scrollbars=yes');
	gwin.focus();
}


// Browser Check
function browserCheck() {
	UA = new Array();
	browserPlatform = navigator.platform;
	ua = navigator.userAgent;
	an = navigator.appName;
	ua = ua.toLowerCase();
	ua_msie = ua.indexOf('msie');
	ua_netscape = ua.indexOf('netscape');
	ua_mozilla = ua.indexOf('mozilla');
	ua_opera = ua.indexOf('opera');
	ua_firefox = ua.indexOf('firefox');
	userAgent = 'other';
	if (ua_msie != -1 && ua_opera == -1) userAgent = 'MSIE';
	if (ua_opera != -1) userAgent = 'Opera';
	if (ua_firefox != -1) userAgent = 'Firefox';
	if (ua_msie == -1 && ua_opera == -1 && ua_firefox == -1) {
		userAgent = 'Mozilla';
		browserVersion = parseFloat(ua.substr(8, 4));
		if (browserVersion >= 5) { // Netscape 6 or higher
			pos = ua.indexOf('netscape');
			if (pos != -1) browserVersion = parseFloat(ua.substr(pos+9, 4));
		}
	}
	if (userAgent == 'MSIE') browserVersion = parseFloat(ua.substr(ua_msie + 5, 5));
	if (userAgent == 'Opera') browserVersion = parseFloat(ua.substr(ua_opera + 6, 4));
	if (userAgent == 'Firefox') browserVersion = parseFloat(ua.substr(ua_opera + 7, 4));
	UA[0] = userAgent;
	UA[1] = browserVersion;
	UA[2] = browserPlatform;
	return UA;
}
userAgent = browserCheck();





/**
 * catalog.js
 */

//Warenkorb

function delItem(pid) {
	document.forms["cartform"].elements["delFromCart"].value = pid;
	document.forms["cartform"].submit();
}
function calcnew() {
	document.forms["cartform"].submit();
}
function checkout( target ) {
	document.forms["cartform"].action = target;
	document.forms["cartform"].submit();
}

//function checkValue(old,anzahl) {
//	if (anzahl.value < 0){
//		alert("Die Mindestbestellmenge beträgt 1  Stück");
//		anzahl.value = old;
//	}
//}

// Adresseingabe

function submitaddress() {
	document.forms["cartaddressform"].submit();
}

function reqData(reqF) {
	if (reqF.type == "text" || reqF.type == "password" || reqF.type == "textarea") {
		if (reqF.value.length == 0){return false;}
		else {return true;}
	} else if (reqF.type == "select" || reqF.type == "select-one") {
		for (i=0;i<reqF.length;i++) {
			if (reqF[i].selected && reqF[i].value != ""){return true;}
		}
		return false;
	} else if (reqF[0].type == "radio" || reqF[0].type == "checkbox") {
		for (i=0;i<reqF.length;i++) {
			if (reqF[i].checked){return true;}
		}
		return false;
	}
}

function valData(valF,valRegExp) {
	if (valF.type == "text" || valF.type == "password") {
		var pattern = new RegExp(valRegExp);
		return pattern.test(valF.value);
	}
}

function addressCheck() {
	if (document.forms["cartaddressform"].elements["up_login"]) {
		if (document.forms["cartaddressform"].elements["up_login"].value != '' && document.forms["cartaddressform"].elements["up_passwort"].value == '') {
			alert ("Bitte wählen Sie ein Passwort aus.");
			return false;
		}
		if (document.forms["cartaddressform"].elements["up_passwort"].value != document.forms["cartaddressform"].elements["passwort2"].value) {
			alert ("Die Passwörter sind nicht identisch.");
			return false;
		}
	}
	for (var i=0;i<document.forms["cartaddressform"].elements.length;i++) {
		frmFld=document.forms["cartaddressform"].elements[i]
		if (frmFld.name.search(/_lrnRequired/) != -1) {
			reqFld=document.forms["cartaddressform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnRequired/))];
			if (!reqFld) { // php-bug
				reqFld=document.forms["cartaddressform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnRequired/))+"[]"];
			}
			// Lieferadresse nur, wenn "separate Lieferadresse" angeklickt
			if (reqFld.name.search(/_lieferadresse/) != -1) {
				if (document.forms["cartaddressform"].elements["showdelivery"].checked) {
					if (!reqData(reqFld)) {
						alert(frmFld.value);
						return false;
					}
				}
			// Ende Lieferadresse
			} else {
				if (!reqData(reqFld)) {
					alert(frmFld.value);
					return false;
				}
			}
		}
		if (frmFld.name.search(/_lrnValidate/) != -1) {
			valFld=document.forms["cartaddressform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnValidate/))];
			if (valFld.value != "") {
				// Lieferadresse nur, wenn "separate Lieferadresse" angeklickt
				if (frmFld.name.search(/_lieferadresse/) != -1) {
					if (document.forms["cartaddressform"].elements["showdelivery"].checked) {
						if (!valData(valFld,frmFld.value)) {
							alert(document.forms["cartaddressform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnValidate/))+"_lrnVText"].value);
							return false;
						}
					}
				// Ende Lieferadresse
				} else {
					if (!valData(valFld,frmFld.value)) {
						alert(document.forms["cartaddressform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnValidate/))+"_lrnVText"].value);
						return false;
					}
				}
			}
		}
	}

}

function checkValue(amount,pid) {

 	wert = document.getElementById(pid).value;
 	if (wert < 0 || isNaN(wert)) {
 		alert("Die Mindestbestellmenge beträgt 1 Stück.");
 		document.forms['cartform'].elements['anzahl['+pid+']'].value = amount;
 	}

}

// Zusammenfassung / Zahlungsinformationen

function submitsummary() {
	document.forms["cartorderform"].submit();
}
function agbCheck(theform) {
	if (document.forms[theform].cart4.value != '' && document.forms[theform].coupon_code.value == '') {
		if (document.forms["cartorderform"].ca_zahlungsart.value == 0) {
			alert("Bitte wählen Sie eine Zahlungsart.");
			document.forms["cartorderform"].ca_zahlungsart.focus();
			return false;
		}
		if (document.forms["cartorderform"].acceptAGB.checked == false) {
			alert("Sie müssen unsere AGBs akzeptieren, damit wir Ihre Bestellung bearbeiten können.");
			return false;
		}
	}
	document.getElementById('orderSubmitButton').style.visibility = 'hidden';
}

// Produktlisten / Details

function order(pid,min,orderform) {
	if (typeof(orderform) == "undefined")
		orderform = "orderform";
	anz = document.forms[orderform].elements["anzahl_"+pid].value;
	if (document.forms[orderform].elements["anzahl2_"+pid]) {
		anz2 = document.forms[orderform].elements["anzahl2_"+pid].value;
		if (anz2 > anz) anz = anz2
	}
	if (anz < min) {
		alert('Die Mindestbestellmenge beträgt '+min+' Stück.');
	} else {
		document.forms[orderform].elements["add2cart"].value = pid;
		document.forms[orderform].elements["amount"].value = anz;
		document.forms[orderform].submit();
	}
}

function remember(pid,orderform) {
	document.forms[orderform].elements["add2favorites"].value = pid;
	document.forms[orderform].submit();
}

function delMiniItem(pid) {
	document.forms["minicartform"].elements["delFromCart"].value = pid;
	document.forms["minicartform"].submit();
}

function delFavorite(pid) {
	document.forms["favoritesform"].elements["delFromFavorites"].value = pid;
	document.forms["favoritesform"].submit();
}

function delMiniFavorite(pid) {
	document.forms["minifavoritesform"].elements["delFromFavorites"].value = pid;
	document.forms["minifavoritesform"].submit();
}

// Userprofile

function feedbackCheck() {
	if (document.forms["profileform"].elements["up_passwort"].value != document.forms["profileform"].elements["passwort2"].value  
	    && document.forms["profileform"].elements["checkISP"].value != 1){
		alert ("Die Passwörter sind nicht identisch.");
		return false;
	}else
	 if (document.forms["profileform"].elements["up_passwort"].value != document.forms["profileform"].elements["passwort2"].value  
	    && document.forms["profileform"].elements["checkISP"].value == 1){
	    alert ("Passwords are not equal");
		return false;	
	 }
	for (var i=0;i<document.forms["profileform"].elements.length;i++) {
		frmFld=document.forms["profileform"].elements[i]
		if (frmFld.name.search(/_lrnRequired/) != -1) {
			reqFld=document.forms["profileform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnRequired/))];
			if (!reqFld) { // php-bug
				reqFld=document.forms["profileform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnRequired/))+"[]"];
			}
			if (!reqData(reqFld)) {
				alert(frmFld.value);
				return false;
			}
		}
		if (frmFld.name.search(/_lrnValidate/) != -1) {
			valFld=document.forms["profileform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnValidate/))];
			if (valFld.value != "") {

				if (!valData(valFld,frmFld.value)) {
					alert(document.forms["profileform"].elements[frmFld.name.slice(0,frmFld.name.search(/_lrnValidate/))+"_lrnVText"].value);
					return false;
				}
			}
		}
	}
}

// ---------------------------------------------------
// PHYWE-Funktionen

var moreImagesEnable = function() {
	var moImages = jQuery('.moreimages a');
	moImages.click( function() {
		jQuery('.bigimage img').attr('src', this.href);
		return false;
	});
}

jQuery(document).ready( function() {
	/** @link http://jquery.andreaseberhard.de/pngFix/ **/
	jQuery("#text").pngFix();

	/** @link http://newism.com.au/blog/post/58/bigtarget-js-increasing-the-size-of-clickable-targets/ **/
	if (! (jQuery.browser.msie && jQuery.browser.version == '6.0.0'))
		jQuery('a.mehr-link').bigTarget();
	
	jQuery('.boxheadline h4 a').bigTarget();

	/** Produktbilder **/
	moreImagesEnable();
	
	/** Suchfunktionen untereinander verlinken **/
	var LRN_SHOPSEARCH = jQuery('#lrn_shopsearch_advanced');
	var LRN_TEXTSEARCH = jQuery('form[name^="lrn_search"]');

	if (document.location.search) {
		var match = document.location.search.match(/query=([^&]+)/);
		var query = "";
		if (match && match[1]) {
			query = match[1];
			query = unescape(query.toString());
			LRN_SHOPSEARCH.find('input[name="q"]').val(query);
			LRN_TEXTSEARCH.find('input[name="q"]').val(query);
		}
	}
	if (LRN_SHOPSEARCH.length || LRN_TEXTSEARCH.length) {
		var searchform = LRN_SHOPSEARCH.length ? LRN_SHOPSEARCH : LRN_TEXTSEARCH;
		var query = searchform.find('input[name="q"]').val();
		jQuery('.search_tabs_a, .search_tabs_n').each(function() {
			var anchor = jQuery(this).find("a");
			anchor.attr('href', anchor.attr('href') + '?query=' + escape(query));
		});
	}
	
	jQuery('.lrn-feedback').each(function(){
		jQuery(this).find('input[name^="Preis"]').each(function(){
			var preis = parseFloat(jQuery(this).val());
			jQuery(this).parent().parent().find('[name^="Menge"]').keyup( function() {
				  var menge = parseInt(jQuery(this).val());
				  if(menge > 0 && !isNaN(menge)){
					  var zeile = preis * menge;
					  var zeilen_inhalt = '<input type="hidden" name="zeile[]" value="' + zeile + '" />'+kaufm(zeile);
					  jQuery(this).parent().parent().find('td:last').html(zeilen_inhalt);
				  }else{
					  jQuery(this).parent().parent().find('td:last').html('');
				  }
				  
				  var gesamt = 0;
				  jQuery('input[name^="zeile"]').each(function(){
					  gesamt += parseFloat(jQuery(this).val());
				  });
				  gesamt += parseFloat(jQuery('input[name^="Preis Versand"]').val());
				  jQuery(this).parents('table').find('tr:last td:last').html('<strong>'+kaufm(gesamt)+'</strong>');
			});
		});
	});
	
	function kaufm(x) {
		  var k = (Math.round(x * 100) / 100).toString();
		  k += (k.indexOf('.') == -1)? '.00' : '00';
		  var p = k.indexOf('.');
		  return k.substring(0, p) + ',' + k.substring(p+1, p+3);
	}
	
	(function(b){b.snowfall=function(a,d){function s(c,f,g,h,j){this.id=j;this.x=c;this.y=f;this.size=g;this.speed=h;this.step=0;this.stepSize=e(1,10)/100;if(d.collection)this.target=m[e(0,m.length-1)];c=b(document.createElement("div")).attr({"class":"snowfall-flakes",id:"flake-"+this.id}).css({width:this.size,height:this.size,background:d.flakeColor,position:"absolute",top:this.y,left:this.x,fontSize:0,zIndex:d.flakeIndex});b(a).get(0).tagName===b(document).get(0).tagName?(b("body").append(c),a=b("body")):
	b(a).append(c);this.element=document.getElementById("flake-"+this.id);this.update=function(){this.y+=this.speed;this.y>n-(this.size+6)&&this.reset();this.element.style.top=this.y+"px";this.element.style.left=this.x+"px";this.step+=this.stepSize;this.x+=Math.cos(this.step);if(d.collection&&this.x>this.target.x&&this.x<this.target.width+this.target.x&&this.y>this.target.y&&this.y<this.target.height+this.target.y){var b=this.target.element.getContext("2d"),c=this.x-this.target.x,a=this.y-this.target.y,
	e=this.target.colData;if(e[parseInt(c)][parseInt(a+this.speed+this.size)]!==void 0||a+this.speed+this.size>this.target.height)if(a+this.speed+this.size>this.target.height){for(;a+this.speed+this.size>this.target.height&&this.speed>0;)this.speed*=0.5;b.fillStyle="#fff";e[parseInt(c)][parseInt(a+this.speed+this.size)]==void 0?(e[parseInt(c)][parseInt(a+this.speed+this.size)]=1,b.fillRect(c,a+this.speed+this.size,this.size,this.size)):(e[parseInt(c)][parseInt(a+this.speed)]=1,b.fillRect(c,a+this.speed,
	this.size,this.size));this.reset()}else this.speed=1,this.stepSize=0,parseInt(c)+1<this.target.width&&e[parseInt(c)+1][parseInt(a)+1]==void 0?this.x++:parseInt(c)-1>0&&e[parseInt(c)-1][parseInt(a)+1]==void 0?this.x--:(b.fillStyle="#fff",b.fillRect(c,a,this.size,this.size),e[parseInt(c)][parseInt(a)]=1,this.reset())}(this.x>l-i||this.x<i)&&this.reset()};this.reset=function(){this.y=0;this.x=e(i,l-i);this.stepSize=e(1,10)/100;this.size=e(d.minSize*100,d.maxSize*100)/100;this.speed=e(d.minSpeed,d.maxSpeed)}}
	function p(){for(c=0;c<j.length;c+=1)j[c].update();q=setTimeout(function(){p()},30)}var d=b.extend({flakeCount:35,flakeColor:"#ffffff",flakeIndex:999999,minSize:1,maxSize:2,minSpeed:1,maxSpeed:5,round:false,shadow:false,collection:false,collectionHeight:40},d),e=function(b,a){return Math.round(b+Math.random()*(a-b))};b(a).data("snowfall",this);var j=[],f=0,c=0,n=b(a).height(),l=b(a).width(),i=0,q=0;if(d.collection!==false)if(f=document.createElement("canvas"),f.getContext&&f.getContext("2d"))for(var m=
	[],f=b(d.collection),k=d.collectionHeight,c=0;c<f.length;c++){var g=f[c].getBoundingClientRect(),h=document.createElement("canvas"),r=[];if(g.top-k>0){document.body.appendChild(h);h.style.position="absolute";h.height=k;h.width=g.width;h.style.left=g.left;h.style.top=g.top-k;for(var o=0;o<g.width;o++)r[o]=[];m.push({element:h,x:g.left,y:g.top-k,width:g.width,height:k,colData:r})}}else d.collection=false;b(a).get(0).tagName===b(document).get(0).tagName&&(i=25);b(window).bind("resize",function(){n=b(a).height();
	l=b(a).width()});for(c=0;c<d.flakeCount;c+=1)f=j.length,j.push(new s(e(i,l-i),e(0,n),e(d.minSize*100,d.maxSize*100)/100,e(d.minSpeed,d.maxSpeed),f));d.round&&b(".snowfall-flakes").css({"-moz-border-radius":d.maxSize,"-webkit-border-radius":d.maxSize,"border-radius":d.maxSize});d.shadow&&b(".snowfall-flakes").css({"-moz-box-shadow":"1px 1px 1px #555","-webkit-box-shadow":"1px 1px 1px #555","box-shadow":"1px 1px 1px #555"});p();this.clear=function(){b(a).children(".snowfall-flakes").remove();j=[];clearTimeout(q)}};
	b.fn.snowfall=function(a){if(typeof a=="object"||a==void 0)return this.each(function(){new b.snowfall(this,a)});else if(typeof a=="string")return this.each(function(){var a=b(this).data("snowfall");a&&a.clear()})}})(jQuery);
	
	$('#lrn-bi-1829').snowfall({
	flakeCount:120,flakeColor:'#FFFFFF',flakeIndex:999999,minSize:1,maxSize:4,round:true
	});
});
