﻿
var ClienteCP = '';
var ClientePoblacion = '';
var ClientePais = '';
var ClientePaisCC = '';
var ClienteLatitud = '';
var ClienteLongitud = '';
var ClienteDireccion = '';


function SetServicioInmediato(opt) {
    //document.getElementById('<%=optInmediato.ClientID%>').checked = true;
    document.getElementById(opt).checked = true;
//    document.getElementById('btnSolicitarInmediato').style.visibility = 'visible';
//    document.getElementById('btnSolicitarReserva').style.visibility = 'hidden';

    //document.getElementById('btnSolicitarInmediato').style.display = 'inline';
    document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'inline';
//    document.getElementById('btnSolicitarInmediato').style.display = 'none';
    document.getElementById('btnSolicitarReserva').style.display = 'none';


}
function SetServicioReserva(opt) {
    document.getElementById(opt).checked = true;
//    document.getElementById('btnSolicitarInmediato').style.visibility = 'hidden';
//    document.getElementById('btnSolicitarReserva').style.visibility = 'visible';

    document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'none';
    document.getElementById('btnSolicitarInmediato').style.display = 'none';
    document.getElementById('btnSolicitarReserva').style.display = 'inline';


}


function GetAddressComponent() {


}


function PonDireccionValidada() {
    document.getElementById('divMapClienteCnt').style.display = 'none'; 
    document.getElementById('btnVerificaDireccion').value = 'Dirección Verificada';
    document.getElementById('chkDireccionClienteValidada').checked = true;
    
    document.getElementById('lblCoordenadas').style.display = 'inline';
    document.getElementById('lblLatValue').style.display = 'inline';
    document.getElementById('lblLatValue').innerHTML = ClienteLatitud;
    document.getElementById('lblLatValueHidden').value = ClienteLatitud;
    document.getElementById('lblLngValue').style.display = 'inline';
    document.getElementById('lblLngValue').innerHTML = ClienteLongitud;
    document.getElementById('lblLngValueHidden').value = ClienteLongitud;
    document.getElementById('lblCP').style.display = 'inline';
    document.getElementById('lblCPValue').style.display = 'inline';
    document.getElementById('lblCPValue').innerHTML = ClienteCP;
    document.getElementById('lblCPValueHidden').value = ClienteCP;
    document.getElementById('lblPoblacion').style.display = 'inline';
    document.getElementById('lblPoblacionValue').style.display = 'inline';
    document.getElementById('lblPoblacionValue').innerHTML = ClientePoblacion;
    document.getElementById('lblPoblacionValueHidden').value = ClientePoblacion;

    //document.getElementById('btnSolicitarInmediato').style.display = 'inline';
    document.getElementById('btnSolicitarInmediato').style.display = 'none';
    //document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'inline';
    document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'block';
    document.getElementById('btnSolicitarReserva').style.display = 'none';

  //  document.getElementById('txtDireccion').value = ClienteDireccion;

}


function PonDireccionValidadaDeCliente() {
    //alert('okok');
    //document.getElementById('divMapClienteCnt').style.display = 'none';
    document.getElementById('btnVerificaDireccion').value = 'Dirección Verificada';
    document.getElementById('chkDireccionClienteValidada').checked = true;

    document.getElementById('lblCoordenadas').style.display = 'inline';
    document.getElementById('lblLatValue').style.display = 'inline';
    //document.getElementById('lblLatValue').innerHTML = lblLatValueHidden.Value;
    document.getElementById('lblLngValue').style.display = 'inline';
    //document.getElementById('lblLngValue').innerHTML = lblLngValueHidden.Value;
    document.getElementById('lblCP').style.display = 'inline';
    document.getElementById('lblCPValue').style.display = 'inline';
    //document.getElementById('lblCPValue').innerHTML = ClienteCP;
    //document.getElementById('lblCPValueHidden').value = ClienteCP;
    document.getElementById('lblPoblacion').style.display = 'inline';
    document.getElementById('lblPoblacionValue').style.display = 'inline';
    //document.getElementById('lblPoblacionValue').innerHTML = ClientePoblacion;
    //document.getElementById('lblPoblacionValueHidden').value = ClientePoblacion;

    //document.getElementById('btnSolicitarInmediato').style.display = 'inline';
    document.getElementById('btnSolicitarInmediato').style.display = 'none';
    //document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'inline';
    document.getElementById('btnSolicitarInmediatoVerificarDisponibilidad').style.display = 'block';
    document.getElementById('btnSolicitarReserva').style.display = 'none';



    ClienteLatitud = document.getElementById('lblLatValueHidden').value;
    ClienteLongitud = document.getElementById('lblLngValueHidden').value;

    ShowMap('map_canvas', ClienteLatitud, ClienteLongitud);

}




