﻿function volverListado(){
    if(document.getElementById('hidBusqueda').value!=""){
        window.location = document.getElementById('hidBusqueda').value;
    }
}
var nroFilaSeleccionado = -1;
function verHorarios(fecha, nroFila, grupos){
    if(grupos==undefined){
        grupos = '';
    }
    //oculto las filas que no corresponden
    for(i=0;i<7;i++){
        if(i!=nroFila){
            if(document.getElementById('trDetalle'+i + 'Grupos')!=null){
                document.getElementById('trDetalle'+i + 'Grupos').style.display='none';
                document.getElementById('row'+ i + 'Grupos').style.backgroundColor='#fdfbfc';
                document.getElementById('lnkOcultarHorarios'+i + 'Grupos').style.display='none';
                document.getElementById('lnkVerHorarios'+i + 'Grupos').style.display='';
            }
            if(document.getElementById('trDetalle'+i)!=null){
                document.getElementById('trDetalle'+i).style.display='none';
                document.getElementById('row'+i).style.backgroundColor='#fdfbfc';
                document.getElementById('lnkOcultarHorarios'+i).style.display='none';
                document.getElementById('lnkVerHorarios'+i).style.display='';
            }
        }else{
            document.getElementById('trDetalle'+i + grupos).style.display='';
            document.getElementById('row'+i + grupos).style.backgroundColor='#D5D5D5';
            document.getElementById('lnkVerHorarios'+i + grupos).style.display='none';
            document.getElementById('lnkOcultarHorarios'+i + grupos).style.display='';
        }
    }
    //guardar la fecha en un hidden para poder reservar
    document.getElementById('hidFechaSeleccionada').value = fecha;
    nroFilaSeleccionado = nroFila;
}
function ocultaHorarios(fecha, nroFila, grupos){
    if(grupos==undefined){
        grupos = '';
    }
    //oculto la fila
    document.getElementById('trDetalle'+nroFila + grupos).style.display='none';
    document.getElementById('row'+nroFila + grupos).style.backgroundColor='#fdfbfc';
    document.getElementById('lnkOcultarHorarios'+nroFila + grupos).style.display='none';
    document.getElementById('lnkVerHorarios'+nroFila + grupos).style.display='';
    //guardar la fecha en un hidden para poder reservar
    document.getElementById('hidFechaSeleccionada').value = '';
    nroFilaSeleccionado = -1;
}
function reservarTurno(idTurno, nroFila){
    var fecha = document.getElementById('hidFechaSeleccionada').value
    var pax = document.getElementById('cmbPax' + nroFila + '_' + idTurno).value;
    //var espacio = document.getElementById('cmbEspacios' + nroFila + '_' + idTurno).value;
    var menu = document.getElementById('cmbMenu' + nroFila + '_' + idTurno).value;
    if (menu == "") {
        alert(document.getElementById('hidTextoTipoReserva').value);
    } else {
        if (parseInt(pax) == 0) {
            alert(document.getElementById('hidTextoNroPersonas').value);
        } else {
            window.location = "reservar1.aspx?idR=" + document.getElementById('hidIdRestaurante').value + "&fecha=" + fecha + "&t=" + idTurno + "&pax=" + pax + "&m=" + menu;
        }
    }
}
function reservarTurnoGrupos(idTurno, nroFila) {
    var fecha = document.getElementById('hidFechaSeleccionada').value
    var pax = document.getElementById('txtPax' + nroFila + '_' + idTurno).value;
    var menu = document.getElementById('cmbMenuGrupo' + nroFila + '_' + idTurno).value;
    var restaurante = document.getElementById('hidNombreRestaurante').value;
    //var espacio = document.getElementById('cmbEspacios' + nroFila + '_' + idTurno).value;
    var espacio = 0;
    if(menu==""){
        alert(document.getElementById('hidTextoTipoReserva').value);
    }else{
        if(pax<=10){
            alert("La cantidad de comensales debe ser mayor a 10.");
        }else{
            //agrego la solicitud por ajax
            simple_ajax('ajaxSolicitudes.aspx','GET',"accion=agregar&idR="+ document.getElementById('hidIdRestaurante').value + "&fecha=" + fecha + "&t=" + idTurno + "&pax=" + pax + "&rnombre="+ restaurante + "&m=" + menu + "&idEsp=" + espacio);
        }
    }
}

