
function SettaTemaRicerca() { 
	//alert(document.Viewer.m_Scalemax);
	document.Viewer.m_Scalemax=250;
    document.SearchTree.SetSearchTheme(document.MAPPA.TEMA_RICERCA.value); 
//    alert(document.MAPPA.TEMA_RICERCA.value);
    
    /*if (document.MAPPA.TEMA_RICERCA.value == "PARTICELLE")
    {
        document.SearchTree.SetSearchAttrib2("FOGLIO","PARTICELLA"); 
        document.SearchTree.SetSearchFeaturePolygon();         
    }
    if (document.MAPPA.TEMA_RICERCA.value == "FABBRICATO")
    {
        document.SearchTree.SetSearchAttrib1("FABBRICATO"); 
        document.SearchTree.SetSearchFeaturePolygon();         
    }
    if (document.MAPPA.TEMA_RICERCA.value == "FOGLI")
    {
        document.SearchTree.SetSearchAttrib1("FOGLIO"); 
        document.SearchTree.SetSearchFeaturePolygon();         
    }
    if (document.MAPPA.TEMA_RICERCA.value == "GRAFOSTRDALE")
    {
        document.SearchTree.SetSearchAttrib1("INDIRIZZO"); 
        document.SearchTree.SetSearchFeatureArc();         
    }*/
    if (document.MAPPA.TEMA_RICERCA.value == "Confini Comunali")
    {
        document.SearchTree.SetSearchAttrib1("COMUNE"); 
        document.SearchTree.SetSearchFeaturePolygon();   
    }
    if (document.MAPPA.TEMA_RICERCA.value == "Catasto - Particelle")
    {
        document.SearchTree.SetSearchAttrib2("NUM_FOGLIO","N_PART");
        document.SearchTree.SetSearchFeaturePolygon();         
    }

}
    

function OnIdentify(ThemeName, FeatureType, FeatureID)
{
      
        //alert(ThemeName);
        var url='';
        var f;
        var p;

        
        //MCS : Gestione generale del campo link per aprire un file collegato
        for (i=0; i < document.Viewer.IdentifyGetAttributeCount() ;i++)
        {
            if (document.Viewer.IdentifyGetAttributeName(i) == "Link") {
                url="istanze/"+ document.Viewer.IdentifyGetAttributeValue(i)+".htm";
                //alert(document.Viewer.IdentifyGetAttributeValue(i));
            }
        }       
        if (url != "")
            document.open(url,"_blank","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=550,directories=no");

        if (ThemeName == "Catasto - Particelle" )
        {
            for (i=0; i < document.Viewer.IdentifyGetAttributeCount() ;i++)
            {
                if (document.Viewer.IdentifyGetAttributeName(i) == "CC") {
                    f=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }
                if (document.Viewer.IdentifyGetAttributeName(i) == "N. Particella") {
                    p=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }    
            }
            
            
            if ((f != "")  )
            {
                f=f*1;
                url="catasto/index.asp?f=" + f;
                if ((p != "")  )
                {
                    url=url+"&p=" + p;
                } 
            }      
            else
                url="";         
            if (url != "")
                if (confirm('Vuoi vedere i dettagli della Particella?')) {
                document.open(url,"_blank","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=550,directories=no");
            }       
                        
        } 
        
        //MCS ELIMINATO
        /*
        //alert(url);            
        //Ambiti Normativi
        if (ThemeName == "Ambiti Normativi" )
        {
            for (i=0; i < document.Viewer.IdentifyGetAttributeCount() ;i++)
            {
                if (document.Viewer.IdentifyGetAttributeName(i) == "Link") {
                    url="schede/"+ document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }
            }       
            if (url != "")
                document.open(url,"_blank","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=550,directories=no");
        }    
        
        if (ThemeName == "Civici" )
        {
            for (i=0; i < document.Viewer.IdentifyGetAttributeCount() ;i++)
            {
                if (document.Viewer.IdentifyGetAttributeName(i) == "CODICE_VIA") {
                    codvia=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }
                if (document.Viewer.IdentifyGetAttributeName(i) == "NUM_CIVICO") {
                    civico=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }    
                if (document.Viewer.IdentifyGetAttributeName(i) == "KEY") {
                    key=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }         
            }
             if ((codvia != "")  )
            {
                url="DatiCivico.asp?CODVIA=" + codvia;
                if ((civico != "")  )
                {
                    url=url+"&CIVICO=" + civico;
                } 
                if ((key != "")  )
                {
                    url=url+"&KEY=" + key;
                }         
            }      
            else
                url="";        

            if (url != "")
                if (confirm('Vuoi vedere i dettagli del Civico?')) {
                document.open(url,"_blank","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=550,directories=no");
            }        
        }        
        
        if (ThemeName == "Particelle" )
        {
            for (i=0; i < document.Viewer.IdentifyGetAttributeCount() ;i++)
            {
                if (document.Viewer.IdentifyGetAttributeName(i) == "FOGLIO") {
                    f=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }
                if (document.Viewer.IdentifyGetAttributeName(i) == "PARTICELLA") {
                    p=document.Viewer.IdentifyGetAttributeValue(i);
                    //alert(document.Viewer.IdentifyGetAttributeValue(i));
                }    
            }
            if ((f != "")  )
            {
                url="catasto/index_visualizza.html?f=" + f;
                if ((p != "")  )
                {
                    url=url+"&p=" + p;
                } 
            }      
            else
                url="";         
                if (url != "")
                    if (confirm('Vuoi vedere i dettagli della Particella?')) {
                    document.open(url,"_blank","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=550,directories=no");
                }        
        }   
        //alert(url);            
        */
}

