var globalBlinkCount=0,globalBlinkTimer=0;
var arColoriBlink=new Array();idxColoriBlink=0;
arColoriBlink[0]='';
arColoriBlink[1]='ff6600';
arColoriBlink[2]='ff9900';
arColoriBlink[3]='ffcc00';
arColoriBlink[4]='ffff00';
arColoriBlink[5]='ffff66';
arColoriBlink[6]='ffffcc';
arColoriBlink[7]='ffff66';
arColoriBlink[8]='ffff00';
arColoriBlink[9]='ffcc00';
arColoriBlink[10]='ff9900';

function blinkElement(idEle,passaggi,sino)
{
    var o=document.getElementById(idEle);
    idxColoriBlink=idxColoriBlink + 1
    if (idxColoriBlink==0 || idxColoriBlink >10) {idxColoriBlink=1;}    
    if (!o) {return;}
    if (globalBlinkCount==0) {        
        arColoriBlink[0]=o.style.backgroundColor;        
    }
    if (globalBlinkCount<passaggi) {        
        o.style.backgroundColor=arColoriBlink[idxColoriBlink];
        globalBlinkCount=globalBlinkCount + 1;
        clearTimeout(globalBlinkCount);
        globalBlinkTimer=setTimeout('blinkElement(\'' + idEle + '\',' + passaggi + ',\'hidden\')',20);
        
    }
    else {
        clearTimeout(globalBlinkCount);
        globalBlinkCount=0; idxColoriBlink=0;
        document.getElementById(idEle).style.visibility='visible';
        o.style.backgroundColor=arColoriBlink[0];
    }
}

function goLinkPagina(strIDLink,iPagina) {
    var sLnk, sType, sFld;
    sLnk = document.getElementById('lnkPaginazione_' + strIDLink).value;
    sType = document.getElementById('ordType_' + strIDLink).value;
    sFld = document.getElementById('ordField_' + strIDLink).value;
    sLnk += '&paginaContenuto=' + iPagina + '&wbCampoOrdinamento=' + sFld + '&wbTipoOrdinamento=' + sType ;
    location.href = sLnk;
}

function apriMappa(filtro,tipoFiltro, objLink)
{
    if (!objLink) {objLink=document.getElementById('linkApriMappaGruppo')};
    objLink.href='creaMappa.asp?filtro=' + filtro + '&tipofiltro=' + tipoFiltro;
    return hs.htmlExpand(objLink, { contentId: 'bloccoMappe', objectType: 'iframe', objectWidth: 700, objectHeight: 650} );
}

function apriindirizzo(sUrl) {
    return apriIndirizzo(sUrl);
}
function apriIndirizzo(sUrl) {
    disabilitaPagina(true);
    displayPopup(Lang_JS11);
    setTimeout(function() { location.href = sUrl; displayPopup(Lang_JS11); }, 100);
}

function AJAX(pagina, onComplete ) {
 var ajax_r
 // per l’oggetto nativo XMLHttpRequest
 if (window.XMLHttpRequest) {
  ajax_r = new XMLHttpRequest();
  ajax_r.onreadystatechange = function() {riceviAJAX(ajax_r,onComplete) };
  ajax_r.open("GET", pagina, true);
  ajax_r.send(null);
 // per IE
 } else if (window.ActiveXObject) {
  ajax_r = new ActiveXObject("Microsoft.XMLHTTP");
  if (ajax_r) {
  ajax_r.onreadystatechange = function() {riceviAJAX(ajax_r,onComplete) };
   ajax_r.open("GET", pagina, true);
   ajax_r.send();
  }
 }
}

function riceviAJAX(strm,onComplete) {
 var strRes;
 var arrValori;
 if (strm.readyState == 4) {
     strRes = strm.responseText;
     return onComplete(strRes);  
 }
}

