var combodropimage='downbox.gif' //path to "drop down" image
var combodropoffsetY=2 //offset of drop down menu vertically from default location (in px)
var combozindex=100

if (combodropimage!="")
	combodropimage='<img class="downimage" src="'+combodropimage+'" title="Select an option" />'

function dhtmlselect(selectid, selectwidth, optionwidth){
	var selectbox=document.getElementById(selectid)
	document.write('<div id="dhtml_'+selectid+'" class="dhtmlselect">'+selectbox.title+" "+combodropimage+'<div class="dropdown">')
	for (var i=0; i<selectbox.options.length; i++)
		document.write('<a href="'+selectbox.options[i].value+'">'+selectbox.options[i].text+'</a>')
	document.write('</div></div>')
	selectbox.style.display="none"
	var dhtmlselectbox=document.getElementById("dhtml_"+selectid)
	dhtmlselectbox.style.zIndex=combozindex
	combozindex--
	if (typeof selectwidth!="undefined")
		dhtmlselectbox.style.width=selectwidth
	if (typeof optionwidth!="undefined")
		dhtmlselectbox.getElementsByTagName("div")[0].style.width=optionwidth
	dhtmlselectbox.getElementsByTagName("div")[0].style.top=dhtmlselectbox.offsetHeight-combodropoffsetY+"px"
	if (combodropimage!="")
		dhtmlselectbox.getElementsByTagName("img")[0].style.left=dhtmlselectbox.offsetWidth+3+"px"
	dhtmlselectbox.onmouseover=function(){
		this.getElementsByTagName("div")[0].style.display="block"
	}
	dhtmlselectbox.onmouseout=function(){
		this.getElementsByTagName("div")[0].style.display="none"
	}
}

function addEvent(element, type, handler) {
	// Modification by Tanny O'Haley, http://tanny.ica.com to add the
	// DOMContentLoaded for all browsers.
	if (type == "DOMContentLoaded" || type == "domload") {
		addDOMLoadEvent(handler);
		return;
	}
	
	if (element.addEventListener) {
		element.addEventListener(type, handler, false);
	} else {
		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		// create a hash table of event types for the element
		if (!element.events) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			// store the existing event handler (if there is one)
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			}
		}
		// store the event handler in the hash table
		handlers[handler.$$guid] = handler;
		// assign a global event handler to do all the work
		element["on" + type] = handleEvent;
	}
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.removeEventListener) {
		element.removeEventListener(type, handler, false);
	} else {
		// delete the event handler from the hash table
		if (element.events && element.events[type]) {
			delete element.events[type][handler.$$guid];
		}
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

// End Dean Edwards addEvent.

// Tino Zijdel - crisp@xs4all.nl This little snippet fixes the problem that the onload attribute on 
// the body-element will overwrite previous attached events on the window object for the onload event.
if (!window.addEventListener) {
	document.onreadystatechange = function(){
		if (window.onload && window.onload != handleEvent) {
			addEvent(window, 'load', window.onload);
			window.onload = handleEvent;
		}
	}
}

// Here are my functions for adding the DOMContentLoaded event to browsers other
// than Mozilla.

// Array of DOMContentLoaded event handlers.
window.onDOMLoadEvents = new Array();
window.DOMContentLoadedInitDone = false;

// Function that adds DOMContentLoaded listeners to the array.
function addDOMLoadEvent(listener) {
	// If the DOMContentLoaded event has happened, run the function.
	if(window.DOMContentLoadedInitDone){
		listener();
		return;
	}

	window.onDOMLoadEvents[window.onDOMLoadEvents.length]=listener;
}

// Function to process the DOMContentLoaded events array.
function DOMContentLoadedInit() {
	// quit if this function has already been called
	if (window.DOMContentLoadedInitDone) return;

	// flag this function so we don't do the same thing twice
	window.DOMContentLoadedInitDone = true;

	// iterates through array of registered functions 
	for (var i=0; i<window.onDOMLoadEvents.length; i++) {
		var func = window.onDOMLoadEvents[i];
		func();
	}
}

function DOMContentLoadedScheduler() {
	// quit if the init function has already been called
	if (window.DOMContentLoadedInitDone) return true;
	
	// First, check for Safari or KHTML.
	// Second, check for IE.
	//if DOM methods are supported, and the body element exists
	//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
	//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
	if(/KHTML|WebKit/i.test(navigator.userAgent)) {
		if(/loaded|complete/.test(document.readyState)) {
			DOMContentLoadedInit();
		} else {
			// Not ready yet, wait a little more.
			setTimeout("DOMContentLoadedScheduler()", 250);
		}
	} else if(document.getElementById("__ie_onload")) {
		return true;
	}

	// Check for custom developer provided function.
	if(typeof DOMContentLoadedCustom == "function") {
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
			// Call custom function.
			if(DOMContentLoadedCustom()) {
				DOMContentLoadedInit();
			} else {
				// Not ready yet, wait a little more.
				setTimeout("DOMContentLoadedScheduler()", 250);
			}
		}
	}

	return true;
}

