var win = null;
var base = 'http://inerzianet.agenciadeviajesonline.com/vuelos/';

function Abririnfos(ubicacion,nombre,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,menubar=no,status=no,location=no,toolbar=no,resizable=yes';
	win = window.open(ubicacion,nombre,opciones);
	try{
		win.window.focus();
	}
	catch(e){}
}

function Abririnfoscroll(ubicacion,nombre,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,menubar=no,status=no,location=no,toolbar=no,resizable=no';
	win = window.open(ubicacion,nombre,opciones);
	win.window.focus();
}

function Abrir(ubicacion,nombre,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,status=yes,MenuBar=no,ToolBar=no,resizable';
	win = window.open(ubicacion,nombre,opciones);
	win.window.focus();
}

function AbrirSR(ubicacion,nombre,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	opciones ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,status=no,MenuBar=no,ToolBar=no,resizable=no';
	win = window.open(ubicacion,nombre,opciones);
	win.window.focus();
}
//ok
function setAirport(pAirId, pAirName, pOrgDest) {
	if (pOrgDest=='autorelleno2') {
		$('aero_destino').value = pAirId;
		descuento();
		document.getElementById(pOrgDest).value = pAirId;
		document.getElementById(pOrgDest).value = pAirName;
	}
	else {
		$('aero_origen').value = pAirId;
		descuento();
		document.getElementById(pOrgDest).value = pAirId;
		document.getElementById(pOrgDest).value = pAirName;
	}
}
// ok
function selectAirport(pOrgDest){
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].id == pOrgDest) {
			document.forms[0].elements[i].focus();
			break;
		}
	}
	if (pOrgDest=='autorelleno2') {
		Abrir(base+'gui.motor.aeropuertos.php?SESS='+document.getElementById('SESS').value +'&cn='+pOrgDest,'Aeropuertos',690,480);
	}
	else{
		Abrir(base+'gui.motor.aeropuertos.php?SESS='+document.getElementById('SESS').value +'&cn='+pOrgDest,'Aeropuertos',690,480);
	}
}
// ok
function descuento() {
	if  (document.getElementById('aero_destino').value != '' && document.getElementById('aero_origen').value != '') {
		var pars= 'SESS='+document.getElementById('SESS').value+'&origen='+ document.getElementById('aero_origen').value + '&destino=' + document.getElementById('aero_destino').value;
		var aj = new Ajax.Updater('descuentos',base+'log.motor.descuento.php',{method:'get',parameters:pars});
	}
}
//ok
function descuento_marcado() {
	if  (document.getElementById('aero_destino').value!='' && document.getElementById('aero_origen').value!='') {
		var pars= 'SESS='+document.getElementById('SESS').value+'marcado=1&origen='+ document.getElementById('aero_origen').value + '&destino=' + document.getElementById('aero_destino').value;
		var aj = new Ajax.Updater('descuentos',base+'log.motor.descuento.php',{method:'get',parameters:pars});
	}
}

