<%@ page language="C#" autoeventwireup="true" inherits="Forms_EmployeeLocation, App_Web_tnfq0fem" %>

<%@ Register Src="~/UserControls/New_Footer.ascx" TagName="Footer" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Employee Location</title>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <%--<script language="javascript" type="text/javascript" src="../js/Map_Google1.js"></script>--%>
    <script src="../js/wow.min.js"></script>
</head>
<body onload="loadMap();">
    <form id="form1" runat="server">
        <div style="width: 400px; height: 25px;">
            <center>
                <asp:ImageButton ID="btnClose" runat="server" ImageUrl="~/images/btn-save.jpg" />
            </center>
        </div>
        <div id="divEmp" style="width: 400px; height: 350px;">
        </div>
        <asp:Panel ID="pnlInfoWindow" runat="server" Style="display: none; height: 60%; width: 60%;">
            <div id="message" style="position: absolute; top: 300px; left: 200px; height: 60%; width: 60%; z-index: 100;">
                &nbsp;
            </div>
        </asp:Panel>
        <asp:HiddenField ID="hdnLatLong" runat="server" />
        <script language="javascript" type="text/javascript">
            var map = null;
            var marker;
            var mapcoord = null
            var geo;
            function loadMap() {
                GUnload();
                map = new GMap2(document.getElementById('divEmp'));
                map.addControl(new GSmallMapControl());
                map.addControl(new GMapTypeControl());
                //map.addControl(new GOverviewMapControl());       
                map.setCenter(new GLatLng(23.805450, 78.486328), 4);
                map.enableScrollWheelZoom();

                GEvent.addListener(map, 'dblclick', function () {
                    map.removeOverlay(marker);

                });

                eventonclick = GEvent.addListener(map, 'click', leftclick);
            }

            function leftclick(overlay, latlng) {
                if (latlng) {
                    if (latlng != null) {
                        map.clearOverlays();
                        mapcoord = latlng;
                        marker = new GMarker(mapcoord);
                        //map.setCenter(mapcoord, 14);
                        map.addOverlay(marker);
                        lat = marker.getLatLng().toUrlValue();
                        var latlng = String(lat).split(',');
                        document.getElementById('hdnLatLong').value = latlng[0] + "*" + latlng[1];
                        var geoFinder = new GClientGeocoder();
                        geoFinder.getLocations(lat, showAddress_Latlng);
                    }
                }

            }
            function showAddress_Latlng(response) {
                if (document.getElementById('ddlType') != null) {
                    showControls(document.getElementById('ddlType').selectedIndex);
                }
                //map.removeOverlay(marker);
                //            var icon = new GIcon(G_DEFAULT_ICON);            
                //            
                //            icon = new GIcon(icon, '../images/poi_viewer_house.gif');
                //            icon.iconSize = new GSize(32, 32);

                if (!response || response.Status.code != 200) {
                    alert("Unable to find the address. Please verify your location on the map.");
                } else {
                    if (response != null) {
                        place = response.Placemark[0];
                        point = new GLatLng(place.Point.coordinates[1],
                                place.Point.coordinates[0]);
                        //                    marker = new GMarker(point, { draggable: true, icon: icon });
                        //                    map.setCenter(point, 14);
                        //                    map.addOverlay(marker);

                        //                    GEvent.addListener(marker, "mouseover", function() {
                        //                        marker.openInfoWindowHtml(
                        //            '<table cellpadding=5 cellspacing=2><tr><td colspan=3><b><u>Location Details</u></b></td><tr><td><b>Original Coordiantes</b></td><td>:</td><td>'
                        //            + response.name.split(",")[0] + " , " + response.name.split(",")[1]
                        //            + '</td></tr><tr><td><b>Adjusted Coordinates</b></td><td>:</td><td>'
                        //            + place.Point.coordinates[1] + " , " + place.Point.coordinates[0]
                        //            + '</td></tr><tr><td><b>Address</b></td><td>:</td><td>' + place.address + '</td></tr></table>');
                        //                    });

                        GEvent.addListener(marker, "click", function () { marker.closeInfoWindow(marker); });
                    }
                    document.getElementById('hdnLatLong').value = place.address + "*" + document.getElementById('hdnLatLong').value;
                }
            }

            if (window.opener.document.getElementById('txtAddress') != null) {
                if (window.opener.document.getElementById('txtAddress').value != '') {
                    search = window.opener.document.getElementById('txtAddress').value;
                    geo = new GClientGeocoder();
                    geo.getLocations(search, function (result) {
                        //map.clearOverlays();

                        if (result.Status.code == G_GEO_SUCCESS) {
                            // ===== If there was more than one result, "ask did you mean" on them all =====
                            if (result.Placemark.length > 1) {
                                document.getElementById("message").innerHTML = "Did you mean:";
                                // Loop through the results
                                for (var i = 0; i < result.Placemark.length; i++) {
                                    var p = result.Placemark[i].Point.coordinates;
                                    document.getElementById("message").innerHTML += "<br>" + (i + 1) + ": <a href='#' onclick='place(" + p[1] + "," + p[0] + ")'>" + result.Placemark[i].address + "<\/a>";
                                }
                                //                            $find('ModalPopupExtender1').show();
                                document.getElementById("pnlInfoWindow").style.display = "block";
                            }
                                // ===== If there was a single marker =====
                            else {
                                document.getElementById("message").innerHTML = "";
                                var p = result.Placemark[0].Point.coordinates;

                                if (document.getElementById('hdnLatLong').value != null) {
                                    document.getElementById('hdnLatLong').value = p[1] + ',' + p[0];
                                }
                                if (result.Placemark[0].AddressDetails.Accuracy < 6) {
                                    alert('Unable to find the address. Please verify the location');
                                }
                                else {
                                    Findplace(p[1], p[0], '', 0, 0);
                                }
                            }
                        }
                            // ====== Decode the error status ======
                        else {
                            var reason = "Code " + result.Status.code;
                            //if (reasons[result.Status.code]) { reason = reasons[result.Status.code] }
                            //alert('Could not find "' + search + '" ' + reason);
                            loadMap();
                            alert('Could not find "' + search + '" ');
                        }
                    }
            );
                }
                //eventonclick = GEvent.addListener(map, 'click', leftclick);
            }
        </script>
    </form>
    <uc2:Footer ID="ucFooter" runat="server" />



    <script type="text/javascript">

        function closePopup() {
            var latlg = String(document.getElementById('hdnLatLong').value).split('*');
            window.opener.document.getElementById('hdnAddressStatus').value = document.getElementById('hdnLatLong').value;
            window.opener.document.getElementById('txtLatitude').value = latlg[1];
            window.opener.document.getElementById('txtlongitude').value = latlg[2];
            if (window.opener.document.getElementById('txtAddress') != null) {
                if (latlg.length == 3) {
                    window.opener.document.getElementById('txtAddress').value = '';
                    window.opener.document.getElementById('txtAddress').value = latlg[0];
                }
            }
            window.close();
            return false;
        }
    </script>

</body>
</html>
