// javascript for newspaper search page
//
// $Revision: #1 $
// $DateTime: 2009/01/23 15:49:54 $
// $Author: Jeris $

// event handler for full search country/state boxes:
// if you choose a country other than USA, the state box blanks and disables itself.
// if you choose a country blank or USA, the state box enables itself.

function country_change_state() {
	if (document && document.getElementById) {
		var state_box = document.getElementById('f_fs_state');
		if (document.getElementById('f_fs_country').selectedIndex > 1) {
			state_box.selectedIndex = 0;
			state_box.disabled = true;
			state_box.className = 'disabled';
		} else {
			state_box.disabled = false;
			state_box.className = '';
		}
	}
	return true;
}

// event handler for year boxes:
// if you choose 'between' in the left one, the right one snaps to 'and' and the right
// year box undisables itself.  if you choose 'equal' in the left one, the right one snaps
// to blank and the right year box disables itself.

function year_cond_change () {
	if (document && document.getElementById) {
		var behavior = document.getElementById('f_fs_year_cond_1').value;
		var right_cond_box = document.getElementById('f_fs_year_cond_2');
		var right_value_box = document.getElementById('f_fs_year_value_2');
		if (behavior == 'between') {
			right_cond_box.disabled = false;
			right_cond_box.selectedIndex = 1;
			right_cond_box.disabled = true;
			right_value_box.disabled = false;
			right_value_box.className = '';			
		} else if (behavior == 'equal') {
			right_cond_box.disabled = false;
			right_cond_box.selectedIndex = 0;
			right_cond_box.disabled = true;
			right_value_box.disabled = true;
			right_value_box.className = 'disabled';			
		}
	}
	return true;
}

// onload handler:
// register event handlers and disable the right year box.

function window_onload() {
	if (document && document.getElementById) {
		var state_box = document.getElementById('f_fs_state');
		var right_cond_box = document.getElementById('f_fs_year_cond_2');
		var right_value_box = document.getElementById('f_fs_year_value_2');

		document.getElementById('f_fs_country').onchange = country_change_state;
		document.getElementById('f_fs_year_cond_1').onchange = year_cond_change;
		state_box.disabled = false;
		right_cond_box.disabled = true;
		right_cond_box.className = 'disabled';
		if (document.getElementById('f_fs_year_cond_1').selectedIndex == 0) {
			right_value_box.disabled = true;
			right_value_box.className = 'disabled';		
		}
	}
	return true;
}
window.onload = window_onload;
