var onLoadHandlers = new Array();
var baseHref = "";

function registerOnLoadHandler(f) {
	if( f == null ) return;
	onLoadHandlers[onLoadHandlers.length] = f; // push not supported on IE5
};
var onLoadStarted = false;
function onLoadChain() {
	if( onLoadStarted ) return; // sometimes this gets called more than once
	onLoadStarted = true;
	for(var i = 0; i < onLoadHandlers.length; i++)
		onLoadHandlers[i]();
};
window.onload = onLoadChain;

function isIE() {
	// Opera DOES implement document.all when in IE-masquerading mode, and reports as MSIE,
	// so we explicitly check for Opera as well as check for IE.
	return navigator.appVersion.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Opera') == -1;
};

function getBaseHREF()//get's base path of stylesheets to be used for image swapping
{
	if(document.styleSheets.length > 0)
	{
		var cssUrl = document.styleSheets[0].href;
		baseHref = cssUrl.substring(0,cssUrl.indexOf("collage/"));
	}
	else
	{
		baseHref = "";
	}
}
registerOnLoadHandler(getBaseHREF);

/***********************************************************************
 * Common utility functions
 ***********************************************************************/

// getElementsByTagName returns all descendant nodes,
// but this method returns only those nodes that are immediate children.
function getImmediateChildrenByTagName(element, tagName)
{
	if( !element ) return new Array(); // quit without error if null is sent in.
	var list = element.getElementsByTagName(tagName);
	// Keep elements that are immediate children 
	// of supplied element.
	var finalList = new Array();
	var finalIdx = 0;
	for( var i = 0; i < list.length; i++ )
		if( list[i].parentNode == element )
			finalList[finalIdx++] = list[i];
	return finalList;
};

function getElementsByClassName(className, container, tagName) {
	var outArray = new Array();
	var all = container.getElementsByTagName(tagName ? tagName : '*');
	for( var i = 0; i < all.length; i++ )
	{
		if( all[i].className.substr() == className ) outArray[outArray.length] = all[i];
	}
	return outArray;
};

// function useful because Safari gets confused when there is more than one element with the same ID 
// even if only one of the elements is currently being displayed
function getChildElementById(parent, id)
{
	for(var i=0; i<parent.childNodes.length; ++i)
	{
		if(parent.childNodes[i].id == id)
		{
			return parent.childNodes[i];
		}
	}
}

function doRYLogin()
{
	document.cookie = 'SECURE_COOKIE=anakincookieookie; domain=.byu.edu; path=/';
	document.cookie = 'usr_byu_edu=anakincookieookie; domain=.byu.edu; path=/';
	document.cookie = 'role_byu_edu=anakincookieookie; domain=.byu.edu; path=/';
	document.cookie = 'byu_ry_po_session=anakincookieookie; domain=.byu.edu; path=/';
	document.cookie = 'SMSESSION=anakincookieookie; domain=.byu.edu; path=/';
	return true;
}

function setCookie(cValue, cookieID) {
	var NameOfCookie = cookieID;
	document.cookie = NameOfCookie + "=" + escape(cValue);
};

function unsetCookie(cookieID) {
	setCookie (null, cookieID);
};

function getCookie(cookieID) {
	var dc = document.cookie, prefix = cookieID + "=", begin = dc.indexOf("; " + prefix);
	if (begin == -1) { 
		begin = dc.indexOf(prefix); 
		if (begin != 0) 
			return null; 
	}
	else 
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) 
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
};
        sfHover = function() {
               var sfEls = document.getElementById("LinksBar").getElementsByTagName("LI");
               for (var i=0; i<sfEls.length; i++) {
                       sfEls[i].onmouseover=function() {
                               this.className+=" sfhover";
                       }
                       sfEls[i].onmouseout=function() {
                               this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                       }
               }
        }
        if (window.attachEvent) window.attachEvent("onload", sfHover);                     
        
