function bb1AddtoWeddingList(item, qty) {
 var addtolist_url = "/app/site/hosting/scriptlet.nl?script=18&deploy=1&compid=917016&h=ad585656e5a4381bf2c6";
 var item_parm = (item&&item!="") ? "&item="+item : "";
 var qty_parm = (qty&&qty!="") ? "&qty="+qty : "";
 var redirect_parm = "&redirect="+encodeURIComponent(location.href);
 var request = bb1CreateXMLHttpRequest();
 if (request) {
  try {
   request.open("POST", addtolist_url, true);
   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   request.onreadystatechange = function() {
      var done = 4, ok = 200;
      if (request.readyState == done) {
       if (request.status == ok)
        alert("done!");
       else
        alert("An error occured while adding the item to your wedding list. Please re-login and try again.\nIf the problem persists please contact us for support.");
      }
     };
   request.send(item_parm.substr(1, item_parm.length) + qty_parm);
  }
  catch (e) {
   location.href = addtolist_url + item_parm + qty_parm + redirect_parm;
  }
 }
 else {
  location.href = addtolist_url + item_parm + qty_parm + redirect_parm;
 }
 return false;
}

function bb1ManageWeddingList(list_ds) {
 var obj = this;
 if (typeof window['bb1_manage_wedding_list'] != 'undefined') {
  obj = window['bb1_manage_wedding_list'];
 }
 obj.closed = list_ds.closed;
 obj.weddingdate = list_ds.weddingdate;
 obj.totalprice = list_ds.totalprice;
 obj.page = list_ds.page;
 obj.page_size = list_ds.page_size;
 obj.page_count = list_ds.page_count;
 obj.record_count = list_ds.record_count;
 obj.post = true;
 obj.d = document;
 obj.list_ds = list_ds.results;
 return obj;
}