// --------- filtro le combo via AJAX ---------------------
var timAjaxFiltra,fileCallAjaxCB,idTestoAjaxCB,idComboAjaxCB
function ajaxFiltraCombo(oDa,idCb,azione,valoreSelezionato,fileASP)
{
    clearTimeout(timAjaxFiltra);
    curComboAjax=document.getElementById(idCb);
    var pagina;
    fileCallAjaxCB='ajaxAzioni.asp';
    if (typeof(fileASP) !='undefined') {fileCallAjaxCB=fileASP;}
    if(fileCallAjaxCB.indexOf('?') < 0) {fileCallAjaxCB =fileCallAjaxCB + '?a=a'}
    fileCallAjaxCB=fileCallAjaxCB + '&azione=' + azione + '&default=' + valoreSelezionato;
    idTestoAjaxCB=oDa.id;
    idComboAjaxCB=idCb;
    timAjaxFiltra = setTimeout('eseguiAjaxFiltra()',800)
}
function eseguiAjaxFiltra()
{
    //alert(fileCallAjaxCB + '&filtro=' + document.getElementById(idTestoAjaxCB).value);
    if (curComboAjax) { AJAX(fileCallAjaxCB + '&filtro=' + document.getElementById(idTestoAjaxCB).value, riceviAjaxFiltra )     }
}
function riceviAjaxFiltra(aa)
{
    updateComboOptions(document.getElementById(idComboAjaxCB),aa)
}
//----------------------------------------------------------------

function updateComboOptions(obj,sVal)
{
    if (GLOBAL_DebugAttivo == '1') { prompt(sVal, sVal) }
    //alert(sVal);
    // sVal deve essere del seguente formato: "Opzione1[1]|Opzione2[2]selected|Opzione3[3]"
    if (sVal.length<3) {return ;}
	
	var mVal=sVal.split('|');
    var iJ,opt,idx,valu,selIndex;
    try {
	obj.options.length=0;
    selIndex=0;
    for (iJ=0; iJ<=mVal.length -1; iJ++)
     {
        if(mVal[iJ].length>2)
        {
            opt=document.createElement('option');
            if (mVal[iJ].indexOf('selected')>0) {selIndex=iJ;}
            idx=mVal[iJ].indexOf('[');
            opt.text=mVal[iJ].substr(0,idx) ;
            valu=mVal[iJ].substr(idx+1);
            valu=valu.substr(0,valu.indexOf(']') );
            opt.value=valu;
            try
                { obj.add(opt, null);}
            catch(ex)
                {obj.add(opt);} 
        }
      } 
     try {obj.selectedIndex=selIndex;} catch(ex) {}
	}
	catch(ee)
	{alert(ee.message + '---->>>' + obj)}
}

//--------- funzioni di validazione dati ------------------------------------
function validaValoreCampo(obj,lMin,lMax,TipoDati,nomeCampo,bRequired)
{
	var strV,sErr;
	sErr='';
	strV=obj.value;
	if (TipoDati.toLowerCase() == 'sinoseleziona')
	{
		if (obj.selectedIndex==0) {sErr=sErr + Lang_JS23;}    // Selezionare una voce 
	}
	
	if (TipoDati.toLowerCase() == 'checkbox' && bRequired==true)
	{
		if (obj.checked==false) {sErr=sErr + Lang_JS23; lMin=0;lMax=0;} //Selezionare una voce
	}
	
	if (lMin >0 && strV.length < lMin) {sErr=Lang_JS20.replace('$1$',lMin).replace('$2$',nomeCampo); };  //inserire almeno n caratteri per il campo...
	if (lMax >0 && strV.length > lMax) {sErr=sErr + Lang_JS21.replace('$1$',lMax).replace('$2$',nomeCampo);}; // inserire massimo n caratteri per il campo...
	if (TipoDati.toLowerCase() == 'numerico' || TipoDati.toLowerCase() == 'intero')
	{
		var espr= new RegExp("[. a-z.\/.\-]")
		if (espr.test(strV)) {sErr=sErr + Lang_JS22;}  //solo valori numerici
	}
	
	if (sErr !='')
	{
		
		mostraAvvisoFisso(obj,sErr);
		
		//obj.style.color='red'
		//obj.style.backgroundcolor='#FFFFFF';
		//alert(sErr);
		//obj.focus()
		return false;
	}
	return true;
}

