/*Busqueda amadeus-RCM*/		
		//Array que controla los dias
		var dias =new Array();
			dias['01'] = "31";
			dias['02'] = "28";
			dias['03'] = "31";
			dias['04'] = "30";
			dias['05'] = "31";
			dias['06'] = "30";
			dias['07'] = "31";
			dias['08'] = "31";
			dias['09'] = "30";
			dias['10'] = "31";
			dias['11'] = "30";
			dias['12'] = "31";
		
		/* ini */

// Array con la lista de paises, de mercados disponibles
var paises =new Array();

		paises['ES'] = "Espaņa";
		paises['FR'] = "France";
	  paises['IT'] = "Italia";
	  paises['UK'] = "United Kingdom";
	  paises['PT'] = "Portugal";
		paises['AR'] = "Argentina";
		paises['BR'] = "Brasil";
		paises['MX'] = "Mexico";
		paises['DO'] = "Rep. Dominicana";
		paises['VE'] = "Venezuela";
		paises['US'] = "USA";
		paises['PE'] = "Peru";
		paises['OT'] = "Otros/Others";

var short_paises=new Array();

		short_paises['ES'] = "ES";
		short_paises['FR'] = "FR";
		short_paises['IT'] = "IT";
		short_paises['UK'] = "UK";
		short_paises['AR'] = "AR";
		short_paises['BR'] = "BR";
		short_paises['MX'] = "MX";
		short_paises['DO'] = "DO";
		short_paises['VE'] = "VE";
		short_paises['US'] = "US";
		short_paises['PT'] = "PT";
		short_paises['PE'] = "PE";	
		short_paises['OT'] = "OT";


// Array con la descripcion de todos los idiomas disponibles

var desc_idiomas =new Array();

		desc_idiomas['IT'] = "Italiano";
		desc_idiomas['FR'] = "Franįais";
		desc_idiomas['ES'] = "Espaņol";
		desc_idiomas['CA'] = "Catalā";
		desc_idiomas['AR'] = "Argentino";
		desc_idiomas['BR'] = "Portuguęs";
		desc_idiomas['EN'] = "English";
		desc_idiomas['PT'] = "Portuguęs";

var short_desc_idiomas =new Array();

		short_desc_idiomas['Italiano'] = "IT";
		short_desc_idiomas['Franįais'] = "FR";
		short_desc_idiomas['Espaņol'] = "ES";
		short_desc_idiomas['Catalā'] = "CA";
		short_desc_idiomas['Argentino'] = "AR";
		short_desc_idiomas['Portuguęs'] = "BR";
		short_desc_idiomas['English'] = "EN"
		short_desc_idiomas['Portuguęs'] = "PT";

