// JavaScript Document
var globalWBMemForm;
var elencoAzioniDaEseguire='';
var prodottoCorrenteConVoli=false;

function mostraMenuWebBooking(visibile)
{
    var bW, bH,mW,mH,obj,xPos,yPos;
    bW=parseInt(document.body.clientWidth);
    bH=parseInt(document.body.clientHeight);
    obj=document.getElementById('bloccoMenuWebBookingContainer');
    if (!obj) {return false;}
    mW=obj.style.width; //600;
    mH=obj.style.height; //480;
    mH=mH.toString().toLowerCase().replace('px','');
    mW=mW.toString().toLowerCase().replace('px','');
    var scrollAttuale=document.body.scrollTop;
    xPos=parseInt(bW/2) - parseInt(mW/2) + parseInt(document.body.scrollLeft);
    yPos=parseInt(bH/2) - parseInt(mH/2) + parseInt(document.body.scrollTop);
    
    if (visibile) {
        disabilitaPagina(true); 
        window.onscroll=function() {document.body.scrollTop=scrollAttuale;}
        obj.style.zIndex=1000;
        obj.style.position='absolute';
        obj.style.top=yPos; //parseInt(bH/2) - parseInt(mH/2);
        obj.style.left=xPos; //parseInt(bW/2) - parseInt(mW/2);
        obj.style.display='block';
    
    }
    else {
        obj.style.display='none';
        window.onscroll=null;
        disabilitaPagina(false); 
    }
    return false;
}

function getValoreParametro(parametro,elencoParametri)
{
    var ar,i;
    ar=elencoParametri.split(';');
    for (i=0;i<ar.length;i++) {
        if(ar[i].toString().toLowerCase().indexOf(parametro.toLowerCase() + '=')>=0) {
            return ar[i].toString().substring(ar[i].toString().toLowerCase().indexOf('=')+1);
        }
    }
    return '';
}


function apriMappaWB(filtro,tipoFiltro, objLink,indirizzo)
{
    objLink.href='WB_creaMappa.asp?filtro=' + filtro + '&tipofiltro=' + tipoFiltro + '&indirizzo=' + indirizzo;
    return hs.htmlExpand(objLink, {objectType: 'iframe', objectWidth: 700, objectHeight: 500,cacheAjax:false,preserveContent:false} );
}

function calcolaTotaleTariffa(idhotel,adt,chd,inf,chkCongruenza)
{
	try
	{
		var m, qta, numGiorni, uPP, uG, mioTot, prezzo,nPax,mioTotNpax,nTipoVoce,bVociConMax,nFlagAllotment,percentuale ;
		var qtaNW,sValutaNW,sValuta,nPaxNW,prezzoNW,P,z,ApplicaRiduzioneLetto;
		var totRigaPercentuali=new Array();
		
		m=document.getElementById('moduloHotel' + idhotel);
		//se la textbox totale non esiste esco dalla funzione
		try
		{	m.totale.value="";	}
		catch(ee)
		{ 	return false; }
		
		numGiorni=m.numgiorni.value;
		mioTotNpax=0;
		mioTot=0;
		bVociConMax=false;
		for (i=1;i<=m.numvoci.value -1;i++)   //cancello gli span
		 {       
		        for (nz=0;nz<=12;nz++) //max 12 giorni
				    {
				        try
				        { objSpan=document.getElementById(idhotel + 'prezzovero' + i + 'giorno' + nz ); objSpan.innerHTML='';}
                        catch(e)
                        {}				    
				    }
		}		    
		
        for (i=0;i<=60;i++)
        {totRigaPercentuali[i]=0;}
        

		for (nz=0;nz<=numGiorni -1;nz++)      //scorro tutti i giorni e calcolo i prezzi veri....
			{		      
		      for (i=1;i<=m.numvoci.value -1;i++)   // scorro tutte le voci e elaboro quelle espresse in % 
		        {					
					qta=eval('m.qta' + i +'.value');
				    nPax=eval('m.npax' + i + '.value');
				    sValuta=eval('m.valuta' + i + '.value');
				    nTipoVoce=eval('m.tipovoce' + i + '.value');
				    percentuale=eval('m.prezzo' + i + 'giorno' + 0 + '.value');
			        percentuale=percentuale.replace(",",".")
    		        percentuale = parseFloat(percentuale);    //--la percentuale di riduzione/supplemento--

				    if (sValuta=='%' && qta > 0 && ! isNaN(qta))        // ----se la riga è espressa in percentuale calcolo il suo prezzovero -----  
				      {
                        P=0;
                        for (z=1;z<=m.numvoci.value -1;z++)   // scorro tutte le voci e elaboro quelle con qta >0, nPax >0 e non espresse in % 
		                  {		      
                            qtaNW=eval('m.qta' + z +'.value');
                            nPaxNW=eval('m.npax' + z + '.value');
                            sValutaNW=eval('m.valuta' + z + '.value');
    				        uPP=eval('m.upp' + z + 'giorno' + nz + '.value');
							uG=eval('m.ug' + z + 'giorno' + nz + '.value');
							prezzoNW=eval('m.prezzo' + z + 'giorno' + nz + '.value');  prezzoNW=prezzoNW.replace(",",".");  prezzoNW = parseFloat(prezzoNW);
							try {
							ApplicaRiduzioneLetto=0;
							ApplicaRiduzioneLetto=document.getElementById('parametri_' + idhotel + '_' + z).getAttribute('ApplicaRiduzioneLetto') ;
				            }
				            catch (Erro)
				            {ApplicaRiduzioneLetto=0;}
				            
				            if (isNaN(prezzoNW)) prezzoNW=0;
				            // ricavo il prezzo per persona della tripla
				            if (nPaxNW>2 && qtaNW>0 && sValutaNW !='%' && ! isNaN(qta))
    				            {
    				                if (uPP.toUpperCase() == "U" && nPaxNW > 0)
    				                    {P = P + (parseFloat(prezzoNW) / parseFloat(nPaxNW));}
    				                else
    				                    {P = P + parseFloat(prezzoNW);}
    				            }                            
    				        if (ApplicaRiduzioneLetto !=0 && nPaxNW==0 && qtaNW>0 && sValutaNW !='%' && ! isNaN(qta))
    				            {
    				                // Aggiungo alla riduzione anche gli altri servizi flaggati
    				                P = P + parseFloat(prezzoNW);
    				            }                            
                          }
                          P=(parseFloat(percentuale) * parseFloat(P)) / 100  // applico la percentuale
                          eval('m.prezzovero' + i + 'giorno' + nz + '.value="' + P.toString().replace('.',',') + '"');                           
                          objSpan=document.getElementById(idhotel + 'prezzovero' + i + 'giorno' + nz );
				          objSpan.innerHTML='<br>(' + P + '€)';
				          totRigaPercentuali[i]=totRigaPercentuali[i] + P;
                          try {
                            objSpan=document.getElementById('CellaTotaleRiga' +idhotel + '_' + i );
                            objSpan.innerHTML=totRigaPercentuali[i].arrotonda(2).toString().replace('.',',');
                          }
                          catch(e)
                          {}
                          
				      }
				    else    // ----se la riga non è espressa in percentuale prezzovero=0
				      {
						eval('m.prezzovero' + i + 'giorno' + nz + '.value="' + 0 + '"');
				      }		        
		        }
            }
		
		var bUnaSistemazioneScelta;
		bUnaSistemazioneScelta=false;
		//calcolo il totale 
		for (i=1;i<=m.numvoci.value -1;i++)
			{	
				qta=eval('m.qta' + i +'.value');
				nPax=eval('m.npax' + i + '.value');
				nTipoVoce=eval('m.tipovoce' + i + '.value');
				eval('m.qta' + i +'.className="InputQtaTariffa"; ');
				if (qta>0 && nPax>0) bUnaSistemazioneScelta=true; 
				if (qta>0 && ! isNaN(qta) && nTipoVoce !=20 && nTipoVoce !=21)
					{						    
					    eval('m.qta' + i +'.className="InputQtaTariffaInserita"; ');
						mioTotNpax += qta * nPax
						salta=1;
						nFlagAllotment=eval('m.flagallotment' + i + '.value');				
						if (nFlagAllotment==2) { bVociConMax=true; };

						for (nz=0;nz<=numGiorni -1;nz++)
							{
								try
								{
									uPP=eval('m.upp' + i + 'giorno' + nz + '.value');
									uG=eval('m.ug' + i + 'giorno' + nz + '.value');
									prezzo=eval('m.prezzo' + i + 'giorno' + nz + '.value');
									prezzo=prezzo.replace(",",".") ;
									
									prezzoNW=eval('m.prezzovero' + i + 'giorno' + nz + '.value');
									prezzoNW=prezzoNW.replace(",",".") ;									
									if (prezzoNW !=0) prezzo=prezzoNW ;
									if (uPP.toUpperCase()=="P" && nPax >0) {prezzo=prezzo * nPax};
									prezzo=prezzo * salta;
									if (uG.toUpperCase()=="U") {salta=0};
									mioTot += prezzo * qta ;									
								}	
								catch(ee)
								{ }
							}
					}
				
			}
		//////////////////////// opzioni per ora ritiro e rilascio auto ////////////////////		
		var oraRit,oraRil,prezzoExtra,objRigaTotale;
		var nGiorni;
		nGiorni=m.numgiorni.value;
		nGiorni=nGiorni -1;
		for (i=1;i<=m.numvoci.value -1;i++)
		{	
				nTipoVoce=eval('m.tipovoce' + i + '.value');				
				if (nTipoVoce==20)
				{  oraRit=eval('m.qta' + i +'.value'); 		}
				
				if (nTipoVoce==21)
				{
					oraRil=eval('m.qta' + i +'.value');
					prezzoExtra=eval('m.prezzo' + i + 'giorno0.value');
					objSpan=document.getElementById(idhotel + 'prezzovero' + i + 'giorno' + nGiorni );
					objRigaTotale=document.getElementById('CellaTotaleRiga' + idhotel + '_' + i);
				}
		}		
		if (parseFloat(oraRil) > parseFloat(oraRit))
		{
			mioTot += parseFloat(prezzoExtra);	
			objSpan.innerHTML='More ' + MoneyFormat(prezzoExtra);
			if (objRigaTotale) {objRigaTotale.innerHTML=MoneyFormat(prezzoExtra);};
		}
		/////////////////////// fine opzioni auto ///////////////////////////////////////
		var impoVoli;		
		impoVoli=0;
		if (m.includiVolo.value==1) {
		    var imAdt, imChd, imInf;
		    
		    imAdt=document.getElementById('prezzoVoloAdt' + idhotel).value;
		    imChd=document.getElementById('prezzoVoloChd' + idhotel).value;
		    imInf=document.getElementById('prezzoVoloInf' + idhotel).value;
		    
		    imAdt=imAdt.replace(',','.');    imChd=imChd.replace(',','.');     imInf=imInf.replace(',','.');
		    
		    if (adt>0) {impoVoli = impoVoli + (parseFloat(imAdt) * adt) ;}
		    if (chd>0) {impoVoli = impoVoli + (parseFloat(imChd) * chd) ;}
		    if (inf>0) {impoVoli = impoVoli + (parseFloat(imInf) * inf) ;}
		    
		    if(imAdt==0 && imChd==0 && imInf==0) {  // se i prezzo non sono separati vedo se è specificata la quota Infant che non è mai inclusa nei prezzi hotel
		    	try {
		    		var qInf, pInf,tInf;
		    		qInf=document.getElementById('qtaInfVolo' + idhotel).value;
		    		pInf=document.getElementById('quotaVoloInf' + idhotel).value;
		    		pInf=pInf.toString().replace(',','.');
		    		tInf=parseInt(qInf) * parseFloat(pInf);
		    		mioTot=mioTot + tInf;		    		
		    	}
		    	catch(ee)
		    	{}		    
		    }
		    
		    mioTot=mioTot + impoVoli;		    
		}
		
		
		try {
		    //applico l'eventuale sconto prenota prima
		    var dblSconto;
		    dblSconto=document.getElementById('scontoEalyBooking').value;
		    mioTot=mioTot + parseFloat(dblSconto.toString().replace(',','.'));
		}
		catch(ex) {
		    //non è presente lo sconto
		}
		
		m.totale.value=mioTot.arrotonda(2).toString().replace('.',',');
		if (bUnaSistemazioneScelta==false && chkCongruenza==0 && m.tipoProdotto.value=='1') m.totale.value=''; //'--n/a--';
		if (mioTot <=0) {return false;}
		if (  ((chkCongruenza==1) && (bVociConMax==true && (mioTotNpax < (adt + chd))) ) ) {return false;}
		if (  ((chkCongruenza==1) && (bVociConMax==false && (mioTotNpax != (adt + chd))) ) ) {return false;}
		
		return true;
	}
	
	catch(ex)
	{
	//	alert(ex.message);
		return false;
	}
}


