_konverter = {};

_konverter.comma_to_dot = function(str) {
    return parseFloat(str.replace(',', '.'));
};

// http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
// example 1: number_format(1234.5678, 2, '.', '');
// returns 1: 1234.57
_konverter.number_format = function(number, decimals, dec_point, thousands_sep) {
    var i, j, kw, kd, km;
    var neg = "";
    // Input sanitation and defaults
    if (isNaN(decimals = Math.abs(decimals))) {
        decimals = 2;
    }
    if (dec_point == undefined) {
        dec_point = ".";
    }
    if (thousands_sep == undefined) {
        thousands_sep = ",";
    }
    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
    if (i.substr(0,1) == "-") {
        number = Math.abs(number);
        neg = "-";
        i = i.substr(1);
    }
    if ((j = i.length) > 3 ) {
        j = j % 3;
    } else {
        j = 0;
    }
    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
    return neg + km + kw + kd;
};

_konverter.compute = function() {
    var in_val, result;
    in_val = this.comma_to_dot($('#in').val());
    if (in_val > 0) {
        result = this.number_format((in_val * $('#curr-from').val()) / $('#curr-to').val(), 2, ',', '.');
        $('#out').val(result);
    }
};