// Open the info box for the specified marker.

function popup( i ) {

// alert("popup("+i+")");

    if ((markers[i]) && (markers[i].point)) {

       markers[i].openInfoWindowHtml( markers[i].infoHtml +

        '<div id="directions' + i + '">' + 

        'Directions: <a href="javascript:createToDirections(' + 

	i + ');">To here</a> - <a href="javascript:createFromDirections(' + i + ');">From here</a>' + 

    	'</div>');

    } else { alert("bad marker, markers["+i+")"); }

}



function makePopupCaller( i )

    {

    	return function() { popup( i ); };

    }



function createToDirections( i ) {

    markers[i].openInfoWindowHtml( markers[i].infoHtml + 

    	'<div id="directions' + i + '">' + 

    		'<form onsubmit="return false;">' +

    		'Directions: <b>To here</b> - <a href="javascript:createFromDirections(' + i + ');">From here</a><br />' + 

			'Start address:<br />' + 

			'<input type="text" style="width:200px" id="toAddress' + i + '"><br />' + 

			'<input type="submit" value="Get Directions" onclick="launchToDirections(' + i + ');">' +

			'</form>' +

    	'</div>'

    ); 

 

}

function createFromDirections( i ) {



    markers[i].openInfoWindowHtml( markers[i].infoHtml + 

    	'<div id="directions' + i + '">' + 

    		'<form onsubmit="return false;">' +

			'Directions: <a href="javascript:createToDirections(' + i + ');">To here</a> - <b>From here</b><br />' + 

			'End address:<br />' + 

			'<input type="text" style="width:200px" id="fromAddress' + i + '"><br />' + 

			'<input type="submit" value="Get Directions" onclick="launchFromDirections(' + i + ');">' + 

			'</form>' +

		'</div>'

    );

}

function launchFromDirections( i ) {

	var fromAddress = document.getElementById('fromAddress' + i);

	

	window.open('http://maps.google.com/maps?saddr=' + encodeURI(markers[i].address) + '&daddr=' + encodeURI(fromAddress.value) + '&hl=en','directions','');

}

function launchToDirections( i ) {

	var toAddress = document.getElementById('toAddress' + i);

	

	window.open('http://maps.google.com/maps?saddr=' + encodeURI(toAddress.value) + '&daddr=' + encodeURI(markers[i].address) + '&hl=en','directions','');

}



// Concatenate the values in an element list.

function concatValues( elements )

	{

		var values = '';

		for ( var i = 0; i < elements.length; ++i )

			{

				if ( values != '' ) values += ' ';

				values += elements[i].firstChild.nodeValue;

			}

		return values;

    }