//10/2009 - support for elevation page

function validate() {
 var loc = getEle("loc");
 var ret = false;
 if(loc) {
  if(loc.value == "") { ret = false; }
  else if(!loc.value) { ret = false; }
  else if(loc.value.length < 5 || loc.value.length > 80) { ret = false }
  else if(loc.value.match(/http/i)){ret = false}
  else if(loc.value.match(/\|<>`~:!@#\$%^\*\(\)\+=}{\[\]/)) { ret = false }
  else { ret= true}
 }
 
 if(!ret) { alert("Please enter a valid location."); }     
 return ret;
}

function getEle(id) { return document.getElementById(id); }

function load(lat,long) {

if(!lat) { lat = 0 }
if(!long) { long = 0 }


if (!GBrowserIsCompatible()) {
alert("Either your browswer can't handle Google Maps, or my google API key is wrong...");
return;
}

var mapOptions = {
    googleBarOptions : {      style : "new",
      adsOptions: {        client: "pub-0412558566882978",
        channel: "veloroutes.org_elevationmap",
        adsafe: "high",
        language: "en"      }  } 
}

var publisher_id = 'pub-0412558566882978';
var adsManagerOptions = {  maxAdsOnMap : 2,  style: 'adunit' };  
// The channel field is optional - replace this field with a channel number   
// for Google AdSense tracking  channel: 'your_channel_id'  

//draggableCursor: 'crosshair', 
//draggingCursor: 'crosshair'

	var map = new GMap2(document.getElementById("map"),mapOptions);
	this.map = map;

adsManager = new GAdsManager(map, publisher_id, adsManagerOptions);
adsManager.enable();


	map.enableGoogleBar(); //ads!


	map.addMapType(G_PHYSICAL_MAP);
	map.setMapType(G_PHYSICAL_MAP);

	if(map != null) {
		
		//show lat & long on load
		/*GEvent.addListener(map, "load", function() {
			showCrossHair();
		});*/

		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		map.addControl(new GScaleControl());
				
		// create crosshair icon
		this.crosshairicon = new GIcon();
		crosshairicon.image = "/images/crosshair1.png";
		crosshairicon.shadow = "";
		crosshairicon.iconSize = new GSize(15, 15);
		crosshairicon.shadowSize = new GSize(0, 0);
		crosshairicon.iconAnchor = new GPoint(7, 7);
		crosshairicon.infoWindowAnchor = new GPoint(7, 7);
		
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();

		
		var z=1;
		if(lat) { z=10 } //zoom in for city	
		moveMapTo(map, lat, long, z);	
		}

		

	if(map && lat && long) {
		//alert(lat + ","+long);
		var ll = new GLatLng(lat,long);
		map.setCenter(ll,z);
		var ovr = new GMarker({latlng:ll});
		ovr.setLatLng( ll ); //why needed?!
		map.addOverlay(ovr);
	}

} //end method
	
function moveMapTo(map, lat, lng,zoom) {
	map.setCenter(new GLatLng(lat, lng), zoom);
		window.setTimeout(function() {
			map.panTo(new GLatLng(lat, lng));
	}, 100);
}

//show/hide the crosshair in center of map
function showCrossHair() {
	if(this.recording) { return; }
	var centerpoint = this.map.getCenter();
		//remove old icon
		if (this.centericon) {
			map.removeOverlay(centericon)
		}
		this.centericon = new GMarker(centerpoint, this.crosshairicon);
		map.addOverlay(centericon);
}