bb1ManageWeddingList.prototype.display = function () {
 var d = this.d, list_ds = this.list_ds, writetodoc = false;
 var container = d.getElementById('weddinglist_container');
 if (container) {
  for (var i=0; i < container.childNodes.length; i++) {
   container.removeChild(container.childNodes[i]);
  }
 }
 else {
  container = d.createElement('DIV'); 
  container.id = "weddinglist_container";
  container.className = "form";
  writetodoc = true;
 }
 var page_nav_top = bb1CreatePageNav(this.page, this.page_size, this.record_count, this.page_count);
 var page_nav_bottom = (page_nav_top) ? page_nav_top.cloneNode(true) : null;
 var closingdate = "";
 var dateparts = this.weddingdate.match(/^(\d*)\/(\d*)\/(\d*)$/);
 if (dateparts) {
  closingdate = new Date(dateparts[2]+'/'+dateparts[1]+'/'+dateparts[3]);
  closingdate.setDate(closingdate.getDate()+42);
  closingdate = closingdate.getDate()+'/'+(closingdate.getMonth()+1)+'/'+closingdate.getFullYear();
 }
 container.innerHTML = '<h1>Manage my wedding list</h1><ul class="print"><li><a href="#" onclick="window.print(); return false;">Print page</a></li></ul>'+(!this.closed?'<p>You can add and remove items from this list. Once you have saved your list, you can edit it until <em>'+closingdate+'</em>.</p>':'<p>This list is now <em>closed</em> and cannot be changed.</p>');
 if (list_ds && list_ds.length>0) {
  if (page_nav_top) container.appendChild(page_nav_top);
  var form = d.createElement('FORM');
  form.id = "weddinglist_form";
  form.name = "weddinglist_form";
  form.action = "/app/site/hosting/scriptlet.nl?script=19&deploy=1&compid=917016&h=1abff62b8f80a75dc5e1&action=update";
  form.method = "post";
  form.onsubmit = function() { this.action=addParamToURL(this.action,'redirect',encodeURIComponent(location.href),true); return true; };
  container.appendChild(form);
  var fieldset = d.createElement('FIELDSET'); 
  form.appendChild(fieldset);
  var table = d.createElement('TABLE'); 
  table.width = "730";
  table.cellPadding = 0;
  table.cellSpacing = 0;
  table.border = 0;
  table.className = "printable weddinglist-table";
  fieldset.appendChild(table);
  var tbody = d.createElement('TBODY');
  table.appendChild(tbody);
  var row_classes = [null,null,null,null,null,"delete"];
  var row_widths = ["120","270","100","100","180","80"];
  var row = bb1CreateListRow(["Product","Description","Quantity","Purchased","Price per item (&pound;)","Delete"], row_classes, row_widths, true);
  tbody.appendChild(row);
  var last_category = "", total = 0;
  for (var i=0; list_ds && i < list_ds.length; i++) {
   var wl = list_ds[i];
   if (wl.category!=last_category) {
    row = d.createElement('TR');
    if (i==0) row.className="first";
    var th = d.createElement('TH');
    th.colSpan = 6;
    th.className = "sub-head";
    th.innerHTML = wl.category;
    row.appendChild(th);
    tbody.appendChild(row);
    last_category = wl.category;
   }
   var thumbnail = (wl.thumbnail) ? '<a href="'+wl.image+'" class="thickbox"><img src="'+wl.thumbnail+(wl.thumbnail.indexOf('?')==-1?'?':'&')+'resizeid=-3&resizeh=50&resizew=50" width="50" height="50" alt="" /></a>' : '';
   var description = (wl.description) ? (wl.url&&wl.url!="" ? '<a href="'+wl.url+'">'+wl.description+'</a>' : wl.description) : '';
   var q = (wl.qty&&!isNaN(parseInt(wl.qty))) ? parseInt(wl.qty) : 0;
   var quantity = (!this.closed) ? '<div class="element"><input type="text" name="item_'+wl.id+'" id="item_'+wl.id+'" class="text" size="6" value="'+q+'" /></div>' : q;
   var purchased = (wl.purchased) ? wl.purchased : '';
   pr = (wl.price&&!isNaN(parseFloat(wl.price))) ? parseFloat(wl.price) : 0;
   pr = Math.round(pr*100)/100;
   var price = (pr!=0) ? '&pound;'+pr.toFixed(2) : '-';
   var del = (parseInt(wl.purchased)>0) ? '' : '<a href="#" onclick="var form=document.forms[\'weddinglist_form\']; form.elements[\'item_'+wl.id+'\'].value=0; if (form.onsubmit()) form.submit(); return false;"><img src="/swd/images/content/delete.jpg" width="12" height="13" alt="Delete" /></a>';
   row = bb1CreateListRow([thumbnail,description,quantity,purchased,price,del], row_classes);
   if (i==list_ds.length-1) row.className = "last";
   tbody.appendChild(row);
   total += q * pr;
  }
  table = d.createElement('TABLE'); 
  table.width = "730";
  table.cellPadding = 0;
  table.cellSpacing = 0;
  table.border = 0;
  table.className = "printable total";
  fieldset.appendChild(table);
  tbody = d.createElement('TBODY');
  table.appendChild(tbody);
  row = d.createElement('TR');
  tbody.appendChild(row);
  var cell = d.createElement('TH');
  cell.width = "505";
  cell.align = "right";
  cell.innerHTML = "Total";
  row.appendChild(cell);
  cell = d.createElement('TD');
  cell.width = "85";
  cell.innerHTML = "&pound;"+this.totalprice.toFixed(2);
  row.appendChild(cell);
  cell = d.createElement('TD');
  cell.width = "140";
  if (!this.closed) cell.innerHTML = '<div class="field submit clear"><div class="element"><input type="submit" value="Update my list" class="submit" id="list-register" name="list-register" /></div></div>';
  row.appendChild(cell);
  if (page_nav_bottom) container.appendChild(page_nav_bottom);
 }
 else {
  var p = d.createElement("P");
  p.innerHTML = "<br><br>No items have been added to this wedding list yet.<br><br>To start adding items to your wedding list, browse our products using the navigation and search links at the top of the page and click the <em>Add to wedding list</em> button to add them to your list.";
  container.appendChild(p);
 }
 if (writetodoc) d.write(container.innerHTML);
}

