
//coco

function checkIfNumber(rVal_compute)
{
    inLen = rVal_compute.length;
    
    for(var i=0; i<inLen; i++) {
        var ch = rVal_compute.substring(i,i+1);

        if (! (ch> "0" || "9"> ch || ch == ".") ) 
        {                         
            alert("Invalid Input, field resetting");
            return -1;
        }
    }
    
    return rVal_compute;
} 

function updateResultcompute()
{   
    document.compute.results_compute.value = doWorkcompute();
    window.focus();
}


function doWorkcompute()
{  
    
    var width = checkIfNumber(document.compute.rm_width_compute.value); // check input
    if (width == -1) {                                           // -1 means invalid input
        document.compute.rm_width_compute.value = 0;                    // reset form field
        width = 0;                                               // zero out variable
    }
        
    var length = checkIfNumber(document.compute.rm_length_compute.value);
    if (length == -1) {
        document.compute.rm_length_compute.value = 0;
        length = 0;
    }
        
    var cost_ft_compute = checkIfNumber(document.compute.cost_ft_compute.value);
    if (cost_ft_compute == -1) {
        document.compute.cost_foot.value = 0;
        cost_ft_compute = 0;
    }
        
    var ret_val_compute = Math.round((width * length)* cost_ft_compute);      // main equation  
    return ret_val_compute;
}


