﻿Framework = {};


Framework.Fecha = {
/*Añade un cero a la izquierda */
addZero : function(vNumero){ 
    return ((vNumero < 10) ? "0" : "") + vNumero 
},
/*Formatea la fecha como*/
formatoDate :function(vDate, vFormat){ 
    var vDay              = Framework.Fecha.addZero(vDate.getDate()); 
    var vMonth            = Framework.Fecha.addZero(vDate.getMonth()+1); 
    var vYearLong         = Framework.Fecha.addZero(vDate.getFullYear()); 
    var vYearShort        = Framework.Fecha.addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = Framework.Fecha.addZero(vDate.getHours()); 
    var vMinute           = Framework.Fecha.addZero(vDate.getMinutes()); 
    var vSecond           = Framework.Fecha.addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
},
/* Comprueba si es biesto */
es_bisiesto : function(anio){
    if(((anio % 4 == 0) && anio % 100 != 0) || anio % 400 == 0)
      return true;
      return false;
},
/* Compara dos fechas */
Comparar_Fecha : function (obj1,obj2) 
{
        String1 = obj1;
        String2 = obj2;
        // Si los dias y los meses llegan con un valor menor que 10 
        // Se concatena un 0 a cada valor dentro del string 
        if (String1.substring(1,2)=="/") {
        String1="0"+String1
        }
        if (String1.substring(4,5)=="/"){
        String1=String1.substring(0,3)+"0"+String1.substring(3,9)
        }

        if (String2.substring(1,2)=="/") {
        String2="0"+String2
        }
        if (String2.substring(4,5)=="/"){
        String2=String2.substring(0,3)+"0"+String2.substring(3,9)
        }

        dia1=String1.substring(0,2);
        mes1=String1.substring(3,5);
        anyo1=String1.substring(6,10);
        dia2=String2.substring(0,2);
        mes2=String2.substring(3,5);
        anyo2=String2.substring(6,10);


        if (dia1 == "08") // parseInt("08") == 10 base octogonal
        dia1 = "8";
        if (dia1 == '09') // parseInt("09") == 11 base octogonal
        dia1 = "9";
        if (mes1 == "08") // parseInt("08") == 10 base octogonal
        mes1 = "8";
        if (mes1 == "09") // parseInt("09") == 11 base octogonal
        mes1 = "9";
        if (dia2 == "08") // parseInt("08") == 10 base octogonal
        dia2 = "8";
        if (dia2 == '09') // parseInt("09") == 11 base octogonal
        dia2 = "9";
        if (mes2 == "08") // parseInt("08") == 10 base octogonal
        mes2 = "8";
        if (mes2 == "09") // parseInt("09") == 11 base octogonal
        mes2 = "9";

        dia1=parseInt(dia1);
        dia2=parseInt(dia2);
        mes1=parseInt(mes1);
        mes2=parseInt(mes2);
        anyo1=parseInt(anyo1);
        anyo2=parseInt(anyo2);

        if (anyo1>anyo2)
        {
        return false;
        }

        if ((anyo1==anyo2) && (mes1>mes2))
        {
        return false;
        }
        if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
        {
        return false;
        } 

        return true;
},
validaFecha_ddmmyyyy : function (strFecha)
{
	var arrayFecha;
	var dia;
	var mes;
	var anyo;

	arrayFecha = strFecha.split("/");

	if (arrayFecha.length < 3)
		return false;
		
	dia = arrayFecha[0];
	mes = arrayFecha[1];
	anyo = arrayFecha[2];
	
	if (dia == "")
		return false;
	
	if (mes == "")
		return false;
		
	if (anyo == "" || anyo<1900 || anyo>9999)
		return false;
			
	if (anyo.indexOf('.')>0)
		return false;

	if (anyo.length!=2 && anyo.length!=4)
		return false;
	
	// La funcion Date entiende el mes dentro del intervalo 0 - 11
	mes = mes - 1;

	with (new Date(anyo, mes, dia)) {
		return (getDate()==dia && getMonth()==mes);
	}
},

/*Funcion para comparar dos fechas con formato dd/mm/yyyy*/
es_mayor : function (fecha1, fecha2) {
	var arrayOfStrings = fecha1.split('/');
	var str1 = arrayOfStrings[2] + arrayOfStrings[1] + arrayOfStrings[0];
	
	var arrayOfStrings = fecha2.split('/');
	var str2 = arrayOfStrings[2] + arrayOfStrings[1] + arrayOfStrings[0];
	str1 = parseInt(str1,10)
	str2 = parseInt(str2,10)
	
	return (str1 > str2); 
		
},
/* Devuelve una fecha con el dia de manana*/
get_dema : function  () {
	var Tomorrow=new Date();
	Tomorrow.setDate(Tomorrow.getDate() + 1);
	return Tomorrow;
},

ValidaFecha : function (stringDate)
{
var datematch = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;
return datematch;
},  
/* Calculo de dias entre dos fechas */
daysBetween : function(date1, date2) {
   var DSTAdjust = 0;
   // constants used for our calculations below
   oneMinute = 1000 * 60;
   var oneDay = oneMinute * 60 * 24;
   // equalize times in case date objects have them
   date1.setHours(0);
   date1.setMinutes(0);
   date1.setSeconds(0);
   date2.setHours(0);
   date2.setMinutes(0);
   date2.setSeconds(0);
   // take care of spans across Daylight Saving Time changes
   if (date2 > date1) {
      DSTAdjust =
      (date2.getTimezoneOffset() - date1.getTimezoneOffset( )) * oneMinute;
   }
   else {
      DSTAdjust =
      (date1.getTimezoneOffset() - date2.getTimezoneOffset( )) * oneMinute;
   }
   var diff = Math.abs(date2.getTime() - date1.getTime( )) - DSTAdjust;
   return Math.ceil(diff / oneDay);
},

/* Valida una fecha en formato dd-mm-yyyy / dd/mm/yyyy */
checkDate : function(fld) {
var mo, day, yr;
var entry = fld.value;
    if(entry !="") {
        var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
        var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
        var valid = (reLong.test(entry)) || (reShort.test(entry));
        if (valid) {
           var delimChar = (entry.indexOf("/") != - 1) ? "/" : "-";
           var delim1 = entry.indexOf(delimChar);
           var delim2 = entry.lastIndexOf(delimChar);
           day = parseInt(entry.substring(0, delim1), 10);
           mo = parseInt(entry.substring(delim1 + 1, delim2), 10);
           yr = parseInt(entry.substring(delim2 + 1), 10);
           // handle two - digit year
           if (yr < 100) {
              var today = new Date( );
              // get current century floor (e.g., 2000)
              var currCent = parseInt(today.getFullYear( ) / 100) * 100;
              // two digits up to this year + 15 expands to current century
              var threshold = (today.getFullYear( ) + 15) - currCent;
              if (yr > threshold) {
                 yr += currCent - 100;
              }
              else {
                 yr += currCent;

              }
           }
           var testDate = new Date(yr, mo - 1, day);
           if (testDate.getDate( ) == day) {
              if (testDate.getMonth( ) + 1 == mo) {
                 if (testDate.getFullYear( ) == yr) {
                    // fill field with database - friendly format
                    fld.value = ((day < 10) ? "0" + String(day) : String(day)) + "/" + ((mo < 10) ? "0" + String(mo) : String(mo)) + "/" + String(yr);
                    return true;
                 }
                 else {
                    //alert("El año es incorrecto");
                 }
              }
              else {
                 //alert("El mes es incorrecto");
              }
           }
           else {
              //alert("Error en la fecha");
           }
        }
        else {
           //alert("Formato incorrecto. Entrar mm/dd/yyyy.");
        }
        return false;
    }else {
        return false;
    }
},

        CovierteFecha : function(fld){
                var fecha = new Date.parse(fld);
                return fecha;    
    
},

formatDate : function(fld){
    var dia = fld.substr(0,2);
    var mes = fld.substr(3,1);
    var anio = fld.substr(5,4);
    return Framework.Fecha.addZero(dia) + "/" + Framework.Fecha.addZero(mes) + "/" + anio;
}
};

