﻿$(document).ready(function() {
    var Method = "Post";
    var Url = "Index.aspx/GetAllUserSalaryLocations";
    var Parms = "";
    var mapsize = 2;
    $("#topNavHome").addClass("selectedtab")
    $.ajax({ type: Method,
        url: Url,
        data: "{" + Parms + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(returnData) { ShowlocationOnMap(returnData.d, mapsize) },
        error: function(xhr, resp, status) { alert(status) }
    });

    function ShowlocationOnMap(lstData, mapsize) {
        var map = new GMap2(document.getElementById('myMap'));
        map.addControl(new GSmallMapControl());
        setCenter(map);

        for (i = 0; i < lstData.length; i++) {
            lat = lstData[i].Latitude
            lng = lstData[i].Longitude
            var address = '';
            if (lstData[i].CityName != '')
            { address = lstData[i].CityName + ' , ' }
            if (lstData[i].CountyName != '')
            { address = address + lstData[i].CountyName + ' , ' }
            if (lstData[i].StateName != '')
            { address = address + lstData[i].StateName + ' , '; }
            if (lstData[i].CountryName != '')
            { address = address + lstData[i].CountryName; }
            loadGoogleMap(lat, lng, address, map)
        }
        if (lstData.length>0 ) {
            $("#UserCount").html(lstData[0].UserSalaryCount);
        }
        else {
            $("#UserCount").html(300);
        }

    }

    function setCenter(map) {
        var point = new GLatLng(25, 12.56738);
        map.setCenter(point, 2);
        //var geocoder = new GClientGeocoder();
        //        geocoder.getLatLng(address,
        //        function(point) {
        //            if (!point) {
        //               
        //                //  alert(address + " not found");
        //            } else {
        //            , 
        //            var point = new GLatLng(41.87194, 12.56738);
        //            map.setCenter(point, 2);
        //            }
        //        });
    }
    function loadGoogleMap(lat, lng, address, map) {
        var point = new GLatLng(lat, lng);
        var marker = createMarker(point, address);
        map.addOverlay(marker);
    }

    function createMarker(point, address) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, 'mouseover', function() {
            marker.openInfoWindowHtml(address);
        });
        return marker;
    }
    //ShowHelp();


});

var b_version = navigator.appVersion;
if (b_version.indexOf("MSIE 6.0") >= 0) {
    document.write('<link href="css/index_ie6.css" rel="stylesheet" type="text/css" media="all">');
}
else {
    document.write('<link href="css/index.css" rel="stylesheet" type="text/css">');

}