
function trim(string) {
return string.replace(/(^\s+)|(\s+$)/g, "");
}

function Search(submit, section, root) {
  
  var form = document.getElementById("frm_search");
  var form2 = document.getElementById("frm_search2");
  var re = /[ ]+/g;
  
  var search_key = trim(form.edt_search_key.value);
  if (form2 != null) {
    var search_city = trim(form2.edt_search_city.value);
  } else {
    var search_city = '';
  }
  if (form.cmb_search_country != undefined) {
    var search_country = trim(form.cmb_search_country.value);
  } else {
    var search_country = '';
  }
  
  search_key = search_key.replace(/[^A-Za-z0-9 +-]/g, "");
  search_city = search_city.replace(/[^A-Za-z0-9 +-]/g, "");
  search_key = search_key.replace(re,"_");
  
  if(search_city == '')
    search_city = 0;
  else
    search_city = search_city.replace(re,"_");
  
  if(search_country == '')
    search_country = 0;
  else
    search_country = search_country.replace(re,"_");
  
//return false;
  if ((trim(form.edt_search_key.value) == "") && 
      (form2 == null || form2 != null && form2.edt_search_city.value == "") && 
      (form.cmb_search_country == undefined || form.cmb_search_country != undefined && form.cmb_search_country.value == "")
     ) {
    alert('Please select at least one search criteria');
    form.edt_search_key.focus();
    if (submit)
      return false;
  } else {
    if (section == 'press')
      document.location = root+
                          form.cmb_search_area.value +
                          //'/press/search/' + form.edt_search_key.value.replace(re,"_");
                          '/press/search/' + search_key.toLowerCase();
    else
      document.location = root+
                          form.cmb_search_area.value +
                          '/site/country/' + search_country +
                          '/city/' + search_city +
                          '/search/' + search_key.toLowerCase();
    if (submit)
      return false;
  }
  
};

function Filter(url, submit) {

  form = document.getElementById("frm_search");

  url = url + 'index.html?text=' + form.edt_search_key.value;
  
  if (document.getElementById("cmb_scope") != null)
    url = url + '&scope=' + document.getElementById("cmb_scope").value;
  if (document.getElementById("cmb_search_area") != null)
    url = url + '&area=' + document.getElementById("cmb_search_area").value;
  if (document.getElementById("cmb_search_country") != null)
    url = url + '&country=' + document.getElementById("cmb_search_country").value;

  document.location = url;

  if (submit)
    return false;

};

function ClearFilter() {

  document.location = '?';

};