//Script for shopping cart
//Author: Pom Srisuthikul

function validate(){
	var v_error;
	v_error = 0;
	//<% IF uBound(aryProductID) < 0 THEN%>
	//alert("You must have at least one product to checkout");
	//return false;
	//<%END IF%>
	for (i=0; i<document.frm_cart.txtQuantity.length;i++){
		if (isNaN(document.frm_cart.txtQuantity[i].value)){
			v_error = 1;
		}
	}
	if (v_error ==1){
		alert("Please only use number in the quantity boxes");
		return false;
	} else{
		return true;
	}
	
}

function removeItem(i){
	document.frm_cart.removeItem.value = i;
	if (validate()){
		document.frm_cart.submit();
	}
}

function checkout(){
	document.frm_cart.action.value = "checkout";
	if (validate()){
		document.frm_cart.submit();
	}
}

function update(){
	if (validate()){
		document.frm_cart.submit();
	}
}

function checkCookies(){

//Free JavaScripts on http://www.ScriptBreaker.com
var cookiesEnabled = false;
 
// Retrieves particular cookie
function getCookie(cookieName)
{
   var cookieFoundAt;
   var cookieValue;
 
   // find start position in cookie string
   cookieFoundAt = document.cookie.indexOf(cookieName + "=");
   
   if (cookieFoundAt < 0)
      {
         cookieValue = "";
      }
   else
      {
         // move to actual start of cookie's data
         cookieFoundAt = document.cookie.indexOf("=",cookieFoundAt);
         cookieFoundAt++;
         
         // find end position of cookie's data
         cookieEnd = document.cookie.indexOf(";", cookieFoundAt);
         if (cookieEnd == -1)
            {
             cookieEnd = document.cookie.length - 1;
            }
         cookieValue =document.cookie.substring(cookieFoundAt,cookieEnd  );
      }
   return cookieValue;
}
 
// Check whether cookies enabled
 
   document.cookie = "Enabled=true";
   var cookieValid = document.cookie;
   
   // if retrieving the VALUE we just set actually works 
   // then we know cookies enabled
   if (cookieValid.indexOf("Enabled=true") != -1)
   {
      cookiesEnabled = true;
   }
   else
   {
      cookiesEnabled = false;
	  alert("To add item(s) to the basket please enable Cookies in your web browser settings.");
   }
 
}