/*
 * Webshop javascript functions
 */

 /* remove all shoppingcart cookies */
 function emptyCart(){
 	var oForm = document.getElementById('orderForm');
	oForm.hiddenActionCode.value = 'emptycart';
	oForm.submit();
 }
 
/* redirect to template_shoppingcart */
 function editCart(){
 	var oForm = document.getElementById('orderForm');
	oForm.hiddenActionCode.value = 'editcart';
	oForm.submit();
 }
 
/* update the quantities of the cart-items */
function updateCart(){
 	var oForm = document.getElementById('orderForm');
	oForm.hiddenActionCode.value = 'updatecart';
	oForm.submit();
}
 
 /* add an item to the shoppingcart */
 function addItem(){
 	var oForm = document.getElementById('orderForm');
	oForm.hiddenActionCode.value = 'additem';
	
	oForm.submit();
 }
 
/* remove an item from the shoppingcart */
function removeItem(cookiename){
	var oForm = document.getElementById('orderForm');

	oForm.hiddenCookieName.value = cookiename;
	oForm.hiddenActionCode.value = 'removeitem';
	oForm.submit();
}
 
/* goto checkout */
function gotoCheckOut(){
	var oForm = document.getElementById('orderForm');
	oForm.hiddenActionCode.value = 'checkout';
	oForm.submit();
}
 
/* onchange-handler for the quantity-input  */
function checkForQuantity(oInput){
	var reNonDigits = /[^0-9]/;
	if( reNonDigits.test(oInput.value) ){
		alert('Alleen cijfers zijn toegestaan!');
		oInput.value = oInput.defaultValue;
		oInput.focus();
		return false;
	}
}

/* place on item in the basket */
function orderProduct(details, attributecode){
 	var oForm = document.getElementById('orderForm');
 	var oAttributeCode = document.getElementById('hiddenProductAttributes');
 	var oAttributeDescription = document.getElementById('attribute_' + nProductID);
	
	oAttributeCode.value = attributecode;
	oAttributeDescription.value = details;
	oForm.hiddenActionCode.value = 'additem';
	
	oForm.submit();
}

/* hover image */
var selectedImage = null;
function hoverImage(sID, sStyle){
	var oImage = document.getElementById(sID);
	
	if(selectedImage)
		selectedImage.style.display = 'none';
	oImage.style.display = sStyle;
	selectedImage = oImage;
}
