﻿

function fechaComboHome() {

	if (hotel_combo_checkHome()) {
             
		fecha2 = document.getElementById("dateEntradaHoteles").value;
    	document.getElementById("fechaEntrada").value = fecha2;
		document.getElementById("fechaEntradaMos").innerHTML=fecha2 + ", "+ GetDiaNombre(fecha2);
        fechaHotelVueltaHome();
        f =  new Date(fecha2);
	}


}

function cambiarHabitacionesHome(val) 
{
	for(var i =1;i<5;i++) 
	{
	    document.getElementById("cajahab" + i).style.visibility="hidden";
	    document.getElementById("cajahab" + i).style.display="none";
  
  		for(var x=1;x<4;x++) 
		{ 
		    document.getElementById("edad" + i + "-" + x).style.visibility="hidden";
		    document.getElementById("edad" + i + "-" + x).style.display="none";
            document.getElementById("cajahab" + i).selectedIndex=0;
        }
        document.getElementById("Habninos" + i).style.visibility="hidden";
        document.getElementById("dHab" + i).className="dHab d-n";
        document.getElementById("edad" + i).className="edad d-n";
	    
	}
	for(i=1;i<=val;i++) 
	{
	    document.getElementById("dHab" + i).className="dHab d-b";
        document.getElementById("habitacion-" + i).style.visibility="visible";
	    document.getElementById("habitacion-" + i).style.display="inline";
        document.getElementById("cajahab" + i).style.visibility="visible";
	    document.getElementById("cajahab" + i).style.display="inline";
	}

}



function validarHoteles() 
{
    document.getElementById("layerError").className = "layerError d-n";
    document.getElementById("destinoAlert").style.visibility="hidden";
    document.getElementById("fechaAlert").style.visibility="hidden";
    document.getElementById("edadesAlert").style.visibility="hidden";
    document.getElementById("destinoAlert").style.display="none";
    document.getElementById("fechaAlert").style.display="none";
    document.getElementById("edadesAlert").style.display="none";
    
	if(!hotel_poblacion_checkHome()) {
        document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("destinoAlert").style.visibility="visible";
 	    document.getElementById("destinoAlert").style.display="";
		return;
    }
    if(!hotel_combo_checkHome()) {
 	    document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("fechaAlert").style.visibility="visible";
 	    document.getElementById("fechaAlert").style.display="";
		return;
    }
    if(!hotel_o_paquete_edad_checkHome()) {
 	    document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("edadesAlert").style.visibility="visible";
 	    document.getElementById("edadesAlert").style.display="";
		return;
    }

    var msg='';
	var poblacion = quitarTilde(document.getElementById('nombreHotel').value);
    var fechahotel = cambiarFechaHotelHome(document.getElementById("fechaEntrada").value);
    var noches; 
    noches=document.getElementById("noches").options[document.getElementById("noches").selectedIndex].value.toString();
	
	
	var habitaciones = document.getElementById("habitaciones").value;
    var ocupacion='';
	var edades='';
	var edadTempAux = "";
	
	for(var i=1;i<=habitaciones;i++) {
		//obtener ocupaciones y edades
		ocupacion += document.getElementById("cajahab" + i).value + "/";
	    var n = document.getElementById("cajahab" + i).value.split("-")[1]; //cuantos ninos
	    n = (!n ? 0 : parseInt(n));
		var ed=(n == 0 ? "--" : "");
	    for(var j=1;j<=n;j++) {
		    edadTempAux =document.getElementById("edad"+i+"-"+j).value + "-";
			//Si peta al cogerlo por JQuery, lo intentamos coger por el metodo tradicional que nunca falla
			if(edadTempAux == "undefined-") {
				edadTempAux = document.getElementById("edad" + i + "-" + j)[document.getElementById("edad" + i + "-" + j).selectedIndex].text + "-";
			}
			ed += edadTempAux;
		}
		ed = ed.substring(0,ed.length-1);
		edades += ed + "/";
	}
	
	
	ocupacion = ocupacion.substring(0,ocupacion.length-1);
	
    var url='/hoteles/Buscador/ResultadosHoteles.aspx?pob=' + poblacion + '&ocupa=' + ocupacion + '&edades=' + edades + '&numhab=' + habitaciones + '&fent=' + fechahotel + '&n=' + noches;
	url = "http://hoteles.muchoviaje.com" + url;
	document.location.href=url;
	return false;
}