var origen='';
var destino='';
// OK
function mostrar_resultado(res){
	if (res.responseText == '1') { // siginifica que el origen y el destino estan OK
		$('boton').value=1;
		$('aero_destino').value=destino;
		$('aero_origen').value=origen;
		document.formBusc.submit() ;
	}else {
		if (res.responseText == '2') { //error en el origen
			try { document.formBusc.autorelleno.focus(); }
			catch(e) {}
			alert(VUE_MOT_ERR_ORIGIN);
		}
		if (res.responseText == '3') { //error en ambos
			try { document.formBusc.autorelleno.focus(); }
			catch(e) {}
			alert(VUE_MOT_ERR_ORIGIN_DESTINY);
		}
		if (res.responseText == '0') { //error en destino
			try { document.formBusc.autorelleno2.focus(); }
			catch(e) {}
			alert(VUE_MOT_ERR_DESTINY);
		}
	}
}
//ok
function validarcampo(id){  //esta funcion se carga cada vez que se llama al evento OnChange del destino o del origen. 
	if (id=='1') {
    if ( document.getElementById('aero_origen').value!='')
      var pars='SESS='+document.getElementById('SESS').value+'&id='+document.getElementById('aero_origen').value;
		else 
      var pars='SESS='+document.getElementById('SESS').value+'&id='+document.getElementById('autorelleno').value;
		var ajx = new Ajax.Request(base+'log.motor.validar.php',
		{
		method: 'get',
		parameters:pars,
		onSuccess: function (res) {
			if (res.responseText!=''){
				var temp = new Array();
				temp = res.responseText.split('*');
				document.getElementById('autorelleno').value=temp[0];
				document.getElementById('aero_origen').value=temp[1];
			}
			else {
				document.getElementById('autorelleno').value=VUE_MOT_ERR_AIRPORT_UNAVAILABLE;
			}
			descuento();
		}
		});
	}
	else{
		if(document.getElementById('aero_destino').value!='') 
      var pars='SESS='+document.getElementById('SESS').value+'&id='+document.getElementById('aero_destino').value;
		else 
      var pars='SESS='+document.getElementById('SESS').value+'&id='+document.getElementById('autorelleno2').value;
		var temporal=document.getElementById('autorelleno2').value;
		var ajxx = new Ajax.Request(base+'log.motor.validar.php',
		{
		method:'get',
		parameters:pars,
		onSuccess: function (res) {
			if (res.responseText!='') {
				var temp = new Array();
				temp = res.responseText.split('*');
				document.getElementById('autorelleno2').value=temp[0];
				document.getElementById('aero_destino').value=temp[1];
			}else {
				document.getElementById('autorelleno2').value=VUE_MOT_ERR_AIRPORT_UNAVAILABLE;
			}
			descuento();
		}
		});
	}
	validar_fecha_de_salida($('dc1').value);  // funcion ubicada en log_motor.php
}

function cambiar_descuento(valor) {
	if (document.getElementById('descuento_check').value=='0')  {
		document.getElementById('descuento_check').value=valor;
	}
	else {
		document.getElementById('descuento_check').value='0';
	}
}
//ok
function validarfiltro() {
	var apretado = 0;
	for (i=0;i<document.formG.elements.length;i++) {
		if(document.formG.elements[i].type == "checkbox") {
			if (document.formG.elements[i].value!='vuelo_directo' && document.formG.elements[i].className=='formu') {
				if (document.formG.elements[i].checked==1) apretado=apretado+1;
			}
		}
	}
	if (apretado==0) {
		alert (VUE_RES_ERR_FIL_NO_COMPANY);
		return false;
	}
	document.formG.modoBus.value = 'filtroVuelos';
  document.formG.submit();
}

