$(document).ready(function(){
	
	var count = 0;
	var totalprice;
	
	$('#add_to_cart').click(function(e){
		//e.preventDefault();
	})
	
	$('#CartVoucher').click(function(){
		if($(this).val() == "discount voucher code"){
			$(this).val("");
		}
	});
	
	$('#CartVoucher').blur(function(){
		if($(this).val() == ""){
			$(this).val("discount voucher code");
		}
	});
	
	function format(number) {
		return Math.max(0,number).toFixed(0).replace(/(?=(?:\d{3})+$)(?!^)/g,',');
	}
 
	$('.radio').click(function(e) {
		var checked = $(this).attr('checked');
		
		if (checked) count++;
		else if (count) count--;
		
		var rangeprice = $('#rangeprice_hidden').val();
		var totalprice = rangeprice * count;
		$('#totalprice').html(format(totalprice.toFixed(0)));
		$('#spanid').html(count);
		$(this).next().children('[alt="CartSelected"]').val(checked);
		console.log(checked);
	});	
	
	function addCart(){

		//use ajax to submit form fields to controllers action: create_basic_add
		$.ajax({
			type:"POST",
			url:'google/',
			dataType: 'json',
			data:data, //contains validation errors
			success:create_basic_callback
		});
		return false;
	};
});