function cambiarOcupacionHome(which, val) 
{
	var n = val.split('-')[1]; //cuantos niños
    n = (!n ? 0 : parseInt(n));
    if (n == 0) 
    {
		for(var i =1;i<4;i++) 
		{
		    document.getElementById("edad" + which + "-" + i).style.visibility = "hidden";
		    document.getElementById("edad" + which).className = "edad d-n";
		}
		   
		
	    document.getElementById("Habninos" + which).style.visibility="hidden";
	    
    }
    else 
    {
	    document.getElementById("Habninos" + which ).style.visibility="visible";
	    document.getElementById("Habninos" + which ).style.display="inline";
	    document.getElementById("edad" + which).className = "edad d-b";
		
		for(var i =1;i<4;i++) 
		{ 
		    document.getElementById("edad" + which + "-" + i).style.visibility="hidden";
		    document.getElementById("edad" + which).className = "edad d-n";
		}
		document.getElementById("edad" + which).className = "edad d-b";
		for(i=1;i<=n;i++) 
		{ 
		    document.getElementById("edad" + which + "-" + i).style.visibility="visible";
		    document.getElementById("edad" + which + "-" + i).style.display="inline";
		 
		}

	} 
	
	
	
}

//funciones para probar si el formulario puede submit o no
function hotel_combo_checkHome() {
	probarFecha = document.getElementById("dateEntradaHoteles").value 
 
	var reg = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
  if (probarFecha.match(reg)) {
	    var fSelecarr = $("#dateEntradaHoteles").val().split("/");
		f =  new Date(fSelecarr[1] + "/" + fSelecarr[0] + "/" + fSelecarr[2]);
        var fArr = document.getElementById("fechaHoy").value.split("/");
		hoy = new Date(fArr[1] + "/" + fArr[0] + "/" + fArr[2]);
	    diferenciaDias = Math.round((f - hoy)/(24*60*60*1000));
    
	    if(diferenciaDias < -1) {
			return false;
		} else {
			return true
        }
    } else {
    return false;
    } 
}

function GetDiaNombre(fecha) {
	//fecha tiene que estar en formato dd/mm/yy o d/m/yy o yyyy
	m = fecha.match(/^(\d*)(\/?)(\d*)(\2)(\d\d)?(\d\d)$/);
	m[1] = mLength(m[1]); // 6 -> 06 dia
	m[3] = mLength(m[3]); // 6 -> 06 mes
	m[5] = yLength(m[5]); // 07 -> 2007 anio
	d =["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"];
	return d[new Date(m[5] + m[6] + "/" + m[3] + "/" + m[1]).getDay()];
}

function yLength(y) {
	y = (parseInt(y) < 100 ? "20" + y : y);
	return y;
}
function mLength(m) {
	m = (m.length == 1 ? "0" + m : m);
	return m;
}

function fechaHotelVueltaHome() {
    fecha =document.getElementById("fechaEntrada").value;
    n = parseInt(document.getElementById("noches").value);
    var fArr = fecha.split("/");
    var d = fArr[0];
    var m = fArr[1]-1;
    var y = fArr[2];
    var fVuelta=new Date();
    fVuelta.setFullYear(y,m,d);
    fVuelta.setDate(fVuelta.getDate()+n);
    dia=fVuelta.getDate();
    mes=(fVuelta.getMonth()+1);
    if(dia <= 9)
        {
            dia = "0" + dia;
        }
        if(mes <= 9)
        {
            mes = "0" + mes;
        }

    fVuelta = dia + "/" + mes + "/" + fVuelta.getFullYear();
    document.getElementById("dateSalidaHoteles").value=fVuelta;
    document.getElementById("fechaVuelta").innerHTML=fVuelta + ", "+ GetDiaNombre(fVuelta);
}

function seleccionarDia (dia, mes, anio) {
        if(dia <= 9)
        {
            dia = "0" + dia;
        }
        if(mes <= 9)
        {
            mes = "0" + mes;
        }

        var ida = dia + "/" + mes + "/" + anio;
        document.getElementById("dateEntradaHoteles").value=ida;
        fechaComboHome();
        fechaHotelVueltaHome();
 
}
       
       function hotel_poblacion_checkHome() {

  	if (document.getElementById("nombreHotel").value=="undefined")
  	{
        p = '';
    }
  	else
  	{
        p =document.getElementById("nombreHotel").value;
  	}
    if (p == 'Elige tu destino...' || p =='' || p.charCodeAt(0) == 32)
    { 
        return  false;
    }
    else
    { 
        return  true;
    }
   
}

