   function safeSplit(string, pattern) {
      var split_array = new Array();
      var split_x = 0;
      var start = 0;
      var end = 0;
   
      while (end < string.length) {
         end = string.indexOf(pattern, start);
         if (end == -1)
            end = string.length;
         split_array[split_x++] = string.substring(start, end);
         start = end + 1;
      }
      return(split_array);
   }
   
   function getCookieField(label) {
      var labelLen = label.length;
      var cookieLen = document.cookie.length;
      var x = 0;
      var cookieEnd;
   
      while(x < cookieLen) {
         var sub = x + labelLen;
         if (document.cookie.substring(x, sub) == label) {
            cookieEnd = document.cookie.indexOf(";", sub);
            if (cookieEnd == -1)
               cookieEnd = cookieLen;
            return(unescape(document.cookie.substring(sub + 1, cookieEnd)));
         }
         x++;
      }
      return("");
   }
   
	function cookieFind(cookie, id) {
		cookies = safeSplit(getCookieField(cookie), ",");
		found = false;
      for(x = 0; x < cookies.length; x++) {
         pair = safeSplit(cookies[x], ":");
         if(pair[0] == id)
            found = true;
      }
      
      return(found);
	}
	
   function basket(basket, id, number) {
      var cookies = safeSplit(getCookieField(basket), ",");
      var cookie = "";
      var found = false;
   
      id = "" + id;
      for(x = 0; x < cookies.length; x++) {
         pair = safeSplit(cookies[x], ":");
         if((pair[0]) && (pair[0] != ";") && (pair[0] != id))
            cookie = cookie + cookies[x] + ",";
      }
   
      if(number > 0)
         cookie += id + ":" + (number - 0);
   
      document.cookie = basket + "=" + cookie + "; path=/";
   }
   
	function addRemove(id) {
      found = cookieFind('download', id);
      if(found == false) {
         basket('download', id, 1);
         document.getElementById('addremove' + id).innerHTML = 'Remove from enquiry';
         alert ("This item has been added to your enquiry. When you have finished browsing, click the 'Enquiry/Contact Us' button and complete the enquiry form.");
      }
      else {
         basket('download', id, 0);
         document.getElementById('addremove' + id).innerHTML = 'Add to enquiry';
         alert ("This item has been removed from your enquiry. When you have finished browsing, click the 'Enquiry/Contact Us' button and complete the enquiry form.");
      }
	}