function place(item_id){
	//process old cookie
  oldcookie =  GetCookie("basket");
	if (oldcookie != null && oldcookie.length > 0){
    var cookieValues = oldcookie.split(',');
    var cookieValue = " ";
    var id_exists = false;
   	for (var i=0; i < cookieValues.length; i++) {
     	values = cookieValues[i].split("=");                     // Extract cookie name & value
      if (values[0] == item_id) {                              // If this cookie is found
				cookieValues.splice(i,1);
        id_exists = true;
        break;
			}
    }
    if (!id_exists) {
     	cookieValues.push(item_id+"=1");
    }
    if (cookieValues) {
    	cookieValue = cookieValues.join(',');
	 	  SetCookie("basket", cookieValue);
		} else {
	 	  SetCookie("basket", "");
		}
  }//ends old cookie IF
  else{
    SetCookie("basket", item_id+"=1");
  }//ends ELSE
}

function updatetotal(){
	var frm = document.forms.checkout;
  var cookieValue = "";
  var total = 0;
  var n =0;
	for (var i=1;i<17;i++) {
		try {
      qty = eval("frm.quantity_"+i+".value");
			qty = parseInt(qty);
      if (qty > 0) {
        if (n > 0 && i != 15) {
					cookieValue += ",";
				}
				n++;
				if (i != 15) {
					cookieValue += i+'='+qty;
        }
	      price = eval("frm.price_"+i+".value");
        total += price*qty;
      }
    } catch(err) {
		}
	}
	total = Math.round(100*total)/100;
	frm.totalamount.value = total;
	var totaltxt = "" + Math.round(100*(Math.round(100*frm.totalamount.value)/100 - Math.floor(frm.totalamount.value)))/100;
	if (totaltxt.length == 3) {
		frm.totalamount.value = frm.totalamount.value + "0"; 
	} else if (totaltxt == "0") {
		frm.totalamount.value = frm.totalamount.value + ".00";
	}
  SetCookie("basket", cookieValue);
}

function update(item_id){
	var frm = document.forms.checkout;
	try {
	  qty = eval("frm.quantity_"+item_id+".value");
		qty = parseInt(qty);
		updatetotal()
  } catch(err) {
	}
}

function remove(item_id){
	var frm = document.forms.checkout;
	try {
	  if ( eval("frm.quantity_"+item_id+".value") > 0 ) {
			eval("frm.quantity_"+item_id+".value=0");
			eval("frm.del_"+item_id+".checked=true");
		} else {
			eval("frm.quantity_"+item_id+".value=1");
			eval("frm.del_"+item_id+".checked=false");
		}
		updatetotal()
  } catch(err) {
	}
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}

function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


function SetCookie (name,value,expires,path) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "");
}

function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}
