$(document).ready(function() {
	$("input[name='amount']").keydown(function(event){
		if(!is_numeric_key(event.keyCode)&&!is_functional_key(event.keyCode)||(event.shiftKey&&is_numeric_key(event.keyCode))){
			return false;
		}
	}).keyup(function(){
		price=parseFloat($("#itemDiv1 div.prw div.pr2").text().replace('$',''));
		for( acn=0; acn<10; acn++ ) {
			el = document.getElementById("check" + acn );
			if( el && el.checked ) {
				pprice = document.getElementById( "check"+acn+"-prodprice" ).value;
				vprice = document.getElementById( "check"+acn+"-valueprice" ).value;
				vamount = document.getElementById( "amount"+acn ).value;
				return checked_acc( acn, pprice, vprice*vamount );
			}
		}
		if(!isNaN(price)){
			amOb=$("#itemDiv1 div.marg2 input[name='amount']");
			if(amOb.val()==''){
				amount=0;
			}else{
				amount=parseInt(amOb.val());
			}
			if(isNaN(amount)||amount!=amOb.val()){
				amOb.val(1);
				amount=1;
			}
			amount = amount > 0 ? amount : 1;
			cust_disc = $("#customer_discount").val();
			$("#pricetext").val('$'+simple_round(amount*price));
			$("#pricetextdisc").val('$'+simple_round(amount* ( price - price/100*cust_disc)));
		}
	});
});
function is_functional_key(code){
	if(code==8||code==46||(code>=112&&code<=123)||(code>=35&&code<=40)){
		return true;
	}
}
function is_numeric_key(code){
	if((code>=48&&code<=57)||(code>=96&&code<=105)){
		return true;
	}else{
		return false;
	}
}
function get_cost(value){
	value=parseFloat(value);
	if(!isNaN(value)){
		dif=Math.abs(Math.round(value)-value);
		if(dif>0.0){
			dif1=Math.abs(Math.round(dif*10)-dif*10);
			if(dif1>0.0){
				return '$'+value;
			}else if(dif1==0.0){
				return '$'+value+'0';
			}
		}else if(dif==0.0){
			return '$'+value+'.00';
		}
	}
}
function simple_round( val ) {
	val = Math.round( val * Math.pow(10,2)) / Math.pow(10,2);
	if( (val+'').match( /\..$/g ))
		val = val + '' + '0';
	if( 0>(val+'').indexOf('.')) {
		val = val + '' + '.00';
	}
	return val;
}

