/**
* Declaracion de vars
**/
var skicos = false;
var d = new Date();
var hoy = new Date(d.getFullYear(), d.getMonth(), d.getDate());
var aplicacion="HOT";
var id_package_hot="12";
var opiniones=new Array();
var img_header_HOT=new Array();
var width_tabla=780;
var dir_hoteles='/hoteles/';
/**
* FUNCIONES
**/
function ver_mapa(mapa_url)
{
    ventana=open(mapa_url,"MAPA",'resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=800,height=600');
}

/**
* BUSCADOR
**/

/**
* Funcion que actualiza el el destino y los nombres segun la seleccion en el desplegable dinamico
*/
function updateId(elem)
{
    id=elem.getAttribute('id').split('_');
    name=elem.getAttribute('name');
    if(id[0]=='cid') $('id_costa').value=id[1];
    else $('id_destino').value=id[1];
    $('nombre_destino').value=$('nombre_destino1').value=$('nombre_destino2').value=name;
    if ( pestanaya_activa=='3' || pestanaya_activa=='5' || pestanaya_activa=='4' || pestanaya_activa=='7' ) reloadHoteles('id_hotel2');
}

function countNinyos()
{
    var nNinos = 0;
    for(i=1;i<5;i++)
    {
        var slc = $('num_ninos_' + i);
        nNinos = nNinos + slc[slc.selectedIndex].value;
    }
    return nNinos;
}

function actualizaNinos(fila)
{
    var strAd = 'num_adultos_'+fila;
    var strNi = 'num_ninos_'+fila;
    var lim = 0;
    var a = $(strAd);
    var n = $(strNi);

    var nAd = parseInt(a[a.selectedIndex].value);
    var nNi = parseInt(n[n.selectedIndex].value);

    n.options.length = 0;

    if (nAd > 1) lim = nAd + 1;
    else lim = nAd;

    var i=0;
    while ((i<lim) && ((nAd+i) <= 6))
    {
        n.options[i] = new Option(i,i);
        if (i == (nNi-0)) n.options[i].selected = true;
        i++;
    }
}

function actualizaAdultos(fila)
{
    var strAd = 'num_adultos_'+fila;
    var strNi = 'num_ninos_'+fila;

    a = $(strAd);
    n = $(strNi);

    nNi = (n[n.selectedIndex].value)-0;
    nAd = (a[a.selectedIndex].value)-0;

    if (nNi > 3)
    {
        errores.push(new Error('12','000','000','No se pueden reservar más de 3 niños por habitación'));
        errores.show();
        n.selectedIndex = 0;
        return false;
    }
    else
    {
        a.options.length=0;

        if (nNi == 0) i = 1;
        else if (nNi <= 2) i = 2;
        else i = nNi - 1;

        j=0;
        while ((i+nNi) <= 6)
        {
            a.options[j] = new Option(i,i);
            if (i == nAd) a.options[j].selected = true;
            j++;
            i++;
        }
    }
}

function mostrarFilasHabitaciones(cantidad)
{
    if(cantidad>1 && $('hab1')) $('hab1').style.display='block';
    else if($('hab1')) $('hab1').style.display='none';
    for(i=2;i<(num_max_hab+1);i++)
    {
        if (i<=cantidad)
        {
            $('fila_hab_'+i+'_a').style.display = (is_ie ? 'block' : 'table-row');
            $('fila_hab_'+i+'_b').style.display = (is_ie ? 'block' : 'table-row');
            $('fila_hab_'+i+'_c').style.display = (is_ie ? 'block' : 'table-row');
            if (!$('num_ninos_'+i).options[0].selected) $('label_edad_'+i).style.display = (is_ie ? 'block' : 'table-row');
        }else{
            $('fila_hab_'+i+'_a').style.display = 'none';
            $('fila_hab_'+i+'_b').style.display = 'none';
            $('fila_hab_'+i+'_c').style.display = 'none';
            $('label_edad_'+i).style.display    = 'none';
        }
    }
}

