/* /framework/global.js 
	Ecliptic Technologies, Inc.
	Copyright 2004-2005 - All Rights Reserved, World Wide
	Unauthorized use or reproduction of this product is strictly prohibited by law.
	Web: http://www.ecliptictech.com
	Email: sales@ecliptictech.com
	
	Name: Park Co BMS Global JavaScript File
	Description: This JavaScript file contains all the JavaScript that should be 
		executed accross the entire application.
		
	Created On: 23 MAR 2005
	Last Modified: 01 APR 2005
	Developer: JNEUHARTH
*/

/* This set of functions are used to set all the anchors tags title text to the status bar. */
	function loadAnchorStatusText() {
		var x = document.getElementsByTagName('a');
		for(var i = 0;i<x.length;i++) {
			if(x[i].getAttribute('title')) {
				x[i].onmouseover = setStatusText;
				x[i].onmouseout = clearStatusText;
			}
		}
	}
	function setStatusText() {
		window.status = this.title;
		event.cancelBubble = true;
		return true;
	}
	function clearStatusText() {
		window.status = '';
		event.cancelBubble = true;
		return true;
	}
	
/* This function is a work around a bug in IE related to element attributes */
	function hasClass(obj) {
		var result = false;
			if (obj.getAttributeNode("class") != null) {
				result = obj.getAttributeNode("class").value;
			}
		return result;
	}  

/* This function sets the default text for the status bar. */
	function loadDefaultStatus() {
		window.defaultStatus='NorthStar Genetics Order/Inventory System'
	}
	
/* This set of functions are used to set alt row colors. */
	function setStripes(table) {
		var even = false;
		/* Look for color arguments, if not there set defaults. */
		var evenColor = arguments[1] ? arguments[1] : "#fff";
		var oddColor = arguments[2] ? arguments[2] : "#edf3fe";
		
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");

			for (var i = 0; i < trs.length; i++) {
			if (!hasClass(trs[i]) && !trs[i].style.backgroundColor) {
				var tds = trs[i].getElementsByTagName("td");
				
				for (var j = 0; j < tds.length; j++) {
					if (!hasClass(tds[j]) && !tds[j].style.backgroundColor) {
						tds[j].style.backgroundColor = even ? evenColor : oddColor;
					}
				}
			}
			even =  ! even;
			}
		}
	}
	function loadStripes() {
		var x = document.getElementsByTagName('table');
		for(var i = 0;i<x.length;i++) {
			if(x[i].getAttribute('striped')) {
				setStripes(x[i]);
			}
		}
	}

/* This set of functions are used to set the table ruler. */
	function setRuler(table) {	
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");

			for (var i = 0; i < trs.length; i++) {
				if (!hasClass(trs[i]) && !trs[i].style.backgroundColor) {
					trs[i].onmouseover = function() {this.className = 'ruled';return false; }
					trs[i].onmouseout = function() {this.className  = '';return false; }
				}
			}
		}
	}
	function loadRuler() {
		var x = document.getElementsByTagName('table');
		for(var i = 0;i<x.length;i++) {
			if(x[i].getAttribute('ruled')) {
				setRuler(x[i]);
			}
		}
	}
	
/* This set of functions are used to set higlight classes on input forms. */
	function focusRowHighlight() {
		for(var node = this.parentNode; node; node=node.parentNode) {  
			if(node.tagName.toLowerCase() == 'tr') { 
				if (!hasClass(node) && !node.style.backgroundColor) {
					node.className = 'rowHighlight';
					return; 
				}
			}
		}
	}
	function blurRowHighlight() {
		for(var node = this.parentNode; node; node=node.parentNode) {  
			if(node.tagName.toLowerCase() == 'tr') { 
				if (node.className == 'rowHighlight' || (!hasClass(node) && !node.style.backgroundColor)) {
					node.className = '';
					return; 
				}
			}
		}
	}
	function setRowHighlight(form) {	
		var fitems = form.getElementsByTagName("input");
		
		for (var i = 0; i < fitems.length; i++) {
			if (fitems[i].type=='text' || fitems[i].type=='radio' || fitems[i].type=='checkbox') {
				fitems[i].onfocus = focusRowHighlight;
				fitems[i].onblur = blurRowHighlight;
			}
		}
		
		var fitems = form.getElementsByTagName("select");
		
		for (var i = 0; i < fitems.length; i++) {
			fitems[i].onfocus = focusRowHighlight;
			fitems[i].onblur = blurRowHighlight;
		}
	}
	function loadRowHighlight() {
		var x = document.getElementsByTagName('form');
		for(var i = 0;i<x.length;i++) {
			if(x[i].getAttribute('rowHighlight')) {
				setRowHighlight(x[i]);
			}
		}
	}

/* This set of functions will let you set different CSS classes for diferent types of inputs. */
	function loadInputClasses() {
		var x = document.getElementsByTagName('input');
		for(var i = 0;i<x.length;i++) {
			
			if(x[i].getAttribute('type')=='text' || x[i].getAttribute('type')=='password') {
				if (!hasClass(x[i]) && !x[i].style.backgroundColor) {
					x[i].className='inputText'
				}
			}
			if(x[i].getAttribute('type')=='button' || x[i].getAttribute('type')=='submit' || x[i].getAttribute('type')=='reset') {
				if (!hasClass(x[i]) && !x[i].style.backgroundColor) {
					x[i].className='inputButtons'
				}
			}
		}
	}
	
/* This function is used to add global onLoad functions to pages without breaking previous onLoads. */
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') { //
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
	
/* Any on page load events for a page should be added like below. */
	addLoadEvent(loadAnchorStatusText);
	addLoadEvent(loadStripes);
	addLoadEvent(loadRuler);
	addLoadEvent(loadDefaultStatus);
	addLoadEvent(loadRowHighlight);
	addLoadEvent(loadInputClasses);
	
/* Function to confirm and redirect for the system logout. */
function confirmLogout(){
    if(confirm("Are you sure you want to log out of the system?")) {
        document.location.href="/xt-logout.jsp";
    }
}

/* AutoBlink
* Puts Google's Autolink on the Blink :)
* (c) 2005 Chris Ridings   http://www.searchguild.com
* Redistribute at will but leave this message intact
*/
/*
var linkcount;
function checklinks() {
	if (!(linkcount==document.links.length)) {
		// Something changed the links!
		// Iterate for an id of _goog
		for (i=0; i < document.links.length; i++) {
			if (document.links[i].id.substring(0,5)=="_goog") {
				// if we find an id of _goog then remove the link!
				var tr = document.links[i].parentTextEdit.createTextRange();
				tr.moveToElementText(document.links[i]);
				tr.execCommand("Unlink",false);
				tr.execCommand("Unselect",false);
			}
		}
	}
		setTimeout("checklinks()",500);
}
if (document.getElementById && document.createElement) {
	linkcount=document.links.length;
	setTimeout("checklinks()",500);
}
*/