﻿var map;
var localSearch = new GlocalSearch();

var icon = new GIcon();
icon.image = "http://www.google.com/mapfiles/marker.png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);


function usePointFromPostcode(postcode, callbackFunction) {

	if ( postcode == "" )
	{
	   alert("Enter Postcode!");
	   return false;
	}
	
	localSearch.setSearchCompleteCallback(null, 
		function() {
			
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				callbackFunction(point);
			}else{
				alert("Postcode not found!");
			}
		});	
		
	localSearch.execute(postcode + ", UK");
}

function SetDestLatLong(point)
{

   
   document.getElementById("hid_dest_latitude").value = point.y;
   document.getElementById("hid_dest_longitude").value = point.x;
   document.getElementById("hid_dest_pc").value = document.getElementById('txt_postcode').value;
	
	var pointA = new GLatLng(document.getElementById("hid_rest_latitude").value, document.getElementById("hid_rest_longitude").value);
   var pointB = new GLatLng(document.getElementById("hid_dest_latitude").value, document.getElementById("hid_dest_longitude").value );
  	var arrLocation = new Array(2);
   arrLocation[0] = pointA;
   arrLocation[1] = pointB; 
   gdir.clear(); 
   
   gdir.loadFromWaypoints(arrLocation); 

}

function onGDirectionsLoad (){

   document.getElementById("hid_distance_meters").value = gdir.getDistance().meters;
   __doPostBack("but_hid_calculate","")
}