// Schedule to run the init function.
setTimeout("DOMContentLoadedScheduler()", 250);

// Just in case window.onload happens first, add it there too.
addEvent(window, "load", DOMContentLoadedInit);

// If addEventListener supports the DOMContentLoaded event.
if(document.addEventListener)
	document.addEventListener("DOMContentLoaded", DOMContentLoadedInit, false);

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			DOMContentLoadedInit(); // call the onload handler
		}
	};
/*@end @*/


// written by Tanny O'Haley, 28 Jul 2006
// http://tanny.ica.com
// Dependencies:
//	events.js

var tabs = {
	name: "tabs",
	obj: document,
	init: function(){
		if(!(/\btabs\b/.test(document.body.className)))
			document.body.className += " tabs";
		
		// Get all div elements and look for elements with a class of "tabs"
		var els=this.getElementsByClassName("tabs", "div", this.obj);
		for(var i=0; i < els.length; i++){
			this.processTab(els[i]);
		}
	},
	processTab: function(el){
		// Get the tabBody.
		var elBody = el.nextSibling;
		while(!(/\btabBody\b/.test(elBody.className)))
			elBody = elBody.nextSibling;

		var els = el.getElementsByTagName("a");

		for(var i=0; i < els.length; i++){
			var elParent = els[i].parentNode;

			// Set the tab parent for speed.
			elParent.tabDiv = el;

			// Set the parent node for speed.
			elParent.tabBody = elBody;

			// Set the tabNo for speed.
			elParent.tabNo = i;

			// Add the click  events.
			addEvent(els[i], "click", this.showTab);
			addEvent(elParent, "click", this.showTab);
			
			// For IE add a hover function for the LI element.
			if(window.attachEvent){
				addEvent(elParent, "mouseover", function() { this.className+=" sfhover"; });
				addEvent(elParent, "mouseout", function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); });
			}
		}
	},
	showTab: function(e){
		// Stop the click event here.
		if(!e) var e = window.event;
		e.cancelBubble = true;
		if(e.stopPropagation) e.stopPropagation();
		e.preventDefault();

		// Get the source element.
		if (e.target)
			var elSrc = e.target;
		else if (e.srcElement)
			var elSrc = e.srcElement;

		// Make sure that we are pointing at the li element.
		if(elSrc.tagName == "A") {
			elSrc.blur();
			elSrc = elSrc.parentNode;
		}

		// Get the tabs.
		var els = elSrc.tabDiv.getElementsByTagName("li");
		for(var i=0; i < els.length; i++){
			if(elSrc == els[i]){
				if(!/\bselected\b/.test(els[i].className))
					els[i].className += " selected";
			} else {
				els[i].className=els[i].className.replace(new RegExp("\\bselected\\b"), "").replace("  ", " ");
			}
		}

		// Get the children of the body and set the selected tab.
		var iTabs = 0;
		els = elSrc.tabBody.childNodes;
		for(i=0; i < els.length; i++){
			if((/\btabItem\b/.test(els[i].className) && els[i].tagName == "DIV")){
				if(iTabs == elSrc.tabNo){
					if(!/\bselected\b/.test(els[i].className))
						els[i].className += " selected";
				}else{
					els[i].className=els[i].className.replace(new RegExp(" selected\\b"), "");
				}
				iTabs++;
			}
		}

		return false;
	},
	getElementsByClassName: function (strClassName, strTagName, oElm){
		if(oElm == null)
			oElm = document;
		if(strTagName == null)
			strTagName = "*";
	
		var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
		var arrReturnElements = new Array();
		strClassName = strClassName.replace(/\-/g, "\\-");
		var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		var oElement;
		for(var i=0; i<arrElements.length; i++){
			oElement = arrElements[i];		
			if(oRegExp.test(oElement.className)){
				arrReturnElements.push(oElement);
			}	
		}
		return (arrReturnElements)
	}
}

addEvent(window, "DOMContentLoaded", function() {tabs.init();});
