function browse(index) {
  document.browseform.index.value = index;
  document.browseform.submit();
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf(prefix);
  if (begin == -1)
    return ':';
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function clear_records(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    alert('Your saved list has been cleared.');
    location.reload(true);
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function add_record(record_no) {
  var expiry = new Date();
  fixDate(expiry);
  expiry.setTime(expiry.getTime() + 1 * 24 * 60 * 60 * 1000);
  var list = getCookie("wsb_saved");
  if (list == 'null') {
    list = '';
  }
  list_array = list.split(":");
  found = 0;
  for (loop = 0; loop<list_array.length; loop++) {
    if (list_array[loop] == record_no) {
      found = 1;
    }
  }
  entries = list_array.length - 1;
  if (found == 1) {
    alert('This entry already exists in your saved list.');
  } else if (list_array.length < 50) {
    list = list + record_no + ':';
    setCookie("wsb_saved", list, expiry);
    alert('This entry has been saved to your list. (' + entries + ' total)');

    document.getElementById('savelink_' + record_no).innerHTML = 'Saved';
    document.anchors['save_' + record_no].removeAttribute("href");
  } else {
    alert('Your entry list is full.  No additional saves can be made.');
  }
}

function save_message() {
  window.status = 'Add this entry to your saved list';
}

function clear_message() {
  window.status = 'Clear your list of bibliography entries';
}

function doNothing() {
  window.status = ' ';
}

