/**
 * This file is intended to hold Javascript functions
 * which deal with select events from the state drop down to populate the city drop down.  
 * for now, the values for both are hard coded. 
 * the original text fields are overwritten so that non-javascript browsers can still manually enter their 
 * search criteria, but possibility for no results found exists in that case. 
 * 
 * version $Id: searchFields.js,v 1.1.2.3 2008/05/08 19:19:46 tcouch Exp $
**/

var locations =  {
    GA: [
      new Option("Blue Ridge", "Blue Ridge"),     
      new Option("Brunswick", "Brunswick"),
      new Option("Dial", "Dial"),
      new Option("Kings Bay", "Kings Bay"),
      new Option("Kingsland", "Kingsland"),
      new Option("Lakewood", "Lakewood"),
      new Option("Mineral Bluff", "Mineral Bluff"),
      new Option("Morgantown", "Morgantown"),
      new Option("St Mary's", "St Mary's"),
      new Option("Woodbine", "Woodbine")    
    ],
	NH: [
	  new Option("Boscawen", "Boscawen"),
	  new Option("Canterbury", "Canterbury"),
	  new Option("Chichester", "Chichester"),
	  new Option("Concord", "Concord"),
	  new Option("Contoocook", "Contoocook"),
	  new Option("Dunbarton", "Dunbarton"),
	  new Option("Hillsborough Upper Vlg", "Hillsborough Upper Village"),
	  new Option("Northwood", "Northwood"),
  	  new Option("Penacook", "Penacook"),
  	  new Option("Pittsfield", "Pittsfield"),
  	  new Option("Salisbury", "Salisbury"),
  	  new Option("Suncook", "Suncook"),
  	  new Option("Washington", "Washington")
	],
	TN: [
	  new Option("Concord", "Concord"),
	  new Option("Farragut", "Farragut")
	],
	WI: [
	  new Option("Albany", "Albany"),
	  new Option("Blanchardville", "Blanchardville"),
	  new Option("Browntown", "Browntown"),	  
	  new Option("Juda", "Juda"),
	  new Option("Monroe", "Monroe"),
      new Option("Monticello", "Monticello"),
      new Option("South Wayne", "South Wayne"),
      new Option("Woodford", "Woodford")
	]
};

var chosenCity = null;
var chosenState = null;


function stateSelected(field) {
	var state = field.options[field.selectedIndex].value;
	$('cityField').options.length = 0;
	var i = 0;
	locations[state].each(function(o) { $('cityField').options[i] = o; i++});
}

function searchFormRendered(search, city, state, threshold) {
	chosenCity = city;
	chosenState = state;
}

Event.observe(window, 'load', function() {
	var sel = $E('select', {id: 'cityField', name: 'city' }, new Option("Select a State", ""));
	$('cityFieldContainer').removeChild($('city'));
	$('cityFieldContainer').appendChild(sel);

	stateSelected($('usStates'));
	for(var i = 0; i < $('cityField').options.length; i++) {
		var o = $('cityField').options[i];
		if(o.value == chosenCity) {
			o.selected = true;
		}
	}
});

function sidebarSubmit(bookCode) {
	openUrl = 'http://hagadone-directory.innovectra.net/' + bookCode + '/index.htm';
	window.open(openUrl);
}

function sidebarDirectory(bookCode) {
        getImage =      "url(http://hagadone-directory.innovectra.net/" + bookCode + "/data/images/cover/" + bookCode + ".jpg)";       
	document.getElementById("sideBar").style.backgroundImage = getImage;  	
}
