
/*******************************************
* FUNZIONI MACROMEDIA per show/hide layers *
********************************************/
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;
		}
	}
}

aimsDHTMLPresent=true;

// Prende in ingresso un url e restituisce un altro url in formato corretto per lo streaming
function createUrl(urlComplete) {
	var result = urlComplete.split("/");
	var file = '';
	for(i=0;i<result.length;i++) {
		if(i == (result.length-1)) file = result[i];
	}
	var index = urlComplete.indexOf(file);
	var url = urlComplete.substring(0,index-1);
	
	return url + '?file_name=' + file;
}

// Restituisce l'url per l'overview
function getOverviewUrl(streaming,caching,completeUrl) {
	var url = '<img id="overviewImage" name="theImage" hspace="0" vspace="0" width="167" height="105" ';
	if(streaming == 'true' && caching == 'false') url += 'src=' + createUrl(completeUrl) + ' />';
	else url += 'src=' + completeUrl + ' />';
	return url;
}
		
// Restituisce il nome del layer correntemente attivo
function getActiveLayerName() {
	// Id del layer attivo
	var activeLayerId = parent.PostFrame.document.theForm.active_layer.value;
	return 'mapLayer_' + activeLayerId;
}

// Restituisce il nome del layer correntemente attivo
function getInactiveLayerName() {
	// Id del layer inattivo
	var activeLayerId = parent.PostFrame.document.theForm.active_layer.value;
	var inactiveLayerId = (activeLayerId == 1) ? 2 : 1;
	return 'mapLayer_' + inactiveLayerId;
}

// Esegue lo switch tra i layers della mappa
function switchActiveLayer() {
	// Layer attivo
	var activeLayer = parent.MapFrame.document.getElementById(getActiveLayerName());
	// Layer inattivo
	var inactiveLayer = parent.MapFrame.document.getElementById(getInactiveLayerName());
	// Visualizzo il layer (nel caso di pan)
	showLayer(getInactiveLayerName());
	// Aggiorno l'id
	var activeLayerId = parent.PostFrame.document.theForm.active_layer.value;
	var inactiveLayerId = (activeLayerId == 1) ? 2 : 1;
	parent.PostFrame.document.theForm.active_layer.value = inactiveLayerId;
	// Imposto la corretta sovrapposizione
	activeLayer.style.zIndex = 0;
	inactiveLayer.style.zIndex = 1;
}

function createLayer(name, inleft, intop, width, height, bgcolor, zindex, visible, content) {
	
	  var cheLayer;
	  
	  cheLayer = '<' + layerTag 
	  			+ ' id="' + name; 
	  
	  if(isNav4){
	  	cheLayer +=  '" left="' + inleft 
							+ '" top="' + intop 
							+ '" width="' + width 
							+ '" height="' + height 
							+ '" visibility="' + (visible ? 'visible' : 'hidden')
							+ '" bgcolor="' + bgcolor
							+ '" z-index="' + zindex
							+ '">';
	  } 
	  else{
	  	cheLayer +=   '" style="position:absolute'
					+ ';left:' + inleft 
					+ 'px;top:' + intop 
					+ 'px;width:' + width
					+ 'px;height:'+ height;
		var pattern=new RegExp('/\D/');			
		if(pattern.test(height.toString()))
		{
			cheLayer += ';visibility:' + (visible ?'visible':'hidden');
		}
		else
		{
			cheLayer += 'px;visibility:' + (visible ?'visible':'hidden');
		}

					//+ 'px;visibility:' + (visible ?'visible':'hidden') 
					cheLayer += ';background:' + bgcolor
					+ ';z-index:' + zindex
					+ ';">';
	  }
	  
	  cheLayer += 	content + '</' + layerTag + '>';
	  parent.MapFrame.document.write(cheLayer);
}

function getLayer(name) {

	var cheStyle = null;	
	if(isNav4){cheStyle = parent.MapFrame.document.layers[name];}
	else if(isNav){cheStyle = parent.MapFrame.document.getElementById(name).style;}
	else if(isIE){cheStyle = parent.MapFrame.document.all[name].style;}	
	return cheStyle;
	
}
		
function isVisible(name) {
	  var cheLayer = getLayer(name);
	  if ((cheLayer.visibility == "show") || (cheLayer.visibility == "visible")){return true;}
	  else{return false;}
}