function reemplazarLinks(){
    var link = document.getElementById('hidLink').value;
    
    var lnkRplc = document.getElementById('lnkFotos');
    if(lnkRplc!=null){
        lnkRplc.href = link.replace("ficha","fotos");
    }
    lnkRplc = document.getElementById('lnkMenus');
    if(lnkRplc!=null){
        lnkRplc.href = link.replace("ficha","menu");
    }
    lnkRplc = document.getElementById('lnkAmigos');
    if(lnkRplc!=null){
        lnkRplc.href = link.replace("bar","diselo").replace("ficha","diselo");
    }
    lnkRplc = document.getElementById('lnkComentarios');
    if(lnkRplc!=null){
        lnkRplc.href = link.replace("ficha","opinion");
    }
    lnkRplc = document.getElementById('lnkComentarios2');
    if(lnkRplc!=null){
        lnkRplc.href = link.replace("ficha","opinion");
    }
    lnkRplc = document.getElementById('lnkFicha');
    if(lnkRplc!=null){
        lnkRplc.href = link;
    }
}

function verComentarios(){
    //window.location = "restaurante_comentarios.aspx?idR=" + document.getElementById('hidIdRestaurante').value;
    window.location = document.getElementById('hidLink').value.replace("ficha","opinion");
}
function verMenus(){
    //window.location = "menus.aspx?idR=" + document.getElementById('hidIdRestaurante').value;
    window.location = document.getElementById('hidLink').value.replace("ficha","menu");
}
function verInfo(anc){
    if(anc==undefined){
        anc = "";
    }
    window.location = document.getElementById('hidLink').value + anc;
}
function verFotos(){
    //window.location = "restaurante_fotos.aspx?idR=" + document.getElementById('hidIdRestaurante').value;
    window.location = document.getElementById('hidLink').value.replace("ficha","fotos");
}
function invitaAmigos(){
    //window.location = "restaurante_diselo.aspx?idR=" + document.getElementById('hidIdRestaurante').value;
    window.location = document.getElementById('hidLink').value.replace("bar","diselo").replace("ficha","diselo");
}
function mostrarInfo(intNro){
    for(i=1;i<6;i++){
        if(document.getElementById('tblInfo' + i)!=null)
            document.getElementById('tblInfo' + i).style.display = 'none';
    }
    document.getElementById('tblInfo' + intNro).style.display = '';
    if(intNro==4){
        try{
            mostrarSolapaFicha(1);
            restaurarSolapaFicha(1);
            window.location = '#ancDisponibilidad';
        }catch(err){
        }
    }
}
function restaurarSolapaFicha(intNro){
    var strDiv = "divDisponibilidad" + intNro;
    var strImagen = "ImgphrImagenSolapa" + intNro;
    
    if(document.getElementById(strDiv).style.display==''){
        document.getElementById(strImagen).src = document.getElementById(strImagen).src.replace('_off','_on');
    }else{
        document.getElementById(strImagen).src = document.getElementById(strImagen).src.replace('_on','_off');
    }
}
function mostrarSolapaFicha(intNro){
    for(i=0;i<=1;i++){
        if(i==intNro){
            if(document.getElementById("ImgphrImagenSolapa" + i)!=null){
                document.getElementById("ImgphrImagenSolapa" + i).src = document.getElementById("ImgphrImagenSolapa" + i).src.replace('_on','_off');
            }
            document.getElementById("divDisponibilidad" + i).style.display = '';
        }else{
            if(document.getElementById("ImgphrImagenSolapa" + i)!=null){
                document.getElementById("ImgphrImagenSolapa" + i).src = document.getElementById("ImgphrImagenSolapa" + i).src.replace('_on','_off');
            }
            document.getElementById("divDisponibilidad" + i).style.display = 'none';
        }
    }
}
function VerMenu(intNro){
    document.getElementById('tblMenu' + intNro).style.display="";
    document.getElementById('lnkVerMenu' + intNro).style.display="none";
    document.getElementById('lnkOcultarMenu' + intNro).style.display="";
}
function OcultarMenu(intNro){
    document.getElementById('tblMenu' + intNro).style.display="none";
    document.getElementById('lnkVerMenu' + intNro).style.display="";
    document.getElementById('lnkOcultarMenu' + intNro).style.display="none";
}
function reservar(id_menu){
    var fecha = document.getElementById('hidFechaSeleccionada').value;
    if(fecha==undefined){
        fecha = "";
    }
    window.location = "reservar1.aspx?idR="+ document.getElementById('hidIdRestaurante').value + "&fecha=" + fecha + "&id_menu=" + id_menu;
}
function cambiarImagen(intNro){
    document.getElementById('imgPrincipal').src = document.getElementById('imgR'+ intNro).src;
}
function consultar(){
    var sNombre = document.getElementById('txtNombre').value;
    var sEmail  = document.getElementById('txtEmail').value;
    var sTelefono = document.getElementById('txtTelefono').value;
    var iMes = document.getElementById('cmbMes').value;
    var iDia = document.getElementById('cmbDia').value;
    var sHorario = document.getElementById('cmbHora').value;
    var iPersonas = document.getElementById('cmbPersonas').value;
    var iSolicita = document.getElementById('cmbSolicitar').value;
    var idR =  document.getElementById('hidIdRestaurante').value;
    var sCheckbox = "";
    
    var d = new Date();
    var anio = d.getFullYear();
    var fecha = new Date(anio, iMes-1, iDia);
    if(fecha<d){
        anio += 1;
    }
    var strFecha = iDia + "/" + iMes + "/" + anio;
    
    if(document.getElementById('chkoferta')!=null && document.getElementById('chkoferta').checked){
        sCheckbox += "oferta,";
    }
    if(document.getElementById('chkbebidas')!=null && document.getElementById('chkbebidas').checked){
        sCheckbox += "bebidas,";
    }
    if(document.getElementById('chkbaperitivos')!=null && document.getElementById('chkbaperitivos').checked){
        sCheckbox += "baperitivos,";
    }
    if(document.getElementById('chkcomida')!=null && document.getElementById('chkcomida').checked){
        sCheckbox += "comida,";
    }
    if(document.getElementById('chkzonaprivada')!=null && document.getElementById('chkzonaprivada').checked){
        sCheckbox += "zonaprivada,";
    }

    simple_ajax('ajaxConsultarFiesta.aspx','GET','idR='+idR+'&nombre='+sNombre+'&email='+sEmail+'&tel='+sTelefono+'&fecha='+strFecha+'&hora='+sHorario+'&personas='+iPersonas+'&solicita='+iSolicita+'&checkbox='+sCheckbox+'&url=' + document.getElementById('hidLink').value);
}


