// constants
var noValue = '-99'
var col2=0
// globals
var curOption = new Array();
var isLoaded = new Array();
var Adati = new Array(5);
var Aregione=new Array(20);
Aregione[1]="PIEMONTE";
Aregione[2]="VALLE D'AOSTA";
Aregione[3]="LOMBARDIA";
Aregione[4]="TRENTINO ALTO ADIGE";
Aregione[5]="VENETO";
Aregione[6]="FRIULI VENEZIA GIULIA";
Aregione[7]="LIGURIA";
Aregione[8]="EMILIA ROMAGNA";
Aregione[9]="TOSCANA";
Aregione[10]="UMBRIA";
Aregione[11]="MARCHE";
Aregione[12]="LAZIO";
Aregione[13]="ABRUZZO";
Aregione[14]="MOLISE";
Aregione[15]="CAMPANIA";
Aregione[16]="PUGLIA";
Aregione[17]="BASILICATA";
Aregione[18]="CALABRIA";
Aregione[19]="SICILIA";
Aregione[20]="SARDEGNA";

function cerca()
{

//if (col2!=0){
//var form2=document.QForm[col2];
//form2.style.backgroundColor="#C0C0C0"
//}
document.forms['QForm'].cap.value="";
document.forms['QForm'].provincia.value="";
document.forms['QForm'].regione.value="";
document.forms['QForm'].capoluogodiprov.value="";
document.forms['QForm'].capoluogodireg.value="";
document.forms['QForm'].abitanti.value="";
document.forms['QForm'].superficie.value="";
emptyList( 'lstMake' );
var comune=document.forms['QForm'].T1.value;
var precisa=document.forms['QForm'].C1.checked;
var dato=comune+"#"+precisa;
if (comune==""){
alert("Attenzione - digitare un comune");
return
}
jsrsExecute( 'select_rs2.asp', cbFillMake, 'makecomune', dato );

 
}


function inizia(){
// setInterval('LayerBanner1()',100000);
LayerWrite('cerca', "Digitare il comune o testo da cercare");
}


function lstMake_onChange(){
  //document.QForm.codice_fiscale.value='';

  var val = this.options[this.selectedIndex].value;
  var val2 = this.options[this.selectedIndex].text;

  if(val == noValue){
    // don't allow novalue selection - revert to current
    selectOption( this.name, curOption[this.name] )
  } else {
//var testox=val2+' C.A.P. codice avviamento postale '+aDati[0]+' in provincia '+aDati[1]+' regione '+aDati[2];
//document.getElementById('ora').innerHTML = testox;
//  window.frames.pippo.location='prova-GOOGLE-LINK.asp?prova='+val2;
//-----window.frames['pippo'].location='GOOGLE-LINK.asp?prova='+val2;

    LayerWrite('cerca', 'Questi i dati del comune '+val2)


    window.status = 'Visualizza i dati';
    curOption[this.name] = val;
var aDati= val.split('-');

//***Visualizza mappa********************************
  mark=val2.indexOf(" (");
 comunemappa=val2.substring(0,mark);
var linkmappa = '<font face="Verdana" size="2" color="#FF0000"><a href="http://www.mediameeting.it/mappe/index.asp?';
linkmappa=linkmappa+'vacanze-a='+comunemappa+'&provincia='+aDati[1]+'" target="_blank">Visualizza mappa di '+val2+'</a></font>';
LayerWrite('mappa', linkmappa);

var testox=val2+' C.A.P. codice avviamento postale '+aDati[0]+' in provincia '+aDati[1]+' regione '+Aregione[aDati[2]];
window.frames['pippo'].location='GOOGLE-LINK.asp?prova='+testox;
//alert(testox);

document.forms['QForm'].cap.value=aDati[0];
document.forms['QForm'].provincia.value=aDati[1];
document.forms['QForm'].regione.value=Aregione[aDati[2]];
if (aDati[3]=="True"){
document.forms['QForm'].capoluogodiprov.value="SI";
}
else{document.forms['QForm'].capoluogodiprov.value="NO";}
if (aDati[4]=="True"){
document.forms['QForm'].capoluogodireg.value="SI";
}
else{document.forms['QForm'].capoluogodireg.value="NO";}
document.forms['QForm'].abitanti.value=aDati[5];
document.forms['QForm'].superficie.value=aDati[6];

  }

}



function cbFillMake ( strMakes ){ 

  window.status = '';
   //prende quanti comuni ci sono
  re="%";
  er=strMakes.indexOf(re);
  num=strMakes.substring(0,er);
  strMakes=strMakes.substring(er+1);
var messag="Numero comuni trovati :"+num
if (num>1){ messag=messag+" Selezionare il comune dalla lista"}
LayerWrite('cerca', messag)
  
//LayerWrite('cerca', messag+'...sto caricando la lista')
 // alert(num) 



  fillList( 'lstMake',  strMakes ); 

}


