//
// Functions for the focus search
//
var pract_divs = new Array;

function pract_onLoad()
{
	// Find all the hide/show layers associated with this search
	// and store them in a global variable
	var divs = getElementsByClassName('PractSearchLayer', 'div');
	for (var i = 0; i < divs.length; i++) {
		pract_divs[i] = divs[i].id;
	}

	// Load the initial select
	pract_loadOptions('PractFocus1', pract_loader());

	document.getElementById('PractFocusGender').selectedIndex = 0;
}

function pract_onChange(ctl, nextCtlId)
{
	var e = ctl.options[ctl.selectedIndex];

	// hide all the hide/show layers after this one
	for (var i = 0; i < pract_divs.length; i++) {
		if (pract_divs[i] == ctl.id + '_Layer') {
			while (++i < pract_divs.length) {
				hideShowLayer(pract_divs[i], 'HIDE');
			}
		}
	}

	_focus_resetGender('PractFocusGender'); //From iss_focus.js

	if (e.sub) {
		if (e.sub == 'gender') {
			if (e.value) {
				hideShowLayer('PractGender', 'SHOW');
				_focus_setGender('PractFocusGender'); //From iss_focus.js
				hideShowLayer('PractLanguage', 'SHOW');
			}
		} else if (nextCtlId) {
			pract_loadOptions(nextCtlId, e.sub);
			if (e.value) {
				hideShowLayer(nextCtlId + '_Layer', 'SHOW');
			}
		}
	}
}

function pract_onSubmit(form)
{
	var e = document.getElementById('PractFocus1');
	if (e.value == '' || e.value == null) {
		alert("Please select a Service Area");
		return false;
	}

	return true;
}

//////////////////////////////////////////////////////////////////////
// Load a select box with the appropriate options
// and set the label on the box
//
function pract_loadOptions(id, sub)
{
	var e = document.getElementById(id);

	// Load the select options
	e.options.length = 0;
	for (var i = 0; i < sub.options.length; i++) {
		e.options[i] = sub.options[i];
	}
	e.selectedIndex = 0;

	// Set the title
	if (sub.title) {
		var label = document.getElementById(id + '_Label');
		if (label) {
			label.innerHTML = sub.title + ':';
		}
	}
}

//////////////////////////////////////////////////////////////////////
// Helper routine, used from the generated javascript
//
function focus_option(sub, text)
{
	var val = focus_option.arguments.length > 2 ? focus_option.arguments[2] : text;
	var o = new Option(text, val);
	if (sub) {
		o.sub = sub;
	}
	return o;
}