function anadirDiselo(){
    var tdEmails = document.getElementById('tdEmails');
    var tdNombres = document.getElementById('tdNombres');
    if(parseInt(document.Form.hidCantidad.value)<20){
        var elmTBODY = document.getElementById('tblAmigos');      
        var intCantidad = elmTBODY.rows.length;
        var anterior = "texto";
        if(document.getElementById('txtNombre' + (intCantidad-2))!=null){
            anterior = document.getElementById('txtNombre' + (intCantidad-2)).value;
        }
        if(anterior!=""){
            var elmTR = elmTBODY.insertRow(intCantidad);
            document.Form.hidCantidad.value = parseInt(document.Form.hidCantidad.value) + 1;
        		
	        //Creo los TDS
	        //Inserto la descripción en la celda 1
   	        elmTD = elmTR.insertCell(0);
            elmTD.setAttribute("style","padding-top:5px");
            elmTD.setAttribute("class","txt_destacado7");
            elmTD.innerHTML = "<input name=\"txtNombre\" id=\"txtNombre"+intCantidad+"\" onfocus=\"anadirDiselo()\" type=\"text\" class=\"imput_news\" style=\"width:130px;\" validationgroupname=\"Recomendados\" />";
            
            //inserto el codigo en la celda 2
            elmTD = elmTR.insertCell(1);
            elmTD.setAttribute("style","padding-top:5px");
            elmTD.setAttribute("class","txt_destacado7");
   	        elmTD.innerHTML = "<input name=\"txtEmail\" id=\"txtEmail"+intCantidad+"\" type=\"text\" tipo=\"EMail\" class=\"imput_news\" style=\"width:160px;\" validationgroupname=\"Recomendados\" />";
   	    }
   	}
}
function enviarDiselo(){
    cssClassDefault     = 'imput_news'; 
    cssClassDefaultError = 'imput_news_error'; 
    cssClassDefaultCombo = 'imput_filtro'; 
    cssClassDefaultErrorCombo = 'imput_news_error'; 
    
    if(ValidarGroup('Recomendados')){
        var arrNombres = document.getElementsByName('txtNombre');
        var arrEmails = document.getElementsByName('txtEmail');
        for(i=0;i<document.getElementById('hidCantidad').value;i++){
            if(arrNombres[i].value!=""){
                document.getElementById('hidRecomendados').value += arrNombres[i].value + "|" + arrEmails[i].value + "#";
            }
        }
        document.Form.hidAction.value = "guardar";
        document.Form.submit();
    }
}

