﻿///////////////////////////////MAP
var map1;
var map;
var directionsPanel1;
var directions1;

function ShowGoogleDirection(psAddress, psToAddress)
{
    map = new GMap2(document.getElementById("divMap"));
	map.addControl(new GLargeMapControl());
    directionsPanel = document.getElementById("divMapDirection");
    directions = new GDirections(map, directionsPanel);
    directions.load("from: " + psAddress + " to: " + psToAddress);
}


function initializeAddressMapLatLang(psLatitude, psLongtitude, pbLargControl)
{
    var vbLargControl = false
    if(typeof(pbLargControl) != "undefined")
    {
        vbLargControl = pbLargControl
    }
    document.getElementById("tddivMapDirection").style.width = "0"
    document.getElementById("divMap").style.width = "100%"
	
	if (GBrowserIsCompatible()) 
	{
		map1 = new GMap2(document.getElementById("divMap"));
		map1.setCenter(new GLatLng(psLatitude, psLongtitude), 15);
		geocoder = new GClientGeocoder();
		if(pbLargControl)
		{
		    map1.addControl(new GLargeMapControl());
		}
		else
		{
		    map1.addControl(new GSmallMapControl());
		}
        map1.addControl(new GMapTypeControl());
	}

    var latlng = new GLatLng(psLatitude, psLongtitude);
    map1.addOverlay(createMarker(latlng, psLatitude, psLongtitude));
    //createMarker(latlng, psLatitude, psLongtitude)
}

function createMarker(point, piLat, piLang) 
{
    var blueIcon = new GIcon(G_DEFAULT_ICON);
    
    blueIcon.image = "../images/house.png";
    blueIcon.iconAnchor = new GPoint(20 >> 1, 20 >> 1);
    blueIcon.iconSize = new GSize(20, 20);
    blueIcon.shadow = "../images/house-shadow.png";
    blueIcon.shadowSize = new GSize(20, 20);
    var markerOptions = { icon:blueIcon };
    var marker = new GMarker(point, markerOptions);
    marker.icon = blueIcon;
    
    return marker
}



function initializeAddressMap(psAddress, pbLargControl)
{
    var vbLargControl = false
    if(typeof(pbLargControl) != "undefined")
    {
        vbLargControl = pbLargControl
    }
    document.getElementById("tddivMapDirection").style.width = "0"
    document.getElementById("tddivMap").style.width = "100%"
	
	initializeAddress(vbLargControl);
	showAddress(psAddress);
}

var geocoder = null;

function initializeAddress(pbLargControl)
{
    if (GBrowserIsCompatible()) 
    {
        map = new GMap(document.getElementById("divMap"));
        geocoder = new GClientGeocoder();
        map.addControl(new GMapTypeControl());
        map.addControl(new GLargeMapControl());
        //showAddress("2350 Dundas St West Toronto ON M6P4B1");
    }
}

function showAddress(address) 
{ 
    geocoder.getLatLng
    (   address, 
        function(point) 
        {
            if (!point) 
            {
                alert(address + " not found"); 
            } 
            else 
            { 
                map.centerAndZoom( point, 3);
                map.addOverlay( new GMarker( point ) );
            } 
        } 
  ); 
}


function initializeAddressOld(pbLargControl) 
{
	if (GBrowserIsCompatible()) 
	{
		map1 = new GMap2(document.getElementById("divMap"));
		//map1.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
		if(pbLargControl)
		{
		    map1.addControl(new GMapTypeControl());
		    map1.addControl(new GLargeMapControl());
		}
		else
		{
		    map1.addControl(new GSmallMapControl());
		}
		//map1.addControl(new GScaleControl());
		//map1.addControl(new GMapTypeControl());
	}
}

