﻿/********************/

/* Create Base Icon */

/********************/


// create a base icon for all of our markers that specifies the shadow, icon dimensions etc.

var baseIcon = new GIcon();

baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";

baseIcon.iconSize = new GSize(20, 34);

baseIcon.shadowSize = new GSize(37, 34);

baseIcon.iconAnchor = new GPoint(9, 34);

baseIcon.infoWindowAnchor = new GPoint(9, 2);

baseIcon.infoShadowAnchor = new GPoint(18, 25);
var map;




function initialize()
        {
            if(GBrowserIsCompatible())
            {
               
                map = new GMap2(document.getElementById("map_canvas"));
                insertMapControls();
              
            }
        }


/***********************/

/* Insert Map Controls */

/***********************/



function insertMapControls()

{

	var postcodelat = document.getElementById('hidPostcodeLatDeg').value;
	var postcodelong = document.getElementById('hidPostcodeLongDeg').value;
	var zoomlevel = document.getElementById('hidZoomlevel').value;
	
	var lat = parseFloat(postcodelat);
	var lon = parseFloat(postcodelong);
	var zoom = parseFloat(zoomlevel);
	

	map.addControl(new GSmallMapControl());



	// control that displays map scale

	map.addControl(new GScaleControl());



	// control with buttons to switch between map types

	map.addControl(new GMapTypeControl());


	// center map on a point and set zoom level

	map.setCenter(new GLatLng(lat,lon),zoom);
	 //map.setCenter(new GLatLng(51.5, -0.1), 10);




	// create a base icon for all of our markers that specifies the shadow, icon dimensions etc.

	var icon = new GIcon();

	icon.shadow = "http://www.google.com/mapfiles/arrowshadow.png";

	icon.iconSize = new GSize(39, 34);

	icon.shadowSize = new GSize(39, 34);

	icon.iconAnchor = new GPoint(19, 34);

	icon.image = "http://www.google.com/mapfiles/arrow.png";



	map.addOverlay(new GMarker(new GLatLng(lat, lon), icon));
	

}



/********************/

/* Show Distributor */

/********************/

 function showDistributor(latitude, longitude, name, street, town, postcode, index)

{

	// center map over given lat/lon values
	
   

	map.setCenter(new GLatLng(latitude, longitude), map.getZoom());



	// create a lettered icon using base icon class

	// var letter = String.fromCharCode("A".charCodeAt(0) + index);

	var icon = new GIcon(baseIcon);

	//icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

	icon.image = "http://www.google.com/mapfiles/marker.png";



	// create marker u

	var marker = new GMarker(new GLatLng(latitude, longitude), icon);



	map.addOverlay(marker);



	var html = "<b>" + name + "</b><br>" + street + '<br>' + town + '<br /> ' + postcode;

	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });


}


/********************/

/* View Distributor */

/********************/

function ViewDistributor(latitude, longitude, name, address1,address2,address3, town,county, postcode,phone,fax, index) {

    // center map over given lat/lon values



    map.setCenter(new GLatLng(latitude, longitude), map.getZoom());



    // create a lettered icon using base icon class

    // var letter = String.fromCharCode("A".charCodeAt(0) + index);

    var icon = new GIcon(baseIcon);

    //icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

    icon.image = "http://www.google.com/mapfiles/marker.png";



    // create marker u

    var marker = new GMarker(new GLatLng(latitude, longitude), icon);



    map.addOverlay(marker);

    var html = "<b>" + name + "</b><br>" + address1 + ' ' + address2 + '<br>';
    if (address3 == '') {
        html = html + address3 + '<br />';
    }
    html = html + town + '<br />' + county + '<br />' + postcode + '<br />' + 'Tel:' + phone + ' Fax:' + fax;
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });


}







//]]>


