var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko") > -1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE") > -1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var Op = (navigator.userAgent.indexOf("Opera") > -1) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5 && !Op) ? true : false;
var origWidth, origHeight;
var offX= 20;
var offY= 12;
var tooltip, tipcss;
var t1,t2;
var tipOn = false;
var mouseX, mouseY;

if (nodyn) {
  event = "nope";
}

if (!nodyn) {
  tooltip = (ie4) ? document.all['tipDiv'] : (ie5 || ns5 || Op) ? document.getElementById('tipDiv') : null;
  tipcss = tooltip.style;
  if (ie4 || ie5 || ns5 || Op) {
    /*
	tipcss.width = '300px';
    tipcss.backgroundColor = '#FFFFFF';
    tipcss.borderColor = '#EA5B86';
    tipcss.borderWidth = '1px';
    tipcss.padding = '0px';
    tipcss.borderStyle = 'ridge';
	*/
	// nel css almeno si personalizza per pagina
  }
}

function ShowTip(evt,text,chiudi) {
  if (!tooltip) {
    return;
  }
  if (t1) {
    clearTimeout(t1);
  }
  if (t2) {
    clearTimeout(t2);
  }
  tipOn = true;
  if (ie4 || ie5 || ns5 || Op) {
    var tip = ''
		tip  = '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLSPACING="5">';
		tip += '<tr>';
    	tip += '<td class="tdDiv" VALIGN="top" WIDTH="16" STYLE="Padding : 2px 2px 2px 2px;"><div id="tipImg"></div></td>';
    	tip += '<td class="testoTip">' + text + '</td>';
    	tip += '</tr>';
		//aggiornamento
		//<img SRC="images/javascript/LgInfoToolTip.png" WIDTH="16" HEIGHT="16" border="0" id="tipImg>"

		tip += '<tr>';
    	tip += '<td class="tdDiv" valign="top" WIDTH="16" style="Padding : 2px 2px 2px 2px;">&nbsp;</TD>';
    	tip += '<td style="padding: 5px 5px 5px 5px; color: #666666;" bgcolor="#ffffff" align="center">'; 
		tip += '<input name="Close" type="button" class="bottoneTip" value="Close" onClick="HideTip();"> ';
		tip += '</td>';
		tip += '</tr>';
		tip += '</TABLE>';
	
    tooltip.innerHTML = tip;
  }
  //0E5082
  //t1 = setTimeout("tipcss.visibility='visible'", 100);
  //PositionTip(evt);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
//arrayPageScroll[1] + 
	var top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 50- 100) / 2);
	//var top = ((arrayPageSize[3]) / 2) ;
	var left = ((arrayPageSize[0] - 20 - 300) / 2);
	
// alert (top);
  //tipcss.top	=	400+ 'px';
  //tipcss.left	=	200+ 'px';
  tipcss.top	=	top+ 'px';
  tipcss.left	=	left+ 'px';
  
 // tipcss.top	=	400+ 'px';
 // tipcss.left	=	200+ 'px';
  t1 = setTimeout("tipcss.visibility='visible'", 100);

}
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function PositionTip(evt) {
  //mouseX = (ns5) ? evt.pageX : window.event.clientX + document.body.scrollLeft;
  //
  // mouseY = (ns5) ? evt.pageY : window.event.clientY + document.body.scrollTop;
  //alert(window.event.clientX);
  // se l'utente usa ie5 devo usere il body se no con il doctype uso il documentElement
if (document.documentElement && document.documentElement.scrollTop)
{
	mouseX = (ns5) ? evt.pageX : window.event.clientX + document.documentElement.scrollLeft;
	mouseY = (ns5) ? evt.pageY : window.event.clientY + document.documentElement.scrollTop;
}
else if (document.body)
{
	mouseX = (ns5) ? evt.pageX : window.event.clientX + document.body.scrollLeft;
	mouseY = (ns5) ? evt.pageY : window.event.clientY + document.body.scrollTop;
}
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX +
document.body.scrollLeft; mouseY = (ns4||ns5)? evt.pageY: window.event.clientY +
document.body.scrollTop; if (tipOn) positionTip(evt);

  // alert (mouseX + " - " + window.event.clientY);
  var tpWd = (ie4 || ie5 || Op) ? tooltip.clientWidth : tooltip.offsetWidth;
  var tpHt = (ie4 || ie5 || Op) ? tooltip.clientHeight : tooltip.offsetHeight;
  var winWd = (ns5) ? window.innerWidth - 20 + window.pageXOffset : document.body.clientWidth + document.body.scrollLeft;
  var winHt = (ns5) ? window.innerHeight - 20 + window.pageYOffset : document.body.clientHeight + document.body.scrollTop;
  if ((mouseX + offX + tpWd) > winWd) {
    tipcss.left = mouseX - (tpWd + offX) + 'px';
  } else {
    tipcss.left = mouseX + offX + 'px';
  }
  if ((mouseY + offY + tpHt) > winHt) {
    tipcss.top = winHt - (tpHt + offY) + 'px';
  } else {
    tipcss.top = mouseY + offY + 'px';
  }
  alert (tipcss.top+ " - "+ tipcss.left);
  tipcss.top	=	400+ 'px';
  tipcss.left	=	200+ 'px';
  t1 = setTimeout("tipcss.visibility='visible'", 100);
}

function HideTip() {
  if (!tooltip) {
    return;
  }
  t2 = setTimeout("tipcss.visibility='hidden'", 100);
  tipOn = false;
}
