/*
	tipo = 'down','up','right' cambia la posizione della punta
	
	NB usare la riga sotto per includere le funzioni
	
	<script id="tooltip_js" type="text/javascript" src="/js/tooltip/tooltip.js"></script>
*/

function open_tooltip(obj,messaggio,tipo) {
	
	// debug
	var idTool = obj.name+'_tooltip';
	if($(idTool))
		{
		return;
		}
	var IeVer = ''+BrowserDetect.version+'';
	if ((BrowserDetect.browser == 'Explorer') && (IeVer.indexOf('6') == 0))
		{
		filterPng = true;
		} else {
		filterPng = false;
		}
	imgPath = '/img96/new/static/tooltip/';
	spcPath = '/img96/static/space.gif';
	
	var tool   = document.createElement("div");
	
	tool.setAttribute('id',idTool);
   
  var oTable='<table border="0" cellpadding="0" cellspacing="0">';
 	oTable+='<tr>';
	oTable+='<td></td>';
  if (tipo=='up') 
		{
		if (filterPng)
			{
			oTable+='<td align="right"><img src="'+spcPath+'" width="42" height="40" style="position:relative;top:+5px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'up.png\', sizingMethod=\'scale\');"></td>';	
			}
			else
			{
			oTable+='<td align="right"><img src="'+imgPath+'up.png" width="42" height="40" style="position:relative;top:+5px;"></td>'; 
			}
		}
		else 
		{
		oTable+='<td></td>';
		}
	oTable+='<td></td>';
	oTable+='</tr>';
  
  oTable+='<tr>';
  	if (filterPng)
		{
		oTable+='<td><img src="'+spcPath+'" width="20" height="13" style="position:relative; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_01.png\', sizingMethod=\'scale\');"></td>';
		oTable+='<td style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_02.png\', sizingMethod=\'scale\');"></td>';
		oTable+='<td><img src="'+spcPath+'" width="21" height="13" style="position:relative; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_03.png\', sizingMethod=\'scale\');"></td>';
		oTable+='</tr>';
	
		oTable+='<tr>';
		oTable+='<td style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_04.png\', sizingMethod=\'scale\');"></td>';
		oTable+='<td style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_05.png\', sizingMethod=\'scale\');"">'+messaggio+'</td>';
		oTable+='<td style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_06.png\', sizingMethod=\'scale\');"></td>';
		oTable+='</tr>';
	
		oTable+='<tr>';
		oTable+='<td><img src="'+spcPath+'" width="20" height="13" style="position:relative; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_07.png\', sizingMethod=\'scale\');"></td>';
		oTable+='<td style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_08.png\', sizingMethod=\'scale\');"></td>';
		oTable+='<td><img src="'+spcPath+'" width="21" height="13" style="position:relative; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'back_09.png\', sizingMethod=\'scale\');"></td>';
		oTable+='</tr>';
		}
		else
		{
		oTable+='<td><img   src="'+imgPath+'back_01.png" width="20" height="13"></td>';
		oTable+='<td background="'+imgPath+'back_02.png"></td>';
		oTable+='<td><img   src="'+imgPath+'back_03.png" width="21" height="13"></td>';
		oTable+='</tr>';
	
		oTable+='<tr>';
		oTable+='<td background="'+imgPath+'back_04.png"></td>';
		oTable+='<td background="'+imgPath+'back_05.png" style="opacity:1;">'+messaggio+'</td>';
		oTable+='<td background="'+imgPath+'back_06.png"></td>';
		oTable+='</tr>';
	
		oTable+='<tr>';
		oTable+='<td><img    src="'+imgPath+'back_07.png" width="20" height="13"></td>';
		oTable+='<td background ="'+imgPath+'back_08.png"></td>';
		oTable+='<td><img    src="'+imgPath+'back_09.png" width="21" height="13"></td>';
		oTable+='</tr>';
		}
	

	oTable+='<tr>';
	oTable+='<td></td>';
  if (tipo=='down')         
  	{
		if (filterPng)
		{
		oTable+='<td align="right"><img src="'+spcPath+'" width="42" height="40"  style="position:relative;top:-6px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'down.png\', sizingMethod=\'scale\');"></td>'; 
		}
		else
		{
		oTable+='<td align="right"><img src="'+imgPath+'down.png" width="42" height="40" style="position:relative;top:-6px;"></td>'; 
		}
	}
  	else if (tipo=='right')   
	{
		if (filterPng)
		{
	oTable+='<td align="right"><img src="'+spcPath+'" width="63" height="34"  style="position:relative;top:-6px;left:23px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgPath+'right.png\', sizingMethod=\'scale\');"></td>'; 
		}
		else
		{
		oTable+='<td align="right"><img src="'+imgPath+'right.png" width="63" height="34" style="position:relative;top:-6px; left: 23px"></td>'; 
		}
	}
  else oTable+='<td></td>';
	oTable+='<td></td>';
	oTable+='</tr>'; 
	oTable+='</table>';

  tool.innerHTML=oTable;

	document.body.appendChild(tool);
  
  refreshTooltip(obj,tipo);
  
  window.onresize = function () {
		refreshTooltip(obj,tipo);
	}
 
 

}

function close_tooltip(obj) {
	var idTool = obj.name+'_tooltip';
	if (document.getElementById(idTool))	document.body.removeChild(document.getElementById(idTool));
}


function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
 }
 
 
function refreshTooltip(obj,tipo) {
	var idTool = obj.name+'_tooltip';
	tool = document.getElementById(idTool);
  
  tool.style.position='absolute';
  tool.style.zIndex="3";
  
  var H = tool.offsetHeight; //if (H<100) H=104;
  var W = tool.offsetWidth;
	//alert(H+'*'+W);
  switch (tipo) {
  	case 'down':
  	  tool.style.top =(findPosY(obj)-H+4)+'px';
 		  tool.style.left=(findPosX(obj)-W+obj.offsetWidth)+'px';
 		  break;
 	  case 'up':
  	  tool.style.top =(findPosY(obj)+obj.offsetHeight-4)+'px';
 		  tool.style.left=(findPosX(obj)-W+obj.offsetWidth)+'px';
 		  break;	  
	 case 'right':
  	  tool.style.top =(findPosY(obj)-H+obj.offsetHeight)+'px';
 		  tool.style.left=(findPosX(obj)-W-4)+'px';
 		  break;	
  }
 	
}