function hotel_o_paquete_edad_checkHome() {
    //segurar que los edades estan rellenados
 var allgood = true;
    for(var i=1;i<=document.getElementById("habitaciones").value;i++) {
				n =document.getElementById("cajahab" + i).value.split("-")
				n= (n[1]? n[1] : 0);
				for(var j=1;j<=n;j++) {
					if(document.getElementById("edad" + i + "-" + j).selectedIndex == 0) { allgood = false; }
				}
            }
    return allgood;
}

function quitarTilde(str) {
	rep ={"á":"-aacute","é":"-eacute","í":"-iacute","ó":"-oacute","ú":"-uacute","Á":"-Aacute","É":"-Eacute","Í":"-Iacute","Ó":"-Oacute","Ú":"-Uacute","ñ":"-ntilde","Ñ":"-Ntilde"};
	for(var p in rep) {
		str=str.replace(p,rep[p]);
	}
	return str;
}

function cambiarFechaHotelHome(fecha) {
	var iArr = fecha.split('/');
	y = yLength(iArr[2]);
	m = mLength(iArr[1]);
	d = mLength(iArr[0]);
	fecha = y + '-' + m + '-' + d;
	return fecha;
}



function cambiaPestana(obj){
    document.getElementById(obj).className = 'selec';
    document.getElementById('hidTipoBuscador').value = obj;
 
    switch (obj)
    {
        case 'hoteles':
            // Paquetes
            document.getElementById(obj).className = "leftSelected";
            document.getElementById('paquetes').className = "";  
            document.getElementById('fechaHasta').className = "fechaHasta d-n"; 
            document.getElementById('busc_av').className = "d-n"; 
            document.getElementById('lblEntrada').innerHTML = "Fecha de Entrada";
            $('#suggestions').hide();
            //Hoteles
            document.getElementById('hab').className = "hab d-b"; 
            document.getElementById('nhab').className = "nHab d-b"; 
            document.getElementById('pfechaHasta').className = "d-b";
            document.getElementById('pfecha').className = "d-b";
            document.getElementById('divnoches').className = "noches d-b"; 
            document.getElementById('lblNom').innerHTML = "Hoteles"
           
            break;
        case 'paquetes':
            // Paquetes
            document.getElementById(obj).className = "rightSelected"; 
            document.getElementById('hoteles').className = "";  
            document.getElementById('fechaHasta').className = "fechaHasta d-b"; 
            document.getElementById('busc_av').className = "d-b"; 
            //Hoteles
            document.getElementById('hab').className = "hab d-n"; 
            document.getElementById('nhab').className = "nHab d-n"; 
            document.getElementById('pfechaHasta').className = "d-n"
            document.getElementById('pfecha').className = "d-n"
            document.getElementById('divnoches').className = "noches d-n"; 
            document.getElementById('lblEntrada').innerHTML = "Para viajar entre:";
            document.getElementById('lblNom').innerHTML = "Escapadas en España y en Europa"
           
            break;
     }
     document.getElementById('nombreHotel').value = '';
}

function DesplegaBusqueda()
{
    if ( document.getElementById("busquedaAvanzada").style.visibility!="visible")
    {
        document.getElementById("busquedaAvanzada").style.visibility="visible";
        document.getElementById("busquedaAvanzada").style.display="";
    }
    else
    {
        document.getElementById("busquedaAvanzada").style.visibility="hidden";
        document.getElementById("busquedaAvanzada").style.display="none";
        document.getElementById("cmbOrigen").selectedIndex=0;
        document.getElementById("cmbMarcas").selectedIndex=0;
    }

}

