$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

jQuery.fn.center = function()
{
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
};


function lb_messages(h2, p, btn, focus){
    var lb = "#lb_message";
    var lb_h2 = lb + "_h2";
    var lb_p = lb + "_p";
    var lb_btn = lb + "_btn";
    var focus_field = lb + "_focus";
    
    $(lb_h2).text(h2);
    $(lb_p).text(p);
    $(lb_btn).text(btn);
    $(focus_field).attr('value',focus);
    
    $(lb).center().show();
};

function valid_values(form, fields){
    var valid = true;
    for (field in fields) {
        var field_value = $(field).val();
        if (field_value == '' || field_value == undefined){
            valid = false;
        };
    };
    return valid;
};

function get_values(tool_list) {
    for (i in tool_list) {
        
        var field = tool_list[i];
        var value = $.cookie(field);
        if (value==null) value = '';
        if (field=='gender') { 
            if (value=='0' || value=='1') {
                $("input[name=input_spol]")[parseInt(value)].checked = true;
            }; 
        } else {
            var field_id = "#"+field;
            $(field_id).val(value);
        };
    };
};

function set_values(tool_list) {
    for (i in tool_list) {
        var field = tool_list[i];
        var field_id = "#"+field;
        if (field=='gender') {
            var value = $("input[name=input_spol]:checked").val();
        } else {
            var value = $(field_id).val();
        };
        $.cookie(field, value, { expires: 30});
    };
}

$(document).ready(function() {
    $('#lb_message_btn').click(function(){
        $('#lb_message').hide();
        if ($('#lb_message_focus').attr('value')) {
            $($('#lb_message_focus').attr('value')).focus();
        };
        return false;
    });    
});
    
function calculate_bmi(height, weight) {
    return (weight/(Math.pow(height/100, 2))).toFixed(1);
};

function dotmare(n) {
    if (n.indexOf(",")>-1) {n=n.replace(/,/,".");};
    return n;
};
    
    
