

function load() 
{
  // START UP THE GOOGLE MAPERATOR
  if (window.GBrowserIsCompatible && GBrowserIsCompatible() && document.getElementById("google_map")) 
  {
	var map = new GMap2(document.getElementById("google_map"));
	map.setCenter(new GLatLng(41.875447, -88.067295), 15);

	//add controls
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());

	// Create our "tiny" marker icon
	var dragonIcon = new GIcon(G_DEFAULT_ICON);
	dragonIcon.image = "http://mikelightner.org/projects/kkirtland/themes/default/img/icons/google_dragon.png";
	dragonIcon.iconSize = new GSize(35, 41);
	dragonIcon.iconAnchor = new GPoint(25, 40);
	dragonIcon.infoWindowAnchor = new GPoint(30, 12);

	// Set up our GMarkerOptions object
	markerOptions = { icon:dragonIcon };

	//add marker
	var point = new GLatLng(41.875447, -88.067295);
	map.addOverlay(new GMarker(point,markerOptions));

	//display window
	map.addOverlay(createMarker(point));
  }

  initialize();

  if (document.getElementById('directions-adv'))
	  document.getElementById('directions-adv').style.display = 'none';
}

// THIS IS BAD, REMOVE ASAP

function initialize() {
  if (window.GBrowserIsCompatible && GBrowserIsCompatible()) {      
	map = new GMap2(document.getElementById("map_canvas"));
	gdir = new GDirections(map, document.getElementById("directions"));
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);

	//setDirections("", "", "en_US");
	map.setCenter(new GLatLng(41.875447, -88.067295), 15);

//add controls
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

	
  }
}

function unload()
{
	if (window.gUnload)
	{
		gUnload();
	}
}

function createMarker(point) 
{
	var marker = new GMarker(point,markerOptions);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml("<span style=\'font-size:1em\'>Kelly A. Kirtland, D.D.S.<br />493 Duane Street<br />Glen Ellyn, Illinois 60137<br />(630) 469-7696</span>");
	});
	return marker;
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
			{ "locale": locale });
}

function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	
   else alert("An unknown error occurred.");
   
}

function onGDirectionsLoad(){ 
  // Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...
}

function switchdirections(type)
{

	if (type == "simple")
	{
		document.getElementById("directions-adv").style.display = "none";
		document.getElementById("directions-simple").style.display = "block";
	}

	if (type == "adv")
	{
		document.getElementById("directions-simple").style.display = "none";
		document.getElementById("directions-adv").style.display = "block";
	}


}


function formGet(formname)
{
	document.location.href="https://kirtlanddds.com/formcenter/pdf/kirtland_"+formname+".pdf";
}

function formFile(formid)
{
	var h = self.innerHeight;

	if(!h)
	{
		h = document.documentElement.clientHeight-document.body.clientHeight;
	}

	var wloc = "https://kirtlanddds.com/?fileform&id="+formid+"&session=";

	window.open(wloc, "currentform","width=790,height="+h+",directories=no,titlebar=no,status=no,toolbar=no,menubar=no,location=no,address=no,resizable=no,scrollbars=yes");    
}

function printform()
{

	if (!document.getElementById('formverify').checked)
	{
		if (confirm("You have not confirmed the form has been filled out completely.  Continue printing?"))
		{
			window.print();
		}

	}
	else
	{
		window.print();
	}
}

function submitform(f)
{
	if (document.getElementById('formverify') && !document.getElementById('formverify').checked)
	{
		alert("Please make sure the form is filled out completely, then check the box below.");
		return false;
	}
	else if (document.getElementById('formemail') && document.getElementById('formemail').value == '' && !confirm("You will not be receiving email confirmation.  Is that ok?"))
	{
		document.getElementById('formsubmit').disabled = 'disabled';
		return false;
	}
	else
	{
		return true;
	}
}

function closeform()
{
	//if (confirm("Thank you for your submission.  Close this window?"))
	//{
		window.close();
		return true;
	//}


}