// constants
//var xlayerbannerx="container";
//var _testobanner="prova prova prova";
var browser = navigator.appName;
var versione = parseInt(navigator.appVersion); 

var noValue = '-99'
var col2=0
// globals
var curOption = new Array();
var isLoaded = new Array();
var Adati = new Array(5);
var Aerror=new Array(5);
Aerror[0]="Attenzione selezionare un Comune";
Aerror[1]="Attenzione inserire un Cognome";
Aerror[2]="Attenzione inserire un Nome";
Aerror[3]="Attenzione inserire il giorno di nascita";
Aerror[4]="Attenzione inserire il mese di nascita";
Aerror[5]="Attenzione inserire l'anno di nascita";

mywin = null;

function open_window()
	{
var cognome=document.forms['QForm'].cognome.value;
var nome=document.forms['QForm'].nome.value;
var cod_fiscale=document.forms['QForm'].codice_fiscale.value;
var gg=document.QForm.giornoNascita.options[document.QForm.giornoNascita.selectedIndex].value; 
var mm=document.QForm.meseNascita.options[document.QForm.meseNascita.selectedIndex].value; 
var aa=document.forms['QForm'].annoNascita.value;
var ss=document.QForm.Sesso.options[document.QForm.Sesso.selectedIndex].value; 
var daticomune=document.QForm.lstMake.options[document.QForm.lstMake.selectedIndex].value; 
prov=daticomune.substring(5,7);
com=daticomune.substring(8);

var dat=gg+"/"+mm+"/"+aa

//var url="../cod-fisc-sml.asp?cognome="+cognome+"&amp;nome="+nome+"&amp;codfis="+cod_fiscale+"&amp;data="+dat+"&amp;sesso="+ss+"&amp;comune="+com+"&amp;prov="+prov
var url='../cod-fisc-sml.asp?cognome='+cognome+'&nome='+nome+'&amp;codfis='+cod_fiscale+"&amp;data="+dat+"&amp;sesso="+ss+"&amp;comune="+com+"&amp;prov="+prov
var url2='http://www.mediameeting.it/cod-fisc-sml.asp?cognome='+cognome+'&nome='+nome+'&codfis='+cod_fiscale+"&data="+dat+"&sesso="+ss+"&comune="+com+"&prov="+prov
	
var w = 500;
	var h = 380;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;




if (browser=='Netscape' && versione=='5'){

WindowObjectReference= window.open(url2,"Codice Fiscale", "resizable=yes, scrollbars=yes, status=yes");

}else{

//mywin = window.open(url,"name",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=570,height=570,top=TopPosition,left=LeftPosition');
   settings ='height='+h+',width='+w+',top='+0+',left='+LeftPosition+',scrollbars='+'yes'+',resizable'
   mywin = window.open(url,"name",settings);

}
	//if(mywin.window.focus){mywin.window.focus();}
	}


function cerca()
{
//alert(Z);

if (col2!=0){
var form2=document.QForm[col2];
form2.style.backgroundColor="#C0C0C0"
}
emptyList( 'lstMake' );
var comune=document.forms['QForm'].T1.value;
//alert(comune);

jsrsExecute( 'select_rs2.asp', cbFillMake, 'makecomune', comune );
}

function vai()
{
Adati[0]=document.QForm.lstMake.options[document.QForm.lstMake.selectedIndex].value; 
Adati[1]=document.forms['QForm'].cognome.value;
Adati[2]=document.forms['QForm'].nome.value;
Adati[3]=document.QForm.giornoNascita.options[document.QForm.giornoNascita.selectedIndex].value; 
Adati[4]=document.QForm.meseNascita.options[document.QForm.meseNascita.selectedIndex].value; 
Adati[5]=document.forms['QForm'].annoNascita.value;
var sesso=document.QForm.Sesso.options[document.QForm.Sesso.selectedIndex].value; 
for (i = 0; i < 6; i++)
{
if (Adati[i]=='' || Adati[i]=='aa' || Adati[i]=='-99')
{

alert(Aerror[i]);
return
}
}
LayerWrite('cerca', "Sto calcolando il codice fiscale")
document.QForm.codice_fiscale.value="CALCOLO IN CORSO";

jsrsExecute( 'calc-cod.asp', result, 'calc', Array(Adati[0], Adati[1], Adati[2], Adati[3], Adati[4], Adati[5], sesso) );


}