//Gestione delle legende dinamiche
function CambiaTematizzazione(quale,tema,tipo) 
{ 

    legenda(quale,tema,tipo);
    
    /*
	document.Viewer.CustomLegendReset();
	document.Viewer.Redraw();

	document.ThemeBar.CustomLegendReset();
	document.ThemeBar.Redraw();

	if (quale != "-")
	{	
		document.Viewer.CustomLegendAdd(tema+";"+tipo+";" + quale);
		document.Viewer.Redraw();
		document.ThemeBar.CustomLegendAdd(tema+";"+tipo+";" + quale);
		document.ThemeBar.Redraw();
        
	}
	*/
//	document.getElementById("legidframe").src = "";
//	document.getElementById("legidframe").src = "ricalcolalegenda.asp";


}

/* test tematizzazioni */
function legenda(sho,tema,tipo)
{
    /*
      document.viewer.CustomLegendReset();
      document.viewer.CustomLegendAdd("comuni;POLYGON;"+sho);
      document.viewer.Redraw();
    
      document.ThemeBar.CustomLegendReset();
      document.ThemeBar.CustomLegendAdd("comuni;POLYGON;"+sho);
      document.ThemeBar.Redraw();
      document.ThemeBar.CloseAllThemes();
    
     
    document.imgleg.src="http://localhost:2001/legende?user=tutti&pwd=tutti&cmd=lgnd";
     
    window.open("http://localhost:2001/legende?user=tutti&pwd=tutti&cmd=lgnd","_blank");
    */
    
    document.Viewer.BeforeDrawReset();
    document.Viewer.BeforeDrawAddCommand("CUSTOMLEGEND_LOAD "+tema+" " +tipo+ " "+sho);
    document.Viewer.AfterDrawReset();
    document.Viewer.AfterDrawAddCommand("CUSTOMLEGEND_UNLOAD "+tema+" " +tipo);
    document.Viewer.Redraw();
    document.ThemeBar.Redraw();
    document.ThemeBar.CustomLegendAdd(tema+";"+tipo+";" + sho);
     
    //document.imgleg.src="http://localhost:2001/legende?user=tutti&pwd=tutti&cmd=lgnd&cust=comuni;POLYGON;"+sho;
     
    //window.open("http://localhost:2001/legende?user=tutti&pwd=tutti&cmd=lgnd&cust=comuni;POLYGON;"+sho,"_blank");

}


//AGO
function VisAttributi(FeatureID,tipoARCPOLPOLYGON,nometema,sidsessione,urlserver)
{
	/*
	//esempio urlserver = http://webgis.sitweb.it:2001/CMP_PRG_SPVL?user=tutti&pwd=tutti
	var newurl = urlserver + '&cmd=list&sid=' + sidsessione + '&them="' + nometema + '"&feat="' + tipoARCPOLPOLYGON.toUpperCase() + '"&los=1&ltbc="FFFFFF"&ltit=Attributi&ltic="000000"';
	if (myWindow != null)
		myWindow.close();
	if (FeatureID != null)
		if (FeatureID != 0)
			myWindow = window.open(urlserver + '&cmd=sadd&sid=' + sidsessione + '&sel="THEME_SELECTION_BYVALUE |' + nometema + '| ' + tipoARCPOLPOLYGON.toUpperCase() + ' TNSHARCUNIQUEID = |' + FeatureID + '| NEW"' , "myWin", 'toolbar=no'); 
	if (myWindow != null)
		myWindow = window.open(newurl , "myWin", 'toolbar=no');
	else
		myWindow.location.replace(newurl);
	*/
	
		
    var thisdate=getDataUnivoca();

	
	var newurl = urlserver + thisdate + '&cmd=list&sid=' + sidsessione + '&them="' + nometema + '"&feat="' + tipoARCPOLPOLYGON.toUpperCase() + '"&los=1&ltbc="FFFFFF"&ltb=1"&lff="Verdana"&ltit="' + ActiveLayerTreeName + '"&ltis="3"';

	
	
	//VisAttributi_AUX("document.getElementById('ifattr').src = '" + newurl + "';");
    window.open(newurl,"ATTRIBUTI","toolbar=no,directories=no,scrollbars=yes,menubar=no,width=750,height=450");
	
}


function VisAttributi_AUX(cmd1)
{
	setTimeout(cmd1,1000);
	setTimeout(VisAttributi_AUX_AUX,2000);
}


function VisAttributi_AUX_AUX()
{
	var isexp = document.all?true:false
	if (isexp)	
	{
		var x = document.frames["ifattr"].document.body.innerHTML;
		document.frames["ifattr"].document.body.innerHTML = replace(document.frames["ifattr"].document.body.innerHTML,"<BR>","");
		document.frames["ifattr"].document.body.innerHTML = replace(document.frames["ifattr"].document.body.innerHTML,"100%","1000px");
	}
	
	document.getElementById('ifattr').style.display = "";
}

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
  }

//AGO

