/*
 * 
 * Created August 16, 2005
 * 
 * This file provides functions for displaying information in 
 * in the Google Maps Info window.  These functions can be
 * called from the ctMarker object.
 *
 * USAGE:
 *   ctMarker.openInfoWindowHtml(getHTML(ct_info));
 *
 */
var start_here=true; //See whether you want directions "to" or "from" the location that is entered

/*
 * Returns the HTML that can be displayed in a
 * Google Maps info window.
 *
 * @param info     array of information that is set
 *				   when the overlay is first requested 
 *				   from the database
 *
 */
function getHTML(info)
{
		//alert(info);
 		var prop_address = "<div id='the_address'><b>" + info[1] + "</b><br>" + info[2];
		var address = info[2] + ", " + info[3];
		prop_address += "<BR>" + info[3];

		var frm = '</div><form name="dirs"><div id="my_address" style="display:none"><input type="text" name="search_address" value="" style="width:12em">';
		frm = frm + '<input type=button onclick="getDirections(\'' + address + '\');" value="Get Directions"/></div></form>';
		var directions='<div style="font-size: small; margin-top: 0.4em">Directions:'+" <a href=\"javascript:showDirectionForm(true)\">To here</a> - "+"<a href=\"javascript:showDirectionForm(false)\">From here</a></div>";

		var html = prop_address+frm+directions;		
 
 		return html;
}

/*
 * Shows the directions form and hides the address
 * information
 *
 * @param is_tohere     boolean value that shows whether
 *						the user wants directions "from"
 *						or "to" this location.
 *
 */
function showDirectionForm(is_tohere)
{
	directions = document.getElementById("my_address").style;
	directions.display = '';
	
	directions = document.getElementById("the_address").style;
	directions.display = 'none';
	
	start_here = is_tohere;
}

/*
 * Get an address from the user, then
 * open a new window and perform a directions search
 * directly through Google Maps website.
 *
 * @param the_address   the address of the selected marker
 *						on the map.
 *
 */
function getDirections(the_address)
{
	searchAddress = document.forms["dirs"].search_address.value;
	if(start_here)
	{
		url = "http://maps.google.com/maps?saddr=" + searchAddress + "&daddr=" + the_address + "&hl=en";
	}
	else
	{
		url = "http://maps.google.com/maps?saddr=" + the_address + "&daddr=" + searchAddress + "&hl=en";
	
	}
	
	window.open(url);
}



