// Values that need to be remembered in order to update the search filter
var lastSubjectID = "";
var timer = "";

function filterResults()
{
    if (timer != null)
        clearTimeout(timer);

   // Values that will be used to also update the search filter
   // (they must also be added to the if statement further below)
   var subjectID = document.getElementById("subject").value; 

   // URL to submit
   var pathString = window.location.pathname +
                    '?a=1' +
                    '&subjectID=' +subjectID +
                    '&categoryID=' + document.getElementById("category").value +
                    '&year=' + document.getElementById("year").value +
                    '&query=' + encodeURI(document.getElementById("query").value.strip());

   // if a parameter that must narrow down the choice of others was changed
   if (lastSubjectID != subjectID) {
       // Update search filters (ex.: categories after choosing a subject)
       new Ajax.Updater('SearchFilter', pathString + "&cmd=updateFilter");

       // Remember the choice of parameters,
       //to determine later on whether they have changed
       lastSubjectID = subjectID;
   }

   // Update search results
   var delayFunction = function () { new Ajax.Updater('PublicationList', pathString + "&cmd=filter"); }
   timer = setTimeout(delayFunction, 500);
}