function validaCaratteri(stringa,CharOK)
{
    var i, z, carattere, stato;
    for (z=0;z<stringa.length;z++)
        {   
            stato='ko';
            carattere=stringa.substring(z,z+1);
	    for (i=0;i<CharOK.length;i++)
                {
                    if (carattere.toLowerCase()==CharOK.toLowerCase().substring(i,i+1)) {stato='ok';} ;                
                }
            if(stato=='ko') {alert('Carattere \'' + carattere + '\' non consentito.') ; return false; }
        }
    return true;
}

function escapeHTML(str) {
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
};

function disabilitaPagina(verofalso) {
    //crea un blocco grigio semitrasparente nella pagina    
    var obj;
    obj=document.getElementById('bloccoDisabilitaPagina');
    if (!obj) {
        obj=document.createElement('div');
        obj.id='bloccoDisabilitaPagina';
        obj.className='bloccoNascondiRisultatiRicerca';
        obj.style.display='none';
        document.body.appendChild(obj);
        paginaDisabilitata = false ;        
    }
    obj.style.display='none';
    if (verofalso) {
        obj.style.position='absolute';
        obj.style.width='100%';
        obj.style.height=6000;
        obj.style.zIndex=50;
        obj.style.top=0;
        obj.style.left=0;
        obj.style.display = 'block';
        paginaDisabilitata = true;
    }

}


// -------- funzioni per visualizzare tooltip ---------------------//
var x,y,timer2;
function mostratool(text,larghezza, tipo){
	if(text=="") return;
	
	var inizio, fine;
	inizio="<table width=\"" + larghezza + "\" class=\"TabellaTooltip\" border=\"0\" ><tr><td>";
	fine="</td></tr></table>";
	if (tipo=="immagine")
		{
			//........caricare l'immagine, ricavare le dimensioni e impostare il frame alle dimensioni volute..........
			inizio="<iframe scrolling=\"no\" id=\"iframeTooltip\" class=\"TabellaTooltip\" width=\"" + larghezza + "\" style=\"z-index:15000;\" src=\"vuota.htm\">" ;
			fine="</iframe>";
			document.getElementById('BloccoTooltip').innerHTML=inizio + fine ;
			var s, frameTT,hImmagine;
			frameTT=document.getElementById('iframeTooltip')
			
			s="<html><head><style type=\"text/css\"> body { margin-left: 0px; 	margin-top: 0px; 	margin-right: 0px; 	margin-bottom: 0px;  background-color: #666666; } </style></head>" ;
			s=s + "<body>" ;
			s=s + "<img id=\"immagineTooltipPreview\" src=\"" + text +"\" border=\"0\" width=\"" + larghezza + "\">"
			s=s + "</body></html>"
			
			frameTT.contentWindow.document.write(s);
			hImmagine=frameTT.contentWindow.document.getElementById('immagineTooltipPreview').height;
			if (hImmagine=="" || hImmagine=='nothing' || hImmagine > 100) hImmagine=80;
			frameTT.style.height=hImmagine;

		} else {
			
			var obj;
			obj = document.getElementById('BloccoTooltip');
			if (!obj) {
			    obj = document.createElement('div')
			    obj.id = 'BloccoTooltip';
			    obj.style.display = 'none';
			    obj.style.border = '1px solid #000000';
			    obj.style.backgroundColor = '#FCFCFC';
			    document.body.insertBefore(obj, document.body.childNodes[0])
			}
			obj.style.width = parseInt(larghezza) + 25;
			obj.innerHTML = ('<table border="0" cellpadding="0" cellspacing="0" style="width:' + larghezza + '" class=""tabellaTooltip""><tr><td><span class="testoTooltip">' + text + '</span></td></tr></table>');
			obj.style.position = 'absolute';
			obj.style.left = x + 10;
			obj.style.top = y + 5;
			obj.style.display = 'block';
			
		}

	 MostraToolTipOK(larghezza);
}

function MostraToolTipOK(larghezza) {
    var obj;
    obj = document.getElementById('BloccoTooltip');
	if (x + larghezza + 10 > document.body.clientWidth) { x=x - larghezza -10 };
	obj.style.visibility="visible";
	obj.style.pixelLeft=x + 3;
	obj.style.pixelTop=y + 6;
	obj.style.left=x + 3;
	obj.style.top = y + 6;
	obj.style.zIndex = 2000;
	timer2=setTimeout("MostraToolTipOK(" + larghezza + ")",10);
}

