var bcolor = "#000000";
var bsize = "1";
var hcolor = "#000000";
var tcolor = "#000000";
var bgcolor = "#d5d5d5";
var btcolor = "#eb590e";

function calculate(){
        var result = document.getElementById('result');
        var weight = document.getElementById('weight');
        var male = document.getElementById('male');
        var beer = document.getElementById('beer');
        var wine = document.getElementById('wine');
        var cocktail = document.getElementById('cocktail');
        var result_image = document.getElementById('result_image');

        var C = 0;
        var A = 0;
        var r = 0.6;
        if(male.checked)
                r = 0.7;
        if(beer.value.length > 0)
                A += beer.value  * 33 * 4.6 * 0.08;
        if(wine.value.length > 0)
                A += wine.value  * 20 * 12 * 0.08;
        if(cocktail.value.length > 0)
                A += cocktail.value  * 60 * 8 * 0.08;
        if(!isNaN(A))
                C = A / weight[weight.selectedIndex].value * r;
        if(C.toFixed(2))
                C = C.toFixed(2);
        if (C >= 4)
                result_image.src = "promille/images/image5.jpg";
        else if (C >=3 )
                result_image.src = "promille/images/image5.jpg";
        else if (C >=2.5 )
                result_image.src = "promille/images/image4.jpg";
        else if (C >=2 )
                result_image.src = "promille/images/image4.jpg";
        else if (C >=1.5 )
                result_image.src = "promille/images/image4.jpg";
        else if (C >=1 )
                result_image.src = "promille/images/image3.jpg";
        else if (C >=0.8 )
                result_image.src = "promille/images/image3.jpg";
        else if (C >=0.5 )
                result_image.src = "promille/images/image1.jpg";
        else if (C >=0.3 )
                result_image.src = "promille/images/image1.jpg";
        else if (C >=0 )
                result_image.src = "promille/images/image0.jpg";
        result.innerHTML = C;

        return null;
}





window.document.write('');

window.document.write('<table width="210" border="'+ bsize +'" cellspacing="0" cellpadding="0" bordercolor="'+bcolor+'" bgcolor="'+bgcolor+'" >');
window.document.write('  <tr >');
window.document.write('    <td style="padding:5px">');
window.document.write('      <div align="center" id="result"></div>');
window.document.write('      <center>');
window.document.write('                        <img src="promille/images/logo.jpg" id="result_image" border="1" alt="">');
window.document.write('      </center>');
window.document.write('      <table width="210" border="0" cellspacing="0" cellpadding="0">');
window.document.write('        <tr>');
window.document.write('          <td class="calc_header"><b>Anzahl der Getränke:</b></td>');
window.document.write('        </tr>');
window.document.write('      </table>');
window.document.write('      <table width="210" border="0" cellspacing="0" cellpadding="0">');
window.document.write('        <tr> ');
window.document.write('          <td width="119"> ');
window.document.write('            <input type="text" class="form" name="beer" id="beer" size="6">');
window.document.write('          </td>');
window.document.write('          <td width="131">Bier (4.6%)</td>');
window.document.write('        </tr>');
window.document.write('        <tr> ');
window.document.write('          <td width="119"> ');
window.document.write('            <input type="text" class="form" name="wine" id="wine" size="6">');
window.document.write('          </td>');
window.document.write('          <td width="131">Wein (12%)</td>');
window.document.write('        </tr>');
window.document.write('        <tr> ');
window.document.write('          <td width="119"> ');
window.document.write('            <input type="text" class="form" name="cocktail" id="cocktail" size="6">');
window.document.write('          </td>');
window.document.write('          <td width="131">Cocktails (8%)</td>');
window.document.write('        </tr>');
window.document.write('      </table>');
window.document.write('      <table width="210" border="0" cellspacing="0" cellpadding="0">');
window.document.write('        <tr>');
window.document.write('          <td width="119"> ');
window.document.write('            <select name="select" class="form" id="weight"></select>');
window.document.write('          </td>');
window.document.write('          <td width="131">Gewicht</td>');
window.document.write('        </tr>');
window.document.write('      </table>');
window.document.write('      <br><b>Geschlecht</b>');
window.document.write('      <table width="210" border="0" cellspacing="0" cellpadding="0">');
window.document.write('        <tr>');
window.document.write('          <td>');
window.document.write('            <input type="radio" name="gender" id="female" checked="true">');
window.document.write('            Weiblich</td>');
window.document.write('          <td>');
window.document.write('            <input type="radio" name="gender" id="male">');
window.document.write('            Männlich </td>');
window.document.write('        </tr>');
window.document.write('      </table>');
window.document.write('      <p>');
window.document.write('        <input type="submit" onclick="calculate();" style="background-color:'+btcolor+'" name="Abschicken" value="Berechnen">');
window.document.write('      </p>');
window.document.write('    </td></font>');
window.document.write('  </tr>');
window.document.write('</table>');

var weight = document.getElementById('weight');
for(i=0; i<111; i++)
        weight.options[i] = new Option(i+40+' kg',i+40);