//<script>

var disabledNavigationMessage = "Members-Only: Login required to access this page";
var debugStuff = "";
var navObjs = new Array();
var imgRadioButtonWhite = new Image();
var imgRadioButtonDark = new Image();
var imgRadioButtonWhiteSelected = new Image();
var imgRadioButtonDarkSelected = new Image();
var imgCheckBox = new Image();
var imgCheckBoxChecked = new Image();

window.onload = initWindow;
	
function initWindow() {
	if (typeof(preInitWindow) == "function")
		preInitWindow();
	var oPrimaryNav = document.getElementById("tdPrimaryNav");
	if (oPrimaryNav)
		initNavigation(oPrimaryNav);
	imgRadioButtonWhite.src = "images/RadioButtonWhite.gif"
	imgRadioButtonDark.src = "images/RadioButtonDark.gif"
	imgRadioButtonWhiteSelected.src = "images/RadioButtonWhiteSelected.gif"
	imgRadioButtonDarkSelected.src = "images/RadioButtonDarkSelected.gif"
	imgCheckBox.src = "images/CheckBox.gif"
	imgCheckBoxChecked.src = "images/CheckBoxChecked.gif"
	var scroller = document.getElementById("sponsorScroller");
	if (scroller)
		scroller.onmouseout();
	if (typeof(postInitWindow) == "function")
		postInitWindow();
}

function initNavigation(oTarget) {
	if (!oTarget) {
		window.status = "WARNING - Primary Nav failed to initialize";
		return;
	}
	if (oTarget.childNodes) {
		for (var i=0; i<oTarget.childNodes.length; i++) {
			initNavigation(oTarget.childNodes[i]);
		}
	}
	if (oTarget.id) {
		var idPrefix = oTarget.id.slice(0,3);
		switch (idPrefix) {
			case "nav":
				oTarget.onmouseover = function() { showSub(this); }
				break;
			case "nsc":
				oTarget.onmouseover = function() { showObject(this); }
				oTarget.onmouseout = function() { hideSub(this); }
				navObjs.push(oTarget); // Add NavSubContainer to navObjs Array
				break;
		}
	}
	if (oTarget.className == "navSubDisabled" && oTarget.title == "")
		oTarget.title = disabledNavigationMessage;
}

function centerWindow() {
	// Center the current Window (can be used only after <body> element is defined)
	if (document.body && document.body.offsetWidth) {
		wWidth = parseInt(document.body.offsetWidth + 10, 10);
		wHeight = parseInt(document.body.offsetHeight + 15, 10);
		wPosX = (screen.availWidth / 2) - (wWidth / 2);
		wPosY = (screen.availHeight / 2) - (wHeight / 2);
		window.moveTo(wPosX, wPosY);
	}
}

function checkWindowSize() { 
	// Fixes window size to show entire contents (You're welcome Glenda!) [IE Only]
	if (document.body && document.body.offsetHeight && document.body.scrollWidth) {
		var windowWidthMod = 0;
		var windowHeightMod = 0;
		if (document.body.scrollWidth > document.body.offsetWidth)
			windowWidthMod = parseInt(document.body.scrollWidth - document.body.offsetWidth + 10, 10);
		if (document.body.scrollHeight + 10 > document.body.offsetHeight)
			windowHeightMod = parseInt(document.body.scrollHeight - document.body.offsetHeight + 15, 10);
		if (windowWidthMod > 0 || windowHeightMod > 0)
			window.resizeBy(windowWidthMod, windowHeightMod);
	}
}

