// --------------------------------------------------------------------------------
// nsatt_adv.js
// --------------------------------------------------------------------------------

var nsatt_adv_pre = "tmpl_nsatt_AdvancedForm_nsattAdvForm_";

// --- Attach JS to document elements and execute simple statements. ---
ow_f_AppendLoadEvent(
function() {

	if (document.getElementById(nsatt_adv_pre + "rg") != null) ow_f_AddEvent(document.getElementById(nsatt_adv_pre + "rg"), "change", nsatt_adv_selectRegion, false);
	if (document.getElementById(nsatt_adv_pre + "comm") != null) ow_f_AddEvent(document.getElementById(nsatt_adv_pre + "comm"), "change", nsatt_adv_selectCommunity, false);
	if (document.getElementById(nsatt_adv_pre + "area") != null) ow_f_AddEvent(document.getElementById(nsatt_adv_pre + "area"), "change", nsatt_adv_selectArea, false);
	
	if (document.getElementById("openMap") != null) ow_f_AddEvent(document.getElementById("openMap"), "click", nsatt_adv_OpenMap, false);

	if (document.getElementById(nsatt_adv_pre + "subm") != null) ow_f_AddEvent(document.getElementById(nsatt_adv_pre + "subm"), "click", nsatt_adv_Click, false);

	if (document.getElementById("nsatt_advForm") != null) {
		var inp = document.getElementById("nsatt_advForm").getElementsByTagName("input");
		for (var i = 0; i < inp.length; i++) {
			if (inp[i].type == "text") ow_f_AddEvent(inp[i], "keypress", nsatt_adv_Key, false);
		}
	}
	
}
);

// --------------------------------------------------------------------------------
// nsatt_adv_Key()
// Fires when a textfield had focus and ENTER was pressed.
function nsatt_adv_Key(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	if (code == 13) {
		document.getElementById(nsatt_adv_pre + "subm").click();
		if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
	}
}

// --------------------------------------------------------------------------------
// nsatt_adv_OpenMap()
// Fires when the travelway dropdown is selected.
// --------------------------------------------------------------------------------
function nsatt_adv_OpenMap() {
	var w =	window.open("/site/regionmap.html", "RegionMap", "status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,width=550,height=302");
}

// --------------------------------------------------------------------------------
// nsatt_adv_selectRegion()
// Fires when the region dropdown is selected.
// --------------------------------------------------------------------------------
function nsatt_adv_selectRegion() {
	if (document.getElementById(nsatt_adv_pre + "comm") != null) document.getElementById(nsatt_adv_pre + "comm").selectedIndex = 0;
	if (document.getElementById(nsatt_adv_pre + "area") != null) document.getElementById(nsatt_adv_pre + "area").selectedIndex = 0;
}

// --------------------------------------------------------------------------------
// nsatt_adv_selectCommunity()
// Fires when the community dropdown is selected.
// --------------------------------------------------------------------------------
function nsatt_adv_selectCommunity() {
	if (document.getElementById(nsatt_adv_pre + "rg") != null) document.getElementById(nsatt_adv_pre + "rg").selectedIndex = 0;
	if (document.getElementById(nsatt_adv_pre + "area") != null) document.getElementById(nsatt_adv_pre + "area").selectedIndex = 0;
}

// --------------------------------------------------------------------------------
// nsatt_adv_selectArea()
// Fires when the area dropdown is selected.
// --------------------------------------------------------------------------------
function nsatt_adv_selectArea() {
	if (document.getElementById(nsatt_adv_pre + "rg") != null) document.getElementById(nsatt_adv_pre + "rg").selectedIndex = 0;
	if (document.getElementById(nsatt_adv_pre + "comm") != null) document.getElementById(nsatt_adv_pre + "comm").selectedIndex = 0;
}

// --------------------------------------------------------------------------------
// nsatt_adv_Click()
// Fires when the submit button was clicked.
// --------------------------------------------------------------------------------
function nsatt_adv_Click(e) {
	if (!nsatt_adv_Valid()) {
		if (!e) var e = window.event;
		if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
	} else {
		return;
	}
}

// --------------------------------------------------------------------------------
// nsatt_adv_Valid()
// Validates the data entered in the Accommodations app.
// --------------------------------------------------------------------------------
// Arguments:
//	- none
// Returns:
//	- the results of the validation [boolean]
// --------------------------------------------------------------------------------

function nsatt_adv_Valid() {
	return true;
}
