﻿var monthNames = [ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre' ]; var dayNames = [ 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado' ]; var onthNamesShort = ['Ene','Feb','Mar','Abr','May','Jun', 'Jul','Ago','Sep','Oct','Nov','Dic']; var dayNamesShort = ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb']; var formatDates = "_DAYWEEK_, _DAY_ de _MONTH_ de _YEAR_ "; 
function validarHoteles() 
{
   
    document.getElementById("layerError").style.visibility="hidden";
    document.getElementById("destinoAlert").style.visibility="hidden";
    document.getElementById("fechaAlert").style.visibility="hidden";
    $("#fechaHastaAlert").css("display") = "none";

	if(!hotel_poblacion_check()) {
 	    document.getElementById("layerError").style.visibility="visible";
 	    document.getElementById("destinoAlert").style.visibility="visible";
 	    document.getElementById("layerError").style.display="";
 	    document.getElementById("destinoAlert").style.display="";
		return;
    }
//    if(!hotel_combo_check()) {
// 	    document.getElementById("layerError").style.visibility="visible";
// 	    document.getElementById("fechaAlert").style.visibility="visible";
// 	    document.getElementById("layerError").style.display="";
// 	    document.getElementById("fechaAlert").style.display="";
//		return;
//    }
//    if(!hotel_combo_fechaHasta()) {
// 	    document.getElementById("layerError").style.visibility="visible";
// 	    document.getElementById("fechaHastaAlert").style.visibility="visible";
// 	    document.getElementById("layerError").style.display="";
// 	    document.getElementById("fechaHastaAlert").style.display="";
//		return;
//    }
    if(!ValidarFecha())
        return;
        
        
    var msg='';
 
	var poblacion = document.getElementById("codigoDestino").value
	
	var typedest = document.getElementById("tipoDestino").value
	var name = document.getElementById("nombreDestino").value
	var fechaDesde = cambiarFechaHotel(document.getElementById("fechaDesde").value)
	var fechaHasta = cambiarFechaHotel(document.getElementById("fechaHasta").value)
	var noches = document.getElementById("ctl00_cphPrincipal_Buscador1_cmbNoches").value;
	var origen='';
	var origen=document.getElementById("ctl00_cphPrincipal_Buscador1_cmbOrigen").value
	var marca='';
	//alert('2');
	//alert($("#ctl00_cphPrincipal_Buscador1_cmbMarcasGenerales").val())
	//if(
	
	var marca = document.getElementById("cmbMarcas").value
	//MostrarEsperaReserva();
	showWaiter();
	//var url='ofertas.aspx?pob=' + poblacion + '&name=' + name + '&tdest=' + typedest + '&FechDesd=' + fechaDesde +'&FechHast=' + fechaHasta + '&n=' + noches + '&origen=' + origen;
	//var url='ofertas.aspx?pob=' + poblacion + '&tdest=' + typedest + '&FechDesd=' + fechaDesde +'&FechHast=' + fechaHasta + '&n=' + noches + '&origen=' + origen;
	
	var url = GetResultsRwPathWithDates(poblacion, name, typedest, fechaDesde, fechaHasta, noches,origen,marca);
	//var url='http://vacaciones.muchoviaje.com/ofertas.aspx?pob=' + poblacion + '&name=' + name + '&tdest=' + typedest + '&FechDesd=' + fechaDesde +'&FechHast=' + fechaHasta + '&n=' + noches + '&origen=' + origen;
	//alert(url)
	//url = "http://localhost:3306/Vacaciones/" + url;
    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 validarBusquedaPaquetes() 
{
    document.getElementById("layerError").style.visibility="hidden";
    document.getElementById("destinoAlert").style.visibility="hidden";
    document.getElementById("fechaAlert").style.visibility="hidden";
    $("#fechaHastaAlert").css("display","none");

	if(!hotel_poblacion_check()) {
 	    document.getElementById("layerError").style.visibility="visible";
 	    document.getElementById("destinoAlert").style.visibility="visible";
 	    document.getElementById("layerError").style.display="";
 	    document.getElementById("destinoAlert").style.display="";
		return;
    }
    
    if(!ValidarFecha())
        return;
//    if(!hotel_combo_check()) {
// 	    document.getElementById("layerError").style.visibility="visible";
// 	    document.getElementById("fechaAlert").style.visibility="visible";
// 	    document.getElementById("layerError").style.display="";
// 	    document.getElementById("fechaAlert").style.display="";
//		return;
//    }
    
    var msg='';
 
	var poblacion = document.getElementById("codigoDestino").value
	
	var typedest = document.getElementById("tipoDestino").value
	
	var name = $("#inputString").val();//document.getElementById("nombreDestino").value
	var fechaDesde = cambiarFechaHotel(document.getElementById("fechaDesde").value)
	var fechaHasta = cambiarFechaHotel(document.getElementById("fechaHasta").value)
	var noches = document.getElementById("ctl00_cphPrincipal_Buscador1_cmbNoches").value;
	var origen='';
	var origen=document.getElementById("ctl00_cphPrincipal_Buscador1_cmbOrigen").value
	var marca='';	
	if($("#ctl00_cphPrincipal_Buscador1_cmbMarcasGenerales").val() == "18")
	{
	    if($("#cmbMarcasHijas").val() != "")
		    marca = $("#cmbMarcasHijas").val()
	    else
	        marca = $("#ctl00_cphPrincipal_Buscador1_cmbMarcasGenerales").val();
	}
	else
	    marca = $("#ctl00_cphPrincipal_Buscador1_cmbMarcasGenerales").val();
	
	if(marca == 0)
	    marca = '';
	//MostrarEsperaReserva();
	showWaiter();
    var url = GetResultsRwPathWithDates(poblacion, name, typedest, fechaDesde, fechaHasta, noches,origen,marca);   
    var navegador = navigator.appName
 
    document.getElementById("codigoDestino").value='';
	$("#PubTop2").hide();
    $("#PubBottom").hide();
    document.location.href=url;

	return false;
}
	
function fechaHotelCB(fecha) {
    if(fecha){
    
        document.getElementById("fechaEntrada").value= fecha;
        resetCombos();
        document.getElementById("fechaEntradaMos").value=fecha + ", "+ GetDiaNombre(fecha);
        fechaHotelVuelta();
    };
    hidepop();
	submitCheck();
}
function fechaHotelVuelta() {

    fecha =document.getElementById("fechaEntrada").value;
    n = parseInt(document.getElementById("ctl00_cphPrincipal_Buscador1_cmbNoches").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);
    fVuelta = fVuelta.getDate() + "/" + (fVuelta.getMonth()+1) + "/" + fVuelta.getFullYear();
    $("#fechaVuelta").html(fVuelta + ", "+ GetDiaNombre(fVuelta));

}
function dateToString(datestr) {
    var match = new RegExp("(\\d{2})/(\\d{2})/(\\d{4})", "g").exec(datestr);
    
    if(match == null) {
		matchISO = new RegExp("(\\d{4})(/|-)(\\d{2})(/|-)(\\d{2})", "g").exec(datestr);
		if(matchISO == null) {
			return datestr;
		} else {
			match = {3: matchISO[1], 2: matchISO[3], 1: matchISO[5]};
		}
    }
    
    var date = new Date(match[3], (match[2]-1), match[1], 0, 0, 0);
    return formatDates.replace("_DAYWEEK_", dayNames[date.getDay()]).replace("_DAY_", match[1]).replace("_MONTH_", monthNames[match[2]-1]).replace("_YEAR_", match[3])
}

function hotel_poblacion_check() {
  	if ($("#codigoDestino").attr("value"))
  	    p = $("#codigoDestino").attr("value");
  	else
  	    p = '';
  	  	
    if (p == 'Poblacion' || p =='' || p.charCodeAt(0) == 32)
        return  false;   
    else
    {     
        if($("#inputString").val() =="")
            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 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 cambiarFechaHotel(fecha) {
if (fecha!='' && fecha!=undefined)
{
	var iArr = fecha.split('/');
	y = yLength(iArr[2]);
	m = mLength(iArr[1]);
	d = mLength(iArr[0]);
	fecha = y + '-' + m + '-' + d;
	}
	
	return fecha;
}
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;
}

//funciones para probar si el formulario puede submit o no
function hotel_combo_check() {
if ($("#fechaDesde").attr("value")!='' && $("#fechaDesde").attr("value")!=undefined)
{
	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 ) {
			return false;
		} else {
			return true
        }
    } else {
        return false;
    } 
    }
    else
    {
    return true
    }
}
function hotel_combo_fechaHasta() {
    if ($("#fechaHasta").attr("value")!='' && $("#fechaHasta").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 loading2() {
    document.getElementById("global").style.visibility="hidden";
 	document.getElementById("Espera").style.visibility="visible";
    document.getElementById("Espera").style.display="inline";

}
function pop(pg,t,w,h) {
	window.open(pg,t,'scrollbars=yes,toolbar=no,status=no,resizable=no,width=' + w + ',height=' + h);
}
function combo(disp) {
    //apagar o mostrar combos (en ie no puedes flotar elementos encima de un combo)
    for (var f = 0; f < document.forms.length; f++){
        for (var e = 0; e < document.forms[f].length; e++) {
			if(disp =="none") {
				if (document.forms[f].elements[e].options) document.forms[f].elements[e].style.visibility = "hidden";
			} else {
				if (document.forms[f].elements[e].options) document.forms[f].elements[e].style.visibility = "visible";
			}
        }
    }
}
function submitshowhide(val) {
    if(val) {
            document.getElementById("buscarDis").style.visibility="hidden";
            document.getElementById("buscar").style.visibility="visible";
            document.getElementById("buscar").style.display="";
    } else {
            document.getElementById("buscar").style.visibility="hidden";
            document.getElementById("buscarDis").style.visibility="visible";
            document.getElementById("buscarDis").style.display="";
    }
}
//funciones generals para manejar fechas etc
function select(id, indice) {
	document.getElementById(id).selectedIndex = indice;
}
function prepDest(cual) {
    v = cual.value
    if (v == "Origen" || v=="Población" || v=="Destino") {
		cual.value="";
		submitshowhide(false);
    }
}


//funciones para probar si el formulario puede submit o no

function fechaCombo() {
	if (hotel_combo_check()) {
        fecha1="";
//        fecha2="";
        fecha3="";
        if ($("#entradaD").attr("value")!='' && $("#entradaD").attr("value")!=undefined)
		{
            if ($("#entradaM").attr("value")!='' && $("#entradaM").attr("value")!=undefined)
		    {
                if ($("#entradaY").attr("value")!='' && $("#entradaY").attr("value")!=undefined)
		        {
		            fecha1 = $("#entradaD").attr("value") + "/" + $("#entradaM").attr("value") + "/" + $("#entradaY").attr("value");
//		            fecha2 = $("#entradaM").attr("value") + "/" + $("#entradaD").attr("value") + "/" + $("#entradaY").attr("value");
		        }
		    }
		}
        if ($("#hastaD").attr("value")!='' && $("#hastaD").attr("value")!=undefined)
		{
            if ($("#hastaM").attr("value")!='' && $("#hastaM").attr("value")!=undefined)
		    {
                if ($("#hastaY").attr("value")!='' && $("#hastaY").attr("value")!=undefined)
		        {
		            fecha3 = $("#hastaD").attr("value") + "/" + $("#hastaM").attr("value") + "/" + $("#hastaY").attr("value");
//		            fecha4 = $("#hastaM").attr("value") + "/" + $("#hastaD").attr("value") + "/" + $("#hastaY").attr("value");
		        }
		    }
		}
        $("#fechaDesde").attr("value", fecha1);
		$("#fechaHasta").attr("value", fecha3);
		$("#fechaEntrada").attr("value", fecha1);
		$("#fechaEntradaMos").html(fecha1 + ", "+ GetDiaNombre(fecha1));
		fechaHotelVuelta();
//        f =  new Date(fecha2);
		//calendarioCtrl.SetSelectedDate(f,true)
	} else {
		//alert('Fecha no valida');
	}
}

function resetCombos() {

    var fechaHoy = document.getElementById("fechaHoy").value.split("/");
	var hoy = new Date(fechaHoy[1] + "/" + fechaHoy[0] + "/" + fechaHoy[2]);

 	fecha =document.getElementById("fechaEntrada").value ;
    var fArr = fecha.split("/");
    var d = fArr[0]-1;
    var m = fArr[1]-1;
    //var y = fArr[2]-2008;
 	fechaHasta =document.getElementById("fechaHasta").value ;
    var fArr2 = fechaHasta.split("/");
    var d2 = fArr2[0];
    var m2 = fArr2[1];
    //var y = fArr[2]-2008;
    var noches=0;
    if (document.getElementById("numnoches").value!='' && document.getElementById("numnoches").value!=undefined)
    {
 	    noches=parseInt(document.getElementById("numnoches").value);
    }

	//alert(hoy.getFullYear());
    var y = fArr[2]-hoy.getFullYear();
    select('entradaD', d);
    select('entradaM', m);
    select('entradaY', y);
    var y2 = fArr2[2]-hoy.getFullYear();
    if (document.getElementById("hastaD") && d2!="")
    {
        select('hastaD', d2);
    }
    if (document.getElementById("hastaM") && m2!=undefined && m2!="")
    {
        select('hastaM', m2);
    }
    if (document.getElementById("hastaY") && isNaN(y2)!=true)
    {
        select('hastaY', y2);
    }
    //select('noches',noches-1)
}

function load(src, dest) {
        //document.getElementById("dest").style.visibility="hidden";
       window.open(src,"xcvb",'scrollbars=yes,toolbar=no,status=no,resizable=no,width=300,height=300');
}
function hidepop() {
        combo('');
        document.getElementById("formspop").style.visibility="hidden";

}

function GetResultsRwPath(mgdscode,name,destination_type)
{
    //return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx";
return "viajes_ofertas.aspx?pob=" + mgdscode + "&tdest=" + destination_type.toLowerCase() + "&name=" + name; 
}
function GetResultsRwPathWithDates(mgdscode,name,destination_type,date_from,date_to,duration,from,mark)
{
    var n=duration.split("-");
    var URL = "viajes_ofertas.aspx?pob=" + mgdscode + "&tdest=" + destination_type.toLowerCase() + "&fechad=" + date_from + "&fechaa=" + date_to + "&name=" + name;;
    //alert(n[0]);
    //alert(n[1]);
    //return false;
    if (n[0]!="" && n[0]!="N" && n[0]!=undefined)
    {
        URL = URL + '&n=' + n[0]
    }
    if (n[1]!="" && n[1]!="N" && n[1]!=undefined)
    {
        URL = URL + '&nmax=' + n[1]
    }
    if (from!="")
    { 
        URL = URL + '&origen=' + from; 
    }
    if (mark!="")
    {
        URL = URL + '&marca=' + mark; 

        //return "" + destination_type.toLowerCase() + "-ofertas-vacaciones-en-" + GetPreparedString(name) + "__" + mgdscode + ".aspx?fechad=" + date_from + "&fechaa=" + date_to + "&n=" + duration + '&origen=' + from + '&marca=' + mark;
    }
    return URL;
    
}
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 ModificacionComboFecha() 
{
    var indiceEntrada = $("#ctl00_cphPrincipal_Buscador1_cmbFecEntrada").val();
    var indiceSalida = $("#ctl00_cphPrincipal_Buscador1_cmbFecSalida").val();        
    var fechaEntrada;
    var fechaSalida;
    var today = new Date();
    var MesActual = today.getMonth() + 1;    
    if(indiceEntrada != "" && indiceSalida != "")
    {    
        if(indiceEntrada == MesActual)
            fechaEntrada = today.getDate() + '/' + indiceEntrada + '/' + today.getFullYear();
        else
        {
            if(indiceEntrada > 12)
                fechaEntrada = '01/' + (indiceEntrada - 12).toString() + '/' + (parseInt(today.getFullYear()) +  Math.floor(((indiceEntrada -1) /12))).toString();
            else
                fechaEntrada = '01/' + indiceEntrada + '/' + today.getFullYear();
        }
        
//        if(indiceEntrada > 12)
//            fechaSalida = dias(indiceSalida,today.getFullYear())+ '/' + indiceSalida + '/' + today.getFullYear();
//        else            
            fechaSalida = dias(indiceSalida,parseInt(today.getFullYear()) + Math.floor(((indiceSalida -1) /12)),indiceSalida)+ '/' + (indiceSalida -12 * Math.floor((indiceSalida -1) / 12)).toString()   + '/' + (parseInt(today.getFullYear()) + Math.floor(((indiceSalida -1) /12))).toString();                
 
    
        $("#fechaDesde").attr("value", fechaEntrada);
        $("#fechaHasta").attr("value", fechaSalida);
        $("#fechaEntrada").attr("value", fechaEntrada);
        $("#fechaEntradaMos").html(fechaEntrada + ", "+ GetDiaNombre(fechaEntrada));
        //fechaHotelVuelta();
    
    
//        if(indiceEntrada == MesActual)
//            fechaEntrada = today.getDate() + '/' + indiceEntrada + '/' + today.getFullYear();
//        else
//            fechaEntrada = '01/' + indiceEntrada + '/' + today.getFullYear();

//        if(indiceSalida >= MesActual)
//            fechaSalida = dias(indiceSalida,today.getFullYear())+ '/' + indiceSalida + '/' + today.getFullYear();
//        else
//            fechaSalida = dias(indiceSalida,today.getFullYear())+ '/' + indiceSalida + '/' + (parseInt(today.getFullYear()) + 1).toString();                
//            
//        $("#fechaDesde").attr("value", fechaEntrada);
//        $("#fechaHasta").attr("value", fechaSalida);
//        $("#fechaEntrada").attr("value", fechaEntrada);
//        $("#fechaEntradaMos").html(fechaEntrada + ", "+ GetDiaNombre(fechaEntrada));
//        fechaHotelVuelta();
    }
}

function dias(mes, anno, indiceSalida) 
{
    var restoMeses = Math.floor((indiceSalida -1)/12);
      mes = parseInt(mes - (12 * restoMeses));
	  anno = parseInt(anno);
      switch (mes) {
	    case 1 : 
	    case 3 : 
	    case 5 : 
	    case 7 : 
	    case 8 : 
	    case 10 : 
	    case 12 : 
	        return 31;
		case 2 : 
		    return (anno % 4 == 0) ? 29 : 28;
	  }
	  return 30;
}


function ValidarFecha()
{
    var today = new Date();
    var MesActual = today.getMonth() + 1;
    var valorEntrada = $("#ctl00_cphPrincipal_Buscador1_cmbFecEntrada").val();
    var valorSalida = $("#ctl00_cphPrincipal_Buscador1_cmbFecSalida").val();
    if(valorEntrada != "" && valorSalida != "")
    {
//        var MesEntrada;
//        if(parseInt(valorEntrada) < MesActual) 
//        {
//            MesEntrada = 12 + parseInt(valorEntrada);
//        }
//        else
//        {
//            MesEntrada = parseInt(valorEntrada);
//        }
//        var MesSalida;
//        if(parseInt(valorSalida) < MesActual)
//        {
//            MesSalida =  12 + parseInt(valorSalida)
//        }
//        else
//        {
//            MesSalida = parseInt(valorSalida);
//        }
        if(parseInt(valorEntrada) > parseInt(valorSalida))
        {
            document.getElementById("layerError").style.visibility="visible";
 	        document.getElementById("fechaAlert").style.visibility="visible";
 	        document.getElementById("layerError").style.display="";
 	        $("#fechaHastaAlert").css("display","block");
 	        return false;
        }    
     }
     else
     {
        document.getElementById("layerError").style.visibility="visible";
        document.getElementById("fechaAlert").style.visibility="visible";
        document.getElementById("layerError").style.display="";
        return false;
     }
     return true;    
}
