
// handle selecting a sub category
function browseSubCat() {

  var nextCat = document.getElementById("subCatSelect").value;

  if (nextCat != 0) {

    window.location.href = "http://" + serverAddress + "/browse.php?type=category&catid=" + nextCat;

  }

}

// handle changing the search order
function changeDisplayOrder(stateType,stateVars) {

  var sortOrder = document.getElementById("sortBySelect").value;

  // expects something in the form of searchcolumn_order
  var sortInfo = sortOrder.split("_");

  var urlString = "http://" + serverAddress + "/browse.php?type=" + stateType + "&sort=" + sortInfo[0] + "&sortorder=" + sortInfo[1];

  // array can be broken into pairs of [statevar,value]
  for (var i = 0; i < stateVars.length; i++) {

    // skip attributes that are 0 or empty string
    if (stateVars[i+1] != "" && stateVars[i+1] != 0) {
      urlString = urlString + "&" + stateVars[i] + "=" + stateVars[++i];
    } else {
      i++;
    }

  }

  window.location.href = urlString;

}

// on pagination hover
function paginateHover(element,type) {

  if (type == "on") {

    element.style.backgroundColor = "#ccccff";
    element.style.cursor = "pointer";

  } else if (type == "off") {

    element.style.backgroundColor = "#dddddd";
    element.style.cursor = "";

  }

}
