var ToggleSearch = {
	initialized : false,
	searchDropdown : null,
	searchBox : null,
	catalogInputs : null,
	resourcesInputs : null,
	hiddenInputs : null,
	form : null,
	
	_changeSearch : null,
	
	initialize : function() {
		if (!this.initialized) {
			this.searchDropdown = $('searchDropdown');
			this.searchBox = $('search');
			this.form = this.searchBox.up('form');
			this.catalogInputs = $('catalog_inputs');
			this.resourcesInputs = $('resources_inputs');
			this.hiddenInputs = $('hidden_inputs');
			this._changeSearch = this.changeSearch.bindAsEventListener(this);
			this.createEvents();
			this.changeSearch();
			this.searchBox = $('search');
		}
	},
	
	createEvents : function() {
		Event.observe(this.searchDropdown, 'change', this._changeSearch);
	},
	
	changeSearch : function() {
		if (this.searchDropdown.selectedIndex == 0) {
			this.form.action = 'http://behrman.powerwebbook.com/searchproducts.cfm';
			this.hiddenInputs.appendChild(this.catalogInputs);
			this.resourcesInputs.remove();
			this.searchBox.name = "keywords";
		} else {
			this.form.action = 'http://www.behrmanhouse.com/cgi-local/htsearch';
			this.hiddenInputs.appendChild(this.resourcesInputs);
			this.catalogInputs.remove();
			this.searchBox.name = "words";
		}
	}
}

Event.observe(window, 'load', function() {
	ToggleSearch.initialize();
});