function deshabilitar_fecha(fecha)
{
    fecha=new Date(fecha.getFullYear(), fecha.getMonth(), fecha.getDate());
    fecha_minima=new Date(d.getFullYear(), d.getMonth(), d.getDate());
    fecha_maxima=new Date(d.getFullYear()+1, d.getMonth(),d.getDate());
    //if (((d.getUTCHours()+2)>19 || ((d.getUTCHours()+2)==19 && d.getMinutes()>=0)) && fecha.valueOf()==hoy.valueOf()) return(true);
    if (fecha.valueOf()<fecha_minima.valueOf() || fecha.valueOf()>fecha_maxima.valueOf()) return(true);
    else return(false);
}


function DivSetVisible(state)
{
    var DivRef = $('completeDiv');
    var IfrRef = $('iFrameChapuza');
    if(state)
    {
        DivRef.style.top = 22;
        DivRef.style.left = 0;
        DivRef.style.width = 265;
        IfrRef.style.width = DivRef.offsetWidth;
        IfrRef.style.height = DivRef.offsetHeight;
        IfrRef.style.top = 22;
        IfrRef.style.left = 0;
        IfrRef.style.zIndex = DivRef.style.zIndex - 1;
        IfrRef.style.display = 'block';
        DivRef.style.display = 'block';
    }
    else
    {
        DivRef.style.display = "none";
        IfrRef.style.display = "none";
    }
}


function mostrarInputsEdades(cantidad,enFila)
{
    for(i=1;i<=3;i++)
    {
        $('edad_'+enFila+'_'+i).style.display = (i<=cantidad)?'inline':'none';
    }
    $('div_edades_'+enFila).style.display = (cantidad>0 ? 'block' : 'none');
    $('label_edad_'+enFila).style.display = (cantidad>0 ? (is_ie ? 'block' : 'table-row') : 'none');
}

