/* ---------------------------------------------------------------------
/
/     toolbox kessel  - Calculating Air Receiver Size - js - /     
/     this file is not to be localized for different countries
/     03.01.05 marion.koerner@kaeser.com
/     04.12.06 mko
/  -------------------------------------------------------------------- */


function auslastung(){
  //Berechnung der Liefermenge des Kompressors V2 aufgrund von der Auslastung des Kompressors
  var V1 = parseFloat(window.document.Rechnen.V1.value);
  var AK = parseFloat(window.document.Rechnen.AK.value);
  var V2 = 0;
  V2 = V1 / 100 * AK;
  V2 = Math.round(V2*1000)/1000;
  window.document.Rechnen.V2.value = V2;
  Auswahl();
}

function auslastung1(){
  //Berechnung der Auslastung des Kompressors abhängig von der Liefermenge des Kompressors im Verhältnis zur Gesamtliefermenge V1
  var V1 = parseFloat(window.document.Rechnen.V1.value);
  var AK = 0;
  var V2 = parseFloat(window.document.Rechnen.V2.value);
  AK = V2 * 100 / V1;
  AK = Math.round(AK*1000)/1000;
  window.document.Rechnen.AK.value = AK;
  Auswahl();
}

function Auswahl(){
  var V1= parseFloat(window.document.Rechnen.V1.value);
  var V2= parseFloat(window.document.Rechnen.V2.value);
  var AF= parseFloat(window.document.Rechnen.AF.value);
  
  if(V1!=0){
    AF= V2/V1;
  }

  window.document.Rechnen.AF.value= AF;
  Volumen2()
}

function Volumen2(){ 
  var V1= parseFloat(window.document.Rechnen.V1.value);
  var V2= parseFloat(window.document.Rechnen.V2.value);
  var Z= parseFloat(window.document.Rechnen.Z.value);
  var AF= parseFloat(window.document.Rechnen.AF.value);
  var Pmax= parseFloat(window.document.Rechnen.Pmax.value);
  var Pmin= parseFloat(window.document.Rechnen.Pmin.value);
  var Vbb = 0;

  //Umrechnung, wenn US
  if (window.document.Rechnen.ISOUS[1].checked == true) {
    V1 = V1 / 35.31467;
    V2 = V2 / 35.31467;
    Pmax = Pmax / 14.5;
    Pmin = Pmin / 14.5;
  }

  Vbb= ((V1*(AF-(AF*AF)))/((Z/60)*(Pmax-Pmin)));
  Vbb= Math.round(Vbb*1000)/1000;
  //alert(V2 + " " + V1);

  //Zurueckrechnung, wenn US
  if (window.document.Rechnen.ISOUS[1].checked == true) {
    Vbb = Vbb * 264.1721;
  }
  
  Vbb = Math.round(Vbb*100)/100;

  if (V2 <= V1) {
    window.document.Rechnen.Vbb.value= Vbb;
  } else {
    window.document.Rechnen.Vbb.value = "V2 > V1"
  }
}

function Ergebnis(){
  var v= window.document.Rechnen.v.value;
  var t= window.document.Rechnen.t.value;
  var max= window.document.Rechnen.max.value;
  var min= window.document.Rechnen.min.value;
  var Vb = window.document.Rechnen.Vb.value;

  //Umrechnung wenn US
  if (window.document.Rechnen.ISOUS[1].checked == true) {
    v = v / 35.31467;
    max = max / 14.5;
    min = min / 14.5;
  }

  if((max-min)<=0 ){
    Vb= "Error";
  } else {
    Vb = v*t/(max-min);
  } 

  if (window.document.Rechnen.ISOUS[1].checked == true) {
    Vb = Vb * 264.1721;
  }
 
  Vb = Math.round(Vb*100)/100;  
    
  window.document.Rechnen.Vb.value= Vb;
}

function Iso_Us()
{
  if (window.document.Rechnen.ISOUS[1].checked == true) {
    us();
  } else { 
    iso(); 
  }
}

function us() {
  window.document.getElementById("volu").firstChild.nodeValue = "cfm"; 
  window.document.getElementById("lmgk").firstChild.nodeValue = "cfm"; 
  window.document.getElementById("lmk").firstChild.nodeValue = "cfm"; 
  window.document.getElementById("bd").firstChild.nodeValue = "psig"; 
  window.document.getElementById("ad").firstChild.nodeValue = "psig"; 
  window.document.getElementById("bed").firstChild.nodeValue = "psig"; 
  window.document.getElementById("ed").firstChild.nodeValue = "psig"; 
  window.document.getElementById("bvolu").firstChild.nodeValue = "gallon"; 
  window.document.getElementById("bvolu1").firstChild.nodeValue = "gallon"; 

  window.document.Rechnen.v.value = 0;
  window.document.Rechnen.t.value = 0; 
  window.document.Rechnen.max.value = 0;
  window.document.Rechnen.min.value = 0;
  window.document.Rechnen.Vb.value = 0;
  window.document.Rechnen.V1.value = 0;
  window.document.Rechnen.V2.value = 0; 
  window.document.Rechnen.Pmax.value = 0;
  window.document.Rechnen.Pmin.value = 0;
  window.document.Rechnen.Z.value = 0;
  window.document.Rechnen.AK.value = 50;
  window.document.Rechnen.AF.value = 0; 
  window.document.Rechnen.Vbb.value = 0;

}

function iso() {
  window.document.getElementById("volu").firstChild.nodeValue = "m³/min"; 
  window.document.getElementById("lmgk").firstChild.nodeValue = "m³/min"; 
  window.document.getElementById("lmk").firstChild.nodeValue = "m³/min"; 
  window.document.getElementById("bd").firstChild.nodeValue = "bar"; 
  window.document.getElementById("ad").firstChild.nodeValue = "bar"; 
  window.document.getElementById("bed").firstChild.nodeValue = "bar"; 
  window.document.getElementById("ed").firstChild.nodeValue = "bar"; 
  window.document.getElementById("bvolu").firstChild.nodeValue = "m³"; 
  window.document.getElementById("bvolu1").firstChild.nodeValue = "m³"; 

  window.document.Rechnen.v.value = 0;
  window.document.Rechnen.t.value = 0; 
  window.document.Rechnen.max.value = 0;
  window.document.Rechnen.min.value = 0;
  window.document.Rechnen.Vb.value = 0;
  window.document.Rechnen.V1.value = 0;
  window.document.Rechnen.V2.value = 0; 
  window.document.Rechnen.Pmax.value = 0;
  window.document.Rechnen.Pmin.value = 0;
  window.document.Rechnen.Z.value = 0;
  window.document.Rechnen.AK.value = 50;
  window.document.Rechnen.AF.value = 0; 
  window.document.Rechnen.Vbb.value = 0;

}