//    bORRAR ?
/*
function aplicarfiltro() {
	try{
		document.getElementById('container').style.display='none';
		document.getElementById('filtrando').style.display='';
	}
	catch(e){}
	var companias='';
	for (i=0;i<document.formG.elements.length;i++) {
		if(document.formG.elements[i].type == "checkbox") {
			if (document.formG.elements[i].checked==1) {
				companias= companias + '&'+ document.formG.elements[i].value + '=' + document.formG.elements[i].value;
			}
		}
	}
	var pars = 'salida_ida=' + $('salida_ida').value + '&llegada_ida=' + $('llegada_ida').value + '&salida_vuelta=' + $('salida_vuelta').value + '&llegada_vuelta=' + $('llegada_vuelta').value + '&tipo=' + $('tipo').value + companias;
	try{
		pars=pars + '&formfil_sp_fecha_i=' + $('formfil_sp_fecha_i').value;
	}
	catch(e){}
	try{
		pars=pars + '&formfil_sp_fecha_v =' + $('formfil_sp_fecha_v').value;
	}
	catch(e){}
  
	var aj = new Ajax.Request('log.resultados.filtrar.php',{method:'post',parameters:pars,onComplete:mostrar_vuelos_filtrados});
}
*/
/**
 * Al realizar una búsqueda con fechas flexibles, obtenemos resultados para +/-1 día
 * Como queremos permitir tener +/-3 días, si nos pasamos de esa diferencia (1) tenemos que volver a buscar
 * Esta función recibe el índice del selector de fecha ida, el indice del selector de fecha de vuelta, la fecha original de ida, y la fecha original de vuelta
 * En base a esos datos determinamos si continuar con el filtro o volver a enviar xml y despues filtrar
 * Todas las fechas están en formato dd/mm/YYYY 
 */
 /*
function preparar_Filtro_Fecha(indice_Filtro_Ida, indice_Filtro_Vue, fecha_Original_Ida, fecha_Original_Vue) {

alert('preparar_Filtro_Fecha ind ida:'+indice_Filtro_Ida+', ind vue:'+indice_Filtro_Vue+', fechaida:'+fecha_Original_Ida+', fechavue:'+fecha_Original_Vue);

	var enviar_XML=false; //por defecto no enviamos el xml nuevamente
	var sq=""; //por defecto no agregamos la etiqueta sq
	var mtr_valores = new Array(); //despues va a contener el arreglo de <SQ> a enviar
	var miliseg_Dia = 1000 * 60 * 60 * 24; //duracion de un dia en milisegundos
alert('a1');	
	var fecha_Seleccionada_Ida = document.getElementById('formfil_sp_fecha_v').options[indice_Filtro_Ida].value; //obtener fecha seleccionada ida
alert('a2');	
	var arr_Fecha_Seleccionada_Ida = fecha_Seleccionada_Ida.split('/'); //separar componentes fecha seleccionada ida
	var date_Fecha_Seleccionada_Ida = new Date(arr_Fecha_Seleccionada_Ida[2], arr_Fecha_Seleccionada_Ida[1]-1, arr_Fecha_Seleccionada_Ida[0]); //construir fecha seleccionada ida como un objeto de fecha
alert('a3');	
	
	var arr_Fecha_Original_Ida = fecha_Original_Ida.split('/'); //separar componentes fecha orig ida
	var date_Fecha_Original_Ida = new Date(arr_Fecha_Original_Ida[2], arr_Fecha_Original_Ida[1]-1, arr_Fecha_Original_Ida[0]); //construir fecha orig ida como un objeto de fecha
alert('a4');	
	
	var diferencia_Ida=Math.ceil( (date_Fecha_Seleccionada_Ida.getTime() - date_Fecha_Original_Ida.getTime() ) / miliseg_Dia); //calcular la diferencia de dias en la ida

alert('a5');	
	//vemos si es un vuelo de solo ida o ida y vuelta
	if(indice_Filtro_Vue == "" && fecha_Original_Vue == ""){
alert('a6');	

		fecha_Seleccionada_Vue = ""; //para no romper nada despues
		//analizar la diferencia
		if(Math.abs(diferencia_Ida) >= 1){
alert('a7');	
		
			mtr_valores = new Array(22,23,24,25,26,27,28);
			sq = mtr_valores[diferencia_Ida + 3]; //tenemos que buscar nuevamente

			enviar_XML = true;

		}
	}
	else{
alert('b1');	
		
		mtr_valores[0] = new Array(1,2,3,4,5,6,7);
		mtr_valores[1] = new Array(8,9,10,11,12,13,14);
		mtr_valores[2] = new Array(15,16,17,18,19,20,21);
		mtr_valores[3] = new Array(22,23,24,25,26,27,28);
		mtr_valores[4] = new Array(29,30,31,32,33,34,35);
		mtr_valores[5] = new Array(36,37,38,39,40,41,42);
		mtr_valores[6] = new Array(43,44,45,46,47,48,49);
		
		var fecha_Seleccionada_Vue = document.getElementById('formfil_sp_fecha_v').options[indice_Filtro_Vue].value; //obtener fecha vuelta
		var arr_Fecha_Seleccionada_Vue = fecha_Seleccionada_Vue.split('/'); //separar componentes fecha seleccionada vuelta
		var date_Fecha_Seleccionada_Vue = new Date(arr_Fecha_Seleccionada_Vue[2], arr_Fecha_Seleccionada_Vue[1]-1, arr_Fecha_Seleccionada_Vue[0]); //construir fecha seleccionada vuelta como un objeto de fecha
	
		var arr_Fecha_Original_Vue = fecha_Original_Vue.split('/'); //separar componentes fecha orig vuelta
		var date_Fecha_Original_Vue = new Date(arr_Fecha_Original_Vue[2], arr_Fecha_Original_Vue[1]-1, arr_Fecha_Original_Vue[0]); //construir fecha orig vuelta como un objeto de fecha
		
		var diferencia_Vue = Math.ceil( (date_Fecha_Seleccionada_Vue.getTime() - date_Fecha_Original_Vue.getTime() ) / miliseg_Dia); //calcular la diferencia de dias en la vuelta
		
		//analizar la diferencia
		if(Math.abs(diferencia_Ida) >= 1 || Math.abs(diferencia_Vue) >= 1){
		
			//tenemos que buscar nuevamente
			sq = mtr_valores[diferencia_Vue + 3][diferencia_Ida + 3];
			enviar_XML = true;
		}
	}
  
  var pars = 'sq=' + sq + '&dc1=' + fecha_Seleccionada_Ida + '&dc2=' + fecha_Seleccionada_Vue;
  alert(pars);
//	document.getElementById('cx').src = 'log.resultados.filtrar.enviarxml.php?' + pars;
	return false;
}
*/
/*
function controlXML(res) {
	if (res.responseText=='ERROR') {  //hay que controlar el error
		$('boton').value=0;
		alert ('ERROR');
		Element.hide('loading');
		Element.show('container');
	}
	else {
		mostrar_vuelos();
	}
}
*/
/*
function controlXML_MP(res) {  //funcion que
	if (res.responseText=='ERROR') {  //hay que controlar el error
		alert ('ERROR');
		try{
			history.go(-1);
		}
		catch(e){
			parent.history.go(-1);
		}
	}
	else {
		mostrar_vuelos();
	}
}
*/
/*
function mostrar_vuelos_filtrados() {
	window.location='gui.resultados.php';
}
*/
/*
function mostrar_vuelos() {
	window.location='gui.resultados.php';
}
*/
function mostrar_vuelos_sobreescribiendo_sesion(id_sesion_anterior) {
	var pars= 'foo=bar&id_sesion_sob=' + id_sesion_anterior;
	var aj = new Ajax.Request('gui.resultados.php',
	{
		method: 'get',
		parameters:pars,
		onSuccess: function (res) {
			Element.remove('loading');
			$('container').replace (res.responseText);
			Element.show('container');
		}
	});
}
// ok
function validar_motor_principal() {
	if (document.formBusc.autorelleno.value=="") {
		alert(VUE_MOT_ERR_NO_ORIGIN);
		document.formBusc.autorelleno.focus();
		return false;
	}
	if (document.formBusc.autorelleno2.value=="") {
		alert(VUE_MOT_ERR_NO_DESTINY);
		document.formBusc.autorelleno2.focus();
		return false;
	}
	if (document.formBusc.autorelleno.value==document.formBusc.autorelleno2.value){
		alert(VUE_MOT_ERR_AIRPORT_MISMATCH);
		return false;
	}
	if (document.formBusc.dc1.value=="") {
		alert(VUE_MOT_ERR_NO_DEPARTURE_DATE);
		document.formBusc.dc1.focus();
		return false;
	}
	if (document.formBusc.dc2.value=="" && $('viaje').value==1) {
		alert(VUE_MOT_ERR_NO_ARRIVAL_DATE);
		document.formBusc.dc2.focus();
		return false;
	}
	if ($('aero_origen')=="" || $F('aero_destino')=="" ) { //significa que escribio algo pero no uso el autocompletar. Entonces vamos a buscar si estan correctos los destinos.
		if ($F('aero_origen')!="") {//significa que el origen esta bien
			var id=$F('aero_origen');
		}
		else{
			var id=$F('autorelleno');
		}
		if ($F('aero_destino')!="") {//significa que el destino esta bien
			var id2=$F('aero_destino');
		}else{
			var id2=$F('autorelleno2');
		}
		origen=id;
		destino=id2;
		var pars= 'SESS='+document.getElementById('SESS').value+'&id=' + id +'&id2=' + id2;
		var aj = new Ajax.Request(base+'log.motor.validar.php',{method:'get',parameters:pars,onComplete:mostrar_resultado});

		return false;
	}
	if ($('boton').value!=1) {
    document.formBusc.submit();
	}
	return false;
}

