function updateQty(code) {
	var qty = parseInt($('#qty_'+code).val());
	location.href = 'action.php?act=update_cart&code='+code+'&qty='+qty;
}

$(document).ready(function() {
	$('#urgent_yes').change(function() {
		$('#urgent_date').removeAttr("disabled");
	});
	$('#urgent_no').change(function() {
		$('#urgent_date').attr("disabled", "disabled");
	});

	$('#country_other').change(function() {
		$('#country_other_value').removeAttr("disabled");
		$('#prov').attr('disabled', "disabled");
		$('#prov').removeClass('required_field');
	});
	$('#country_it').change(function() {
		$('#country_other_value').attr("disabled", "disabled");
		$('#prov').removeAttr("disabled");
		$('#prov').addClass('required_field');
	});
	
	$('.placeholder_field').focus(function() {
		this.value = '';
	}).blur(function() {
		if(this.value.length <= 0) {
			this.value = this.defaultValue;
		}
	});
	
	$('#cart_form').submit(function() {
		var send_form = true;
		var totPieces = parseInt($('#cartTotalPieces').val());
		if(totPieces <= 0) {
			alert('Your cart is empty');
			return false;
		}
		
		$(this).find('.required_field').each(function() {
			if(!send_form) return;
			if(this.value.length <= 0 || this.value == 'NULL') {
				alert('Please fill all the required fields');
				this.focus();
				send_form = false;
			}
		});
		
		if(send_form) {
			$(this).find('.retype_field').each(function() {
				if(!send_form) return;
				var v2 = $('#'+this.id+'2').val();
				if(this.value != v2) {
					alert('The two '+this.id+' fields do not match');
					this.focus();
					send_form = false;
				}
			});
		}
		
		if(send_form) {
			$('.placeholder_field').each(function() {
				if(this.value == this.defaultValue) { this.value = ''; }
			});
		}
		
		return send_form;
	});
});

function toggleShippingAddress() {
	var box = $('#shipping_address_box');
	if(box.css('display') == 'none') {
		box.show();
	} else {
		box.hide();
	}
}

function showShippingAddress() {
	var box = $('#shipping_address_box');
	box.show();
}