var trip_finder_values = new Array();

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '37', 'Cancun, Mexico',
        '2012-02-17', 'Feb 17, 2012'
      ));

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '15', 'Ottawa, ON',
        '37', 'Cancun, Mexico',
        '2012-02-17', 'Feb 17, 2012'
      ));

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '37', 'Cancun, Mexico',
        '2012-02-17', 'Feb 17, 2012'
      ));

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '52', 'Nassau, Bahamas',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '53', 'San Juan, Puerto Rico',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '54', 'Charlotte Amalie, Virgin Islands',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '55', 'Port Everglades, Florida',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '56', 'Caribbean',
        '2012-02-18', 'Feb 18, 2012'
      ));

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '52', 'Nassau, Bahamas',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '53', 'San Juan, Puerto Rico',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '54', 'Charlotte Amalie, Virgin Islands',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '55', 'Port Everglades, Florida',
        '2012-02-18', 'Feb 18, 2012'
      ));
      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '13', 'Montreal, QC',
        '56', 'Caribbean',
        '2012-02-18', 'Feb 18, 2012'
      ));

      trip_finder_values.push(new Array(
        '2', 'Beach Trips',
        '29', 'Toronto, ON',
        '39', 'Punta Cana, Dominican Republic',
        '2012-02-19', 'Feb 19, 2012'
      ));

      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '23', 'Boston, MA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '27', 'Durham, NH',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '40', 'New York, NY',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '47', 'Stony Brook, NY',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '89', 'Hamden, CT',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '90', 'Medford, MA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '91', 'Kingston, RI',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '92', 'Providence, RI',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '97', 'Susquehanna, PA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '100', 'Wellesley, MA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '101', 'Amherst, MA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '103', 'Bethlehem, PA',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '104', 'Delhi, NY',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '106', 'Plattsburgh, NY',
        '23', 'Mont Tremblant, QC',
        '2012-02-10', 'Feb 10, 2012'
      ));

      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '66', 'Philadelphia, PA',
        '23', 'Mont Tremblant, QC',
        '2012-02-09', 'Feb  9, 2012'
      ));

      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '13', 'Montreal, QC',
        '23', 'Mont Tremblant, QC',
        '2012-02-20', 'Feb 20, 2012'
      ));

      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '14', 'London, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '18', 'St. Catharines, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '20', 'Windsor, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '22', 'Waterloo, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '29', 'Toronto, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '33', 'Guelph, ON',
        '27', 'Blue Mountain, ON',
        '2012-02-20', 'Feb 20, 2012'
      ));

      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '14', 'London, ON',
        '23', 'Mont Tremblant, QC',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '15', 'Ottawa, ON',
        '23', 'Mont Tremblant, QC',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '16', 'Kingston, ON',
        '23', 'Mont Tremblant, QC',
        '2012-02-20', 'Feb 20, 2012'
      ));
      trip_finder_values.push(new Array(
        '1', 'Ski Trips',
        '29', 'Toronto, ON',
        '23', 'Mont Tremblant, QC',
        '2012-02-20', 'Feb 20, 2012'
      ));

function tripMatch(value_set) {
  trip_type_id = $('search_type_id').getValue();
  return (trip_type_id == '' || value_set[0] == trip_type_id);
}

function originMatch(value_set) {
  origin_id = $('search_origin_id').getValue();
  return (origin_id == '' || value_set[2] == origin_id);
}

function destMatch(value_set) {
  dest_id = $('search_destination_id').getValue();
  return (dest_id == '' || value_set[4] == dest_id);
}

function add_origin_option(options, value_set) {
  add_option(options, value_set[3], value_set[2]);
}

function add_dest_option(options, value_set) {
  add_option(options, value_set[5], value_set[4]);
}

function add_date_option(options, value_set) {
  add_option(options, value_set[7], value_set[6]);
}

function add_option(options, text, value) {
  if (text == '') {
    return;
  }

  for (var i = 0; i < options.length; i++) {
    if (options[i][1] == value) {
      return;
    }
  }

  options[options.length] = [text, value];
}

function set_options(element, new_options, value_sort) {
  options = element.options;
  options.length = 1;
  if (value_sort == true) {
    new_options.sort(function(a,b) {
      if (a[1] > b[1]) {
        return 1;
      }
      else if (a[1] < b[1]) {
        return -1;
      }
      else {
        return 0;
      }
    });
  }
  else {
    new_options.sort();
  }
  for (var i = 0; i < new_options.length; i++) {
    options[options.length] = new Option(new_options[i][0], new_options[i][1], false, false);
  }
}

function tripTypeSelected() {
  origin_options = [];
  dest_options = [];
  date_options = [];

  trip_finder_values.each(function(value_set) {
    if (tripMatch(value_set)) {
      add_origin_option(origin_options, value_set);
      add_dest_option(dest_options, value_set);
      add_date_option(date_options, value_set);
    }
  });
  set_options($('search_origin_id'), origin_options);
  set_options($('search_destination_id'), dest_options);
  set_options($('search_date'), date_options, true);
}

function originSelected() {
  dest_options = [];
  date_options = [];

  trip_finder_values.each(function(value_set) {
    if (tripMatch(value_set) && originMatch(value_set)) {
      add_dest_option(dest_options, value_set);
      add_date_option(date_options, value_set);
    }
  });
  set_options($('search_destination_id'), dest_options);
  set_options($('search_date'), date_options, true);
}

function destinationSelected() {
  date_options = [];

  trip_finder_values.each(function(value_set) {
    if (tripMatch(value_set) && originMatch(value_set) && destMatch(value_set)) {
      add_date_option(date_options, value_set);
    }
  });
  set_options($('search_date'), date_options, true);
}

function selectTripType(value) {
  $$('select#search_type_id option').each(function(o){
    if (o.value == value) { o.selected = true; }
  });
  tripTypeSelected();
}

function selectOrigin(value) {
  $$('select#search_origin_id option').each(function(o){
    if (o.value == value) { o.selected = true; }
  });
  originSelected();
}

function selectDestination(value) {
  $$('select#search_destination_id option').each(function(o){
    if (o.value == value) { o.selected = true; }
  });
  destinationSelected();
}

function selectDepartureDate(value) {
  $$('select#search_date option').each(function(o){
    if (o.value == value) { o.selected = true; }
  });
}

document.observe('dom:loaded', function() {
  tripTypeSelected();
  $('search_type_id').observe('change', tripTypeSelected);
  $('search_origin_id').observe('change', originSelected);
  $('search_destination_id').observe('change', destinationSelected);
});

