﻿
	window.onload = function(){
		if (self.init)
			mainjsinit();
	}
  
	/*
	function menuOver(divID) {
		var theDiv = document.getElementById(divID + "SUB");
		var theA = document.getElementById(divID);
		theDiv.style.zIndex = 99;
		theDiv.style.display = "";
		theA.style.backgroundColor = "#F0F0F0";
	}
	function menuOut(divID) {
		var theDiv = document.getElementById(divID + "SUB");
		var theA = document.getElementById(divID);
		theDiv.style.zIndex = -1;
		theDiv.style.display = "none";
		theA.style.backgroundColor = "";
	}
	*/
	function menuOverTab(divID) {
		/*if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;
		if (tg.id != divID && tg.id != (divID + "SUB")) return;
		*/
		var theDiv = document.getElementById(divID + "SUB");
		var theA = document.getElementById(divID);
		theDiv.style.zIndex = 1;
		theDiv.style.visibility = "visible";
		//theDiv.style.display = "";
		theA.src = "static/images/btn" + divID + "-over.gif";
	}
	function menuOutTab(divID) {
		/*if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;		
		if (tg.id != divID && tg.id != (divID + "SUB")) return;
		*/
		var theDiv = document.getElementById(divID + "SUB");
		var theA = document.getElementById(divID);
		theDiv.style.zIndex = -1;
		theDiv.style.visibility = "hidden";
		//theDiv.style.display = "none";
		theA.src = "static/images/btn" + divID + ".gif";
	}
	function menuOverTabSub(divID,divIDSub,rowCnt){
		menuOverTab(divID)
		var theDiv = document.getElementById(divIDSub);
		var theA = document.getElementById(divIDSub + "A");
		if(theA){theA.className = "subDivTab2Over"}
		theDiv.style.zIndex = 1;
		theDiv.style.visibility = "visible";
		theDiv.style.top = "0px" //(24 * rowCnt) + "px";
		_menuOverFlag = 1
	}
	function menuOutTabSub(divID,divIDSub,rowCnt) {
		menuOutTab(divID)
		var theDiv = document.getElementById(divIDSub);
		var theA = document.getElementById(divIDSub + "A");
		if(theA){theA.className = "subDivTab2Out"}
		theDiv.style.zIndex = -1;
		theDiv.style.visibility = "hidden";
		theDiv.style.top = "-1000px";
		_menuOverFlag = 0
	}
	function menuOverTabSubL(divIDSub){
		var theDiv = document.getElementById(divIDSub);
		var theA = document.getElementById(divIDSub + "A");
		if(theA){theA.className = "subDivTab2OverL"}
		theDiv.style.zIndex = 1;
		theDiv.style.visibility = "visible";
		theDiv.style.top = "0px" //(24 * rowCnt) + "px";
		_menuOverFlag = 1
		_captureEventY = 263
	}
	function menuOutTabSubL(divIDSub) {
		var theDiv = document.getElementById(divIDSub);
		var theA = document.getElementById(divIDSub + "A");
		if(theA){theA.className = "subDivTab2OutL"}
		theDiv.style.zIndex = -1;
		theDiv.style.visibility = "hidden";
		theDiv.style.top = "-1000px";
		_menuOverFlag = 0
	}

	/* Added _ prefix to prevent conflict with CORESense javascript */
	var _scrollTimer
	var _freeze = 0
	var _count = 0
	var _startY = 0
	var _elemTop = 0
	
	var _scrollTop = 0
	var _top = 0
	var _bottom = 0
	var _windowHeight = 0
	var _y = 0
	var _y2 = 0
	var _testElem
	var _testElem2
	var _bottomLimit
	var _captureEventY
	var _captureEventYB
	var _captureEventYBC
	
	function mainjsinit(){		
		setGValues()
		
		_testElem = document.getElementById("data")
		_testElem2 = document.getElementById("dataB")
	
		document.body.onmousemove = movemenu3;
		window.onmousemove = movemenu3;
		
		if(document.getElementById("LibrarySUBhd")){
			document.getElementById("LibrarySUBhd").onmousemove = movemenu;
			document.getElementById("LibrarySUBhw").onmousemove = movemenu;
			document.getElementById("LibrarySUBia").onmousemove = movemenu;
			document.getElementById("LibrarySUBn").onmousemove = movemenu;
		}
		if(document.getElementById("LLibrarySUBhd")){
			document.getElementById("LLibrarySUBhd").onmousemove = movemenu;
			document.getElementById("LLibrarySUBhw").onmousemove = movemenu;
			document.getElementById("LLibrarySUBia").onmousemove = movemenu;
			document.getElementById("LLibrarySUBn").onmousemove = movemenu;
		}
		
		statusUpdate()
	}
	function setGValues(){
		_windowHeight = (self.innerHeight) ? self.innerHeight : document.body.clientHeight + document.documentElement.clientHeight;
		_top = 50
		_bottom = _windowHeight - 50
		_scrollTop = (self.innerHeight) ? window.pageYOffset : document.body.scrollTop;
		
		setGValuesTimer = setTimeout("setGValues()",3000)
	}
	function statusUpdate(){
		if(_testElem2){
		_testElem2.style.top = _y2 + "px"
		_testElem2.innerHTML = "" +
		"Timer: " + _scrollTimer + "<br />" +
		"OverFlag: " + _menuOverFlag + "<br />" + 
		"Freeze: " + _freeze + "<br />" + 
		"Top: " + _top + "<br />" + 
		"Bottom: " + _bottom + "<br />" + 			
		"Y: " + _y + "<br />" + 
		"WinHeight: " + _windowHeight + "<br />" +
		"ScrollTop: " + _scrollTop + "<br />" +
		"bottLimit: " + _bottomLimit + "<br />" +
		"captEventY: " + _captureEventY + "<br />" +
		"captEventYB: " + _captureEventYB + "<br />" +
		"captEventYBC: " + _captureEventYBC + "<br />"
		}
		
		_scrollTop = (self.innerHeight) ? window.pageYOffset : document.body.scrollTop;
		_bottomLimit = _captureEventYB + _captureEventY - _windowHeight
		
		statusTimer = setTimeout("statusUpdate()",50)
	}
	
	function movemenu2(e){
		if (!e) var e = window.event;
		var _testElem = document.getElementById("data")
		//_testElem.innerHTML = _windowHeight + "|" + e.clientY + "|" + top + "|" + _bottom
	}
	
	function movemenu3(e){
		if (!e) var e = window.event;
		_y2 = (e.pageY) ? (e.pageY - 50) : (e.clientY + _scrollTop - 50);
	}
	
	function movemenu(e){
		if (!e) var e = window.event;
		_y = (e.pageY) ? (e.pageY - _scrollTop) : e.clientY;
		
		if(_y < _top){
			if(_freeze == 0){
				_freeze = 1
				movemenuScroll(-5)
			}
		}else if(_y > _bottom){
			if(_freeze == 0){
				_freeze = 1
				movemenuScroll(5)
			}
		}else{
			movemenuStopScroll()
		}
	}
	
	function movemenuStopScroll(){
		_freeze = 0
		clearTimeout(_scrollTimer)
		_scrollTimer = undefined
	}
	
	function movemenuScroll(yScroll){		
		if(_scrollTop <= _captureEventY && yScroll < 0){}
		else if(_scrollTop >= _bottomLimit && yScroll > 0){}
		else if(_menuOverFlag == 0){}
		else{	
			window.scrollBy(0,yScroll)
			_scrollTimer = setTimeout("movemenuScroll(" + yScroll + ")",100)
		}
	}
	var _captureEventY = 0
	var _captureEventYB = 0
	var _captureElement = ""
	var _menuOverFlag = 0
	function captureEvent(e,elemId){
		//GET target event
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;		
		_captureElement = tg.id
		if (tg.id != elemId) return;
		
		/*
		if (tg.nodeName != 'DIV') return;
		_captureElement = tg.nodeName
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		while (reltg != tg && reltg.nodeName != 'BODY')
			reltg = reltg.parentNode
		if (reltg == tg) return;
		*/
		
		//if(_captureEventY != 0) return
		//GET MOUSE X AND Y
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		_captureEventY = posy
	}
	function getMenuHeight(elem){
		var elemNodes = elem.childNodes
		var elemCnt = elem.getElementsByTagName("A").length
		_captureEventYB = (elemCnt * 24)
		_captureEventYBC = elemCnt
		
		//for (y=0;y<=elemCnt;_y++){	
		//	elemNodes[y].className = elemNodes[y].className.replace(replaceText,replaceWith)
		//}
				
		/*if(BrowserDetect.browser == "Explorer"){//Explorer
			for (_y = 0;_y <= elemCnt;_y++){
				elemNodes[y].className = elemNodes[y].className.replace(replaceText,replaceWith)
			}
		*/
		/*
		}else{//Safari and Mac
			for (_y = 0;_y <= elemCnt;_y++){
				if(elemNodes[y].valueOf() == "[object HTMLTableCellElement]"){elemNodes[y].className = elemNodes[y].className.replace(replaceText,replaceWith)}
			}
		}
		*/
	}
	function unloadEvent(e){
		//GET target event
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;
		if (tg.nodeName != 'DIV') return;
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		while (reltg != tg && reltg.nodeName != 'BODY')
			reltg = reltg.parentNode
		if (reltg == tg) return;
		//if(document.getElementById("data")) document.getElementById("data").innerHTML = "reset"
		//_captureEventY = 0
	}
	function searchGo() {
		var varSearchField = document.getElementById("searchBox");
		if (varSearchField.value != varSearchField.defaultValue && varSearchField.value != "") {
		//	document.searchform.action = "http://www.google.com/search";
			document.searchform.action = "searchResults.asp"; //?q=" + varSearchField.value;
			document.searchform.submit();
		}
	}
	
	function validateEmail(xEmail) {
		var emailField = document.getElementById(xEmail);
		
		if (emailField.value.length == 0 || emailField.value.indexOf("@") == -1 || emailField.value.indexOf(".") == -1) {
			alert("Email address is invalid.");
			emailField.focus();
			return false;
		} else {
			return true;
		}
	}
		
	function emailFrmFirst() {
	  	var emailDiv1 = document.getElementById("emailBox1");
		var emailDiv2 = document.getElementById("emailBox2");
		var emailField1 = document.getElementById("emailSignUp1");
		var emailField2 = document.getElementById("emailSignUp2");
		var varPrevEmail = document.getElementById("prevEmail");
		
		if (validateEmail("emailSignUp1") == true && emailField2.value.length == 0) {
			varPrevEmail.innerHTML = emailField1.value;
			emailDiv1.style.display = "none";
			emailDiv2.style.display = "";
			emailField2.focus();
			}
		if (emailField2.value.length > 0) {
			emailFrmSubmit();
		}
	}
	
	function changeEmail() {
		var emailDiv2 = document.getElementById("emailBox2");
		var emailDiv1 = document.getElementById("emailBox1");
		var emailField1 = document.getElementById("emailSignUp1");
		
		emailDiv2.style.display = "none";
		emailDiv1.style.display = "";
		emailField1.focus();
	}
	
	function emailFrmSubmit() {
		var emailDiv2 = document.getElementById("emailBox2");
		var emailDiv3 = document.getElementById("emailBox3");
		var emailField1 = document.getElementById("emailSignUp1");
		var emailField2 = document.getElementById("emailSignUp2");
		var varFinalEmail = document.getElementById("finalEmail");
		
		if (validateEmail("emailSignUp2") == true) {
			if (emailField2.value.toLowerCase() == emailField1.value.toLowerCase()) {
				document.emailSignUpForm.action = "emailSubmit.asp";
				document.emailSignUpForm.submit();
			} else {
				alert("The email addresses did not match!");
				emailField2.focus();
			}
		}
	}
	
	function emailSuccess() {	
		var emailDiv2 = document.getElementById("emailBox2");
		var emailDiv3 = document.getElementById("emailBox3");
		var emailField2 = document.getElementById("emailSignUp2");
		var varFinalEmail = document.getElementById("finalEmail");
		
		varFinalEmail.innerHTML = emailField2.value;
		emailDiv2.style.display = "none";
		emailDiv3.style.display = "";
	}
	
	function clearField(fId,fTxt) {
		if (fId.value == fTxt) {
			fId.value = "";
		}
	}
	
	function fillField(fId,fTxt) {
		if(fId.value == "") {
			fId.value = fTxt;
		}
	}
	
	//ADMIN FUNCTIONS
	function validateLength(elem,maxLen) {
		if(elem.value.length > maxLen) {
			alert("You have " + elem.value.length + " characters. The maximum number of characters is " + maxLen + ". To continue, please make it " + maxLen + " characters or less.");
			elem.select();
		}
	}
	
