$(document).ready(function() {
    
    function calculate(volume, weight) 
    {
        var iBiggest = 0; 
        var k = 167; 

    
        volume = _prependFloat(volume);
        weight = _prependFloat(weight);
    
        
        iBiggest = volume * k; 
        iBiggest = Math.max(iBiggest, weight); 
        $('#paid_load_weight_is').val(tomoney(iBiggest));
    }
    
    function _prependFloat(value) 
    {
        var reg=/,/g; 
        return value.replace(reg, "."); 
    }
    
    function tomoney(amount) 
    { 
        var a=round(amount); 
        return (a==Math.floor(a))?a+'.00':((a*10==Math.floor(a*10))?a+'0':a); 
    } 
    
    function round(number,decimal) 
    { 
        var d=(decimal?decimal:2); 
        return Math.round(number*Math.pow(10,d))/Math.pow(10,d); 
    }

    
    function error() 
    {
        alert(error_message);
    }
    
    $('#calculate').click(function() {
        var volume = $('#load_volume').val();
        var weight = $('#load_weight').val();
        
        if (volume && weight) {
            calculate(volume, weight);
        } else {
            error();
        }
        return false;
    });
    
});