﻿// 2745 - message enhancements
//Also I figured that tool tips are a type of message, so I am adding them in here as well
//These arrays are the colours the system fades through
var Color= new Array("FFFFCC","FFFFCE","FFFFD0","FFFFD3","FFFFD6","FFFFD9","FFFFDD","FFFFE1","FFFFE5","FFFFED","FFFFF2","FFFFF5","FFFFF8","FFFFFB","FFFFFD","FFFFFF");
var BorderColor= new Array("F9B550","F9B755","F9BB5E","FABF68","FAC473","FBC87D","FBCE8C","FCD49A","FCDAA6","FCDFB3","FDE6C3","FDEBD0","FEF0DB","FEF4E6","FEF8EF","FFFFFF");
// position of the tooltips relative to the mouse in pixel //
var tipOffsetX = 12;
var tipOffsetY =  8;
var tipheight = 0;


	function initMessageFade()
	{    
		var Msg = document.getElementById('msgBox'); 
		if (Msg) {
			setTimeout("messageFade(0)", 5000)
		}
	}

	function messageFade(where){
		var Msg = document.getElementById('msgBox');    
		if (where<Color.length) {
			//Fade the background a bit more
			Msg.style.background="#"+Color[where];
			Msg.style.borderColor="#"+BorderColor[where];
			
			where += 1;
			setTimeout("messageFade("+where+")", 100)
		}
	}

//Tooltips

		//tooltip start
		function tts(tip) {
			tipOffsetX = 12;
			tipOffsetY =  8;		
			tsBase(tip);
			document.onmousemove = ttMove;
		}

		function tsBase(tip) {
			if(!$('tooltip')) ttInit();
			var el = $('tooltip');
			el.innerHTML = tip;
			el.style.display = 'block';		
			tipheight =  el.offsetHeight;
		}

		//tool tip end
		function tte() {
			document.getElementById('tooltip').style.display = 'none';
		}

		function ttMove(e) {
			var mouseX=getMouseX(e);
			var mouseY=getMouseY(e);
			var minWidth = 100;
			var minWidth = 100;
			var myWidth = 0, myHeight = 0;
            var scrOfX = 0, scrOfY = 0;
            
            //get window size  
            if( typeof( window.innerWidth ) == 'number' ) {
                //Non-IE
                myWidth = window.innerWidth;
                myHeight = window.innerHeight;
            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                //IE 6+ in 'standards compliant mode'
                myWidth = document.documentElement.clientWidth;
                myHeight = document.documentElement.clientHeight;
            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
            //get scrolling offsets
            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;
            }
            
           //get the element
            var el = document.getElementById('tooltip');
            
            mouseX=mouseX+tipOffsetX;
            mouseY=mouseY+tipOffsetY;
            
            //check for going over the screen
            if ((mouseX + minWidth) > myWidth) {
                mouseX = mouseX - ((mouseX + minWidth) - myWidth);
            }
            if ((mouseY + tipheight) > (myHeight + scrOfY)) {
                mouseY  = mouseY - (tipOffsetY * 2) - tipheight;
            }
            //set the position
            if(!isNaN(mouseX)) el.style.left = (mouseX) + 'px';
            if(!isNaN(mouseY)) el.style.top = (mouseY) + 'px';  
		}

		function ttInit() { 
			if(document.createElement)
			{ 
				var el = document.createElement('div'); 
				el.id = 'tooltip';
				el.className='tooltip';    
				with(el.style)
				{ 
					display = 'none';
					position = 'absolute';
				} 
				el.innerHTML = '&nbsp;'; 
				document.body.appendChild(el);
			} 
		} 
//Centered message boxes
	var cbWidth=350;
	var cbHeight=80;
	//Centered box show
	function cbs(tip){
		tsBase('<div class="messagePleaseWait">' + tip + '</div>');
		var msgBox=$('tooltip');
		msgBox.style.height=cbHeight+'px';	
		msgBox.style.width=cbWidth+'px';	
		cbOnScroll();		
		if (window.attachEvent)
			window.attachEvent('onresize', cbOnScroll);
		else if (window.addEventListener)
			window.addEventListener('resize', cbOnScroll, false);
		else
			window.onresize = cbOnScroll;
			
		if (window.attachEvent)
			window.attachEvent('onscroll', cbOnScroll);
		else if (window.addEventListener)
			window.addEventListener('scroll', cbOnScroll, false);
		else
			window.onscroll = cbOnScroll;

	}
	//center box exit
	function cbe(){
		tte();	
		if (window.detachEvent)
			window.detachEvent('onresize', cbOnScroll);
		else if (window.removeEventListener)
			window.removeEventListener('resize', cbOnScroll, false);
		else
			window.onresize = null;
			
		if (window.detachEvent)
			window.detachEvent('onscroll', cbOnScroll);
		else if (window.removeEventListener)
			window.removeEventListener('scroll', cbOnScroll, false);
		else
			window.onscroll = null;		
	}
	
	function cbPosLeft() {
		if (typeof window.pageXOffset!='undefined')
			return window.pageXOffset;
		else if (document.documentElement && document.documentElement.scrollLeft)
			return document.documentElement.scrollLeft;
		else if (document.body.scrollLeft)
			return document.body.scrollLeft;
		else
			return 0;
	}
	function cbPosTop() {
		if (typeof window.pageYOffset!='undefined') 
			return window.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop) 
			return document.documentElement.scrollTop;
		else if (document.body.scrollTop)
			return document.body.scrollTop;
		else
			return 0;
	}
	function cbOnScroll() {
		var msgBox=$('tooltip');
		var cbTop=cbPosTop()+((windowHeight()-cbHeight)/2)-12;
		var cbLeft=cbPosLeft()+((windowWidth()-cbWidth)/2)-12;
		if (cbTop<0) cbTop=0;
		if (cbLeft<0) cbLeft=0;
		msgBox.style.top=cbTop+'px';	
		msgBox.style.left=cbLeft+'px';	
	}
	