function showAddressOld(address) 
{
	if (geocoder) 
	{
		geocoder.getLatLng(address,
									function(point) 
									{
										if (!point) 
										{
											alert(address + " not found");
										} 
										else 
										{
											map1.setCenter(point, 15);
											//map1.centerAndZoom( point, 6 );
											var marker = new GMarker(point, {draggable: true});
											map1.addOverlay(marker);
											
											//alert(marker.getPoint().lat())
											
                                            GEvent.addListener(marker, "dragend", function() {
                                              //marker.openInfoWindowHtml("Just bouncing along...");
                                              alert(marker.getPoint().lat())
                                            });
											
											//alert(marker.getPoint().lat())
											//marker.openInfoWindowHtml(address);
										}
									}
		);
	}
}



function initializeAddress_2(pbLargControl, psAddress)
{
    var address = psAddress;
    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
    }
    var latlng
    var myOptions
    map = new google.maps.Map(document.getElementById("divMap"), myOptions);
    map.addControl(new GSmallMapControl());

    if (geocoder) 
    {
        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
                        });
                    } 
                    else 
                    {
                        alert("Geocode was not successful for the following reason: " + status);
                    }
                }
                );
    }
}



function initializeAddress_123(pbLargControl, psAddress) 
{
        var address = psAddress;
        
        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("divMap"), myOptions);
        /*if (geocoder) 
        {
            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
                            });
                        } 
                        else 
                        {
                            alert("Geocode was not successful for the following reason: " + status);
                        }
                    }
                    );
        }
        */
}

function initializeAddressMapDiv(psAddress, psDivId)
{
	initializeAddressDiv(psDivId);
	showAddressDiv(psAddress);
}

function initializeAddressDiv(psDivId) 
{
	if (GBrowserIsCompatible()) 
	{
		map1 = new GMap2(document.getElementById(psDivId));
		//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
		//map1.addControl(new GLargeMapControl());
		map1.addControl(new GSmallMapControl());
		//map1.addControl(new GScaleControl());
		//map1.addControl(new GMapTypeControl());
	}
}

function showAddressDiv(address) 
{
	if (geocoder) 
	{
		    geocoder.getLatLng(address,
									    function(point) 
									    {
										    if (!point) 
										    {
											    //alert(address + " not found");
										    } 
										    else 
										    {
											    map1.setCenter(point, 15);
											    //map1.centerAndZoom( point, 6 );
											    var marker = new GMarker(point);
											    map1.addOverlay(marker);
											    //marker.openInfoWindowHtml(address);
										    }
									    }
		    );
	}
}



var objMapIFrame
function GetGoogleDirection_Website_LayOut()
{
	if(document.getElementById("divGetDirection").childNodes.length > 0)
	{
	    document.getElementById("divGetDirection").removeChild(objMapIFrame);
	}
    
	objMapIFrame = document.createElement("IFRAME");
	objMapIFrame.src = "http://localhost/autodealers/Root_WebForms/Google_Map.htm?qsFromAddress=" + document.getElementById("txtMapAddress").value + "&qsToAddress=" + document.getElementById("txtGoogleGetDirectionStreet").value + "&qsGetDirection=Y&qsWidth=" + document.getElementById("txtMapWidth").value + "&qsHeight=" + document.getElementById("txtMapHeight").value;
	objMapIFrame.style.width = "875";
	objMapIFrame.style.height = "600";
	objMapIFrame.scrolling = "no";
	objMapIFrame.frameBorder = "2";

	if(document.getElementById("divGetDirection").childNodes.length == 0)
	{
		document.getElementById("divGetDirection").appendChild(objMapIFrame)
	}
	YAHOO.example.container.panel4.show();
	
}

function GetGoogleDirection_Website()
{
	try
	{
        ViewProcessing()
        voResponse = clWebsiteSettings.GetCompanyWebsiteModules_Dynamic("ContactUs_GetDirection.ascx")
		if(IsAjaxError(voResponse))
		{
            window.location.href = "Index.aspx?qsMenuId=" + voResponse.value + "&qsFromAddress=" + document.getElementById("txtGoogleGetDirectionStreet").value + "&qsToAddress=" + document.getElementById("txtMapAddress").value + "&qsGetDirection=Y&qsWidth=400&qsHeight=400";
		}
		StopProcessing()
	}
	catch(err)
	{
		alert("GetGoogleDirection_Website : " + err.message)
	}
    
}

//////////////////////////////END MAP

