function buildCountry(pLoad) {
  var objRegion=getElement('Region');
  var objCountry=getElement('Country');
  objCountry.options.length=0;
  var j=0;
  if(objRegion.value==0){objCountry.options[j]=new Option('(all countries)', 0)}
  else{objCountry.options[j] = new Option('(all countries in ' + objRegion.options[objRegion.selectedIndex].text + ')', 0)}
  j++;
  for (var i=0; i<countryOptions.length; i++) {
    var opt=countryOptions[i].split(";");
    if(opt[0]==objRegion.value||objRegion.value==0){objCountry.options[j] = new Option(opt[2], opt[1]);j++;}
  }
  if(pLoad==1){objCountry.value=getElement('selCountry').value;}
  else{getElement('selCountry').value=objCountry.value;}
  buildLocation(pLoad);
}

function buildLocation(pLoad) {
  var objCountry=getElement('Country');
  var objLocation=getElement('Location');
  objLocation.options.length = 0;
  var j=0;
  if(objCountry.value==0){objLocation.options[j]=new Option('(all locations)', 0)}
  else{objLocation.options[j] = new Option('(all locations in ' + objCountry.options[objCountry.selectedIndex].text + ')', 0)}
  j++;
  for (var i=0; i<locationOptions.length; i++) {
    var opt=locationOptions[i].split(";");
    if(opt[0]==objCountry.value){objLocation.options[j]=new Option(opt[2], opt[1]);j++;}
  }
  objLocation.disabled=true;
  if(objLocation.options.length > 1){objLocation.disabled=false};
  
  if(pLoad==1){objLocation.value=getElement('selLocation').value;}
  else{getElement('selLocation').value=objLocation.value;}
}

function buildActivity(pLoad) {
  var objActivityCategory=getElement('ActivityCategory');
  var objActivity=getElement('Activity');
  objActivity.options.length = 0;
  var j=0;
  if(objActivityCategory.value==0){objActivity.options[j] = new Option('(all activities)', 0);objActivity.disabled=true;}
  else{objActivity.options[j] = new Option('(all ' + objActivityCategory.options[objActivityCategory.selectedIndex].text + ')', 0);objActivity.disabled=false;}
  j++;
  for (var i=0; i<activityOptions.length; i++) {
    var opt=activityOptions[i].split(";");
    if(opt[0]==objActivityCategory.value||objActivityCategory.value==0){objActivity.options[j] = new Option(opt[2], opt[1]);j++;}
  }
  if(pLoad==1){objActivity.value=getElement('selActivity').value;}
  else{getElement('selActivity').value=objActivity.value;}
}  

function setFields() {
  getElement('selCountry').value=getElement('Country').value;
  getElement('selLocation').value=getElement('Location').value;
  getElement('selActivity').value=getElement('Activity').value;
}

function getElement(psID) { 
  if(document.all) {return document.all[psID];}
  else{return document.getElementById(psID);}
} 

function getSearchValues() {
  getElement('Region').value = getElement('selRegion').value;
  getElement('Country').value = getElement('selCountry').value;
  getElement('Location').value = getElement('selLocation').value;
  getElement('ActivityCategory').value = getElement('selActivityCategory').value;
  getElement('Activity').value = getElement('selActivity').value;
  getElement('DepartDay').value = getElement('selDepartDay').value;
  getElement('DepartMonth').value = getElement('selDepartMonth').value;
  getElement('PlusMinus').value = getElement('selPlusMinus').value;
  getElement('Duration').value = getElement('selDuration').value;
}

