
// 2002010219.44 th
// this file contains the scripts neccessary to run the tooltip function.
// this file is called by the following files:
// html/calendar.html
// cgi/templateEditRecords.txt
// cgi/templateUserAdminMultiForm.txt

// Currently the following arrTooltipMessages slots have been reserved:
//    500 +  reserved for ScheduleToolDisplayCalendar - used for appointments
// 
//    500 +  reserved for ScheduleToolEdit/NewRecord - used for Group administration
//    500 +  reserved for UserAdminEdit/NewUser      - used for Group administration
//    500 +  reserved for GroupAdminEdit/NewGroup    - used for Group administration
//    100-199 reserved for ScheduleToolEditRecord - used for permission sets
//          100, 101, 102, 103  Owner
//          120, 121, 122, 123  Group
//          140, 141, 142, 143  World
//    200-299 reserved for UserAdminEditUser|UserAdminDisplayList - used for permission sets
//          200, 201, 202, 203  Owner
//          220, 221, 222, 223  Group
//          240, 241, 242, 243  World

// if not included by the file, then the following array must be populated with the messages you want displayed
// arrTooltipMessages= new Array()
// arrTooltipMessages[0]="Toggle fade effect"
// arrTooltipMessages[1]="Switch <br>anim<br>ation on and off"
// arrTooltipMessages[2]="Toggle the window detection between 'smooth' and 'flip'"

// you will also need to place the following into your html file:
/*
troubleshooting:
   tooltips don't appear:
      check:
         ensure arrTooltipMessages is correctly populated, and has an entry for your desired tool tip
         ensure you are calling the subTooltipPopUp() correctly
         does the body have an onLoad() attribute, if so, is it needed and already handled? if not try removeing the onLoad() attribute

<style>

// This is the style for the tooltips. 

#divTooltip {position:absolute; top:0px; width:250px; visibility:hidden; z-index:200; background-color:#f3f3f3; layer-background-color:#f3f3f3;}

.TooltipNormalStyle    {padding:2px; text-align:left; font-weight:500; width:250px; color:#000000; top:100px; font-family:verdana,arial,helvetica; font-size:11px; background-color:#f3f3f3; layer-background-color:#f3f3f3; border-width:1px; border-style:solid; border-color:#000000; cursor:default;}

.TooltipNetscape4Style {padding:0px; text-align:left; font-weight:500; width:300; color:#000000; top:100px; font-family:verdana,arial,helvetica; font-size:11px; background-color:#f3f3f3; layer-background-color:#f3f3f3; border:1px solid #000000;}  

</style>

<body>
<div id='divTooltip'></div>
</body>
*/

var flagTooltipBrowser=new funTooltipLibBrowserCheck()


// Variables to set:
intTooltipPrefFromX= -1           // How much from the actual mouse X should the description box appear?
intTooltipPrefFromY= 21           // How much from the actual mouse Y should the description box appear?
blnTooltipNS4Center= 0        // Centering the text in ns4 doesn't work with css, use this variable instead... the value is 1 or 0
blnTooltipUseFading= 0        // 1 for a fading effect in windows explorer 5+ and all platforms ns6, 0 for no fading effect.
blnTooltipAnimation= 1        // 1 if you want animation, 0 for no animation.
blnTooltipDetectionType= 0    // 1 for 'smooth' window size detection, 0 for 'flip' window size detection.
blnTooltipDelay= 300          // The time before showing the popup, in milliseconds.


/*** There should be no need to change anything beyond this. ***/ 

// A unit of measure that will be added when setting the position of a layer.
var strTooltipPX = flagTooltipBrowser.ns4||window.opera?"":"px";
var intTooltipMouseX=0,intTooltipMouseY=0,intTooltipSetX=0,intTooltipSetY=0;
var blnTooltipHovering=false, intTooltipScreenWidthScrolled=0, intTooltipScreenHeightScrolled=0;
makeTooltip.prototype.showTimer= null;
makeTooltip.prototype.popTimer= null;
var scrollbarWidth= flagTooltipBrowser.ns6&&flagTooltipBrowser.win?14:flagTooltipBrowser.ns6&&!flagTooltipBrowser.win?16:flagTooltipBrowser.ns4?16:0;
makeTooltip.prototype.step= 8;
makeTooltip.prototype.i= 0;
makeTooltip.prototype.fadeTimer= null;
var blnTooltipIsLoaded= false;