function bb1SearchWeddingList(list_ds) {
 var obj = this;
 if (typeof window['bb1_search_wedding_list'] != 'undefined') {
  obj = window['bb1_search_wedding_list'];
 }
 obj.page = list_ds.page;
 obj.page_size = list_ds.page_size;
 obj.page_count = list_ds.page_count;
 obj.record_count = list_ds.record_count;
 obj.post = true;
 obj.d = document;
 obj.list_ds = list_ds.results;
 return obj;
}

bb1SearchWeddingList.prototype.display = function () {
 var d = this.d, list_ds = this.list_ds, writetodoc = false;
 var container = d.getElementById('weddinglist_container');
 if (container) {
  for (var i=0; i < container.childNodes.length; i++) {
   container.removeChild(container.childNodes[i]);
  }
 }
 else {
  container = d.createElement('DIV'); 
  container.id = "weddinglist_container";
  container.className = "form";
  writetodoc = true;
 }
 var page_nav_top = bb1CreatePageNav(this.page, this.page_size, this.record_count, this.page_count);
 var page_nav_bottom = (page_nav_top) ? page_nav_top.cloneNode(true) : null;
 container.innerHTML = '<h1>Search wedding lists</h1><div class="clear"><p>Select one of the wedding list\'s from the list below to browse and buy wedding gifts.</p></div>'
 if (page_nav_top) container.appendChild(page_nav_top);
 var form = d.createElement('FORM');
 form.id = "weddinglist_form";
 form.name = "weddinglist_form";
 form.action = "#";
 form.method = "post";
 form.onsubmit = function() { this.action=addParamToURL(this.action,'redirect',encodeURIComponent(location.href),true); return true; };
 container.appendChild(form);
 var fieldset = d.createElement('FIELDSET'); 
 form.appendChild(fieldset);
 var table = d.createElement('TABLE'); 
 table.width = "730";
 table.cellPadding = 0;
 table.cellSpacing = 0;
 table.border = 0;
 table.className = "printable weddinglist-table";
 fieldset.appendChild(table);
 var tbody = d.createElement('TBODY');
 table.appendChild(tbody);
 var row_classes = [null,null,null,"view"];
 var row_widths = ["100","300","130","200"];
 var row = bb1CreateListRow(["Image","List holder","Wedding date",""], row_classes, row_widths, true);
 tbody.appendChild(row);
 row = d.createElement('TR');
 var th = d.createElement('TH');
 th.colSpan = 5;
 row.appendChild(th);
 tbody.appendChild(row);
 var baseurl = location.href;
 var remove_parms = ["action","search_id","search_name1","search_name2","search_date","page","sortby","sortorder"];
 for (var i=0; i < remove_parms.length; i++) {
  baseurl = removeParamFromURL(baseurl, remove_parms[i]);
 }
 for (var i=0; list_ds && i < list_ds.length; i++) {
  var wl = list_ds[i];
  var thumbnail = (wl.image) ? '<a href="'+wl.image+'" class="thickbox"><img src="'+wl.image+(wl.image.indexOf('?')==-1?'?':'&')+'resizeid=-3&resizeh=50&resizew=50" width="50" height="50" alt="" /></a>' : '';
  var listholder = '<strong>' + (wl.p1_firstname&&wl.p1_firstname!="" ? wl.p1_firstname+' ' : '') + (wl.p1_surname&&wl.p1_surname!="" ? wl.p1_surname : '') + '</strong> and <strong>' + (wl.p2_firstname&&wl.p2_firstname!="" ? wl.p2_firstname+' ' : '') + (wl.p2_surname&&wl.p2_surname!="" ? wl.p2_surname : '') + '</strong>';
  var weddingdate = (wl.weddingdate&&wl.weddingdate!="" ? wl.weddingdate : '');
  var listlink = (wl.id&&wl.id!="") ? '<a href="'+addParamToURL(addParamToURL(baseurl, "action", "get", true), "search_id", wl.id, true)+'">View wedding list</a>' : "";
  row = bb1CreateListRow([thumbnail,listholder,weddingdate,listlink],row_classes);
  if (tbody.rows.length==1) row.className="first";
  tbody.appendChild(row);
 }
 if (tbody.rows.length>1) tbody.rows[1].className="first";
 if (tbody.rows.length>2) tbody.rows[tbody.rows.length-1].className = "last";
 if (page_nav_bottom) container.appendChild(page_nav_bottom);
 if (writetodoc) d.write(container.innerHTML);
}


