$(document).ready(function(){

    /**
     * razeni
     *
     */
    $("form#frazeni select").change(function(){
        $("form#frazeni").submit();
    });
    
    
	/**
	 * formatovani ceny
	 * @param String nStr
	 */
    function addCommas(nStr){
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ' ' + '$2');
        }
        return x1 + x2;
    }
    
    
    /**
     *  prepocet a formatovani ceny pri zmene varianty 
     */
    $("input[name=varianta]").click(function(){
        if ($(this).attr("checked")) {
            var varianta = $(this).val();
            var cena = $("input#" + varianta + "").val();
            if (cena != '') {
                num = parseInt(cena);
                result = addCommas(num.toFixed(0));
				result = result + '&nbsp;Kč';
                $("#produkt-cena").html("" + result + "");
            }
        }
    });
    
});

