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

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
    }
  else {
    parent.insertBefore(newElement,targetElement.nextSibling);
    }
  }	
	
var req;

function loadXMLDoc(url, runFunction) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        	} 
		catch(e) {
			req = false;
        	}
		}
	// branch for IE/Windows ActiveX version
    else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      		} 
		catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        		} 
			catch(e) {
          		req = false;
        		}
			}
    	}
	if(req) {
		req.onreadystatechange = function() {
			// only if req shows "loaded"
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200 || window.location.href.indexOf("http")== -1) {  // status is ok, or request is for a local file
					runFunction();
					}
				else { 
					alert("There was a problem retrieving the XML data:\n" + req.status + " " + req.statusText);
					}
				}
			}
		req.open("GET", url, true);
		req.send("");
		}
	}

function openGear() {
	loadXMLDoc("o2mgear.xml", parseGear);
	}
		
function parseGear() {

	// make a new unordered list to hold all of the info from the xml file
	
	var new_list = document.createElement("ul");
	new_list.setAttribute("id","products");
	var existing_element = document.getElementsByTagName("p");
	insertAfter(new_list,existing_element[0]);
		
	// create a new list item for each record in the xml file
	
	var new_list_item, new_elem, new_text;
	var class_on_off = "on";
	var no_of_records = req.responseXML.getElementsByTagName("gear_title").length;

	/* for each record in xml file, create a list item element, and insert the values from the file into the list item */

	for (i=0; i < no_of_records; i++) {
		
		new_list_item = document.createElement("li");
		new_list_item.setAttribute("class",class_on_off);
		new_list_item.setAttribute("className",class_on_off);  /* IE bug  */
		new_list.appendChild(new_list_item);
		
		/* switch the value of the class variable to allow alternating treatment in css */
		
		if (class_on_off == "on") {
			class_on_off = "off";
			}
		else {
			class_on_off = "on";
			}
		
		new_elem = document.createElement("img");
		new_elem.setAttribute("src","images/"+req.responseXML.getElementsByTagName("gear_image")[i].childNodes[0].nodeValue);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("h2");
		new_text = document.createTextNode(req.responseXML.getElementsByTagName("gear_title")[i].childNodes[0].nodeValue);
		new_elem.appendChild(new_text);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("p");
		new_text = document.createTextNode(req.responseXML.getElementsByTagName("gear_desc")[i].childNodes[0].nodeValue);
		new_elem.appendChild(new_text);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("a");
		new_elem.setAttribute("href",req.responseXML.getElementsByTagName("gear_address")[i].childNodes[0].nodeValue);
		new_elem.setAttribute("target","_blank");
		new_text = document.createTextNode(req.responseXML.getElementsByTagName("gear_address")[i].childNodes[0].nodeValue);
		new_elem.appendChild(new_text);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("p");
		new_elem.setAttribute("class","clear");
		new_elem.setAttribute("className","clear");	
		new_list_item.appendChild(new_elem);
		}
	}

function openExhibit() {
	loadXMLDoc("o2mexhibit.xml", parseExhibit);
	}
		
function parseExhibit() {

	// make a new unordered list to hold all of the info from the xml file
	
	var new_list = document.createElement("ul");
	new_list.setAttribute("id","dispItems");
	var existing_element = document.getElementsByTagName("p");
	insertAfter(new_list,existing_element[0]);
		
	// create a new list item for each record in the xml file
	
	var new_list_item, new_elem, new_text;
	var class_on_off = "on";
	var no_of_records = req.responseXML.getElementsByTagName("item_title").length;

	/* for each record in xml file, create a list item element, and insert the values from the file into the list item */

	for (i=0; i < no_of_records; i++) {
		
		new_list_item = document.createElement("li");
		new_list_item.setAttribute("class",class_on_off);
		new_list_item.setAttribute("className",class_on_off);  /* IE bug  */
		new_list.appendChild(new_list_item);
		
		/* switch the value of the class variable to allow alternating treatment in css */
		
		if (class_on_off == "on") {
			class_on_off = "off";
			}
		else {
			class_on_off = "on";
			}
		
		new_elem = document.createElement("img");
		new_elem.setAttribute("src","images/"+req.responseXML.getElementsByTagName("item_image")[i].childNodes[0].nodeValue);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("h2");
		new_text = document.createTextNode(req.responseXML.getElementsByTagName("item_title")[i].childNodes[0].nodeValue);
		new_elem.appendChild(new_text);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("p");
		new_text = document.createTextNode(req.responseXML.getElementsByTagName("item_desc")[i].childNodes[0].nodeValue);
		new_elem.appendChild(new_text);
		new_list_item.appendChild(new_elem);
		new_elem = document.createElement("p");
		new_elem.setAttribute("class","clear");
		new_elem.setAttribute("className","clear");
		new_list_item.appendChild(new_elem);
		}
	}

function codeMail() {
	var nospam_mail = document.getElementById("jsmail");
	
	// eMail Obfuscator Script 2.1 by Tim Williams - freeware

 	var coded = "AZKFVM0YS@4JIjYFIA42CIT.K4A",
		cipher = "aZbYcXdWeVfUgThSiRjQkPlOmNnMoLpKqJrIsHtGuFvEwDxCyBzA1234567890",
		shift = coded.length,
		link = "";
	for (i=0; i<coded.length; i++) {
		if (cipher.indexOf(coded.charAt(i))==-1) {
			ltr = coded.charAt(i);
			link += (ltr);
			}
		else {     
			ltr = (cipher.indexOf(coded.charAt(i))-shift+cipher.length) % cipher.length;
			link += (cipher.charAt(ltr));
			}				
    	}
	nospam_mail.href="mailto:"+link; // this line replaces 'document.write...' from original t.williams script
	nospam_mail.firstChild.nodeValue = link; // update link text so address is viewable to user
	
    }

function setCopyright() {
	var element = document.getElementById("copyright");
	var date = element.childNodes[0].nodeValue;
	var year = new Date().getFullYear();
	if(year > date)
		element.childNodes[0].nodeValue = date + "-" + year;
	else
		element.childNodes[0].nodeValue = date;
	}
	
