var Search = {};

Search.toggleSubNav = function(id) {
  var subSearch = document.getElementById(id);
  if (subSearch.style.display == "none") {
    subSearch.style.display = "block";
  } else {
    subSearch.style.display = "none";
  }
}

Search.perform = function(element_id) {
  var keywords = document.getElementById(element_id).value;
  if (keywords.length > 0) {
    location.href = '/search/' + keywords + '/';
  }
  return false;
}

Search.updateLink = function(id, quantity) {
  var q = document.getElementById(quantity + '_' + id);
  var link = document.getElementById('addLink_' + id);
  link.href = '/addToCart/' + id + '/' + q.options[q.selectedIndex].value + '/';
}

Search.updateLinkWithBulb = function(id, quantity, bulb) {
  if (!document.getElementById(bulb + '_' + id)) {
    Search.updateLink(id, quantity);
    return;
  }
  var q = document.getElementById(quantity + '_' + id);
  var b = document.getElementById(bulb + '_' + id);
  var link = document.getElementById('addLink_' + id);
  link.href = '/addToCart/' + id + '/' + q.options[q.selectedIndex].value + '/' + escape(b.options[b.selectedIndex].value) + '/';
}