Framework.Utils = {

GetCoords : function(evt){
var coords = {left:0, top:0};
    if (evt.pageX) {
        coords.left = evt.pageX;
        coords.top = evt.pageY;
    } else if (evt.clientX) {
        coords.left =
        evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        coords.top =
        evt.clientY + document.body.scrollTop - document.body.clientTop;

    if (document.body.parentElement && document.body.parentElement.clientLeft) {
        var bodParent = document.body.parentElement;
        coords.left += bodParent.scrollLeft - bodParent.clientLeft;
        coords.top += bodParent.scrollTop - bodParent.clientTop;
    }
    }
return coords;
},

mouseLeaves :function  (element, evt)
{
   if (typeof evt.toElement != 'undefined' && evt.toElement && typeof
    element.contains != 'undefined') {
    
      return ! element.contains(evt.toElement);
   }
   else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget)
   {
      return ! contains(element, evt.relatedTarget);
   }
},

contains :function  (container, containee)
{
   while (containee)
   {
      if (container == containee)
      {
         return true;
      }
      containee = containee.parentNode;
   }
   return false;
},
hideElement : function (element)
{
   if (element.style)
   {
      element.style.visibility = 'hidden';
   }
},

showElement : function (element)
{
   if (element.style)
   {
      element.style.visibility = 'visible';
   }
},

