var select_vorbesitzer_old = 0;
var kontakt;
function isANumber(n){
   var s = "" + n //Umwandlung in eine Zeichenkette
   var ziffern = "0123456789" //Gültige Zeichen
   for (var i=0; i<s.length; i++)
      if (ziffern.indexOf(s.charAt(i))==-1) //keine Ziffer
         return false
   return true
}
function isANumber2(n){
   var s = "" + n //Umwandlung in eine Zeichenkette
   var ziffern = "0123456789" //Gültige Zeichen
   if (s=="0") //Bei "0"
      return true
   if (s.charAt(0)=="0") //Bei 0 am Anfang
      return false
   for (var i=0; i<s.length; i++)
      if (ziffern.indexOf(s.charAt(i))==-1) //keine Ziffer
         return false
   return true
}
function isANumber3(n){
   var s = "" + n //Umwandlung in eine Zeichenkette
   var ziffern = "0123456789" //Gültige Zeichen
   if (s.charAt(0)=="-")  //führendes Minus entfernen
      s = s.substring(1, s.length)
   if (s=="0") //Bei "0"
      return true
   if (s.charAt(0)=="0") //Bei 0 am Anfang
      return false
   for (var i=0; i<s.length; i++)
      if (ziffern.indexOf(s.charAt(i))==-1) //keine Ziffer
         return false
   return true
}
function isAFract(n){
   var s = "" + n //Umwandlung in String
   while (s.indexOf(",")>-1){//Kommata durch Punkte ersetzen
      s=s.substring(0,s.indexOf(",")) + "." + s.substring(s.indexOf(",")+1 ,s.length)
   }
   var anzahl_punkt=0//Variable zum Zählen der Dezimalpunkte
   for (var i=0; i<s.length; i++)
      if (s.charAt(i)==".")
         anzahl_punkt++
   if (anzahl_punkt>1) //Mehr als ein Dezimalpunkt?
      return false
   // *** Eigentliche Überprüfung nach obigem Muster
   // *** Neu: Der Dezimalpunkt ist ein erlaubtes Zeichen
   var ziffern = ".0123456789" //Gültige Zeichen
   if (s.charAt(0)=="-")  //Führendes Minus entfernen
      s = s.substring(1, s.length)
   if (s=="0") //Bei "0"
      return true
   if (s.charAt(0)=="0" &&s.charAt(1)!=".")
      //Bei 0 am Anfang ohne folgenden Punkt
      return false
   for (var i=0; i<s.length; i++)
      if (ziffern.indexOf(s.charAt(i))==-1) //Keine Ziffer
         return false
   return true
}
function isAPhoneNumber(n){
   var s = "" + n //Umwandlung in eine Zeichenkette
   var zeichen = "0123456789+-()[]/ " //Gültige Zeichen
   for (var i=0; i<s.length; i++)
      if (zeichen.indexOf(s.charAt(i))==-1)
         //kein gültiges Zeichen
         return false
   return true
}
function smartEval(n){
   var s = "" + n //Umwandlung in eine Zeichenkette
   for (var i=0; i<s.length; i++)  //Kommata in Zahlen
      if (s.charAt(i)==",")
         s=s.substring(0,i)+"."+s.substring(i+1,s.length)
   if (isAFrac(s))
      return 1*s //Umwandlung in einen Zahlenwert
   else
      return 0
}

