﻿var urlBuscador = "/restaurantes/";

function limpiarVW(param) {
    var searchType = (searchType != undefined ? true : false);

    searchType = true;
    
    if (!searchType) {
        var url = location.href;
        searchType = url.indexOf(urlBuscador) > 0 ? true : false;
    }

   
    document.Form.__VIEWSTATE.disabled = true;
/*
    if (document.Form.hidAction != null && '' == document.Form.hidAction.value) { quitarControl(document.Form.hidAction); }
    if (document.Form.hidIdIdioma != null && '' == document.Form.hidIdIdioma.value) { quitarControl(document.Form.hidIdIdioma); }
    if (document.Form.hidOrigen != null && '' == document.Form.hidOrigen.value) { quitarControl(document.Form.hidOrigen); }
    if (document.Form.rbComida != null && '' == document.Form.rbComida.value) { quitarControl(document.Form.rbComida); }
    if (document.Form.cmbPrecios != null && '' == document.Form.cmbPrecios.value) { quitarControl(document.Form.cmbPrecios); }
    if (document.Form.hRegBusq != null && '' == document.Form.hRegBusq.value) { quitarControl(document.Form.hRegBusq); }
    if (document.Form.puntos != null && '' == document.Form.puntos.value) { quitarControl(document.Form.puntos); }
    if (document.Form.chkEmpresas != null && '' == document.Form.chkEmpresas.value) { quitarControl(document.Form.chkEmpresas); }
    if (document.Form.txtFecha != null && '' == document.Form.txtFecha.value) { quitarControl(document.Form.txtFecha); }
    if (document.Form.txtComensales != null && '' == document.Form.txtComensales.value) { quitarControl(document.Form.txtComensales); }
    if (document.Form.txtPalabraClave != null && '' == document.Form.txtPalabraClave.value) { quitarControl(document.Form.txtPalabraClave); }
    if (document.Form.txtDireccion != null && '' == document.Form.txtDireccion.value) { quitarControl(document.Form.txtDireccion); }
    if (document.Form.txtCiudad != null && '' == document.Form.txtCiudad.value) { quitarControl(document.Form.txtCiudad); }
    if (document.Form.rbCampoBusqueda != null && '' == document.Form.rbCampoBusqueda.value) { quitarControl(document.Form.rbCampoBusqueda); }
    if (document.Form.tipoOf != null && '-3' == document.Form.tipoOf.value) { quitarControl(document.Form.tipoOf); }
    if (document.Form.chkOfertas != null && '0' == document.Form.chkOfertas.value) { quitarControl(document.Form.chkOfertas); }
    if (document.Form.chkMapa != null && '0' == document.Form.chkMapa.value) { quitarControl(document.Form.chkMapa); }
    if (document.Form.chkZonaPrivada != null && '0' == document.Form.chkZonaPrivada.value) { quitarControl(document.Form.chkZonaPrivada); }
    if (document.Form.hidBar != null && '0' == document.Form.hidBar.value) { quitarControl(document.Form.hidBar); }
    if (document.Form.hidIdBF != null && '0' == document.Form.hidIdBF.value) { quitarControl(document.Form.hidIdBF); }
    if (document.Form.hidIdServ != null && '0' == document.Form.hidIdServ.value) { quitarControl(document.Form.hidIdServ); }
    if (document.Form.chkSalasPrivadas != null && '0' == document.Form.chkSalasPrivadas.value) { quitarControl(document.Form.chkSalasPrivadas); }
    if (document.Form.idProvincia != null && '0' == document.Form.idProvincia.value) { quitarControl(document.Form.idProvincia); }
    if (document.Form.cmbOrden != null && '0' == document.Form.cmbOrden.value) { quitarControl(document.Form.cmbOrden); }
    if (document.Form.cmbCerca != null && '0' == document.Form.cmbCerca.value) { quitarControl(document.Form.cmbCerca); }
    if (document.Form.cmbTipoCocina != null && '0' == document.Form.cmbTipoCocina.value) { quitarControl(document.Form.cmbTipoCocina); }
    if (document.Form.cmbAmbientes != null && '0' == document.Form.cmbAmbientes.value) { quitarControl(document.Form.cmbAmbientes); }

    var query = jQuery("#Form").serialize();*/

    if (searchType) {
  
        try {
/*
            hidAction = "&hidAction=" + document.Form.hidAction.value;
            hidIdIdioma = "&hidIdIdioma=" + document.Form.hidIdIdioma.value;
            rbComida = "&rbComida=" + document.Form.rbComida.value;
            cmbPrecios = "&cmbPrecios=" + document.Form.cmbPrecios.value;
            hRegBusq = "&hRegBusq=" + document.Form.hRegBusq.value;
            puntos = "&puntos=" + document.Form.puntos.value;
            chkEmpresas = "&chkEmpresas=" + document.Form.chkEmpresas.value;
            txtFecha = "&txtFecha=" + document.Form.txtFecha.value;
            txtComensales = "&txtComensales=" + document.Form.txtComensales.value;
            txtPalabraClave = "&txtPalabraClave=" + document.Form.txtPalabraClave.value;
            txtDireccion = "&txtDireccion=" + document.Form.txtDireccion.value;
            txtCiudad = "txtCiudad=" + document.Form.txtCiudad.value;
            chkOfertas = "&chkOfertas=" + document.Form.chkOfertas.value;
            chkMapa = "&chkMapa=" + document.Form.chkMapa.value;
            chkZonaPrivada = "&chkZonaPrivada=" + document.Form.chkZonaPrivada.value;
            hidBar = "&hidBar=" + document.Form.hidBar.value;
            chkSalasPrivadas = "&chkSalasPrivadas=" + document.Form.chkSalasPrivadas.value;
            idProvincia = "&idProvincia=" + document.Form.idProvincia.value;

            cmbPrecios = "&cmbPrecios=" + jQuery("#cmbPrecios option:selected").text();
            cmbTipoCocina = "&cmbTipoCocina=" + jQuery("#cmbTipoCocina option:selected").text();
            cmbAmbientes = "&cmbAmbientes=" + jQuery("#cmbAmbientes option:selected").text();
            cmbCerca = "&cmbCerca=" + jQuery("#cmbCerca option:selected").text();
            cmbOrden = "&cmbOrden=" + jQuery("#cmbOrden option:selected").text();



            hidIdBF = "&hidIdBF=" + document.getElementById('nameBf').value;
            hidIdServ = "&hidIdServ=" + document.getElementById('nameServ').value;
            tipoOf = "&tipoOf=" + document.getElementById('nameOf').value;
            hidZona = "&hidZona=" + document.getElementById('nameZona').value;
            
            
            
            rbCampoBusqueda = "";

            var idioma = getIdioma();

            switch (document.getElementById('rbCampoBusqueda').value) {
                case '1':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "nobar" : idioma == 2 ? "nobar" : idioma == 3 ? "nobar" : "nobar");
                    break;
                case '2':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "bar" : idioma == 2 ? "bar" : idioma == 3 ? "bar" : "bar");
                    break;
                case '3':
                    buscarPor = "&txtCiudad=" + txtCiudad;
                    break;
                case '4':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "calle" : idioma == 2 ? "calle" : idioma == 3 ? "calle" : "calle");
                    break;
                case '5':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "cocina" : idioma == 2 ? "cocina" : idioma == 3 ? "cocina" : "cocina");
                    break;
                case '6':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "cp" : idioma == 2 ? "cp" : idioma == 3 ? "cp" : "cp");
                    break;
                case '7':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "estacion tren" : idioma == 2 ? "estacion tren" : idioma == 3 ? "estacion tren" : "estacion tren");
                    break;
                case '7':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "estacion metro" : idioma == 2 ? "estacion metro" : idioma == 3 ? "estacion metro" : "estacion metro");
                    break;
                case '8':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "ideal para" : idioma == 2 ? "ideal para" : idioma == 3 ? "ideal para" : "idela para");
                    break;
                case '9':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "zona" : idioma == 2 ? "zona" : idioma == 3 ? "zona" : "zona");
                    break;
                case '100':
                    buscarPor = "rbCampoBusqueda" + "=" + (idioma == 1 ? "zona" : idioma == 2 ? "zona" : idioma == 3 ? "zona" : "zona");
                    break;
            }

            query = txtCiudad + txtPalabraClave + rbCampoBusqueda + hidIdBF + hidIdServ + tipoOf + hidZona + rbComida + cmbPrecios + puntos + chkEmpresas + txtComensales + txtFecha + cmbPrecios + cmbTipoCocina + cmbAmbientes + cmbCerca + cmbOrden + hidAction + hidIdIdioma + hRegBusq + txtDireccion + chkOfertas + chkMapa + chkZonaPrivada + hidBar + chkSalasPrivadas + idProvincia;
*/
            //window.location = urlBuscador + encode(query);

            try {
                espera();
                window.scrollTo(0, 0);
                document.Form.Action = "/resultados.aspx";
                setTimeout("buscar1('','',true);", 1500);
            } catch (Error) { }

        } catch (error) { }
    } else {
        try {
            espera();
            window.scrollTo(0, 0);
            document.Form.Action = "/resultados.aspx";
            setTimeout("document.Form.submit();", 1500);
        } catch (Error) { }
    }
       

    /*
    if (param && searchType) 
    {
    buscar1('', '', 'on');
    }
    else {
    try {
    espera();
    window.scrollTo(0, 0);
    } catch (Error) { }
    document.Form.Action = "/resultados.aspx";
    setTimeout("document.Form.submit();", 1500);
    }*/
    /*
    jQuery.ajax({
    type: "GET",
    url: '/buildQueryBreadCrumb.aspx',
    data: jQuery("#Form").serialize(),
    beforeSend: function() {
    alert(jQuery("#Form").serialize());
    try {
    espera();
    window.scrollTo(0, 0);
    } catch (Error) { }

    },
    success: function(msg) {
    window.location = msg;
    }
    });*/
}

