function $get(el) {

	var obj = document.getElementById(el);
	if (obj) {
		return obj;		
	} else {
		return null;
	}
} 

function updateBasketQuantity(frm,s1) {
	frm = $get(frm);
	s1 = $get(s1);
	
	var s1input = document.createElement('input'); 
	s1input.setAttribute('type','hidden');
	s1input.setAttribute('name',s1.name);
	s1input.setAttribute('value',s1.value);
	frm.appendChild(s1input);
	s1.disabled='disabled';
	
	frm.submit();	
}
function confirmDeleteItem() {
	return confirm('Are you sure you wish to remove this item from your basket ?');	
}
function valNum(str) {
var test = "0123456789.";
var errors = 0;
if(str.length == 0) {
	errors++;
	}
else {
	for (var i = 0; i <= str.length -1; i++) {
   		if (test.indexOf(str.charAt(i)) == -1) errors++;
		}
	}
if(!errors) {
	if(parseFloat(str) <= 0) {
		alert("Please enter a value greater than 0");
		return false;
		}
	else
		return true;
	}
else {
	alert("Please ensure this field is numerical");
	return false;
	}
}
function setDonationAmount(v,f) {
var val = v;
if(val.indexOf('.00') == -1)
	val+='.00';
if(v > 0)
	f.donation.value = val;
else {
	f.donation.value = '';
	f.donation.focus();
	}
}
function checkAddBasketForm(f) {
	if(!isNaN(parseInt(f.product_ref.value)) && !isNaN(parseInt(f.quantity.value)) && f.src != '') {
		if(f.donation) {
			if(valNum(f.donation.value) == false) {
			f.donation.focus();
			return false;
			}
		}
		return true;
	}
	else {
		alert("Form is missing required parameters\nThis item cannot be added to the basket.");
		return false;
	}
}
function setBasketGiftAid(n) {
// makes sure that a changed gift aid value is transferred from basket page update form to quantity form
if(document.getElementById('basketUPD'+n)) {
	if(document.getElementById('basketQUA'+n)) {
		document.getElementById('basketQUA'+n).gift_aid.value = document.getElementById('basketUPD'+n).gift_aid.checked;
		}
	}
}
