document.charset="utf-8";
var oe=function(Fehler,Datei,Zeile){alert('Es ist der JS- Fehler: '+Fehler+', in der Datei: '+Datei+', in der Zeile: '+Zeile+'Aufgetreten.');};
var oe2=function(){return true;};
window.onerror=oe2;// Wenn Projekt fertig, bitte auf oe2 setzen. Mit der Funktion oe wird das errorhandlich auf "scharf" gestellt. und fehler werden als alerts ausgegeben
window.opera = window.opera;
window.$GLOBALS = {};
$GLOBALS.hiddens = [];
$GLOBALS.leasingAllowed = false;
$GLOBALS.tmr = null;
$GLOBALS.maxArrays = [];
$GLOBALS.IE = false;
$GLOBALS.IE6 = false;
$GLOBALS.IE7 = false;
$GLOBALS.IE8 = false;
if(navigator.appVersion.match(/MSIE/)&&!navigator.appVersion.match(/Macintosh/)&&!opera&&!navigator.appVersion.match(/Konqueror/)){
	$GLOBALS.IE=true;
	if(navigator.appVersion.match(/MSIE 6/))$GLOBALS.IE6 = true;
	if(navigator.appVersion.match(/MSIE 7/))$GLOBALS.IE7 = true;
	if(navigator.appVersion.match(/MSIE 8/))$GLOBALS.IE8 = true;
}
function _(id, Doc) {
	return typeof id == 'string' ? (Doc||document).getElementById(id) : id == 'object' ? id : null;
};
var _T = function(Tag,Parent)
{// TOM:: Hiermit zieht man bestimmte tags als Objekte, auch mit Angabe eines bestimmten Parents möglich
	Tag=Tag?Tag:'*';
	return ((Tag=='*') && !document.getElementsByTagName('*').length)?(Parent||document).all:(Parent||document).getElementsByTagName(Tag);
}
var _C = function(className, Tag)
{// TOM:: Hiermit zieht man alle tags mit einem bestimmten className als Objekte, auch mit Angabe eines bestimmten Tags möglich
    var muster = new RegExp("(^| )" + className + "($| )");
    var alles = _T();
    var gefunden = [];
	for(i=0;i<alles.length;i++){
		if (alles[i].tagName && (alles[i].tagName.toLowerCase() == Tag) && alles[i].className && (alles[i].className != "")) {
            if (alles[i].className.match(muster)) {
                gefunden[gefunden.length] = alles[i];
			}
        }
	}
    return gefunden;
};
function _A(Obj)
{
	// TOM:: Hiermit konvertiert man zu einem Array, zB aus nem Objectrange ein Array machen, damit man alle funktionen eines Arrays sicher anwenden kann..
	var ret = [];
	for(var i=0;i<Obj.length;i++){
		ret[i] = Obj[i];
	}
	return ret;
}
function makeHiddenField(Form,Name,Value){
	if(_(Name)){
		var myHidd = _(Name);
	}
	else{
		var myHidd=Form.appendChild($GLOBALS.IE==true?document.createElement('<INPUT TYPE=HIDDEN />'):document.createElement('input'));
		if(!$GLOBALS.IE){
			myHidd.setAttribute('type','hidden');
		}
		myHidd.id=Name;
		myHidd.name=Name;
	}
	myHidd.value=Value;
}
function openCenteredWindow(url, n, w, h) {
	var l = (screen.availWidth / 2) - (w / 2);
	var t = (screen.availHeight / 2) - (h / 2);
	return openWindow(url, n, w, h, l, t);
};
function openWindow(url, n, w, h, l, t, s) {
	if(l == undefined) l = 200;
	if(t == undefined) t = 100;
    if(s == undefined) s = 'no';

	var params = new Array();

	if(w > 0) params.push('width='  + w);
	if(h > 0) params.push('height=' + h);
	params.push('left=' + l);
	params.push('top='  + t);

	params.push('location=no');
	params.push('statusbar=no');
	params.push('scrollbars=' + s);
	return window.open(url, n+ Math.round(Math.random() * 100000), params.join(','));
};
// Bestellformular abschicken
function send_form(id, action, target)
{
	$(id).value = action;
	var frm = $(id).form;
	if(target != undefined) {
		frm.action = target;
	}
	if(typeof frm.onsubmit == 'function')frm.onsubmit();else frm.submit();
};
// Lieferadresse ausgrauen	#1
function disable()
{
if (_('CheckoutUseBillingAddress').checked)
	{
	_('ShippingAddressSalutation').disabled=true;
	_('ShippingAddressForename').disabled=true;
	_('ShippingAddressSurname').disabled=true;
	_('ShippingAddressStreet').disabled=true;
	_('ShippingAddressStreetNr').disabled=true;
	_('ShippingAddressZipcode').disabled=true;
	_('ShippingAddressCity').disabled=true;
	_('ShippingAddressCountry').disabled=true;
	}
else
	{
	_('ShippingAddressSalutation').disabled=false;
	_('ShippingAddressForename').disabled=false;
	_('ShippingAddressSurname').disabled=false;
	_('ShippingAddressStreet').disabled=false;
	_('ShippingAddressStreetNr').disabled=false;
	_('ShippingAddressZipcode').disabled=false;
	_('ShippingAddressCity').disabled=false;
	_('ShippingAddressCountry').disabled=false;
	}
};
// Lieferadresse ausgrauen #2
function disable_update()
{
	_('ShippingAddressSalutation').disabled=true;
	_('ShippingAddressForename').disabled=true;
	_('ShippingAddressSurname').disabled=true;
	_('ShippingAddressStreet').disabled=true;
	_('ShippingAddressStreetNr').disabled=true;
	_('ShippingAddressZipcode').disabled=true;
	_('ShippingAddressCity').disabled=true;
	_('ShippingAddressCountry').disabled=true;
};
// Produktansicht: Bild austauschen
function swap(id, fullsizeWidth, fullsizeHeight, zoomWidth, zoomHeight)
{
	_('fullsizeImage').src = '/images/' + id + '/' + fullsizeWidth + 'x' + fullsizeHeight + '.jpg';
};
function swapProductImage(productId, imageName, fileId, zoomWidth, zoomHeight, fullsizeWidth, fullsizeHeight)
{
    _('fullsizeImage').src = '/images/' + fileId + '/' + fullsizeWidth + 'x' + fullsizeHeight + '.jpg';
    func = new Function('openCenteredWindow(\'/pages/productImagePopup/' + productId + '/' + imageName + '\', \'ProductImagePopup\', ' + zoomWidth + ', ' + zoomHeight + ');return false;');
    _('fullsizeLink1').onclick = func;
    //_('fullsizeLink2').onclick = func;
};
// Produktansicht: Bild aufpoppen
function zoom(id, width, height)
{
	window.open('/images/' + id + '/' + width + 'x' + height + '.jpg', 'PopUp', 'left=300, top=50,width=' + width + ',height=' + height + ',status=no,scrollbars=no,resizable=yes');
};
// IE form submit ohne submit-Button fixen und für alle anderen ohne submit UND ohne image Button, wobei Textarea ein
// Return haben darf und es wird geschaut, ob es ein form onsubmit="... gibt, wenn ja wird dann dieser auch ausgeführt
// ...und das auch für die Beriche, wo kein Mootools eingebunden ist, die  wir langsam nach und nach entfernen sollten.
function addInputSubmitEvent(form) {
    if($GLOBALS.IE){    
        form.onkeydown = function(e) {
            e = window.event;
            if (e.keyCode == 13) {
            	if(e.srcElement.tagName == 'TEXTAREA'){
            		return true;
            	}
                if(typeof form.onsubmit == 'function')form.onsubmit(); else form.submit();
                return false;
            }
        };
    }
    else{
    	form.onkeydown = function(e) {
            if (e.keyCode == 13) {
            	if(e.target.tagName == 'TEXTAREA'){
            		return true;
            	}
		    	var is_submit_tag = false;
		    	for(var i=0;i<_A(form.elements).length;i++){
		    		var El = _A(form.elements)[i];
		    		if((El.type == 'image') || (El.type == 'submit')){
		    			is_submit_tag = true;
		    		}
		    	}
		    	if(!is_submit_tag){
		    		if(typeof form.onsubmit == 'function')form.onsubmit(); else form.submit();
		    		return false;
		    	}
            }
    	};
    }
};
function str2float(num)
{// TOM:: hat die gleich Funktionalität wie die UserIO::str2float, nur js seitig
	num = num + '';
	return num.indexOf(',') != -1 ? num.replace(/\./g,'').replace(',','.') * 1 : num * 1;
}
function float2str(num)
{// TOM:: hat die gleich Funktionalität wie die UserIO::float2str, nur js seitig
	num+= '';
	if(num.indexOf(',') != -1 ) return num;
	num*=1;
	num = num.toFixed(2);
	num+= '';
	var num2 = num.substr(num.length-2);
	var num1 = num.substring(0,num.length-3);
	var ctr = 0;
	var num3 = '';
	for(var i=num1.length-1;i>=0;i--){
		ctr++;
		num3+=num1.substr(i,1);
		if(ctr%3==0 && i>0){
			num3+='.';
		}
	}
	num1 = '';
	for(i=num3.length-1;i>=0;i--){
		num1+=num3.substr(i,1);
	}
	return num1 + ',' + num2;
}
/*position of the tooltip relative to the mouse in pixel */
var offsetx = 20;
var offsety = 8;
function newelement(newid)
{
    if(document.createElement)
    {
        var el = document.createElement('div');
        el.id = newid;
        with(el.style)
        {
            display = 'none';
            position = 'absolute';
        }
        el.innerHTML = '&nbsp;';
        document.body.appendChild(el);
    }
};
var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode &&
        document.compatMode != 'BackCompat') ?
        document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = _('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
};
function tooltip(tip)
{
    if(!_('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = _('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
};
function exit()
{
    _('tooltip').style.display = 'none';
};
function checkAll(formId, fieldName, state) {
    var frm = _(formId);

    var inputs = frm.getElementsByTagName('input');

    for(var i=0; i < inputs.length; i++) {
        var inp = inputs[i];
        if(inp.name != fieldName) continue;

        inp.checked = state;
    }
};

if(window['addEvent'])window.addEvent('domready', function() {
	if($$('div.thumbnails div.image')){
		$GLOBALS.toolTipps = new Tips('div.thumbnails div.image img',{className:'tooltipp3',offset:{y:-170}});
		$GLOBALS.toolTipps.addEvent('show', function(tip, el){
			tip.getElement('div.tip').innerHTML = '<img src="' + el.src.replace('150x150.jpg','526x300.jpg') + '" />';
		});
	}
		
	if($GLOBALS.IE6){
		var url = $('main').getStyle('background-image').replace('url("','').replace('")','');
		$('main').setStyle('background-image','none');
		$('main').setStyle('position','relative');
		var img = new Element('img', {
			'src'		: url,
			styles: {
				'position'  : 'absolute',
				'top'		: '30px',
				'left'		: '0px'
			},
			'width'		: '961',
			'height'	: '120'
		}).inject($('main'));
		img.style.behavior = 'url(/js/iepngfix.htc);';
	}
	var bill = null;
	if($('vat_cont')&& (bill = $('BillingAddressCountry')))bill.addEvent('change',function(event){
		if(bill.options[bill.selectedIndex].value==31){
			$('vat_cont').style.display = 'none';
			$('VatNr').value = '';
		}
		else{
			$('vat_cont').style.display = 'block';
		}
	});
    $each($$('form'),function(Obj){addInputSubmitEvent(Obj);});
    var a = $$('a,input[type="button"],input[type="image"],input[type="submit"],input[type="radio"],input[type="checkbox"]');
    $each(a, function(Obj){
    	Obj.onmousedown = function()
		{
			this.onfocus = function()
			{
				this.blur();
			};
		};
		Obj.onmouseout = function()
		{
			this.onfocus = $empty;
		};
		Obj.onmousemove = Obj.onmouseout;
		Obj.style.cursor = 'pointer';
    });
	if(window['focus_field'])focus_field();

	if($('price') && $priceArray){
		var inp = $$('form#productform input');
		$each(inp,function(Obj){
			if(Obj.getParent('div.konfigurator') && Obj.type != 'text'){
				Obj.onclick = changePrice;
			}
			else if(Obj.getParent('div.konfigurator')){
				Obj.onkeyup = changePrice;
			}
		});
		changePrice(-1);
	}
	if($('productform')){
		$each($$('form#productform div.toggle label'), function (Obj){
			Obj.style.cursor = 'pointer';
			var myFx = new Fx.Slide(Obj.getParent('div').getNext('div'),{duration: 600,transition: Fx.Transitions.Pow.easeOut});
			Obj.getParent('div').onclick = function()
			{
				myFx.toggle();
				this.getElement('label').style.backgroundPosition = myFx.open ? '0 3px' : '0 -30px';
			};
		});
		$each($$('form#productform div.konfigurator span'), function (Obj){
			Obj.style.cursor = 'pointer';
			if((Obj.className != 'price') && (Obj.className != 'hint'))Obj.addEvent('click', function(){
				var check = $(this).getParent('div').getElement('input[type="radio"], input[type="checkbox"]');
				check.checked = check.checked && check.type == 'checkbox' ? false : true;
				check.onclick();
			});
		});
	}
	if($$('div.cart div.box_middle tr ul.main')[0] && $$('div.cart div.box_middle tr td.quantity input')[0]){
		$GLOBALS.myFx = [];
		$each($$('div.cart div.box_middle tr ul.main'), function(Obj,i){
			$GLOBALS.myFx[i] = new Fx.Slide(Obj,{duration: 600,transition: Fx.Transitions.Pow.easeOut});
			if(document.URL.indexOf('cart/popup') === -1)$GLOBALS.myFx[i].hide();
			$this = Obj.getParent('tr').getPrevious('tr.product');
			if($this.getElement('td.description p'))$this.style.cursor = 'pointer';
			$this.addEvent('click', function(event)
			{
				event.stop();
				$GLOBALS.myFx[i].toggle();
			});
			$this.getElement('td.description a').addEvent('click',function(event){
				location.href = this.href;
				event.stop();
			});
			$this.getElements('td.quantity a')[0].addEvent('click',function(event){
				var Inp = $(this).getParent('td').getElement('input[type="text"]');
				if(!Inp.value){
					if(confirm(window['javascript.inputs.really_delete_product'])){
						Inp.value = '0';
						send_form('CartAction', 'update');
					}
					else{
						Inp.value = '1';
					}
				}
				else{
					send_form('CartAction', 'update');
				}
				event.stop();
			});
			$this.getElements('td.quantity a')[1].addEvent('click',function(event){
				if(confirm(window['javascript.inputs.really_delete_product']))location.href=this.href;;
				event.stop();
			});
			$this.getElement('td.quantity input[type="text"]').addEvent('click',function(event){
				event.stop();
			});
		});
	}
	if($$('div.box_middle table.cart ul.side')[0]){
		$GLOBALS.myFx2 = [];
		$GLOBALS.myPrice = [];
		$each($$('div.box_middle table.cart ul.side'), function(Obj,i){
			$GLOBALS.myFx2[i] = new Fx.Slide(Obj,{duration: 600,transition: Fx.Transitions.Pow.easeOut});
			$GLOBALS.myFx2[i].hide();
			if($this = Obj.getParent('td').getElement('strong.group')){
				$this.style.cursor = 'pointer';
				$this.addEvent('click', function(event)
				{
					$GLOBALS.myFx2[i].toggle();
				});
			}
		});
	}
	if($$('div.cart table.cart td.quantity input[type="text"]')[0]){
		$each($$('div.cart table.cart td.quantity input[type="text"]'), function(Inp){
			Inp.addEvent('keyup', function(event){
				if(event.key=='up'){
					this.value = (this.value*1)+1+'';
				}
				if(event.key=='down'){
					this.value = (this.value*1)-1+'';
				}
				if(this.value=='0'){
					this.value = !confirm(window['javascript.inputs.really_delete_product']) ? '1' : '0';
				}
				while(isNaN(this.value.trim()))this.value = this.value.substr(0,this.value.length-1);
			});
		});
	}
	if(window.$tooltipArr){
		$each($tooltipArr, function(o){
			$each($$('div.' + o),function(D){
				D.title = D.title.replace('_pppp_','&#x2B;').replace('_klamuf_','&#x28;').replace('_klamzu_','&#x29;').replace('_nbsp_',' ').replace('_komma_',',').replace('_onquot_',"'").replace(/\_(.*?)\_/g,'&$1;');
			});
			var myTips = new Tips('div.' + o,{className:'tooltipp',offset:{y:-56}});
		});
	}
	if(window.pluginFunc)pluginFunc();
	$GLOBALS.tmr = null;
	$GLOBALS.topPosition = 0;
	$GLOBALS.lastTopPosition = 0;
	var komp = {};
	if(komp = $('komponenten')){
		komp.setStyle('visibility','visible');
		$GLOBALS.offsetX = -18;
		$GLOBALS.offsetY = komp.getStyle('top').toInt() + 183;
		var mover = new Fx.Move(komp);
		$$('body')[0].addEvent('efx.scroll.event', function(){
			var $go = false;
			if(window.getScroll().y > $GLOBALS.offsetY){//-80
				$y = window.getScroll().y;//+80
				$go = true;
			}
			else if(window.getScroll().y < $GLOBALS.offsetY){
				$y = $GLOBALS.offsetY;
				if(komp.getPosition().y != $GLOBALS.offsetY){
					$go = true;
				}
			}
			if($go){
				mover.start({
				    relativeTo: $('container'),
				    position: 'upperRight',
				    edge:'upperRight',
				    offset: {x:$GLOBALS.offsetX,y:$y}
				});
			}
		});
		$$('body')[0].fireEvent('efx.scroll.event');
		window.addEvent('scroll', function(){
			$clear($GLOBALS.tmr);
			$GLOBALS.tmr = (function(){
				$$('body')[0].fireEvent('efx.scroll.event');
			}).delay(400);
		});
	}

	if($$('textarea.freetext')[0]){
		$each($$('textarea.freetext'), function(Txt){
			Txt.addEvent('keyup', function (){
				if(this.value.trim())makeHiddenField(this.form,'data[Cart][freetext_hooks][' + (this.id.replace('freetext_','')) + ']', this.value);
				else if($('data[Cart][freetext_hooks][' + (this.id.replace('freetext_','')) + ']')) $('data[Cart][freetext_hooks][' + (this.id.replace('freetext_','')) + ']').destroy();
			});
			Txt.addEvent('blur', function (){
				if(!this.value.trim()){
					if($('data[Cart][freetext_hooks][' + (this.id.replace('freetext_','')) + ']'))$('data[Cart][freetext_hooks][' + (this.id.replace('freetext_','')) + ']').destroy();
				}
			});
			Txt.addEvent('click', function (){
				return false;
			});
		});
	}
	if($$('a.print#preview')[0]){
		window.popups = [];
		var my_components = $('komponenten').clone().getElement('div');
		var fullsizeimage = $('fullsizeImage') ? $('fullsizeImage').clone() : null;
		if(fullsizeimage){
			$$('a.print#preview')[0].addEvent('click', function(){
				var summ = str2float($('price').firstChild.data.replace('€ ',''));
				var fullimage = fullsizeimage.clone();
				time = new Date();
				time = time.getTime();
				window.popups[time] = window.open('/products/popup' + '?id=' + this.rev + '&price=' + summ, 'Config' + time, 'width=770, height=650, scrollbars = yes');
				var $this = this;
				var func = function(){
					var productform = $('productform').clone();
					productform.action = '/products/popup' + '?id=' + $this.rev + '&price=' + summ;
					productform.target = window.popups[time].name;
					productform.style.display = 'none';					
					productform.inject(document.body);
					productform.submit();
					productform.destroy();
				}.delay(500);
				return false;
			});
		}
	}
	if($$('div#komponenten a.printpage_bottom')[0]){
		if(fullsizeimage){
			$$('div#komponenten a.printpage_bottom')[0].addEvent('click', function(){
				var summ = str2float($('price').firstChild.data.replace('€ ',''));
				var fullimage = fullsizeimage.clone();
				time = new Date();
				time = time.getTime();
				window.popups[time] = window.open('/products/popup' + '?id=' + this.rev, 'Config' + time, 'width=770, height=650, scrollbars = yes');
				var $this = this;
				var func = function(){
					var productform = $('productform').clone();
					productform.action = '/products/popup' + '?id=' + $this.rev + '&price=' + summ;
					productform.target = window.popups[time].name;
					productform.style.display = 'none';					
					productform.inject(document.body);
					productform.submit();
					productform.destroy();
				}.delay(500);
				return false;
			});
		}
	}
	if($$('textarea.freetext')[0]){
		$each($$('textarea.freetext'), function (Txt,i){
			Txt.addEvent('focus', function(){
				this.getPrevious('input').checked = true;
				this.getPrevious('input').onclick();
			});
		});
	}
	$GLOBALS.done = false;
	handleLeasing();
	if($('nonform')){
		$each($A($('nonform').elements), function(Elm){
			if(!$GLOBALS.IE)Elm.removeEvents();
			else if(Elm.type && (Elm.type=='radio')){Elm.disabled=true;}
			Elm.onfocus = function(){this.blur();return false;};
			Elm.onmousedown = function(){this.blur();return false;};
			Elm.onclick = function(){this.blur();return false;};
			Elm.onkeydown = function(){this.blur();return false;};
			Elm.oncontextmenu = function(){this.blur();return false;};
		});
	}
});
else{
	window.onload = function()
	{
		var forms = document.forms;
	    for (var i=0;i < forms.length;i++) {
	    	addInputSubmitEvent(forms[i]);
	    }
	    var a = _A(_T('a'));
	    var inp = _T('input');
	    for(var x=0;x<inp.length;x++){
	    	if(inp[x].type == 'button'||inp[x].type == 'image'||inp[x].type == 'submit'||inp[x].type == 'radio'||inp[x].type == 'checkbox'){
				inp[x].style.cursor = 'pointer';
				a = a.concat(inp[x]);
			}
	    }
		for(var i=0;i<a.length;i++){// http://www.tomislav.net/gestrichelte-linie-um-link-verstecken.htm
			a[i].onmousedown = function()
			{
				this.onfocus = function()
				{
					this.blur();
				};
			};
			a[i].onmouseout = function()
			{
				this.onfocus = function(){};
			};
			a[i].onmousemove = a[i].onmouseout;
		}
	};
}
function changePrice(e)
{/* Preiswechsel für den Konfigurator */
	if(e==-1){
		var innpp = $$('form#productform input');
		$each(innpp,function(Obbj){
			if(Obbj.getParent('div.konfigurator') && (Obbj.type == 'text') && Obbj.value && (Obbj.value > 0)){
				Obbj.onkeyup();
			}
			else if(Obbj.getParent('div.konfigurator') && ((Obbj.type == 'radio')||(Obbj.type == 'checkbox')) && (Obbj.checked==true)){
				Obbj.onclick();
			}
		});
		return false;
	}
	if(!e)e=window.event;
	$this = $(this);
	$name = $this.name ? $this.name : $this.getNext('input[type="checkbox"]').name;
	if($this.type != 'radio'){
		var math_id = $this.getParent('div').getProperty('id');
		var max_key = $this.getParent('div').getElement('input[type="checkbox"]').getProperty('name');
		var value = $this.value;
		var sum = 0;
		if(e && e.keyCode && $this.type == 'text'){
			if(e.keyCode == '13'){
				 return false;
			}
			if(isNaN($this.value) || ($this.value === '')){
				$this.value = '0';
				$this.getParent('div').getElement('input[type="checkbox"]').checked = false;
			}
			else if(!isNaN($this.value)){
				$this.getParent('div').getElement('input[type="checkbox"]').checked = true;
			}
			if(e.keyCode){
				 if(e.keyCode == '38'){
					 $this.value = $this.value*1+1;
					 $this.getParent('div').getElement('input[type="checkbox"]').checked = true;
				 }
				 if(e.keyCode == '40'){
					 $this.value = $this.value*1-1;
					 if($this.value<=0){
						 $this.value = 0;
						 this.getParent('div').getElement('input[type="checkbox"]').checked = false;
					 }
				 }
				 if(e.keyCode == '8'){
					 $this.value = '';
				 }
			}
		}
		$this.addEvent('blur', function(event){
			this.value = this.value ? this.value : '0';
		});
		var inps = $$('form#productform input[type="checkbox"]');
		$each(inps, function(Obj){
			if(Obj.checked && $maxArray[Obj.name] && ($maxArray[Obj.name][math_id] || $maxArray[Obj.name][math_id]===0)){
				var deflt = Obj.getParent('div').getElement('input[type="text"]').value*1 ? Obj.getParent('div').getElement('input[type="text"]').value*1 : 1;
				sum += deflt;
			}
		});
		if(sum > $maxArray[max_key][math_id]){
			if($this.type == 'text'){
				$this.value = $this.value*1 - (sum*1 - $maxArray[max_key][math_id]*1);
				if($this.value<=0){
					$this.value = 0;
					$this.getParent('div').getElement('input[type="checkbox"]').checked=false;
				}
			}
			else if($this.type == 'checkbox'){
				$this.getParent('div').getElement('input[type="text"]').value='0';
				$this.checked = false;
			}
			if($this.getNext('textarea'))$this.getNext('textarea').blur();
			alert(window['javascript.messages.max_multi_availibles_1'] + ' ' + $maxArray[max_key][math_id] + ' ' + window['javascript.messages.max_multi_availibles_2']);
		}
		if($this.checked || ($this.type=="text" && $this.getParent('div').getElement('input[type="checkbox"]').checked)){
			if(!$('komponenten').getElement('div.' + $name)){
				var div = new Element('div',{'class': $name});
				var h2 = new Element('h2',{title: $name, styles : {'color':'#444444','margin':'5px 0 0','background':'url(/img/icons/bg_config_img.gif) 0 1px no-repeat','padding-left':'12px'}});
				h2.innerHTML = $name.replace('_pppp_','&#x2B;').replace('_klamuf_','&#x28;').replace('_klamzu_','&#x29;').replace('_nbsp_',' ').replace('_komma_',',').replace('_onquot_',"'").replace(/\_(.*?)\_/g,'&$1;') + ':';
				div.inject($('komponenten').getElement('div'));
				h2.inject(div);
				var iDiv =  new Element('div',{'title': $name});
				iDiv.inject(div);
			}
			else{
				iDiv = $('komponenten').getElement('div[title="' + $name + '"]');
			}
			if(!$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_',''))){
				var span = new Element('span', { styles : {'display' : 'block'}, id: 'span_' + math_id.replace('math_','')});
				span.innerHTML = 1 + ' x ' + $this.getNext('span').firstChild.data;
				span.inject(iDiv);
				var h21 = {};
				if(h21=iDiv.getParent('div').getPrevious('h2')){
					if(h21.myFx.open){
						var sh = function(){
							h21.myFx.show();
						};
						sh.delay(10);
					}
				}
			}
			else{
				$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_','')).innerHTML = $this.getParent('div').getElement('input[type="text"]').value + ' x ' + $this.getNext('span').firstChild.data;
			}
		}
		else if(!$this.checked){
			if($('komponenten').getElement('span#' + 'span_' + math_id.replace('math_',''))){
				var h21 = {};
				if(h21=$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_','')).getParent('div').getParent('div').getPrevious('h2')){
					if(h21.myFx.open){
						var sh = function(){
							h21.myFx.show();
						};
						sh.delay(10);
					}
				}
				$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_','')).destroy();
				if(!$('komponenten').getElement('div[title="' + $name + '"] span')){
					if($('komponenten').getElement('div[title="' + $name + '"]'))$('komponenten').getElement('div[title="' + $name + '"]').destroy();
					if(!$('komponenten').getElement('div.' + $name + ' span')){
						if($('komponenten').getElement('div.' + $name))$('komponenten').getElement('div.' + $name).destroy();
					}
				}
			}
		}
	}
	else if($this.type == 'radio'){
		math_id = $this.getParent('div').getProperty('id');
		max_key = $this.getParent('div').getElement('input[type="radio"]').getProperty('name');
		if($this.checked){
			if($('komponenten').getElement('div.' + $name + ' span')){
				$('komponenten').getElement('div.' + $name + ' span').destroy();
			}
			if(!$('komponenten').getElement('div.' + $name)){
				var div = new Element('div',{'class': $name});
				var h2 = new Element('h2',{title: $name, styles : {'color':'#444444','margin':'5px 0 0','background':'url(/img/icons/bg_config_img.gif) 0 1px no-repeat','padding-left':'12px'}});
				h2.innerHTML = $name.replace('_pppp_','&#x2B;').replace('_klamuf_','&#x28;').replace('_klamzu_','&#x29;').replace('_nbsp_',' ').replace('_komma_',',').replace('_onquot_',"'").replace(/\_(.*?)\_/g,'&$1;') + ':';
				div.inject($('komponenten').getElement('div'));
				h2.inject(div);
				var iDiv =  new Element('div',{'title': $name});
				iDiv.inject(div);
			}
			else{
				iDiv = $('komponenten').getElement('div[title="' + $name + '"]');
			}
			if(math_id){
				if(!$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_',''))){
					var span = new Element('span', { styles : {'display' : 'block'}, id: 'span_' + math_id.replace('math_','')});
					span.innerHTML = 1 + ' x ' + $this.getNext('span').firstChild.data;
					span.inject(iDiv);
				}
				else{
					$('komponenten').getElement('span#' + 'span_' + math_id.replace('math_','')).innerHTML = 1 + ' x ' + $this.getNext('span').firstChild.data;
				}
			}
			else if($('komponenten').getElement('div.' + $name)){
				$('komponenten').getElement('div.' + $name).destroy();
			}
		}
	}
	if(h2 && $$('h2[title="' + $name + '"]')[0]){
		h2.style.cursor = 'pointer';
		var myFx = new Fx.Slide(iDiv,{duration: 600,transition: Fx.Transitions.Pow.easeOut});
		h2.onclick = function()
		{
			this.myFx.toggle();
			this.style.backgroundPosition = myFx.open ? '0 1px' : '0 -86px';
		};
		h2.myFx = myFx;
		h2.myFx.hide();
	}
	if($GLOBALS.hiddens.length){
		$each($GLOBALS.hiddens, function(Obj){
			if($(Obj))$(Obj).destroy();
		});
		$GLOBALS.hiddens = [];
	}
	// Alle Inputs in Form ziehen (außer die generierten Hiddens)
	var inp = $$('form#productform input[type="radio"],form#productform input[type="checkbox"],form#productform input[type="text"]'), id= null, price = $priceArray[0]*1, text = null;
	// Beim Starten, onLoad
	$each(inp,function(Obj){
		if(Obj.type=='radio'){
			if(Obj.checked && (id = Obj.getParent('div').getProperty('id'))){
				makeHiddenField(Obj.form,'data[Cart][accessories][' + (id.replace('math_','')) + ']', 1);
				$GLOBALS.hiddens[$GLOBALS.hiddens.length] = 'data[Cart][accessories][' + (id.replace('math_','')) + ']';
				price += $priceArray[Obj.name][id]*1;
			}
		}
		if(Obj.type == 'checkbox'){
			if(Obj.checked && (id = Obj.getParent('div').getProperty('id'))){
				text = Obj.getParent('div').getElement('input[type="text"]');
				text.value = text.value > '0' ? text.value*1 : 1;
				makeHiddenField(Obj.form,'data[Cart][accessories][' + (id.replace('math_','')) + ']', text.value);
				$GLOBALS.hiddens[$GLOBALS.hiddens.length] = 'data[Cart][accessories][' + (id.replace('math_','')) + ']';
				price += $priceArray[Obj.name][id]*1*text.value;
				if($defaultPricePlus[id]){
					price += $defaultPricePlus[id]*1*text.value;
					if($('data[Cart][extraPrice][' + id.replace('math_','') + ']'))$('data[Cart][extraPrice][' + id.replace('math_','') + ']').destroy();
				}
			}
			else if(!Obj.checked && (id = Obj.getParent('div').getProperty('id'))){
				text = Obj.getParent('div').getElement('input[type="text"]');
				if(($this === text) && ($this.value === '')){
					text.value = '';
				}
				else{
					text.value = '0';
				}
				if($defaultPricePlus[id]){
					//price += $defaultPricePlus[id]*1;
					//makeHiddenField(Obj.form,'data[Cart][extraPrice][' + id.replace('math_','') + ']',$defaultPricePlus[id]);
				}
			}
		}
	});
	$plus = 0;
	$('price').firstChild.data = '€ ' +  float2str(price+$plus);
	handleLeasing(inp[0].form);

}
function handleLeasing(Form)
{
	if ($('leasingvalue') && $('price')) {
		var $rates = $A([]);
		var $value = '';
		var $price = str2float($('price').firstChild.data.replace('€ ', ''));
		var Min = 0;
		var p = $('mth').getParent('p');
		$each($A($('leasingvalue').options), function(Opt, i){
			var Int = Opt.id.toInt();
			if (!$rates[Int]) 
				$rates[Int] = $A([]);
			var $value = Opt.value.split('__');
			$each($value, function(Val, o){
				var val = Val.split('_');
				if (!Min) 
					Min = val[0];
				$rates[Int][val[0]] = val[1];
				Opt.wert = !(Opt.wert) ? [] : Opt.wert;
				Opt.wert[o] = val[1];
				if ($price >= val[0] && ($('leasingvalue').options[$('leasingvalue').selectedIndex] == Opt)) {
					$('mth').innerHTML = '€ ' + float2str(Opt.wert[o] * $price / 100);
					if($GLOBALS.leasingAllowed)makeHiddenField(Form, 'data[Cart][leasing][' + $('CartProductId').value + ']', $('mth').innerHTML.replace('€', '').trim() + '_' + $('leasingvalue').options[$('leasingvalue').selectedIndex].text.replace('Monate', ''));
					else if($('data[Cart][leasing][' + $('CartProductId').value + ']')){
						$('data[Cart][leasing][' + $('CartProductId').value + ']').destroy();
					}
				}
			});
		});
		$('leasing').title = 'Um Leasing in Anspruch zu nehmen, darf der Warenwert von ' + Min + ' € nicht unterschritten werden !';
		var myTip = new Tips($('leasing'), {
			className: 'tooltipp2',
			offset: {
				y: -56
			}
		});
		$('leasingvalue').addEvent('change', function(){
			var $this = this;
			var $Wert = $this.options[$this.selectedIndex].value.split('__');
			$each($Wert, function(Wrt, i){
				var wrt = Wrt.split('_');
				if ($price >= wrt[0]) {
					$('mth').innerHTML = '€ ' + float2str($this.options[$this.selectedIndex].wert[i] * $price / 100);
					if($('data[Cart][leasing][' + $('CartProductId').value + ']')){
						$('data[Cart][leasing][' + $('CartProductId').value + ']').destroy();
					}
					if($GLOBALS.leasingAllowed)makeHiddenField(Form, 'data[Cart][leasing][' + $('CartProductId').value + ']', $('mth').innerHTML.replace('€', '').trim() + '_' + $this.options[$this.selectedIndex].text.replace('Monate', ''));
				}
			});
		});
		if(!$GLOBALS.leasingAllowed || $price < Min){
			$('leasing').title = 'Um Leasing in Anspruch zu nehmen, darf der Warenwert von ' + Min + ' € nicht unterschritten werden !';
			if(!myTip)myTip = new Tips($('leasing'),{className:'tooltipp2',offset:{y:-56}});
			$('leasingvalue').disabled = true;
			$('leasing').title = '';
			p.style.display = 'none';
			return;
		}
		else {
			myTip.detach($('leasing'));
			myTip = null;
			$('leasing').title = '';
			$('leasingvalue').disabled = false;
			p.style.display = 'block';
		}
		$('leasingvalue').blur();
	}
}