function printOferta(){
    var myWindow = window.open("", "tinyWindow", 'toolbar=no,width=435,height=200');
    myWindow.document.write("<link href=\"css/restalo.css\" rel=\"stylesheet\" type=\"text/css\" />\n");
    myWindow.document.write(document.getElementById('div_fichaResto_oferespec').innerHTML);
    myWindow.document.close();
    myWindow.print();
    myWindow.close();
}

function verVideo(){
    if(document.getElementById('hidVideo').value!=""){
        document.getElementById('imgResto').style.display = 'none';
        document.getElementById('ply').style.display = '';
        //var strVideo = document.getElementById('hidVideo').value;
        //openPopup("video.aspx?url="+strVideo, 400, 400, false, false, "test")
    }
}

function muestraFecha(){
    if(document.getElementById('cmbFecha').value=="1"){
        document.getElementById('TbltxtFecha').style.display = '';
    }else{
        document.getElementById('TbltxtFecha').style.display = 'none';
    }
}
function muestraHora(){
    if(document.getElementById('cmbHora').value=="1"){
        document.getElementById('txtHora').style.display = '';
        document.getElementById('txtHora').value = '22:00';
    }else{
        document.getElementById('txtHora').style.display = 'none';
    }
}
function cambiaPax(combo){
    if(combo.value>10){
        combo.selectedIndex = 0;
        MM_swapImage('ImgphrImagenSolapa1','','images/idioma1/btn_reserva_grup_on.gif',1);
        mostrarSolapaFicha(1);
        verHorarios(document.getElementById('hidFechaSeleccionada').value, nroFilaSeleccionado, 'Grupos')
    }    
}
function seleccionarAmigos(){
    simple_ajax('ajaxRedirecciona.aspx','GET','pag='+getCurrentPage()+'&js=openPopup("popSeleccionaAmigos.aspx", 450, 400, false, false, "test")&a=6');
}
function enviarMenu(id_menu){
    if(id_menu==undefined){
        id_menu = 0;
    }
    simple_ajax('ajaxRedirecciona.aspx','GET','pag=enviarMenu.aspx||idR='+document.getElementById('hidIdRestaurante').value+'|id_menu='+id_menu+'&a=7');
}
function cambiarDescuento(fila, idTurno, nroDia, id_menu, grupo) {
    if (grupo == undefined) grupo = '';
    var strTextoDescuento = document.getElementById('hidTextoNoDisc').value;
    if(arrMenus[nroDia]!=null && arrMenus[nroDia][idTurno]!=null){
        arrDescuentos = arrMenus[nroDia][idTurno].split('|');
        for(i=0;i<arrDescuentos.length;i++){
            if(arrDescuentos[i]!=''){
                arrMenu = arrDescuentos[i].split('-');
                if(arrMenu[0]==id_menu){
                    strTextoDescuento = arrMenu[1];
                }
            }
        }
    }
    document.getElementById('disc' + grupo + fila).innerHTML = strTextoDescuento;
}