// JavaScript Document

function calculateFieldsBuecher(amount,price1,price3,price10,price50){
	
	if(amount==0){
		
		amount=	document.getElementById('amount').value;
	}
	
	
	if(document.getElementById('country').value==10){
		ust=10;
		document.getElementById('ustname7').style.display = "none";
		document.getElementById('ustname10').style.display = "block";
		}
		else {
		ust=7;	
		document.getElementById('ustname10').style.display= "none";
		document.getElementById('ustname7').style.display= "block";
		}
	
	
	if(amount<3 && amount > 0){
		
		
		pricetotalex = amount*price1;
		usttotal = pricetotalex*(ust/100);
		
		pricetotalink = pricetotalex + usttotal;
		document.getElementById('pricepiece').value=price1;
		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(usttotal,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);
	}
	
	if(amount<10 && amount >2){
	
		pricetotalex = amount*price3;
		usttotal = pricetotalex*(ust/100);
		
		pricetotalink = pricetotalex + usttotal;
		document.getElementById('pricepiece').value=price3;
		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(usttotal,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);

	}
	
	if(amount>9 && amount <50){
		pricetotalex = amount*price10;
		usttotal = pricetotalex*(ust/100);
		
		pricetotalink = pricetotalex + usttotal;
		document.getElementById('pricepiece').value=price10;
		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(usttotal,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);
		
	}
	if(amount>49){
				pricetotalex = amount*price50;
		usttotal = pricetotalex*(ust/100);
		
		pricetotalink = pricetotalex + usttotal;
		document.getElementById('pricepiece').value=price50;
		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(usttotal,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);

		
	}
	
}




function calculateFieldsTermine(amount,price1st,price2nd,percent,abteilnehmer,mengenrabatt,ustbool){
	
	
	if(amount==0){
		
		amount=	document.getElementById('amount').value;
	}

	
	if(document.getElementById('country').value==20){
		ustpercent=20;
		document.getElementById('ustname19').style.display = "none";
		document.getElementById('ustname20').style.display = "block";
		}
		else {
		ustpercent=19;	
		document.getElementById('ustname20').style.display= "none";
		document.getElementById('ustname19').style.display= "block";
		}
	
	
	
	if(mengenrabatt==1){
		
	if(amount<abteilnehmer){
		
	pricetotalex=amount*price1st;
	if (ustbool != 1) {
		ust = 0;
	}
	else {
		ust = pricetotalex * (ustpercent / 100);
	}
	
	pricetotalink=pricetotalex+ust;
		
	}
	
	if(amount>=abteilnehmer){
	amount2nd=amount-(abteilnehmer-1);
	amount1st=amount-amount2nd;
	
	
	pricetotalex=(amount1st*price1st) + (amount2nd*price2nd);
	if (ustbool != 1) {
		ust = 0;
	}
	else {
		ust = pricetotalex * (ustpercent / 100);
	}
	pricetotalink=pricetotalex+ust;
		
	}
	

		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(ust,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);

		
		
	} else {
	
		
	pricetotalex=amount*price1st;
	if (ustbool != 1) {
		ust = 0;
	}
	else {
		ust = pricetotalex * (ustpercent / 100);
	}
	pricetotalink=pricetotalex+ust;
		
		document.getElementById('pricetotalex').value=format(pricetotalex,2);
		document.getElementById('ust').value=format(ust,2);
		document.getElementById('pricetotalink').value=format(pricetotalink,2);
	
	}
	
	
	
	
	
}




function format (expr, decplaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) {
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}



function MM_validateForm() { //v5.00
  var i,p,q,nt,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) {
				nt = (args[i+1]=='' ? val.name : args[i+1]);
		if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nt+' muss eine gültige Adresse beinhalten!\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nt+' muss eine Zahl beinhalten!\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+='- '+nt+' muss eine Zahl zwischen '+min+' und '+max+' beinhalten!\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nt+' muss angegeben werden!\n'; }
  } if (errors) alert('Folgende Fehler sind aufgetreten:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}