posicionDiv : function(div, posX, event){
	var divcalendar = $(div);
	var yy = divcalendar.style.top;
	var y =  event.clientY-event.offsetY;
	divcalendar.style.top = (y)+"px";
	divcalendar.style.left = (posX)+"px";
},
showdiv : function (event,divcal,posX, posY)
{
	//determina un margen de pixels del div al raton
	margin=15;
    marginTop = 5;
	//La variable IE determina si estamos utilizando IE
	var IE = document.all?true:false;

	var tempX = 0;
	var tempY = 0;
	var tempClientX = 0;
	var tempClientY = 0;
    var _txt = $("txtFechaEnt#1");
	//document.body.clientHeight = devuelve la altura del body
	if(IE)
	{ //para IE
		//event.y|event.clientY = devuelve la posicion en relacion a la parte superior visible del navegador
		//event.screenY = devuelve la posicion del cursor en relaciona la parte superior de la pantalla
		//event.offsetY = devuelve la posicion del mouse en relacion a la posicion superior de la caja donde se ha pulsado
		tempX = event.x
		tempY = event.y
		tempClientX = posX;
		tempClientY = posY;
		if(window.pageYOffset){
			tempY=(tempY+window.pageYOffset);
			tempX=(tempX+window.pageXOffset);
		}else{
			tempY=(tempY+Math.max(document.body.scrollTop,document.documentElement.scrollTop));
			tempX=(tempX+Math.max(document.body.scrollLeft,document.documentElement.scrollLeft));
		}
	}else{ //para netscape
		//window.pageYOffset = devuelve el tamaño en pixels de la parte superior no visible (scroll) de la pagina
		document.captureEvents(Event.MOUSEMOVE);
		tempX = event.pageX;
		tempY = event.pageY;
	}

	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}

	/*modificamos el valor del id posicion para indicar la posicion del mouse hay que crear un span en la pagina aspx y llamarle posicion
	 de esta manera veremos las coordenadas del puntero*/
	//document.getElementById('posicion').innerHTML="PosX = "+tempX+" | PosY = "+tempY;*/

	//window.alert(event.pageYOffset+" - "+document.body.pageYOffset+" - "+screen.pageYOffset+" - "+this.pageYOffset+" - "+window.pageYOffset);
    var div = $(divcal);

	document.getElementById(divcal).style.display='block';
	document.getElementById(divcal).style.top = (tempClientY)+"px";
	document.getElementById(divcal).style.left = (tempClientX)+"px";     
	    //document.getElementById(divcal).style.display='block';

	return;
},

/* combobox utilities */