function nasconditool(){
	document.getElementById('BloccoTooltip').style.visibility="hidden";
	clearTimeout(timer2);
}

function seleziona(o,posIniz)
{
    var lung,range;
    lung=o.value.length;
    if (lung>1 && posIniz <lung)
    {
        range=o.createTextRange();        
	    range.findText(o.value.substr(1));
	    range.select();
    }    
}
function testoSelect(obj)
{
    return obj.options[obj.selectedIndex].text;
}

function getMousePos(e){
	if (!e)
		var e = window.event||window.Event;
	if('undefined'!=typeof e.pageX){
		x = e.pageX;
		y = e.pageY;
	} else {
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
}
    //window.status = 'X:' + x + '  Y:' + y;
}

// You need to tell Mozilla to start listening:
if(window.Event && document.captureEvents)
 	document.captureEvents(Event.MOUSEMOVE);
// Then assign the mouse handler
document.onmousemove = getMousePos;

// -------- fine funzioni tooltip ---------------------//


function acquistaContenuto(objForm)
{
	if (confirm('Aggiungere il prodotto al carrello ordini?'))
		{
			
			objForm.azione.value="addcontenutocarrello";
			objForm.submit();
		}
}
function carrelloContenuto(objForm)
{
	objForm.azione.value="mostracontenutocarrello";
	objForm.submit();
}

function zoomImg(img)
{
	nw=window.open('zoomimage.asp?img=' + img,'mwin','titlebar=0,toolbar=no,status=0,menubar=no,scrollbars=no,width=20,height=20,resizable=yes,left=' + screen.width/2 + ',top=' + screen.height/2 );
	nw.focus();
}