function seleccionaRegistro() {
    if (document.getElementById('hidTipoBuscador').value == 'hoteles')
          validarHoteles();
          
    if (document.getElementById('hidTipoBuscador').value == 'paquetes') {      
    if ((document.getElementById("codigoDestino").value=='')&&((document.getElementById("suggestions").style.visibility == 'hidden' || document.getElementById("suggestions").style.visibility == ''))) 
    { 
        document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("destinoAlert").style.visibility="visible";
 	    document.getElementById("destinoAlert").style.display="";
 	}
    else 
    {
        if (document.getElementById("suggestions").style.visibility == 'visible')  
        {
            if (($("#sugestionContador").attr("value")!=undefined)&&($("#sugestionContador").attr("value")!=''))
                document.getElementById("autoSuggestionsList" + $("#sugestionContador").attr("value")).onclick();
            else 
                document.getElementById("autoSuggestionsList0").onclick();
                
        }
        validarPaquetes();
    }
    }
  }   
    
    function validarPaquetes() 
{
   
    document.getElementById("layerError").className = "layerError d-n";
    document.getElementById("destinoAlert").style.visibility="hidden";
    document.getElementById("fechaAlert").style.visibility="hidden";
    document.getElementById("edadesAlert").style.visibility="hidden";
    document.getElementById("destinoAlert").style.display="none";
    document.getElementById("fechaAlert").style.display="none";
    document.getElementById("edadesAlert").style.display="none";
    
	if(!hotel_poblacion_checkHome()) {
        document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("destinoAlert").style.visibility="visible";
 	    document.getElementById("destinoAlert").style.display="";
		return;
    }
    if(!hotel_combo_checkHome()) {
 	    document.getElementById("layerError").className = "layerError d-b";
 	    document.getElementById("fechaAlert").style.visibility="visible";
 	    document.getElementById("fechaAlert").style.display="";
		return;
    }
   
    var msg='';
 
	var poblacion = document.getElementById("codigoDestino").value;
	
	var typedest = document.getElementById("tipoDestino").value;
	var name = document.getElementById("nombreHotel").value;
	var fechaDesde = cambiarFechaHotelHome(document.getElementById("fechaEntrada").value);

	var fechaHasta = cambiarFechaHotelHome(document.getElementById("fechaSalidaPaq").value);

	var noches = document.getElementById("noches").value;
	var origen='';
	var origen=document.getElementById("cmbOrigen").value;
	var marca='';
	var marca=document.getElementById("cmbMarcas").value;
    	 
	
	 var url = 'http://vacaciones.muchoviaje.com/' + GetResultsRwPathWithDates(poblacion, name, typedest, fechaDesde, fechaHasta, noches,origen,marca);
                                
    document.getElementById("busquedaAvanzada").style.visibility="hidden";
    document.getElementById("busquedaAvanzada").style.display="none";
   
    var navegador = navigator.appName;
    document.getElementById("codigoDestino").value='';
    document.location.href=url;
	return false;
	}
	
	function hotel_poblacion_check() {
    //segurar que poblacion no es igual a "poblacion" o con valor blanco¡
    p = trim($("#poblacion").attr("value") ? $("#poblacion").attr("value") : " ")
    return (p == 'Poblacion' || p =='' || p.charCodeAt(0) == 32 ? false : true)
}

function hotel_combo_check() {
	probarFecha = ($("#entradaD").attr("value") + "/" + $("#entradaM").attr("value") + "/" + $("#entradaY").attr("value"));
    
	var reg = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if (probarFecha.match(reg)) {
		//probar fecha es mas que ayer y menos que hoy+334
		f =  new Date($("#entradaM").attr("value") + "/" + $("#entradaD").attr("value") + "/" + $("#entradaY").attr("value"));
		var fArr = $("#fechaHoy").attr("value").split("/");
		hoy = new Date(fArr[1] + "/" + fArr[0] + "/" + fArr[2]);
		diferenciaDias = Math.round((f - hoy)/(24*60*60*1000));
		if(diferenciaDias < -1  || diferenciaDias > 334) {
			return false;
		} else {
			return true
        }
    } else {
        return false;
    } 
}

function hotel_combo_fechaHasta() {
    if ($("#fechaSalida").attr("value")!='' && $("#fechaSalida").attr("value")!=undefined)
    {
	    probarFecha = ($("#hastaD").attr("value") + "/" + $("#hastaM").attr("value") + "/" + $("#hastaY").attr("value"));
	    var reg = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
        if (probarFecha.match(reg)) 
        {
		    //probar fecha es mas que ayer y menos que hoy+334
		    f =  new Date($("#hastaM").attr("value") + "/" + $("#hastaD").attr("value") + "/" + $("#hastaY").attr("value"));
		    var fArr = $("#fechaHoy").attr("value").split("/");
		    hoy = new Date(fArr[1] + "/" + fArr[0] + "/" + fArr[2]);
		    diferenciaDias = Math.round((f - hoy)/(24*60*60*1000));
		    if(diferenciaDias < -1 ) 
		    {
			    return false;
		    } 
		    else 
		    {
		        diferenciaDias=0;
      		    var fArr = $("#fechaDesde").attr("value").split("/");
		        hoy = new Date(fArr[1] + "/" + fArr[0] + "/" + fArr[2]);
		        diferenciaDias = Math.round((f - hoy)/(24*60*60*1000));
                if(diferenciaDias < -1 ) 
		        {
			        return false;
		        } 
		        else 
		        {
		            return true;
                }
		    }
        } 
        else 
        {
            return false;
        } 
    }
    else{return true}

}


function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
function trim( value ) {
	return LTrim(RTrim(value));
}



