//Energysavings, default valus
function window_onload() {
	window.form1.text1.value=100
	window.form1.text2.value=8760
	window.form1.text3.value=0.10
	window.form1.text4.value=80
}
	
<!-- Calculationfunction for inverters -->
//Check if ok
function kolla(form)
{
   if (document.form1.belastning.value == "zero")
  {
    document.form1.belastning.focus();    
    alert("Select the load.");
	return (false);
  }
  if (document.form1.text1.value == "")
  {
	document.form1.text1.focus();
    alert("Specify rated motor power.");
    return (false);
  }

  if (document.form1.text2.value == "")
  {
    document.form1.text2.focus();
    alert("Specify operating time per year");
    return (false);
  }
  if (document.form1.text3.value == "")
  {
    document.form1.text3.focus();
    alert("Specify cost of electricity per kWh.");
    return (false);
  }
   if (document.form1.text4.value == "")
  {
    document.form1.text4.focus();
    alert("Specify average rotation requirement per year.");
    return (false);
  }
  if (document.form1.text5.value == "")
  {
    document.form1.text5.focus();
    alert("Specify investment cost for a frequency inverter.");
    return (false);
  }
  return (true);
}

function berakna() {	
	//get info
	var bel = document.form1.belastning.value   //hämta värdet från belastnings ddm
	var A = document.form1.text1.value		// kW
	var B = document.form1.text2.value		// Timmar
	var C = document.form1.text3.value		// Kr
	var D = document.form1.text4.value	 	// %
	var E = document.form1.text5.value		// investering
	
	var bel=document.form1.belastning.value
	if (bel=="pump"){
		var re=/,/g  //regular expression=,
		A=A.replace(re,".")
		B=B.replace(re,".")
		C=C.replace(re,".")
		D=D.replace(re,".")
		E=E.replace(re,".")
		var y=Math.pow((D/100),3) 

		// Formelsamling
		var formel1a=A * y * B * C
		//Köra formel
		formel1a=parseInt(formel1a)
		//Spara till senare kalkyler
		var formel1a_b=formel1a
		document.form2.text6.value=formel1a	

		var formel2a=A * B * 0.80 * C
		formel2a=parseInt(formel2a)
		//Spara till senare kalkyler
		var formel2a_b=formel2a
		document.form2.text7.value=formel2a	

		var formel3a=(formel2a_b - formel1a_b)
		formel3a=parseInt(formel3a)
		document.form2.text8.value=formel3a	

		var formel4a=(E/formel3a)
		document.form2.text9.value=formel4a
		
		commafy() 

	}
	
	else if (bel=="konstant"){
	
		var re=/,/g  //regular expression=,
		
		A=A.replace(re,".")
		B=B.replace(re,".")
		C=C.replace(re,".")
		D=D.replace(re,".")
		E=E.replace(re,".")
		var y=(D/100)
	

		// Formelsamling
		var formel1b=A * y * B * C
		//Köra formel
		formel1b=parseInt(formel1b)
		//Spara till senare kalkyler
		var formel1b_b=formel1b
		document.form2.text6.value=formel1b	

		var formel2b=(A * B  * C)
		formel2b=parseInt(formel2b)
		//Spara till senare kalkyler
		var formel2b_b=formel2b
		document.form2.text7.value=formel2b	

		var formel3b=(formel2b_b - formel1b_b)
		formel3b=parseInt(formel3b)
		document.form2.text8.value=formel3b	

		var formel4b=(E/formel3b)
		document.form2.text9.value=formel4b
		
		commafy() 		
	}
}
//Decimalavrundning
function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ",";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = "0," + whole;
                
        }
        return result;
        
}


//Tusentalsseparering -pump/fläktdrift
function commafy() {
	var re2= /(-?\d+)(\d{3})/
		
	var formel1c = document.form2.text6.value
	while (re2.test(formel1c)) {
		formel1c=formel1c.replace(re2, "$1 $2")
	}
	document.form2.text6.value=formel1c + " euro"
			
	var formel2c = document.form2.text7.value
	while (re2.test(formel2c)) {
		formel2c=formel2c.replace(re2, "$1 $2")
	}
	document.form2.text7.value=formel2c + " euro"
			
	var formel3c = document.form2.text8.value
	while (re2.test(formel3c)) {
		formel3c=formel3c.replace(re2, "$1 $2")
	}
	document.form2.text8.value=formel3c + " euro"
	
	var formel4c = document.form2.text9.value
	formel4c=roundOff(formel4c, 2)
	//var re2=//g  //regular expression=,
		//formel4c=formel4c.replace(re2,",")
	document.form2.text9.value=formel4c + " year"
}

//  End -->