function chkDisponibilita(idhotel)
{
    var i,m, qta, qtaDis,desMessage;
    m=document.getElementById('moduloHotel' + idhotel);
    for (i=1;i<=m.numvoci.value -1;i++)
	{	
		try
		{
		    qta=eval('m.qta' + i + '.value');
		    qtaDis=document.getElementById('dispoVoce_' + i).getAttribute('Disponibilita');
		    desMessage=document.getElementById('dispoVoce_' + i).getAttribute('descrizioneTool');
		    document.getElementById('dispoVoce_' + i).className='WB';
		    if(parseInt(qta) > parseInt(qtaDis) || parseInt(qtaDis)<=0)
		    {
		        document.getElementById('dispoVoce_' + i).className='WBVoceNonDisponibile';
		    }
		}
		catch(w)
		{}
	}
}

function chkToolDisponibilita(obj,kVoce,idH)
{
	var qta, qDisp,desMessage;
	qta=document.getElementById('qta' + idH + '_' + kVoce).value;
	qDisp=obj.getAttribute('Disponibilita');
	desMessage=obj.getAttribute('descrizioneTool');
	if (qta>qDisp || qDisp <=0) {mostratool(desMessage,280,'html'); }
}


function suggerisciRiduzioni(idhotel,adt,chd,inf)
{
    try
	{
	    var m, qta, nPax,mioTotNpax,nTipoVoce,bContieneRidChd,nFlagAllotment ;
		m=document.getElementById('moduloHotel' + idhotel);
		mioTotNpax=0;
		bContieneRidChd=false;
		var iNdoppie, iNsingole, iNtriple,iNquadruple,iPaxRestanti,iTotPax
		iNdoppie=0; iNsingole=0; iNtriple=0; iNquadruple=0;
		iTotPax=parseInt(adt) + parseInt(chd);
		
		// vedo quante sono le singole, doppie, triple e quadruple selezionate //
		for (i=1;i<=m.numvoci.value -1;i++)
			{	
				
				nPax=eval('m.npax' + i + '.value');
				nTipoVoce=eval('m.tipovoce' + i + '.value');
			    qta=eval('m.qta' + i + '.value');
			    if (parseInt(nTipoVoce)==11) bContieneRidChd=true;
				switch (parseInt(nPax))
			        {
			            case 1:
			                if (qta != '' && qta>0) iNsingole = parseInt(iNsingole) + parseInt(qta);
			                break;
			            case 2:
			                if (qta != '' && qta>0) iNdoppie = parseInt(iNdoppie) + parseInt(qta);
                            break;
                        case 3:
			                if (qta != '' && qta>0) iNtriple = parseInt(iNtriple) + parseInt(qta);
			                break;
			            case 4:
			                if (qta != '' && qta>0) iNquadruple = parseInt(iNquadruple) + parseInt(qta);
			                break;
			        }    
			}
			
			//  calcolo il numero di riduzioni necessarie   //		     
		    var adtFatto, chdFatto, infFatto, iNridADT, iNridCHD, iNridINF, numVoci;
			adtFatto=0; chdFatto=0; infFatto=0; iNridADT=0; iNridCHD=0; iNridINF=0;
			numVoci=m.numvoci.value;
		    if(iNtriple + (2 * iNquadruple) > 0 && chd >0) iNridCHD = chd ;
		    if(iNtriple + (2 * iNquadruple) < iNridCHD ) iNridCHD=iNtriple + (2 * iNquadruple);
		    if(iNtriple + (2 * iNquadruple) - iNridCHD  >0) iNridADT = iNtriple + (2 * iNquadruple) - iNridCHD  ;
		    
		    iNridINF=inf;
		    
			if (bContieneRidChd==false) {iNridADT=iNridADT + iNridCHD ; iNridCHD=0};
			var z;
			for (z=1;z<=10;z++)
			{					
		        nPax=eval('m.npax' + z + '.value');
				nTipoVoce=eval('m.tipovoce' + z + '.value');
			    switch (parseInt(nTipoVoce))
		           {
		               case 10:  // 3°/4° letto ADT
		                   if (adtFatto==0) { eval('m.qta' + z + '.value=' + iNridADT); adtFatto=1; if (iNridADT>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + z).style.display='';} }
		                   break;
		               case 11:   // 3°/4° letto CHD
		                   if (chdFatto==0) { eval('m.qta' + z + '.value=' + iNridCHD); chdFatto=1;if (iNridCHD>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + z).style.display='';} }
                           break;
                       case 12:  // 3°/4° letto CHD Free
					   	   //if (infFatto==0) { eval('m.qta' + z + '.value=' + iNridINF); infFatto=1;if (iNridINF>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + z).style.display='';} }
					   	   break;
					}
		    }	
		return true;
	}
	catch(ex)
	{
		//alert(ex.message);
		return false;
	}
}


function suggerisciSistemazione(idhotel, adt, chd, inf, iControllaPax)
{
	if (globalWBAttivaSpecificheCamera==1) {
    	//vengono eseguite via server
    	try {MostraNascondiRigheTabella(document.getElementById('rigaPrezzo' + idhotel + '_1'),'none');} catch(oo) {}
	    suggerisciRiduzioni(idhotel, adt, chd,inf);
	    return true;
	}  
	if (iControllaPax=='1' || iControllaPax=='-1') {return true;}
	try
	{
		var m, qta, numGiorni, uPP, uG, mioTot, prezzo,nPax,mioTotNpax,nTipoVoce,bVociConMax,nFlagAllotment ;
		m=document.getElementById('moduloHotel' + idhotel);
		m.totale.value="";
		numGiorni=m.numgiorni.value;
		mioTotNpax=0;
		mioTot=0;
		bVociConMax=false;
		var MaxNpax, okSingola, okDoppia, okTripla, okQuadrupla;
		var iNdoppie, iNsingole, iNtriple,iNquadruple,iPaxRestanti,iTotPax
		iNdoppie=0; iNsingole=0; iNtriple=0; iNquadruple=0;
		MaxNpax=0; okSingola=0 ; okDoppia=0;  okTripla=0;  okQuadrupla=0;
		iTotPax=parseInt(adt) + parseInt(chd);
		iPaxRestanti=iTotPax;
		for (i=1;i<=m.numvoci.value -1;i++)
			{	
				nPax=eval('m.npax' + i + '.value');
				nTipoVoce=eval('m.tipovoce' + i + '.value');
			    if (nPax > MaxNpax) { MaxNpax = nPax} ;
			    if (nPax==1) {okSingola=1};
			    if (nPax==2) {okDoppia=1};
			    if (nPax==3) {okTripla=1};
			    if (nPax==4) {okQuadrupla=1};			    
			}
		if (okQuadrupla==1)
		    {
		        iNquadruple=0;
		        if (iTotPax >= 4) {iNquadruple=Math.floor(iTotPax / 4)} ;
		        iPaxRestanti=iTotPax - (4 * iNquadruple) ;
		    }
		if (okTripla==1)
		    {
		        if (iPaxRestanti >= 3) {iNtriple=Math.floor(iPaxRestanti / 3)} ;
		        iPaxRestanti=iPaxRestanti - (3 * iNtriple) ;
		    }
		if (okDoppia==1)
		    {
		        if (iPaxRestanti >= 2) {iNdoppie=Math.floor(iPaxRestanti / 2)} ;
		        iPaxRestanti=iPaxRestanti - (2 * iNdoppie) ;
		    }
		if (okSingola==1)
		    {
		        if (iPaxRestanti >= 1) {iNsingole=Math.floor(iPaxRestanti)} ;
		        iPaxRestanti=0;
		    }
	
		var sOK, dOK, tOK,qOK;
		sOK=0;  dOK=0; tOK=0; qOK=0;
		for (i=1;i<=m.numvoci.value -1;i++)
			{	
				nPax=eval('m.npax' + i + '.value');
				nTipoVoce=eval('m.tipovoce' + i + '.value');
				if (GLOBAL_SoloVociSistemazioneEconomica=='1' ) {
				    if(i==1) MostraNascondiRigheTabella(document.getElementById('rigaPrezzo' + idhotel + '_' + i),'none');
				}
				switch (parseInt(nPax))
			        {
			            case 1:
			                if (sOK==0) {eval('m.qta' + i + '.value=' + iNsingole); sOK=1; if (iNsingole>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + i).style.display='';}}
			                break;
			            case 2:
			                if (dOK==0) {eval('m.qta' + i + '.value=' + iNdoppie); dOK=1; if (iNdoppie>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + i).style.display='';}}
                            break;
                        case 3:
			                if (tOK==0) {eval('m.qta' + i + '.value=' + iNtriple); tOK=1; if(iNtriple>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + i).style.display='';}}
			                break;
			            case 4:
			                if (qOK==0) {eval('m.qta' + i + '.value=' + iNquadruple); qOK=1;if (iNquadruple>0) {document.getElementById('rigaPrezzo' + idhotel + '_' + i).style.display='';}}
			                break;
			        } 
			}		
		suggerisciRiduzioni(idhotel, adt, chd,inf);
		return true;
	}
	catch(ex)
	{
		alert('...' + ex.message);	
		return false;
	}
}


