// on load add error boxes and validation checks to every form element
addEvent(window,"load", load);
// add an event to the current element
function addEvent(el,evt,fxn) {
	// cross browser handling
	if(el.addEventListener) el.addEventListener(evt, fxn, false);
	else if(el.attachEvent) el.attachEvent("on" + evt, fxn);
}

function load() {
	if (GBrowserIsCompatible()) {
		// get latitude and longitude to set the point on the map
		var point = new GLatLng(document.getElementById("floristLat").value, document.getElementById("floristLong").value);

		// setup new base icon
		var icon = baseIcon();
		// specify the icons image
		icon.image = "http://www.google.com/mapfiles/markerA.png";

		// Format marker
		var florist = document.getElementById("floristName").value;
		var streetAddress = document.getElementById("floristAddr").value;
		var city = document.getElementById("floristCity").value;
		var state = document.getElementById("floristState").value;
		var zip = document.getElementById("floristZip").value;
		var markerDescription = florist + '<br />' + streetAddress + '<br />' + city + ', ' + state + ' ' + zip;

		var floristLoc = new mapLocation(point, icon, markerDescription);

		gmap = new GMap2(document.getElementById("map"));

		// Add scrolling and zoom controls
		gmap.addControl(new GSmallMapControl());

		// center map
		gmap.setCenter(point, 15);


		var marker = new GMarker(point,icon);
		// add on click handler to reopen bubble if it is closed
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(markerDescription);
		});
		// Add the marker to map
		gmap.addOverlay(marker);
		marker.openInfoWindowHtml(markerDescription);
	}
}

function mapLocation(point, icon, info) {
	this.point = point;
	this.icon = icon;
	this.info = info;
}

function baseIcon() {
	// 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);
	return baseIcon;
}

function setCenter (lat, long) {
	var point = new GLatLng(lat, long);
	gmap.setCenter(point, 15);
	
}