function quitarControl(control) {
    
    try {
        
        control.parentNode.removeChild(control);
        
    } catch (error) { }
}

function mostrarBuscador(buscador) {

    if (buscador == 1) {
        
        document.getElementById('divBuscador2').style.display = 'none';
        document.getElementById('divBuscador1').style.display = '';
        //cambiar ImgphrImagenBuscar1 y 2
        document.getElementById('ImgphrImagenBuscar1').src = document.getElementById('ImgphrImagenBuscar1').src.replace('.gif','on.gif');
        document.getElementById('ImgphrImagenBuscar2').src = document.getElementById('ImgphrImagenBuscar2').src.replace('on.gif', '.gif');

    } else {
        
        document.getElementById('divBuscador1').style.display = 'none';
        document.getElementById('divBuscador2').style.display = '';
        document.getElementById('ImgphrImagenBuscar1').src = document.getElementById('ImgphrImagenBuscar1').src.replace('on.gif','.gif');
        document.getElementById('ImgphrImagenBuscar2').src = document.getElementById('ImgphrImagenBuscar2').src.replace('.gif','on.gif');
    }
}

function mostrarAcotar(nro){
    for(var i=1; i<5; i++){
        document.getElementById('divAcotar'+i).style.display = 'none';
    }
    document.getElementById('divAcotar'+nro).style.display = '';
}

