var CO2Faktor = 0;
var Ind       = 0;
var H         = 0;

//**********************************************************************
function ResetErgebnis()
{
   window.document.FormEB.Edit_Liter.value = "";
   window.document.FormEB.Edit_Geld.value  = "";
   window.document.FormEB.Edit_CO2.value   = "";
}

//**********************************************************************
function SetUalt()
{
   Ind  = document.FormEB.LB_UwAlt.selectedIndex;
   document.FormEB.Edit_U.value = document.FormEB.LB_UwAlt.options[Ind].value;
   ResetErgebnis();
}

//**********************************************************************
function SetUNeu()
{
   Ind     = document.FormEB.LB_UwNeu.selectedIndex;
   document.FormEB.Edit_UNeu.value = document.FormEB.LB_UwNeu.options[Ind].value;;
   ResetErgebnis ();
}

//**********************************************************************
function SetHeizwerte()
{
   Ind  = document.FormEB.LB_Energieart.selectedIndex;
   var i = document.FormEB.LB_Energieart.options[Ind].value;
   if (i == 1) // Öl
   {
   document.FormEB.Edit_Preis.value= 40;
   H = 9.92;
   CO2Faktor = 2.7; // kg/l
   }
   
   if (i == 2) // Erdgas
   {
   document.FormEB.Edit_Preis.value= 50;
   H = 10.0;
   CO2Faktor = 2.22; // kg/m3
   }
   
   if (i == 3) // Flüssiggas
   {
   document.FormEB.Edit_Preis.value= 60;
   H = 12.87;
   CO2Faktor = 3.08; // kg/kg
   }
 
   ResetErgebnis();
}


//**********************************************************************
function BerechneErgebnis()
{
 // die Funktion geht nicht
 //if (window.document.FormEB.RB_Glas[0].Checked == true) UN = 5.8
 //  else
 //if (window.document.FormEB.RB_Glas[1].Checked == true) UN = 3.0;
  //SetHeizwerte (); 
  Ind       = document.FormEB.LB_Energieart.selectedIndex;
  var ETyp  = document.FormEB.LB_Ort.options[Ind].value;

  Ind       = document.FormEB.LB_Ort.selectedIndex;
  var G     = document.FormEB.LB_Ort.options[Ind].value;
  var F     = document.FormEB.Edit_F.value;
  var UN    = document.FormEB.Edit_UNeu.value;
  UA        = document.FormEB.Edit_U.value;
  var W     = document.FormEB.Edit_W.value;
  //alert(UA);
  //alert(UN);
  //alert(F);
  //alert(G);
  //alert(H);
  //alert(W);
  var Einheit = Math.round(((UA-UN)*F*G*24) /(10*H*W));
  var Geld  = Einheit * document.FormEB.Edit_Preis.value / 100;
  var CO2   = Math.round(Einheit * CO2Faktor );
  document.FormEB.Edit_Liter.value = Einheit ;
  document.FormEB.Edit_Geld.value  = Geld;
  document.FormEB.Edit_CO2.value   = CO2;

}

//**********************************************************************
function UWertInfo()
{
  alert("Fenster mit Isolierglas ohne Beschichtung\n\n" + 
        "2.80 W/m² K  - Kunststoff- und Holzfenster\n" +
        "2.90 W/m² K  - Aluminiumfenster\n" +
        "3.20 W/m² K  - sonstige Fenster, z.B. Stahl oder Beton\n\n" +
        "\n\n" + 
        "Fenster mit Einfachglas\n\n" +
        "4.80 W/m² K  - Kunststoff- und Holzfenster\n" +
        "5.00 W/m² K  - Aluminiumfenster\n" +
        "5.00 W/m² K  - sonstige Fenster, z.B. Stahl oder Beton");
        }

//**********************************************************************

function PruefenInt(Element,ElementWert)
 {
 ResetErgebnis(); 
 z = (1==1);
 z=iCheck(ElementWert);
 if(!z)
   {
   Element.focus();
   alert('Dies ist kein gültiger Wert!');
   return false;
   }
  return true;
 }

//**********************************************************************

function PruefenFloat(Element,ElementWert)
 { 
 ResetErgebnis(); 
 z = (1==1);
 z=fCheck(ElementWert);
 if(!z)
   {
   Element.focus();
   alert('Dies ist kein gültiger Wert!');
   return false;
   }
  return true;
 }

//**********************************************************************

function fCheck(s)
 {
 n='.1234567890';
 for(var i=0;i<s.length;i++)
  if((n.indexOf(s.charAt(i))==-1))return false;
 return true;
 }

//**********************************************************************

function iCheck(s)
 {
 n='1234567890';
 for(var i=0;i<s.length;i++)
  if((n.indexOf(s.charAt(i))==-1))return false;
 return true;
 }

//**********************************************************************
function UWertInfo() 
{ 
  alert("Fenster mit Isolierglas ohne Beschichtung\n\n" + "2.80 W/m² K - Kunststoff- und Holzfenster\n" + "2.90 W/m² K - Aluminiumfenster\n" + "3.20 W/m² K - sonstige Fenster, z.B. Stahl oder Beton\n\n" + "\n\n" + "Fenster mit Einfachglas\n\n" + "4.80 W/m² K - Kunststoff- und Holzfenster\n" + "5.00 W/m² K - Aluminiumfenster\n" + "5.00 W/m² K - sonstige Fenster, z.B. Stahl oder Beton"); 
}