function isEmailAddress(sEmail) {
	// Determine if a string is a valid e-mail address (Abc_123.xxx.xxx-yyy-zzz@Abc_123.Abc_123.TLD)
	// This function utterly fails with "friendly" addresses like "John Smith <john@here.com>"
	// Note: when escaping a character in a JavaScript RegExp Pattern string, TWO backslashes (\\) must be used!
	var gTLDs = "com|edu|gov|int|mil|net|org|biz|info|name|pro|aero|coop|museum";
	var rePattern = "^[a-zA-Z0-9\\._\\-]+@[a-zA-Z0-9\\._\\-]+\\.(?:[a-zA-Z]{2}|" + gTLDs + ")$";
	var re = new RegExp(rePattern, "i");
	return re.test(sEmail);
}


function haltScroller(objContainer) {
	try {
		var timerID = eval("scrollerTimer" + objContainer.id + "ID");
		window.clearInterval(timerID);
	} catch (ex) {}
}

function hideObject(oTarget) {
	if (oTarget) {
		oTarget.style.visibility = "hidden";
		oTarget.timerID = "";
		hideSelectObjects(false);
	}
}

// Hide/Show SELECT boxes since they always have top-most position (IE ONLY)
function hideSelectObjects(forceHide) {
	if (document.all) {
		var AllSelects = document.getElementsByTagName("SELECT");
		for (var i=0; i < AllSelects.length; i++) {
			var obj = AllSelects(i);
			if (obj.id != "TranslateInto") {
				if (forceHide) {
					if (!obj.originalVisibility) {
						if (obj.style.visibility == "")
							obj.originalVisibility = "visible";
						else
							obj.originalVisibility = obj.style.visibility;
					}
					obj.style.visibility = "hidden";
				} else {
					if (obj.originalVisibility)
						obj.style.visibility = obj.originalVisibility;
				}
			}
		}
	}
}

function hideSub(oTarget) {
	if (oTarget) {
		var cmd = "hideObject(document.getElementById('" + oTarget.id + "'))";
		oTarget.timerID = window.setTimeout(cmd, 500);
	}
}

function hideWait() {
	var o = document.getElementById("showWait");
	if (o)
		o.style.display = "none";
}

function initScroller(objContainer, contentID, scrollDelay) {
	var objContent = document.getElementById(contentID);
	var containerHeight = parseInt(objContainer.style.height.slice(0, -2), 10);
	var contentHeight = parseInt(objContent.scrollHeight);
	var timerID = window.setInterval("moveObject(\"" + contentID + "\", 0, -1, null, " + -contentHeight + ", null, " + containerHeight + ");", scrollDelay);
	eval("scrollerTimer" + objContainer.id + "ID = " + timerID);
}

function moveObject(objectID, offsetX, offsetY, limitX, limitY, resetX, resetY) {
	var o = document.getElementById(objectID);
	var currentX = parseInt(o.style.left.slice(0, -2), 10);
	if (isNaN(currentX))
		currentX = 0;
	var newX = currentX + offsetX;
	var currentY = parseInt(o.style.top.slice(0, -2), 10);
	if (isNaN(currentY))
		currentY = 0;
	var newY = currentY + offsetY;
	if ((offsetX) && offsetX != 0) {
		if (!limitX || ((limitX > 0 && newX <= limitX) || (limitX < 0 && newX >= limitX)))
			o.style.left = newX + "px";
		else {
			if (!isNaN(resetX))
				o.style.left = resetX + "px";
		}	
	}
	if ((offsetY) && offsetY != 0) {
		if (!limitY || ((limitY > 0 && newY <= limitY) || (limitY < 0 && newY >= limitY)))
			o.style.top = newY + "px";
		else {
			if (!isNaN(resetY))
				o.style.top = resetY + "px";
		}	
	}
}

function newFeature() {
	alert("We're sorry, but this feature is not \nyet available.  Please try again soon!");
}

function popupWindow (wWidth, wHeight, wHREF, wName) {
	// Popup a Window
	wPosX = (screen.availWidth / 2) - (wWidth / 2);
	wPosY = (screen.availHeight / 2) - (wHeight / 2);
	wFeatures = "top=" + wPosY + ", left=" + wPosX + ", width=" + wWidth + ", height=" + wHeight +
		", scrollbars=yes";
	window.open(wHREF, wName, wFeatures);
}

