//<![CDATA[
// JavaScript Document
	var map = '';
	var mapLatLong = '';
	var toAddress = '5552 South Apache Road, Las Vegas, NV 89148';
	var directionsPanel = '';
	var directions = '';
    var ghtml = '<div class="vcard">'
               + '<span class="adr">'
               + '<span class="fn org">Speech Therapy Center of Excellence</span><br />'
               + '<span class="street-address">5552 South Fort Apache Rd., Ste. 120</span><br />'
               + '<span class="locality">Las Vegas</span>, '
               + '<abbr class="region" title="Nevada">NV</abbr> '
               + '<span class="postal-code">89148</span>'
               + '</span>'
			   + '<span class="tel">'
    		   + '<span class="type">Voice</span>:'
               + '<abbr title="702 641 8255"><span class="value">702 641 8255</span>702 641 TALK</abbr>'
			   + '</span>'
			   + '<span class="tel">'
    		   + '<span class="type">Fax</span>:'
               + '<abbr title="702 399 8255"><span class="value">702 399 8255</span>702 399 TALK</abbr>'
			   + '</span>'
			   + '</div>'
			   + '<a href="../speech-therapy-directions.html" title="Click to get directions for Speech Terapy Center of excellence" onclick="getDirections(); return false;" id="adrclick">Get Directions</a>';
			   

    function setDirections(fromAddress, toAddress, locale) {
      directions.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
	  
    }
	
	function getDirections(obj)
	{
	    var formAddress = document.getElementById('drvaddr');
		var addressText = '';
		if (formAddress)
		{
			if (formAddress.value.length > 0) {
				setDirections(formAddress.value, toAddress, 'en_US');
			}
			else {
				alert('Please provide starting address');
				return false;
			}
		}
		return false;
	}
	
	function onGDirectionsLoad() {
        map.setCenter(mapLatLong, 15);			   
	    map.openInfoWindowHtml(map.getCenter(), ghtml);
	}
	
	function handleErrors() {
		if (directions && directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
		   	alert('Address not found, please check your source address.');
		}
		else  {
			if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {
			alert('Address cannot be processed, please call us at (702) 641 8255 and we will provide you with directions.');
			}
			else {
			alert('Unknown error has occured, please call us at (702) 641 8255 and we will provide you with directions.');			
			}
		}
	}

    function addAddressToMap(response) {
      	if (!response || response.Status.code != 200) {
        	alert("Sorry, we were unable to geocode that address");
      	} 
		else {
        	var place = response.Placemark[0];
        	var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		
			map = new GMap2(document.getElementById("gmap"));
			mapLatLong = point;
			
			map.setCenter(mapLatLong, 15);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());

			directionsPanel = document.getElementById("gdrv");
			directions = new GDirections(map, directionsPanel);
			
			GEvent.addListener(directions, "load", onGDirectionsLoad);
			GEvent.addListener(directions, "error", handleErrors);
			map.openInfoWindowHtml(map.getCenter(), ghtml);
      }
    }

    function gload() {
	  var formdir = document.getElementById('drvdir');
	  
	  if (formdir) {
	  	formdir.onsubmit = getDirections;
	  }
	  
      if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		geocoder.getLocations(toAddress, addAddressToMap);
      }
    }	
	//]]>