if(document.layers){ //NS4 resize fix.
    intTooltipScreenWidth= innerWidth; intTooltipScreenHeight= innerHeight;
    onresize= function(){if(intTooltipScreenWidth!= innerWidth || intTooltipScreenHeight!= innerHeight){history.go(0)} };
    } // end if

// Initiates page on pageload if the browser is ok.
if(flagTooltipBrowser.browser && !blnTooltipIsLoaded) onload= subTooltipInitiate;

function funTooltipLibBrowserCheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.browser=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
	} // end function funToolTipLibBrowserCheck()

// object constructor...
function makeTooltip(obj){								
   	// this.elm= funFindObj(obj); 
	this.elm= document.getElementById? document.getElementById(obj):flagTooltipBrowser.ie4?document.all[obj]:flagTooltipBrowser.ns4?document.layers[obj]:0;
   	this.css= flagTooltipBrowser.ns4?this.elm:this.elm.style;
   	this.wref= flagTooltipBrowser.ns4?this.elm.document:this.elm;
	this.obj= obj+'makeTooltip'; eval(this.obj+'=this');
	this.w= flagTooltipBrowser.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= flagTooltipBrowser.ns4? this.elm.clip.height: this.elm.offsetHeight;
	}; // end function makeTooltip(object)

makeTooltip.prototype.measureIt= function(){
	this.w= flagTooltipBrowser.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= flagTooltipBrowser.ns4? this.elm.clip.height: this.elm.offsetHeight;
	}; // end function()

makeTooltip.prototype.writeIt= function(text){
	if (flagTooltipBrowser.ns4) {this.wref.write(text); this.wref.close()}
	else this.wref.innerHTML= text;
	}; // end function(text)

// Mousemove detection
function funTooltipGetMouseMove(e){
	intTooltipMouseX= (flagTooltipBrowser.ns4||flagTooltipBrowser.ns6)? e.pageX: flagTooltipBrowser.ie&&flagTooltipBrowser.win&&!flagTooltipBrowser.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
	intTooltipMouseY= (flagTooltipBrowser.ns4||flagTooltipBrowser.ns6)? e.pageY: flagTooltipBrowser.ie&&flagTooltipBrowser.win&&!flagTooltipBrowser.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
	if (blnTooltipIsLoaded && blnTooltipHovering && blnTooltipAnimation) funTooltipPlaceIt();
	}; // end function funTooltipGetMouseMove(event)

function funTooltipPlaceIt(){
	if (blnTooltipDetectionType==1) intTooltipSetX= intTooltipMouseX+intTooltipPrefFromX+tooltip.w > intTooltipScreenWidthScrolled ? intTooltipScreenWidthScrolled-tooltip.w: intTooltipMouseX+intTooltipPrefFromX;
	if (blnTooltipDetectionType==1) intTooltipSetY= intTooltipMouseY+intTooltipPrefFromY+tooltip.h > intTooltipScreenHeightScrolled ? intTooltipScreenHeightScrolled-tooltip.h: intTooltipMouseY+intTooltipPrefFromY;
	if (blnTooltipDetectionType==0) intTooltipSetX= intTooltipMouseX+intTooltipPrefFromX+tooltip.w > intTooltipScreenWidthScrolled ? intTooltipMouseX-intTooltipPrefFromX-tooltip.w: intTooltipMouseX+intTooltipPrefFromX;
	if (blnTooltipDetectionType==0) intTooltipSetY= intTooltipMouseY+intTooltipPrefFromY+tooltip.h > intTooltipScreenHeightScrolled ? intTooltipMouseY-intTooltipPrefFromY-tooltip.h: intTooltipMouseY+intTooltipPrefFromY;
	if (intTooltipSetX<0) intTooltipSetX= 0;
	if (intTooltipSetY<0) intTooltipSetY= 0;
	tooltip.css.left= intTooltipSetX+strTooltipPX;
	tooltip.css.top= intTooltipSetY+strTooltipPX;
	}; // end function funTooltipPlaceIt()

