/* 
map.js

Software design and development by:
	Terence M. Bandoian
	P.O. Box 4074
	Austin, TX 78765
	http://www.tmbsw.com
	terence@tmbsw.com

Copyright (c) 2010 Terence M. Bandoian. All rights reserved.
*/

function openMapWindow( a ) { if (( typeof( ListingAgentMapWindow ) == 'undefined' ) || ( ListingAgentMapWindow.closed )) { ListingAgentMapWindow = window.open( '', 'ListingAgentMapWindow', 'directories=no' + ',location=yes' + ',menubar=yes' + ',toolbar=yes' + ',personalbar=no' + ',status=yes' + ',scrollbars=yes' + ',width=720' + ',height=800' + ',resizable=yes' + ',left=0' + ',top=0' ); } ListingAgentMapWindow.location.href = a.href; ListingAgentMapWindow.focus(); return false; } if ( typeof listingagent == 'undefined' ) { listingagent = {}; } listingagent.maps = {}; listingagent.maps.Map = function( properties ) { this.mapCanvasId = properties.mapCanvasId; this.latitude = properties.latitude; this.longitude = properties.longitude; this.zoom = properties.zoom; this.markerTitle = properties.markerTitle; this.infoContent = properties.infoContent; this.map = null; this.marker = null; this.infoWindow = null; this.isInfoWindowVisible = false; }; listingagent.maps.Map.prototype.getMapCanvasId = function() { return this.mapCanvasId; }; listingagent.maps.Map.prototype.getMap = function() { return this.map; }; listingagent.maps.Map.prototype.getMarker = function() { return this.marker; }; listingagent.maps.Map.prototype.show = function() { var map = this; var location = new google.maps.LatLng( this.latitude, this.longitude ); this.map = new google.maps.Map( document.getElementById( this.mapCanvasId ), { zoom: this.zoom ,center: location ,mapTypeId: google.maps.MapTypeId.ROADMAP ,mapTypeControl: false ,navigationControl: true ,scrollwheel: false ,backgroundColor: '#f0f0f0' } ); this.marker = new google.maps.Marker( { position: location ,map: this.map ,title: this.markerTitle } ); this.infoWindow = new google.maps.InfoWindow( { content: this.infoContent } ); google.maps.event.addListener( this.marker, 'click', function() { map.toggleInfo(); } ); }; listingagent.maps.Map.prototype.showMarker = function() { this.marker.setVisible( true ); }; listingagent.maps.Map.prototype.hideMarker = function() { this.marker.setVisible( false ); this.infoWindow.close(); this.isInfoWindowVisible = false; }; listingagent.maps.Map.prototype.toggleInfo = function() { if ( this.isInfoWindowVisible ) { this.infoWindow.close(); } else { this.infoWindow.open( this.map, this.marker ); } this.isInfoWindowVisible = !this.isInfoWindowVisible; }; listingagent.maps.Directions = function( properties ) { this.reference = properties.reference; this.map = properties.map; this.formContainerId = properties.formContainerId; this.originId = properties.originId; this.errorContainerId = properties.errorContainerId; this.textContainerId = properties.textContainerId; this.textPanelId = properties.textPanelId; this.clearControlId = properties.clearControlId; this.directionsService = null; this.directionsRenderer = null; }; listingagent.maps.Directions.prototype.showForm = function( f ) { var e; if (( e = f ) || ( e = document.getElementById( this.formContainerId ) )) { e.style.display = 'block'; if ( e = document.getElementById( this.originId ) ) { e.focus(); } } return false; }; listingagent.maps.Directions.prototype.hideForm = function( f ) { var e; if (( e = f ) || ( e = document.getElementById( this.formContainerId ) )) { e.style.display = ''; this.hideError(); } return false; }; listingagent.maps.Directions.prototype.toggleForm = function() { var e = document.getElementById( this.formContainerId ); if ( e ) { if ( e.style.display == 'block' ) { this.hideForm( e ); } else { this.showForm( e ); } } return false; }; listingagent.maps.Directions.prototype.setError = function( error ) { var e = document.getElementById( this.errorContainerId ); if ( e ) { e.innerHTML = error; } }; listingagent.maps.Directions.prototype.showError = function() { var e = document.getElementById( this.errorContainerId ); if ( e ) { e.style.display = 'block'; } return false; }; listingagent.maps.Directions.prototype.hideError = function() { var e = document.getElementById( this.errorContainerId ); if ( e ) { e.style.display = ''; } return false; }; listingagent.maps.Directions.prototype.setText = function( result ) { var route = result.routes[ 0 ]; var leg = route.legs[ 0 ]; var panel = document.getElementById( this.textPanelId ); var html; var step; var style; panel.innerHTML = ''; html = '<table border="0" cellspacing="0" cellpadding="0">' + '<tr>' + '<td colspan="3" style="background-color: #f0f0f0;">' + '<a' + ' class="map-directions-text-control"' + ' href="javascript:void(0)"' + ' onclick="return ' + this.reference + '.hideText();"' + '>' + 'Close' + '</a>' + '<b>Origin</b> ' + leg.start_address + '<br/>' + '<b>Destination</b> ' + leg.end_address + '<br/>' + ( leg.distance && leg.distance.text ? '<b>Distance</b> ' + leg.distance.text : '' ) + '</td>' + '</tr>'; style = ' style="padding-top: .5em;"'; for ( var n = 0; n < leg.steps.length; n++ ) { step = leg.steps[ n ]; html += '<tr>' + '<td' + style + '>' + (n + 1) + '.' + '</td>' + '<td' + style + '>' + step.instructions + '</td>' + '<td class="nowrap"' + style + '>' + step.distance.text + '</td>' + '</tr>'; style = ''; } if ( route.warnings && ( route.warnings.length > 0 )) { html += '<tr>' + '<td colspan="3" style="padding-top: .25em;">' + '<b>Warnings</b><br/>'; for ( var n = 0; n < route.warnings.length; n++ ) { html += route.warnings[ n ] + '<br/>'; } html += '</td>' + '</tr>'; } html += '<tr>' + '<td colspan="3" style="padding-top: .25em;">' + route.copyrights + '</td>' + '</tr>' + '</table>'; panel.innerHTML = html; }; listingagent.maps.Directions.prototype.showText = function() { var map = document.getElementById( this.map.getMapCanvasId() ); var directions = document.getElementById( this.textContainerId ); if ( map && directions ) { directions.style.display = 'block'; if ( directions.offsetHeight > ( map.offsetHeight / 6.46 ) * 1.5 ) { directions.style.pageBreakBefore = 'always'; } else { directions.style.pageBreakBefore = ''; } } }; listingagent.maps.Directions.prototype.hideText = function() { var e = document.getElementById( this.textContainerId ); if ( e ) { e.style.display = ''; } }; listingagent.maps.Directions.prototype.showClearControl = function() { var e = document.getElementById( this.clearControlId ); if ( e ) { e.style.display = 'inline'; } return false; }; listingagent.maps.Directions.prototype.hideClearControl = function() { var e = document.getElementById( this.clearControlId ); if ( e ) { e.style.display = ''; } return false; }; listingagent.maps.Directions.prototype.set = function() { var directions = this; var origin = document.getElementById( this.originId ).value; var destination = this.map.getMarker().getPosition(); var request = { origin: origin ,destination: destination ,travelMode: google.maps.DirectionsTravelMode.DRIVING ,provideRouteAlternatives: false ,avoidTolls: true }; if ( this.directionsService == null ) { this.directionsService = new google.maps.DirectionsService(); this.directionsRenderer = new google.maps.DirectionsRenderer( { suppressMarkers: false ,suppressInfoWindows: false } ); } this.hideError(); this.directionsService.route( request, function( result, status ) { if ( status == google.maps.DirectionsStatus.OK ) { directions.map.hideMarker(); directions.directionsRenderer.setDirections( result ); directions.directionsRenderer.setMap( directions.map.getMap() ); directions.setText( result ); directions.showText(); directions.showClearControl(); directions.hideForm(); } else { directions.clear(); directions.showForm(); directions.setError( 'Error retrieving directions. Please try again.' ); directions.showError(); } } ); return false; }; listingagent.maps.Directions.prototype.clear = function() { if ( this.directionsRenderer ) { this.directionsRenderer.setMap( null ); } this.map.showMarker(); this.hideText(); this.hideClearControl(); }; listingagent.maps.Notes = function( properties ) { this.defaultClass = properties.defaultClass; this.userClass = properties.userClass; }; listingagent.maps.Notes.prototype.focus = function( e ) { if ( e.value == e.defaultValue ) { e.value = ''; e.className = this.userClass; } return true; }; listingagent.maps.Notes.prototype.blur = function( e ) { if ( e.value == '' ) { e.value = e.defaultValue; e.className = this.defaultClass; } return true; };

/* Copyright (c) 2010 Terence M. Bandoian. All rights reserved. */