/**
 * Recupera el combobox con el identificador indicado.
 *
 * @param   id       El identificador del combobox.
 * @return      El combobox con el id especificado.
 *
 * @throws      Si no se encuentra ningún combobox con el identificador indicado.
 */
_cmbGet : function (id) {
    var callerName;
    try {
        callerName = Framework.Utils._cmbGet.caller.toString().match(/function (\w*)/)[1];
    } catch(ex) {
        callerName = 'Unknown';
    }

    var cmb = document.getElementById(id);
    if (cmb == null) throw new Error(callerName + ": Invalid id '" + id + "'");
    if (cmb.tagName.toUpperCase() != 'SELECT') throw new Error(callerName + ": Invalid node type '" + cmb.tagName + "' for id '" + id + "', 'SELECT' type expected");
    
    return cmb;
},

/**
 * Recupera el valor seleccionado del combobox con el identificador indicado.
 *
 * @param   id       El identificador del combobox.
 * @return      El valor seleccionado, o un string vacío '' si no hay ninguno. 
 *
 * @throws      Si no se encuentra ningún combobox con el identificador indicado.
 */
cmbGetValue : function (id) {
    var cmb = Framework.Utils._cmbGet(id);
   
    if (cmb.hasChildNodes() && cmb.options) {
        return cmb.options[cmb.selectedIndex].value;
    }
    
    return '';
},

/**
 * Selecciona el valor especificado para el combobox con el identificador indicado.
 * Si el combobox no tiene ese valor, entonces esta función no hace nada.
 *
 * @param   id      El identificador del combobox.
 * @param   value   El valor que se quiere seleccionar.
 *
 * @throws      Si no se encuentra ningún combobox con el identificador indicado.
 */
cmbSelectValue : function (id, value) {
    var cmb = Framework.Utils._cmbGet(id);

    if (cmb.hasChildNodes() && cmb.options) {
        for (i = 0; i < cmb.options.length; i++) {
            if (cmb.options[i].value == value) {
                cmb.selectedIndex = i;
                return;
            }
        }
    }
},

/**
 * Rellena el combobox con los valores indicados en el array. El array estará compuesto
 * por parejas de (valor, texto) de modo que el elemento arr[i] es el 'value' y el elemento
 * arr[i+1] es el texto del 'OPTION' generado.
 *
 * @param   id      El identificador del combobox.
 * @param   arr     Array de parejas (valor, texto) para generar las opciones.
 *
 * @throws      Si no se encuentra ningún combobox con el identificador indicado. 
 */
 cmbSetValues : function (id, arr) {
    var cmb = Framework.Utils._cmbGet(id);

    nodeRemoveAllChilds(cmb);

    for (i = 0; i < arr.length; i += 2) {
        var oOption;        
        oOption = document.createElement("OPTION");
        oOption.value = i;
        oOption.innerHTML = i+1;
        cmb.appendChild(oOption);
    }
},

/**
 * Rellena el combobox con los valores desde min hasta max, abmos inclusive.
 *
 * @param   id      El identificador del combobox.
 * @param   min     Valor mínimo.
 * @param   max     Valor máximo.
 *
 * @throws      Si no se encuentra ningún combobox con el identificador indicado. 
 */
cmbSetValues : function (id, min, max) {
    var cmb = Framework.Utils._cmbGet(id);

    nodeRemoveAllChilds(id);

    for (i = min; i <= max; i ++) {
        var oOption;        
        oOption = document.createElement("OPTION");
        oOption.value = i;
        oOption.innerHTML = i;
        cmb.appendChild(oOption);
    }
},

/* DOM generic */

/**
 * Elimina todos los nodos hijos del elemento indicado. Si no se encuentra el
 * elemento está función no hace nada.
 *
 * @param   id  El identificador del elemento.
 */
nodeRemoveAllChilds : function (id) {
    var obj = document.getElementById(id);
    if (obj != null) {
        while (obj.firstChild) {
            obj.removeChild(obj.firstChild);
        }
    }
}
};

// Funciones de login y registros

function cerrarSesion() {
    petiAjaxMain("loginWeb" + sepGra + "cerrarSesion" + sepBloc, cerrarSesionVuelta);
}

