/*
$Archive: $
$Revision: $
$Author: $
$Date: $

Description:  This file contains functions for the client tool tip component.
$History: $

*/
//State variables
var keepAlive = false; 		//toolTip state on/off
var isTranslated = false;	//Identifies if the toolTip has already been positioned for the current term
var openTimer = 0;			//Time to keep toolTip visible (ms)
var lastUniqueId = 0;		//Identifies the last element passed into the showToolTip function
var allSupport = true;		//Identifies the browser viewing the page (true: all browsers but Netscape, false: Netscape)

//Object variables
var containerEl = "";		//Identifies the container element used to store the content element
var contentEl = "";			//Identifies the content element that holds content

//Location variables
var mousex = 0;				//Identifies the current mouse position along the x axis
var mousey = 0;				//Identifies the current mouse position along the y axis

//Detect browser window size 
if (parseInt(navigator.appVersion)>3) {
	if (navigator.appName=="Netscape") {
		//Capture events for mouse coordinates for Netscape browsers
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = setMouseCoord;
		allSupport = false;
	 }else{
		allSupport = true;
	 }
}
	
function setMouseCoord(e){
	//For Netscape only, stores current mouse x, y position
	mousex = e.pageX;
	mousey = e.pageY;
}

function showToolTip(content, uId){
	// Get container element per browser
	if (allSupport){ //Is most browsers
	  containerEl = document.all.toolTip;
	  contentEl = document.all.toolTipContent;
	}else{ //Is netscape
	  containerEl = document.getElementById("toolTip");
	  contentEl = document.getElementById("toolTipContent");
	}
	
	 containerEl.width="100%";
	 containerEl.height="100%";
	 
	//Clear openTimer
	window.clearTimeout(openTimer);
	//If this element is different then the last, allow new translation
	
	if(uId != lastUniqueId){
		isTranslated = false;
	}
	//Assign new lastUniqueId
	lastUniqueId = uId;
	//Validate that content is present
	if(content.length > 0){
		//Populate content div
		contentEl.innerHTML = content;
	}else{
		//Display error message if no content is passed in.
		contentEl.innerHTML = "<b>The following error(s) has occured:</b><br /><br />No definition has been found for this term.";
	}
	//Position toolTip
	translateToolTip();
	//Set mouseOnTerm to true
	toolTipKeepAlive(true);
	//Set the timer
	setTimer();
}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function translateToolTip(){
	var xOffSet = 15; 				//Extra translation value for toolTip on x axis
	var yOffSet = 15; 				//Extra translation value for toolTip on y axis
	var windowX = 0; 				//Width of the browser window
	var windowY = 0; 				//Height of the browser window
	var isYAutoCorrected = false; 	//Specifies if the system made changes to the x coordinate
	var isXAutoCorrected = false; 	//Specifies if the system made changes to the y coordinate

	//Translate position each time the menu is initially displayed
	if(!isTranslated){
		//Configure variables for translation
		if (allSupport){ 
		 	//Store mouse x, y coordinates
		  	mousex = window.event.clientX + getScrollWidth();
		  	mousey = window.event.clientY + getScrollHeight();
			/*NOTE: Mouse coordinates are decided by the getMouseCoord function for Netscape browsers*/
		}
			
		//Store current browser window size and scroll offset, if any
		windowX = document.body.clientWidth + getScrollWidth();
		windowY = document.body.clientHeight + getScrollHeight();

		//Check for right screen boundry
		if(mousex + xOffSet + containerEl.width > windowX){
			containerEl.style.left = windowX - containerEl.width + "px";
			isXAutoCorrected = true;
		}
		
		//Check for left screen boundry
		if(mousex + xOffSet + containerEl.width < 0){
			containerEl.style.left = 0 + "px";
			isXAutoCorrected = true;
		}
		
		//Check for top screen boundry
		if(mousey + yOffSet + containerEl.height < 0){
			containerEl.style.top = 0 + "px";
			isYAutoCorrected = true;
		}
		
		//Check for bottom screen boundry
		if(mousey + yOffSet + containerEl.height > windowY){
			containerEl.style.top = windowY - containerEl.height + "px";
			isYAutoCorrected = true;
		}
		
		//if no autocorrection done, use initial inputs
		if(!isXAutoCorrected){
			containerEl.style.left = mousex + xOffSet + "px";
		}
		
		if(!isYAutoCorrected){
			containerEl.style.top = mousey + yOffSet + "px";
		}
		 
		//Mark as translated for this element
		isTranslated = true;
		
		//Show container element
		toggleToolTip(true);
	}
}

function toggleToolTip(bool){
	//Turns toolTip visibility on/off
	if(bool){
		//Show toolTip
		containerEl.style.visibility = "visible";
	}else{
		//Hide toolTip
		containerEl.style.visibility = "hidden";
	}
}

function toolTipKeepAlive(bool){
	//Update keepAlive variable for open state
	keepAlive = bool;
}

function checkToolTipOpenStatus(){
	//Determine if the toolTip is still in use at the end of the timeout.
	if(!keepAlive){
		//Reset for next translation
		isTranslated = false;
		//Hide toolTip
		toggleToolTip(false);
	}else{
		//Continue to show toolTip
		toggleToolTip(true);
	}
}

function setTimer(){
	//Set the timer 
	openTimer = setTimeout("setTimer()", 1500);
	//Evaluate keepAlive status
	checkToolTipOpenStatus();
}


/* top menu */
function ChangeLayer(str)
{
	document.images.mnu01.src = "/img/common/menu/top01.gif"
	document.images.mnu02.src = "/img/common/menu/top02.gif"
/*	document.images.mnu03.src = "/img/common/menu/top03.gif"*/
/*	document.images.mnu04.src = "../img/common/menu/top04.gif"*/

	str2 = eval("document.images.mnu" + str )
	str2.src = "/img/common/menu/top" + str + "on.gif"

	document.all.div01.style.display = "none" 
	document.all.div02.style.display = "none" 
	/*document.all.div03.style.display = "none" */
	/*document.all.div04.style.display = "none" */

	
	str3 = eval("document.all.div" + str )
	str3.style.display = "inline"

}



/* Αφ΅΅ */
/* top menu */
function ImgLayer(str)
{

	document.all.fla01.style.display = "none" 
	document.all.fla02.style.display = "none" 
	document.all.fla03.style.display = "none" 
	document.all.fla04.style.display = "none" 

	
	str3 = eval("document.all.fla" + str )
	str3.style.display = "inline"

}



function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
