function ddVisteControl() {
    }
    ddVisteControl.prototype = new GControl();

    ddVisteControl.prototype.initialize = function(map) {
   
      var container = document.createElement("div");
      var zoomInDiv = document.createElement("div");
      this.elem=zoomInDiv;
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      
      var myselect = document.createElement("select");
      myselect.setAttribute("id", "ddViste");
      // myselect.setAttribute("onchange", "Evidenzia()");
      myselect.onchange=Evidenzia;

      zoomInDiv.appendChild(myselect);
   
      map.getContainer().appendChild(container);
      return container;
    }

   
    ddVisteControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(44, 10));
    }

  

      ddVisteControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "none";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";

      button.style.marginBottom = "2px";
      button.style.textAlign = "center";
      button.title="";
      button.style.filter="alpha(opacity=80)";
	  button.style.opacity=".80";
     }
     
     
     
     
function K_HtmlControl(html)
	{
		this.html=html;
	}
	K_HtmlControl.prototype=new GControl(true,false);
	K_HtmlControl.prototype.initialize=function(a)
	{
		this.Map=map;
		this.div=document.createElement("div");
		this.div.style.cursor="default";
		this.div.style.position="absolute";
		this.div.unselectable="on";
		this.div.onselectstart=function(){return false};
		this.div.style.fontSize="11px";
		this.div.style.fontFamily="Arial, sans serif";
		this.div.style.MozUserSelect="none"
		this.div.innerHTML=this.html;
		a.getContainer().appendChild(this.div);
		GEvent.bindDom(this.div,"click",this,this.onClick);
		return this.div;
	};
	K_HtmlControl.prototype.getDefaultPosition=function()
	{
		return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(10,30))
	};
	K_HtmlControl.prototype.onClick=function()
	{
		GEvent.trigger(this,"click");
	}
	
   K_HtmlControl.prototype.getHtmlText=function()
	{
		return this.div.innerHTML;
	};
	
  K_HtmlControl.prototype.setHtmlText=function(html)
 {
		this.div.innerHTML=html;
	};
	
	
	
function FotoControl() {
    }
    FotoControl.prototype = new GControl();

    FotoControl.prototype.initialize = function(map) {
      var container = document.createElement("div");

      var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
          
    
      var myh=' <INPUT id="cbO" type="checkbox" name="cbO" onclick="HSO();" >';
      myh+='<a href="javascript:cbOClick()">Ortofoto</a>';
      zoomInDiv.innerHTML=myh;
       
       
      map.getContainer().appendChild(container);
      return container;
    }

      FotoControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 23));
    }


      FotoControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "none";
      button.style.color = "#000000";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "1px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "6em";
      button.style.cursor = "pointer";
      button.title = "mostra/nasconde ortofoto del comune";
 }

function cbOClick() {
	document.getElementById("cbO").click();
}
	
	
// SPONSOR

function ReadSponsor(myurl)
{
  var request = GXmlHttp.create();
  
  
  request.open("GET", myurl, true);
     request.onreadystatechange = function() {
        if (request.readyState == 4) {
        var xmlDoc = request.responseXML;
        
        var mySponsors = xmlDoc.documentElement.getElementsByTagName("Sponsor");
        var vistecodice='';
       
       aSponsors=[];
    
       // Nome="Europa" BannerI="Pro/1/7.jpg" Iw="90" Ih="50" SLink="www.google.it" 
       
        for (var x = 0; x < mySponsors.length; x++) {
           var nome = mySponsors[x].getAttribute("Nome");
           var tit=   mySponsors[x].getAttribute("Tit");
           var des =mySponsors[x].getAttribute("Des");
		   var bi =   mySponsors[x].getAttribute("BannerI");
		   var iw=    mySponsors[x].getAttribute("Iw");
		   var ih=    mySponsors[x].getAttribute("Ih");
		   var sl=    mySponsors[x].getAttribute("SLink");
		   var bo=    mySponsors[x].getAttribute("Bo");
		   var lat=   mySponsors[x].getAttribute("Lat");
		   var lng=   mySponsors[x].getAttribute("Lng");
			   
		   var mysponsor=new Sponsor(nome,tit,des,bi,iw,ih,sl,bo,lat,lng);
		   aSponsors.push(mysponsor);   			   	
		   	    				   
		}
		IntiIconSponsor();
		aSponsors.sort(SponsorOrder);	
  	   var x="";
  	     for (var a = 0; a < aSponsors.length; a++) {
               x+= aSponsors[a].Nome + ';';
          } // fine for

		iAcceso =-1;
		t=setTimeout("MostraBanner(4)",1);

              
        } //end if
      } //end funtion
      request.send(null);
}