function MostraNascondiRigheTabella(TR,display)
{
    //------ nasconde le righe della tabella prezzi tranne quelle con attributo VisualizzaSempre=1 -------
    var M;
    M=TR.parentNode
    if (M.nodeName.toLowerCase()=='tbody' || M.nodeName.toLowerCase()=='table' )
    {
        for (var ii=0;ii<M.childNodes.length;ii++)
        {
            if (M.childNodes[ii].nodeName.toLowerCase()=='tr')
            {
                var vSempre;
                vSempre=M.childNodes[ii].getAttribute('VisualizzaSempre');
                if (vSempre !='1' && M.childNodes[ii].className.toLowerCase() !='rigatotalitariffa' && M.childNodes[ii].className.toLowerCase() !='rigaintestazionetariffa') {M.childNodes[ii].style.display=display;}
            }
        }
    }
}

function WBDisplayDatiFattura(obj)
{
	if(obj.checked)
		{obj.value='YES';document.getElementById('bloccoDatiFatturazione').style.display='block';}
	else
		{obj.value='NO';document.getElementById('bloccoDatiFatturazione').style.display='none';}
}



function prenotaHotel(azione,idhotel, adt, chd,inf,DisableCheckPax,objSubmit)
{
	try
	{
		if (calcolaTotaleTariffa(idhotel, adt, chd,inf, 1))
			{
				var oForm,possoAndare;
				oForm=document.getElementById('moduloHotel' + idhotel);
				possoAndare=true;
				
				for (i=1;i<=oForm.numvoci.value -1 && azione !='variahotel';i++)   //controllo se ci sono valori selezionati e non consentiti
	             {       
            		try
		             {  
		                var objSpan;
    		            objSpan=document.getElementById('qta' + idhotel + '_' + i);
	                    if (objSpan.tagName.toUpperCase().indexOf("SELECT")>=0) {
	                        var vNonOK;
	                        vNonOK=objSpan.options[objSpan.selectedIndex].getAttribute('NonConsentito');	                        
	                        if (parseInt(vNonOK)==1 || parseInt(vNonOK)==-1) { mostraAvvisoFisso(objSpan,Lang_JS04);possoAndare=false;  };
	                    };		    
		             }
                    catch(e)
                     {}	
                     
                    try
                    { 
                    var nQtaVoce,sDipendenze,objParametri,objQta;
    		        objQta=document.getElementById('qta' + idhotel + '_' + i)
    		        nQtaVoce=objQta.value;
	                // leggo i parametri di questa voce .. es. dipendenze, età minima e massima etc...    
	                objParametri = document.getElementById('parametri_' + idhotel + '_' + i);
	                sDipendenze=objParametri.getAttribute('dipendenza');
	                
	                if (nQtaVoce >0 && sDipendenze !='') {
	                    // verifico se le dipendenze sono soddisfatte.	                    
	                    if (chkDipendenze(idhotel, oForm.numvoci.value -1, i)==false) {mostraAvvisoFisso(objQta,Lang_JS05);possoAndare=false;}
	                }	                                     
                    }
                    catch(e)
                    {}
                }
	            if (possoAndare==false){ return false;}
	            
				memorizzaHotel(idhotel,1,objSubmit); return true;  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
				
				displayPopup(Lang_JS11);
				oForm.azione.value=azione;
				if(objSubmit) objSubmit.disabled=true;
				oForm.submit();
				
			}
			else
			{
				if (DisableCheckPax==1 || DisableCheckPax==-1)
				{
				
				memorizzaHotel(idhotel,1,objSubmit); return true;  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
				
				var oForm;
				oForm=document.getElementById('moduloHotel' + idhotel);
				oForm.azione.value=azione;
				oForm.submit();
				return;
				}				
				alert(Lang_JS02);
			}			
	}
	catch(ex)
	{		
	}
}


function chkDipendenze(idhotel, nVoci, nVoceCheck)
{
    // Segna le voci che dipendono dalla corrente e che non sono state scelte  //
    // Se le dipendenze sono OK (voci selezionate) non segna nulla e ritorna true
    var nQtaVoce,sDipendenze,objParametri,nIdVoce,matDipendenze,i,k,nIdVoceCheck,valRitorno;
    objParametri = document.getElementById('parametri_' + idhotel + '_' + nVoceCheck );
    sDipendenze=objParametri.getAttribute('dipendenza');
    sVoceCheck='<b>' + objParametri.getAttribute('testoVero') + '</b>'; 
    if (sDipendenze.substring(sDipendenze.length -1,sDipendenze.length)==']') {sDipendenze=sDipendenze.substring(0,sDipendenze.length -1);}  //tolgo l'ultimo carattere
    if (nVoci==0) nVoci=document.getElementById('moduloHotel' + idhotel).numvoci.value -1;
    
    matDipendenze=sDipendenze.split(']');
    valRitorno=true;
    
    for (k=0;k<matDipendenze.length;k++)
    {
        nIdVoceCheck=matDipendenze[k];
        nIdVoceCheck=nIdVoceCheck.replace('[','');
        for (i=1;i<=nVoci;i++)
        {       
    		nQtaVoce=document.getElementById('qta' + idhotel + '_' + i).value;
    		if (nQtaVoce=='' || nQtaVoce=='null') {nQtaVoce=0;}
	        // leggo i parametri di questa voce .. es. dipendenze, età minima e massima etc...    
	        objParametri = document.getElementById('parametri_' + idhotel + '_' + i);
	        nIdVoce=objParametri.getAttribute('idVoce');
	        if (nIdVoce==nIdVoceCheck && parseInt(nQtaVoce) <=0) {
	            // dipendenza non soddisfatta 
	            mostraAvvisoFisso(document.getElementById('qta' + idhotel + '_' + i),Lang_JS06 + ' ' + sVoceCheck);
	           valRitorno=false;
	        }	             
	    }
    }
    return valRitorno;
}


function aggiungiHotel(idhotel, adt, chd,objSubmit)
{
	var oForm;
	displayPopup(Lang_JS11);
	oForm=document.getElementById('moduloHotel' + idhotel);
	oForm.azione.value='aggiungihotel';
	if(objSubmit) objSubmit.disabled=true;
	oForm.submit();
}


function checkNomi()
{
	try
	{
		//inserire il controllo di obbligatorietà della data di nascita dei bambini
		var elenco, matT, i, obj, obj2,oNomi;
		oNomi=document.getElementById("elencoTextboxNomi");
		if (!oNomi) {return true;}
		elenco=oNomi.value;
		matT=elenco.split(";");
		i=0
		while (i < matT.length)
 			{				 
				if (matT[i].length >0) 
				{
				obj=document.getElementById('txtCognome' + matT[i])
				obj2=document.getElementById('txtNome' + matT[i])
				 if (obj.value.length < 3 || obj2.value.length < 3) 
				 	{
						mostraAvvisoFisso(obj,Lang_JS08);
						return false;
					}				
				}
			  i+=1;
			}
		return true;
	}
	catch (ex)
	{
		alert("---" + ex.message)
		return false;
	}
}

function WB_CheckValoriCombo(idHotel,SkipCheck,objSubmit)
{
	var k,n,i,obj,objD;
	n=document.getElementById('moduloHotel' + idHotel).numvoci.value;
	i=1;
	while (i < n)
 		{
			obj=eval('document.getElementById(\'moduloHotel' + idHotel + '\').qta' + i);
			objD=eval('document.getElementById(\'moduloHotel' + idHotel + '\').desQta' + i);
			if(obj.type.toLowerCase().indexOf('select') >=0)
				{
					for (k=0;k<obj.options.length;k++)
					{
						if (obj.selectedIndex==k) {objD.value=obj.options[k].text;};
						if (obj.options[k].getAttribute('NonConsentito') !=0 && obj.selectedIndex==k)
						{	mostraAvvisoFisso(obj,Lang_JS09); return false;}
					}
				}			
			i+=1;
		}
return true;
}

function memorizzaHotel(idHotel,SkipCheck,objSubmit)
{
	if (SkipCheck !=1 && SkipCheck !=-1) { if (!checkNomi()) {return false;} }
	if (WB_CheckValoriCombo(idHotel,SkipCheck,objSubmit) == false) {return false;}
	//if (confirm(Lang_JS14))
	//	{
			displayPopup(Lang_JS11); // elaborazione in corso
	        if(objSubmit) objSubmit.disabled=true;
			document.getElementById('moduloHotel' + idHotel).azione.value='memorizzahotel';
			document.getElementById('moduloHotel' + idHotel).submit();
	//	}
}

function WB_AnnullaPrenotazione(msg,lnk)
{
	if (confirm(msg)) {
		document.location.href=lnk;		
	}
}

function WB_MemorizzaPrenotazione(msg,oForm)
{
	
	if (!checkNomi()) {return false;}
	
	var sCF,sPIVA      //P.IVA o Cod. Fisc.     
	//-----------verifica dei valori immessi-------------------------
 	if (! validaValoreCampo(oForm.RagSoc,3,60,'','Ragione sociale') ) {return false;}
 	if (! validaValoreCampo(oForm.Via,3,60,'','Indirizzo') ) {return false;}
 	if (! validaValoreCampo(oForm.Comune,2,30,'','Comune') ) {return false;}
 	if (! validaValoreCampo(oForm.Provincia,2,30,'','Provincia') ) {return false;} 	
	if (! validaValoreCampo(oForm.email,5,30,'','Email') ) {return false;} 	
	
	sCF=oForm.CF.value; sPIVA=oForm.PIVA.value;
	if (sCF != '') {if (sCF.length != 16) {alert('Inserire il Codice Fiscale corretto.');return false; } }	
	if (sCF =='' || sPIVA != '') { if (! validaValoreCampo(oForm.PIVA,11,16,'','Partita Iva') ) {return false;}  }
		
	if(oForm.RichiestaFattura.checked==true)
	{
		// --------- Dati per la fatturazione -------------------------------------------- s//
		if (! validaValoreCampo(oForm.RagSocFatturazione,3,60,'','Ragione sociale Fatturazione') ) {return false;}
		if (! validaValoreCampo(oForm.ViaFatturazione,3,60,'','Indirizzo Fatturazione') ) {return false;}
		if (! validaValoreCampo(oForm.ComuneFatturazione,2,30,'','Comune Fatturazione') ) {return false;}
		if (! validaValoreCampo(oForm.ProvinciaFatturazione,2,30,'','Provincia Fatturazione') ) {return false;} 	
		sCF=oForm.CFFatturazione.value; sPIVA=oForm.PIVAFatturazione.value;
		if (sCF != '') {if (sCF.length != 16) {alert('Inserire il Codice Fiscale Fatturazione corretto.');return false; } }	
		if (sCF =='' || sPIVA != '') { if (! validaValoreCampo(oForm.PIVAFatturazione,11,16,'','Partita Iva Fatturazione') ) {return false;}  }			
	}
	
	
	// ----- dati per prodotti in prenotazione -------------  //
	var sElencoID,aryID,n,sIdElemento,oElemento;
	var lMin,lMax,tipoDati,sNomeCampo,bObbligatorio;
	sElencoID=document.getElementById('ElencoIdCampiRichiesti').value;
	aryID=sElencoID.split(';');
	for (n=0;n<aryID.length;n++)
	{
		sIdElemento=aryID[n];
		if (sIdElemento.length >0)
		{
			oElemento=document.getElementById(sIdElemento);
			try
			{
			lMin=oElemento.getAttribute('lMin');
			lMax=oElemento.getAttribute('lMax');
			tipoDati=oElemento.getAttribute('tipoDati');
			bObbligatorio=oElemento.getAttribute('obbligatorio');
			if (bObbligatorio=='1' || bObbligatorio=='-1') {bObbligatorio=true;} else {bObbligatorio=false;}
			sNomeCampo=oElemento.getAttribute('nomeCampo');		
			
			if (! validaValoreCampo(oElemento,lMin,lMax,tipoDati,sNomeCampo,bObbligatorio) ) {return false;}
			}
			catch(ss)
			{}
		}
	}
	
	if(confirm(msg))
        {
            oForm.memorizza.disabled=true;
			displayPopup(Lang_JS12);
			globalWBMemForm=oForm;
			setTimeout('submitFormWB()',600);
        }
}

