function ju(cl) {
	document.cookie = "clwhin=" + cl + "; path=/";
	return true;
}

function Mausklick (Ereignis) {
  if (!Ereignis)
    Ereignis = window.event;
  rx = document.documentElement.scrollLeft + Ereignis.clientX - document.getElementById("topboard").offsetLeft;
  ry = document.documentElement.scrollTop + Ereignis.clientY - document.getElementById("topboard").offsetTop;
  aus += rx + "," + ry + "|";
  document.cookie = "mvt=" + aus + "; path=/";
}
var aus = "";
document.onclick = Mausklick;


var http;
if (window.XMLHttpRequest) {
   http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
   http = new ActiveXObject("Microsoft.XMLHTTP");
}

function filta() {
	var a = document.flut;
	var b = a.length;
	var c="";
	var d;
	var i,ses;
	for (i=0; i<b; i++) {
		d=a[i].name;
		if (d.substr(0,4)=="filt") c=c + ";" + escape(a[i].value);
	}
	if (http != null) {
		http.open("GET", "/arwer.php?ausg=1&txt=" + c, false);
		http.onreadystatechange = function () {
			if (http.readyState == 4) {
				var tp = http.responseText;
				var tc =new Array();
				tc = tp.split("\n");
				document.getElementById("artimen").innerHTML = tc[0];
			}
		}

		http.send(null);
	}
}


function InZahl (Wert) {
	if (Wert.length==0) wert=0;
	var PosPunkt = Wert.indexOf(".",0);
	var PosKomma = Wert.indexOf(",",0);
	if (PosKomma < 0) PosKomma = Wert.length;
	while ((0 <= PosPunkt) && (PosPunkt < PosKomma)) {
		Wert = Wert.substring(0, PosPunkt) + Wert.substring(PosPunkt + 1, Wert.length);
		PosPunkt = Wert.indexOf(".",0);
		PosKomma--;
	}
	PosKomma = Wert.indexOf(",",0);
	if (PosKomma >= 0) {
		Wert = Wert.substring(0, PosKomma) + "." + Wert.substring(PosKomma + 1, Wert.length);
	}
	return parseFloat(Wert);
}

function kaufm(x) {
	if (isNaN(x)) return "0,00";
	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 komma(x) {
	if (isNaN(x)) return "0";
	var k =(Math.round(x * 10000) / 10000).toString();
	var p = k.indexOf('.');
	if (p >=0) {
		k = k.substring(0, p) + ',' + k.substring(p+1, k.length);
	}
	return k;
}

function promo_zubehoer_preise ($that) {
	var $parent = $that.parents('.promo_zubehoer_ele');
	if ($that.attr('tagName') == 'SELECT'){
		var newpreis = $that.find(':selected').attr('rel');
		$parent.find('.promo_zubehoer_preis').text(newpreis);
	}
	var preis = $parent.find('.promo_zubehoer_preis').text().replace(',','.');
	var $summe = $parent.find('.promo_zubehoer_gesamtpreis');
	var $inputs = $parent.find('input[type=text]');

	var menge = 0;
	var stck = 0;
	var summe = 0;
	
	preis = parseFloat(preis);
	
	$inputs.each(function(){
		var name = $(this).attr('name');
		var val = $(this).val().replace(',','.');
		if (/^verkaufsmenge/i.test(name)) {
			menge += parseFloat(val);
		} else {
			stck += parseFloat(val);
		}
	});

	if (menge > 0) {
		summe = menge * preis;
	} else {
		summe = stck * preis;
	}
	
	if (summe > 0) {
		$summe.html(summe.toFixed(2).replace('.',',') + " €");
	}
	
	//console.log(stck, "||", menge, "||", preis);
}

$(document).ready(function() {

$('.promo_zubehoer_ele').each(function(){
	$(this).find('input[type=text]').each(function(){
		promo_zubehoer_preise($(this));
	});
});

$('.promo_zubehoer_evt').change(function(){
	promo_zubehoer_preise($(this));
});

$('#zufass_dropartnr').change(function(){
	var path = location.href.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '')
	path += "/" + $(this).val() + ".html";
	window.location = path;
});

});

