var $ = YAHOO.util.Dom.get;

function updateId(elem)
{
	id=elem.getAttribute('id').split('_');
	$('id_city2').value=id[1];
    $('destino').value=$('destino').value=elem.innerHTML;
}
function setDestino(set_destino, id_destino, do_submit)
{
     document.buscador_restaurantes_form.destino.value = set_destino;
     document.buscador_restaurantes_form.id_city.value = id_destino;
     document.buscador_restaurantes_form.id_city2.value = id_destino;
     $('popup').style.display='none';
     $('popup2').style.display='none';
     if(do_submit == 'true')
     {
         /*document.buscador.keywords.value = '';
         document.buscador.pg.value = 'home';
         buscar();*/
     }
}
function showDestinosMenu(titulo, pos_x, pos_y, do_submit)
{
    $('destinos_title').innerHTML=titulo;
    $('destinos_lista').innerHTML="<li>Cargando ...<"+"/li>";
    new Ajax.Request('/restaurantes/index.php', {
        method:'get',
        parameters:'pg=do_ajax&pg_action=destinos_con_marca&tipo='+titulo,
        onSuccess: function (response)
        {
            var html='';
            xmldata=response.responseXML.documentElement;
            nodes = xmldata.getElementsByTagName('data')[0].getElementsByTagName('destinogrp');
            $('destinos_lista').innerHTML='';
            z=0;
            for(i=0;i<nodes.length;i++)
            {
                html+='<li><a href="#" onclick="setDestino(\''+nodes[i].getAttribute("nombre").replace(/\'/g, "\\\'")+'\','+nodes[i].getAttribute("id_destino")+', \''+do_submit+'\');return false;">'+nodes[i].getAttribute("nombre")+'<'+'/a><'+'/li>\n';
                html+='<ul>';
                subnodes=nodes[i].getElementsByTagName('destino');
                if(titulo!='Provincias')
                {
                    for(y=0;y<subnodes.length;y++)
                    {
                        html+='<li><a href="#" onclick="setDestino(\''+subnodes[y].getAttribute("nombre").replace(/\'/g, "\\\'")+'\','+subnodes[y].getAttribute("id_destino")+',\''+do_submit+'\');return false;">'+subnodes[y].getAttribute("nombre")+'<'+'/a><'+'/li>\n';
                    }
                }
                html+='<'+'/ul>';
            }

            $('destinos_lista').innerHTML=html;
        }
    });
    $('popup').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup').style.right = (pos_x-250)+'px';
    $('popup2').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup2').style.right = (pos_x-250)+'px';
    $('popup').style.display='block';
    $('popup2').style.display='block';
}

function showDestinosMasProvincias(titulo, pos_x, pos_y)
{
    $('destinos_title').innerHTML=titulo;
    $('destinos_lista').innerHTML="<li>Cargando ...<"+"/li>";
    new Ajax.Request('/restaurantes/index.php', {
        method:'get',
        parameters:'pg=do_ajax&pg_action=destinos_mas_prov&tipo='+titulo,
        onSuccess: function (response)
        {
            var html='';
            xmldata=response.responseXML.documentElement;
            nodes = xmldata.getElementsByTagName('data')[0].getElementsByTagName('destinogrp');
            $('destinos_lista').innerHTML='';
            z=0;
            for(i=0;i<nodes.length;i++)
            {
                html+='<li><a href="/restaurantes/resultados?accion=especial&amp;grupos=0&amp;id_destino='+nodes[i].getAttribute("id_destino")+'" class="menu_2" title="'+nodes[i].getAttribute("nombre").replace(/\'/g, "\\\'")+'">'+nodes[i].getAttribute("nombre")+'</a><'+'/li>\n';
                html+='<ul>';
                subnodes=nodes[i].getElementsByTagName('destino');
                if(titulo!='Provincias')
                {
                    for(y=0;y<subnodes.length;y++)
                    {
                        html+='<li><a href="/restaurantes/resultados?accion=especial&amp;grupos=0&amp;id_destino='+subnodes[y].getAttribute("id_destino")+'" class="menu_2" title="'+subnodes[y].getAttribute("nombre").replace(/\'/g, "\\\'")+'">'+subnodes[y].getAttribute("nombre")+'</a><'+'/li>\n';
                    }
                }
                html+='<'+'/ul>';
            }

            $('destinos_lista').innerHTML=html;
        }
    });
    $('popup').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup').style.right = (pos_x+100)+'px';
    $('popup2').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup2').style.right = (pos_x+100)+'px';
    $('popup').style.display='block';
    $('popup2').style.display='block';
}

function showDestinosMenuSeccion(titulo, accion, id, param_id, pos_x, pos_y)
{
    $('destinos_title').innerHTML=titulo;
    $('destinos_lista').innerHTML="<li>Cargando ...<"+"/li>";
    new Ajax.Request('/restaurantes/index.php', 
    {
        method:'get',
        parameters:'pg=do_ajax&pg_action='+accion+'&tipo='+param_id+'&id='+id,
        onSuccess: function (response)
        {
            var html='';
            xmldata=response.responseXML.documentElement;
            nodes = xmldata.getElementsByTagName('data')[0].getElementsByTagName('destinogrp');
            $('destinos_lista').innerHTML='';
            z=0;
            for(i=0;i<nodes.length;i++)
            {
                html+='<li><a href="/restaurantes/resultados?accion=especial&amp;grupos=0&amp;id_destino='+nodes[i].getAttribute("id_destino")+'&amp;'+param_id+'='+id+'" class="menu_2" title="'+nodes[i].getAttribute("nombre").replace(/\'/g, "\\\'")+'">'+nodes[i].getAttribute("nombre")+'</a><'+'/li>\n';
                html+='<ul>';
                subnodes=nodes[i].getElementsByTagName('destino');
                if(titulo!='Provincias')
                {
                    for(y=0;y<subnodes.length;y++)
                    {
                        html+='<li><a href="/restaurantes/resultados?accion=especial&amp;grupos=0&amp;id_destino='+subnodes[y].getAttribute("id_destino")+'&amp;'+param_id+'='+id+'" class="menu_2" title="'+subnodes[y].getAttribute("nombre").replace(/\'/g, "\\\'")+'">'+subnodes[y].getAttribute("nombre")+'</a><'+'/li>\n';
                    }
                }
                html+='<'+'/ul>';
            }

            $('destinos_lista').innerHTML=html;
        }
    });
    $('popup').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup').style.right = (pos_x+100)+'px';
    $('popup2').style.top = (pos_y-200)+document.documentElement.scrollTop+'px';
    $('popup2').style.right = (pos_x+100)+'px';
    $('popup').style.display='block';
    $('popup2').style.display='block';
}

// Función que hace la llamada AJAX para cargar los Favoritos o MasBuscados,
// dependiendo de si el usuario está logeado o no. Se hace de esta forma para
// evitar que la caché de SQUID no lo actualice bien
function cargar_favoritos_o_masbuscados()
{
    var callback ={ 
            timeout: 10000,
            success: function(o) 
            {
                // Incrustamos en la capa del banner el codigo html devuelto por la llamada AJAX
                document.getElementById('favoritos_o_masbuscados').innerHTML = o.responseText;
            }
        }
    // Llamada AJAX    
    YAHOO.util.Connect.asyncRequest("GET", "/restaurantes/do_ajax?pg_action=favoritos_o_masbuscados", callback );
}

