/*
** Function to make external or image anchors open in a new window
*/
function setExternalLinks() {
	if (document.getElementsByTagName) {
		var AnchorArray = document.getElementsByTagName("a");

		for (var i = 0; i < AnchorArray.length; i++) {

			if (AnchorArray[i].getAttribute("href") && AnchorArray[i].getAttribute("rel") == "external") {
				AnchorArray[i].target = "_blank";
				AnchorArray[i].className += " externallink";
			}

			if (
				AnchorArray[i].getAttribute("href")
				&& AnchorArray[i].getAttribute("rel")
				&& AnchorArray[i].getAttribute("rel").substring(0,5) == "other"
			)
				if (AnchorArray[i].getAttribute("rel").length > 6)
					AnchorArray[i].target = AnchorArray[i].getAttribute("rel").substring(6,60);
				else
					AnchorArray[i].target = "_blank";

			if (AnchorArray[i].getAttribute("href") && AnchorArray[i].getAttribute("rel") == "image")
				AnchorArray[i].target = "_blank";
		}
	}
}

/*
** IE6 popup menu code from http://www.csscreator.com/menu/multimenu.php
*/
function activateDropDown(ULID) {
	if (document.getElementById(ULID)) {

		if (document.all && document.getElementById(ULID).currentStyle) {  
			var navroot = document.getElementById(ULID);
	
			/* Get all the list items within the menu */
			var lis=navroot.getElementsByTagName("LI");  
			for (i=0; i<lis.length; i++) {
	
				/* If the LI has another menu level */
				if(lis[i].lastChild.tagName=="UL"){
					lis[i].onmouseover=function() {this.lastChild.style.display="block";}
					lis[i].onmouseout=function() {this.lastChild.style.display="none";}
				}
			}
		}

	}
}

/*
** Previous version of the dropdown function - kept here for backwards compatibility
*/
function activateMenu() {
	activateDropDown('navigation');
}

/*
** Function to set the focus to the quick search bar when someone clicks one of the radio btns
*/
function quickSearchFocus() {
	SearchForm = document.getElementById("searchform_query");
	SearchForm.focus();
	if (SearchForm.value == "Search UWF")
		SearchForm.value = "";
}

/*
** Function to rotate header images every few seconds
*/
function rotateHeaderImage(ImgObjectID,Delay,CurrentImage,TotalImages,FilenamePrefix) {
	var ParamString = "rotateHeaderImage('" + ImgObjectID + "'," + Delay + "," 
		+ (CurrentImage+1) % TotalImages
		+ "," + TotalImages + ",'" + FilenamePrefix + "')";
		
	document.getElementById(ImgObjectID).src = FilenamePrefix + (CurrentImage % TotalImages) + ".jpg";
	
	self.setTimeout(ParamString, Delay*1000);
}


/*
** =================================================================================================
** functions that control toggle groups (boxes that open/close with onclick events)
*/

/*
** global variables that set image src loc. for use as icons meaning, "open" and "close"
*/
var Twisty_Opened = "/webpresence/resources/common/icon/twistie/plus/icn_twisty_opened.gif";
var Twisty_Closed = "/webpresence/resources/common/icon/twistie/plus/icn_twisty_closed.gif";
var Twisty_OpenedAll = "/webpresence/resources/common/icon/twistie/plus/icn_twistyall_opened.gif";
var Twisty_ClosedAll = "/webpresence/resources/common/icon/twistie/plus/icn_twistyall_closed.gif";

/*
** open/close functions (don't call these directly. use toggleShown instead.)
*/
function expand(TargetID) {
	document.getElementById(TargetID).style.display = "";
	document.getElementById(TargetID + "btn").style.backgroundImage = "url(" + Twisty_Opened + ")";
	if (document.getElementById(TargetID + "summary") != null)
		document.getElementById(TargetID + "summary").style.display = "none";
}
function collapse(TargetID) {
	document.getElementById(TargetID).style.display = "none";
	document.getElementById(TargetID + "btn").style.backgroundImage = "url(" + Twisty_Closed + ")";
	if (document.getElementById(TargetID + "summary") != null)
		document.getElementById(TargetID + "summary").style.display = "";
}

/*
** function to expand or collapse an object (show it or hide it)
*/
function toggleShown(TargetID) {
	if (document.getElementById(TargetID).style.display == "none")
		expand(TargetID);
	else
		collapse(TargetID);

	// the first time this function is called, we remove the href attr (it's only needed for users
	// that don't have javascript running.
	document.getElementById(TargetID + "btn").removeAttribute('href');
}

/*
** function to expand or collapse every object that's a child of ParentID
*/
function expand_collapse_all(ParentID,TagName,ClassName,Expand,Caller) {
	if (Caller.getAttribute('Expanded') == null) Caller.setAttribute('Expanded',Expand);
	else {
		Caller.setAttribute('Expanded',Caller.getAttribute('Expanded')*-1);
		Expand = Caller.getAttribute('Expanded');
	}

	var Children = document.getElementById(ParentID).getElementsByTagName(TagName);
	for (var i=0; i < Children.length; i++) {
		if (Children[i].className.indexOf(ClassName) != -1) {
			if (Expand == 1) expand(Children[i].id);
			else collapse(Children[i].id);
		}
	}

	Caller.removeAttribute('href');
	if (Expand == 1) Caller.style.backgroundImage = "url(" + Twisty_OpenedAll + ")";
	else Caller.style.backgroundImage = "url(" + Twisty_ClosedAll + ")";

}


/*
** =================================================================================================
** functions related to flash and flex
*/

/*
** displays a flash object (if you hardcode the <object> tag then popout menus will go behind it)
*/
function showFlash(url,width,height) {
	document.write('<object type="application/x-shockwave-flash" data="' + url + '" style="width:' + width + ';height:' + height + ';">');
	document.write('<param name="movie" value="' + url + '"/>');
	document.write('<param name="wmode" value="opaque"/>');
	document.write('</object>');
}

/*
** puts a flash <object> tag in the innerHTML of another element
*/
function putFlash(url,width,height,id,containerElement) {
	var containerObj = document.getElementById(containerElement);
	if (containerObj != null) {
		var tmp="";
		tmp+= "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"";
		tmp+= 'codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" width="' + width + '" height="' + height + '" id="' + id + '">';
		tmp+= '<param name="movie" value="' + url + '" />';
		tmp+= '<param name="wmode" value="opaque"/>';
		tmp+= '<embed src="' + url + '" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" "http://www.adobe.com/go/getflashplayer" wmode="opaque"/>';
		tmp+= '</object>';
		containerObj.innerHTML = tmp;
		return true;
	} else 
		return false;
}
