function createMarker(name, icon, point, index) { 
 var markerIcon = new GIcon(G_DEFAULT_ICON); 
  switch(icon){
	 case "walking":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/trail.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/trail.shadow.png";
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 case "bike":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/motorcycling.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/motorcycling.shadow.png";
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 case "rail":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/rail.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/rail.shadow.png";
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 case "bus":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/bus.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/bus.shadow.png";
		markerIcon.iconSize = new GSize(28, 28); 
		markerIcon.shadowSize = new GSize(55, 28); 
		markerIcon.iconAnchor = new GPoint(8, 28); 
		break;
	 case "green":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/grn-pushpin.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/pushpin_shadow.png"; 
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 case "venue":
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/grn-pushpin.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/pushpin_shadow.png"; 
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 default:
		markerIcon.image = "http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png"; 
		markerIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/pushpin_shadow.png"; 
		markerIcon.iconSize = new GSize(32, 32); 
		markerIcon.shadowSize = new GSize(59, 32); 
		markerIcon.iconAnchor = new GPoint(12, 32); 
		break;
	 }
 
  // Set up our GMarkerOptions object 
  markerOptions = { icon:markerIcon }; 
  var name = new GMarker(point, markerOptions); 
 
  if (index){
	GEvent.addListener(name, "click", function() { 
		name.openInfoWindowHtml(index); 
		}); 
	}
  return name; 
}

/*var localSearch = new GlocalSearch();

function handleClicks(marker, point){
	lat = point.lat();
	lng = point.lng();
	reverse(point);
	//add_steps(point.lat() + ", " + point.lng());
}


function ispostcode(postcode){
var re = new RegExp('^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$');
if (postcode.match(re)) {
return true;
} else {
return false;
}
}

function usePointFromPostcode(postcode, callbackFunction) {
	
	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 checkpostcode(postcode) {
	if (ispostcode(postcode) == true){
	localSearch.setSearchCompleteCallback(null, 
		function() {
			if (localSearch.results[0])
			{
				document.getElementById('lat').value = localSearch.results[0].lat;
				document.getElementById('lng').value = localSearch.results[0].lng;
				document.getElementById('submit').disabled=false;
			}else{
				alert('Postcode not found!');
			}
		});	
	
	localSearch.execute(postcode + ", UK");
	} else {
	alert('Postcode incorrect!');
	}
}

function search_place(name){
	if (name != ""){
		localSearch.setSearchCompleteCallback(null,
			function() {
				if (localSearch.results[0])
					{
						lat = localSearch.results[0].lat.substr(0,7);
						lng = localSearch.results[0].lng.substr(0,7);
						var point = new GLatLng(lat,lng);
						//placeMarkerAtPoint(point);
						setCenterToPoint(point);
						reverse(point);
					} else {
						info.innerHTML = "<p class=error>Unable to find place, please click a road!</p>";
					}
				}
			);
			
		localSearch.execute(name + ", Cheshire,  UK");
		}
}

function search_event(name){
if (ispostcode(name) == true){
		localSearch.setSearchCompleteCallback(null,
			function() {
				if (localSearch.results[0])
					{
						lat = localSearch.results[0].lat;
						lng = localSearch.results[0].lng;
						var point = new GLatLng(lat,lng);
						//placeMarkerAtPoint(point);
						setCenterToPoint(point);
						reverse(point);
					} else {
						info.innerHTML = "<p class=error>Unable to find location, please click nearest road!</p>";
					}
				}
			);
			
		localSearch.execute(name + ",  UK");
		} else {
		info.innerHTML = "<p class=error>Postcode Incorrect, Please use full postcode (WA11 1EX) to search!</p>";
		}
}

function search_postcode_latlng(name){
if (ispostcode(name) == true){
		localSearch.setSearchCompleteCallback(null,
			function() {
				if (localSearch.results[0])
					{
						lat = localSearch.results[0].lat;
						lng = localSearch.results[0].lng;
						var point = new GLatLng(lat,lng);
						//placeMarkerAtPoint(point);
						setCenterToPoint(point);
						placeMarkerAtPoint(point);
						document.getElementById("lat").value = point.lat();
						document.getElementById("lng").value = point.lng();
					} else {
						info.innerHTML = "<p class=error>Unable to find location, please click nearest road!</p>";
					}
				}
			);
			
		localSearch.execute(name + ",  UK");
		} else {
		info.innerHTML = "<p class=error>Postcode Incorrect, Please use full postcode (WA11 1EX) to search!</p>";
		}
}


function showPointLatLng(point)
{
	alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addUnLoadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
	  window.onunload = func;
	} else {
	  window.onunload = function() {
	    oldonunload();
	    func();
	  }
	}
}



