/* Ratio: 24.1% */

var locationTimeout,map,geocoder,panMap;function getLocation(address,print)
{window.clearTimeout(locationTimeout);offset=0;if(print)
{offset=-50;}
geocoder.getLocations(address,function(response){map.clearOverlays();if(!response||response.Status.code!=200){alert("Sorry, we were unable to geocode that address");}else{place=response.Placemark[0];point=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);map.getCurrentMapType().getMaxZoomAtLatLng(point,function(response)
{if(print)
{$('#logocontrol').css({'z-index':200,bottom:'145px',left:'140px'});$('div[dir=ltr]').css({'z-index':150,top:'496px',right:'146px','white-space':'normal',width:'200px'});}
else
{$('#logocontrol').css({'z-index':200,bottom:'10px',left:'140px'});$('div[dir=ltr]').css({'z-index':150,top:'460px',right:'146px','white-space':'normal',width:'200px'});}
if(response.status==200)
{if(response.zoom<16)
{map.setZoom(response.zoom);}}});map.setCenter(point,16);marker=new GMarker(point);map.addOverlay(marker);var output='<h1>Address:</h1>';output+='<h2>';try
{var thoroughfare=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;cityStateZip=place.address.replace(thoroughfare+', ','');output+=thoroughfare+'<br>'+cityStateZip;}
catch(error)
{if(place.AddressDetails.Country&&place.AddressDetails.Country.AdministrativeArea&&place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea&&place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality&&place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.AddressLine)
{thoroughfare=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.AddressLine;cityStateZip=place.address.replace(thoroughfare+', ','');output+=thoroughfare+'<br>'+cityStateZip;}
else
{output+=place.address;}}
function panMap()
{map.panBy(new google.maps.Size(-50,offset));}
output+='</h2>';output+='<p id="custom_message">'+nl2br($('#MapMessage').val())+'</p>';marker.openInfoWindowHtml(output,{maxWidth:200,onOpenFn:panMap()});$('.gmnoprint').each(function()
{$(this).removeClass('gmnoprint');});}});}
function nl2br(myString)
{var regX=/\n/gi;s=new String(myString);s=s.replace(regX,"<br> \n");return s;}
$('document').ready(function()
{$('#MapAddress').blur(function()
{getLocation($('#MapAddress').val());});$('#MapAddress').keydown(function(event)
{if(event.keyCode==13)
{getLocation($('#MapAddress').val());return false;}});$('#MapMessage').keyup(function()
{$('#custom_message').html(nl2br($('#MapMessage').val()));});});