function MostraBanner(quanti)
{
if (iAcceso + quanti >= aSponsors.length ) iAcceso=-1;

var mycode='';
mycode='<table><tr>';

for( var i=1; i <= quanti; i++) mycode += Accendi(i);
mycode+='</tr></table>';
e("tuttiContent").innerHTML=mycode; 
iAcceso+=quanti;
t=setTimeout("MostraBanner(4)",10000);
}

function Accendi(i)
{

var c='';
c+='<td><a href="' + aSponsors[iAcceso+i].Sl + '" target="_blank" ><img src="' +  aSponsors[iAcceso+i].Bi+ '" ></a></td><td><b>' + '<a href="' + aSponsors[iAcceso+i].Sl + '" target="_blank" >' +  aSponsors[iAcceso+i].Ti + '</a></b><br>' +  aSponsors[iAcceso+i].De +'</td><td>';
if (aSponsors[iAcceso+i].La > 0 )
{
	c+='<a href="javascript:CentraS(' + parseInt(iAcceso + i) +')" ><img src="http://maps.google.com/mapfiles/kml/pal5/icon14.png" ></a>';

}
c+='</td>';
return c;
}


function IntiIconSponsor()
{
var baseIcon = new GIcon();
          baseIcon.iconSize=new GSize(32,32);
          baseIcon.shadowSize=new GSize(56,32);
          baseIcon.iconAnchor=new GPoint(16,32);
          baseIcon.infoWindowAnchor=new GPoint(16,0);
          
          pushpin = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
}
    
 
function CentraS(i)
{
if (markerSponsor != null) {
map.removeOverlay(markerSponsor);
markerSponsor=null;
}

 markerSponsor = new GMarker(new GLatLng(aSponsors[i].La,aSponsors[i].Lo),{icon: pushpin});
 map.addOverlay(markerSponsor);

var html="";
html +="<div class='info'>"; 
html= '<h2>'+ aSponsors[i].Ti + '</h2>';
html += aSponsors[i].Bo;
html +='<br>';
html +='</div>';

if (aSponsors[i].Sl != '') html +='<a href=" ' + aSponsors[i].Sl + '" target="_blank" ><span class="approf">' + '...vai'+ '</span>' +  '</a>';

  html += '<p class="percorso">';
  html +='<img src="immagini/car2.jpg"><a href="javascript:PercorsoSponsor('+ i + ')" > ' +  'percorso stradale' +'</a><br>';
  html +='</p>';
  html += '<p class="zoom">';
  html +='<a href="javascript:zoominS(' + i  + ')" ><img src="immagini/plus.gif"> ' + 'zoom in' +'</a>';
  html +='&nbsp;&nbsp;&nbsp;'
  html +='&nbsp;<a href="javascript:zoomoutS(' + i + ')" ><img src="immagini/min.gif"> '  +  'zoom out' +'</a>';
  html +='</p>';
  map.openInfoWindow(new GLatLng(aSponsors[i].La,aSponsors[i].Lo),html);
  window.location.hash="anchorMap";
}


function PercorsoSponsor(indice)
{
var html='';
var ind='';


// var value=gmarkers[indice].Name +' "@"' + gmarkers[indice].getLatLng().lat() + ',' + gmarkers[indice].getLatLng().lng();

 var value='' + aSponsors[indice].La + ',' + aSponsors[indice].Lo;

html +='<div>';
html += '<form action="javascript:getDirections()">';

html += '<select id="s1" onchange="s1c()">';
html +='<option>partenza</option><option>destinazione</option></select><br>';

html += '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value=" ' + aSponsors[indice].Nome +  ' " /><br>';
html +=' <input type="hidden" id="coord" value="'+ value +'" />';
html += '<select id="s2" onchange="s2c()"><option>partenza</option><option selected>destinazione</option></select><br>';
		
html += '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>';
html += '<INPUT value="Percorso" TYPE="SUBMIT">'; 
     
        html +='</form>';   
        html +='</div>';   
        
        markerSponsor.openInfoWindowHtml(html);
}