function submitFormWB()
{globalWBMemForm.submit();}

function WB_MostraSchedaProdotto(idProdotto)
{
    var i;
    i=0;
	while (i < 30)
 		{
 		  try
 		    {
 		        document.getElementById('divWBProdotto' + i).style.display='none';
 		        document.getElementById('CellaTabPulsantiAltriProdotti' + i).className='CellaTabPulsantiAltriProdotti';
 		    }
 		   catch(ex)
 		    {
 		    }
		  i+=1;
		}
		document.getElementById('divWBProdotto' + idProdotto).style.display='block';
		document.getElementById('CellaTabPulsantiAltriProdotti' + idProdotto).className='CellaTabPulsantiAltriProdottiAttiva';
}

function WB_AggiungiServizioSingolo(strForm,data, idVoce,k)
{
    var oForm, tipoP, idP, dalCercato, alCercato, nVoci, nGiorni, tariffa, sVoce, sData,iQta;
    oForm=document.getElementById(strForm);
    tariffa=oForm.tariffa.value;
    tipoP=oForm.tipoProdotto.value;
    nVoci=oForm.numvoci.value;
    idP=oForm.idHotel.value;
    sVoce=document.getElementById('desVoce' + tipoP + '_' + k).getAttribute('testoVero');
    //sVoce=TestoDaHtml(sVoce);  //--questa istruzione  incasina la funzione....
    sData=data.toString();
    sData=sData.substring(6,8) + '/' + sData.substring(4,6) + '/' + sData.substring(0,4);
    iQta=0;
	try
		{
			iQta=eval('oForm.qta' + k + '.value');
			if (iQta=='') iQta=0;
			if (iQta <=0) {alert(Lang_JS03); return; }
		}
	catch(ee)
		{}
		
	if (confirm(Lang_JS14 + '\n\n' + Lang_JS16 + ': ' + iQta + '\n' + Lang_JS15 +': ' + sVoce + '\n' + Lang_JS17 + ': ' + sData ))
    {
        var qString ='wb_actionAjax.asp?azione=aggiungisingoloservizio';
        qString =qString + '&qtaScelta=' + iQta ;
        qString =qString + '&dataScelta=' + data ;
        qString =qString + '&idVoceScelta=' + idVoce ;
        qString =qString + '&idHotel=' + idP ;
        qString =qString + '&tipoProdotto=' + tipoP ;
        qString =qString + '&desQtaScelta=' + eval('oForm.desQta' + k + '.value') ;
        //alert(qString);
        AJAX(qString ,esitoAggiungiSingoloServizio);          
    }
}

function esitoAggiungiSingoloServizio(w)
{
    displayPopup(w);
}

function WB_EliminaHotel(act)
{
    if (confirm(Lang_JS18))
    {
        location.href=act;    
    }
}

function WB_CancellaServizio(act)
{
    if (confirm(Lang_JS19))
    {
        location.href=act;    
    }
}

function WB_MostraDiv(blocco)
{ document.getElementById(blocco).style.display="block";}

function WB_NascondiDiv(blocco)
{ document.getElementById(blocco).style.display="none";}