function fillList( listName, strOptions ){

  // fill any list with options
  emptyList( listName );
  // always insert selection prompt
  var lst = document.forms['QForm'][listName];
if(strOptions!=0){
  lst.disabled = true;
  // options in form "value~displaytext|value~displaytext|..."
  var aOptionPairs = strOptions.split('|');
  for( var i = 0; i < aOptionPairs.length; i++ ){
     if (aOptionPairs[i].indexOf('~') != -1) {
      var aOptions = aOptionPairs[i].split('~');
if (aOptionPairs.length>2){
      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
}
else{
lst.options[i] = new Option(aOptions[1], aOptions[0]);
var aDati= aOptions[0].split('-');

//***Visualizza mappa********************************
  mark=aOptions[1].indexOf(" (");
 comunemappa=aOptions[1].substring(0,mark);
var linkmappa = '<font face="Verdana" size="2" color="#FF0000"><a href="http://www.mediameeting.it/mappe/index.asp?';
linkmappa=linkmappa+'vacanze-a='+comunemappa+'&provincia='+aDati[1]+'" target="_blank">Visualizza mappa di '+aOptions[1]+'</a></font>';
LayerWrite('mappa', linkmappa);

  var val2 = aOptions[1];  
//var testox=val2+' C.A.P. codice avviamento postale '+aDati[0]+' in provincia '+aDati[1]+' regione '+aDati[2];
//document.getElementById('ora').innerHTML = testox;
//---window.frames['pippo'].location='GOOGLE-LINK.asp?prova='+val2;
var testox=val2+' C.A.P. codice avviamento postale '+aDati[0]+' in provincia '+aDati[1]+' regione '+Aregione[aDati[2]];
window.frames['pippo'].location='GOOGLE-LINK.asp?prova='+testox;

document.forms['QForm'].cap.value=aDati[0];
document.forms['QForm'].provincia.value=aDati[1];
document.forms['QForm'].regione.value=Aregione[aDati[2]];
if (aDati[3]=="True"){
document.forms['QForm'].capoluogodiprov.value="SI";
}
else{document.forms['QForm'].capoluogodiprov.value="NO";}
if (aDati[4]=="True"){
document.forms['QForm'].capoluogodireg.value="SI";
}
else{document.forms['QForm'].capoluogodireg.value="NO";}
document.forms['QForm'].abitanti.value=aDati[5];
document.forms['QForm'].superficie.value=aDati[6];
 }      
    }
  }


//alert(aOptionPairs.length);
   if (aOptionPairs.length>2){
    lst.options[0] = new Option('-- Seleziona il comune --', noValue);
}
    window.status = 'Seleziona adesso il comune...';
  // init to no value
  selectOption( listName, noValue );
  lst.onchange = eval( listName + "_onChange" );
  isLoaded[listName] = true;
  lst.disabled = false;

}
else{  lst.options[0] = new Option('-- Comune non trovato --', noValue);}

}

function emptyList( listName ){

  var lst = document.forms['QForm'][listName];
  lst.options.length = 0;
  lst.onchange = null;
  isLoaded[listName] = false;
  curOption[listName] = noValue;
 window.status = 'Caricamento comuni in corso...';
  lst.options[0] = new Option('--- Attendi un attimo ---', noValue);
}

function selectOption( listName, optionVal ){
  // set list selection to option based on value
  var lst = document.forms['QForm'][listName];
  for( var i = 0; i< lst.options.length; i++ ){
    if( lst.options[i].value == optionVal ){
      lst.selectedIndex = i;
      curOption[listName] = optionVal;
      return;
    }  
  }
}

function LayerWrite(_layer, _testo)
   {
   if (document.layers)
      with (document.layers[_layer].document) {
         open();
         write(_testo);
         close(); }
   else if (document.getElementById)
      document.getElementById(_layer).innerHTML=_testo;
      else _layer.innerHTML=_testo
   }

function infocus(test)
// se si posiziona su un campo o select
{
dato2=document.QForm.lstMake.options[document.QForm.lstMake.selectedIndex].text; 
dato=document.QForm.lstMake.options[document.QForm.lstMake.selectedIndex].value; 
LayerWrite('cerca', 'Dati del comune '+dato2)


}

function resetta(){
LayerWrite('cerca', 'Cancellazione in corso...')
var listname="lstMake";
emptyList2( listname );
if (col2!=0){
var form2=document.QForm[col2];
form2.style.backgroundColor="#C0C0C0"
}
 var form = document.QForm;
form.B2.disabled = true
form.codice_fiscale.disabled = true

//for(i=0; i<document.QForm.giornoNascita.length; i++)
//      if(document.QForm.giornoNascita.options[i].defaultSelected == true)
document.QForm.giornoNascita.options[0].selected=true;
document.QForm.meseNascita.options[0].selected=true;
document.QForm.Sesso.options[0].selected=true;
document.forms['QForm'].annoNascita.value='aa';
document.forms['QForm'].cognome.value='';
document.forms['QForm'].nome.value='';
document.forms['QForm'].T1.value='';
document.QForm.codice_fiscale.value='';
window.status = '';
inizia()
}

function emptyList2( listName ){
    var lst = document.forms['QForm'][listName];
  lst.options.length = 0;
  lst.onchange = null;
  isLoaded[listName] = false;
  curOption[listName] = noValue;
 //window.status = 'Caricamento comuni in corso...';
  lst.options[0] = new Option('--- Digitare sopra il comune di nascita ---', noValue);
}

function LayerBanner1(){
var nIndex2 = now.getTime()+'aa';
if (document.getElementById){
LayerBanner('Loading...')
jsrsExecute( '../../admentor/scriptinject4-g.asp', LayerBanner, 'makebanner', nIndex2);}
}

function LayerBanner(risultato)
   {
xlayerbannerx="container";
testobanner=risultato;
   if (document.layers)
      with (document.layers['container'].document) {
         open();
         write(testobanner);
         close(); }
   else if (document.getElementById)
     document.getElementById('container').innerHTML= testobanner;
      else xlayerbannerx.innerHTML= testobanner
   }