function calc() {
}

function calc_level() {
        
        var /*ser = $("#server_id").val(), */lev_1 = 1*$("#item_level1").val(), lev_2 = 1*$("#item_level2").val();

        if (lev_1*1>=lev_2*1) {
                //$("#item_level2").val(lev_1+1);
                $("#days_need").html("---");
                $("#hours_need").html("---");
                $("#item_sum_html").html("---");
                return;
        }
        var id = $("#item_id").val();
        var s = 0,tim = 0, str="";
        
        for (var i=lev_1; i<lev_2;i++) {
                if ((typeof(profs[id].l[i])!="undefined")&&(profs[id].l[i].p>0))  {
                        s += 1*profs[id].l[i].p;
                        s = Math.round(s*100)/100;
                } else {
                        $("#item_sum").val("---");
                        alert(i);
                        return;
                }
                if ((typeof(profs[id].l[i])!="undefined")&&(profs[id].l[i].t>0))  {
                        
                        tim+=profs[id].l[i].t;
                }
                
        }
        

        var t = s;
        var d = userdiscount;
        
        for(var i=0;i<discounts.length;i++) if (discounts[i]) {
                if (discounts[i][1]*1<=t) {
                        if (discounts[i][0]>d)
                                d = discounts[i][0];//+" - "+discounts[i][1];
                } else {
                        break;
                }
        }
        if (userdiscount>d) {
                        d = userdiscount;
                }
        if (d)  {
                t = t-d*t/100;
                
        }
        var rat = 1;
        
        if (document.getElementById("discountSpan"))   {
                        document.getElementById("discountSpan").innerHTML = d;
        }
                        if (selectedCurrency)
        if(allCurrencies[selectedCurrency]>0) {
                        rat = allCurrencies[selectedCurrency];
                        t = t * rat;
        }
        //$("#item_sum").val(t);
        $("#days_need").html(Math.floor(tim/24));
        $("#hours_need").html(tim%24);
        var te = $("#item_price_hidden").val()*rat;
        if ((te>0)&&(te>t)) {
                t = te;
                $("#need_more_help").show();
        } else {
                $("#need_more_help").hide();
        }
        $("#item_sum_html").html(Math.round(t*100)/100);
}


function calc2(o) {
        var c = jQuery("#cost").val()*1;
        if(Math.floor(o.value)!=o.value)
                o.value = Math.floor(o.value);

        
        if ((c<=0)||(o.value<0)) {
                jQuery("#summ").val(0);
                o.value = 0;
                                 if (document.getElementById("discountSpan")) {
                                document.getElementById("discountSpan").innerHTML = 0;
                                }
                return;
        }
        jQuery("#cost").val(c);

        if (o.value=="-") {
                jQuery("#summ").val(0);
                                 if (document.getElementById("discountSpan")) {
                                document.getElementById("discountSpan").innerHTML = 0;
                                }
                return;
        }
        o.value = Math.floor(o.value)*1;

        var d = userdiscount;



        var t = c*(Math.round(o.value*1));
        for(var i=0;i<discounts.length;i++) if (discounts[i]) {
                if (discounts[i][1]*1<=t) {
                        if (discounts[i][0]>d)
                                d = discounts[i][0];//+" - "+discounts[i][1];
                } else {
                        break;
                }
        }
        if (d)  {
                t = t-d*t/100;
                
        }
        if (document.getElementById("discountP"))   {
                        document.getElementById("discountP").innerHTML = d+"%";
                        }
        if (selectedCurrency)
                if(allCurrencies[selectedCurrency]>0)
                        t = t * allCurrencies[selectedCurrency];

        jQuery("#summ").val(t.toFixed(2));
        
        //t.toFixed(2)

}

var discounts = [], userdiscount = 0;

function calc3(o) {
        var c = jQuery("#cost").val()*1;

        if ((c<=0)||(o.value<0)) {
                jQuery("#col").val(0);
                o.value = 0;
                                 if (document.getElementById("discountSpan")) {
                                document.getElementById("discountSpan").innerHTML = 0;
                                }
        } else {
                var s = o.value.replace(",",".");
                var t = 1.0*(s)/c;
                                if (selectedCurrency)
                        if(allCurrencies[selectedCurrency]>0)
                                t = t / allCurrencies[selectedCurrency];


                var d = userdiscount;
                for(var i=0;i<discounts.length;i++) if (discounts[i] ) {
                        
                        if ((discounts[i][1]<=s)) {
                                if (discounts[i][0]>c*1)
                                        d = discounts[i][0];//+" - "+discounts[i][1];
                        } /*else if ((((o.value*100/(100-discounts[i][0]))/c>=discounts[i][1]))&&(d<discounts[i][0])) {
                                d = discounts[i][0];
                                break;
                        }*/
                }

                if (d){
                        t = t*100/(100-d);
                        

                 }
                         if (document.getElementById("discountP"))   {
                        document.getElementById("discountP").innerHTML = d+"%";
                        }


                jQuery("#col").val(Math.round(t));
                jQuery("#cost").val(c);
//              alert(c + " "+ d+" "+s);
                //Math.floor(t)
                 //+" "+ d+" "+c+" "+o.value/

        }
        
}
