// VERY IMPORTANT - DO NOT DELETE
// prevents flicker with moving background images for those IE users who have their cache
// settings for those IE users who have their cache settings to 'every visit to the page'
try { document.execCommand("BackgroundImageCache",false,true); } catch(e) {};

// node functions
if(!window.Node){
	var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}

checkNode = function(node,filter){
	return(node==null||node.nodeType==Node[filter]||node.nodeName.toUpperCase()== filter.toUpperCase());
}

getAllChildren = function(node,filter){
	var result = new Array();
	var children = (node.all)? node.all:node.getElementsByTagName('*');
	for(i=0;i<children.length;i++){
  		if(node.all){
			var test = new Array();
			if(children[i].tagName==filter.toUpperCase()){
    			result[result.length] = children[i];
    		}
    	}else{
    		if(checkNode(children[i],filter)) result[result.length] = children[i];
		}
	}
  	return result;
}

getChildren = function(node,filter){
	var result = new Array();
	var children = (node.all)? node.all:node.getElementsByTagName('*');
 	for(i=0;i<children.length;i++){
		if(node.all){
			var test = new Array();
			if(children[i].tagName==filter.toUpperCase()){
    			result[result.length] = children[i];
    		}
    	}else{
    		if(checkNode(children[i],filter)) result[result.length] = children[i];
    	}
	}
  	return result;
}

getParent = function(el,pTagName){
	if(el==null){
		return null;
	}else if(el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()){
		return el;
	}else{
		return getParent(el.parentNode, pTagName);
	}
}

getElementsByClassName = function(oElm, strTagName, strClassName){
    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)
}
getNextSibling = function(node, filter){
  for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
    if(checkNode(sibling, filter)) return sibling;
  }
  return null;
}
// /node functions

// change the text area size of the rich text areas (for IE)
changeTextAreaSize = function(){
	if(!document.getElementsByTagName){
		return;
	}
	var aTemp = document.getElementsByTagName("textarea");
	for(i=0; i < aTemp.length; i++){
		if(aTemp[i].className=="doChangeSize"){
			if(navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){
				aTemp[i].cols = '80';
			}
		}
	}
}
// /change the text area size of the rich text areas (for IE)


// refine by search stuff
refineBy = function(){
	return;
}

refineBy.getLists = function(){
	if(!document.getElementsByTagName||!document.getElementById('filterArticles')){
		return;
	}
	var oRefine = document.getElementById('filterArticles');
	var aHeaders = getChildren(oRefine,'h3');
	for(i=0;i<aHeaders.length;i++){
		aHeaders[i].onclick = function(){
			this.className = (this.className=='on')? '':'on';
			var oList = getNextSibling(this,'ul');
			if(oList.className!='chosen'){
				oList.className = (this.className=='on')? 'hide':'';
			}
			var aLink = getChildren(this,'a');
			aLink[0].href = 'javascript:;';	
			this.blur();
		}
	}
}
// /refine by search stuff

// add our functions
var WindowListener = {
  add : function(event,func){
    var e = this.Functions[event];
    e[func] = func;
  },
  remove : function(event,func){
    var e = this.Functions[event];
    delete e[func];
  },
  addEvent : function(event){
    window["on"+event] = function(){WindowListener.run(event)};
    this.Functions[event] = {};
  },
  removeEvent : function(event){
    window["on"+event] = null;
    delete this.Functions[event];
  },
  run : function(event){// Private
    var e = this.Functions[event];
    for(var i in e) eval(e[i]);
  },
  Functions : {}
}

fixIEselectBug = function() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.body.style.height = document.documentElement.scrollHeight + 'px';
	}
}

/* --- virtual :hover on div elements in IE 6 ---*/
/*Usage: Add the class name "hover" to any div's and onMouseOver will assign a 'over' class which you can style using css*/

var IEHover				= {
	getElementsForIEHover : function(className, tag, elm){ //This is essentially a tweaked 'getElementsByClassName' function
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	},

	IEHover : function(className, tag, elm){
	if (document.all&&document.getElementById) {
		// then this is IE5/6
		var navRoot = IEHover.getElementsForIEHover("hover", "div", document);
		for (i=0; i<navRoot.length; i++) {
				navRoot[i].onmouseover=function() {
					this.className+=" over";
				}
				navRoot[i].onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

WindowListener.addEvent("load");
WindowListener.add("load","changeTextAreaSize()");
WindowListener.add("load","refineBy.getLists()");
WindowListener.add("load","fixIEselectBug()");
WindowListener.add("load","IEHover.IEHover()");
// /add our functions