// Main popUp function.
function subTooltipPopUp(num){
//alert(arrTooltipMessages[num]);
	if(blnTooltipIsLoaded){
		clearTimeout(tooltip.popTimer);
		funTooltipDoPopDown();
		if (flagTooltipBrowser.ns4){
			var text= '<span class="TooltipNetscape4Style"><table width=300><tr><td width=300>' + (blnTooltipNS4Center?'<center>':"") + arrTooltipMessages[num] + (blnTooltipNS4Center?'</center>':"") + '</td></tr></table></span>';
			tooltip.writeIt(text);
			} // end if
		if (!flagTooltipBrowser.ns4) tooltip.writeIt(arrTooltipMessages[num]);
		intTooltipScreenWidthScrolled= funTooltipScreenWidth + (flagTooltipBrowser.ie?document.body.scrollLeft:pageXOffset);
		intTooltipScreenHeightScrolled= funTooltipScreenHeight + (flagTooltipBrowser.ie?document.body.scrollTop:pageYOffset);
		blnTooltipHovering= true;
		
		if (flagTooltipBrowser.ie4) setTimeout('tooltip.measureIt(); funTooltipPlaceIt();', blnTooltipDelay/2);
		else { tooltip.measureIt(); funTooltipPlaceIt(); }
		if (blnTooltipUseFading) tooltip.showTimer= setTimeout('tooltip.blendIn()', blnTooltipDelay);
		if (!blnTooltipUseFading) tooltip.showTimer= setTimeout('tooltip.css.visibility="visible"', blnTooltipDelay);
    		} // end if
	}; // end function subTooltipPopup(num)

// Hiding routines
function subTooltipPopDown(){
	if (blnTooltipIsLoaded) {
		tooltip.popTimer= setTimeout('funTooltipDoPopDown()', 30)
		} // end if
	} // end function subTooltipPopDown()
	
function funTooltipDoPopDown(){
	blnTooltipHovering= false;
	clearTimeout(tooltip.showTimer);
	clearTimeout(tooltip.fadeTimer);
	tooltip.css.visibility= 'hidden';
	tooltip.i= 0;
	}; // end function funTooltipDoPopDown()

// Measure screensize.
function measureScreen() {
	tooltip.css.top= 0+strTooltipPX;
	tooltip.css.left= 0+strTooltipPX;
	funTooltipScreenWidth= (flagTooltipBrowser.ie?document.body.clientWidth:innerWidth) - scrollbarWidth;
	funTooltipScreenHeight= (flagTooltipBrowser.ie?document.body.clientHeight:innerHeight);
	}; // end function measureScreen()

// Opacity methods.
makeTooltip.prototype.blendIn= function(){
	if (flagTooltipBrowser.ie && flagTooltipBrowser.win && !flagTooltipBrowser.ie4) {
		this.css.filter= 'blendTrans(duration=0.5)';
		this.elm.filters.blendTrans.apply();
		this.css.visibility= 'visible';
		this.elm.filters.blendTrans.play();
		} else {
		this.css.visibility= 'visible';
		if (!flagTooltipBrowser.ns4) this.fadeIt();
		} // end if
	}; // end function()

makeTooltip.prototype.fadeIt= function(){
	this.i+= this.step;
	//this.css.filter= 'alpha(opacity='+this.i+')';
	this.css.MozOpacity= this.i/100;
	if (this.i<100) this.fadeTimer= setTimeout(this.obj+'.fadeIt()', 40);
	else this.i= 0;
	}; // end function()

// Init function...
function subTooltipInitiate(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	flagTooltipBrowser.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (flagTooltipBrowser.opera5) flagTooltipBrowser.ns6 = 0
	
	//Extending the browsercheck to add windows platform detection.
	flagTooltipBrowser.win= (navigator.userAgent.indexOf('Windows')>-1)

	tooltip= new makeTooltip('divTooltip');
	tooltip.elm.onmouseover= function(){ clearTimeout(tooltip.popTimer); if(flagTooltipBrowser.ns4){setTimeout('clearTimeout(tooltip.popTimer)',20)}; };
	tooltip.elm.onmouseout= funTooltipDoPopDown;
	if (flagTooltipBrowser.ns4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove= funTooltipGetMouseMove;
	measureScreen();
	if (!flagTooltipBrowser.ns4) onresize= measureScreen;
	if (!flagTooltipBrowser.ns4) tooltip.elm.className= 'TooltipNormalStyle';
	if (flagTooltipBrowser.ie && flagTooltipBrowser.win && !flagTooltipBrowser.ie4) tooltip.css.filter= 'alpha(opacity=100)'; //Preloads the windows filters.
	blnTooltipIsLoaded= true;
	}; // end function subTooltipInitiate()

