/* --------------------------------------------------------------------------------------------------------
AUTHOR:			Ryan Marincovich
DATE CREATED:	2008.05.23
File Purpose:	NMRA Common Javascript File
-------------------------------------------------------------------------------------------------------- */


// MAIN NAVIGATION FUNCTIONS/DATA ------------------------------------------

// load nav images
if (document.images) {
	nav_about_on = new Image();
	nav_about_on.src = "/_images/nav/nav_about_on.gif";
	nav_about_off = new Image();
	nav_about_off.src = "/_images/nav/nav_about_off.gif";
	nav_about_roll = new Image();
	nav_about_roll.src = "/_images/nav/nav_about_roll.gif";
	nav_membership_on = new Image();
	nav_membership_on.src = "/_images/nav/nav_membership_on.gif";
	nav_membership_off = new Image();
	nav_membership_off.src = "/_images/nav/nav_membership_off.gif";
	nav_membership_roll = new Image();
	nav_membership_roll.src = "/_images/nav/nav_membership_roll.gif";
	nav_events_on = new Image();
	nav_events_on.src = "/_images/nav/nav_events_on.gif";
	nav_events_off = new Image();
	nav_events_off.src = "/_images/nav/nav_events_off.gif";
	nav_events_roll = new Image();
	nav_events_roll.src = "/_images/nav/nav_events_roll.gif";
	nav_rules_regulations_on = new Image();
	nav_rules_regulations_on.src = "/_images/nav/nav_rules_regulations_on.gif";
	nav_rules_regulations_off = new Image();
	nav_rules_regulations_off.src = "/_images/nav/nav_rules_regulations_off.gif";
	nav_rules_regulations_roll = new Image();
	nav_rules_regulations_roll.src = "/_images/nav/nav_rules_regulations_roll.gif";
	nav_education_on = new Image();
	nav_education_on.src = "/_images/nav/nav_education_on.gif";
	nav_education_off = new Image();
	nav_education_off.src = "/_images/nav/nav_education_off.gif";
	nav_education_roll = new Image();
	nav_education_roll.src = "/_images/nav/nav_education_roll.gif";
	nav_communications_on = new Image();
	nav_communications_on.src = "/_images/nav/nav_communications_on.gif";
	nav_communications_off = new Image();
	nav_communications_off.src = "/_images/nav/nav_communications_off.gif";
	nav_communications_roll = new Image();
	nav_communications_roll.src = "/_images/nav/nav_communications_roll.gif";
	nav_government_affairs_on = new Image();
	nav_government_affairs_on.src = "/_images/nav/nav_government_affairs_on.gif";
	nav_government_affairs_off = new Image();
	nav_government_affairs_off.src = "/_images/nav/nav_government_affairs_off.gif";
	nav_government_affairs_roll = new Image();
	nav_government_affairs_roll.src = "/_images/nav/nav_government_affairs_roll.gif";
	nav_contact_on = new Image();
	nav_contact_on.src = "/_images/nav/nav_contact_on.gif";
	nav_contact_off = new Image();
	nav_contact_off.src = "/_images/nav/nav_contact_off.gif";
	nav_contact_roll = new Image();
	nav_contact_roll.src = "/_images/nav/nav_contact_roll.gif";
	
	icon_activity_on = new Image();
	icon_activity_on.src = "/_images/modules/icon_activity_on.gif";
	icon_activity_off = new Image();
	icon_activity_off.src = "/_images/modules/icon_activity_off.gif";
	icon_housing_on = new Image();
	icon_housing_on.src = "/_images/modules/icon_housing_on.gif";
	icon_housing_off = new Image();
	icon_housing_off.src = "/_images/modules/icon_housing_off.gif";
	icon_100_on = new Image();
	icon_100_on.src = "/_images/modules/icon_100_on.gif";
	icon_100_off = new Image();
	icon_100_off.src = "/_images/modules/icon_100_off.gif";
	
	tab_education_on = new Image();
	tab_education_on.src = "/_images/home/tab_education_on.gif";
	tab_education_off = new Image();
	tab_education_off.src = "/_images/home/tab_education_off.gif";
	tab_communications_on = new Image();
	tab_communications_on.src = "/_images/home/tab_communications_on.gif";
	tab_communications_off = new Image();
	tab_communications_off.src = "/_images/home/tab_communications_off.gif";
	tab_association_on = new Image();
	tab_association_on.src = "/_images/home/tab_association_on.gif";
	tab_association_off = new Image();
	tab_association_off.src = "/_images/home/tab_association_off.gif";
	tab_government_on = new Image();
	tab_government_on.src = "/_images/home/tab_government_on.gif";
	tab_government_off = new Image();
	tab_government_off.src = "/_images/home/tab_government_off.gif";
}

function navOn(which) {
	showNav(which);
	return true;
}
function navOff(which) {
	hideNav(which);
	return true;
}