function moveLayer(name, x, y) {	
  	var cheLayer = getLayer(name);		
  	if (isNav4){
    	cheLayer.left = x;
   		cheLayer.top  = y;
	}
	else {
    	cheLayer.left = x + "px";
   		cheLayer.top  = y + "px";
  	}
//La parte di codice sottostante ? un aggiunta che non ? propriamente corretta.
var wmsLayerPrincipale=parent.MapFrame.document.getElementById('wmsLayer');	
	if(wmsLayerPrincipale)
	for (var i=0; i<wmsLayerPrincipale.getElementsByTagName('div').length; i++) {
		var cheLayer=wmsLayerPrincipale.getElementsByTagName('div')[i].style;   			 	
  	if (isNav4){
    	cheLayer.left = x;
   		cheLayer.top  = y;
	}
	else {
    	cheLayer.left = x + "px";
   		cheLayer.top  = y + "px";
  	}
   }
   
 wmsLayerPrincipale=parent.MapFrame.document.getElementById('mapLayer_evidenzia');	
	if(wmsLayerPrincipale){
		var cheLayer=wmsLayerPrincipale.style; 		 	
	  	if (isNav4){
	    	cheLayer.left = x;
	   		cheLayer.top  = y;
		}
		else {
	    	cheLayer.left = x + "px";
	   		cheLayer.top  = y + "px";
	  	}
	}
}

function setLayerBackgroundColor(name, color) {
  	var cheLayer = getLayer(name);
 	if (isNav4){cheLayer.bgColor = color;}
	else{cheLayer.background = color;}
}

function hideLayer(name) {
  	var cheLayer = getLayer(name);		
  	if (isNav4){cheLayer.visibility = "hide";}
	else{cheLayer.visibility = "hidden";}
}

function showLayer(name) {
  	var cheLayer = getLayer(name);
  	if (isNav4){cheLayer.visibility = "show";}
	else{cheLayer.visibility = "visible";}
}

// ridisegna il layer in basse alle coordinate clipleft, cliptip, clipright, clipbottom
// Not working with Mozilla Milestone 12 (Nav5)
function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
	var cheLayer = getLayer(name);
	if (isNav4) {					
		cheLayer.clip.left   = clipleft;
		cheLayer.clip.top    = cliptop;
		cheLayer.clip.right  = clipright;
		cheLayer.clip.bottom = clipbottom;
	}
	else{
		cheLayer.top = parseInt(cheLayer.top.substring(0,cheLayer.top.indexOf("px"))) + cliptop;
		cheLayer.left = parseInt(cheLayer.left.substring(0,cheLayer.left.indexOf("px"))) + clipleft;
		cheLayer.width = clipright - clipleft;
		cheLayer.height = clipbottom - cliptop;
	}
	
}

function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {
	var cheLayer = getLayer(name);
	if (isNav4) {
		cheLayer.clip.left   = clipleft;
		cheLayer.clip.top    = cliptop;					
		cheLayer.clip.right  = clipright;
		cheLayer.clip.bottom = clipbottom;
	}
	else{
		cheLayer.top = cliptop + "px";
		cheLayer.left = clipleft + "px";
		cheLayer.width = clipright - clipleft;
		cheLayer.height = clipbottom - cliptop;
	}
}

function boxIt(theLeft,theTop,theRight,theBottom) {
	
	clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
	clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
	clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
	clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);
	
	showLayer("zoomBoxTop");
	showLayer("zoomBoxLeft");
	showLayer("zoomBoxRight");
	showLayer("zoomBoxBottom");
	
}

// verifica l'eistenza di un layer 
function hasLayer(name) {
	var result = false;
	if (isNav4) {
		if (parent.MapFrame.document.layers[name]!=null) result=true;
	}  else if (isIE) {
		if (eval('parent.MapFrame.document.all.' + name)!=null) result=true;
	} else if (isNav) {
		var theElements = parent.MapFrame.document.getElementsByTagName("DIV");
		var theObj;
		var j = -1;
		for (i=0;i<theElements.length;i++) {
			if (theElements[i].id==name) result=true;
		}
    }
	return result;
}

function mostraFinestraErrore(TitoloFinestra, TitoloErrore, TestoErrore){
	   var infoStatusBar = parent.MapFrame.infoStatusBar;
		// Imposto il titolo della finestra
		infoStatusBar.setTitle(TitoloFinestra);
		// Cancello l'info gi? presente
		infoStatusBar.setInfoTitle("");
		// Imposto il titolo informativo
		infoStatusBar.setInfoTitle(TitoloErrore);
		infoStatusBar.showTitle();
		var errText='<div class="infoItemBig textLeft" style="float:left;margin:5px 0px 5px 0px;padding:0px 0px 0px 0px;">' +
						'<div class="infoText textLeft inline" style="float:left;width:250px;">' +
							TestoErrore+
							'</div>' +
						'</div>';
    	// Imposto il contenuto
		infoStatusBar.setInfoBody(TestoErrore,200,true);		
		// Imposto il valore e la action del pulsante
		infoStatusBar.setInfoButton('Chiudi','parent.MapFrame.dd.elements.infoStatusBarLayer.hide()');		
		// Visualizzo la finestra
		infoStatusBar.showAll(true);
		parent.MapFrame.dd.elements.infoStatusBarLayer.maximizeZ();
}


