﻿// JScript File
/* 
Inverte lo stato del Layer passato, aggiorna l'aspetto del link e dell'icona.
Se il Layer non esiste notifica l'errore con un allert.
Se bCloseOther è true, chiude tutti gli altri Layer indipendentemente dal loro stato, 
aggiornando l'aspetto sia del link che dell'icona
*/
/* 
Nasconde il Layer indicato dall'indice iCnt.
Se nell'array è presente un Layer sbagliato, notifica l'errore con un allert.
*/
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function _AT_HideLayer(iCnt, Contenuti, Links){
	if (isNaN(iCnt) || (iCnt > Contenuti.length)){
		alert('Indice ' + iCnt + ' non numerico o non trovato');
		return;
	} else {
	
		if ((MM_findObj(Contenuti[iCnt]))!=null) { 
			//if (objLayer.style) {objLayer = objLayer.style;}
			//objLayer.display = 'none'; 
			MM_findObj(Contenuti[iCnt]).style.display = "none"
			MM_findObj(Links[iCnt]).className = " "
	
		} else {
			alert('Oggetto ' + Contenuti[iCnt] + ' non trovato.');
			return;
		}
	}
}

/* 
Scorre l'array del Layer e li nasconde tutti.
Se nell'array è presente un Layer sbagliato, notifica l'errore con un allert.
*/
function AT_HideLayers(Contenuti, Links){

	for (iCnt = 0; iCnt < Contenuti.length; iCnt++){
		_AT_HideLayer(iCnt,Contenuti, Links)
	}
}

/* 
Inverte lo stato del Layer passato, aggiorna l'aspetto del link e dell'icona.
Se il Layer non esiste notifica l'errore con un allert.
Se bCloseOther è true, chiude tutti gli altri Layer indipendentemente dal loro stato, 
aggiornando l'aspetto sia del link che dell'icona
*/
function AT_ChangeStatus(aLayer, aLink, Contenuti, Links, bCloseOther, bCloseSelf){

//	if ((objLayer=MM_findObj(aLayer))!=null) { 
//		if (objLayer.style) {objLayer = objLayer.style; }
//		objLayer.display = (objLayer.display =='none') ? '':'none'; 
//		
//		if (((objLink=MM_findObj(aLink))!=null)  ) { 
//			objLink.className = (objLayer.display =='none') ? STYLE_GRUPPOCHIUSO: STYLE_GRUPPOAPERTO;
//			
//		} else {
//			alert('Oggetto ' + aLink + ' oppure '  +  '  non trovato.');
//			return;
//		}

//	} else {
//		alert('Oggetto ' + aLayer + ' non trovato.');
//		return;
//	}
    
    
        if (MM_findObj(aLayer) != null)
        {
            if ( MM_findObj(aLayer).style.display == "none")
            {
                MM_findObj(aLayer).style.display = ""
                MM_findObj(aLink).className = "selected"
            }
            else
            {
                if(bCloseSelf)
                {
                 MM_findObj(aLayer).style.display = "none"
                 MM_findObj(aLink).className = " "
                }
                 
            }
            
        }


		// Imposta il campo hidden per mantenere lo stato
		// in caso di postback (salvataggio ad esempio)
		/*
		MM_findObj('TxtCurrentLayerId').value = -1;
    	if (objLayer.display ==''){
			for (iCnt = 0; iCnt < lstContenuti.length; iCnt++){
				if (lstContenuti[iCnt] == aLayer) 
					{
					MM_findObj('TxtCurrentLayerId').value = iCnt;
					break
					}
			}
		}
		*/  

	
	if (bCloseOther) {
		for (iCnt = 0; iCnt < Contenuti.length; iCnt++){
		    if (Contenuti[iCnt] != aLayer) _AT_HideLayer(iCnt,Contenuti, Links)
		}
	}
	
}
/* ========== Fine Gestione Layer e apertura / chiusura ========== */