function bb1BrowseWeddingList(list_ds) {
 var obj = this;
 if (typeof window['bb1_browse_wedding_list'] != 'undefined') {
  obj = window['bb1_browse_wedding_list'];
 }
 obj.listid = list_ds.listid;
 obj.listholdername1 = list_ds.listholdername1;
 obj.listholdername2 = list_ds.listholdername2;
 obj.image = list_ds.image;
 obj.message = unescape(list_ds.message);
 obj.weddingdate = list_ds.weddingdate;
 obj.page = list_ds.page;
 obj.page_size = list_ds.page_size;
 obj.page_count = list_ds.page_count;
 obj.record_count = list_ds.record_count;
 obj.sortby = list_ds.sortby;
 obj.sortorder = list_ds.sortorder;
 obj.post = true;
 obj.d = document;
 obj.list_ds = list_ds.results;
 return obj;
}

bb1BrowseWeddingList.prototype.display = function () {
 var d = this.d, list_ds = this.list_ds, writetodoc = false;
 var container = d.getElementById('weddinglist_container');
 if (container) {
  for (var i=0; i < container.childNodes.length; i++) {
   container.removeChild(container.childNodes[i]);
  }
 }
 else {
  container = d.createElement('DIV'); 
  container.id = "weddinglist_container";
  container.className = "form";
  writetodoc = true;
 }
 var page_nav_top = bb1CreatePageNav(this.page, this.page_size, this.record_count, this.page_count, true);
 var page_nav_bottom = (page_nav_top) ? page_nav_top.cloneNode(true) : null;
 container.innerHTML = '<h1>Browse wedding list</h1><ul class="print"><li><a href="#" onclick="window.print(); return false;">Print page</a></li></ul><div class="clear">'+(this.image!=''?'<img src="'+this.image+(this.image.indexOf('?')==-1?'?':'&')+'resizeid=-5&resizeh=120&resizew=120" width="120" height="120" class="image-left" />':'')+'<p>Welcome to the Wedding list of <strong>'+this.listholdername1+'</strong> and <strong>'+this.listholdername2+'</strong>.</p><p>'+this.message.replace(/\r\n/g,"<br>")+'</p></div>'
 if (page_nav_top) container.appendChild(page_nav_top);
 var form = d.createElement('FORM');
 form.id = "weddinglist_form";
 form.name = "weddinglist_form";
 form.action = "https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=31&deploy=1&compid=917016&h=625d26eeb011b305ea7f&wl="+this.listid;
 form.method = "post";
 //form.onsubmit = function() { this.action=addParamToURL(this.action,'redirect',encodeURIComponent(location.href),true); return true; };
 container.appendChild(form);
 var fieldset = d.createElement('FIELDSET'); 
 form.appendChild(fieldset);
 var table = d.createElement('TABLE'); 
 table.width = "730";
 table.cellPadding = 0;
 table.cellSpacing = 0;
 table.border = 0;
 table.className = "printable weddinglist-table";
 fieldset.appendChild(table);
 var tbody = d.createElement('TBODY');
 table.appendChild(tbody);
 var row_classes = [null,null,null,null,"quantity"];
 var row_widths = ["120","350","120","180","80"];
 var row = bb1CreateListRow(["Product","Description","Remaining","Price per item (&pound;)","Quantity"], row_classes, row_widths, true);
 tbody.appendChild(row);
 var last_category = "", total = 0;
 if (this.sortby!="category") {
  row = d.createElement('TR');
  var th = d.createElement('TH');
  th.colSpan = 5;
  row.appendChild(th);
  tbody.appendChild(row);
 }
 for (var i=0; list_ds && i < list_ds.length; i++) {
  var wl = list_ds[i];
  var q = (wl.qty&&!isNaN(parseInt(wl.qty))) ? parseInt(wl.qty) : 0;
  var p = (wl.purchased&&!isNaN(parseInt(wl.purchased))) ? parseInt(wl.purchased) : 0;
  if (q-p<=0) continue;
  if (this.sortby=="category" && wl.category!=last_category) {
   row = d.createElement('TR');
   var th = d.createElement('TH');
   th.colSpan = 5;
   th.className = "sub-head";
   th.innerHTML = wl.category;
   row.appendChild(th);
   tbody.appendChild(row);
   last_category = wl.category;
  }
  var thumbnail = (wl.thumbnail) ? '<a href="'+wl.image+'" class="thickbox"><img src="'+wl.thumbnail+(wl.thumbnail.indexOf('?')==-1?'?':'&')+'resizeid=-3&resizeh=50&resizew=50" width="50" height="50" alt="" /></a>' : '';
  var description = (wl.description) ? (wl.url&&wl.url!="" ? '<a href="'+wl.url+'">'+wl.description+'</a>' : wl.description) : '';
  var remaining = (q-p)+' of '+q;
  pr = (wl.price&&!isNaN(parseFloat(wl.price))) ? parseFloat(wl.price) : 0;
  pr = Math.round(pr*100)/100;
  var price = (pr!=0) ? '&pound;'+pr.toFixed(2) : '-';
  var quantity = '<select name="quantity" id="quantity" giftid="'+wl.id+'" itemid="'+wl.itemid+'" price="'+wl.price+'">';
  for (var j=0; j <= q-p; j++)
   quantity += '<option value="'+j+'">'+j+'</option>';
  quantity += '</select>';
  quantity += '<input type="hidden" name="giftid" value="'+wl.id+'" />';
  quantity += '<input type="hidden" name="itemid" value="'+wl.itemid+'" />';
  row = bb1CreateListRow([thumbnail,description,remaining,price,quantity], row_classes);
  if (tbody.rows.length==1) row.className="first";
  tbody.appendChild(row);
  total += q * pr;
 }
 if (tbody.rows.length>1) tbody.rows[1].className="first";
 if (tbody.rows.length>2) tbody.rows[tbody.rows.length-1].className = "last";
 table = d.createElement('TABLE'); 
 table.width = "730";
 table.cellPadding = 0;
 table.cellSpacing = 0;
 table.border = 0;
 table.className = "printable total";
 fieldset.appendChild(table);
 tbody = d.createElement('TBODY');
 table.appendChild(tbody);
 row = d.createElement('TR');
 tbody.appendChild(row);
 cell = d.createElement('TD');
 cell.align = "right";
 cell.innerHTML = '<div class="field submit clear"><div class="element"><input type="button" value="Calculate total" class="submit" id="list-calculate" name="list-calculate" onclick="bb1CalculateBuyTotal();" /></div></div>';
 row.appendChild(cell);
 row = d.createElement('TR');
 tbody.appendChild(row);
 var cell = d.createElement('TD');
 cell.align = "right";
 cell.innerHTML = '<div id="weddinglist_total">&pound;0.00</div>';
 row.appendChild(cell);
 row = d.createElement('TR');
 tbody.appendChild(row);
 cell = d.createElement('TD');
 cell.align = "right";
 cell.innerHTML = '<div class="field submit clear"><div class="element"><input type="submit" value="Buy gifts" class="submit" id="list-buy" name="list-buy" /></div></div>'; //onclick="var bb1_multiaddtocart = new AjaxMultiAddToCart(\'/s.nl/c.917016/sc.3/.f\'); bb1_multiaddtocart.AddItemsToCart();" 
 row.appendChild(cell);
 if (page_nav_bottom) container.appendChild(page_nav_bottom);
 if (writetodoc) d.write(container.innerHTML);
}

