Element.observe(document,"dom:loaded", function(){
});

function deliveryType() {
	$('basket').setOpacity(0.2);
    if($F('deliveryType')=='express') {
        if(!confirm("This delivery type may incur a charge from customs.")) {
            $('basket').setOpacity(1);
            $('deliveryType').setValue('standard');
            return false;
        }
    }
	new Ajax.Request('ajax/selectDeliveryType.php', {method: 'post', parameters: {deliveryType: $F('deliveryType')}, onSuccess: show_basket, onFailure: show_basket_fail});
}
function removeProd(id) {
	if (!confirm("Please confirm you wish to remove this item from your basket.")) return;
	$('basket').setOpacity(0.2);
	new Ajax.Request('ajax/removeFromBasket.php', {method: 'post', parameters: {giftVoucher: 0, pID: id}, onSuccess: show_basket, onFailure: show_basket_fail});
}
function removeGiftVoucher(key) {
	if (!confirm("Please confirm you wish to remove this item from your basket.")) return;
	$('basket').setOpacity(0.2);
	new Ajax.Request('ajax/removeFromBasket.php', {method: 'post', parameters: {giftVoucher: 1, key: key}, onSuccess: show_basket, onFailure: show_basket_fail});
}
function update_quantity(id, act) {
	$('basket').setOpacity(0.3);
	perform_update_quantity(id, act);	
}
function perform_update_quantity(id, act) {
	var formData = $('quantity_form-'+id).serialize(true);
	formData.q = act;
	new Ajax.Request('ajax/updateBasket.php', {method: 'post', parameters: formData, onSuccess: show_basket, onFailure: show_basket_fail});
}

function edit_quantity(id) {
	$('quantity_0-'+id).hide();
	$('quantity_1-'+id).appear({ duration: 0.5 });
}
function add_giftbox() {
	$('basket').fade({ to:0.3,duration: 0.3 });
	new Ajax.Request('ajax/addGiftBox.php', {method: 'post', onSuccess: show_basket, onFailure: show_basket_fail});
}
function remove_giftbox() {
	$('basket').fade({ to:0.3,duration: 0.3 });
	new Ajax.Request('ajax/removeGiftBox.php', {method: 'post', onSuccess: show_basket, onFailure: show_basket_fail});
}

function show_basket(response) {
	var str = response.responseText;
	str = str.split(":::::");
	$('basket').innerHTML=str[0];
	if ($('top_basket_total')) $('top_basket_total').innerHTML=str[1];
	if($('msg')) $('msg').hide();
	$('basket').setOpacity(1);
}
function show_basket_fail(response) {
	$('basket').appear({ duration: 0.5 });
	$('basket').innerHTML=response.responseText;
	if($('msg')) $('msg').hide();
}
function hidedeladdresstable(obj) {
	if (obj.checked) $('deladdresstable').fade({ duration: 0.5 });
	else $('deladdresstable').appear({ duration: 0.5 });
}
function hidedeladdresstable_custid(obj) {
	if (obj.checked) $('deladdress_custid').fade({ duration: 0.5 });
	else $('deladdress_custid').appear({ duration: 0.5 });
}
function canSubmit() {
	if ($F('code').length>0) {
		alert("Please press 'APPLY NOW' to apply your discount code.");
		return false;
	}
	return true;
}