function WB_MostraRicercaHotel(valoreProdotto,idBlocco,bSubmit,initCB)
{
	var matDiv,i;
	document.getElementById('BloccoMenuRicercaLoading').style.display='none';
	matDiv=WB_ElencoDivRicerca.split(',');
	for(i=0;i<matDiv.length;i++ ) 	{document.getElementById('WBPulsCerca' + matDiv[i]).className='CellaPulsantiBloccoRicerca'; 	}
	document.getElementById('WBPulsCerca' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';
	document.getElementById('WBIntestazioneCercaHotel').innerHTML='HOTEL';
	modu=document.getElementById('moduloWBMenuCercaHotel')
	document.getElementById('RigaRicercaTipologiaHotel').style.display='';
    modu.wbcurrentdivcerca.value=idBlocco;
	document.getElementById('BloccoMenuRicercaHotel').style.display="block";
    document.getElementById('BloccoMenuRicercaAltri').style.display="none";
    document.getElementById('BloccoMenuRicercaPacchetti').style.display="none";	
    if (initCB==true) {initComboWB(false,0,valoreProdotto)}
}

function WB_MostraRicercaHotelSeparati(valoreProdotto,idBlocco,bSubmit,initCB,sTitolo)
{
	var matDiv,i;
	document.getElementById('BloccoMenuRicercaLoading').style.display='none';
	matDiv=WB_ElencoDivRicerca.split(',');
	if (document.getElementById('WBPulsCercaHTL' + idBlocco).getAttribute('richiediVoli') !='0') {
	    // GESTIONE COME HOTEL + VOLO (PACCHETTO)
	    WB_MostraRicercaPacchetti(-2,'VoliHotel',!initCB,sTitolo,idBlocco);
	    for(i=0;i<matDiv.length;i++ ) 	{document.getElementById('WBPulsCerca' + matDiv[i]).className='CellaPulsantiBloccoRicerca'; 	}
	    document.getElementById('WBPulsCercaHTL' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';
	    modu=document.getElementById('moduloWBMenuCercaPacchetti')
	    modu.wbcurrentdivcerca.value='HTL' + idBlocco;
	    document.getElementById('wbCercaTipologiaHotelVoli').value=idBlocco;
	    //document.getElementById('WBCercaTipologiaPacchetto').value=document.getElementById('WBPulsCercaHTL' + idBlocco).getAttribute('comePacchetto');			    
	}
	else {
	    // GESTIONE COME SEMPLICE HOTEL 
	    for(i=0;i<matDiv.length;i++ ) 	{document.getElementById('WBPulsCerca' + matDiv[i]).className='CellaPulsantiBloccoRicerca'; 	}
	    document.getElementById('WBPulsCercaHTL' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';
	
	    modu=document.getElementById('moduloWBMenuCercaHotel')
        modu.wbcurrentdivcerca.value='HTL' + idBlocco;
	    document.getElementById('WBIntestazioneCercaHotel').innerHTML=sTitolo;
	    document.getElementById('WBCercaTipologiaHotel').value=idBlocco;
	    document.getElementById('RigaRicercaTipologiaHotel').style.display='none';
	    document.getElementById('BloccoMenuRicercaHotel').style.display="block";
        document.getElementById('BloccoMenuRicercaAltri').style.display="none";
        document.getElementById('BloccoMenuRicercaPacchetti').style.display="none";	
        document.getElementById('WBCercaTipologiaPacchetto').value=document.getElementById('WBPulsCercaHTL' + idBlocco).getAttribute('comePacchetto');		
        if (initCB==true) {initComboWB(false,0,valoreProdotto)}
    }
}

function WB_MostraRicercaPacchetti(valoreProdotto,idBlocco,bNonEseguireInitCombo,testo,iTipologiaHotel)
{
    var matDiv,i;
    if (!iTipologiaHotel || iTipologiaHotel==null) {iTipologiaHotel='0';}
    document.getElementById('BloccoMenuRicercaLoading').style.display='none';
	matDiv=WB_ElencoDivRicerca.split(',');
	for(i=0;i<matDiv.length;i++ ) 	{document.getElementById('WBPulsCerca' + matDiv[i]).className='CellaPulsantiBloccoRicerca'; 	}
	if (idBlocco=='') {return;}
	document.getElementById('WBPulsCerca' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';
	try {document.getElementById('WBIntestazioneCercaProdotto').innerHTML=ReplaceTags(document.getElementById('WBPulsCerca' + idBlocco).innerHTML);} catch(exc){};
	modu=document.getElementById('moduloWBMenuCercaPacchetti')
    modu.wbcurrentdivcerca.value=idBlocco;
    document.getElementById('BloccoMenuRicercaHotel').style.display="none";
    document.getElementById('BloccoMenuRicercaAltri').style.display="none";    
	document.getElementById('BloccoMenuRicercaPacchetti').style.display="block";
	
	if (document.getElementById('WBPulsCerca' + idBlocco).getAttribute('dateFisse')=='1' || document.getElementById('WBPulsCerca' + idBlocco).getAttribute('dateFisse')=='-1') {
	    // ---- date fissate -----
	    document.getElementById('rigaDatePartenze').style.display='';
	    document.getElementById('rigaRicercaDalPacchettiWB').style.display='none';
	    document.getElementById('rigaRicercaAlPacchettiWB').style.display='none';
	}
	else
	{   // --- date libere ----
	    document.getElementById('rigaDatePartenze').style.display='none';
	    if (idBlocco=='VoliHotel') {  //volo + hotel
	    document.getElementById('rigaRicercaDalPacchettiWB').style.display='none';
	    document.getElementById('rigaRicercaAlPacchettiWB').style.display='none';
	    }
	    else { 
	    document.getElementById('rigaRicercaDalPacchettiWB').style.display='';
	    document.getElementById('rigaRicercaAlPacchettiWB').style.display='';	    
	    }	    
	}
	
	if (valoreProdotto != -1)
	{		
		document.getElementById('WBCercaTipologiaPacchetto').value=valoreProdotto;
		document.getElementById('WBPulsCerca' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';	
	};
	try {
	document.getElementById('WBCercaTipologiaHotelVoli').value=iTipologiaHotel;  //Attenzione! verificare xke su Firefox e Safari non funziona
	}
	catch(oo)
	{alert('Attenzione! Il sito è ottimizzato per l\'uso di Microsoft Internet Explorer 6.0 o superiore.\nIl tuo browser non è supportato.'); }
	//if (bNonEseguireInitCombo) {submitWBRicerca('nuovaricerca',document.getElementById('WBCercaTipologiaPacchetto').form);}
	var veroValoreProdotto=valoreProdotto;
	if (valoreProdotto='-1') {veroValoreProdotto=document.getElementById('WBCercaTipologiaPacchetto').value;}
	if (bNonEseguireInitCombo==false) {initComboWB(true,idBlocco,veroValoreProdotto)}
}

function WB_MostraRicercaAltri(valoreProdotto,idBlocco,bSubmit)
{
    var matDiv,i;
    document.getElementById('BloccoMenuRicercaLoading').style.display='none';
	matDiv=WB_ElencoDivRicerca.split(',');
	for(i=0;i<matDiv.length;i++ ) 	{document.getElementById('WBPulsCerca' + matDiv[i]).className='CellaPulsantiBloccoRicerca'; 	}
	document.getElementById('WBPulsCerca' + idBlocco).className='CellaAttivaPulsantiBloccoRicerca';
	
	modu=document.getElementById('moduloWBMenuCercaAltri')
    modu.wbcurrentdivcerca.value=idBlocco;
	document.getElementById('BloccoMenuRicercaHotel').style.display="none";
    document.getElementById('BloccoMenuRicercaPacchetti').style.display="none";	
    document.getElementById('BloccoMenuRicercaAltri').style.display="block"; 
    if (valoreProdotto !='-1') {chkTipologiaAltriProdotti(document.getElementById('WBCercaTipologiaAltri').value, document.getElementById('WBCercaTipologiaAltri').form.id);    }
}

function submitWBRicerca(azione,modulo)
{ 
	var x;	
	if (azione == 'nuovaricerca') x=document.getElementById("localitaMenuCerca");
	if (azione == 'nuovaricercaaltri') 	x=document.getElementById("localitaMenuCercaAltri");	
	modulo.azione.value='nuovaricerca';
	//verifica ricerca hotel
	if (modulo.id=='moduloWBMenuCercaHotel') {
		if (globalWBAttivaSpecificheCamera==1) { 
			if (document.getElementById('numeroCamereHotel').value==0) {mostraAvvisoFisso(document.getElementById('numeroCamereHotel'),Lang_JS01);return false;}
			if (chkPaxCamera(null, 'H',null)==false) {mostraAvvisoFisso(document.getElementById('numeroCamereHotel'),Lang_JS29);return false;}
		}
	    if (document.getElementById('gruppolocalitaMenuCerca').selectedIndex==0 && document.getElementById('localitaMenuCerca').selectedIndex==0 && document.getElementById('WBCercaTipologiaHotel').selectedIndex==0) {
	        mostraAvvisoFisso(document.getElementById('gruppolocalitaMenuCerca'),Lang_JS01);
	        return false;
	        }
	}
	//verifica ricerca pacchetti
	var obj,vl;
	obj=document.getElementById('WBCercaTipologiaPacchetto');
	vl='0';
    if (obj) {vl=obj.value;}
    var dateFissate,VoloHotel,RichiediSistemazione;
    
    dateFisse=getValoreParametro('DateFissate',document.getElementById('opzioniprodottocorrente').value);
    RichiediSistemazione=getValoreParametro('RichiediSistemazione',document.getElementById('opzioniprodottocorrente').value);
    VoloHotel=getValoreParametro('VoloPiuHotel',document.getElementById('opzioniprodottocorrente').value);

	if (modulo.id=='moduloWBMenuCercaPacchetti') {
		if ((globalWBAttivaSpecificheCamera==1 && RichiediSistemazione !='0' && RichiediSistemazione !='') || VoloHotel=='1') { 
			if (document.getElementById('numeroCamerePacchetti').value==0) {mostraAvvisoFisso(document.getElementById('numeroCamerePacchetti'),Lang_JS01);return false;}		
			if (chkPaxCamera(null, 'P',null)==false) {mostraAvvisoFisso(document.getElementById('numeroCamerePacchetti'),Lang_JS29);return false;}
		}
	    
	    if (document.getElementById('gruppolocalitaPacchettiMenuCerca').selectedIndex==0 && document.getElementById('localitaPacchettiMenuCerca').selectedIndex==0) {
	        mostraAvvisoFisso(document.getElementById('localitaPacchettiMenuCerca'),'--' + Lang_JS01);	        
	        return false;
        }
        
        if (VoloHotel=='1') {
            //verifiche pacchetti con voli
	        if (chkVoliSelezionati()==false) {
	            alert(Lang_JS25); //selezionare il volo
	            return false;
	        }
	    }
	}
	
	disabilitaRisultatiRicerca(Lang_JS11);
	//displayPopup(Lang_JS11);
	mostraMenuWebBooking(false);
	setTimeout(function(){modulo.submit();},100);
}


function disabilitaRisultatiRicerca(testo)
{
    var oChk;
    try
    {
        oChk=document.getElementById('parametriRicerca').innerHTML;
        if (oChk !='null') {
            var oResult, oHideResult;
	        oResult=document.getElementById('bloccoRisultatiRicerca');
	        oHideResult=document.getElementById('bloccoNascondiRisultatiRicerca');
	        oHideResult.style.top=0;
	        oHideResult.style.left=0;
	        oHideResult.style.width=oResult.clientWidth + 'px';
	        oHideResult.style.display='block';
	        oHideResult.style.height=oResult.clientHeight + 'px';
	        oHideResult.innerHTML='<span>' + testo + '</span>';	        
	    }
	}
	catch(p)
	{}
	return true;	
}


function MostraHotelPerLocalita(link)
{
    var o;
    o=document.getElementById('gruppolocalitaMenuCerca');
    if(o.value=='0') {mostraAvvisoFisso(o,Lang_JS13); return false;}
    location.href=link + '&zona=' + o.value;
}

function WB_AggiornaData(idObjInizio,idObjFine)
{
    var data1=document.getElementById(idObjInizio).value;
    var data2=document.getElementById(idObjFine).value;
    if (data1=="") return true;
    var oggetto2,gg,mm,aaaa;
    var oggetto1=new Date(parseInt(data1.substr(6)) ,parseInt(data1.substr(3, 2)-1),parseInt(data1.substr(0, 2)));
    if (data2=="") {oggetto2=new Date(2007,0,1) } else { oggetto2=new Date(parseInt(data2.substr(6)), parseInt(data2.substr(3, 2)-1), parseInt(data2.substr(0, 2)));  } ;
    if (oggetto2-oggetto1<0) {        
        newdate=dateAdd("d",7,oggetto1);
        gg=datePart("d",newdate); if(gg<10) {gg='0'+gg};
        mm=datePart("m",newdate);if(mm<10) {mm='0'+mm};
        aaaa=datePart("yyyy",newdate);
        document.getElementById(idObjFine).value=gg + '/' + mm + '/' + aaaa;
	    }    
}



//-------------------------denominazione delle funzioni di verifica dati, ricerca ajax e aggiornamento combo----------------------------------------------------------------------------------
//
// (chk)       tutte le funzioni che iniziano con chkXXXXXX(...) sono le funzioni attribuite all'evento onchange delle varie combo
// (cerca)     tutte le funzioni che iniziano con cercaXXXXX(...) sono le funzioni che lanciano una ricerca AJAX e che poi in maniera asyncrona lanciano le funzioni aggiornaXXXX(...)
// (aggiorna)  tutte le funzioni che iniziano con aggiornaXXXX(...) sono le funzioni invocate dalle chiamate AJAX asincrone.
//
// se si eseguono chiamate alla funzione eseguiAzioniAJAXConsecutive(elencoFunzioni) assicurarsi che in tutte le funzioni aggiornaXXXXX(...) e nelle altre eventuali funzioni
// invocate dal risultato di una chiamata AJAX sia presente come ultima istruzione eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  altrimenti non verranno eseguite le altre chiamate AJAX in standBy
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function chkTipologiaHotel(valTipo,manuale) {
    cercaGruppiLocHotel(valTipo);
}


//-----camere e pax change---

function chkAdult(o,valore)
{disabilitaRisultatiRicerca(Lang_JS24);return chkPaxChange(o,valore)}

function chkChild(o,valore)
{disabilitaRisultatiRicerca(Lang_JS24);return chkPaxChange(o,valore)}

function chkInfant(o,valore)
{disabilitaRisultatiRicerca(Lang_JS24);return chkPaxChange(o,valore)}

function chkPaxChange(o,valoreSel)
{
 if (!o) {return false;} 
 var adH, chH, adP, chP,totP,oCamP,oCamH;
 
 adH=document.getElementById('adultiHotel');
 chH=document.getElementById('childHotel');
 adP=document.getElementById('adultiPacchetto');
 chP=document.getElementById('childPacchetto');
 if(o.id.toLowerCase().indexOf('pacchetto') >0)
   {  adH.value=adP.value; chH.value=chP.value;   }
 else
   {  adP.value=adH.value; chP.value=chH.value;   } 
 
 try 
 {
    totP=parseInt(adH.value) + parseInt(chH.value);
    
    if (globalWBAttivaSpecificheCamera==1) { totP=5;}
    oCamP=document.getElementById('numeroCamerePacchetti');
    oCamH=document.getElementById('numeroCamereHotel');
    var optDefault=document.createElement('option');
    var optDefaultH=document.createElement('option'); 
 
     optDefault=oCamP.options[0];
     optDefaultH=oCamH.options[0];
     oCamP.options.length=0;
     oCamH.options.length=0;
     //  --- creo numero massimo camere per Pacchetti ----
     try { oCamP.add(optDefault, null); }  catch(ex) {oCamP.add(optDefault);}
     
     for (iJ=1; iJ<=totP; iJ++)
     {
        optDefault=document.createElement('option');
        optDefault.text=iJ;
        optDefault.value=iJ;
        try
            { oCamP.add(optDefault, null);}
        catch(ex)
            {oCamP.add(optDefault);} 
      }
      
    //  --- creo numero massimo camere per Hotel ----
     try { oCamH.add(optDefaultH, null); } catch(ex) {oCamH.add(optDefaultH);}
     
     for (iJ=1; iJ<=totP; iJ++)
     {
        optDefault=document.createElement('option');
        optDefault.text=iJ;
        optDefault.value=iJ;
        try
            { oCamH.add(optDefault, null);}
        catch(ex)
            {oCamH.add(optDefault);} 
      }
       
     if(valoreSel=='') {valoreSel=0;}
     try {oCamP.selectedIndex=parseInt(valoreSel); oCamH.selectedIndex=parseInt(valoreSel);chkSpecificheCamere(oCamH,'');chkSpecificheCamere(oCamP,'')} catch(ex) {}
}
catch(iii)
{
    //la gestione camere non è abilitata    
}
}

function chkTipoPax(obj,idRiga,numRiga)
{
 if(obj.value.toLowerCase()=='child') {
    document.getElementById('divEta' + idRiga).style.display='';    
 }
 else {
    document.getElementById('divEta' + idRiga).style.display='none';
    document.getElementById('txtEta' + numRiga).value='';
 }
}


function chkSpecificheCamere(obj,azione)
{
    if (globalWBAttivaSpecificheCamera==0 || azione=='') return;
    if (azione=='varia') disabilitaRisultatiRicerca(Lang_JS24);
    var i, k, oDiv, s, sHoP,nVal,Appartamento;
    s='';
    Appartamento=0;
    if(obj.id.indexOf('Hotel') >0) {oDiv=document.getElementById('specificheCamereHotel');sHoP='H';} else {oDiv=document.getElementById('specificheCamerePacchetti');sHoP='P';}
    if (obj.value == 0) {oDiv.innerHTML='';return;}
    
    nVal=obj.value;
	if (nVal=='1A' || nVal=='2A') {nVal=nVal.substring(0,1);Appartamento=1;}
    for (k=1;k<=nVal;k++)
    {
        var nAdt, nChd, nInf,maxAdt;
        try {nAdt=document.getElementById('adtCamera' + sHoP + k).value;} catch(ee) {nAdt=0;}
        try {nChd=document.getElementById('chdCamera' + sHoP + k).value;} catch(ee) {nChd=0;}
        try {nInf=document.getElementById('infCamera' + sHoP + k).value;} catch(ee) {nInf=0;}
        s +='<div class="divSpecificheSingolaCamera" >';
        if (Appartamento==0) {maxAdt=4;s +='<span class="nomeCameraRicerca">' + Lang_JS34;}
        if (Appartamento==1) {maxAdt=8;s +='<span class="nomeCameraRicerca">' + Lang_JS37;}
        
        s +=' ' + k + '</span><br>' + Lang_JS32 + ' ' + '<select onChange="chkPaxCamera(this,\'' + sHoP + '\')" id="adtCamera' + sHoP + k + '" name="adtCamera' + k + '"" class="mySelect" >' ;
        for (i=1;i<=maxAdt;i++)
        {
            if(i==1) {s +='<option value="0" style="background-color:red;color:#ffffff;">-</option>';}
            s +='<option value="' + i + '" ';
            if (i==nAdt) {s +=' selected ';}
            s += '>' + i + '</option>';
        }
        s +='</select>';
        // --- numero child ----
        //if (obj.form.chd.value >0)
        //{
            s +=' ' + Lang_JS33 + ' <select onChange="mostraComboEta(this,\'' + sHoP + '\',' + k + ');chkPaxCamera(this,\'' + sHoP + '\')" id="chdCamera' + sHoP + k + '" name="chdCamera' + k + '"" class="mySelect" >' ;
            for (i=1;i<=3;i++)
            {
                if(i==1) {s +='<option value="0" >-</option>';}
                s +='<option value="' + i + '" ';
                if (i==nChd) {s +=' selected ';}
                s += '>' + i + '</option>';
            }
            s +='</select>';
        //}
        //else
        //{s +='<input type="hidden" name="chdCamera' + k + '" value="0" id="chdCamera' + sHoP + k + '">';}
        
        s +='<div class="divEtaChdCamera" id="divEtaChd' + sHoP + k + '" style="display:block;">';
        
        var ii,etaVecchia,kk;
		for (ii=1;ii<=nChd;ii++) {
			if (ii>1) {s +=' - ';}
			try {etaVecchia=document.getElementById('etaChdCamera' + sHoP + k + '_' + ii).value;} catch(ee) {etaVecchia=0;}
			s += Lang_JS36 + ' ' + ii + '° ' + Lang_JS35 + ' ';
			s +='<select onChange="chkPaxCamera(this,\'' + sHoP + '\')" id="etaChdCamera' + sHoP + k + '_' + ii + '" name="etaChd' + k + '_' + ii + '"" class="mySelect" >' ;
				s +='<option value="0" style="background-color:red;color:#ffffff;" >-?-</option>';
				s +='<option value="2" '
            	if (etaVecchia==2) {s +=' selected ';}
	            s +='>&lt;=2</option>';            
    	        for (kk=3;kk<=16;kk++)
				{                
					s +='<option value="' + kk + '" ';
					if (kk==etaVecchia) {s +=' selected ';}
					s += '>' + kk + '</option>';
				}
				s +='<option value="17" >&gt;16</option>';
				s +='</select>';
		}
		s +='</div>';
        
        // numero infant -----
        //if (obj.form.inf.value >0)
        //{
        /*
            s +=' INF: <select onChange="chkPaxCamera(this,\'' + sHoP + '\')" id="infCamera' + sHoP + k + '" name="infCamera' + k + '"" class="mySelect" >' ;
            for (i=1;i<=4;i++)
            {
                if(i==1) {s +='<option value="0" >-</option>';}
                s +='<option value="' + i + '" ';
                if (i==nInf) {s +=' selected ';}
                s += '>' + i + '</option>';
            }
            s +='</select>';
        */
        //}
        //else
        //{s +='<input type="hidden" name="infCamera' + k + '" value="0" id="infCamera' + sHoP + k + '">';}
        s +='</div>';
    }
    oDiv.innerHTML=s;

    var ss=''
	if (globalWBAttivaGestioneAvanzataVoli==1) {ss+='cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');';}
	eseguiAzioniAJAXConsecutive(ss);

}

function getTotalePax(HoP,tipoPax)
{
    if (globalWBAttivaSpecificheCamera==0) {
    	// leggo dalle 3 combo
    
    	return 0;
    }
    else
    {
    	// leggo e sommo i pax di ogni singola camera
    	var i, k, obj;
		if(HoP=='H') {obj=document.getElementById('numeroCamereHotel');} else {obj=document.getElementById('numeroCamerePacchetti');}
		if (obj.value == 0) {return 0;}
		var nAdt, nChd, nInf, tAdt,tChd,tInf,etaChd;
		tAdt=0 ; tChd=0; tInf=0;
		for (k=1;k<=obj.value;k++)
		{
			try {nAdt=document.getElementById('adtCamera' + HoP + k).value;} catch(ee) {nAdt=0;}
			try {nChd=document.getElementById('chdCamera' + HoP + k).value;} catch(ee) {nChd=0;}
			//try {nInf=document.getElementById('infCamera' + HoP + k).value;} catch(ee) {nInf=0;}
			for (z=1;z<=nChd;z++) {
			    try {
			        etaChd=3;  //sotto i 2 anni l considero infant
			        try {etaChd=document.getElementById('etaChdCamera' + HoP + k + '_' + z).value;} catch(ee) {etaChd=0;}
			        if (etaChd <=2) {
			            nChd=nChd -1;
			            nInf=nInf + 1;
			        }			        
			    }
			    catch(oo) {}			
			}
			
			tAdt=parseInt(tAdt) + parseInt(nAdt);
			tChd=parseInt(tChd) + parseInt(nChd);
			tInf=parseInt(tInf) + parseInt(nInf);			
		}
		if (tipoPax.toLowerCase()=='adt') {return tAdt;}
		if (tipoPax.toLowerCase()=='chd') {return tChd;}
		if (tipoPax.toLowerCase()=='inf') {return tInf;}
		if (tipoPax.toLowerCase()=='tutti' || tipoPax.toLowerCase()=='totale') {return parseInt(tAdt) + parseInt(tChd) + parseInt(tInf);}
		if (tipoPax.toLowerCase()=='adtchd' || tipoPax.toLowerCase()=='adt+chd') {return parseInt(tAdt) + parseInt(tChd);}
		
	}
}

function chkPaxCamera(objCaller, HoP,kRiga)
{
		// verifico se è presenta almeno un adulto per camera
    	var i, k,z, obj;
		if(HoP=='H') {obj=document.getElementById('numeroCamereHotel');} else {obj=document.getElementById('numeroCamerePacchetti');}
		if (obj.value == 0) {return false;}
		var nAdt,nChd,etaChd, ritorno,nVal,Appartamento;
		ritorno=true
		nVal=obj.value;
		if (nVal=='1A' || nVal=='2A') {nVal=nVal.substring(0,1);}
		for (k=1;k<=nVal;k++)
		{
			try {nAdt=document.getElementById('adtCamera' + HoP + k).value;} catch(ee) {nAdt=0;}
			if (parseInt(nAdt)==0) {ritorno=false;}
			try {nChd=document.getElementById('chdCamera' + HoP + k).value;} catch(ee) {nChd=0;}
			//try {nInf=document.getElementById('infCamera' + HoP + k).value;} catch(ee) {nInf=0;}
			for (z=1;z<=nChd;z++) {
			    try {
			        etaChd=0;
			        try {etaChd=document.getElementById('etaChdCamera' + HoP + k + '_' + z).value;} catch(ee) {etaChd=0;}
			        if (etaChd ==0) { return false;}			        
			    }
			    catch(oo) {}			
			}
			
		}
		
		
	if (ritorno==false) {
		try {
			document.getElementById('grigliaVoliAndata').innerHTML='';
			document.getElementById('grigliaVoliRitorno').innerHTML='';
		}
		catch(xx) {}
		return false;
	}
	if (!objCaller) {return ritorno;}
	// rieseguo la ricerva dei voli
	var ss=''
	if (globalWBAttivaGestioneAvanzataVoli==1) {ss+='cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');';}
	eseguiAzioniAJAXConsecutive(ss);
}

function mostraComboEta(objCaller,HoP,kRiga)
{
	var i,k,kk,s,obj,etaVecchia;
	obj=document.getElementById('divEtaChd' + HoP + kRiga);
	obj.style.display='none';
	k=objCaller.value;
	s='';
	for (i=1;i<=k;i++) {
		if (i>1) {s +=' - ';}
		try {etaVecchia=document.getElementById('etaChdCamera' + HoP + kRiga + '_' + i).value;} catch(ee) {etaVecchia=0;}
		s += 'Eta ' + i + '° ' + Lang_JS35 + ' ';
		s +='<select onChange="chkPaxCamera(this,\'' + HoP + '\')" id="etaChdCamera' + HoP + kRiga + '_' + i + '" name="etaChd' + kRiga + '_' + i + '"" class="mySelect" >' ;
            s +='<option value="0" style="background-color:red;color:#ffffff;">-?-</option>';
            s +='<option value="2" '
            if (etaVecchia==2) {s +=' selected ';}
            s +='>&lt;=2</option>';            
            for (kk=3;kk<=16;kk++)
            {                
                s +='<option value="' + kk + '" ';
                if (kk==etaVecchia) {s +=' selected ';}
                s += '>' + kk + '</option>';
            }
            s +='<option value="17" >&gt;16</option>';
            s +='</select>';
	}
	obj.innerHTML=s;
	obj.style.display='';

}


// --------------------------
function impostaAttributiProdottoCorrente()
{
   try {
   var obj;
   obj=document.getElementById('WBCercaTipologiaPacchetto');
   AJAX('wb_actionAjax.asp?azione=opzioniprodotto&TipoProdotto=' + obj.value,aggiornaAttributiProdottoCorrente);    
   }
   catch(ss)
   {eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire); }
}
function aggiornaAttributiProdottoCorrente(w) {
    document.getElementById('opzioniprodottocorrente').value=w;
    eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire); 
}

function chkComboCercaTipologiaPacchetti(inizializzaCombo)
{   
    var obj,vl,richiediCamere,dateFisse,voloHotel;	
        obj=document.getElementById('WBCercaTipologiaPacchetto');
        
        richiediCamere=getValoreParametro('RichiediSistemazione',document.getElementById('opzioniprodottocorrente').value);
        dateFisse=getValoreParametro('DateFissate',document.getElementById('opzioniprodottocorrente').value);
        voloHotel=getValoreParametro('VoloPiuHotel',document.getElementById('opzioniprodottocorrente').value);
        vl='0';
        if (obj) {vl=obj.value;}
        if (voloHotel=='1') {
            //è un pacchetto volo + hotel
			prodottoCorrenteConVoli=true;
			document.getElementById('rigaCercaLocalitaPartenza').style.display='';
			document.getElementById('rigaDataApprossimativaRicerca').style.display='';
			//document.getElementById('rigaRicercaDalPacchettiWB').style.display='none';
			//document.getElementById('rigaRicercaAlPacchettiWB').style.display='none';
			document.getElementById('RigaRicercaAdultiPacchetto').style.display='none';
			document.getElementById('RigaRicercaChildPacchetto').style.display='none';
            document.getElementById('RigaRicercaCamerePacchetti').style.display='';
            document.getElementById('RigaSpecificheCamerePacchetti').style.display='';
            
			if (globalWBAttivaGestioneAvanzataVoli !=1) {document.getElementById('rigaDatePartenze').style.display='';}
			//mostro le righe dei voli  
			document.getElementById('rigaVoliAndata').style.display='';
			document.getElementById('rigaVoliRitorno').style.display='';
			document.getElementById('separatoreWBCerca4').style.display='';			
        }
        else {
            //non è un pacchetto volo + hotel
		    prodottoCorrenteConVoli=false;
			if (globalWBAttivaGestioneAvanzataVoli !=1) {document.getElementById('rigaDatePartenze').style.display='none';}
			document.getElementById('rigaCercaLocalitaPartenza').style.display='none';
            document.getElementById('localitaPartenzaMenuCerca').value='0';
            document.getElementById('rigaDataApprossimativaRicerca').style.display='none';
			
			//document.getElementById('rigaRicercaDalPacchettiWB').style.display='';
			//document.getElementById('rigaRicercaAlPacchettiWB').style.display='';
			
			if (richiediCamere !='1' && richiediCamere !='-1' ) {  //tipo prodotto non hotel
			    document.getElementById('RigaRicercaAdultiPacchetto').style.display='';
			    document.getElementById('RigaRicercaChildPacchetto').style.display='';
			    document.getElementById('RigaRicercaCamerePacchetti').style.display='none';
			    document.getElementById('RigaSpecificheCamerePacchetti').style.display='none';
			    
			    //document.getElementById('numeroCamerePacchetti').value='0';
			}
            //nascondo le righe dei voli
            document.getElementById('rigaVoliAndata').style.display='none';
			document.getElementById('rigaVoliRitorno').style.display='none';
			document.getElementById('separatoreWBCerca4').style.display='none';
            
            if(vl.indexOf('[')>=0 || vl=='0')
                { //è un pacchetto
                }
            else
                { //non è pacchetto
			    }   
        }         
        if (inizializzaCombo==true) {initComboWB(true,1,vl);} //viene eseguita solo se è abilitato altri prodotti in combo      
        eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire); 
}

function chkDestinazione(o)
{    
    document.getElementById('localitaMenuCerca').value=0;
    document.getElementById('localitaMenuCercaAltri').value=0;
    
    if(o.form.id.toLowerCase().indexOf('cercapacchetti')>0)
    {
        var ss=''
		//ss='chkComboCercaTipologiaPacchetti();';
		ss +='cercaLocalitaPacchetti();cercaLocalitaPartenza();cercaDatePartenza();';
		ss+='cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');' ;
		eseguiAzioniAJAXConsecutive(ss);
	}
	else 
	{
	    var tProdAltri;
	    try
	    {tProdAltri=document.getElementById('localitaMenuCercaAltri').value;}
	    catch(dd)
	    {tProdAltri='-1'}
	    cercaLocalita(o.value,o.form.id)
	}
}

function chkLocalita(o)
{    
	if (o.form.id.toLowerCase().indexOf('cercapacchetti')>0) {
	var ss=''
	if (globalWBAttivaGestioneAvanzataVoli==1) {ss+='cercaDatePartenza();cercaLocalitaPartenza();cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');';}
	eseguiAzioniAJAXConsecutive(ss);
	}
}

function chkLocalitaPartenza(o)
{
	//cercaDatePartenza();
	var ss=''
	if (globalWBAttivaGestioneAvanzataVoli==1) {ss+='cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');';}
	eseguiAzioniAJAXConsecutive(ss);
}

function chkDataApprossimativaPartenza(obj)
{
	if(obj.value !='') {
	var ss=''
	if (globalWBAttivaGestioneAvanzataVoli==1) {ss+='cercaVoliAndata(\'cerca\');cercaVoliRitorno(\'cerca\');';}
	eseguiAzioniAJAXConsecutive(ss);
	}
}


function chkDatePartenze(obj)
{
	var v,d1,d2;
	v=obj.value;
	d1='' ; d2='';
	if(v.indexOf('*')>0) {
		d1=v.substr(0,v.indexOf('*')) ;
		d2=v.substr(v.indexOf('*')+1) ;
	}
	else {
		d1=v;
		d2=0;
	}
	if (d1=='0' || d1=='' ) {return false;}
	document.getElementById('WbTxtDalPkg').value=d1;
	if (d2 !=0) {	document.getElementById('WbTxtAlPkg').value=d2;}
	
}

function chkTipologiaAltriProdotti(valTipologia, idForm)
{
    try
    {
    document.getElementById('localitaMenuCercaAltri').options[document.getElementById('localitaMenuCercaAltri').selectedIndex].text='...loading...';
    document.getElementById('gruppolocalitaAltriMenuCerca').options[document.getElementById('gruppolocalitaAltriMenuCerca').selectedIndex].text='...loading...';
    }
    catch(ex)
    {}
    AJAX('wb_actionAjax.asp?azione=elencogruppilocalitaaltri&WBCercaTipologiaAltro=' + valTipologia ,aggiornaComboGruppiLocalitaAltri);    
	setTimeout(function() {cercaLocalita(document.getElementById('gruppolocalitaAltriMenuCerca').value,idForm ,valTipologia);},800);
}


function initComboWB(bControllaPacchetti,schedaAttiva,sTipoProdotto)
{
    if (schedaAttiva.toString()=='') {return false; }
    if (schedaAttiva.toString() !='0' && schedaAttiva !='2') {
        var ss='impostaAttributiProdottoCorrente();';
		if (bControllaPacchetti==true) {ss +='chkComboCercaTipologiaPacchetti(false);'}  // serve a mostrare o nascondere le caselle dei voli e date di partenza
		if (sTipoProdotto != '-1'){ss += 'cercaGruppiLocPacchetti(\'' + sTipoProdotto + '\');' ;}
        ss +='cercaLocalitaPacchetti();cercaLocalitaPartenza();cercaDatePartenza();cercaVoliAndata(\'\');cercaVoliRitorno(\'\');';
		eseguiAzioniAJAXConsecutive(ss);
    }
    if (schedaAttiva.toString()=='0') {
		eseguiAzioniAJAXConsecutive('chkTipologiaHotel(' + document.getElementById('WBCercaTipologiaHotel').value + ');cercaLocalita(' + document.getElementById('gruppolocalitaMenuCerca').value + ',\'moduloWBMenuCercaHotel\');');
         }
    if (schedaAttiva.toString()=='2') { chkTipologiaAltriProdotti(document.getElementById('WBCercaTipologiaAltri').value,document.getElementById('WBCercaTipologiaAltri').form.id) ;   }	
}


function cercaGruppiLocPacchetti(tipoProd)
{
    var sTipoHot,voloHotel;
    try {
        sTipoHot = document.getElementById('wbCercaTipologiaHotelVoli').value;
        voloHotel=getValoreParametro('VoloPiuHotel',document.getElementById('opzioniprodottocorrente').value);
    }
    catch(ex) {
        sTipoHot='0';
        voloHotel='0';
    }
    AJAX('wb_actionAjax.asp?azione=elencogruppilocalitapacchetti&WBCercaTipologiaPacchetto=' + tipoProd + '&TipologiaHotelPacchetto=' + sTipoHot + '&volopiuhotel=' + voloHotel,aggiornaComboGruppiLocalitaPacchetti);
}

function cercaGruppiLocHotel(tipoHotel)
{
	AJAX('wb_actionAjax.asp?azione=elencogruppilocalitahotel&tipohotel=' + tipoHotel ,aggiornaComboGruppiLocalitaHotel);
}

function cercaLocalitaPacchetti()
{
    var tipoVal,gruppoLocVal;
	gruppoLocVal=document.getElementById('gruppolocalitaPacchettiMenuCerca').value;
    tipoVal=document.getElementById('WBCercaTipologiaPacchetto').value;
    try
    { document.getElementById('localitaPacchettiMenuCerca').options[document.getElementById('localitaPacchettiMenuCerca').selectedIndex].text='...loading...';    }
    catch(ex)
    {}
    AJAX('wb_actionAjax.asp?azione=elencolocalita&tipohotel=' + document.getElementById('WBCercaTipologiaHotelVoli').value + '&WBCercaTipologiaPacchetto=' + tipoVal + '&gruppolocalita=' + gruppoLocVal ,aggiornaComboLocalita);
}

function cercaLocalitaPartenza()
{
    var tipoVal,gruppoLocVal, locVal;
    gruppoLocVal=document.getElementById('gruppolocalitaPacchettiMenuCerca').value;
    locVal=document.getElementById('localitaPacchettiMenuCerca').value;
    tipoVal=document.getElementById('WBCercaTipologiaPacchetto').value;
    try
    { document.getElementById('localitaPartenzaMenuCerca').options[document.getElementById('localitaPartenzaMenuCerca').selectedIndex].text='...loading...';    }
    catch(ex)
    {}
    AJAX('wb_grigliaVoli.asp?azione=elencolocalitapartenza&WBCercaTipologiaPacchetto=' + tipoVal + '&gruppolocalita=' + gruppoLocVal + '&localita=' + locVal ,aggiornaComboLocalitaPartenza);
}



function cercaLocalita(valore,idForm,tipoProdotto)
{
    if (!tipoProdotto) {tipoProdotto='-1';}
    if (idForm.toLowerCase().indexOf('cercahotel')>0) { AJAX('wb_actionAjax.asp?azione=elencolocalitahotel&tipohotel=' + document.getElementById('WBCercaTipologiaHotel').value + '&gruppolocalita=' + valore ,aggiornaComboLocalitaHotel);}
    if (idForm.toLowerCase().indexOf('cercaaltri')>0) { AJAX('wb_actionAjax.asp?azione=elencolocalitaaltri&WBCercaTipologiaAltro=' + tipoProdotto + '&gruppolocalita=' + valore ,aggiornaComboLocalitaAltri);}
}

function cercaDatePartenza()
{
	//-------------------------------------------------------------
	var VoloPiuHotel,dateFisse;
	VoloPiuHotel=getValoreParametro('VoloPiuHotel',document.getElementById('opzioniprodottocorrente').value);
	dateFisse=getValoreParametro('DateFissate',document.getElementById('opzioniprodottocorrente').value);
	if (VoloPiuHotel=='1' || VoloPiuHotel=='-1') {	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);return ; }  // per il volo + hotel non serve
	if (dateFisse=='1' || dateFisse=='-1') { 
	    var tipoVal,gruppoVal,locPartVal;
        tipoVal=document.getElementById('WBCercaTipologiaPacchetto').value;
	    if (tipoVal=='' || tipoVal=='0') {document.getElementById('WbDatePartenze').options.length=0;eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);return ;}
        gruppoVal=document.getElementById('gruppolocalitaPacchettiMenuCerca').value;
        locPartVal=document.getElementById('localitaPacchettiMenuCerca').value;
        AJAX('wb_actionAjax.asp?azione=elencodatepartenze&WBCercaTipologiaPacchetto=' + tipoVal + '&gruppolocalita=' + gruppoVal + '&localita=' + locPartVal ,aggiornaComboDatePartenza);    
        eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire)
    }
}