function setCB(targetID) {
	var oTarget = document.getElementById(targetID);
	var cbhf = document.getElementById(oTarget.name);
	if (oTarget.src == imgCheckBoxChecked.src) {
		oTarget.src = imgCheckBox.src;
		oTarget.status = "";
		cbhf.value = "";
	} else {
		oTarget.src = imgCheckBoxChecked.src;
		oTarget.status = "Checked";
		cbhf.value = oTarget.value;
	}
}

function setRBs(targetID) {
	var oTarget = document.getElementById(targetID);
	var rbs = document.getElementsByName(oTarget.name);
	var rbhf = document.getElementById(oTarget.name);
	for (var i=0; i<rbs.length; i++) {
		var oRB = rbs[i];
		if (oRB.tagName == "IMG") {
			if (oRB.id == oTarget.id) {
				if (oRB.cBG == "White")
					oRB.src = imgRadioButtonWhiteSelected.src;
				else
					oRB.src = imgRadioButtonDarkSelected.src;
				rbhf.value = oRB.value;
			} else {
				if (oRB.cBG == "White")
					oRB.src = imgRadioButtonWhite.src;
				else
					oRB.src = imgRadioButtonDark.src;
			}
		}
	}
}

function showdisclaimer() {
	// Show legal disclaimer when linking to an an external website
	alert("You are about to leave the IAMP web site.\n\n" +
		"The IAMP makes no guarantees concerning the accuracy or \n" +
		"completeness of any of the information contained on the \n" +
		"site being linked to.\n\n" + 
		"Additionally, the IAMP expressly disclaims any and all \n" + 
		"liability for any use of information contained therein.");
	return true;
}

function showObject(oTarget) {
	if (oTarget) {
		if (oTarget.timerID && oTarget.timerID != "")
			window.clearTimeout(oTarget.timerID);
		oTarget.style.visibility = "";
	}
}

function showSub(oTarget) {
	var subID = "nsc" + oTarget.id.slice(3);
	var oSub = document.getElementById(subID)
	// Hide all other subs
	for (var i=0; i<navObjs.length; i++) {
		if (navObjs[i].style.visibility != "hidden")
			hideObject(navObjs[i]);
	}
	// Hide all SELECT boxes since they always have top-most position (IE ONLY)
	if (oTarget.hideSelects == "true")
		hideSelectObjects(true);
	showObject(oSub);
}

function showWait() {
	var o = document.getElementById("showWait");
	if (o)
		o.style.display = "block";
	//return false; // Unremark to test by disabling the link itself
}

function unObscureWindow() {
	// Show all of the current Window (move it away from edge of screen if the right or bottom edge goes off screen)
	if (document.body && document.body.offsetWidth && screen.availWidth) {
		var windowWidth = parseInt(document.body.offsetWidth + 10, 10);
		var windowHeight = parseInt(document.body.offsetHeight + 15, 10);
		var windowX = window.screenLeft;
		var windowY = window.screenTop;
		var windowRight = parseInt(windowX + windowWidth, 10);
		var windowBottom = parseInt(windowY + windowHeight, 10);
		if (windowRight > parseInt(screen.availWidth, 10)) {
			window.moveBy(parseInt(screen.availWidth - windowRight, 10), 0);
		}
		if (windowBottom > parseInt(screen.availHeight, 10)) {
			window.moveBy(0, parseInt(screen.availHeight - windowBottom, 10));
		}
	}
}

function viewData(tbl, target, autoClose) {
	var url = "https://members.IAMP.biz/database/db_view.asp";
	url += "?t=" + tbl;
	switch (target) {
		case "parent":
			window.parent.location.href = url;
			break;
		case "opener":
			window.opener.location.href = url;
			if (autoClose)
				self.close();
			break;
		default:
		location.href = url;
	}
}