function zoominS(indice)
{
oldb=null;
map.closeInfoWindow();

//start=-1* gmarkers[indice].Id;
map.setCenter(new GLatLng(aSponsors[indice].La,aSponsors[indice].Lo),map.getZoom());
//map.setCenter(gmarkers[indice].getPoint(),map.getZoom());
map.zoomIn();
CentraS(indice);
}	


function zoomoutS(indice)
{
oldb=null;
map.closeInfoWindow();
map.setCenter(new GLatLng(aSponsors[indice].La,aSponsors[indice].Lo),map.getZoom());
map.zoomOut();
CentraS(indice);
}	       
    
          
  
         
                  

function Sponsor(nome,tit,des,bi,iw,ih,sl,bo,lat,lng)
{
this.Nome=nome;
this.Ti=tit;
this.De=des;
this.Bi=bi;
this.Iw=iw;
this.Ih=ih;
this.Sl=sl;
this.Order=Math.floor(Math.random() * 1000);
this.On = false;
this.Bo=bo;
this.La=parseFloat(lat);
this.Lo=parseFloat(lng);
}




function SponsorOrder(a,b) {
return (a.Order - b.Order);
}

function Reorder()
{
for(var i=0; i< aSponsors.length; i++) 
aSponsors[i].Order=Math.floor(Math.random() * 1000);
aSponsors.sort(SponsorOrder);

}


function Legenda()
{
  if(!LgOn)
 { 
  var myh='';
  LgOn=true;
  
  myh='<a href="javascript:void(0)" onclick="javascript:GL()">applica filtro</a>&nbsp;<a href="javascript:void(0)" onclick="javascript:GL()"><img src="immagini/filter.gif" alt="filter" /></a>&nbsp;&nbsp;';
  myh +=' <a href="javascript:void(0)" onclick="javascript:Legenda()">chiudi</a> &nbsp;<a href="javascript:void(0)" onclick="javascript:Legenda()"><img src="immagini/close.gif" alt="Close" /></a>';
  document.getElementById("altra_bar").innerHTML=  myh;
  myh = aAree[CurrentArea].getLegIndicatori();
  document.getElementById("sidebar").innerHTML=myh;
 }
else
{
    LgOn = false;
    document.getElementById("sidebar").innerHTML=sidebarhtml;
    document.getElementById("altra_bar").innerHTML='';
}
}

function Repaint(){
    aAree[CurrentArea].getSelect();
    fixMarks();
}


// Dati
function getDato(conti,quad)
{
 var i = conti.indexOf(quad);
 if (i >=0 ){
    return conti.substring(i + quad.length, conti.indexOf(",",i+1)) ;
 }
 return '!';
}

function whereDati(conti)
{
 var tc='';
 tc='<table class="whered" title="mostra la distribuzione dei dati">';
 tc+='<tr ><td style="border-bottom: 1px solid #000000; border-right: 1px solid #000000;">'+ getDato(conti,',NO:').toString() + '</td><td>' + getDato(conti,',N:') + '</td><td style="border-bottom: 1px solid #000000; border-left: 1px solid #000000;">' + getDato(conti,',NE:') + '</td></tr>';
 tc+='<tr><td>' + getDato(conti,',O:') + ' </td><td style="border: 1px solid #000000;">'+ getDato(conti,',C:') + '</td><td>' + getDato(conti,',E:') + '</td></tr>';
 tc+='<tr><td style="border-top: 1px solid #000000; border-right: 1px solid #000000;">' + getDato(conti,',SO:')  + '</td><td>' + getDato(conti,',S:') +'</td><td style="border-top: 1px solid #000000; border-left: 1px solid #000000;">' + getDato(conti,',SE:') + '</td></tr>';
 tc+='</table>';
 
 return tc;
}