function ValidaDireccion() {



    /* initialize */
    geocoder = new google.maps.Geocoder();
    //var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 15,
        //center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("MapCliente"), myOptions);




    /*var address = document.getElementById("address").value;*/
    var address = document.getElementById("txtDireccion").value;
    if (geocoder) {
        /*geocoder.geocode({ 'address': address }, function(results, status) {*/
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });


                //                    if (results[1]) {
                //                    map.setZoom(11);
                //                    marker = new google.maps.Marker({
                //                        position: latlng, 
                //                        map: map
                //                    });



                //alert(results[0].address_components);


                ClienteLatitud = results[0].geometry.location.lat();
                ClienteLongitud = results[0].geometry.location.lng();


                for (var j = 0; j < results[0].address_components.length; j++) {
                    //var omycountry = mycountry;
                    try {
                        //alert('aqui 1');
                        //alert(results[0].address_components[j].types);
                        var xty = results[0].address_components[j].types;
                        //alert(xty.toString() + ':' + results[0].address_components[j].long_name);
                        //alert(xty);
                        //alert(xty + '=' + results[0].address_components[j].long_name);

                        /*if (xty.indexOf('postal_code') != -1) {*/
                        if (xty.toString() == 'postal_code') {
                            //alert('eyy CP');
                            try {
                                ClienteCP = results[0].address_components[j].long_name;
                                //alert('HAY:' + CP);
                            } catch (ee) { ClienteCP = ''; }
                        };




                        if (xty.toString().indexOf('locality') != -1) {
                            //alert(results[0].address_components[j].long_name.toString());
                            try {
                                ClientePoblacion = results[0].address_components[j].long_name.toString();
                            } catch (ee) { ClientePoblacion = ''; }
                        };

                        if (xty.toString().indexOf('country') != -1) {
                            try {
                                ClientePais = results[0].address_components[j].long_name;
                            } catch (ee) { ClientePais = '' };
                            try {
                                ClientePaisCC = results[0].address_components[j].short_name;
                            } catch (ee) { ClientePaisCC = '' }

                        }



                    } catch (ee) {
                        //alert('hubo algun fallo'); 
                    }
                };





                /* PENDIENTE: COMPROBAR SI POBLACION DEL CLIENTE ESTA DENTRO DEL AREA DE LA EMPRESA QUE TIENE ESTA WEB */



                ClienteDireccion = results[0].formatted_address;
                var infowindow = new google.maps.InfoWindow();
                //infowindow.setContent(results[0].formatted_address + "<br/><span style='cursor:pointer;text-decoration:underline;' onclick='javascript:document.getElementById(\'btnVerificaDireccion\').value=\'Dirección Verificada\';document.getElementById('chkDireccionVlienteValidada').value='checked'; '>Haga click aquí para confirmar su dirección</span>");
                infowindow.setContent(results[0].formatted_address
/*                 + "<br/><span style='cursor:pointer;text-decoration:underline;' onclick=javascript:document.getElementById('divMapClienteCnt').style.display='none';document.getElementById('btnVerificaDireccion').value='Dirección&nbsp;Verificada';document.getElementById('chkDireccionVlienteValidada').checked=true;document.getElementById('lblCoordenadas').style.display='inline';document.getElementById('lblLatValue').style.display='inline';document.getElementById('lblLatValue').innerHTML='" + results[0].geometry.location.lat() + "';document.getElementById('lblLngValue').style.display='inline';document.getElementById('lblLngValue').innerHTML='" + results[0].geometry.location.lng() + "';document.getElementById('lblCP').style.display='inline';document.getElementById('lblCPValue').style.display='inline';document.getElementById('lblCPValue').innerHTML='" + CP + "';document.getElementById('lblPoblacion').style.display='inline';document.getElementById('lblPoblacionValue').style.display='inline';document.getElementById('lblPoblacionValue').innerHTML='" + Poblacion + "';>Haga click aquí para confirmar que es esta la dirección</span>"); */
                 + "<br/><span style='cursor:pointer;text-decoration:underline;' onclick=javascript:PonDireccionValidada();>Haga click aquí para confirmar que es esta la dirección</span>");

                infowindow.open(map, marker);


                ShowMap('map_canvas', ClienteLatitud, ClienteLongitud);

            } else {
                alert("No se ha podido determinar la ubicación de la dirección especificada. Código de error: " + status);
                document.getElementById('txtDireccion').click();

            }
        });
    }






  //  alert('Verifique el mapa');

    

}