var idiomas =new Array();

		idiomas['IT'] = [['IT'], ['ES']];
		idiomas['FR'] = [['FR'], ['ES']];
		idiomas['UK'] = [['ES'], ['EN']];
		idiomas['ES'] = [['ES'], ['EN'], ['CA']];
		idiomas['AR'] = [['ES'], ['EN']];
		idiomas['BR'] = [['BR'], ['ES']];
		idiomas['MX'] = [['ES'], ['EN']];
		idiomas['DO'] = [['ES'], ['EN']];
		idiomas['VE'] = [['ES'], ['EN']];
		idiomas['US'] = [['ES'], ['EN']];
		idiomas['PT'] = [['PT'], ['ES']];
		idiomas['PE'] = [['ES'], ['EN']];	
		idiomas['OT'] = [['ES'], ['EN']];	// OT = otros

		//Resetea las opciones elegidas de aeropuertos
		function resetAtps()
		{
			document.getElementById('combo_aptdep').selectedIndex = 0;
			document.getElementById('combo_aptarr').options.length = 0;	
			generaOpcionCombo('Select..',0,'combo_aptarr', 0);
			document.getElementById('combo_aptarr').selectedIndex = 0;
			showInfoPrecioMenu(0);
		}
		//Opcion de cambio de idioma
		function cambiaIdioma(valor) 
		{	
			 document.foSesionParam.xsid.value=document.foLogin.xsid.value;
			 document.foSesionParam.p_codidi.value=valor;
			 document.foSesionParam.p_codidi.value=valor;
			 document.foSesionParam.submit();
		}

		function cambiaIdioma_ama(valor) 
		{	
	    	 /*alert(document.foLogin.xsid.value);*/
			 /*document.foSesionParam.xsid.value=document.foLogin.xsid.value;
			 document.foSesionParam.p_codidi.value=valor;
			 document.foSesionParam.p_codidi.value=valor;
			 document.foSesionParam.submit();*/
			 document.location="../"+valor.toLowerCase()+"/default_amadeus.html";
		}

		//Lanzado de carga pagina
		function init_default()
		{		
			cargaPaises('combo_aptpai');	// Cargamos el combo de paises
			document.foDatosSesion.submit();
		}

		function init_default_iframe()
		{		
			cargaOrigenes('combo_aptdep'); //cargamos el combo de ida

			document.getElementById('combo_aptdep').value='LGW';
			cargaDestinos('combo_aptdep','combo_aptarr');
		}

		function cargaHome(paisId, idiomaId){
			var fechaExp = new Date();			// Estable una fecha desde la cual se va a calcular la fecha final para la caducidad de la cookie

			var aptIdi=document.getElementById(idiomaId).value;
			var aptPai=document.getElementById(paisId).value;
			document.foDatosSesion.p_codmer.value=aptPai;
			document.foDatosSesion.p_codidi.value=aptIdi;
			if(aptPai!='0' && aptIdi!='0'){
			 if(typeof(borrarAeropuertos)=='function') borrarAeropuertos();
			 if(typeof(establecerPaisLang)=='function'){
			  establecerPaisLang(true,aptPai);
			  establecerPaisLang(false,aptIdi);
    }
				document.foDatosSesion.submit();
			}else{
				alert('Both a country and a language should be specified. Thank you.');
			}
		}

		function cargaPaises(comboId){
			var posCombo = 0;
			var txt = '';
			var value = '';
			//borramos contenido
			document.getElementById(comboId).options.length = 0;			
			//aņadimos un elemento centinela ?->	
			generaOpcionCombo('...',0,comboId, 0);
			for(pai in paises)
			{
				posCombo++;
				txt=paises[pai];
				generaOpcionComboPaises(txt, short_paises[pai], comboId, posCombo);
			}
		}

		function cargaIdiomas(paisId, idiomaId){
			var posComboIdioma=0;
			var aptPai= document.getElementById(paisId).value;
			var l_idioma = idiomas[aptPai];
			//var nomIdioma;
			document.getElementById(idiomaId).options.length=0;
			//generaOpcionCombo('...',0,comboId,0);
			generaOpcionCombo('...',0,idiomaId,0);
			for(listaIdioma in l_idioma){
				//alert('entra en bucle');
				var arrIdioma=l_idioma[listaIdioma];
				posComboIdioma++;
				nomIdioma=desc_idiomas[arrIdioma[0]];
				generaOpcionCombo(nomIdioma,arrIdioma[0],idiomaId,posComboIdioma);
			}
		}

		function generaOpcionCombo(txt,value,idCombo,pos) {
			oOption = document.createElement("OPTION");
			oOption.text = txt;
			oOption.value = value;
			if (value=='EN'){
				oOption.selected = "Inglés";
			}
			//asi se puede acceder al browser que sea	
			document.getElementById(idCombo).options[pos] = oOption;
		}

		// Genera las opciones para el combobox de paises dejando seleccionado por defecto el Espaņa
		function generaOpcionComboPaises(txt,value,idCombo,pos) {
			oOption = document.createElement("OPTION");
			oOption.text = txt;
			oOption.value = value;
			document.getElementById(idCombo).options[pos] = oOption;
		}

		/* fi */

		//Funcion Fecha inicial acorde con fecha de sistema
		function cargaFecha_old(B_DIA_1,B_DIA_2,B_MES_1,B_MES_2)
		{
			var dias_mes =new Array();
				dias_mes[1] = "31";
				dias_mes[2] = "28";
				dias_mes[3] = "31";
				dias_mes[4] = "30";
				dias_mes[5] = "31";
				dias_mes[6] = "30";
				dias_mes[7] = "31";
				dias_mes[8] = "31";
				dias_mes[9] = "30";
				dias_mes[10] = "31";
				dias_mes[11] = "30";
				dias_mes[12] = "31";
			var fecha= new Date();
			var dia = fecha.getDate()+3;
			var mes = fecha.getMonth()+1;
			if(dia > dias_mes[mes])
			{
				mes++;
			}
				B_DIA_1.value = dia;
				B_DIA_2.value = dia;
					if (mes<10) mes='0'+mes;				
					B_MES_1.value = mes;
					B_MES_2.value = mes;				
		}
	    //Funcion Fecha inicial acorde con fecha de sistema
		function cargaFecha(B_DIA_1,B_DIA_2,B_MES_1,B_MES_2)
		{
			var dias_mes =new Array();
				dias_mes[1] = "31";
				dias_mes[2] = "28";
				dias_mes[3] = "31";
				dias_mes[4] = "30";
				dias_mes[5] = "31";
				dias_mes[6] = "30";
				dias_mes[7] = "31";
				dias_mes[8] = "31";
				dias_mes[9] = "30";
				dias_mes[10] = "31";
				dias_mes[11] = "30";
				dias_mes[12] = "31";
				var origen= document.getElementById('combo_aptdep').value;
				var destino= document.getElementById('combo_aptarr').value;
				if (destino.length==4)
        {
          destino=destino.substring(0,3);
        }
				if ((origen=="JFK")||(destino=="JFK"))
        {
            dia='01';
  	        mes='06';
  	       /* alert(parseInt(mes));
  	        for (var i=parseInt(mes);i<=B_MES_1.length-mes;i--){
  	        	alert(B_MES_1.options[i]);
  	        	B_MES_1.options[i]
  	         B_MES_1.remove(i);            
            }
  	        for (i=mes;i<B_MES_2.length-mes;i--){
  	        B_MES_2.remove(i);    
  	         B_MES_2.options[i].disabled;            
            }*/
  	     }else{
  	       	var fecha = new Date();
      			var dia = fecha.getDate();
      			var mes = fecha.getMonth()+1;
      			for(var i=0; i<=2; i++)
      			{
      				dia++;
      				if(dia > dias_mes[mes])
      				{
      					dia=1;
      					mes++;
      				}
  			    }
  			    if(dia < 10) dia='0'+dia;
  			    if (mes<10) mes='0'+mes;
         }
         B_DIA_1.value = dia;
      	 B_DIA_2.value = dia;
      	 B_MES_1.value = mes;
      	 B_MES_2.value = mes;										
      //
      if (eval(document.getElementById('B_DIA_IPT_1')))
      {
			  document.getElementById('B_DIA_IPT_1').value = document.getElementById('B_DIA_1').options[document.getElementById('B_DIA_1').value - 1].text;
			  document.getElementById('B_MES_IPT_1').value = document.getElementById('B_MES_1').options[document.getElementById('B_MES_1').value - 1].text;
			  document.getElementById('B_ANIO_IPT_1').value = document.getElementById('B_ANIO_1').value;
		}
      //
      if (eval(document.getElementById('B_DIA_IPT_2')))
      {
  			document.getElementById('B_DIA_IPT_2').value = document.getElementById('B_DIA_2').options[document.getElementById('B_DIA_2').value - 1].text;
  			document.getElementById('B_MES_IPT_2').value = document.getElementById('B_MES_2').options[document.getElementById('B_MES_2').value - 1].text;
  			document.getElementById('B_ANIO_IPT_2').value = document.getElementById('B_ANIO_2').value;
      }
      //
		}
		//Ajustar dia de una cifra
		function ajustarDia(){
			var dia = document.getElementById('B_DIA_1').value;	
			document.getElementById('B_DIA_2').value=dia;
		}
		//Validar la cantidad de pasajeros:
		function validatevPaxQuantity(){
	
			var a=document.getElementById('TRAVELLER_TYPE_ADT').value;
			var b=document.getElementById('TRAVELLER_TYPE_CHD').value;
			var c= parseInt(a) + parseInt(b);
			
			var d=document.getElementById('HAS_INFANT').value;
			
				if (parseInt(d) > parseInt(a))
				{
					alert("The number of babies for a reservation cannot exceed the number of adults");
					return false;
				}
				if(c > 9)
				{
					alert("Number of passengers cannot exceed 9");
				return false;
				}
				return true;
		}
		//Envio de pasajeros
		function envioPasajeros(){
		  var numAdt = parseInt(document.getElementById('TRAVELLER_TYPE_ADT').value);
		  var numBaby = parseInt(document.getElementById('HAS_INFANT').value);
		  var numChd = numAdt +parseInt(document.getElementById('TRAVELLER_TYPE_CHD').value);
		  for (var i =1;i<=document.getElementById('TRAVELLER_TYPE_ADT').value;i++){
		     document.getElementById('TRAVELLER_TYPE_' + i).value = 'ADT';
			 if (numBaby > 0){
				document.getElementById('HAS_INFANT_' + i).value = 'TRUE';
			    numBaby--;
			 } else document.getElementById('HAS_INFANT_' + i).value = 'FALSE';
	      }
		  for (var i = numAdt + 1;i<= numChd;i++){
		     document.getElementById('TRAVELLER_TYPE_' + i).value = 'CHD';
			 document.getElementById('HAS_INFANT_' + i).value = 'FALSE';
	      }
     //TRAVELLER_TYPE_1=CHD&HAS_INFANT_1=FALSE&TRAVELLER_TYPE_2=ADT&HAS_INFANT_2=FALSE&TRAVELLER_TYPE_3=ADT&HAS_INFANT_3=TRUE&TRAVELLER_TYPE_4=&HAS_INFANT_4=FALSE 
        //  for (var i =1;i<=9;i++){
		 // }
	    }
		//Validacion de trayecto
		function validarTrayecto()
		{
			var a=document.getElementById('combo_aptdep').value;
			var b=document.getElementById('combo_aptarr').value;
				if (a=='0' || a=='')
				{
					alert("Select Origin");
					return false;
				}
				if (b=='0' || b=='')
				{
					alert("Select Destination");
					return false;
				}
				return true;
		}		
		function validar(oForm)
		{
			if (validatevPaxQuantity() && validarTrayecto()){
				envioPasajeros();
				enviar(oForm);
			}	
		}
		//Enviar formulario
		function enviar(objForm)
		{ 
		  //Controlar disponibilidad de otras compaņias: UX,IB,JK
		  var origen= objForm.ORIGEM.value;
		  var destino= objForm.DESTINO.value;
		  if (destino.length >= 4) 
			{
         var dispo_cia=destino.substr(4,1);
			   destino=destino.substring(0,3);
			   //dispo_cia (0UX,1UXJK,2UXIBJK)
			   if (dispo_cia==0){
			      objForm.SO_SITE_REST_AIRLINES_LST.value='UX';
           // alert('1'+objForm.SO_SITE_REST_AIRLINES_LST.value);
         }else{
            if (dispo_cia==1){
              objForm.SO_SITE_REST_AIRLINES_LST.value='UX;JK';
  		       // alert('2' +objForm.SO_SITE_REST_AIRLINES_LST.value); 
            }else{
              objForm.SO_SITE_REST_AIRLINES_LST.value='UX;IB;JK';
              //alert('3'+objForm.SO_SITE_REST_AIRLINES_LST.value);
            }
         }
			}else{
       objForm.SO_SITE_REST_AIRLINES_LST.value='UX;JK';
       //alert('1B'+objForm.SO_SITE_REST_AIRLINES_LST.value);
      }
			//Funcion anyo
			function formatAno(anyo) 
			{
				//var fecha = new Date();
				//var anyo = fecha.getYear()+'';
				if (anyo.length<4) anyo='20'+ anyo.substring(1,3);
				return anyo;				
			}	
			//variables y formato de fecha para 'yyyymmddhhnn'
			var fecha = new Date();
			var anyo = fecha.getUTCFullYear();
			var anyo2 = fecha.getUTCFullYear();
			var mes = fecha.getMonth() + 1 ;
			if (mes > objForm.B_MES_1.value) anyo ++;			
			objForm.B_DATE_1.value = formatAno(anyo) + objForm.B_MES_1.value + objForm.B_DIA_1.value + '0000';
			if (mes > objForm.B_MES_2.value) anyo2 ++;
			objForm.B_DATE_2.value = formatAno(anyo2) + objForm.B_MES_2.value + objForm.B_DIA_2.value + '0000';
			if (objForm.B_DATE_1.value > objForm.B_DATE_2.value) {
				alert('The return date is not valid');
			}
			else{
            //montar o(s) trecho(s)
	         objForm.B_LOCATION_1.value = objForm.ORIGEM.value;
	      	 objForm.E_LOCATION_1.value = destino;
	         objForm.B_LOCATION_2.value = destino;
	       	 objForm.E_LOCATION_2.value = objForm.ORIGEM.value;
	        //envia o form
		
	         objForm.action="http://wftc2.e-travel.com/plnext/AirEuropa/Override.action";
	         objForm.method="post";
	      	 objForm.submit();
//	      	 parent.document.getElementById('ifBuscador').style.height = '1200px';
           parent.document.getElementById('pie').style.display = 'none';
           doDocResize(parent.document);
		    //modificar divs para visualizar busqueda
	/*		 document.getElementById('idCuerpo').style.display='none';
			 document.getElementById('sub_cont_medio_i').style.display='none'; 
			 document.getElementById('clear28').style.display='none';
			 document.getElementById('idBusqueda').style.display='inline';
			 document.getElementById('ifBusqueda').height = '473px'; */
			 
			 }
	  	}