function bb1CalculateBuyTotal() {
 var total = 0;
 var form = document.forms["weddinglist_form"];
 for (var i=0; i < form.elements.length; i++) {
  var elem = form.elements[i];
  if (elem.tagName=="SELECT" && elem.name=="quantity") {
   var qty = elem.options[elem.selectedIndex].value;
   var qty = (qty&&!isNaN(parseInt(qty))) ? parseInt(qty) : 0;
   var price = elem.getAttribute('price');
   price = (price&&!isNaN(parseFloat(price))) ? parseFloat(price) : 0;
   total += qty * price;
  }
 }
 var c = document.getElementById("weddinglist_total");
 if (c) c.innerHTML = "&pound;"+total.toFixed(2);
}


bb1BrowseWeddingList.prototype.reload = function (category) {
 if (this.post) {
  var url = removeParamFromURL(window.location.href, "page");
  location.href = addParamToURL(url, "stockist", category, true);
  return;
 }
 var d = this.d;
 var script = d.getElementById('bb1_weddinglist_servelet');
 var url = addParamToURL(script.src, "stockist", category, true);
 script.parentNode.removeChild(script);
 var new_script = d.createElement('SCRIPT');
 new_script.type = 'text/javascript';
 new_script.id = 'bb1_weddinglist_servelet';
 new_script.src = url;
 d.getElementsByTagName('HEAD')[0].appendChild(new_script);
}