function GetResultsRwPathWithDates(mgdscode,name,destination_type,date_from,date_to,duration,from,mark)
{
    if (from!="")
    {
        if (mark!="")
        {
            return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx?fechad=" + date_from + "&fechaa=" + date_to + "&n=" + duration + '&origen=' + from + '&marca=' + mark;
        }
        else
        {
            return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx?fechad=" + date_from + "&fechaa=" + date_to + "&n=" + duration + '&origen=' + from;
        }
    }
    else
    {
        if (mark!="")
        {
            return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx?fechad=" + date_from + "&fechaa=" + date_to + "&n=" + duration + '&marca=' + mark;
        }
        else
        {
            return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx?fechad=" + date_from + "&fechaa=" + date_to + "&n=" + duration;
        }
    }
    
}
function GetPreparedString(str)
{
    str = str.toLowerCase();
    str = str.replace(" ", "-");
    str = str.replace("/", "-");
    str = str.replace("\\", "-");
    str = str.replace("'", "");
    str = str.replace("*", "");
    str = str.replace("&", "");
    str = str.replace("[", "");
    str = str.replace("]", "");
    str = str.replace("{", "");
    str = str.replace("}", "");
    str = str.replace("(", "");
    str = str.replace(");", "");
    str = str.replace("^", "");
    str = str.replace("'", "-");
    str = str.replace("\"", "");
    str = str.replace("<", "");
    str = str.replace(">", "");
    str = str.replace("¿", "");
    str = str.replace("?", "");
    str = str.replace("~", "");
    str = str.replace("%", "");
    str = str.replace("#", "");
    str = str.replace("·", "-");
    str = str.replace("!", "");
    str = str.replace("¡", "");
    str = str.replace("´", "-");
    str = str.replace("`", "");
    str = str.replace("+", "-");
    str = str.replace("¨", "");
    str = str.replace(",", "-");
    str = str.replace(".", "-");

    str = str.replace("á", "a");
    str = str.replace("é", "e");
    str = str.replace("í", "i");
    str = str.replace("ó", "o");
    str = str.replace("ú", "u");
    str = str.replace("Á", "a");
    str = str.replace("É", "e");
    str = str.replace("Í", "i");
    str = str.replace("Ó", "o");
    str = str.replace("Ú", "u");

    str = str.replace("à", "a");
    str = str.replace("è", "e");
    str = str.replace("ì", "i");
    str = str.replace("ò", "o");
    str = str.replace("ù", "u");
    str = str.replace("À", "a");
    str = str.replace("È", "e");
    str = str.replace("Ì", "i");
    str = str.replace("Ò", "o");
    str = str.replace("Ù", "u");

    str = str.replace("ä", "a");
    str = str.replace("ë", "e");
    str = str.replace("ï", "i");
    str = str.replace("ö", "o");
    str = str.replace("ü", "u");
    str = str.replace("Ä", "a");
    str = str.replace("Ë", "e");
    str = str.replace("Ï", "i");
    str = str.replace("Ö", "o");
    str = str.replace("Ü", "u");

    str = str.replace(",", "-");
    str = str.replace(".", "-");

    str = str.replace("ñ", "n");
    str = str.replace("Ñ", "n");

    str = str.replace("ç", "n");
    str = str.replace("Ç", "n");
    
    return str;
}

function BuscarVueloHotel()
{
    var departure=$('#departureTH').val();
    var arrival=$('#arrivalTH').val();  
    var dateGo=$('#dateGoTH').val();
    var dateReturn=$('#dateReturnTH').val();

    if(departure != "" && arrival != "")
    {
        if(dateGo != "" && dateReturn != "")
        {
            var FecIdaarr = dateGo.split("/");
            var FecVuearr = dateReturn.split("/");
            var FechaIda = new Date(FecIdaarr[2],parseFloat(FecIdaarr[1]) - 1,FecIdaarr[0]);
            var FechaVue = new Date(FecVuearr[2],parseFloat(FecVuearr[1]) - 1,FecVuearr[0]);
            if(FechaVue > FechaIda)
            {
                showWaiterRedirect(URL_VH());
            }   
            else
            {
                $("#diverror").show();
                $("#lblError").text("Rellene Correctamente los campos de las fechas");
            }
        }
        else
        {
            $("#diverror").show();
            $("#lblError").text("Tiene que rellenar las Fechas");
        }
    }
    else
    {
        $("#diverror").show();
        if(departure == "")        
            $("#lblError").text("Rellene los campos de Origen");
        else
            $("#lblError").text("Rellene los campos de Destino");
    }
    //return showWaiterRedirect(URL_VH());

    return false;
}