function Calculate(n,fieldname) {

/*
if (fieldname == "selling_price") {
	var csvFile = "kalk1.xls";
	var oShell = new ActiveXObject("Wscript.Shell");
	var excelApp = oShell.Run("excel \"" + csvFile + "\"");
}
*/
if (isAFract(n) == true || n == 1) {
//  Wenn Rep. aktuell > Rep kalk., dann VKP aktualisieren
if (document.form.object_nr.value != '') {
	document.form.cost_of_repairs_calc_amount_sm.value = (document.form.cost_of_repairs_calc_sm.value *= 1) + (document.form.cost_of_repairs_calc_head_sm.value *= 1);
	document.form.cost_of_repairs_acc_amount_sm.value = (document.form.cost_of_repairs_acc_sm.value *= 1) + (document.form.cost_of_repairs_acc_head_sm.value *= 1);
  var feld1 = parseInt(document.form.cost_of_repairs_calc_amount_sm.value, 10);
  var feld2 = parseInt(document.form.cost_of_repairs_acc_amount_sm.value, 10);

//  if (document.form.cost_of_repairs_acc_amount_sm.value > document.form.cost_of_repairs_calc_amount_sm.value) {
  if (feld2 > feld1) {
  	if (document.form.internal_price.value > 0) {
  		document.form.selling_price_sm.value = (document.form.internal_price.value *= 1) ;
      if (document.form.cost_of_repairs_acc_sm.value > document.form.cost_of_repairs_calc_sm.value)
  		  document.form.selling_price_sm.value = (document.form.internal_price.value *= 1) + ((document.form.cost_of_repairs_acc_sm.value *= 1) - (document.form.cost_of_repairs_calc_sm.value *= 1));
      fieldname = 'selling_price_sm';
  	}
    if (document.form.internal_price_head.value > 0) {
  		document.form.selling_price_head_sm.value = (document.form.internal_price_head.value *= 1) ;
      if (document.form.cost_of_repairs_acc_head_sm.value > document.form.cost_of_repairs_calc_head_sm.value)
  		  document.form.selling_price_head_sm.value = (document.form.internal_price_head.value *= 1) + ((document.form.cost_of_repairs_acc_head_sm.value *= 1) - (document.form.cost_of_repairs_calc_head_sm.value *= 1));
      fieldname = 'selling_price_head_sm';
  	}
  }
//	window.alert(fieldname);
}

//	WFW-Verkaufspreis
	document.form.selling_price_amount_sm.value = (document.form.selling_price_sm.value *= 1) + (document.form.selling_price_head_sm.value *= 1);
	document.form.preis_dis.value = (document.form.selling_price_amount_sm.value *= 1);
	document.form.preis.value = (document.form.preis_dis.value *= 1);
	document.form.selling_price_amount_d.value = (document.form.selling_price_d.value *= 1) + (document.form.selling_price_head_d.value *= 1);

//	Tatsächlicher VKP
	document.form.realised_price_amount_sm.value = (document.form.realised_price_sm.value *= 1) + (document.form.realised_price_head_sm.value *= 1);
	document.form.realised_price_percent_sm.value = Math.round(((document.form.realised_price_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Vermittlungsprovision
	if (fieldname == 'commission_percent_fixed') {
		if (document.form.commission_percent_fixed.value == 1)
			document.form.commission_percent_fixed.value = 0;
		else
			document.form.commission_percent_fixed.value = 1;
	}

	if (document.form.commission_percent_fixed.value == 0) {
		if ((document.form.select_vorbesitzer.value != select_vorbesitzer_old) || (document.form.selling_price_sm.value != document.form.selling_price_old.value) || (document.form.selling_price_head_sm.value != document.form.selling_price_head_old.value)) {
			if (document.form.selling_price_amount_sm.value >= 200000)
				document.form.commission_percent_sm.value = 2.5;
			else {
				if (document.form.selling_price_amount_sm.value >= 100000)
					document.form.commission_percent_sm.value = 3.0;
				else {
					if (document.form.selling_price_amount_sm.value >= 50000)
						document.form.commission_percent_sm.value = 3.5;
					else
						document.form.commission_percent_sm.value = 4.0;
				}
			}
			if (document.form.select_vorbesitzer.value == 10)
				document.form.commission_percent_sm.value = (document.form.commission_percent_sm.value *= 1) / 2;
	/*
			document.form.selling_price_old.value = document.form.selling_price.value;
			document.form.selling_price_head_old.value = document.form.selling_price_head.value;
	*/
			select_vorbesitzer_old = document.form.select_vorbesitzer.value;
		}
	}

//	Vermittlungsprovision
//	document.form.commission_sm.value = Math.round((document.form.selling_price_sm.value *= 1) * (document.form.commission_percent_sm.value *= 1)) / 100;
//	document.form.commission_head_sm.value = Math.round((document.form.selling_price_head_sm.value *= 1) * (document.form.commission_percent_sm.value *= 1)) / 100;
//	document.form.commission_amount_sm.value = (document.form.commission_sm.value *= 1) + (document.form.commission_head_sm.value *= 1);

//	Haendlereinkaufspreis
//	document.form.dealer_purchase_sm.value = Math.round((document.form.selling_price_sm.value *= 1) * (document.form.dealer_purchase_percent_sm.value *= 1)) / 100;
//	document.form.dealer_purchase_head_sm.value = Math.round((document.form.selling_price_head_sm.value *= 1) * (document.form.dealer_purchase_percent_sm.value *= 1)) / 100;
//	document.form.dealer_purchase_amount_sm.value = (document.form.dealer_purchase_sm.value *= 1) + (document.form.dealer_purchase_head_sm.value *= 1);

//	Reparaturkosten, kalkuliert
	document.form.cost_of_repairs_calc_amount_sm.value = (document.form.cost_of_repairs_calc_sm.value *= 1) + (document.form.cost_of_repairs_calc_head_sm.value *= 1);
	document.form.cost_of_repairs_calc_percent_sm.value = Math.round(((document.form.cost_of_repairs_calc_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Reparaturkosten, durchgefuehrt
	document.form.cost_of_repairs_acc_amount_sm.value = (document.form.cost_of_repairs_acc_sm.value *= 1) + (document.form.cost_of_repairs_acc_head_sm.value *= 1);
	document.form.cost_of_repairs_acc_percent_sm.value = Math.round(((document.form.cost_of_repairs_acc_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;
/*
//  Wenn Rep. aktuell > Rep kalk., dann VKP aktualisieren
if (document.form.object_nr.value != '') {
	if (document.form.internal_price.value > 0 && (document.form.cost_of_repairs_acc_sm.value > document.form.cost_of_repairs_calc_sm.value)) {
		document.form.selling_price_sm.value = (document.form.internal_price.value *= 1) + ((document.form.cost_of_repairs_acc_sm.value *= 1) - (document.form.cost_of_repairs_calc_sm.value *= 1));

	}
  if (document.form.internal_price_head.value > 0 && (document.form.cost_of_repairs_acc_head_sm.value > document.form.cost_of_repairs_calc_head_sm.value)) {
//	if (document.form.limit_price_percent_sm.value > 0)  {
		document.form.selling_price_head_sm.value = (document.form.internal_price_head.value *= 1) + ((document.form.cost_of_repairs_acc_head_sm.value *= 1) - (document.form.cost_of_repairs_calc_head_sm.value *= 1));
//window.alert(document.form.internal_price_amount_sm.value);
	}
}
*/
//	Limitpreis
	if (fieldname == 'select_standort' || document.form.limit_price_percent_sm.value == 0) {

//	Kundenauftrag = 100%
		if (document.form.select_standort.value == 15) {
			document.form.limit_price_percent_sm.value = 100;
			document.form.dealer_purchase_percent_sm.value = 99.75;
		}
		else
			document.form.limit_price_percent_sm.value = 97;
	}
	if (fieldname == 'select_standort' || fieldname == 'limit_price_percent_sm' || fieldname == 'dealer_selling_price_percent_sm' || fieldname == 'selling_price_sm' || fieldname == 'selling_price_head_sm' || (document.form.limit_price_sm.value == 0 && document.form.selling_price_sm.value > 0) || (document.form.limit_price_head_sm.value == 0 && document.form.selling_price_head_sm.value > 0)) {
		if (fieldname != 'select_standort') {
			document.form.limit_price_sm.value = Math.round((document.form.selling_price_sm.value *= 1) * (document.form.limit_price_percent_sm.value *= 1)) / 100;
			document.form.limit_price_head_sm.value = Math.round((document.form.selling_price_head_sm.value *= 1) * (document.form.limit_price_percent_sm.value *= 1)) / 100;
		}

//	Haendler-Verkaufspreis
		if (fieldname != 'dealer_selling_price_percent_sm') {
			document.form.dealer_selling_price_percent_sm.value = 100;
			if (document.form.neu_gebraucht_hidden.value == '4') {
//				document.form.dealer_selling_price_percent_sm.value = 106.7;
				document.form.dealer_selling_price_percent_sm.value = 100;
				if (document.form.select_vorbesitzer.value == 10)
					document.form.dealer_selling_price_percent_sm.value = 105;
			}
		}
		document.form.dealer_selling_price_sm.value = document.form.selling_price_sm.value;
		document.form.dealer_selling_price_head_sm.value = document.form.selling_price_head_sm.value;
		if (document.form.neu_gebraucht_hidden.value == '4') {
//			document.form.dealer_selling_price_sm.value = Math.round((document.form.limit_price_sm.value *= 1) + (((document.form.limit_price_sm.value *= 1) / 100) * 10));
//			document.form.dealer_selling_price_head_sm.value = Math.round((document.form.limit_price_head_sm.value *= 1) + (((document.form.limit_price_head_sm.value *= 1) / 100) * 10));
			document.form.dealer_selling_price_sm.value = Math.round((document.form.selling_price_sm.value *= 1) * (document.form.dealer_selling_price_percent_sm.value *= 1) / 100);
			document.form.dealer_selling_price_head_sm.value = Math.round((document.form.selling_price_head_sm.value *= 1) * (document.form.dealer_selling_price_percent_sm.value *= 1) / 100);
		}
		if (fieldname == 'dealer_selling_price_percent_sm') {
			document.form.dealer_selling_price_sm.value = Math.round((document.form.selling_price_sm.value *= 1) * (document.form.dealer_selling_price_percent_sm.value *= 1)) / 100;
			document.form.dealer_selling_price_head_sm.value = Math.round((document.form.selling_price_head_sm.value *= 1) * (document.form.dealer_selling_price_percent_sm.value *= 1)) / 100;
		}
	}
	document.form.limit_price_amount_sm.value = (document.form.limit_price_sm.value *= 1) + (document.form.limit_price_head_sm.value *= 1);
	document.form.dealer_selling_price_amount_sm.value = (document.form.dealer_selling_price_sm.value *= 1) + (document.form.dealer_selling_price_head_sm.value *= 1);
//	if (!fieldname || fieldname == 'limit_price' || fieldname == 'limit_price_head') {
	if (fieldname == 'limit_price_sm' || fieldname == 'limit_price_head_sm') {
		document.form.limit_price_percent_sm.value = Math.round(((document.form.limit_price_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;
	}

//	Leasingpreis
/*
	if (document.form.neu_gebraucht_hidden.value == 2 && document.form.leasing_deposit_amount_sm.value < 1) {
		document.form.leasing_factor_sm.value = 1.2457;
		document.form.leasing_deposit_percent_sm.value = 15;
		document.form.salv_value_percent_sm.value = 25;
	}

	if (document.form.neu_gebraucht_hidden.value == 4 && document.form.leasing_deposit_amount_sm.value < 1) {
		document.form.leasing_factor_sm.value = 1.4949;
		document.form.leasing_deposit_percent_sm.value = 20;
		document.form.salv_value_percent_sm.value = 20;
	}
*/
//	if (fieldname == 'leasing_deposit_percent_sm' || document.form.leasing_deposit_amount_sm.value < 1) {
		document.form.leasing_deposit_sm.value = Math.round((document.form.dealer_selling_price_sm.value *= 1) * (document.form.leasing_deposit_percent_sm.value *= 1)) / 100;
		document.form.leasing_deposit_head_sm.value = Math.round((document.form.dealer_selling_price_head_sm.value *= 1) * (document.form.leasing_deposit_percent_sm.value *= 1)) / 100;
//	}
	document.form.leasing_deposit_amount_sm.value = (document.form.leasing_deposit_sm.value *= 1) + (document.form.leasing_deposit_head_sm.value *= 1);
	if (fieldname == 'leasing_deposit_sm') {
		document.form.leasing_deposit_percent_sm.value = Math.round(((document.form.leasing_deposit_amount_sm.value *= 1) / (document.form.dealer_selling_price_amount_sm.value *= 1)) * 10000) / 100;
	}

		document.form.leasing_salv_value_sm.value = Math.round((document.form.dealer_selling_price_sm.value *= 1) * (document.form.leasing_salv_value_percent_sm.value *= 1)) / 100;
		document.form.leasing_salv_value_head_sm.value = Math.round((document.form.dealer_selling_price_head_sm.value *= 1) * (document.form.leasing_salv_value_percent_sm.value *= 1)) / 100;
	document.form.leasing_salv_value_amount_sm.value = (document.form.leasing_salv_value_sm.value *= 1) + (document.form.leasing_salv_value_head_sm.value *= 1);
	if (fieldname == 'leasing_salv_value_sm') {
		document.form.leasing_salv_value_percent_sm.value = Math.round(((document.form.leasing_salv_value_amount_sm.value *= 1) / (document.form.dealer_selling_price_amount_sm.value *= 1)) * 10000) / 100;
	}

		document.form.leasing_rate_sm.value = Math.round(((document.form.dealer_selling_price_sm.value *= 1) * (document.form.leasing_factor_sm.value *= 1)) / 100);
		document.form.leasing_rate_head_sm.value = Math.round(((document.form.dealer_selling_price_head_sm.value *= 1) * (document.form.leasing_factor_sm.value *= 1)) / 100);
	document.form.leasing_rate_amount_sm.value = (document.form.leasing_rate_sm.value *= 1) + (document.form.leasing_rate_head_sm.value *= 1);

	if (document.form.leasing_deposit_amount_sm.value > 0) {
		document.form.leasing_tax_sm.value = Math.round((((document.form.leasing_rate_sm.value *= 1) * (document.form.leasing_month_sm.value *= 1) * (document.form.tax.value *= 1)) / 100) + (((document.form.leasing_deposit_sm.value *= 1) * (document.form.tax.value *= 1)) / 100) + (((document.form.leasing_salv_value_sm.value *= 1) * (document.form.tax.value *= 1)) / 100));
		document.form.leasing_tax_head_sm.value = Math.round((((document.form.leasing_rate_head_sm.value *= 1) * (document.form.leasing_month_sm.value *= 1) * (document.form.tax.value *= 1)) / 100) + (((document.form.leasing_deposit_head_sm.value *= 1) * (document.form.tax.value *= 1)) / 100) + (((document.form.leasing_salv_value_head_sm.value *= 1) * (document.form.tax.value *= 1)) / 100));
		document.form.leasing_tax_amount_sm.value = (document.form.leasing_tax_sm.value *= 1) + (document.form.leasing_tax_head_sm.value *= 1);
	}

	document.form.leasing_deposit_tax_sm.value = (document.form.leasing_deposit_sm.value *= 1) + (document.form.leasing_tax_sm.value *= 1);
	document.form.leasing_deposit_tax_head_sm.value = (document.form.leasing_deposit_head_sm.value *= 1) + (document.form.leasing_tax_head_sm.value *= 1);
	document.form.leasing_deposit_tax_amount_sm.value = (document.form.leasing_deposit_tax_sm.value *= 1) + (document.form.leasing_deposit_tax_head_sm.value *= 1);

//	WFW interner Preis
	document.form.internal_price_amount.value = (document.form.internal_price.value *= 1) + (document.form.internal_price_head.value *= 1);

//	WFW-Verkaufspreis
	document.form.preis_dis.value = (document.form.dealer_selling_price_amount_sm.value *= 1);
	document.form.preis.value = (document.form.preis_dis.value *= 1);
	document.form.selling_price_d.value = document.form.dealer_selling_price_sm.value;
	document.form.selling_price_head_d.value = document.form.dealer_selling_price_head_sm.value;
	document.form.selling_price_amount_d.value = (document.form.selling_price_d.value *= 1) + (document.form.selling_price_head_d.value *= 1);

//	Haendler-Verkaufspreis-Prozent
	if (fieldname == 'dealer_selling_price_sm' || fieldname == 'dealer_selling_price_head_sm') {
		document.form.dealer_selling_price_percent_sm.value = Math.round(((document.form.dealer_selling_price_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;
	}

//	WFW VB Provsionspauschale
	document.form.wfw_profit_percent_sm.value = Math.round(((document.form.wfw_profit_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Vermittlungsprovision
	document.form.commission_sm.value = Math.round((document.form.dealer_selling_price_sm.value *= 1) * (document.form.commission_percent_sm.value *= 1)) / 100;
	document.form.commission_head_sm.value = Math.round((document.form.dealer_selling_price_head_sm.value *= 1) * (document.form.commission_percent_sm.value *= 1)) / 100;
	document.form.commission_amount_sm.value = (document.form.commission_sm.value *= 1) + (document.form.commission_head_sm.value *= 1);

//	Haendlereinkaufspreis
	document.form.dealer_purchase_sm.value = Math.round((document.form.dealer_selling_price_sm.value *= 1) * (document.form.dealer_purchase_percent_sm.value *= 1)) / 100;
	document.form.dealer_purchase_head_sm.value = Math.round((document.form.dealer_selling_price_head_sm.value *= 1) * (document.form.dealer_purchase_percent_sm.value *= 1)) / 100;
	document.form.dealer_purchase_amount_sm.value = (document.form.dealer_purchase_sm.value *= 1) + (document.form.dealer_purchase_head_sm.value *= 1);

//	EK Netto
	document.form.net_cash_amount_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.net_cash_head_sm.value *= 1);
	document.form.net_cash_percent_sm.value = Math.round(((document.form.net_cash_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Tatsächlicher VKP zu Netto-EK
	document.form.realised_price_percent_nc_sm.value = Math.round(((document.form.realised_price_amount_sm.value *= 1) / (document.form.net_cash_amount_sm.value *= 1)) * 10000) / 100;

//	Summe Fracht/Verzollung
	document.form.freight_amount_sm.value = (document.form.freight_sm.value *= 1) + (document.form.freight_head_sm.value *= 1);

//	Summe WFW Intern
//	document.form.wfw_intern_amount_sm.value = (document.form.wfw_intern_sm.value *= 1) + (document.form.wfw_intern_head_sm.value *= 1);

//	Summe WFW Sonstiges
	document.form.wfw_sonst_amount_sm.value = (document.form.wfw_sonst_sm.value *= 1) + (document.form.wfw_sonst_head_sm.value *= 1);

//	Summe EK kalkuliert inkl. Fracht, Intern, Sonst, Rep. kalk
/*
	if (document.form.net_cash_freight.value == 0)
		document.form.net_cash_freight.value = document.form.net_cash.value;
	if (document.form.net_cash_freight_head.value == 0)
		document.form.net_cash_freight_head.value = document.form.net_cash_head.value;
*/
//	document.form.net_cash_freight_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) + (document.form.wfw_intern_sm.value *= 1) + (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_calc_sm.value *= 1);
//	document.form.net_cash_freight_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) + (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_calc_sm.value *= 1);
	document.form.net_cash_freight_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) - (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_calc_sm.value *= 1);

//	document.form.net_cash_freight_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) + (document.form.wfw_intern_head_sm.value *= 1) + (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_calc_head_sm.value *= 1);
//	document.form.net_cash_freight_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) + (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_calc_head_sm.value *= 1);
	document.form.net_cash_freight_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) - (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_calc_head_sm.value *= 1);

	document.form.net_cash_freight_amount_sm.value = (document.form.net_cash_freight_sm.value *= 1) + (document.form.net_cash_freight_head_sm.value *= 1);
	document.form.net_cash_freight_percent_sm.value = Math.round(((document.form.net_cash_freight_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Summe EK kalkuliert eff. Fracht, Intern, Sonst, Rep. durchgefuehrt
//	document.form.net_cash_freight_eff_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) + (document.form.wfw_intern_sm.value *= 1) + (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_acc_sm.value *= 1);
//	document.form.net_cash_freight_eff_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) + (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_acc_sm.value *= 1);
	document.form.net_cash_freight_eff_sm.value = (document.form.net_cash_sm.value *= 1) + (document.form.freight_sm.value *= 1) - (document.form.wfw_sonst_sm.value *= 1) + (document.form.cost_of_repairs_acc_sm.value *= 1);

//	document.form.net_cash_freight_eff_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) + (document.form.wfw_intern_head_sm.value *= 1) + (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_acc_head_sm.value *= 1);
//	document.form.net_cash_freight_eff_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) + (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_acc_head_sm.value *= 1);
	document.form.net_cash_freight_eff_head_sm.value = (document.form.net_cash_head_sm.value *= 1) + (document.form.freight_head_sm.value *= 1) - (document.form.wfw_sonst_head_sm.value *= 1) + (document.form.cost_of_repairs_acc_head_sm.value *= 1);

	document.form.net_cash_freight_eff_amount_sm.value = (document.form.net_cash_freight_eff_sm.value *= 1) + (document.form.net_cash_freight_eff_head_sm.value *= 1);
	document.form.net_cash_freight_eff_percent_sm.value = Math.round(((document.form.net_cash_freight_eff_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	WFW HSP kalkuliert
	document.form.margin_calc_sm.value = (document.form.selling_price_sm.value *= 1) - (document.form.net_cash_freight_sm.value *= 1);

	document.form.margin_calc_head_sm.value = (document.form.selling_price_head_sm.value *= 1) - (document.form.net_cash_freight_head_sm.value *= 1);

	document.form.margin_calc_amount_sm.value = (document.form.margin_calc_sm.value *= 1) + (document.form.margin_calc_head_sm.value *= 1);

	document.form.margin_calc_percent_sm.value = Math.round(((document.form.margin_calc_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	WFW HSP effektiv
	var net_cash = document.form.net_cash_freight_eff_sm.value *= 1;
	var net_cash_head = document.form.net_cash_freight_eff_head_sm.value *= 1;
	if (net_cash == 0)
		var net_cash = document.form.net_cash_sm.value *= 1;
	if (net_cash_head == 0)
		var net_cash_head = document.form.net_cash_head_sm.value *= 1;

	document.form.margin_eff_sm.value = (document.form.selling_price_sm.value *= 1) - net_cash;
	if (document.form.cost_of_repairs_acc_sm.value == 0)
		document.form.margin_eff_sm.value = 0;

	document.form.margin_eff_head_sm.value = (document.form.selling_price_head_sm.value *= 1) - net_cash_head;
	if (document.form.cost_of_repairs_acc_head_sm.value == 0)
		document.form.margin_eff_head_sm.value = 0;

	document.form.margin_eff_amount_sm.value = (document.form.margin_eff_sm.value *= 1) + (document.form.margin_eff_head_sm.value *= 1);
	document.form.margin_eff_percent_sm.value = Math.round(((document.form.margin_eff_amount_sm.value *= 1) / (document.form.selling_price_amount_sm.value *= 1)) * 10000) / 100;

//	Tatsächlicher VKP zu effektivem EK
	document.form.realised_price_percent_mc_sm.value = Math.round(((document.form.realised_price_amount_sm.value *= 1) / (document.form.net_cash_freight_eff_amount_sm.value *= 1)) * 10000) / 100;

//	WFW HSP limit
	document.form.margin_limit_sm.value = (document.form.limit_price_sm.value *= 1) - net_cash;
	if (document.form.cost_of_repairs_acc_sm.value == 0)
		document.form.margin_limit_sm.value = 0;

	document.form.margin_limit_head_sm.value = (document.form.limit_price_head_sm.value *= 1) - net_cash_head;
	if (document.form.cost_of_repairs_acc_head_sm.value == 0)
		document.form.margin_limit_head_sm.value = 0;

	document.form.margin_limit_amount_sm.value = (document.form.margin_limit_sm.value *= 1) + (document.form.margin_limit_head_sm.value *= 1);

	document.form.margin_limit_percent_sm.value = Math.round(((document.form.margin_limit_amount_sm.value *= 1) / (document.form.limit_price_amount_sm.value *= 1)) * 10000) / 100;

}
}

function MM_openBrWindow(theURL,winName,features) {
features=features + 'screenX=0,screenY=0';
  window.open(theURL,winName,features);
}

function Webs_openWindow(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}

function TwoFrames(frame1, url1, frame2, url2)
{
	frame1.location.href = url1;
	frame2.location.href = url2;
}

function senddata(button){
	if(button == "delete") {
		Check = confirm("Wollen Sie diesen Eintrag endgültig löschen?\nBitte beachten Sie, dass die Daten nicht wieder hergestellt werden können.");
		if(Check == false) button = "cancel";
	}
/*
	if(button == "userfile1") {
		var csvFile = "R:/Web/WFW/html/dokumente/Kalkulationen/kalk1.xls";
		var oShell = new ActiveXObject("Wscript.Shell");
		var excelApp = oShell.Run("excel \"" + csvFile + "\"");
	}
*/
  document.form.button.value = button;
}

function pruefen ()
{
	var re_email = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+\.([a-zA-Z]{2,3})$/;
	var email=document.antwort.email.value;
	var re_menge = /^([0-9]{1,5})$/;

	if(document.antwort.a_title.value=="")
	{
		window.alert("Bitte Frage eingeben.");
		document.antwort.a_title.focus();
		document.antwort.sent.value==0;
		return false;
	}

	if(document.antwort.name.value=="")
	{
		window.alert("Bitte Namen eingeben.");
		document.antwort.name.focus();
		return false;
	}
	
	if ((re_email.test(email))==false || email.length==0)
/*	if ((re_email.test(email))==false && email.length > 0)*/
	{
		window.alert("Bitte geben Sie eine korrekte eMail-Adresse ein.");
		document.antwort.email.focus();
		return false;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

