﻿var idLngActual; 	//id de idioma actual
var vecLangs; 		//Vector con los nombres de los idiomas en el idioma actual
//var Server = "www.sercotelhotel.com";
var idCabecera = "Cabecera1_";
var idPieVacio = "pie_";
var url = window.location.href;
var Server = url.substring(url.indexOf("//") + 2, url.indexOf("/", url.indexOf("//") + 2));
var Path = "/SercotelWeb/";

//Solo admite numeros
function numeros(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
}

//Solo admite numeros menos el cero
function numerosYNoCero(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 49 || charCode > 57)) {
        return false;
    }
}

//Telefonos, fax, movil --> numeros y simbolos () + <--
function telefono(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 57) {
        return false;
    } else if (charCode > 32 && charCode < 40) {
        return false;
    } else if (charCode == 42 || charCode > 43 && charCode < 48) {
        return false;
    }

}

var thabits = new Array(1); thabits[1] = new Array(2);
thabits[1][0] = 1;
thabits[1][1] = 0;
var _total;
var _combinacion;
var _activePag;

function pintarTablaDatos(ind, controlId, panelListboxes) {
    var objPanel;
    var str = "";
    var indice;
    var divPanel;
    var numeroHabitaciones;
    if (ind == undefined) {
        ind = "";
    }
    if (controlId == "") {
        controlId = "FechasHab_nHabitacionesFiltro";
    }

    if (panelListboxes == undefined) {
        divPanel = "panelListboxesCombinaciones" + ind;
    } else {
        divPanel = panelListboxes;
    }

    objPanel = document.getElementById(divPanel);
    var postFijo = "";
    if (divPanel.indexOf("Fit") != -1)
        postFijo = "Fit";

    var idHabs = controlId + ind;
    numeroHabitaciones = getCtl(idHabs).value;
    if (numeroHabitaciones == "") {
        alertAjax("263");
        //$F("FechasHab_nHabitacionesFiltro" + ind).item(0).selected = true;
        //$F(idHabs).item(0).selected = true;
        numeroHabitaciones = 1;
    }
    indice = 1;
    var sels = objPanel.getElementsByTagName("select");
    var saltos = objPanel.getElementsByTagName("br");
    var selAdult;
    var minAdult = 1;
    var maxAdult = 4;
    var resul;
    var numObjs = 0;

    try {
        if (sels.length > 0) {
            numObjs = sels.length;
            selAdult = sels[0];
            minAdult = selAdult.options[0].value;
            maxAdult = selAdult.options[selAdult.options.length - 1].value;
            /* limpiamos los selects que haya creados previamente */

            var elems = objPanel.childNodes;
            for (var i = elems.length - 1; i > -1; i--) {
                objPanel.removeChild(elems[i]);
            }
            /*
            for (var i = numObjs - 1; i > -1; i--) {
            objPanel.removeChild(sels[i]);
            objPanel.removeChild(saltos[i]);
            }
            */
        }
    } catch (e) {
    }
    // str += "<table class='adultos' cellSpacing='0' cellPadding='0' border='0'>";	
    while (indice <= numeroHabitaciones) {
        resul = "";
        for (var i = parseInt(minAdult); i < parseInt(maxAdult) + 1; i++) {
            resul += i + sepVal + i;
            resul += sepElem;
        }
        resul = resul.substring(0, resul.length - sepElem.length);
        creaSel(divPanel, "nAdultosHab_" + indice + "_Filtro" + postFijo + ind, resul);
        var salto = document.createElement("br");
        objPanel.appendChild(salto);
        /*
        str += 	"<tr>";
        str += 	"</tr>";
        str += 	"<tr>";
        str +=      "<td valign='top' align='left'></td>";
        str += 		"<td valign='top' align='left' valign='top'>";
        str += 			"<select id='nAdultosHab_" + indice + "_Filtro" + ind;
        str +=          "'>";
        str += 				"<option value='1' selected>1</option>";
        str += 				"<option value='2'>2</option>";
        str += 				"<option value='3'>3</option>";
        str += 				"<option value='4'>4</option>";
        str +=				"</select>";
        str += 		"</td>";	
        str += 	"</tr>";
        */
        indice++;
    }
    /*
    str += "</table>";
    objPanel.innerHTML = str;
    */
    return true;
}

function pintarListboxesCombinaciones(ind, controlId, panelListboxes) {
    var ctlId = "";
    var idHabs = "";
    if (ind == undefined) {
        ind = "";
    }
    if (controlId == undefined) {
        controlId = "FechasHab_nHabitacionesFiltro";
    }
    pintarTablaDatos(ind, controlId, panelListboxes); //escribe las filas con 2ad y 0ni
    var idHabs = controlId + ind;

    with (window.document.forms[0]) {
        for (var j = 1; j < thabits.length; j++) {
            if ($(idHabs).value >= j) {
                ctlId = "nAdultosHab_" + j + "_Filtro" + ind;
                elements[ctlId].value = thabits[j][0];
            }
        }
    } //end with
}

var hDestinos = [];
var idestinos = 0;