function setCheckedValue(radioObj, newValue) {
    if(!radioObj)
    return;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for(var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if(radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

/**
 * Calendario
 **/
function update_calendars(cal)
{
    var date = cal.date;
    var time = date.getTime()
    var field = $("fecha_entrada");
    if (field == cal.params.inputField)
    {
        field = $("fecha_salida");
        if (field.value != '')
        {
            var a = field.value.split('/');
            var dia = a[0];
            var mes = a[1];
            var anyo = a[2];
            var date2 = new Date(anyo, mes-1, dia);
            var time2 = date2.getTime();
            if (time > time2)
            {
                errores.push(new Error('12','000','000',"La fecha de salida no puede ser anterior a la de entrada"));
                field.value = '';
                field.style.borderColor='#CC0000'
                field.style.backgroundColor='#FFFFCC'
            }
        }
        else
        {
            var date2 = date;
            date2.setTime(time+(86000000));
            field.value = date2.print("%d/%m/%Y");
            field.style.borderColor='#CC0000'
            field.style.backgroundColor='#FFFFCC'
        }
    }
    else
    {
        field = $("fecha_entrada");
        if (field.value != '')
        {
            var a = field.value.split('/');
            var dia = a[0];
            var mes = a[1];
            var anyo = a[2];
            var date2 = new Date(anyo, mes-1, dia);
            var time2 = date2.getTime();
            field = $("fecha_salida");
            if (time < time2)
            {
                errores.push(new Error('12','000','000','La fehca de salida no puede ser anterior a la de entrada'));
                field.value = '';
                field.style.borderColor='#CC0000'
                field.style.backgroundColor='#FFFFCC'
            }
            else
            {
                field.style.borderColor='';
                field.style.backgroundColor='';
            }
        }
    }
    errores.show();
}
/**
 * Metodo para inercambiar las fotos de la ficha
 **/
function flipFoto(donde,que)
{
    que=que.replace('width=50&height=36','width=225&height=158')
    $(donde).src=que;
}

/**
 * Metodoque iguala las alturas de dos capas
 **/
function igualarAlturas(capa1,capa2,nombre_comun)
{
    var offset=0;
    if(!$(capa1) || !$(capa2)) return false;
    for(i=0;i<2;i++)
    {
        if ($(nombre_comun+i).offsetHeight>offset)  offset=$(nombre_comun+i).offsetHeight;
    }
    for(i=0;i<2;i++)
    {
        $(nombre_comun+i).style.height=(offset-6)+'px';
    }
}

/**
* Calendarios
**/
function setUpCalendar()
{
    Calendar.setup(
    {
        inputField          :   "fecha_entrada",
        button              :   "entrada-trigger",
        range               :   [d.getFullYear(), d.getFullYear()+1],
        onUpdate            :   update_calendars,
        ifFormat            :   "%d/%m/%Y",
        electric            :   false,
        firstDay            :   1,
        dateStatusFunc      :   deshabilitar_fecha,
        weekNumbers         :   false
    }
    );

    Calendar.setup(
    {
        inputField          :   "fecha_entrada",
        button              :   "campo_entrada",
        range               :   [d.getFullYear(), d.getFullYear()+1],
        onUpdate            :   update_calendars,
        ifFormat            :   "%d/%m/%Y",
        electric            :   false,
        firstDay            :   1,
        dateStatusFunc      :   deshabilitar_fecha,
        weekNumbers         :   false
    }
    );

    Calendar.setup(
    {
        inputField          :   "fecha_salida",
        button              :   "salida-trigger",
        range               :   [d.getFullYear(), d.getFullYear()+1],
        onUpdate            :   update_calendars,
        ifFormat            :   "%d/%m/%Y",
        electric            :   false,
        firstDay            :   1,
        dateStatusFunc      :   deshabilitar_fecha,
        weekNumbers         :   false
    }
    );

    Calendar.setup(
    {
        inputField          :   "fecha_salida",
        button              :   "campo_salida",
        range               :   [d.getFullYear(), d.getFullYear()+1],
        onUpdate            :   update_calendars,
        ifFormat            :   "%d/%m/%Y",
        electric            :   false,
        firstDay            :   1,
        dateStatusFunc      :   deshabilitar_fecha,
        weekNumbers         :   false
    }
    );
}

/**
* Muestra el layer con varios destinos
*/
function mostrar_destinos(app)
{
    if($('dest_iframe_hoteles').style.display=="inline")
    {
        cerrar(app);
        return;
    }
    if($('dest_iframe_hoteles').innerHTML=='')
    {
        new Ajax.Request(dir_hoteles+'index.php',{method:'get',parameters:'pg=destinos_hoteles',onSuccess:function(response){$('dest_iframe_hoteles').innerHTML=response.responseText;$('dest_iframe_hoteles').style.display="inline";$('dest_iframe_hoteles2').style.display="inline";}});
    }else
    {
        $('dest_iframe_hoteles').style.display="inline";
        $('dest_iframe_hoteles2').style.display="inline";
    }
}

/**
* Cierra el layer de los destinos sugeridos
*/
function cerrar(prod)
{
    $('dest_iframe_'+prod).style.display="none";
    $('dest_iframe_'+prod+'2').style.display="none";
}

function informar(text,code)
{
    var txt = parent.$('id_destino3');
    var idF = parent.$('idField');
    $('id_destino').value = code;
    $('nombre_destino').value = text;
    $('nombre_destino1').value = text;
    $('nombre_destino2').value = text;
    cerrar('hoteles');
}

function informar2(text,code)
{
    var txd = parent.$('id_destino1');
    var txt = parent.$('id_destino3');
    $('id_destino').value = '';
    $('nombre_destino').value = text;
    $('nombre_destino1').value = text;
    $('nombre_destino2').value = text;
    $('id_costa').value = code;
    cerrar('hoteles');
}

