<!--//

function computeProductPrice(productID) {

	productCount = document.bestellung['product_'+productID+'_count'].value;
	
	if (productCount != 0 && productCount != '') {
	
		productPriceSingle = 0;
		productPriceTotal = 0;
	
		for (i=products[productID].length-1; i>=0; i--) {
			if (productCount >= products[productID][i]['limit']) {
				productPriceSingle = products[productID][i]['preis'];
				break;
			}
		}
	
		if (productPriceSingle == 0) productPriceSingle = (Math.round(products[productID][0]['preis'] * 1.125  * 100 +0.005) / 100);
	
		productPriceTotal = productPriceSingle * productCount;
	
		document.bestellung['product_'+productID+'_single'].value = numberFormat(productPriceSingle);
		document.bestellung['product_'+productID+'_total'].value = numberFormat(productPriceTotal);
	
		computeOrderPrice();
		
	}
	
}



function computeOrderPrice() {

	netto = 0;

	vat = 0;

	total = 0;

	

	for (key in products) {
		
		if (document.bestellung['product_'+key+'_total']) {
			productTotal = document.bestellung['product_'+key+'_total'].value;
		} else {
			alert(key);
		}
		
		if (productTotal != "") {

			netto+= numberUnformat(productTotal);

		}

	}

	

	vat = Math.round(parseFloat(netto) * 0.19 * 100)/100;

	

	total = parseFloat(netto) + parseFloat(vat);

	

	document.bestellung.netto.value = numberFormat(netto);

	if (language == "") {

		document.bestellung.vat.value = numberFormat(vat);

		document.bestellung.total.value = numberFormat(total);

	}

}

function initForm() {
	for (key in products) {
		computeProductPrice(key);
	}
}

function numberFormat(number){

		number = number.toFixed(2);

		number = number.toString();

		return number.replace(".", ",");

}



function numberUnformat(number) {

		return parseFloat(number.replace(",", "."));

}



var buttonPressed = false;



function checkReturnKey() {

	if (buttonPressed == true) {

		MM_validateForm('stamm_firmabehoerde','','R','stamm_email','','RisEmail','stamm_vorwahl','','RisNum','stamm_telefon','','RisNum');

		if (document.MM_returnValue == true)

			document.forms[0].submit()

		else

			return document.MM_returnValue;

	} else

		return false;

}



function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0

  if(window.screen)if(isCenter)if(isCenter=="true"){

    var myLeft = (screen.width-myWidth)/2;

    var myTop = (screen.height-myHeight)/2;

    features+=(features!='')?',':'';

    features+=',left='+myLeft+',top='+myTop;

  }

  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);

}



function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

    if (val) { nm=val.name; if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

      } else if (test!='R') { num = parseFloat(val);

        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

          min=test.substring(8,p); max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

  } if (errors) alert('The following error(s) occurred:\n'+errors);

  document.MM_returnValue = (errors == '');

}

//-->