// JavaScript Document
/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var menuwidth='165px' //default menu width
var menubgcolor='lightblue'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6) dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!=""){
	dropmenuobj.widthobj=dropmenuobj.style
	dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover") obj.visibility=visible
	else if (e.type=="click") obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
mostraNascondiCombo(false);
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
mostraNascondiCombo(true);
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function mostraNascondiCombo(stato)
{
	var vis, Combo;
	vis='hidden';
	if(stato) {vis='visible'};
	try
	{
		Combo=document.body.getElementsByTagName('select');
		for(i=0;i<Combo.length;i++)
		{
			try
			{ Combo[i].style.visibility=vis; }
			catch(ex)
			{		}
		}
	}
	catch(ex)
	{ }
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


function TestoDaHtml(s)
{
    var v;
    v=s;
    if (s.indexOf('<') > 0) v=s.substring(0,s.indexOf('<'));
    if (s.indexOf('>') > 0) v=v + s.substring(s.indexOf('>')+1);
    if (v.indexOf('<') > 0) v=TestoDaHtml(v) ;
    return v;
}



//**********************************                  ***********/////

function MostraRigaSottomenu(oggetto,idSottomenu,idPlace)
{
    var blocco,aa;
    for(i=0;i<20;i++)
       {
         try
            {
                aa='';
                aa=document.getElementById('TDMenuTop' + i).className;
                if(aa.toLowerCase().indexOf("selezionato")>0) {aa=aa.toLowerCase().replace("selezionato","")}
                document.getElementById('TDMenuTop' + i).className=aa;
                document.getElementById('PlaceHolderSottomenu' + i).style.display='none';                                
            }
            
            catch(e)
            {  
            }
        }
    blocco=document.getElementById(idSottomenu).innerHTML;
    document.getElementById(idPlace).innerHTML=blocco;
    document.getElementById(idPlace).className='PlaceHolderSottomenuAttivo';
    aa=document.getElementById('TDMenuTop' + oggetto).className;
    if(aa.toLowerCase().indexOf("selezionato")<=0) {aa=aa + 'Selezionato'}
    document.getElementById('TDMenuTop' + oggetto).className=aa;
    document.getElementById(idPlace).style.display='block';
}

function chiudiPopup() {
    var d;
    d=document.getElementById('CMS_BodyPopup');
    if (d) d.style.display='none';
    return false;
    
}
function displayPopup(str,mW,mH)
{
    var d;
    var bW, bH,obj,xPos,yPos;
    bW=parseInt(document.body.clientWidth);
    bH=parseInt(document.body.clientHeight);
    if (!mW) mW=400;
    if (!mH) mH=130;
    var scrollAttuale=document.body.scrollTop;
    xPos=parseInt(bW/2) - parseInt(mW/2) + parseInt(document.body.scrollLeft);
    yPos=parseInt(bH/2) - parseInt(mH/2) + parseInt(document.body.scrollTop);
    
    d=document.getElementById('CMS_BodyPopup');
    if (!d) {
		d=document.createElement('div')
		d.id='CMS_BodyPopup';
		d.style.display='none';
		d.style.border='1px solid #000000';
		d.style.backgroundColor='#FCFCFC';
		document.body.insertBefore(d,document.body.childNodes[0])			
	}
	d.cssClass='divPopupFisso';
	str = '<div class="titoloPopupFisso" style="width:' + mW + 'px;" >' +
        '<a href="#" onclick="return chiudiPopup();" >CHIUDI</a></div>' + 
        '<div style="width:' + mW + 'px;height:' + mH + 'px;display:block;float:left;padding:4px;">' + str + '</div>';
    d.innerHTML=str;
    
    //window.onscroll=function() {document.body.scrollTop=scrollAttuale;}
    d.style.width=mW + 'px';
    d.style.height=mH + 'px';
    d.style.zIndex=9000;
    d.style.position='absolute';
    d.style.top=yPos; //parseInt(bH/2) - parseInt(mH/2);
    d.style.left=xPos; //parseInt(bW/2) - parseInt(mW/2);
    d.style.display='block';
    return true;
}

function espandiHS(objLink,Larghez,Altez,Titolo,NomeDiv,bIframe,bDisabilitaPagina)
{
	if (NomeDiv=='' || !NomeDiv) {NomeDiv='highslideIframePrincipale';}
	//if (NomeDiv=='highslideIframePrincipale') {document.getElementById('titoloPopupIframeComune').innerHTML=Titolo;}
    if (bDisabilitaPagina) disabilitaPagina(true);
	if (bIframe==false)
	{ return hs.htmlExpand(objLink, { contentId: NomeDiv, objectWidth: Larghez, objectHeight: Altez, allowHeightReduction: true, allowWidthReduction: true, preserveContent: true }); }
	else
	{ return hs.htmlExpand(objLink, { contentId: NomeDiv, objectType: 'iframe', objectWidth: Larghez, objectHeight: Altez, objectLoadTime: 'before', allowHeightReduction: true, allowWidthReduction: true, cacheAjax: false, preserveContent: false }); }
	
}

var curObjUserid;
function verificaUserid(obj,conferma)
{
    curObjUserid=obj;
    if (obj.value=='' && conferma==true) {alert(Lang_JS07);return false;}
    if (conferma==true) {AJAX('AJAXazioni.asp?azione=verificauserid&valore=' + obj.value, esitoVerificaUserid )}
    if (conferma==false) {AJAX('AJAXazioni.asp?azione=verificauserid&valore=' + obj.value, esitoNascostoVerificaUserid )}
}
function esitoVerificaUserid(aa)
{
    if (aa=='false') alert('Attenzione!!\n\nLa userid scelta è già utilizzata.');
    if (aa=='true') alert('La userid scelta è valida e disponibile.');    
}
function esitoNascostoVerificaUserid(aa)
{
    if (aa=='false') {curObjUserid.style.color='#FF0000';alert('Attenzione!!\n\nLa userid scelta è già utilizzata.');}
    if (aa=='true') {curObjUserid.style.color='#000000';}
}



// ----------- gestione tooltip per validazione form ---------------
var maxTooltipZIndex, tooltipCounter;
maxTooltipZIndex=9999999;
tooltipCounter = 1

function mostraAvvisoFisso(obj,msg)
{
    maxTooltipZIndex=maxTooltipZIndex + 1;
    tooltipCounter=tooltipCounter + 1;
    var coords = {x: 0, y: 0}, xPos,yPos,objW,marginL;
    coords=getPageCoords(obj);
    xPos=coords.x - 290;
    yPos=coords.y - 15;
    objW=0;marginL='0';
    
    if (xPos < 300) {
        // ricavo la larghezza dell'oggetto---------
         try      { objW=obj.style.width; }
         catch(a) {objW=0}
         if (objW==0) {
             try      { objW=obj.width; }
             catch(a) {objW=0}
         }
         if (typeof(objW)=='undefined' || objW=='') objW=50;
         xPos=coords.x + parseInt(objW.toString().toLowerCase().replace('px','')) + 10;
         marginL='25px';
    }
    var newDiv = document.createElement("div");
    var closeDiv = document.createElement("div");
    newDiv.className='AvvisoFisso';
    newDiv.Id='tooltip' + tooltipCounter;
    newDiv.onclick=function() {maxTooltipZIndex=maxTooltipZIndex + 1;this.style.zIndex=maxTooltipZIndex;closeDiv.style.zIndex=maxTooltipZIndex;}
    newDiv.style.position='absolute';
    newDiv.style.width='290px';
    newDiv.style.height='45px';
    newDiv.style.left=xPos;
    newDiv.style.top=yPos;
    if (objW==0) newDiv.style.background='url(../images/AvvisoFisso_45.png) no-repeat';
    if (objW !=0) newDiv.style.background='url(../images/AvvisoFisso_45SX.png) no-repeat';
    newDiv.style.zIndex=maxTooltipZIndex;
    newDiv.style.display='block';
    
    
    closeDiv.style.position='absolute';
    closeDiv.style.width='12px';
    closeDiv.style.height='12px';
    closeDiv.style.fontSize='9px';
    closeDiv.style.textAlign='center';
    if (objW==0) closeDiv.style.left=xPos +5 ; 
    if (objW !=0) closeDiv.style.left=xPos + 328; 
    closeDiv.style.top=yPos - 2;
    closeDiv.style.background='url(../images/AvvisoFisso_close.png) no-repeat';
    closeDiv.style.cursor='pointer';
    closeDiv.style.zIndex=maxTooltipZIndex;
    closeDiv.onclick=function() {newDiv.style.display='none';this.style.display='none';}
    closeDiv.innerHTML='&nbsp;';
    
    var s='';
    s=s + '<div style="float:left;position:relative;width:260px;margin-left:' + marginL + ';height:27px;overflow-y:auto;">' + msg + '</div>';
    newDiv.innerHTML=s;
    document.body.appendChild(newDiv);
    document.body.appendChild(closeDiv);
    //-------------------------------------------------------------------------------
    //---- Aggiungo la funzione per nascondere il tooltip all'oggetto  --------------
    //-------------------------------------------------------------------------------
    if(window.addEventListener){ // Mozilla, Netscape, Firefox
      obj.addEventListener('change', function() {newDiv.style.display='none';closeDiv.style.display='none';}, false);      
    } else { // IE
      obj.attachEvent('onchange', function() {newDiv.style.display='none';closeDiv.style.display='none';});      
    }
    //-------------------------------------------------------------------------------
    if (document.body.scrollTop>yPos - 50) {document.body.scrollTop=yPos -50;}
}



function getPageCoords(element) { // thanks to 'Martin Honnen' for this function 
    var coords = {x: 0, y: 0}; 
    while (element) { 
    coords.x += element.offsetLeft; 
    coords.y += element.offsetTop; 
    element = element.offsetParent; 
    } 
    return coords; 
} 


 function arrotonda(decimalpositions)
{
    var n;
	var i = this * Math.pow(10,decimalpositions);
    i = Math.round(i);
    n=i / Math.pow(10,decimalpositions);
	if (n.toString().indexOf('.') <0 )
	 {return n + '.00';
	 }
	else
	{
	    if (n.toString().indexOf('.') == n.toString().length -2) {return n.toString() + '0'; }
	    return n;
	}
}
Number.prototype.arrotonda = arrotonda;


function stringLeft(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function stringRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}



