
function SetAptArrivo() {
 var fVolo = document.frmAresFlight;
 var fArrivi = fVolo.fAptArrivo.options;
 var fApt = fVolo.fAptPartenza.options[fVolo.fAptPartenza.selectedIndex].value;

 if ( fVolo.fAptPartenza.selectedIndex == -1 ) {
    return;
 }
 if ( fApt == '-' ) {
    return;
 }

 var Rotte = eval('Tratte'+fApt);

 fArrivi.length = 1;
 for (loop=0; loop < Rotte.length; loop++) {
    fArrivi[loop] = new Option(eval(Rotte[loop]));
    fArrivi[loop].value = Rotte[loop];
 }
 fArrivi.selectedIndex = 0;
}
function SelezionaApt(AptSel) {
 var fVolo = document.frmAresFlight;
 var SelIdx;
 var i;

 SelIdx = -1;
 if (AptDir == 'P') {
    for( i=0; i<fVolo.fAptPartenza.length; i++ ) {
       if (fVolo.fAptPartenza.options[i].value == AptSel) {
          SelIdx = i;
          break;
       }
    }
    if (SelIdx == -1) {
       alert('Warning: airport not operated.');
       return;
    } else {
       fVolo.fAptPartenza.options.selectedIndex = SelIdx;
       SetAptArrivo();
       AptDir = 'A';
    }
 } else {
    for( i=0; i<fVolo.fAptArrivo.length; i++ ){
       if (fVolo.fAptArrivo.options[i].value == AptSel){
          SelIdx = i;
          break;
       }
    }
    if (SelIdx == -1) {
       alert('Warning: route not operated.');
       return;
    } else {
       fVolo.fAptArrivo.options.selectedIndex = SelIdx;
       AptDir = 'P';
    }
 }
}

function DispFreq(dir) {
 var fVolo = document.frmAresFlight;
 var AptPartenza = fVolo.fAptPartenza.options[fVolo.fAptPartenza.selectedIndex].value;
 var AptArrivo = fVolo.fAptArrivo.options[fVolo.fAptArrivo.selectedIndex].value;
 var Tratta;
 var i;
 var Volo;

 if ( AptPartenza=='-' || AptArrivo=='-') {
    alert("Warning: select departure and arrival cities.");
 }
 if (dir=='A') {
    Volo='Departure flight is operated:\n';
    Tratta=AptPartenza+AptArrivo; }
 else {
    Volo='Return flight is operated:\n';
    Tratta=AptArrivo+AptPartenza; }

 for( i=0; i<Tratte.length; i++ ) {
    if (Tratta==Tratte[i]) {
       alert(Volo + Frequenze[i]);
       break;
    }
 }
}

function ChkApt()
{
	if (AptPartenza == '-') {
		alert ('Warning: select the airport of origin.');
		return false;
	}
	if (AptArrivo == '-') {
		alert ('Warning: select the airport of destination.');
		return false;
	}
	if (AptPartenza == AptArrivo) {
		alert ('Warning: the airport of origin must be different to the airport of destination.');
		return false;
	}
	return true;
}

function ChkDate()
{
   if (DataAndata=='') {
      alert('Warning: departure date is mandatory.');
      return false;
   }
   if (isDate(DataAndata)==false) {
      //alert('Warning: departure date is wrong,\nuse format dd/mm/yyyy.');
      //return false;
   }
   if (compareToday(DataAndata)<0) {
      alert('Warning: departure date is in the past.');
      return false;
   }

   //if (DataRitorno=='') {
   //   alert('Warning: this reservation needs the return.');
   //   return false;
   //}

   if (DataRitorno!='') {
     if (isDate(DataRitorno)==false) {
        alert('Warning: return date is wrong,\nuse format dd/mm/yyyy.');
        return false;
     }
     if (compareToday(DataRitorno)<0) {
        alert('Warning: return date is in the past.');
        return false;
     }
     if (compareDate(DataAndata,DataRitorno)>0) {
        alert('Warning: select correct departure and return date\ndeparture first, return last.');
        return false;
     }
   }

   return true;
}

function gotoStep2(){
  var fVolo = document.frmAresFlight;
  if ( fVolo.fAptArrivo.options.selectedIndex == -1 || fVolo.fAptPartenza.options.selectedIndex == -1 ) {
     alert ('Warning: Select origin and destination city.');
     return false;
  }
  //
  NrPasseggeri = fVolo.fNrAdult.options[fVolo.fNrAdult.selectedIndex].value;
  AptPartenza = fVolo.fAptPartenza.options[fVolo.fAptPartenza.selectedIndex].value;
  AptArrivo   = fVolo.fAptArrivo.options[fVolo.fAptArrivo.selectedIndex].value;
  //
  DataAndata = fVolo.fDataAndata.value;
  DataRitorno = fVolo.fDataRitorno.value;
  //
  if (!ChkApt()) return false;
  if (!ChkDate()) return false;
  //
  return true;
}