function CopiaProvincia(sel) {
    var _selec = [];
    _select = sel.split(sepElem);
    var _provincia = $(_select[0]);         //$("selProvincias");
    var _selpais = $(_select[1]);           //$("selPaisPrefe");
    var _seldestinos = $(_select[2]);       //$("seldestinos");
    var destino;
    var bSalir = false;
    var bCopia = false;

    if (_selpais.options.length != 0) {

        with (_provincia)
            if (selectedIndex >= 0) {
            if (selectedIndex == 0) {
                //destino = _selpais.options[_selpais.selectedIndex].text + " " +_selpais.options[_selpais.selectedIndex].value;
                destino = _selpais.options[_selpais.selectedIndex].text;
            } else {
                //destino = _selpais.options[_selpais.selectedIndex].text + " " + _provincia.options[_provincia.selectedIndex].text;
                destino = _provincia.options[_provincia.selectedIndex].text;
            }
        } else {
            //destino =_selpais.options[_selpais.selectedIndex].text + " " + _selpais.options[_selpais.selectedIndex].value; 
            destino = _selpais.options[_selpais.selectedIndex].text;
        }
        if (destino != "  " && destino != "") {
            _seldestinos.style.display = "inline";
            if (hDestinos.length == 0) {
                var pro = $F(_provincia); //.options[_provincia.selectedIndex].value;
                if (pro == null) {
                    hDestinos[hDestinos.length] = { Destino: destino, Pais: $F(_selpais), Provincia: "" };
                } else {
                hDestinos[hDestinos.length] = { Destino: destino, Pais: $F(_selpais), Provincia: $F(_provincia) };
                }
                if (destino != "") {
                    var opt = new Option(destino, $F(_selpais) + " " + $F(_provincia));
                    try {
                        _seldestinos.add(opt, 1);
                    } catch (e) { }
                }
            } else {
                for (var i = 0; i < hDestinos.length; i++) {
                    if (destino == hDestinos[i].Destino) {
                        bCopia = true;
                    }
                }
                if (!bCopia) {
                    var pro = $F(_provincia); //.options[_provincia.selectedIndex].value;
                    if (pro == null) {
                        hDestinos[hDestinos.length] = { Destino: destino, Pais: $F(_selpais), Provincia: "" };
                    } else {
                    hDestinos[hDestinos.length] = { Destino: destino, Pais: $F(_selpais), Provincia: $F(_provincia) };
                    }
                    if (destino != "" && destino != " ") {
                        var opt = new Option(destino, $F(_selpais) + " " + $F(_provincia));
                        try {
                            _seldestinos.add(opt, 1);
                            bCopia = false;
                        } catch (e) { }
                    }
                }
            }
        }
    }
}

function BorrarDestino(select) {
    var _selec = [];
    var seldestinos = $("seldestinos");
    _select = select.split(sepElem);
    var _sel = $(_select[0]);  //$("seldestinos");
    var _selpais = $(_select[1]);  //$("selPaisPrefe");
    var encontrado = false;
    var destino;

    with (_sel)
        if (selectedIndex >= 0) {
        destino = options[selectedIndex].text;
        options[selectedIndex] = null
    }
    if (_sel.options.length == 0) {
        _sel.style.display = "none";
        hDestinos.length = 0;
    } else {
        for (var i = hDestinos.length - 1; i > -1 && !encontrado; i--) {
            if (destino == hDestinos[i].Destino) {
                removeByIndex(hDestinos, i);
                encontrado = true;
            }
        }
    }
}

function removeByIndex(arrayName, arrayIndex) {
    arrayName.splice(arrayIndex, 1);
}
/* Opcion Nueva  busqueda desde la reserva, borra las sessiones antes de hacer nada 
reservar1.js,reservar2.js,reservar3.js
*/

function NuevaBusqueda(elemento) {
    var params = "reservar" + sepGra + "BorraSesiones";
    petiAjaxMain(params, RespSessiones);
}

function RespSessiones(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 + "reservar.aspx";
}

function muestraPopup(select, div) {
    $$('#' + select).invoke('hide');
    $(div).show();
}

function OcultaPopup(select, div) {
    $(div).hide();
    $$('#' + select).invoke('show');
}

function NuevaBusquedaReserva(evt) {
    evt = (evt) ? evt : event;
    if (evt.type == "click") {
        NuevaBusqueda();
    }
}

/* devuelve el valor del hidden de la reserva */
function getValorReserva() {
    var hidReserva = document.getElementById(idPieVacio + "hidReserva"); // datos de la reserva

    //return CodificaGetPost(hidReserva.value);
    return hidReserva.value;
}

function setValorReserva(valor) {
    var hidReserva = document.getElementById(idPieVacio + "hidReserva"); // datos de la reserva

    hidReserva.value = valor;
}

function hayHidReserva() {
    var ok;

    ok = document.getElementById(idPieVacio + "hidReserva") != null;

    return ok;
}

function CodificaGetPost(texto) {
    var trans = new Array("&", "=", "?", "/", "<", "#", "+", "{_A_}", "{_B_}", "{_S_}");
    var val = new Array("(_1_)", "(_2_)", "(_3_)", "(_4_)", "(_6_)", "(_9_)", "(_A_)", "(_7_)", "(_8_)", "(_9_)");
    var result = texto;
    for (var i = 0; i < val.length; i++) {
        result = replace(result, trans[i], val[i]);
    }
    return result;
}