ja.include('jqarta.validator.js');

$(document).ready(function()
{
	$qty = $('.input-quantity');
	$firtload=true;
	if($qty.length)
	{
		$qty.keydown(function(e)
		{
	
			if(!((e.keyCode>=49 && e.keyCode<=57) ||  e.keyCode==8  ||  e.keyCode==46))
			{
				return false;
			}
			
		}).bind('blur keyup', function(e)
		{
			if(this.value=='' || this.value==0)
				this.value=1;
			price = parseFloat(this.getAttribute('price'));
			if(!$firtload)
			$('#_'+ this.id).text( (price * this.value).formatCurrency() );
			else
			$('#_'+ this.id).text( (price * this.value) );
			
			var total=0;
			$qty.each(function()
			{
				total += parseFloat(this.getAttribute('price')) * this.value;
			});
			
			$('#price_total').text( ($firtload)?total: total.formatCurrency() );
		});
		
		$qty.trigger('blur');
	
	}
	$('.currency').each(function()
	{
		$el = $(this)
		var p = parseFloat($el.text());
		$el.text( p.formatCurrency() );
		
	});
	$firtload=false;
	//$('form').validate();
	
});
