// Javascript for RRR

// GENERATES EMAIL ADDRESS "SAFE" FROM HARVESTERS
function generateAntiSpiderEmail(Username, DomainName, TLD, OutputText, NoLink) {
	EmailAddress = Username + "&#64;" + DomainName + "&#46;" + TLD;
	OutputText   = ((OutputText)?OutputText:EmailAddress);
	
	document.write((NoLink)?OutputText:"<a href=\"ma" + "il" + "to:" + EmailAddress + "\">" + OutputText + "</a>");
}

// Image rollover for homepage
function imageLinkRollover(ImgObj, Over) {
	ImgObj.src = ImgObj.src.replace((Over)?'.jpg':'_light.jpg', (Over)?'_light.jpg':'.jpg');
}

// Toggles the Resource Library drop-down
function ResourcesMenuToggle(Display, OverrideContainerID) {
	document.getElementById((OverrideContainerID != null)?OverrideContainerID:'ResourcesSubMenu').style.display = (Display)?'block':'none';
}
// Toggles the Resource Library drop-down
function ResourcesMenuToggle2(Display, OverrideContainerID) {
	document.getElementById((OverrideContainerID != null)?OverrideContainerID:'ResourcesSubMenu2').style.display = (Display)?'block':'none';
}


// FUNCTIONS FOR DISCOVERING THE CURRENT PAGE/SECTION AND HIGHLIGHTING THE CORRECT TOP NAV LINK

function getScriptName(OverrideURL, IncludeQueryStr) {
	UseURL         = (OverrideURL)?OverrideURL:document.location.href;
	UseURL         = UseURL.replace(/#.*/, '');
	PosOfSlash     = UseURL.lastIndexOf('/')+1;
	QueryStrExists = UseURL.indexOf('?') != -1;
		
	if (!QueryStrExists || IncludeQueryStr)
		return UseURL.substr(PosOfSlash);	
	
	else if (QueryStrExists)
		return UseURL.substr(PosOfSlash, UseURL.indexOf('?')-PosOfSlash);
}

function trimHREF(HREF) {
	return HREF.substr(HREF.lastIndexOf('/'));
}

function setCSSClass(AObj, OverrideURL) {
	url = (OverrideURL != null)?OverrideURL:document.location.href;
	
	Protocol = new RegExp('^[A-Za-z]{3,6}\://');
	url      = url.replace(/#.*/, '').replace(Protocol, '').replace(/\/index.html.*$/, '');
	url      = url.substr(url.indexOf('/')+1);
	UrlArray = url.split('/');
	
	A_ID = AObj.getAttribute('id');
	
	for (var i = UrlArray.length-1; i >= 0; i--) {
		if (UrlArray[i] == A_ID) {
			AObj.className = 'TopNavOnPage';
			return;
		}
	}
	
	AObj.className = 'TopNav';
}

function loopThroughNavLinks() {
	TopNavLinks = document.getElementById('TopNavLinksContainer').getElementsByTagName('a');
	for (var i = 0; i < TopNavLinks.length; i++)
		setCSSClass(TopNavLinks[i]);
}



// OPENS A WINDOW TO DISPLAY AN IMAGE, BUT ALSO HAS A DOCUMENT.TITLE
function openImageWindow(ImgFile, WindowOptions, WindowTitle) {
	tmpName = Math.random();
	winName = String(tmpName).replace(/\./, "");

	imgWin = window.open("", winName, WindowOptions + ",left=" + getWindowCenterX(getVarsFromList(WindowOptions, "width")) + ",top=" + getWindowCenterY(getVarsFromList(WindowOptions, "height")));

	with (imgWin.document) {
		open();
		write("<html><head><title>" + WindowTitle + "</title></head><body onLoad=\"window.focus()\"><img src=\"" + ImgFile + "\"></body></html>");
		close();
	}
}

// GET HORIZONTAL CENTER OF WINDOW
function getWindowCenterX(w) {
	w = (w)?w:document.body.clientWidth;
	return ((screen.width-w)/2);
}

// GETS CERTAIN VARS FROM A LIST (seperated by commas with no comma at the end -- useful for grabbing vars from window.open options)
function getVarsFromList(VarList, GetVar) {

	IndexOfVar    = VarList.indexOf(GetVar + '=') + (GetVar.length + 1);
	CommaAfterVar = VarList.substr(IndexOfVar).indexOf(",");
	return (CommaAfterVar > 0)?VarList.substr(IndexOfVar, CommaAfterVar):VarList.substr(IndexOfVar);
}

// GET VERTICAL CENTER OF WINDOW
function getWindowCenterY(h) {
	h = (h || navigator.appName != "Microsoft Internet Explorer")?h:document.body.clientHeight;
	return ((screen.height-h)/2);
}