﻿var navXmlhttp;

function GetNavLinks() {
	var url = 'http://www.catpa.org/main/generic.jsp?type=links';
	navXmlhttp = GetXMLHttp();
	navXmlhttp.onreadystatechange=ProcessNavLinks;
	navXmlhttp.open("GET",url,true);
	navXmlhttp.send(null);	
}
function ProcessNavLinks() {
	if (navXmlhttp.readyState==4) {
		if (navXmlhttp.status==200) {
			document.getElementById("nav").innerHTML = navXmlhttp.responseText;
			document.getElementById("footerNav").innerHTML = navXmlhttp.responseText;
		} else {
			alert("An error occured while trying to retrieve the nav links");
		}
	}
}
function GetXMLHttp () {
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		alert("Your browser does not support DOM");
	}
}
/*
	This function will search a given element's parent for this element's next sibling - it
	will only return the next sibling if it is the same node type as the original element. For
	instance if the body of a document contained div1 and div2 and the search was based on div1,
	div2 would be returned, however, if the document contained H1 followed by a div, the same
	search would return null. 
*/
function FindNextSameSibling(element) {
	var parentNode = element.parentNode;
	var children = parentNode.childNodes;
	var index = -1;
	for (i = 0; i < children.length; i++) {
		if (children[i] == element) {
			index = i;
			break;
		}
	}
	if (index != -1) {
		for (i = +index + 1; i < children.length; i++) {
			if (children[i].nodeType == element.nodeType) {
				return children[i];
			}
		}
	}
	return null;
}

function FindNextSibling(elId) {
	var origin = document.getElementById(elId);
	var originType = origin.nodeType;
	var index = -1;
	var next = null;
	if (origin != null) {
		var parent = origin.parentNode;
		var children = parent.childNodes;
		/* first iteration finds the origin list's index */
		for (i = 0; i < children.length; i++) {
			if (children[i] == origin) {
				index = i;
				break;
			}
		}
		/* now iterate through the remainder of the list for another non-TextNode element*/
		if (index != -1) {
			for (i = +index + 1; i < children.length; i++) {
				if (children[i].nodeType == originType) {
					next = children[i];
					break;
				}
			}
		}
	}
	return next;
}