
function calc() {
}

function calc2(o) {
	var c = jQuery("#cost").val();
	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;
	}

	if (o.value=="-") {
		jQuery("#summ").val(0);
				 if (document.getElementById("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = 0;
				}
		return;
	}

	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("discountSpan"))   {
			document.getElementById("discountSpan").innerHTML = d;
			}
	jQuery("#summ").val(t.toFixed(2));
	
	//t.toFixed(2)

}

var discounts = [], userdiscount = 0;

function calc3(o) {
	var c = jQuery("#cost").val();

	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;

		var d = userdiscount;
		for(var i=0;i<discounts.length;i++) if (discounts[i] ) {
			
			if ((discounts[i][1]<=s)) {
				if (discounts[i][0]>d*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("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = d;
				}

		jQuery("#col").val(Math.round(t));
//		alert(c + " "+ d+" "+s);
		//Math.floor(t)
		 //+" "+ d+" "+c+" "+o.value/

	}
	
}