function result(risultato){

document.QForm.codice_fiscale.value=risultato;
 var form = document.QForm;
form.B2.disabled = false
form.codice_fiscale.disabled = false
LayerWrite('cerca', "Puoi copiare ed incollare il codice oppure stampare un fac-simile")

}

function inizia(){
 //setInterval('LayerBanner1()',100000);


LayerWrite('cerca', "Digitare prima il comune di nascita");
}



function body_onLoad(iniziale, col){
document.QForm.codice_fiscale.value='';
if (col2=='')
{
var form3=document.QForm[col];
form3.style.backgroundColor="red"
col2=col
}


var valiniziale=iniziale;

  // initialize lists
  emptyList( 'lstMake' );
//  emptyList( 'lstModel');
// emptyList( 'lstOptions' );
//alert (col2);
 var form = document.QForm;
form.B2.disabled = true


if (col2!=col)
{
var form3=document.QForm[col];
form3.style.backgroundColor="red"
var form2=document.QForm[col2];
form2.style.backgroundColor="#C0C0C0"
col2=col
}
LayerWrite('cerca', 'Attendi un attimo, sto cercando i comuni con la lettera :'+valiniziale)


//document.flash.bottone1.style.backgroundColor=swap[i]

jsrsExecute( 'select_rs.asp', cbFillMake, 'makeList', valiniziale );
}

function lstMake_onChange(){
  document.QForm.codice_fiscale.value='';
  var val = this.options[this.selectedIndex].value;
//alert(val)
  if(val == noValue){
    // don't allow novalue selection - revert to current
    selectOption( this.name, curOption[this.name] )
  } else {
    LayerWrite('cerca', 'Inserisci i dati Cognome, Nome, Data di nascita e sesso')
    window.status = 'Digita il Cognome ed il Nome...';
    curOption[this.name] = val;
//alert(this.name)

    // init dependent lists
    //---emptyList( 'lstModel' );
    //--emptyList( 'lstOptions');
    //--window.status = 'Loading Model Selections...';
    //--jsrsExecute( 'select_rs.asp', cbFillModel, 'modelList', val );
  }  
}

function lstModel_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    emptyList( 'lstOptions');
    window.status = 'Loading Options Selections...';
    jsrsExecute( 'select_rs.asp', cbFillOptions, 'optionsList', val );
  }  
}

function lstOptions_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    var msg = "You have selected: \n\n";
    msg += this.form.lstMake.options[this.form.lstMake.selectedIndex].text + "\n";
    msg += this.form.lstModel.options[this.form.lstModel.selectedIndex].text + "\n";
    msg += this.options[this.selectedIndex].text + "\n";
    alert (msg);
  }
}

function cbFillMake ( strMakes ){ 
//alert (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
LayerWrite('cerca', messag)
  
//LayerWrite('cerca', messag+'...sto caricando la lista')
 // alert(num) 

  fillList( 'lstMake',  strMakes ); 
}

function cbFillModel ( strModels ){ 
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstModel',  strModels ); 
}

function cbFillOptions( strOptions ){ 
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstOptions', strOptions ); 
}

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]);
}      
    }  

  }
//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; 


comun=document.forms['QForm'].T1.value;

   if (dato=='' || dato=='-99')
   {
 if (comun!='' && dato2=='--- Digitare sopra il comune di nascita ---')
{
  
alert('Attenzione devi premere CERCA');
}

if (comun!='' && dato2=='-- Seleziona il comune --')
{alert('Attenzione devi selezionare un comune nella lista trovata');
}

if (comun==''){
alert('Attenzione non hai digitato un comune');
}
   }
   else {
 LayerWrite('cerca', 'Inserisci '+test)
}
}
function inblur()
{
//se si lascia un campo o si seleziona un valore in select sesso
LayerWrite('cerca', '')
}

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';
//alert(nIndex2);
if (document.getElementById){
jsrsExecute( '../admentor/scriptinject3-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
   }