function cerrarSesionVuelta(res) {
    window.location.href = "default.aspx";        
}

function iniciaLoginWeb() {
    petiAjaxMain("loginWeb" + sepGra + "accesoLoginado" + sepBloc + getNomPagina(window.location.href.toLowerCase()), iniciaLoginWebVuelta);
}

function iniciaLoginWebVuelta(res) {
    var resul = res.split(sepBloc);
    var ejecutarAutoComplete = true;
    var pagsNoEj = "datoshabit,dispohabit,elimmodifhabit,modifreserva2,modifreserva3,reserva,reservar,reservar1,reservar2,reservar3,cambio_precio,pruebas,mbreservar";
    var pags = pagsNoEj.split(",");
    var web = window.location.href.toLowerCase();
    for (var i = 0; i < pags.length && ejecutarAutoComplete; i++) {
        if (web.indexOf(pags[i] + ".aspx") != -1)  {
            ejecutarAutoComplete = false;
        }        
    }
    if (ejecutarAutoComplete) {
        GetAutoComplete("ListaDestinos", resul[4], null, "txtPiePoblacion", "selHotel", "hidCodDest");
    }
    if (resul[0] == "ok") {
        if (getCtl("tblSinRegistro") != null) {
            ocultaCtl("tblSinRegistro");
            verCtl("tblRegistrado");
            ponValsCtlsForm("Menu1_spaMenuRegUser,Menu1_spaMenuRegTipo", resul[1]);
            if (getCtl("Menu1_spaMenuRegTipo").innerHTML == "undefined") {
                getCtl("Menu1_spaMenuRegTipo").innerHTML = "";   
            }
            getCtl("Menu1_lnkMenuInicio").href = resul[2];
        }      
        getCtl("Cabecera1_lnkCabeceraInicio").href = resul[2];                
    } else {
        ocultaCtl("tblRegistrado");
        verCtl("tblSinRegistro");
        if (resul[2] != "") {
            window.location.href = resul[2];
        }
    }
    var dvMarcaBlanca = getCtl("divMarcaBlanca");
    var estiloClass = "dvGen";
    if (resul[5] == "") {
        verCtlsVerif("dvCabecera1,menu,dvReservar1,captacion");        
        if (dvMarcaBlanca != null) {
            ocultaCtl("divMarcaBlanca");
        }       
    } else {
        if (dvMarcaBlanca != null) {
            if (getCtl("captacion") != null) {
                estiloClass= "dvGenMBConBanners";
            } else {
                estiloClass = "dvGenMB";                            
            }            
        } else {
            verCtlsVerif("dvCabecera1,menu,dvReservar1,captacion");            
        }
    }
    if (getNomPagina(window.location.href) == "reserva.aspx" && modoReser == "imprime") {
        ocultaCtl("menu");
    }
    getCtl("divGeneral").className = estiloClass;
    if (getCtl("divLoading") != null) {
        ocultaCtl("divLoading");
    }
    if (getCtl("divLoadingPag") != null) {
        ocultaCtl("divLoadingPag");
    }
    if (getCtl("divContenidoCentral") != null) {
        verCtl("divContenidoCentral");
    }
    if (getCtl("central") != null) {
        verCtl("central");
    }      
}

function verCtlsVerif(nomsCtl) {
	var ctl = nomsCtl.split(",");    
    var nCtl = ctl.length;
    for (var i = 0; i < nCtl; i++) {
        if (getCtl(ctl[i]) != null) {
            verCtl(ctl[i]);
        }
    }    	
}

function irAMisReservas() {
    // Falta implementar
    alert("Falta implementar");
}

function irAMisDatos() {
    petiAjaxMain("loginWeb" + sepGra + "misDatos" + sepBloc, irAMisDatosVuelta);
}

function irAMisDatosVuelta(res) {
    var href = "";
    var hidServer = getCtl(idCabecera + "hidServer").value;
    var hidEsReal = getCtl(idCabecera + "hidEsReal").value;
    
    if (hidEsReal == "1") {
        hidServer = hidServer.substring(hidServer.indexOf("//") + 2, hidServer.length);
        href = "https://" + hidServer + Path;
    }
    window.location.href = href + res;        
}