function cargareserva(){
	try{ Element.hide('container'); }
	catch(e){}
	try{ Element.show('reservando2'); }
	catch(e){}
}

function descargareserva(){
	try{ document.getElementById('img_reservando2').src='../images/esperando.jpg'; }
	catch(e){}
	try{ Element.show('container'); }
	catch(e){}
	try{ Element.hide('reservando2'); }
	catch(e){}
}

function ValidaFecha(field){
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	DateValue = DateField.value;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) {
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}
	DateValue = DateTemp;
	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 6) {
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
		if (DateValue.length != 8) {
			err = 19;}
			/* year is wrong if year = 0000 */
			year = DateValue.substr(4,4);
			if (year == 0) {
				err = 20;
			}
			/* Validation of month*/
			month = DateValue.substr(2,2);
			if ((month < 1) || (month > 12)) {
				err = 21;
			}
			/* Validation of day*/
			day = DateValue.substr(0,2);
			if (day < 1) {
				err = 22;
			}
			/* Validation leap-year / february / day */
			if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
				leap = 1;
			}
			if ((month == 2) && (leap == 1) && (day > 29)) {
				err = 23;
			}
			if ((month == 2) && (leap != 1) && (day > 28)) {
				err = 24;
			}
			/* Validation of other months */
			if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
				err = 25;
			}
			if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
				err = 26;
			}
			/* if 00 ist entered, no error, deleting the entry */
			if ((day == 0) && (month == 0) && (year == 00)) {
				err = 0; day = ""; month = ""; year = ""; seperator = "";
			}
			/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
			if (err == 0) {
				DateField.value = day + seperator + month + seperator + year;
			}
			/* Error-message if err != 0 */
			else {
				alert("La fecha ingresada es incorrecta.");
				DateField.select();
				DateField.focus();
			}
}

