//function library for search feature

function LoadBody()
{
  var SelectBox;

  SelectBox = document.getElementById("AreaSelectBox");
  SelectBox.selectedIndex = 0;
  BuildAllDataArrays();
}

function AreaSelected()
{
  var pAreaSelect;

  pAreaSelect = document.getElementById("AreaSelectBox");
  LoadCountySelect( pAreaSelect.options[pAreaSelect.selectedIndex].value );
  LoadCitySelect( pAreaSelect.options[pAreaSelect.selectedIndex].value );
}

function CountySelected()
{
  var pCountySelect;

  pCountySelect = document.getElementById("CountySelectBox");
  if( pCountySelect.options[pCountySelect.selectedIndex].value == "Philadelphia" ){
    LoadRegionSelect();
  }
}

function LoadCountySelect( AreaName )
{
  var pCell;
  var HTMLText;

  pCell = document.getElementById("CountySelectCell");
  HTMLText = "Select a County:<br><select id=\"CountySelectBox\" name=\"County\" onChange=\"CountySelected()\">";
  HTMLText += "<option value=\"EMPTY\">-</option>";
  for( i=0; i<Counties[AreaName].length; i++ ){
    HTMLText += "<option value=\"" + Counties[AreaName][i] + "\">" + Counties[AreaName][i] + "</option>";
  }
  HTMLText += "</select>";
  pCell.innerHTML = HTMLText;
}

function LoadCitySelect( AreaName )
{
  var pCell;
  var HTMLText;

  pCell = document.getElementById("CitySelectCell");
  if( AreaName == "Greater Philadelphia" ) {
    HTMLText = "";
  } else {
    HTMLText = "<strong>or</strong> Select a City:<br><select name=\"City\" id=\"CitySelectBox\">";
    HTMLText += "<option value=\"EMPTY\">-</option>";
    for( i=0; i<Cities[AreaName].length; i++ ){
      HTMLText += "<option value=\"" + Cities[AreaName][i] + "\">" + Cities[AreaName][i] + "</option>";
    }
    HTMLText += "</select>";
  }
  pCell.innerHTML = HTMLText;
}

function LoadRegionSelect()
{
  var pCell;
  var HTMLText;

  pCell = document.getElementById("CitySelectCell");
  HTMLText = "and Select a Region:<br><select name=\"Region\" id=\"RegionSelectBox\">" +
             "<option value=\"All\">All Regions</option>" +
             "<option value=\"North\">North</option>" +
             "<option value=\"Northwest\">Northwest</option>" +
             "<option value=\"Northeast\">Northeast</option>" +
             "<option value=\"Center City\">Center City</option>" +
             "<option value=\"South\">South</option>" +
             "<option value=\"Southwest\">Southwest</option>" +
             "<option value=\"Southeast\">Southeast</option>" +
             "</select>";
  pCell.innerHTML = HTMLText;
}

function CheckDataForSubmission()
{
  var ProductType;
  var Area;
  var City;
  var County;

  Area = document.getElementById("AreaSelectBox");
  if( Area.options[Area.selectedIndex].value == "INVALID" ){
    alert( "You must select an area" );
    return false;
  } else if( Area.options[Area.selectedIndex].value != "Greater Philadelphia" ){
    County = document.getElementById("CountySelectBox");
    if( County.options[County.selectedIndex].value == "EMPTY" ){
      City = document.getElementById("CitySelectBox");
      if( City.options[City.selectedIndex].value == "EMPTY" ){
        alert( "You must select either county or city" );
	return false;
      }
    }
  }
  
  return true;
}