function bb1PurchasedItemsList(list_ds) {
 var obj = this;
 if (typeof window['bb1_purchased_items_list'] != 'undefined') {
  obj = window['bb1_purchased_items_list'];
 }
 obj.page = list_ds.page;
 obj.page_size = list_ds.page_size;
 obj.page_count = list_ds.page_count;
 obj.record_count = list_ds.record_count;
 obj.post = true;
 obj.d = document;
 obj.list_ds = list_ds.results;
 return obj;
}

bb1PurchasedItemsList.prototype.display = function () {
 var d = this.d, list_ds = this.list_ds, writetodoc = false;
 var container = d.getElementById('weddinglist_container');
 if (container) {
  for (var i=0; i < container.childNodes.length; i++) {
   container.removeChild(container.childNodes[i]);
  }
 }
 else {
  container = d.createElement('DIV'); 
  container.id = "weddinglist_container";
  container.className = "form";
  writetodoc = true;
 }
 var page_nav_top = bb1CreatePageNav(this.page, this.page_size, this.record_count, this.page_count);
 var page_nav_bottom = (page_nav_top) ? page_nav_top.cloneNode(true) : null;
 container.innerHTML = '<h1>Purchased items</h1><ul class="print"><li><a href="#" onclick="window.print(); return false;">Print page</a></li></ul>';
 if (page_nav_top) container.appendChild(page_nav_top);
 var div = d.createElement('DIV'); 
 div.className = "purchases";
 container.appendChild(div);
 var ul = d.createElement('UL'); 
 div.appendChild(ul);  
 for (var i=0; list_ds && i < list_ds.length; i++) {
  var item = list_ds[i];
  var name = item.name;
  var gifts = "";
  for (var j=0; j < item.itemurls.length; j++) {
   gifts += '<li><a href="'+item.itemurls[j]+'">'+item.quantities[j]+' '+item.items[j]+'</a></li>';
  }
  var itemurls = item.itemurls;
  var message = unescape(item.message).replace(/\r\n/g,"<br />");
  var address = unescape(item.address);
  var datepurchased = item.datepurchased;
  var li = d.createElement("LI");
  li.innerHTML = '<dl><dt>Name:</dt><dd>'+name+'</dd><dt>Gift:</dt><dd><ul>'+(gifts!=""?gifts:'<li></li>')+'</ul></dd><dt>Message:</dt><dd>'+message+'</dd><dt>Address:</dt><dd>'+address+'</dd><dt>Date purchased:</dt><dd>'+datepurchased+'</dd></dl>';
  ul.appendChild(li);
 }
 if (page_nav_bottom) container.appendChild(page_nav_bottom);
 if (writetodoc) d.write(container.innerHTML);
}

