// JavaScript Document
function getVal(obj){
        
                if (parseInt(document.forms['mainForm'][obj].value, 10) == 'NaN'){
                        return -1;
                } else {
                        return new Number(document.forms['mainForm'][obj].value);
                }        
        }
 
        function round(number,x) {
                // rounds number to x decimal places, defaults to 2
                x = (!x ? 2 : x);
                return Math.round(number*Math.pow(10,x))/Math.pow(10,x);
        }        
        
        function calc(){
                var f = document.mainForm;
                var vol = getVal('thickness') * getVal('width') * getVal('length') * getVal('pieces'); 
                var volMCubed, volPerPiece, priceTotal, pricePerPiece,priceLinearM ,price100LinerM
                
                
                volMCubed = vol/1000000000;
                volPerPiece = volMCubed / getVal('pieces')
                priceTotal = getVal('pricePerMCubed') * volMCubed
                pricePerPiece = priceTotal / getVal('pieces')
                priceLinearM = priceTotal /( getVal('length')/1000 * getVal('pieces'))
                price100LinearM = priceLinearM * 100
                
                f.volMCubed.value = round(volMCubed, 3);
                f.volPerPiece.value = round(volPerPiece, 4);
                f.priceTotal.value = round(priceTotal, 2);
                f.pricePerPiece.value = round(pricePerPiece, 2);
                f.priceLinearM.value = round( priceLinearM,2)
                f.price100LinerM.value = round( price100LinearM , 2)
 
        }