function alterURL(){
  var catindex = document.form.f_selectedCategory.selectedIndex;
  var cattext = document.form.f_selectedCategory.options[catindex].text;
  document.form.action = document.form.action + "/f_selectedCategory/" + cattext;
  return true;
}

function onclick_country(baseUrl)
{
  var chkbox = document.getElementById("chkbox-country");

  if(chkbox.checked == false){
    var divtag = document.getElementById("listbox-country");
    divtag.innerHTML = "";
  }
  else{
    var chkbox1 = document.getElementById("chkbox-state");
    var chkbox2 = document.getElementById("chkbox-city");
    chkbox1.checked = false;
    chkbox2.checked = false;
    emptyListBoxes();
    getCountries(baseUrl);
    
  }
}

function onclick_state(baseUrl)
{
  var chkbox = document.getElementById("chkbox-state");

  if(chkbox.checked == false){
    var divtag = document.getElementById("listbox-state");
    divtag.innerHTML = "";
  }
  else{
    var chkbox1 = document.getElementById("chkbox-country");
    var chkbox2 = document.getElementById("chkbox-city");
    chkbox1.checked = false;
    chkbox2.checked = false;
    emptyListBoxes();
    getStates(baseUrl);
    
  }
}

function onclick_city(baseUrl)
{
  var chkbox = document.getElementById("chkbox-city");

  if(chkbox.checked == false){
    var divtag = document.getElementById("listbox-state");
    divtag.innerHTML = "";
    divtag = document.getElementById("listbox-city");
    divtag.innerHTML = "";
  }
  else{
    var chkbox1 = document.getElementById("chkbox-country");
    var chkbox2 = document.getElementById("chkbox-state");
    chkbox1.checked = false;
    chkbox2.checked = false;
    emptyListBoxes();
    getCities(baseUrl);
    
  }
}

function getCountries(baseUrl)
{
  displayAjaxLoading("ajax-loading1");
  var conn = new XHConn();
  var url = baseUrl + "/f_service/Countries";
  conn.connect(url,"GET","",whenDoneCountry);
}

function getStates(baseUrl)
{
  displayAjaxLoading("ajax-loading1");
  var conn = new XHConn();
  var url = baseUrl + "/f_service/USStates";
  conn.connect(url,"GET","",whenDoneState);
}

function getCities(baseUrl)
{
  getStates(baseUrl);

  displayAjaxLoading("ajax-loading1");
  var conn = new XHConn();
  var url = baseUrl + "/f_service/USCities";
  conn.connect(url,"GET","",whenDoneCity);
}

function whenDoneCountry(XML)
{
  var divtag = document.getElementById("listbox-country");
  divtag.innerHTML = XML.responseText;
  hideAjaxLoading("ajax-loading1");
}

function whenDoneState(XML)
{
  var divtag = document.getElementById("listbox-state");
  divtag.innerHTML = XML.responseText;
  hideAjaxLoading("ajax-loading1");
}

function whenDoneCity(XML)
{
  var divtag = document.getElementById("listbox-city");
  divtag.innerHTML = XML.responseText;
  hideAjaxLoading("ajax-loading1");
}

function onchange_state(baseUrl){
  var isCitySelected = document.getElementById("chkbox-city").checked;
  if(! isCitySelected) return;

  var selectTag = document.getElementById("select-state");
  var options = selectTag.options;
  var index = selectTag.selectedIndex;
  var selectedState = options[index].text;

  displayAjaxLoading("ajax-loading1");
  var conn = new XHConn();
  var url = baseUrl + "/f_service/USCities/f_selectedState/" + selectedState;
  conn.connect(url,"GET","",whenDoneCity);

}

function emptyListBoxes(){
  var listbox1 = document.getElementById("listbox-state");
  var listbox2 = document.getElementById("listbox-city");
  var listbox3 = document.getElementById("listbox-country");
  listbox1.innerHTML = "";
  listbox2.innerHTML = "";
  listbox3.innerHTML = "";
}

function openAdvancedSearch(){
  var spantag = document.getElementById("collapse");
  var rowtag1 = document.getElementById("places-row");
  var rowtag2 = document.getElementById("empty-row1");
  var rowtag3 = document.getElementById("morefilters-row");
  if(spantag.innerHTML == "Advanced Search &gt;&gt;"){
    spantag.innerHTML = "Collapse &lt;&lt;";
    rowtag1.style.display = "";
    rowtag2.style.display = "";
    rowtag3.style.display = "";
  }
  else{
    spantag.innerHTML = "Advanced Search &gt;&gt;";
    rowtag1.style.display = "none";
    rowtag2.style.display = "none";
    rowtag3.style.display = "none";
  }
}