// javascripts/dynamic_guides.js.erb
var guides = new Array();
  guides.push(new Array(1, 'Central Florida', '2-central-florida', "Orlando, Apopka, Altamonte Springs, Kissimmee, Winter Haven, Mt. Dora, Daytona Beach, Winter Park, New Smyrna Beach, Maitland, Lake Mary, Sanford"));
  
  guides.push(new Array(1, 'Greater Palm Beach', '4-greater-palm-beach', "Palm Beach, West Palm Beach, Boca Raton, Lake Worth, Jupiter, Delray Beach, Boynton Beach, Riviera Beach, Jensen Beach, Ft Pierce"));
  
  guides.push(new Array(1, 'Greater Tampa', '3-greater-tampa', "Tampa, St. Petersburg, Clearwater, Lakeland, Zephyrhills, Dade City, Land O Lakes, Lake Wales, Brandon, Largo, Tarpon Springs, New Port Richey, Brooksville"));
  
  guides.push(new Array(1, 'Northeast Florida', '1-northeast-florida', "Jacksonville and its Beaches, Ponte Vedra Beach, Orange Park, St. Augustine, Amelia Island/Fernandina Beach ,Palm Coast, Palatka, Macclenny"));
  
  guides.push(new Array(1, 'South Florida', '5-south-florida', "Miami Metropolitan area, Miami’s Beaches, Ft. Lauderdale, Hollywood Homestead, Key Biscayne, Pompano Beach"));
  
  guides.push(new Array(3, 'South Hampton Roads', '6-south-hampton-roads', "Virginia Beach, Norfolk, Chesapeake, Suffolk and Portsmouth"));
  

function stateSelected() {
	$('cities_list').update();
  state_id = $('search_state').getValue();
  options = $('search_guide').options;
  options.length = 1;
  guides.each(function(guide) {
    if (guide[0] == state_id) {
      options[options.length] = new Option(guide[1], guide[2]);
    }
  });
  if (options.length == 1) {
    $('search_guide').hide();
  } else {
    $('search_guide').show();
  }
}

function guideSelected() {
	guide_url = $('search_guide').getValue();
	//alert("here");
	guides.each(function(guide) {
    if (guide[2] == guide_url) {
    	$('cities_list').update("This guide includes the following cities:<br />" + guide[3]);
    }
  });
}

function formGuideCheck() {
	if( $('search_guide').getValue() == 0 ) {
		alert('Please select a guide.');
		//Event.stop(event);
	} else {
		//Event.stop(event);
		guideName = $('search_guide').getValue();
	
		window.location = "/guides/" + guideName;
	}
}

document.observe('dom:loaded', function() {
  stateSelected();
  $('search_state').observe('change', stateSelected);
  $('search_guide').observe('change', guideSelected);
  //$('search_form').observe('submit', formCheck);
  $('search_submit').observe('click', formGuideCheck);
});