
function getSearchResults(theForm) {

   window.status = "Retrieving details for search";

   var contentID = "search-results-container";
   var idiv = window.document.getElementById(contentID);

   var username = theForm.username.value.trim();
   var city = theForm.city.value.trim();
   var state = theForm.state.value.trim();
   var country = theForm.country.value.trim();
   var challengename = theForm.challengename.value.trim();

   if (!(username.length>0 || city.length>0 || state.length>0 || country.length>0 || challengename.length>0)) {
      alert ('You must specify user name, city, state, country, or challenge name');
   }
   else {
      var idiv = window.document.getElementById(contentID + "-load-status");
      if (idiv) idiv.style.display='';

      idiv = window.document.getElementById(contentID + "-loading-indicator");
      if (idiv)
         idiv.innerHTML = '<img src="images/loading.gif" alt="Loading indicator"/> Retrieving ...' ;
      else {
         idiv = window.document.getElementById(contentID);
         if (idiv) {
            idiv.innerHTML = '<div style="text-align: center;margin-top:50px;"><img src="images/loadingBig.gif" alt="Loading indicator"/><p>Retrieving users...</p></div>';
         }
      }

   //   if (idiv) idiv.innerHTML = '<div style="text-align: center;margin-top:50px;"><img src="images/loadingBig.gif" alt="Loading indicator"/><p>Retrieving users...</p></div>';

      var url="getSearchResults.php?" + "username=" +  escape(username) +
      "&city=" +  escape(city)  +
      "&state=" +  escape(state)  +
      "&country=" +  escape(country)  +
      "&challengename=" +  escape(challengename) +
      "&gender=" +  escape(theForm.gender.value);

      for (i=0; i<theForm.searchtype.length; i++) {
         if (theForm.searchtype[i].checked) {
            url = url + "&searchtype=" +  escape(theForm.searchtype[i].value);
            break;
         }
      }

      //to prevent caching
      var now = new Date();
      url = url + '&time=' + now.getTime();

      makeRequest(url, contentID);
   }
}

function resetSearchForm(theForm) {
   theForm.username.value="";
   theForm.city.value="";
   theForm.state.value="";
   theForm.country.value="";
   theForm.challengename.value="";

   theForm.gender.value=0;

   theForm.searchtype[0].checked = true;
   for(var i = 1; i < theForm.searchtype.length; i++) {
      theForm.searchtype[i].checked = false;
   }
   var contentID = "search-results-container";
   var idiv = window.document.getElementById(contentID);
   if (idiv) idiv.innerHTML = 'There are no search results yet.';
}