function GetAllRisorseOfArea(x1,y1,x2,y2)
{
   var request = GXmlHttp.create();
   
   var Src =2;
 
   var myurl='GetRisorseOfArea.aspx';
    
  myurl +='?x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2 + '&s=' + start + '&D=' + selectDati +  '&o=' + selectOrdine ;
  myurl += '&Src=' + Src + '&L=' + Lingua + ' &n=' + pagina;
  request.open("GET", myurl, true);
     request.onreadystatechange = function() {
        if (request.readyState == 4) {
        var xmlDoc = request.responseXML;
        
        var aRisorse = xmlDoc.documentElement.getElementsByTagName("R");
	    
	        
		var mh="";
		
	    
	     for (var t=0; t<gmarkers.length; t++)
	       gmarkers[t].On=false;
	    
			 
	    var trovato;
	 
	    for (var a = 0; a < aRisorse.length; a++) {
            var Id = aRisorse[a].getAttribute("Id");
            trovato=false;
            for(var i=0; i< gmarkers.length;i++)
             if( gmarkers[i].Id == Id ) {
              trovato=true;  gmarkers[i].On=true;
              break;
           }
             
           if (trovato) continue;    
            
            var Rt = aRisorse[a].getAttribute("RC");
            var Nome = aRisorse[a].getAttribute("NL");
            
            var La = parseFloat(aRisorse[a].getAttribute("La").replace(',','.'));
            var Lo = parseFloat(aRisorse[a].getAttribute("Lo").replace(',','.'));    
            var Ind = aRisorse[a].getAttribute("In");
            var Loc = aRisorse[a].getAttribute("C"); 
            var Li = aRisorse[a].getAttribute("Li");  
            var Info = aRisorse[a].getAttribute("RCo");
            var More =aRisorse[a].getAttribute("RDe");
            var Img= aRisorse[a].getAttribute("Img");
            var O = aRisorse[a].getAttribute("O");                 
			
			
		   
			
		  var marker = createMarkerRisorsa(La,Lo,Rt,Nome,Ind,Loc,Li,Id,Info,More,Img,O);
	   	 	  	   	  
	   	  map.addOverlay(marker);
 	  	                           
          } 
		
		for (var t=gmarkers.length -1 ; t >= 0; t--)
			if(! gmarkers[t].On) {	map.removeOverlay(gmarkers[t]);
			   gmarkers.splice(t,1);
			  }   	
		
		for (var t=gmarkers.length -1 ; t >= 0; t--)  gmarkers[t].indice=t;
		   	
			  createSideBar();
			
	      var report=xmlDoc.documentElement.getElementsByTagName("report");
	      var da =  parseInt(report[0].getAttribute("da"));
	      var a =  parseInt(report[0].getAttribute("a"));
    	  var tot=report[0].getAttribute("tot");
    	  var conti=report[0].getAttribute("conti");
    	    	
    	  cWD.setHtmlText(whereDati(conti));
    	   var myhtml=  aTesti['Results']+ " <strong>" + Math.max(da,Math.min(1,tot)) + "</strong> - <strong>" + a + "</strong> " +  aTesti['Of'] + " <strong>" + tot + "</strong>";
    	  document.getElementById("lblSituazione").innerHTML=myhtml;
    	  start=da;
    	
    	  if(da > 0) {
    	    disableAnchor(document.getElementById("lbPgPrev"), false,(da-pagina));
    	 
    	   }
    	  else 
    	  { 
    		disableAnchor(document.getElementById("lbPgPrev"), true)
    	  }	  
    	   pgPrevStart=Math.max(0,da-pagina);
    	  
    	  if((da + pagina) < tot )
    	  {
    	   disableAnchor(document.getElementById("lbPgNext"), false,(da+pagina));
    	  }  
    	  else  disableAnchor(document.getElementById("lbPgNext"), true);
    	  
    	  pgNextStart=Math.min((tot -1),(da + pagina));
    	
    	  if (! LgOn) document.getElementById("sidebar").innerHTML=sidebarhtml; 
        } //end if
        start=0;
      } //end funtion
      request.send(null);
}