/*********UTILITY FUNCTIONS**********/
	function getAbsoluteLeft(o) {    
		oLeft = o.offsetLeft	
		while(o.offsetParent!=null) {	
			oParent = o.offsetParent	
			oLeft += oParent.offsetLeft	
			o = oParent	
		}	
		return oLeft	
	}
	
	function getAbsoluteTop(o) {	
		oTop = o.offsetTop	
		while(o.offsetParent!=null) {	
			oParent = o.offsetParent	
			oTop += oParent.offsetTop	
			o = oParent	
		}	
		return oTop	
	}
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if(typeof(window.pageYOffset) == 'number') {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}
	
	function getWindowSize(){	
	  var winWidth = 0, winHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    winWidth = window.innerWidth;
	    winHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    winWidth = document.documentElement.clientWidth;
	    winHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    winWidth = document.body.clientWidth;
	    winHeight = document.body.clientHeight;
	  }
	 return [winWidth,winHeight];
	}

	function ScreenObject(){		
		var _docHeight = (document.height || document.body.offsetHeight);
		var _docWidth = (document.width || document.body.offsetWidth);
		
		this.left = getScrollXY()[0];
		this.right = _docWidth > getWindowSize()[0] ? getWindowSize()[0] + getScrollXY()[0]:_docWidth;
		this.top =  getScrollXY()[1];
		this.bottom =   _docHeight > getWindowSize()[1]?getWindowSize()[1] + getScrollXY()[1]:_docHeight;		
		return this;
	}
	
	//cross browser event listener
	function addListener(objtohit,event,functionname){
		if (objtohit.attachEvent){
			event = 'on'+event;
			return objtohit.attachEvent(event,functionname);
		}
		else{
			return objtohit.addEventListener(event,functionname,false)
		}
	}
	function removeListener(objtohit,event,functionname){
		if (objtohit.attachEvent){
			event = 'on'+event;
			return objtohit.detachEvent(event,functionname);
		}
		else{
			return objtohit.removeEventListener(event,functionname)
		}
	}
	function addClass(objtohit,cssClass){	
		return objtohit.className = objtohit.className+' '+cssClass;
	}	
	function removeClass(objtohit,cssClass){
		return objtohit.className = objtohit.className.replace(cssClass, '');
	}

	var getElementsByClassName = function (classname,tag) {	
	 	if(!tag) tag = "*";
	 	var elements =  document.getElementsByTagName(tag);
	 	var total_elements = elements.length;
	 	var regexp = new RegExp('\\b' + classname + '\\b');
	 	var class_elements = new Array();
	  	//Go thru all the links seaching for the class name
	 	for(var i = 0; i < total_elements; i++) { 
	 		var this_element = elements[i];
	 		if(regexp.test(this_element.className)) {
	 			class_elements.push(this_element);
	  	}
	 }
	 
	 return class_elements;
		 
	}
	//Function to control opacity levels across browsers
	function setOpacity(obj, opacity) {
		opacity = (opacity == 100)?99.999:opacity;
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}

/*********GLOBAL VARS**********/
	//tooltips on or off
	var enableTooltips = 1;

		
	var eventSource= function(e){return (document.attachEvent)?e.srcElement:e.target;}
	

	
	
/*********** TOOL TIPS *****************/
	var tipTimer;
	function fadeLayer(objId,fadeIn,step,milisecs,opacity,opTo) {		
		clearTimeout(tipTimer);
		obj = document.getElementById(objId);	
		if(isNaN(parseInt(opacity))){
			opTo = 100 * fadeIn;
			opacity = Math.abs(opTo - 100);	
		}	
		var fadeby = (fadeIn==0)?0-step:step;
		var diffBetween = Math.abs(opacity - opTo);				
		if(diffBetween > 0){	
			opacity = (diffBetween < step)?opTo: opacity + fadeby;				
			setOpacity(obj, opacity);
			tipTimer = window.setTimeout("fadeLayer('"+objId+"',"+fadeIn+","+step+", "+milisecs+","+opacity+","+opTo+")", milisecs);
		}	
			
	}
	
	function tipOverHandler(e){
		if(enableTooltips==1){
			var screen = new ScreenObject();
			var caller = eventSource(e);	
			var target = document.getElementById('tipshell');
			target.style.display = 'block';
			if(target.childNodes.length > 1){
				target.removeChild(target.childNodes[0])
			}
			caller.setAttribute('title','');
			target.insertBefore(caller.child,target.lastChild);	
			caller.child.style.display = 'block';			
			
			fadeLayer('tipshell',1,30,20)
			target.style.position = 'absolute';	
			if(e.type=="focus"){
				target.style.left = (getAbsoluteLeft(caller))+"px";	
			}
			else
			{
				var relLeft = e.clientX + screen.left-30;
				target.style.left = (relLeft <= 30) ? "1px" : relLeft+"px";	
			}		
					
			target.style.top = (getAbsoluteTop(caller) - target.offsetHeight)+"px";	
			removeClass(target,'flydown');
			
			var targTop = parseInt(target.style.top);
			var targLeft = parseInt(target.style.left);
				
			if((targLeft + target.offsetWidth) > screen.right){				
				target.style.left = (targLeft - ((targLeft + target.offsetWidth) - screen.right)) + "px";
				
			}
			if(targTop < screen.top){	
				target.style.top = (getAbsoluteTop(caller) + caller.offsetHeight)+17+"px";	
				addClass(target,'flydown');
			}		
		}
	}
	
	function tipOutHandler(e){
		if(enableTooltips==1){
			var caller = eventSource(e);
			var target = document.getElementById('tipshell');
			caller.setAttribute('title',caller.object.content.toString());
			setOpacity(document.getElementById('tipshell'), 0);
			fadeLayer('tipshell',0,30,20);
			target.style.display = 'none';
		}
	}
	
	function ToolTipItem(itemdata){
		this.item = itemdata;
		this.item.object = this;
		this.content = document.createTextNode(this.item.getAttribute('title').toString());
		
		this.item.tooltop = new ToolTip(this.content,this)
		addListener(this.item,'mouseover',tipOverHandler);
		addListener(this.item,'focus',tipOverHandler);
		addListener(this.item,'mouseout',tipOutHandler);
		addListener(this.item,'blur',tipOutHandler);
		
	}
	function ToolTip(tipdata,parent){
		this.container = document.createElement("DIV");	
		this.container.object = this;
		this.container.appendChild(tipdata);
		addClass(this.container,'tip_text')
		this.container.parent = parent.item;
		this.container.parent.child = this.container;
		this.container.style.display= 'none';
		document.getElementsByTagName("body")[0].appendChild(this.container);	
	}
	
	
	function initTips(styleName,tagName){	
		var toolTipShell = document.createElement('DIV');
			toolTipShell.setAttribute('id','tipshell');
			addClass(toolTipShell,'tip_shell')
			setOpacity(toolTipShell, 0)
			
		var toolTipBottomCap =  document.createElement('DIV');
			toolTipBottomCap.setAttribute('id','tipbottomcap');
			addClass(toolTipBottomCap,'tip_bottom');		
		
			toolTipShell.appendChild(toolTipBottomCap);		
			toolTipShell.style.display = 'none';
			document.getElementsByTagName("body")[0].appendChild(toolTipShell);	
		
		var tips = getElementsByClassName(styleName,tagName);
		
		for(var x=0; x < tips.length; x++){
			tips[x] = new ToolTipItem(tips[x]);
		}
	}
