function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1 || endstr=='')
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
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) {
  document.cookie = name + "=" + escape(value) + "; path=/";
}
function AddSize(){
location = document.selecter.select1.options[document.selecter.select1.selectedIndex].value
}
function donothing() {}
function ShowBasket() {
  var basket=null
  alert(" Product Basket opens in a New Window\nYou MUST Enable your browser\'s POP-UP");
  basket=window.open('webwares/basket.html','basket','resizable=0,menubar=0,scrollbars=0,status=0,width=250,height=260,dependent=1,screenX=375,left=375,screenY=185,top=185');
  if (basket != null) {
    if (basket.opener == null) {
      basket.opener = self;
      self.location.href=document.location;
    }
  }
              basket.focus();
}
function split(str,piece) {
      var a = str.indexOf(",");
      var b = str.lastIndexOf(",");
      var c = str.indexOf("|");
      if (piece==1) return str.substring(0,a);
      if (piece==2) return str.substring(a+1,b);
      if (piece==3) return str.substring(b+1,c);
      if (piece==4) return str.substring(c+1,str.length);
}
var newnum;
function AddtoBasket(name,url,price) {
        newnum = GetCookie("num") ? GetCookie("num") : 1;       
        var exist = 0;
        id = name + "," + url + "," + price;
        for (var i=1;i<newnum;i++) { 
                if (GetCookie("item"+i)){
                if (split(GetCookie("item"+i),1)==name) { exist=1; break;} } }          
        if (exist) {
                var current = 0;
                current = split(GetCookie("item"+i),4); 
                current++;
                id += "|"+current;
                SetCookie("item"+i,id);
        }
        else {
                id += "|1";
                SetCookie("item"+newnum,id);
                newnum++; SetCookie("num",newnum);
        }
        ShowBasket();
}