function bb1CreateListRow(labels, classes, widths, heading) {
 var d = document;
 var row = d.createElement('TR');
 for (var i=0; i < labels.length; i++) {
  var cell = d.createElement((heading ? 'TH' : 'TD'));
  cell.innerHTML = labels[i];
  if (classes&&classes.length>=i+1&&classes[i]) cell.className = classes[i];
  if (widths&&widths.length>=i+1&&widths[i]) cell.width = widths[i];
  row.appendChild(cell);
 }
 return row;
}

function bb1CreatePageNav(page, page_size, record_count, page_count, price_sort) {
 var d = document, div = null, index = 1;
 var url = removeParamFromURL(window.location.href, "page");
 if (page_count > 1) {
  var html = '<div class="left">';
  var prev_link = addParamToURL(url, "page", page-1, true);
  html += '<ul class="previous"><li>'+(page>1?'<a href="'+prev_link+'">previous</a>':'<a class="active">previous</a>')+'</li></ul><ul>';
  do {
   if (index == page)
    html += '<li><strong>'+index+'</strong></li>';
   else {
    var i_link = addParamToURL(url, "page", index, true);
    html += '<li><a href="'+i_link+'">'+index+'</a></li>';
   }
   index++;
  } while (index <= page_count)
  var next_link = addParamToURL(url, "page", page+1, true);
  html += '</ul><ul class="next"><li>'+(page!=0&&page<page_count?'<a href="'+next_link+'">next</a>':'<a class="active">next</a>')+'</li></ul>';
  var showall_link = addParamToURL(url, "page", "all", true);
  var sortbyprice_link = addParamToURL(url, "sortby", "price", true);
  html += '<ul class="extra">';
  html += (page!=0?'<li><a href="'+showall_link+'">Show me everything</a></li>':'<li><a class="active">Show me everything</a></li>');
  html += (price_sort?'<li><a href="'+addParamToURL(sortbyprice_link, "sortorder", "asc", true)+'"'+(getParameter('sortby')=="price"&&getParameter('sortorder')=="asc"?' class="active"':'')+'>Price ascending</a></li><li><a href="'+addParamToURL(sortbyprice_link, "sortorder", "desc", true)+'"'+(getParameter('sortby')=="price"&&getParameter('sortorder')=="desc"?' class="active"':'')+'>Price descending</a></li>':'');
  html += '</ul>';
  html += '</div>';
  div = d.createElement("DIV");
  div.className = "pagination clear";
  div.innerHTML = html;
 }
 return div;
}

function bb1CreateXMLHttpRequest() {
 if (typeof XMLHttpRequest != "undefined") {
  return new XMLHttpRequest();
 }
 else if (typeof ActiveXObject != "undefined") {
  try {
   return new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    return new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    throw new Error("Microsoft.XMLHTTP not supported");
   }
  }
 } 
 else if (window.createRequest) {
 	return window.createRequest();
 }
 else {
  return null;
 }
}


function AjaxMultiAddToCart(redirecturl) {
 this.d = document;
 this.errors = false;
 this.form = this.d.forms['weddinglist_form'];
 this.redirecturl = (redirecturl) ? redirecturl : '';
 this.request = bb1CreateXMLHttpRequest(); 
 this.itemarray = null;
 this.addtocarturl = "/app/site/backend/additemtocart.nl";
 this.currentitem = 0;
 this.addcount = 0;
}

