	// Funzione tolta per nuovo popup ajax
	/*
	function noenter() 
	{		
		if(event.keyCode == 13) 
		{
			showObj('LayerPopup', document.FHOTEL.destination.value, '/cs/ContentServer?pagename=BoscoloB2CSite%2FPage%2FB2B%2FCommon%2FStandalone%2FLocalityPopUp&destination=');
			document.FHOTEL.destination.blur();
			return false;
		}		
  }	
  */	

var numeroRighe=0;
var rigaCorrente = 0;

var array_des_localita = new Array();
var array_cod_localita = new Array();

var currentFieldNameDes  = "";
var currentFieldNameCode = "";
var currentDivName       = "";
var currentSpanName      = "";

function resettaArray()
{
  //alert("resettaArray()");
  array_des_localita = new Array();
  array_cod_localita = new Array();
  
  currentFieldNameDes  = "";
  currentFieldNameCode = "";
  currentDivName       = "";
  currentSpanName      = "";
}
  
  function columnLayoutInit()
  {
  	try
	  {
		  cancellaCodiceLocalita();
      inizializza();
      	  
    }
	  catch(e){}
  }

	function submitFhotel() 
	{
		if (trim(document.forms['FHOTEL'].localityId.value) != '') 
		{
			document.forms['FHOTEL'].Search.style.display="none"
			formsSubmit("hotelQueryGet",document.FHOTEL);toggleLink(this,"");
		} 
		else 
		{
			alert("Digita la destinazione");
		}
	}
	
		
	function cancellaCodiceLocalita()
	{
	  try
	  {
	  		document.forms['FHOTEL'].localityId.value="";
        document.forms['FHOTEL'].destination.value="";        
        
	  }
	  catch(e){}
	}
	
	createCalendar();

