function JS_addCartItem(productid,prefix){
	
	var quantity = document.getElementById('cart_quantity_'+prefix);
	
	if(isNaN(quantity.value) || quantity.value==0){
		alert("Please enter a quantity value, using digits only (eg. 3, not 'three') \nand note 0 doesn't count.");
		setTimeout(function(){ 
					quantity.focus()
					},0);
		return false;
	}
	
	var price = document.getElementById('cart_price_'+prefix).value;
	JS_setBasketLoading();//set loading text
	var res = agent.call("/ajax/Cart.ajax.php","AJ_addCartItem","",productid,quantity.value,price);
	if(res!='success'){
		alert("Failed to add this item to the cart, please try again or report this error to info@eco-eye.co.za");
		return;
	}else JS_reloadBasket();
}

function JS_removeCartItem(productid){
	var res, oldHTML, elem = (document.getElementById('cart_quantity_'+productid)).parentNode;
	while(elem.nodeName !="TR") elem = elem.parentNode;
	oldHTML = elem.innerHTML;
	elem.innerHTML = '<td colspan="4">working...</td>';
	res = agent.call("/ajax/Cart.ajax.php","AJ_removeCartItem","",productid);
	if(res=='success'){
		JS_reloadFullBasket();
		JS_reloadBasket();
	}else{
		elem.innerHTML = oldHTML;
		alert("Oops something went wrong, Failed to remove item from your basket.");
	}
}

function JS_reloadFullBasket(){
	agent.call('/ajax/Cart.ajax.php',"AJ_drawFullBasket","basket_fullcontainer");
}

function JS_reloadBasket(){
	agent.call('/ajax/Cart.ajax.php',"AJ_drawBasket","rcol_basket_container");
}

function JS_setBasketLoading(){
	document.getElementById("rcol_basket_container").innerHTML = '<p>Working....</p>';
}

function JS_checkQuantity(elem){
	if(isNaN(elem.value)){
		alert("Invalid quantity value entered, please enter numbers only eg. (3 not \"three\")");
		elem.className = "cart_error";
		setTimeout(function(){ 
					elem.focus()
					},0);
	}else elem.className="";
	JS_giveFocus(elem);
	return false;
}

function JS_giveFocus(elem){
	return false;
}
