/*
Object that enables the state/province DDL if USA or Canada is selected,
and disables it if any other country is selected
*/
var dynamicSearchDDLs = {
	countryDDL : Object,
	stateprovDDL : Object,
	stateDDLdiv : Object,
	
	init: function() {
		dynamicSearchDDLs.build();
	},
	
	build : function() {
		// initialize local object vars
		this.countryDDL = $dom.getById('ddl_CountryID');
		this.stateprovDDL = $dom.getById('ddl_StateID');
		this.stateDDLdiv = $dom.getById('stateDDLdiv');
		
		// on page load, check if state/province ddl should be enabled
		this.toggleStateProvDDL_do(this.countryDDL);
		
		$event.add(this.countryDDL,'change',this.toggleStateProvDDL);
	},
	
	toggleStateProvDDL : function() {
		dynamicSearchDDLs.toggleStateProvDDL_do(this);
	},
	toggleStateProvDDL_do : function(countryDDL) {
		if (countryDDL.selectedIndex == 1 || countryDDL.selectedIndex == 2) {
			//show the State/Province DDL
			this.stateDDLdiv.style.visibility = "visible";
		} else {
			//reset ddl to 'select all'
			this.stateprovDDL.selectedIndex = 0;
			//hide the State/Province DDL
			this.stateDDLdiv.style.visibility = "hidden";
		}
	}
}
$pop.event.add(window,'load',dynamicSearchDDLs.init);

/*
Object that attaches an event to the name textbox to search when "enter" key is pressed
*/
var searchOnEnter = {
	authorField : Object,
	searchButton : Object,

	init: function() {
		searchOnEnter.build();
	},
	
	build : function() {
		this.authorField = $dom.getById('txt_AuthorFirst');
		this.searchButton = $dom.getById('Img_btn_Search');
		
		$event.add(this.authorField,'keypress',this.submitSearch);
	},
	
	submitSearch : function(e) {
		var ev = e || window.event;
		if (ev.keyCode == 13) {
			$pop.event.stop(ev);
			searchOnEnter.searchButton.click();
		}
	}
}
$pop.event.add(window,'load',searchOnEnter.init);