function initRequest(url) {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        isIE = true;
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function doCompletion(event, aField, spanName, fieldNameDes, fieldNameCode, divName, spanName, onlyFlight) 
{

  //alert("doCompletion() " + event.keyCode);
  if(event.keyCode == 38)
  {
    //alert("su");
    coloraRigaNumero(rigaCorrente - 1);
  }
  else if(event.keyCode == 40)
  {
    //alert("giu");
    coloraRigaNumero(rigaCorrente + 1);
  }
  else if(event.keyCode == 13)
  {
    //alert("return con popup aperto");
    inserisciRiga();
  }
  else
  {      	


	  if (aField.value.length>2) 
	  {
	    //alert("doCompletion length>2");
	    
	    resettaArray();
	    
	    urlOnlyFlight = "/cs/ContentServer?pagename=BoscoloB2CSite%2FPage%2FB2B%2FCommon%2FStandalone%2FFlightDestinationsPopUp&destination=" + aField.value;
	    
	    urlFlightHotel = "/cs/ContentServer?pagename=BoscoloB2CSite%2FPage%2FB2B%2FCommon%2FStandalone%2FFlightHotelDestinationsPopUp&destination=" + aField.value;
	    
	    
      if(onlyFlight=='true') url=urlOnlyFlight;
      else url = urlFlightHotel;
      
      mostraDiv("", 'Ricerca in corso ...', divName, spanName, fieldNameDes, fieldNameCode);

		  req = initRequest(url);
		  req.onreadystatechange = function() 
		  {
		    if (req.readyState == 4) 
		    {
		      if (req.status == 200) 
		      {
		        parsaDestinations(trim(req.responseText), spanName, fieldNameDes, fieldNameCode, divName, spanName);
		      } 
		      else if (req.status == 204)
		      {
		        //chiudiDiv(divName, spanName);
		        chiudiTuttiDiv();
		      }
		    }
		  }
		  req.open("GET", url, true);
		  req.send(null);
	  }
	  else
	  {
	    //chiudiDiv(divName, spanName);
	    chiudiTuttiDiv();
	  }
	}
}


function chiudiDiv(divName, spanName)
{
  //alert("chiudiDiv divName="+ divName + " spanName=" + spanName);
  document.getElementById(divName).style.visibility='hidden';
  document.getElementById(spanName).style.border='0px';  
  document.getElementById(spanName).style.borderStyle='none';  
  document.getElementById(spanName).style.backgroundColor='transparent';
  document.getElementById(spanName).innerHTML="";
  showSelect();  
}

function mostraDiv(innerHtml, messaggio, divName, spanName, fieldNameDes, fieldNameCode)
{
  //alert("mostraDiv " + divName + " " + spanName);
  
  document.getElementById(divName).style.display='block';
  
  var htmlSeleziona=creaTestataDiv(messaggio, divName, spanName, fieldNameDes, fieldNameCode);
  
  document.getElementById(spanName).innerHTML=htmlSeleziona + "<br>" + innerHtml;
  document.getElementById(spanName).style.visibility='visible';
  document.getElementById(spanName).style.position='absolute';
  document.getElementById(spanName).style.backgroundColor='#ffffff';
  //document.getElementById(spanName).style.width='220px';
  document.getElementById(spanName).style.width='250px';
  document.getElementById(spanName).style.padding='3px'; 
  document.getElementById(spanName).style.zIndex='10';  
  document.getElementById(spanName).style.border='3px';  
  document.getElementById(spanName).style.borderStyle='solid';  
  document.getElementById(spanName).style.borderColor='#91BC2D';   
  hideSelect();
}


function creaTestataDiv(messaggio, divName, spanName, fieldNameDes, fieldNameCode)
{

  var html = "<div style='float:left;margin:2px 0 1px 0'>";
  html += "<strong class='gr'>";
  html += "<span name='messaggio' id='messaggio'>" + messaggio + "</span>";
  html += "</strong>";
  html += "</div>";
  html += "<div style='float:right;margin:2px 2px 1px 0'>";  
  html += "<a href=\"javascript:chiudiDiv('" + divName + "','" + spanName + "');resetFields('" + fieldNameDes + "','" + fieldNameCode + "');\">";
  html += "<strong class='gr'>Close</strong>&nbsp;";
  html += "<img src='img/close_pop.gif' alt='' align='absmiddle'>";
  html += "</a>";
  html += "</div>";
  html += "<br clear='all'>";
  return html;
}


function parsaDestinations(responseText,spanName,fieldNameDes,fieldNameCode,divName,spanName)
{
  numeroRighe = 0;
  var destinations=contenutoTag(responseText,'destinations');  
  var innerHtml = "<table cellpadding='0' cellspacing='0' width='100%'>";
  var des_localita_nazione="";
  //var cod_aircity="";
  var des_loc_4="";
  
  
  while(true)
  {
    var destination=contenutoTag(destinations,'destination');
    if(destination=='') break;    
    else
    {
      numeroRighe++;
      
      des_localita_nazione=contenutoTag(destination,'des_localita_nazione');
      //cod_aircity=contenutoTag(destination,'cod_aircity');
      des_loc_4=contenutoTag(destination,'des_loc_4');
      cod_loc_4=contenutoTag(destination,'cod_loc_4');
      
      array_des_localita[numeroRighe] = des_localita_nazione + " - " + des_loc_4;
      array_cod_localita[numeroRighe] = cod_loc_4;
      
      currentFieldNameDes = fieldNameDes;
      currentFieldNameCode= fieldNameCode;
      currentDivName      = divName;
      currentSpanName     = spanName;       
      
      innerHtml += "<tr><td id='rowPopUp" + numeroRighe + "' onClick=\"javascript:inserisci('" + fieldNameDes + "','" + fieldNameCode + "','" + des_localita_nazione + " - " + des_loc_4 + "','" + cod_loc_4 + "','" + divName + "','" + spanName + "');\" onMouseOver='coloraRigaNumero(" + numeroRighe + ");' class='normalRow'>" 
      + des_localita_nazione + " - " + des_loc_4 + "</td></tr>";
      destinations=sottraiTag(destinations,'destination');
    }
  }
  innerHtml += "</table>"
  if(numeroRighe == 0) innerHtml = 'Nessuna destinazione reperita'; //"Nessuna destinazione reperita";
  //alert(innerHtml);
  mostraDiv(innerHtml, 'Scegli', divName, spanName, fieldNameDes, fieldNameCode);
  if(numeroRighe>0)
  {
    rigaCorrente=1;
    coloraRigaNumero(rigaCorrente);
  }
}

function coloraRigaNumero(numeroRiga)
{
  //alert("coloraRigaNumero() - " + numeroRiga);
  try
  {
    if(numeroRiga >=1 && numeroRiga <= numeroRighe)
    {
      rigaCorrente = numeroRiga;
      coloraRiga(rigaCorrente);
    }
  }catch(e){}
}

function inserisciRiga()
{
  //alert("inserisciRiga()");
  //alert("rigaCorrente=" + rigaCorrente);
  if(rigaCorrente>0) 
  {
    //document.getElementById('rowPopUp' + rigaCorrente).click();
    inserisci(currentFieldNameDes, currentFieldNameCode, array_des_localita[rigaCorrente], array_cod_localita[rigaCorrente], currentDivName, currentSpanName);
  }
  rigaCorrente = 0;
}


function coloraRiga(numeroRiga)
{
  //alert("numeroRighe=" + numeroRighe);
  for(var rowCounter = 1;rowCounter<=numeroRighe;rowCounter++)
  {
    //alert("rowCounter " + rowCounter);
    document.getElementById('rowPopUp' + rowCounter).className='normalRow';
  }
  //alert("evidenzio la riga " + numeroRiga);
  document.getElementById('rowPopUp' + numeroRiga).className='currentRow';
}


function contenutoTag(codiceXml,nomeTag)
{
  //alert("contenutoTag()");
  var tagInizio = "<" + nomeTag + ">";
  var tagFine   = "</" + nomeTag + ">";
  var indiceInizio = codiceXml.indexOf(tagInizio,0);
  var indiceFine = codiceXml.indexOf(tagFine,0);
  if(indiceInizio>=0 && indiceFine>=0)
  {
    indiceInizio += tagInizio.length;
    var lunghezza = indiceFine - indiceInizio;
    return codiceXml.substr(indiceInizio,lunghezza)
  }
  else return "";
  
}   

function sottraiTag(codiceXml,nomeTag)
{
  var tagFine   = "</" + nomeTag + ">";
  var indiceFine = codiceXml.indexOf(tagFine) + tagFine.length; 
  var lunghezza = codiceXml.length - indiceFine;
  return codiceXml.substr(indiceFine,lunghezza);
}

function trim(stringa)
{
  re=/\s+$|^\s+/g;
  return stringa.replace(re,"");
}

function inserisci(fieldNameDes, fieldNameCode, destinationDes, destinationCode, divName, spanName)
{
  //alert("fieldNameDes=" + fieldNameDes);
  //alert("fieldNameCode=" + fieldNameCode);
  //alert("destinationDes=" + destinationDes);
  //alert("destinationCode=" + destinationCode);
  popolaCampo(fieldNameDes, fieldNameCode, destinationDes, destinationCode);
  chiudiDiv(divName,spanName);
}

function popolaCampo(fieldNameDes, fieldNameCode, destinationDes, destinationCode)
{
	document.forms['FHOTEL'].elements[fieldNameDes].value=destinationDes;
	document.forms['FHOTEL'].elements[fieldNameCode].value=destinationCode;
}

function popolaForm(depCode, retCode)
{
	var url = "/cs/ContentServer?pagename=BoscoloB2CSite/Page/B2B/Common/Standalone/FlightRouteRetrieval&departure=" + depCode + "&arrival=" + retCode;
	req = initRequest(url);
	req.onreadystatechange = function() 
	{
		if (req.readyState == 4 && req.status == 200) 
		{		
			var responseText = trim(req.responseText);
			var dtag = contenutoTag(responseText, 'departure');
			var atag = contenutoTag(responseText, 'arrival');
			
			//alert(responseText);
			
			var depCod4 = contenutoTag(dtag, 'cod_loc_4');
			if (depCod4 != "")
			{
				var departure = contenutoTag(dtag, 'des_localita_nazione') + ' - ' + contenutoTag(dtag, 'des_loc_4');
				popolaCampo('voli_partenza_des', 'voli_partenza', departure, depCod4);
			}
			
			var retCod4 = contenutoTag(atag, 'cod_loc_4');
			if (retCod4 != "")
			{
				var arrival = contenutoTag(atag, 'des_localita_nazione') + ' - ' + contenutoTag(atag, 'des_loc_4');
				popolaCampo('voli_destinazione_des', 'voli_destinazione', arrival, retCod4);
			}
		}
	}
	req.open("GET", url, true);
	req.send(null);
}

function aggiornaComboDate(date, combo, isOut)
{
	thisForm = document.FHOTEL;
	cTP = combo;
	ccn = isOut;
	
	// data nella forma dd-MM-yyyy HH:mm
	var dateFields = date.split(" ")[0].split("-");
	
	dSd = parseInt(dateFields[0], 10);		// giorno
	mSd = parseInt(dateFields[1], 10) - 1;	// mese
	ySd = parseInt(dateFields[2], 10);		// anno
	
	cC(); // aggiorna combo
}

function aggiornaComboOrario(date, combo)
{
	var options = combo.options;
	var depTime = date.split(" ")[1];
	var regexp = /^[0-9][0-9]:00$/;
	for (var i = 0; i < options.length; i++)
	{
		var o = options[i].text;
		if (o.match(regexp) && o >= depTime)
		{
			options[depTime.substr(0, 2) != "00" ? i - 1 : options.length - 1].selected = true;
			break;
		}
	}
}

function aggiornaComboCompagnia(alCode, airline)
{
	var combo = document.getElementById("voli_compagnia");
	var opt = combo.options[1];
	opt.value = alCode;
	opt.text = airline;
	opt.selected = true;
	var layer = document.getElementById("airline_layer");
	layer.style.display = "block";
}

function verificaDisponibilita(depCode, retCode, depDate, retDate, alCode, airline)
{
	popolaForm(depCode, retCode);
	
	aggiornaComboDate(depDate, document.FHOTEL.COMBO_INIZIOMM_AA, false);
	aggiornaComboOrario(depDate, document.FHOTEL.COMBO_INIZIO_ORA);
	aggiornaComboDate(retDate, document.FHOTEL.combo_finemm_aa, true);
	aggiornaComboOrario(retDate, document.FHOTEL.COMBO_FINE_ORA);
	aggiornaComboCompagnia(alCode, airline);
}

function resetFields(fieldName1,fieldName2)
{  
  document.forms['FHOTEL'].elements[fieldName1].value="";
  document.forms['FHOTEL'].elements[fieldName2].value="";  
}

var combo_da_nascondere = new Array('COMBO_INIZIO_ORA','COMBO_FINE_ORA','flight_dep_class','combo_camere','combo_adulti1','combo_bambini1','combo_bambini_eta11','combo_bambini_eta12','combo_bambini_eta13','voli_compagnia');

function hideSelect(){
  for(var i=0;i<combo_da_nascondere.length;i++){
	  var nome_combo=combo_da_nascondere[i];
	  try
	  {
	    //document.forms['FHOTEL'].elements[nome_combo].style.display = "none";
        document.forms['FHOTEL'].elements[nome_combo].style.visibility = "hidden";
	  }
	  catch(e){}
	}
}

var span_da_chiudere = new Array('voliPartenzaSpan','voliDestinazioneSpan','voliPartenzaAltSpan','voliDestinazioneAltSpan');
var div_da_chiudere = new Array('LayerPopupPar','LayerPopupArr','LayerPopupParAlt','LayerPopupArrAlt');

function chiudiTuttiDiv(){
  //alert("chiudiTuttiDiv()");
  //alert("span_da_chiudere.length=" + span_da_chiudere.length);
  for(var i=0;i<span_da_chiudere.length;i++){
    //alert("i=" + i);
	  var nome_span=span_da_chiudere[i];
	  //alert("nome_span=" + nome_span);
	  var nome_div=div_da_chiudere[i];
	  //alert("nome_div=" + nome_div);
	  chiudiDiv(nome_div,nome_span);
	}  
}


			      
function showSelect(){
	for(var i=0;i<combo_da_nascondere.length;i++){
	  var nome_combo=combo_da_nascondere[i];
	  try
	  {
	    //document.forms['FHOTEL'].elements[nome_combo].style.display = "block";
        document.forms['FHOTEL'].elements[nome_combo].style.visibility = "visible";
	  }
	  catch(e){}
	}
}


    function submitFFlight(soloVolo)
{
        
//inizio nuova parte
        elSelStartPart = document.getElementById("selStartPart");        
        elSelStartArr = document.getElementById("selStartArr");
        if (elSelStartPart) {
            if (elSelStartPart.checked) {
                document.getElementById("timeTypeStart").value="VOLIPRELIS_ORA_TIT"; //Ora Partenza            
            } else {            
                document.getElementById("timeTypeStart").value="VOLIPRELIS_ORA_RIT_TIT";            
            }
        }
        elTimeStart = document.getElementById("time_start");
        document.getElementById("timeDescStart").value = elTimeStart.options[elTimeStart.selectedIndex].text;           
        elSelEndPart = document.getElementById("selEndPart");        
        elSelEndArr = document.getElementById("selEndArr");        
        if (elSelEndPart) {
            if (elSelEndPart.checked) {
                document.getElementById("timeTypeEnd").value="VOLIPRELIS_ORA_TIT";
            } else {
                document.getElementById("timeTypeEnd").value="VOLIPRELIS_ORA_RIT_TIT";            
            }
        }
        elTimeEnd = document.getElementById("time_end");
        document.getElementById("timeDescEnd").value=elTimeEnd.options[elTimeEnd.selectedIndex].text
//fine nuova parte
        if (soloVolo=='S') {
            if (!dateCoerentiSoloVolo(document.forms['FHOTEL'].COMBO_INIZIOMM_AA.value,document.forms['FHOTEL'].combo_finemm_aa.value))
			  {
			    alert('Data andata maggiore della data di ritorno, controllare');
			    return;
			  }
        } else {
			  if(!dateCoerenti(document.forms['FHOTEL'].COMBO_INIZIOMM_AA.value,document.forms['FHOTEL'].combo_finemm_aa.value))
			  {
			    alert('Data andata maggiore della data di ritorno, controllare');
			    return;
			  }
		 }	  
        if (trim(document.forms['FHOTEL'].voli_partenza.value) != '' && trim(document.forms['FHOTEL'].voli_destinazione.value) != '')
        {
                document.forms['FHOTEL'].Search.style.display="none"
                document.forms['FHOTEL'].submit();toggleLink(this,"");
        }
        else
        {
                alert("Inserisci la destinazione");
        }
}