function ValidaFechaM(field){
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	DateValue = DateField.value;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) {
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}
	DateValue = DateTemp;
	/* Always change date to 8 digits - string OBSOLETO*/
	/* if year is entered as 2-digit / always assume 20xx */
	/*if (DateValue.length == 6) {
	DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }*/

	if (DateValue.length != 8) {
		err = 19;}
		/* year is wrong if year = 0000 */
		year = DateValue.substr(4,4);
		if (year == 0) {
			err = 20;
		}
		/* Validation of month*/
		month = DateValue.substr(2,2);
		if ((month < 1) || (month > 12)) {
			err = 21;
		}
		/* Validation of day*/
		day = DateValue.substr(0,2);
		if (day < 1) {
			err = 22;
		}
		/* Validation leap-year / february / day */
		if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
			leap = 1;
		}
		if ((month == 2) && (leap == 1) && (day > 29)) {
			err = 23;
		}
		if ((month == 2) && (leap != 1) && (day > 28)) {
			err = 24;
		}
		/* Validation of other months */
		if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
			err = 25;
		}
		if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
			err = 26;
		}
		/* if 00 ist entered, no error, deleting the entry */
		if ((day == 0) && (month == 0) && (year == 00)) {
			err = 0; day = ""; month = ""; year = ""; seperator = "";
		}
		/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
		if (err == 0) {
			DateField.value = day + seperator + month + seperator + year;
		}
		/* Error-message if err != 0 */
		else {
			alert(VUE_BOK_ERR_DATE);
			DateField.select();
			DateField.focus();
		}
}

/*
* ValidaEmail: Comprobamos que siga el patrón de una direccióin de email válida
*/
function ValidaEmail(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if (regex.test(src)) {
		return true;
	} else {
		return false;
	}
}