function anterior_nuevo() {
    Buscar_nuevo('PagRestaurantes', document.getElementById('hidAnterior').value);
}

function siguiente_nuevo() {
    Buscar_nuevo('PagRestaurantes', document.getElementById('hidSiguiente').value);
}

function anterior() {
    Buscar('PagRestaurantes', document.getElementById('hidAnterior').value);
}

function siguiente() {
    Buscar('PagRestaurantes', document.getElementById('hidSiguiente').value);
}

function cambiarSolapa(solapa){
    if(solapa==1 && document.getElementById('hidBar').value!=0){
        document.getElementById('hidBar').value = 0;
        document.getElementById('chkMapa').value = 0;
        limpiarVW();
    }else if(solapa==2 && document.getElementById('hidBar').value!=1){
        document.getElementById('hidBar').value = 1;
        document.getElementById('chkMapa').value = 0;
        limpiarVW();
    }
    //si llega acá es porque no necesita hacer submit
    if(solapa==1){
       document.getElementById('ImgphrImagenListado').src = document.getElementById('ImgphrImagenListado').src.replace('_off','_on');
       /*document.getElementById('ImgphrImagenBares').src = document.getElementById('ImgphrImagenBares').src.replace('_on','_off');*/
       document.getElementById('ImgphrImagenMapa').src = document.getElementById('ImgphrImagenMapa').src.replace('_on','_off');
       document.getElementById('chkMapa').value = 0;
       document.getElementById('trListado').style.display = '';
       document.getElementById('trMapa').style.display = 'none';
       if(document.getElementById('ImgphrImagenAnterior')!=null){
            document.getElementById('ImgphrImagenAnterior').style.display = '';
       }
       if(document.getElementById('ImgphrImagenSiguiente')!=null){
            document.getElementById('ImgphrImagenSiguiente').style.display = '';
       }
       /*if(document.getElementById('TblPagRestaurantes')!=null){
            document.getElementById('TblPagRestaurantes').style.display = '';
       }*/
    }else if(solapa==2){
       document.getElementById('ImgphrImagenListado').src = document.getElementById('ImgphrImagenListado').src.replace('_on','_off');
       document.getElementById('ImgphrImagenBares').src = document.getElementById('ImgphrImagenBares').src.replace('_off','_on');
       document.getElementById('ImgphrImagenMapa').src = document.getElementById('ImgphrImagenMapa').src.replace('_on','_off');
       document.getElementById('chkMapa').value = 0;
       document.getElementById('trListado').style.display = '';
       document.getElementById('trMapa').style.display = 'none';
       if(document.getElementById('ImgphrImagenAnterior')!=null){
            document.getElementById('ImgphrImagenAnterior').style.display = '';
       }
       if(document.getElementById('ImgphrImagenSiguiente')!=null){
            document.getElementById('ImgphrImagenSiguiente').style.display = '';
       }
      /* if(document.getElementById('TblPagRestaurantes')!=null){
            document.getElementById('TblPagRestaurantes').style.display = '';
       }*/
    }else{
       document.getElementById('ImgphrImagenListado').src = document.getElementById('ImgphrImagenListado').src.replace('_on','_off');
       /*document.getElementById('ImgphrImagenBares').src = document.getElementById('ImgphrImagenBares').src.replace('_on','_off');*/
       document.getElementById('ImgphrImagenMapa').src = document.getElementById('ImgphrImagenMapa').src.replace('_off','_on');
       document.getElementById('trListado').style.display = 'none';
       document.getElementById('trMapa').style.display = '';
       if(!bMapaVisible){
        initialize();
       }
       if(document.getElementById('ImgphrImagenAnterior')!=null){
            document.getElementById('ImgphrImagenAnterior').style.display = 'none';
       }
       if(document.getElementById('ImgphrImagenSiguiente')!=null){
            document.getElementById('ImgphrImagenSiguiente').style.display = 'none';
       }
       /*if(document.getElementById('TblPagRestaurantes')!=null){
            document.getElementById('TblPagRestaurantes').style.display = 'none';
       }*/
    }
}

