﻿/*
History
~~~~~~~~
v1.02 042904 Edi, Changed the long IF statement of select box checking, to a shorter one.
v1.01 042404 Oren, added NotificationBubble
v1.00 022504 Edi, First Version.
*/


/*
Javascript code foe handling the tooltip layers (HelpBubble).
Functions collected, created, and fixed by Edi Buslovich, December 2003.
*/
var BoxName,xBoxPos,yBoxPos
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

var bubbletype=0 //Type of help bubble, (0 HelpBubble, 1 NotificationBubble)
var displaymode="all"
var enablefade="yes" //("yes" to enable fade in effect, "no" to disable)
var autohidebox=["no", 5] //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
var showonscroll="yes" //Should box remain visible even when user scrolls page? ("yes"/"no)
var IEfadelength=0.6 //fade in duration for IE, in seconds
var Mozfadedegree=0.05 //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)
if (parseInt(displaymode)!=NaN)
	var random_num=Math.floor(Math.random()*displaymode)

function displayfadeinbox(){
	var ie=document.all && !window.opera
	var dom=document.getElementById
	iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	objref=(dom)? document.getElementById(BoxName) : document.all.fadeinbox
	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
	var docwidth=(ie)? iebody.clientWidth : window.innerWidth
	docheight=(ie)? iebody.clientHeight: window.innerHeight
	var objwidth=objref.offsetWidth
	objheight=objref.offsetHeight

	
	/////////////////////////////////////////////
	//Code that was added to the original code://
	/////////////////////////////////////////////
	var objrefWidth = objref.style.width
	var objrefHeight = objref.style.height
	objrefWidth=Number(objrefWidth.substr(0,objrefWidth.indexOf("px")))
	objrefHeight=Number(objrefHeight.substr(0,objrefHeight.indexOf("px")))
	//Check if the layer isn't getting out of the screen. If so, then move it some pixels, so that it will be inside the screen: 
	if((xMousePos+objrefWidth)>xMousePosMax){
		xBoxPos=xMousePos-objrefWidth
	}else{
		xBoxPos=xMousePos+10
	}
	if((yMousePos+objrefHeight)>yMousePosMax){
		yBoxPos=yMousePos-objrefHeight
	}else{
		yBoxPos=yMousePos+10
	}
	yBoxPos=yMousePos+10;
	
	//Check type of bubble
	//If it's a Notification Bubble display it according to pre defined values, not mouse position.
	if (bubbletype==1){
		objref_pos=document.getElementById("notification_position")
		xBoxPos=GetElementLeft(objref_pos)
		yBoxPos=GetElementTop(objref_pos)
		bubbletype=0
	}
	
	//Go through all the select boxes and check if the layer box isn't located above the select box.
	for(var i=0;i<document.forms.length;i++) {
		var e = document.forms[i].elements
		for(var j=0;j<e.length;j++) {
			if(e[j].options) {
				var selectLeft=GetElementLeft(e[j])
				var selectRight=selectLeft+e[j].offsetWidth
				var selectTop=GetElementTop(e[j])
				var selectBottom=selectTop+e[j].offsetHeight
				var BoxLeft=xBoxPos
				var BoxRight=BoxLeft+objrefWidth
				var BoxTop=yBoxPos
				var BoxBottom=BoxTop+objrefHeight
				//if((((selectLeft>BoxLeft)&&(selectLeft<BoxRight))||((selectRight>BoxLeft)&&(selectRight<BoxRight))||((BoxLeft>selectLeft)&&(BoxLeft<selectRight))||((BoxRight>selectLeft)&&(BoxRight<selectRight)))&&(((selectTop>BoxTop)&&(selectTop<BoxBottom))||((selectBottom>BoxTop)&&(selectBottom<BoxBottom))||((BoxTop>selectTop)&&(BoxTop<selectBottom))||((BoxBottom>selectTop)&&(BoxBottom<selectBottom)))){
				if((((selectLeft>BoxLeft)&&(selectLeft<BoxRight))||((selectRight>BoxLeft)&&(selectRight<BoxRight)))&&(((selectTop>BoxTop)&&(selectTop<BoxBottom))||((selectBottom>BoxTop)&&(selectBottom<BoxBottom)))){
					e[j].style.visibility='hidden'
				}
			}
		}
	}
	
	objref.style.left=xBoxPos+"px"
	objref.style.top=yBoxPos+"px"
	/////////////////////////////////////////////////////////
	

	if (showonscroll=="yes")
	showonscrollvar=setInterval("staticfadebox()", 50)

	if (enablefade=="yes" && objref.filters){
		objref.filters[0].duration=IEfadelength
		objref.filters[0].Apply()
		objref.filters[0].Play()
	}
	objref.style.visibility="visible"
	if (objref.style.MozOpacity){
		if (enablefade=="yes")
			mozfadevar=setInterval("mozfadefx()", 90)
		else{
			objref.style.MozOpacity=1
			controlledhidebox()
		}
	}
	else
	controlledhidebox()	
}