/*
*  Normaliza: Quitamos todos los acentos y signos de puntuaión
*/
function Normaliza(fieldname) {
	var campo=document.getElementById(fieldname).value;

	while (campo.indexOf(".")>=0) {
		campo=campo.replace(/./,'');
	}

	while (campo.indexOf("-")>=0) {
		campo=campo.replace(/-/,'');
	}

	while (campo.indexOf("_")>=0) {
		campo=campo.replace(/_/,'');
	}

	while (campo.indexOf("'")>=0) {
		campo=campo.replace(/'/,'');
 }

 while (campo.indexOf("´")>=0) {
    campo=campo.replace(/´/,'');
 }

 while (campo.indexOf("`")>=0) {
    campo=campo.replace(/`/,'');
 }

 while (campo.indexOf('"')>=0) {
    campo=campo.replace(/"/,'');
	}

	while (campo.indexOf('á')>=0) {
		campo=campo.replace(/á/,'a');
	}
	while (campo.indexOf('é')>=0) {
		campo=campo.replace(/é/,'e');
	}
	while (campo.indexOf('í')>=0) {
		campo=campo.replace(/í/,'i');
	}
	while (campo.indexOf('ó')>=0) {
		campo=campo.replace(/ó/,'o');
	}
	while (campo.indexOf('ú')>=0) {
		campo=campo.replace(/ú/,'u');
	}

	while (campo.indexOf('Á')>=0) {
		campo=campo.replace(/Á/,'A');
	}
	while (campo.indexOf('É')>=0) {
		campo=campo.replace(/É/,'E');
	}
	while (campo.indexOf('Í')>=0) {
		campo=campo.replace(/Í/,'I');
	}
	while (campo.indexOf('Ó')>=0) {
		campo=campo.replace(/Ó/,'O');
	}
	while (campo.indexOf('Ú')>=0) {
		campo=campo.replace(/Ú/,'U');
	}

	while (campo.indexOf('à')>=0) {
		campo=campo.replace(/à/,'a');
	}
	while (campo.indexOf('è')>=0) {
		campo=campo.replace(/è/,'e');
	}
	while (campo.indexOf('ì')>=0) {
		campo=campo.replace(/ì/,'i');
	}
	while (campo.indexOf('ò')>=0) {
		campo=campo.replace(/ò/,'o');
	}
	while (campo.indexOf('ù')>=0) {
		campo=campo.replace(/ù/,'u');
	}

	while (campo.indexOf('À')>=0) {
		campo=campo.replace(/À/,'A');
	}
	while (campo.indexOf('È')>=0) {
		campo=campo.replace(/È/,'E');
	}
	while (campo.indexOf('Ì')>=0) {
		campo=campo.replace(/Ì/,'I');
	}
	while (campo.indexOf('Ò')>=0) {
		campo=campo.replace(/Ò/,'O');
	}
	while (campo.indexOf('Ù')>=0) {
		campo=campo.replace(/Ù/,'U');
	}

	while (campo.indexOf('ñ')>=0) {
		campo=campo.replace(/ñ/,'n');
	}
	while (campo.indexOf('Ñ')>=0) {
		campo=campo.replace(/Ñ/,'N');
	}
	while (campo.indexOf('ç')>=0) {
		campo=campo.replace(/ç/,'c');
	}
	while (campo.indexOf('Ç')>=0) {
		campo=campo.replace(/Ç/,'C');
	}

	while (campo.indexOf('ä')>=0) {
		campo=campo.replace(/ä/,'a');
	}
	while (campo.indexOf('ë')>=0) {
		campo=campo.replace(/ë/,'e');
	}
	while (campo.indexOf('ï')>=0) {
		campo=campo.replace(/ï/,'i');
	}
	while (campo.indexOf('ö')>=0) {
		campo=campo.replace(/ö/,'o');
	}
	while (campo.indexOf('ü')>=0) {
		campo=campo.replace(/ü/,'u');
	}

	while (campo.indexOf('Ä')>=0) {
		campo=campo.replace(/Ä/,'A');
	}
	while (campo.indexOf('Ë')>=0) {
		campo=campo.replace(/Ë/,'E');
	}
	while (campo.indexOf('Ï')>=0) {
		campo=campo.replace(/Ï/,'I');
	}
	while (campo.indexOf('Ö')>=0) {
		campo=campo.replace(/Ö/,'O');
	}
	while (campo.indexOf('Ü')>=0) {
		campo=campo.replace(/Ü/,'U');
	}

	while (campo.indexOf('â')>=0) {
		campo=campo.replace(/â/,'a');
	}
	while (campo.indexOf('ê')>=0) {
		campo=campo.replace(/ê/,'e');
	}
	while (campo.indexOf('î')>=0) {
		campo=campo.replace(/î/,'i');
	}
	while (campo.indexOf('ô')>=0) {
		campo=campo.replace(/ô/,'o');
	}
	while (campo.indexOf('û')>=0) {
		campo=campo.replace(/û/,'u');
	}

	while (campo.indexOf('Â')>=0) {
		campo=campo.replace(/Â/,'A');
	}
	while (campo.indexOf('Ê')>=0) {
		campo=campo.replace(/Ê/,'E');
	}
	while (campo.indexOf('Î')>=0) {
		campo=campo.replace(/Î/,'I');
	}
	while (campo.indexOf('Ô')>=0) {
		campo=campo.replace(/Ô/,'O');
	}
	while (campo.indexOf('Û')>=0) {
		campo=campo.replace(/Û/,'U');
	}

	while (campo.indexOf('º')>=0) {
		campo=campo.replace(/º/,'o');
	}

	while (campo.indexOf('ª')>=0) {
		campo=campo.replace(/ª/,'a');
	}
	while (campo.indexOf('/')>=0) {
		campo=campo.replace(/\//,'');
	}
	while (campo.indexOf('\\')>=0) {
		campo=campo.replace(/\\/,'');
	}
	while (campo.indexOf('\|')>=0) {
		campo=campo.replace(/\|/,'');
	}
	while (campo.indexOf(',')>=0) {
		campo=campo.replace(/,/,'');
	}
	while (campo.indexOf(';')>=0) {
		campo=campo.replace(/;/,'');
	}
	document.getElementById(fieldname).value=campo;
}

/**
 * @TODO hacer algo como la gente
 */
function stripHtml(s) {
	s=s.replace('<b>','');
	s=s.replace('</b>','');
	s=s.replace('<font>','');
	s=s.replace('</font>','');
	s=s.replace('<B>','');
	s=s.replace('</B>','');
	s=s.replace('<FONT>','');
	s=s.replace('</FONT>','');
	s=s.replace('<TR>','');
	s=s.replace('</TR>','');
	s=s.replace('<TD>','');
	s=s.replace('</TD>','');
	s=s.replace('<tr>','');
	s=s.replace('</tr>','');
	s=s.replace('<td>','');
	s=s.replace('</td>','');
	s=s.replace(' ','');
	return s;
}

function mostrarreserva_pre(){
	Element.hide('container');
	Element.show('reservando2');
}

function mostrarreserva_cancel(){
	Element.show('container');
	Element.hide('reservando2');
}

function mostrarreserva(id_vuelo,id_sesion,descuento){
	if(descuento=='') descuento=0;
	var pars= '?id_vuelo=' + id_vuelo +'&id_sesion=' + id_sesion+'&descuento='+descuento;
	var aj = new Ajax.Request('gui.reserva.php',
	{
		method: 'get',
		parameters:pars,
		onSuccess: function (res) {
			$('container').replace (res.responseText);
			Element.show('container');
			Element.hide('reservando2');
		}
	});
}

function mostrarConfirmacion(respuestaxml,id_sesion,id_sesion_anterior,product_id,postdata,duracion_ida,duracion_vuelta){
	try{
		window.clearTimeout(iTimeoutID);
	}
	catch(e){}
	try{
		window.parent.clearTimeout(iTimeoutID);
	}
	catch(e){}
	var pars='?foo=bar&respuesta='+respuestaxml+'&id_sesion='+id_sesion+'&id_sesion_anterior='+id_sesion_anterior+'&product_id='+product_id+'&postdata='+postdata+'&di='+duracion_ida+'&dv='+duracion_vuelta;
	var aj2 = new Ajax.Request('gui.bono.php',
	{
		method:'post',
		parameters:pars,
		onSuccess:function(res){
			try { document.getElementById('container').innerHTML=res.responseText; }
			catch(e) { alert(VUE_BOK_ERR_SHOWING_TICKET); }
			try { Element.show('container'); }
			catch(e) { alert(VUE_BOK_ERR_SHOWING_TICKET); }
			try { Element.hide('reservando2'); }
			catch(e) {}
		}
	});
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/

/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0;  /* hex output t. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test(){
	return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len)
{
	/* append padding */
	x[len >> 5] |= 0x80 << ((len) % 32);
	x[(((len + 64) >>> 9) << 4) + 14] = len;

	var a =  1732584193;
	var b = -271733879;
	var c = -1732584194;
	var d =  271733878;

	for(var i = 0; i < x.length; i += 16)
	{
		var olda = a;
		var oldb = b;
		var oldc = c;
		var oldd = d;

		a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
		d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
		c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
		b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
		a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
		d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
		c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
		b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
		a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
		d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
		c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
		b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
		a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
		d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
		c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
		b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

		a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
		d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
		c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
		b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
		a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
		d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
		c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
		b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
		a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
		d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
		c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
		b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
		a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
		d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
		c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
		b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

		a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
		d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
		c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
		b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
		a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
		d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
		c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
		b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
		a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
		d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
		c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
		b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
		a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
		d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
		c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
		b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

		a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
		d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
		c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
		b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
		a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
		d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
		c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
		b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
		a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
		d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
		c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
		b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
		a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
		d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
		c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
		b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

		a = safe_add(a, olda);
		b = safe_add(b, oldb);
		c = safe_add(c, oldc);
		d = safe_add(d, oldd);
	}
	return Array(a, b, c, d);

}

/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
	return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
	return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
	return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
	return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
	return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data)
{
	var bkey = str2binl(key);
	if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

	var ipad = Array(16), opad = Array(16);
	for(var i = 0; i < 16; i++)
	{
		ipad[i] = bkey[i] ^ 0x36363636;
		opad[i] = bkey[i] ^ 0x5C5C5C5C;
	}

	var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
	return core_md5(opad.concat(hash), 512 + 128);
}

/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
	var lsw = (x & 0xFFFF) + (y & 0xFFFF);
	var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
	return (msw << 16) | (lsw & 0xFFFF);
}

/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
	return (num << cnt) | (num >>> (32 - cnt));
}

/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str)
{
	var bin = Array();
	var mask = (1 << chrsz) - 1;
	for(var i = 0; i < str.length * chrsz; i += chrsz)
	bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
	return bin;
}

/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin)
{
	var str = "";
	var mask = (1 << chrsz) - 1;
	for(var i = 0; i < bin.length * 32; i += chrsz)
	str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
	return str;
}

/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray)
{
	var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
	var str = "";
	for(var i = 0; i < binarray.length * 4; i++)
	{
		str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
		hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
	}
	return str;
}

/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray)
{
	var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var str = "";
	for(var i = 0; i < binarray.length * 4; i += 3)
	{
		var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
		| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
		|  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
		for(var j = 0; j < 4; j++)
		{
			if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
			else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
		}
	}
	return str;
}

function Mod10(s){
	var v = "0123456789";
	var w = "";
	for (var i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	var j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7){
		alert(VUE_BOK_ERR_TC_NUMBER_WRONG);
		return false;
	}
	var k = Math.floor(j);
	var m = Math.ceil(j) - k;
	var c = 0;
	for (var i=0; i<k; i++) {
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	var result=(c%10 == 0);
	if(!result) alert(VUE_BOK_ERR_TC_NUMBER_WRONG);
	return result;
}

function limpiar_busqueda_vuelos_secundario(){
	document.getElementById('autorelleno').value='';
	document.getElementById('autorelleno2').value='';
	document.getElementById('dc1').value='';
	document.getElementById('dc2').value='';
	document.getElementById('num_adultos').value='1';
	document.getElementById('num_ninios').value='0';
	document.getElementById('num_bebes').value='0';
	try { document.getElementById('descuento').value='0'; }   catch(e){}
	try { document.getElementById('descuento').checked=''; }   catch(e){}
	try {	document.getElementById('incluir_lowcost').checked=''; } catch(e){}
	try { document.getElementById('fechas_flexibles').checked='';	} catch(e){}
}

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

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

/**
 * elementId id del tbody que contiene los input
 * flightType a = automatico, c = combinado
 * routeType oi = ida y vuelta, o = ida, i = vuelta
 */
function uncheckRadiosIn(elementId,formName,flightType,routeType){
	try{
		if(document.getElementById('e'+formName).prev_flighttype.value=='a'){
			/**
			 * el vuelo anterior era de ida y vuelta juntos asi que limpiamos todo para poder validar despues
			 */
			 document.getElementById('e'+formName).ida.value='';
			 document.getElementById('e'+formName).vuelta.value='';
		}
		document.getElementById('e'+formName).prev_flighttype.value=flightType;
	}
	catch(e){}
	try{
	treeTraverseRecursion(document.getElementById(elementId));
	}
	catch(e){}
}

function treeTraverseRecursion(currentElem) {
	var i = 0;
	var currentElemChild = currentElem.childNodes[i];

	if (currentElem) {
		while (currentElemChild) {
			treeTraverseRecursion(currentElemChild);
			i++;
			currentElemChild = currentElem.childNodes[i];
		}
		visit(currentElem);
	}
}

function visit(elem) {
	if(elem.tagName=='INPUT'){
        if(elem.getAttribute('type')=='radio'){
            elem.checked=false;
            elem.setAttribute('checked',false);
        }
    }
}