function aggiornaComboLocalita(w)
{    
    updateComboOptions(document.getElementById('localitaPacchettiMenuCerca'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}
function aggiornaComboLocalitaHotel(w)
{    
    updateComboOptions(document.getElementById('localitaMenuCerca'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}
function aggiornaComboLocalitaAltri(w)
{
    updateComboOptions(document.getElementById('localitaMenuCercaAltri'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}

function aggiornaComboLocalitaPartenza(w)
{  
   updateComboOptions(document.getElementById('localitaPartenzaMenuCerca'),w);
   eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}


function aggiornaComboDatePartenza(w)
{  
   updateComboOptions(document.getElementById('WbDatePartenze'),w);
   chkDatePartenze(document.getElementById('WbDatePartenze'));
   eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}


function aggiornaComboGruppiLocalitaAltri(w)
{
    updateComboOptions(document.getElementById('gruppolocalitaAltriMenuCerca'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}

function aggiornaComboGruppiLocalitaHotel(w)
{
    updateComboOptions(document.getElementById('gruppolocalitaMenuCerca'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}

function aggiornaComboGruppiLocalitaPacchetti(w)
{
    updateComboOptions(document.getElementById('gruppolocalitaPacchettiMenuCerca'),w);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}



// ------------- GESTIONE VOLI --------------------------------------

var errMsgVoloAndata, errMsgVoloRitorno
var variatoVoloSelezionato=false;
function verificaDatiPerVoloAndata()
{
	var a,b, obj;
	errMsgVoloAndata='';
	a=document.getElementById('localitaPacchettiMenuCerca').value;
	b=document.getElementById('gruppolocalitaPacchettiMenuCerca').value;
	if ((a=='0' && b=='0') || (a=='' && b=='') ) {errMsgVoloAndata=Lang_JS26; return false;}  
	a=document.getElementById('WbTxtDataApprossimativaPkg').value;	
	if (a=='0' || a=='' ) {errMsgVoloAndata=Lang_JS27; return false;} 
	if (globalWBAttivaSpecificheCamera==1) { 
		if (document.getElementById('numeroCamerePacchetti').value==0) {errMsgVoloAndata=Lang_JS28; return false;}
		if (!chkPaxCamera(null,'P') ) {errMsgVoloAndata=Lang_JS29;return false;} 
	}
	    
	obj=document.getElementById('WBCercaTipologiaPacchetto');
    a='0';
    if (obj) {a=obj.value;}
    if(a.indexOf('[')>=0 || a=='0')
       {  //non è un pacchetto volo + hotel
          return false;
	   }
    	
	return true;
}

function verificaDatiPerVoloRitorno()
{
	var obj;
	errMsgVoloRitorno='';
	obj=document.getElementById('tabellaVoliAndata');
	if (!obj) {errMsgVoloRitorno='';return false;}  //tabella voli andata non presente
	obj=document.getElementById('voloAndataSelezionato');
	if (!obj) {errMsgVoloRitorno=Lang_JS31;return false;}  //non è un prodotto con voli
	if (obj.value=='' || obj.value=='0' || obj.value=='-1') {errMsgVoloRitorno=Lang_JS30;return false;} //volo andata non selezionato
	return true;	
}

function cercaVoliAndata(azione)
{
	//verifico se si tratta di un prodotto che prevede voli, se il volo di andata è stato selezionato e se si tratta di un charter con date di rientro fissate.
	if (document.getElementById('voloAndataSelezionato').value==0) {azione='cerca';}
	if (azione=='') {return;}
	document.getElementById('voloAndataSelezionato').value=0;
	if (!verificaDatiPerVoloAndata() ) {
	    impostaOverflowVoli('grigliaVoliAndata',false);
		document.getElementById('grigliaVoliAndata').innerHTML=errMsgVoloAndata;
		eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
	}
	else
	{
		impostaOverflowVoli('grigliaVoliAndata',false);
		document.getElementById('grigliaVoliAndata').innerHTML='loading..';
		var pag='wb_grigliavoli.asp?azione=elencovoliandata';
		var grLoc, loc, dtAppr, tipoPacchetto,iNgg
		loc=document.getElementById('localitaPacchettiMenuCerca').value;
		grLoc=document.getElementById('gruppolocalitaPacchettiMenuCerca').value;
		dtAppr=document.getElementById('WbTxtDataApprossimativaPkg').value;
		iNgg=document.getElementById('piuMenoGiorniPacchetti').value;
		tipoPacchetto=document.getElementById('WBCercaTipologiaPacchetto').value;
    	pag +='&gruppoLocalita=' + escape(grLoc);
    	pag +='&Localita=' + escape(loc);
    	pag +='&dataapprossimativa=' + escape(dtAppr);
    	pag +='&tipopacchetto=' + escape(tipoPacchetto);
    	pag +='&partenza=' + escape(document.getElementById('localitaPartenzaMenuCerca').value);
    	pag +='&npax=' + escape(getTotalePax('P','adtchd'));
    	pag +='&ngg=' + escape(iNgg);

		AJAX(pag,aggiornaVoliAndata); 
	}
}

function impostaOverflowVoli(nomeDiv,bVisibile) {
    var obj;
    obj=document.getElementById(nomeDiv);
    if (bVisibile) {
        obj.style.height='90px';
        obj.style.overflowY='auto';
        obj.style.border='1px solid #FCFCFC';
    }
    else {
        obj.style.height='30px';
        obj.style.overflowY='auto';
        obj.style.border='0';
    }
    
}

function cercaVoliRitorno(azione)
{
	//verifico se si tratta di un prodotto che prevede voli, se il volo di andata è stato selezionato e se si tratta di un charter con date di rientro fissate.
	if (azione=='') {return;}
	document.getElementById('voloRitornoSelezionato').value=0;
	if (!verificaDatiPerVoloRitorno()) {
	    impostaOverflowVoli('grigliaVoliRitorno',false);
		document.getElementById('grigliaVoliRitorno').innerHTML=errMsgVoloRitorno;
		eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
	}
	else
	{
		impostaOverflowVoli('grigliaVoliRitorno',false);
		document.getElementById('grigliaVoliRitorno').innerHTML='loading..';
		var pag='wb_grigliavoli.asp?azione=elencovoliritorno';
		pag +='&idvoloandata=' + document.getElementById('voloAndataSelezionato').value;
		pag +='&npax=' + escape(getTotalePax('P','adtchd'));
		AJAX(pag,aggiornaVoliRitorno); 
	}
}


function aggiornaVoliAndata(w)
{
	document.getElementById('grigliaVoliAndata').innerHTML=w;
	impostaOverflowVoli('grigliaVoliAndata',w.toString().length>400);
	setTimeout('scrollObj(\'containerBloccoOpzioniRicercaWB\',\'fine\')',200);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}
function aggiornaVoliRitorno(w)
{
	document.getElementById('grigliaVoliRitorno').innerHTML=w;
	impostaOverflowVoli('grigliaVoliRitorno',w.toString().length>400);
	setTimeout('scrollObj(\'containerBloccoOpzioniRicercaWB\',\'fine\')',200);
	eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);  //esegue tutte le eventuali azioni nel buffer
}

function chkVoliSelezionati()
{
	var oVolo=document.getElementById('voloAndataSelezionato');
	if (!oVolo) {return false;}
	if (oVolo.value==0 || oVolo.value=='') {return false;}
	
	if (variatoVoloSelezionato==true) {
	    var rigaVolo,apt4,dataRitorno,dataPartenza
	    rigaVolo=document.getElementById('rigaVoloAndata' + oVolo.value);
	    apt4=rigaVolo.getAttribute('apt4');
	    dataPartenza=rigaVolo.getAttribute('dataPartenza');
	    dataRitorno=rigaVolo.getAttribute('dataPartenzaV2');
    	
	    if(apt4 !='' && dataPartenza !='' && dataRitorno !='') {return true;}  // il volo selezionato è un charter andata e ritorno. Non servono altri controlli
	}
	oVolo=document.getElementById('voloRitornoSelezionato');
	if (!oVolo) {return false;}
	if (oVolo.value=='') {return false;}
	return true;
}


function selezionaVolo(AoR,idVolo)
{
	document.getElementById('volo' + AoR + 'WB' + idVolo).checked=true;
	document.getElementById('volo' + AoR + 'Selezionato').value=idVolo;
    variatoVoloSelezionato=true;
    var rigaVolo,apt4,dataRitorno,dataPartenza
	if (AoR=='Andata') {	    
	    rigaVolo=document.getElementById('rigaVoloAndata' + idVolo);
	    apt4=rigaVolo.getAttribute('apt4');
	    dataPartenza=rigaVolo.getAttribute('dataPartenza');
	    dataRitorno=rigaVolo.getAttribute('dataPartenzaV2');
	    document.getElementById('WbTxtDalPkg').value=dataPartenza;
	    if(apt4 !='' && dataPartenza !='' && dataRitorno !='') {document.getElementById('WbTxtAlPkg').value=dataRitorno;} 
	    cercaVoliRitorno('cerca');	    
	}
	else {
	    rigaVolo=document.getElementById('rigaVoloRitorno' + idVolo);
	    dataPartenza=rigaVolo.getAttribute('dataPartenza');
	    document.getElementById('WbTxtAlPkg').value=dataPartenza; 	  	    
	}	
}
//-----------------------------------------------------------------

function scrollObj(idObj,dove)
{
    try {
    var obj=document.getElementById(idObj)
    if (!idObj) {return false;}
    obj.scrollTop=obj.scrollHeight + 50;
    }
    catch(oo) {}
}


function eseguiAzioniAJAXConsecutive(strFunzioni)
{
	// Attenzione! le funioni di ritorno delle chiamate AJAX devono rifare  una call a eseguiAzioniAJAXConsecutive(elencoAzioniDaEseguire);
	// altrimenti le rimanenti funzioni in coda non verranno eseguite
	
	
	try {
		if (strFunzioni.toString().length<1) {return false;}
		if(strRight(strFunzioni,1)==';') {strFunzioni=strFunzioni.substring(0,strFunzioni.length -1);}
		if (GLOBAL_DebugAttivo=='1') {alert('azioni da eseguire:' + strFunzioni);}
		var matAzioni=strFunzioni.split(';');
		var i;
		for (i=0;i < matAzioni.length;i++)
		{
			if (matAzioni[i].length>1 && i==0) {setTimeout(matAzioni[i],100);  }
			if (i==0) {elencoAzioniDaEseguire='';}
			if (i>0) {elencoAzioniDaEseguire=elencoAzioniDaEseguire + matAzioni[i] +';'}			
		}
	}
	catch(oo)
	{alert('Errore AJAX multipo:' + oo.message + '\n' + strFunzioni + '-----' + elencoAzioniDaEseguire );
	}
	
}



// Gestione Aste //
function confermaOffertaAsta(testo,idAsta,rilancio,prezzoCorrente)
{
    if (document.getElementById('inputOffertaAsta' + idAsta).value == '') { mostraAvvisoFisso(document.getElementById('inputOffertaAsta' + idAsta),Lang_JS10); return;}
    var pC,pO,pR;
    pC=parseInt(prezzoCorrente);
    pO=document.getElementById('inputOffertaAsta' + idAsta).value;
    pR=parseInt(rilancio);
    
    if((pC + pR)>pO ) {alert('Il rilancio minimo è di ' + rilancio + ' Euro.\nFare un\'offerta di ' + (parseInt(prezzoCorrente) + parseInt(rilancio)) + ' euro o superiore.') ; return;} 
    if (confirm(testo)) {
    document.getElementById('formAsta' + idAsta).submit();
    }
}