// Funciones de reservas

function obtenerDatos() {
    var res = "";
    var nHab = parseInt(getCtl("FechasHab_nHabitacionesFiltro").value);
    var prev = "wcReservar1_";
    var adultos = 0;
    var datos = "";
    var valor;
    for (var i = 1; i < nHab + 1; i++) {
        valor = getCtl("nAdultosHab_" + i + "_Filtro").value;        
        adultos += parseInt(valor);
        if (i > 1) {
            datos += "|";
        }
        datos += "adultos:" + valor + "{_A_}ninos:0{_A_}bebes:0{_A_}";
    }
    
    res = getValoresForm("selHotel," + prev + "txtFechaEnt_1," + prev + "txtFechaSal_2,txtNoches,FechasHab_nHabitacionesFiltro") 
        + sepCtl + adultos + sepCtl + getSelValsEnString("selHotel");
    res += sepCtl + datos + sepCtl + getCtl("txtPiePoblacion").value + sepCtl + getCtl(idCabecera + "hidLang").value/**/; // pasamos el idioma porque al cambiar a servidor seguro perdemos la sesión
    
    return res;
}

function reservarDesdePie() {
    setTimeout(function() { reservarPie() }, 500);
}

function reservarPie() {
    var href = "";
    if(CompruebaReserva("selHotel", "hidCodDest")) {
        var hidDatos = document.getElementById("hidDatosRes");
        hidDatos.value = "previo" + sepSBloc + obtenerDatos();
        //var frm = document.getElementById("frmPie");
        var frm = document.forms[0];
        var hidServer = getCtl(idCabecera + "hidServer").value;
        var hidEsReal = getCtl(idCabecera + "hidEsReal").value;
    
        if (hidEsReal == "1") {
            hidServer = hidServer.substring(hidServer.indexOf("//") + 2, hidServer.length);
            href = "https://" + hidServer + Path;
        }
        frm.action = href + "reservar1.aspx";
        frm.submit();
        //petiAjaxMain("reservar" + sepGra + "previo" + sepBloc + obtenerDatos(), reservarDesdePieVuelta);
    }
}

//function reservarDesdePieVuelta(res) {
//    $("divLoadingPie").style.display = "none";
//    $("divReservar").style.display ="inline";
//    window.location.href = "reservar1.aspx";
//}

function viajaConNinosDesdePie() {
    setTimeout(function() { iniciaReserNinos() }, 500);
}

function iniciaReserNinos() {
    var href = "";
    // No comprobamos que estén rellenados el destion y/o el hotel
    //if(CompruebaReserva("selHotel", "hidCodDest")) {
    var Isdivloading = $("divLoadingPie") != null;
    if(Isdivloading) {
    $("divLoadingPie").style.display = "inline";
    $("divReservar").style.display ="none";
    }
    
    var hidDatos = document.getElementById("hidDatosRes");
    hidDatos.value = "previo" + sepSBloc + obtenerDatos() + sepCtl + getCtl("hidCodDest").value + sepCtl + sepCtl + "ninyos";
    //var frm = document.getElementById("frmPie");
    var frm = document.forms[0];
    var hidServer = getCtl(idCabecera + "hidServer").value;
    var hidEsReal = getCtl(idCabecera + "hidEsReal").value;

    if (hidEsReal == "1") {
        hidServer = hidServer.substring(hidServer.indexOf("//") + 2, hidServer.length);
        href = "https://" + hidServer + Path;
    }
    frm.action = href + "reservar.aspx";
    frm.submit();
    //petiAjaxMain("reservar" + sepGra + "previo" + sepBloc + obtenerDatos() + sepCtl + getCtl("hidCodDest").value + sepCtl + sepCtl + "ninyos", viajaConNinosDesdePieVuelta);
    //}
}

