//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// The following two functions make it possible to have web standard popups
window.onload = function() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
    if (lnks[i].className == "popup") {
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
  }
	if(document.getElementById('txtSearch')){
		document.getElementById('txtSearch').onfocus = function(){document.getElementById('txtSearch').value = ''}
	}
}

function popUp(winURL) {
  window.open(winURL,"popup");
}

//-- Create a :Hover psuedo attribute for IE for headerNav -- //
hdrHover = function() {
	if (document.getElementById('headerNav') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrCat = document.getElementById("headerNav").getElementsByTagName("li");
			for (var i=0; i<hdrCat.length; i++) {
				hdrCat[i].onmouseover=function() {
					this.className+=" hdrhover";
				}
				hdrCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdrhover\\b"), "");
				}
			}
		}	
	}
}
//-- Create a :Hover psuedo attribute for IE for ilfNav -- //
ilfHover = function() {
	if (document.getElementById('ilfNav') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrCat = document.getElementById("ilfNav").getElementsByTagName("li");
			for (var i=0; i<hdrCat.length; i++) {
				hdrCat[i].onmouseover=function() {
					this.className+=" hdrhover";
				}
				hdrCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdrhover\\b"), "");
				}
			}
		}	
	}
}
//-- Create a :Hover psuedo attribute for IE for sidebarUtilNav -- //
sbHover = function() {
	if (document.getElementById('sidebarUtilNav') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrCat = document.getElementById("sidebarUtilNav").getElementsByTagName("li");
			for (var i=0; i<hdrCat.length; i++) {
				hdrCat[i].onmouseover=function() {
					this.className+=" hdrhover";
				}
				hdrCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdrhover\\b"), "");
				}
			}
		}	
	}
}

//**************************************************scroolbar on divs**************************************************//
function showScrollBar() {
	if (!document.getElementById('contentContainer')) return false;
	if (!document.getElementById('copyInner')) return false;
	if (!document.getElementById('scrollbar')) return false;
	document.getElementById('copyInner').style.overflow = 'hidden';
	if (document.getElementById('contentContainer').offsetHeight > 175) {
		document.getElementById('pageup').style.display = 'block';
		document.getElementById('pagedown').style.display = 'block';
	}
}


//**************************************************move the scrollbar div**************************************************//
function moveSlider() {
	if (!document.getElementById('contentContainer')) return false;
	if (!document.getElementById('pageup')) return false;
	if (!document.getElementById('pagedown')) return false;
	document.getElementById('pageup').onmouseover=function() {
		pos = document.getElementById('contentContainer').style.top;
		scrollerUp('contentContainer',pos);
	}
	document.getElementById('pageup').onmouseout=function() {
		terminateTimer();
	}
	document.getElementById('pagedown').onmouseover=function() {
		pos = document.getElementById('contentContainer').style.top;
		scrollerDown('contentContainer',pos);
	}
	document.getElementById('pagedown').onmouseout=function() {
		terminateTimer();
	}
}
var timerID = null;
function scrollerUp(page,pos) {
	if (typeof pos == "string") {
		pos = pos.replace('px', '');
		pos = 1 * pos;
	}
	if ((pos * -1) > 0) {
		pos = eval(pos + 15);
	}
	document.getElementById(page).style.top =	pos+"px";
	timerID = window.setTimeout('scrollerUp("contentContainer",'+pos+')',100);
}
function scrollerDown(page,pos) {
	if (typeof pos == "string") {
		pos = pos.replace('px', '');
	}
	if ((pos * -1) < (document.getElementById(page).offsetHeight - (document.getElementById(page).parentNode.offsetHeight/2))) {
		pos = eval(pos - 15);
	}
	document.getElementById(page).style.top =	pos+"px";
	timerID = window.setTimeout('scrollerDown("contentContainer",'+pos+')',100);
}
function terminateTimer() {
	window.clearTimeout(timerID);
}

//**************************************************Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementsByTagName('img')) return false;
  var imgList = document.getElementsByTagName('img');
  for (var i=0; i<imgList.length; i++) {
    var align = imgList[i].getAttribute('align');
		if (align) {
			if (align == 'left') {
				imgList[i].className = 'left';
			}
			if (align == 'right') {
				imgList[i].className = 'right';
			}
			if (align == 'middle') {
				imgList[i].className = 'middle';
			}
    	imgList[i].removeAttribute('align')
    }
  }
}

//**************************************************load functions**************************************************//
addLoadEvent(ilfHover);
addLoadEvent(hdrHover);
addLoadEvent(sbHover);
addLoadEvent(showScrollBar);
addLoadEvent(moveSlider);
addLoadEvent(replaceAlign);