function mozfadefx(){
	if (parseFloat(objref.style.MozOpacity)<1)
		objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+Mozfadedegree
	else{
		clearInterval(mozfadevar)
		controlledhidebox()
	}
}

function staticfadebox(){
	var ie=document.all && !window.opera
	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
	objref.style.top=yBoxPos+"px"
}

function hidefadebox(strBoxName){
	document.getElementById(strBoxName).style.visibility="hidden"
	toggleSelectBoxes('show')
	if (typeof showonscrollvar!="undefined")
		clearInterval(showonscrollvar)
}

function controlledhidebox(){
	if (autohidebox[0]=="yes"){
		var delayvar=(enablefade=="yes" && objref.filters)? (autohidebox[1]+objref.filters[0].duration)*1000 : autohidebox[1]*1000
		setTimeout("hidefadebox()", delayvar)
	}
}

function initfunction(strBoxName){
	BoxName=strBoxName
	setTimeout("displayfadeinbox()", 100)
}



/////////////////////////////////////////////////////
//Functions , that were added to the original code://
////////////////////////////////////////////////////
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousedown = getMouseXY;
} else if (document.all) { // Internet Explorer
    document.onmousedown = getMouseXY;
} else if (document.getElementById) { // Netcsape 6
    document.onmousedown = getMouseXY;
}
//Get the X/Y coordinates of the mouse:
function getMouseXY(e) 
{
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
		xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

//Get the absolute left value any element (measured from the left edge of the screen):
function GetElementLeft(eElement) { 
	var nLeftPos = eElement.offsetLeft; // initialize var to store calculations 
	var eParElement = eElement.offsetParent; // identify first offset parent element 
	while (eParElement != null) { 
		// move up through element hierarchy 
		nLeftPos += eParElement.offsetLeft; // appending left offset of each parent 
		eParElement = eParElement.offsetParent; // until no more offset parents exist 
	} 
	return nLeftPos; // return the number calculated 
} 

//Get the absolute top value any element (measured from the top edge of the screen):
function GetElementTop(eElement){ 
	var nTopPos = eElement.offsetTop; // initialize var to store calculations var 
	eParElement = eElement.offsetParent; // identify first offset parent element 
	while (eParElement != null) { 
		// move up through element hierarchy 
		nTopPos += eParElement.offsetTop; // appending top offset of each parent 
		eParElement = eParElement.offsetParent; // until no more offset parents exist 
	} 
	return nTopPos; // return the number calculated 
}


//Find select boxes in the page, and make them visible/invisible (because select box is a problematic object, which is always on top of any layer):
function toggleSelectBoxes(arg) {
	for(var i=0;i<document.forms.length;i++) {
		var e = document.forms[i].elements
		for(var j=0;j<e.length;j++) {
			if(e[j].options) {
				e[j].style.visibility = (arg=='hide') ? 'hidden' : 'visible';
			}
		}
	}
}
//////////////////////////////////////////////////////
