

var grasscost = '0'; 
var currencysymbol = '£'; 
var vat_rate = 1.175; 


function calculate_cost() { 
            //alert("calculate cost!"); 
            // cost = width x length x quantity x grasscost 


            subtotal = 0; 
    radios = document.getElementsByName('rollwidth'); 
    for (i = 0; i < radios.length; i++) { 
                        if (radios[i].checked) rollwidth = radios[i].value; // now we know the width 
            } 
            subtotal = rollwidth; 


            element = document.getElementById('itemcode'); // this is the length 
            selectvalue = element.selectedIndex; 
            subtotal = subtotal * selectvalue; 


            element = document.getElementById('quantity'); // now the quantity 
            totalarea = subtotal * element.value; 




            element = document.getElementById('area'); // now the quantity 
            if (element) 
            { 
                        element.innerHTML = totalarea.toFixed(0); 
            } 


            totalcost = grasscost * totalarea; 


    element = document.getElementById('exvatprice'); 
            element.value = currencysymbol + totalcost.toFixed(2); 
            // now add VAT uplift  to totalcost 
            totalcost = totalcost * vat_rate; 
    element = document.getElementById('incvatprice'); 
            element.value = currencysymbol + totalcost.toFixed(2); 




} 


function attachEvent() { 
            // need to attach events to our form parameters 
            element = document.getElementById('itemcode'); 
            element.onchange = calculate_cost; 


            element = document.getElementById('quantity'); 
            element.onkeyup = calculate_cost; 


    radios = document.getElementsByName('rollwidth'); 
    for (i = 0; i < radios.length; i++) { 
                                    radios[i].onclick = calculate_cost; 
            } 


} 


function display_cost() { 
            cost = grasscost * 1; // forces conversion to numeric value 
            document.write(currencysymbol + cost.toFixed(2)); 
} 