function doDocResize(doc){
 if(!doc.documentElement) return;
 var y0=doc.getElementById('franja'),h=doc.documentElement.clientHeight || doc.body.clientHeight;
 y0=y0.offsetTop+y0.offsetHeight;
 var h2=parent.document.getElementById('pie').offsetHeight+30;
 doc.getElementById('ifBuscador').style.height=(h-y0-h2)+'px';
}
      function resizeIframe() {
	  	  parent.document.getElementById('ifBuscador').style.height = '450px';
        parent.document.getElementById('pie').style.display = '';
      }	
		//Redimensionamiento dinamico del iFrame de busqueda     
	//	function iFrameHeight(ifBusqueda)
	// 	{
  //	ifBusqueda.height = ifBusqueda.document.body.scrollHeight + 450;
	//	}		 
	    // Funcion que elimina todos los valores de la combo.
		function borraSelect(oSel)
		{
		  if (eval(oSel))
		  {
		    nNumOptions = oSel.options.length;
		    // borra los options anteriores de la select
		    for (j=0;j<nNumOptions;j++)
		    {
		      oSel.remove(j); 
		    }
		    oSel.options.length = 0;
		  }
		} 


		// Funciķn que carga todos los valores de la combo.
		function cargarCombo (mes,oSelect) 
		{	
		  var dia   = oSelect.value;
			var fecha = new Date();
			var anyo = fecha.getYear();
			borraSelect(oSelect);
			n = oSelect.length;
			if (anyoBisiesto(anyo) && mes =='02')
			{
				for (i=1;i<=29;i++)
				{
					if (i<10) oSelect.options[n] = new Option(i,'0'+i);
					else oSelect.options[n] = new Option(i,i);
					n++;
				}	
			}else	
			{		
				for (i=1;i<=dias[mes];i++)
				{
				if (i<10) oSelect.options[n] = new Option(i,'0'+i);
					else oSelect.options[n] = new Option(i,i);
					n++;
				}
			}
			for (i=0;i<oSelect.options.length;i++)
			{
				if (oSelect.options[i].value == dia){
         oSelect.value = dia;
         break;
        }
			}	
			
		}
		// Funcion para comprobar si una aņo es bisiesto argumento anyo > aņo extraido de la fecha introducida por el usuario
		function anyoBisiesto(anyo)
		{
			//si el aņo introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
			if (anyo < 100)
			var fin = anyo + 1900;
			else
			var fin = anyo ;
			// primera condicion: si el resto de dividir el aņo entre 4 no es cero > el aņo no es bisiesto es decir, obtenemos aņo modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
			if (fin % 4 != 0)
			return false;
			else
			{
			if (fin % 100 == 0)
			{
			// si el aņo es divisible por 4 y por 100 y divisible por 400 > es bisiesto
			if (fin % 400 == 0)
			{
			return true;
			}
			// si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
			else
			{
			return false;
			}
			}
			//si es divisible por 4 y no es divisible por 100 > el aņo es bisiesto
			else
			{
			return true;
			}
			}
		}

		// Activar y desactivar los list box de dia y del mes, en condicion si selecciona ida y vuelta o solo ida

		function activarRegreso(opcion)
		{
			//var numAdt = parseInt(document.getElementById('TRAVELLER_TYPE_ADT').value);
			var idFormulario=document.getElementById('Override');
			for(i=0;i<opcion.length;i++)
			{
				if(opcion[i].checked)
				{
					if(opcion[i].value=='R')
					{
						document.getElementById('B_DIA_2').disabled = false;
						document.getElementById('B_MES_2').disabled = false;
						if (eval(document.getElementById('B_DIA_IPT_2')))
						{
						  document.getElementById('B_DIA_IPT_2').disabled = false;
						  document.getElementById('B_MES_IPT_2').disabled = false;
						  document.getElementById('B_ANIO_IPT_2').disabled = false;
						  document.getElementById('B_ANIO_2').disabled = false;
						}
					}else{
						document.getElementById('B_DIA_2').disabled = true;
						document.getElementById('B_MES_2').disabled = true;
						if (eval(document.getElementById('B_DIA_IPT_2')))
						{
  						document.getElementById('B_DIA_IPT_2').disabled = true;
  						document.getElementById('B_MES_IPT_2').disabled = true;
  						document.getElementById('B_ANIO_IPT_2').disabled = true;
  						document.getElementById('B_ANIO_2').disabled = true;
            }
					}
				}
			}
				
		}