//function viajaConNinosDesdePieVuelta(res) {
//    var Isdivloading = $("divLoadingPie") != null;
//    if(Isdivloading) {
//        $("divLoadingPie").style.display = "none";
//        $("divReservar").style.display ="inline";
//    }
//    var hidServer = getCtl(idCabecera + "hidServer").value;
//    hidServer = hidServer.substring(hidServer.indexOf("//") + 2, hidServer.length);
//    window.location.href = /*"https://" + hidServer +*/ Path + "reservar.aspx";
//}

 function SoloFechas(evt){
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 46 || charCode > 57)) {
        return false;
    }
 }
 
 function CompruebaReserva(idSelHotel, idCodDestino)
 {
    var ok = false;
    var selHotel = document.getElementById(idSelHotel);
    var hidDestino = document.getElementById(idCodDestino);
    if(hidDestino.value != "" || selHotel.selectedIndex > 0 || selHotel.style.display == "none") ok = true;
    else multiAlertAjax("280");
    return ok;
 }

function GetConfigHotel(codhot)
{
    var paremetros = "";
    var idhotel = "";
    if(codhot != undefined) {
        idhotel = codhot;
    } else {
        idhotel = $F("selHotel");
    }

    if(idhotel != "") {
        petiAjaxMain("reservar" + sepGra + "GetConfigHotel" + sepBloc + idhotel, GetConfigVuelta);
    } else {
        GetConfigVuelta();
    }
}

function GetConfigVuelta(res)
{
    //4{_A_}{_B_}1{_E_}2{_B_}0{_E_}1{_B_}0{_E_}0{_A_}{_B_}18{_E_}1000{_B_}4{_E_}17{_B_}0{_E_}3
    var _selHab = $("FechasHab_nHabitacionesFiltro");
    var _selAdult = $("nAdultosHab_1_Filtro");
    var _selNinos = $("nNinosHab_1_Filtro");
    var _selBebes = $("nBebesHab_1_Filtro");
    var ok = true;
    
    if(res != undefined) {
        var desglosa = [];
        var num = 0;
        _selHab.innerHTML = "";
        if (res != "") {
            var hidConfig = document.getElementById("hidConfig");
            hidConfig.value = res;
            
            var desglosa = res.split(sepArg);
            num = desglosa[0]; // max. habitaciones
            var ocupacion = desglosa[1].split(sepBloc);
            var edades = desglosa[2].split(sepBloc);
            var adult = ocupacion[0].split(sepElem);
            var ninos = ocupacion[1].split(sepElem);
            var bebes = ocupacion[2].split(sepElem);
            var edadNinos = edades[1].split(sepElem);
            CargaConfig("FechasHab_nHabitacionesFiltro", 1, parseInt(num));
            CargaConfig("FechasHab_nHabitacionesFiltroFit", 1, parseInt(num));
            CargaConfig("nAdultosHab_1_Filtro", parseInt(adult[0]), parseInt(adult[1]));
            CargaConfig("nNinosHab_1_Filtro", parseInt(ninos[0]), parseInt(ninos[1]));
            CargaConfig("nBebesHab_1_Filtro", parseInt(bebes[0]), parseInt(bebes[1]));
            CargaConfig("seledad_1", parseInt(edadNinos[0]), parseInt(edadNinos[1]));
        } else {
             ok = false;
        }
    } else {
        ok = false;
    }
    
    if(!ok) {
        CargaConfig("FechasHab_nHabitacionesFiltro", 1, 8);
        CargaConfig("nAdultosHab_1_Filtro", 1, 4);
    }
    
    if (_selAdult.id.indexOf("seladultos") == -1) 
        pintarListboxesCombinaciones("", 'FechasHab_nHabitacionesFiltro', 'panelListboxesCombinaciones');
    else {
        pintarListboxesCombinacionesReser(1,0);
    }
}

function CargaConfig(idSel, min, max) {
    var sel = document.getElementById(idSel);
    
    if (sel != null) {
        sel.innerHTML = "";
        for (var i = parseInt(min); i < parseInt(max) + 1; i ++ ) {
            Funciones.Tools._AddOpcion(sel, parseInt(i), i);
        }
    }
}