function mostrarCercaDe(id){
    var arrDivs = getElementsByName_iefix('div','divCerca');
    for(var i=0; i<arrDivs.length; i++){
        arrDivs[i].style.display = 'none';
    }
    document.getElementById('divCerca'+id).style.display = '';
}

function filtrarBF(idBF){
    document.getElementById('hidIdBF').value = idBF;
    limpiarVW();
}


function filtrarServicios(idS){
    document.getElementById('hidIdServ').value = idS;
    limpiarVW();
}


function filtrarOfertas(tipoOf){
    document.getElementById('tipoOf').value = tipoOf;
    limpiarVW();
}


function filtrarCiudad1(ciudad, nameCiudad) {
    document.getElementById('txtCiudad').value = ciudad;
    document.getElementById('hidnameCiudad').value = nameCiudad;
    limpiarVW(true);
}
function filtrarBF1(idBF, nameBf) {
    document.getElementById('hidIdBF').value = idBF;
    document.getElementById('nameBf').value = nameBf;
    limpiarVW(true);
}
function filtrarOfertas1(tipoOf, nameOf) {
    document.getElementById('tipoOf').value = tipoOf;
    document.getElementById('nameOf').value = nameOf;
    limpiarVW(true);
}
function filtrarServicios1(idS, nameServ) {
    document.getElementById('hidIdServ').value = idS;
    document.getElementById('nameServ').value = nameServ;
    limpiarVW(true);
}
function filtrarZona(zona, name) {
    document.getElementById('hidZona').value = zona;
    document.getElementById('nameZona').value = name;
    limpiarVW(true);
}


function filtrarCiudad(ciudad){
    document.getElementById('txtCiudad').value = ciudad;
    limpiarVW(true);
}


function filtrarCercaDe(idCercaDe){
    document.getElementById('cmbCerca').value = idCercaDe;
    limpiarVW(true);
}
function reordenar(){
    limpiarVW(true);
}
function centrarBusqueda(){
    cssClassDefault = 'imput_news'; 
    cssClassDefaultError = 'imput_news_error'; 

    if(ValidarGroup('frmDireccion')){
        var ciudad = "";
        if(document.getElementById('txtCiudad')!=null && document.getElementById('txtCiudad').value!=""){
            ciudad = "," + document.getElementById('txtCiudad').value;
        }
        address = document.getElementById('txtDireccion').value + ciudad;
        geocoder = new GClientGeocoder();
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found. Please, insert a new location.");
            } else {
                // Create our marker icon
                var myIcon = new GIcon(G_DEFAULT_ICON);
                //myIcon.image = document.getElementById('hidURLMarker').value;
                //myIcon.iconSize = new GSize(47, 34);  
                // Set up our GMarkerOptions object
                markerOptions = { icon:myIcon };

              map.setCenter(point, 14);
              var marker = new GMarker(point, markerOptions);
              map.addOverlay(marker);
              //marker.openInfoWindowHtml(address);
            }
          }
        );
    }
}
function Restaurante(id, nombre, contenido, coordenadas, reserva, nro){
    this.id = id;
    this.nombre = nombre;
    this.contenido = contenido;
    this.coordenadas = coordenadas;
    this.reserva = reserva;
    this.nro = nro;
}

function enviarMenu(id_menu, id_restaurante){
    if(id_menu==undefined){
        id_menu = 0;
    }
    simple_ajax('/ajaxRedirecciona.aspx','GET','pag=enviarMenu.aspx||idR='+id_restaurante+'|id_menu='+id_menu+'&a=7');
}
