function remove_item(cartid)
{
	if(confirm("Are you sure you want to remove this item?"))
	{
		new Ajax.Request('./ajax.php?act=removeCart&cartid='+cartid, {
		  onSuccess: function(transport) {
			document.location = 'cart.php';
		  }
		});
	}
}
function update_qty(cartid)
{
	onewqty = document.getElementById('cart_'+cartid);
	newqty = onewqty.value;
	new Ajax.Request('./ajax.php?act=updateQty&newqty='+newqty+'&cartid='+cartid, {
	  onSuccess: function(transport) {
		window.location.reload(true);
	  }
	});
}

function checkNumber()
{
	cust = $('login_name');

	if(cust.value.match(/^\d+$/))
	{
		return true;
	}
	 else
	{
		 alert('The customer number must be numeric');
		 return false;
	}
}

function ajaxtocart( form )
{
	details = form.serialize();	
	new Ajax.Request('./ajax.php?act=addtocart&'+details, {
	  onSuccess: function(transport) {
		window.location.reload(true);
	  },
	  onFailure: function(transport) {
		alert("There was an error while adding this item to your cart");
	  }
	});
}

function updatePrice()
{
	oForm = $('addToCartForm');
	oForm.disable();
	opts	= document.getElementsByClassName('product_option');
	opts.each( function(obj){
			$('details').value += obj.name+'='+obj.value+'&';
	});
	
	oForm.action	= './ajax.php?' + $('details').value;
	oForm.request({
		method: 'post',
		parameters: {prodId:productId,act:'productPrice'},
		onCreate: function() {
			$('price').innerHTML = 'Looking up new price...';
		},
		onSuccess: function(transport) {
			resp = transport.responseText;
			oPrice = $('price');
			if(resp=='notfound')
			{
				oPrice.innerHTML = 'This combination of options is not available.';
				$('add_btn').disable();
			}
			else 
			{
				oPrice.innerHTML = '$'+resp;
				$('add_btn').enable();
			}
		}
	});
	oForm.action = '#';
	oForm.enable();

	updateSku();
}

function updateSku()
{
	oForm = $('addToCartForm');
	oForm.disable();
	opts	= document.getElementsByClassName('product_option');
	opts.each( function(obj){
			$('details').value += obj.name+'='+obj.value+'&';
	});
	
	oForm.action	= './ajax.php?' + $('details').value;
	oForm.request({
		method: 'post',
		parameters: {prodId:productId,act:'productSku'},
		onCreate: function() {
			$('sku').innerHTML = 'Looking up new SKU...';
		},
		onSuccess: function(transport) {
			resp = transport.responseText;
			oPrice = $('sku');
			if(resp=='notfound')
				oPrice.innerHTML = 'The SKU for this combination could not be found.';
			else 
				oPrice.innerHTML = resp;
		}
	});
	oForm.action = '#';
	oForm.enable();
}