function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Basically changes display from none to whatever you want.
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
	
}

// Jeremy Keith's function to turn something on and others off.
function toggleSection(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.display = "none";
    } else {
      divs[i].style.display = "block";
    }
  }
}


// Nice function that helps you add alternating classes to any number of child elements.

function striper(parentElementTag, parentElementClass, childElementTag, styleClasses)
{
	var i=0,currentParent,currentChild;
	// capability and sanity check
	if ((document.getElementsByTagName)&&(parentElementTag)&&(childElementTag)&&(styleClasses)) {
		// turn the comma separate list of classes into an array
		var styles = styleClasses.split(',');
		// get an array of all parent tags
		var parentItems = document.getElementsByTagName(parentElementTag);
		// loop through all parent elements
		while (currentParent = parentItems[i++]) {
			// if parentElementClass was null, or if the current parent's class matches the specified class
			if ((parentElementClass == null)||(currentParent.className == parentElementClass)) {
				var j=0,k=0;
				// get all child elements in the current parent element
				var childItems = currentParent.getElementsByTagName(childElementTag);
				// loop through all child elements
				while (currentChild = childItems[j++]) {
					// based on the current element and the number of styles in the array, work out which class to apply
					k = (j+(styles.length-1)) % styles.length;
					// add the class to the child element - if any other classes were already present, they're kept intact
					currentChild.className = currentChild.className+" "+styles[k];
				}
			}
		}
	}
}

// Really handy function. Adds any class you want to any element you want.

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

// Finds all the elements of a certain class. Pretty handy.

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// for the sources pop-ups

function sp_Open( sURL , sTitle , sParameters ) {
    var remote = window.open( '' , sTitle , sParameters );
    remote.location.replace(sURL);
    if (!remote.opener)
        remote.opener = self;
    if (window.focus)
        remote.focus();
    return remote;
    }
    codexmendoza = window.codexmendoza;
    if (!codexmendoza)
    codexmendoza = null;
    function SpawnNewWindow0( url , name )
    {
    myWidth = 412;
    myHeight = 603;
    myLeft = 5;
    myTop = 5;
    if (window.screen)
    {
        var myLeft = ( ( screen.availWidth - 10 ) - 412 ) / 2;
        var myTop = ( ( screen.availHeight - 30 ) - 603 ) / 2;
    }
    return sp_Open( url , name , "width=" + myWidth + ",height=" + myHeight + ",left=" + myLeft + ",top=" + myTop + ",screenX=" + myLeft + ",screenY=" + myTop + ",scrollbars=yes,resizable=yes,toolbar=no,status=no,menubar=yes,null,null");
    }