AjaxMultiAddToCart.prototype.AddItemsToCart = function() {
 bb1AddLoadingLayer();
 this.currentitem = 0;
 this.errors = false;
 this.itemarray = new Array();
 for (var i=0; i < this.form.elements.length; i++) {
  var elem = this.form.elements[i];
  if (elem.name=="quantity" && elem.value!='0') {
   var index = this.itemarray.length;
   this.itemarray[index] = new Object();
   this.itemarray[index].id = elem.getAttribute('itemid');
   this.itemarray[index].qty = elem.options[elem.selectedIndex].value;
   this.itemarray[index].giftid = elem.getAttribute('giftid');
  }
 }
 this.itemarray.reverse();
 this.AddNextItem();
 return false;
}

AjaxMultiAddToCart.prototype.AddNextItem = function() {
 if (!this.request) return;
 if (this.currentitem >= this.itemarray.length) {
  if (this.addcount > 0) {
   if (!this.errors) {
    if (this.redirecturl != '') location.href = this.redirecturl;
   }
   else {
    alert('An error occurred while adding one of the items to your shopping cart. Please try again and if the problems persists please contact us for support.');
   }
  }
  bb1RemoveLoadingLayer();
 }
 if (this.currentitem < this.itemarray.length) {
  this.SendAddToCartRequest();
  this.addcount++;
  this.currentitem++;
 }
}

AjaxMultiAddToCart.prototype.SendAddToCartRequest = function() {
 var request = this.request;
 request.bb1cart = this;
 if (!request) return;
 request.open("POST", this.addtocarturl, true);
 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 request.onreadystatechange = function() {
    var done = 4, ok = 200;
    if (request.readyState == done) {
     if (request.status != ok) request.bb1cart.errors = true;
     request.bb1cart.AddNextItem();
    }
   };
 var item = this.itemarray[this.currentitem];
 var account_parm = 'c=917016';
 var redirect_parm = '&redirect=/swd/blank.html';
 var buyid_parm = '&buyid='+item.id;
 var qty_parm = '&qty='+item.qty;
 var giftid_parm = '&custcol_bb1_weddinggift='+item.giftid;
 this.request.send(account_parm + buyid_parm + qty_parm + giftid_parm + redirect_parm);
}


function bb1AddLoadingLayer() {
 if (arguments.callee.done) return bb1ShowLoadingLayer(true);
 arguments.callee.done = true;
 var translayer = document.createElement('div');
 translayer.id = 'bb1_transbackground';
 translayer.className = 'bb1_transbackground';
 translayer.onclick = function () {return false;};
 translayer.onmousedown = function () {return false;};
 translayer.onmousemove = function () {return false;};
 translayer.onmouseup = function () {return false;};
 translayer.ondblclick = function () {return false;};
 translayer.innerHTML = '&nbsp;';
 var screencentre = document.createElement('div');
 screencentre.id = 'bb1_screencenter';
 screencentre.className = 'bb1_screencentre';
 var image_container = document.createElement('div');
 image_container.id = 'bb1_image_container';
 image_container.className = 'bb1_image_container';
 image_container.innerHTML = '<table width="100%" height="130" cellpadding="0" cellspacing="0" border="0" id="bb1_cat_page_progressbar"><tr><td align="center" valign="middle"><img src="/swd/images/progress-bar.gif"><br><br>Please wait we update your shopping cart...</td></tr></table>';
 screencentre.appendChild(image_container);
 document.getElementsByTagName("body")[0].appendChild(translayer);
 document.getElementsByTagName("body")[0].appendChild(screencentre);
 document.getElementsByTagName("body")[0].style.overflow = 'hidden';
}

function bb1RemoveLoadingLayer() {
 bb1ShowLoadingLayer(false);
}

function bb1ShowLoadingLayer(show) {
 var transbackground = document.getElementById('bb1_transbackground');
 var screencenter = document.getElementById('bb1_screencenter');
 if (transbackground && screencenter) {
  transbackground.style.display = (show) ? 'block' : 'none';
  screencenter.style.display = (show) ? 'block' : 'none';
  document.getElementsByTagName("body")[0].style.overflow = (show) ? 'hidden' : '';
 }
}