// function to roll a nav button on
function navStayOn(which) {
	changeImages("nav_"+which,"nav_"+which+"_roll");
	return true;
}
// function to roll a nav button off
function navStayOff(which, state) {
	changeImages("nav_"+which,"nav_"+which+"_"+state);
	return true;
}

var currIcon = null;

function quicklinkIconOn(which) {
	if ((currIcon != null) && (currIcon != which)) {
		quicklinkIconOff(currIcon);
	}
	changeImages("icon_"+which,"icon_"+which+"_on");
	eval("document.getElementById('icon_text_" + which + "').style.display = 'block'");
	currIcon = which;
	return true;
}
function quicklinkIconOff(which) {
	changeImages("icon_"+which,"icon_"+which+"_off");
	eval("document.getElementById('icon_text_" + which + "').style.display = 'none'");
	return true;
}

var currTab = "education";

function featureTabOn(which) {
	if ((currTab != null) && (currTab != which)) {
		featureTabOff(currTab);
	}
	changeImages("tab_"+which,"tab_"+which+"_on");
	eval("document.getElementById('tab_" + which + "').style.zIndex = 20");
	eval("document.getElementById('bg_tabs_" + which + "').style.display = 'block'");
	currTab = which;
	return true;
}
function featureTabOff(which) {
	changeImages("tab_"+which,"tab_"+which+"_off");
	eval("document.getElementById('tab_" + which + "').style.zIndex = 10");
	eval("document.getElementById('bg_tabs_" + which + "').style.display = 'none'");
	return true;
}

var currPaymentSection = null;

function toggleFormPayment(which) {
	if ((currPaymentSection != null) && (currPaymentSection != which)) {
		currentPaymentObj = eval("document.getElementById('payment" + currPaymentSection + "').style");
		currentPaymentObj.display = 'none';
	}
	currPaymentSection = which;
	newPaymentObj = eval("document.getElementById('payment" + currPaymentSection + "').style");
	newPaymentObj.display = 'block';
	return true;
}

// UTILITY FUNCTIONS/DATA --------------------------------------------------

// sets cursor focus on the field given by param (formID.fieldID)
function formFocus(strFormAndFieldIDs) {
	if (isPageLoaded) {
		eval("document.forms." + strFormAndFieldIDs + ".focus();");
	} else {
		setTimeout("formFocus('" + strFormAndFieldIDs + "')", 100);
	}
}

// vars for dropdown menus
var navTimer = null;
var currNav = null;
var navHideDelay = 500;
var isNavLoaded = false;

// build dropdown objects (run onload)
function buildNav() {
	aboutDropNavObj = eval(doc + '"aboutDropNav"' + sty);
	membershipDropNavObj = eval(doc + '"membershipDropNav"' + sty);
	rules_regulationsDropNavObj = eval(doc + '"rules_regulationsDropNav"' + sty);
	educationDropNavObj = eval(doc + '"educationDropNav"' + sty);
	communicationsDropNavObj = eval(doc + '"communicationsDropNav"' + sty);
	government_affairsDropNavObj = eval(doc + '"government_affairsDropNav"' + sty);
	contactDropNavObj = eval(doc + '"contactDropNav"' + sty);
	isNavLoaded = true;
}

// shows a dropdown menu, hides any other dropdown that is currently showing
function showNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((currNav != null) && (currNav != which)) {
			eval(currNav + "DropNavObj.visibility = 'hidden'");
		}
		if ((which == "about") || (which == "membership") || (which == "rules_regulations") || (which == "education") || (which == "communications") || (which == "government_affairs") || (which == "contact")) {
			currNav = which;
			eval(currNav + "DropNavObj.visibility = 'visible'");
		}
	}
}
// hides a dropdown menu on a time delay
function hideNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((which == "about") || (which == "membership") || (which == "rules_regulations") || (which == "education") || (which == "communications") || (which == "government_affairs") || (which == "contact")) {
			navTimer = setTimeout(which + "DropNavObj.visibility = 'hidden'", navHideDelay);
		}
	}
}

// swap one or more images
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			var argArray = arguments[i].split('.');
			var objName;
			if ((document.layers && argArray.length > 1) || argArray.length <= 1) {
				objName = eval("document." + arguments[i]);
			} else {
				objName = eval("document." + argArray[argArray.length - 1]);
			}
			objName.src = eval(changeImages.arguments[i+1] + ".src");
		}
	}
}

// dhtml layer variables for cross-browser compatability
if (document.layers) {	// Netscape 4
	doc = "document[";
	conDoc = "document";
	sty = "]";
	htm = ".document";
	cls = "].className";
} else if (document.getElementById) {	// NS 6 or IE 5 and up (W3C compliant browsers).
	doc = "document.getElementById(";
	conDoc = "document.getElementById(";
	sty = ").style";
	htm = ".document";
	cls = ").className";
} else if (document.all) {	// IE 4
	doc = "document.all[";
	conDoc = "document.all[";
	sty = "].style";
	htm = "";
	cls = "].className";
}