function DrivingDirections(){var B=null;var J=null;function H(){RfgShowWaitDialog(g_strMainMapObjId,true,"Calculating Route")}function F(){RfgHideWaitDialog(g_strMainMapObjId)}function C(L){F();var K=obj("drivinginstructions");if(K){K.innerHTML="<div class='tr'></div><div class='bl'></div><div class='br'></div></div>"+D(L)}var K=obj("printbutton");if(K){K.style.display=""}}function E(M,O,L){if(J){var K=new VERouteOptions();K.DrawRoute=true;K.RouteCallback=L;K.RouteOptimize=VERouteOptimize.MinimizeDistance;try{J.GetDirections(O,K)
}catch(N){}}}var I=null;function A(M,K){var L=[M,g_objPropertyLatLong];if(I!=null){J.DeleteShape(I);I=null}if(B.visit.checked){I=RfgAddPushPin(g_strMainMapObjId,g_objOfficeLatLong.Latitude,g_objOfficeLatLong.Longitude,g_strOfficeName+"<br>"+g_strOfficeAddr,"","/images/search/mapview/pushpin.gif");L.push(g_objOfficeLatLong)}try{E(g_strMainMapObjId,L,C)}catch(N){F();alert(N.message)}}this.GetDirectionsFromForm=function(L){try{J=g_pRfgMapContainer[g_strMainMapObjId];B=L;if(L.city.value==""||L.state.selectedIndex==0||L.zip.value==""){alert("Directions from where?\nYou need to fill in the address, city, state and zip you are coming from.");
return false}else{ClosePopoutDrivingDirections();H();RfgSetMapStyle(g_strMainMapObjId,"AerialVE");g_objFromAddress=new Address(L.address.value,L.city.value,L.state.options[L.state.selectedIndex].value,"US",L.zip.value,null,null);RfgFindLocation(g_strMainMapObjId,g_objFromAddress,true,false,G)}}catch(K){F();alert(K.message)}return false};function G(N,P,O,M,L){if(O&&O.length>0){var K=O[0];A(K.LatLong,g_objPropertyLatLong)}else{F();alert("I'm sorry, but we were unable to locate the address you entered.  Please double check your data and try again.")
}}function D(K){var Q=document.createElement("TABLE");var P,O;for(var N=0;N<K.RouteLegs.length;N++){P=K.RouteLegs[N];var M=Q.insertRow(Q.rows.length);M.insertCell(0).innerHTML="#";M.insertCell(1).innerHTML="<b>Driving Directions to "+["Property",g_strOfficeName+" - "+g_strOfficeAddr][N]+"</b> ("+parseInt(P.Distance)+" miles  "+parseInt(P.Time/60)+" minutes)";for(var L=0;L<P.Itinerary.Items.length;L++){O=P.Itinerary.Items[L];M=Q.insertRow(Q.rows.length);M.insertCell(0).innerHTML=(L+1);M.cells[0].align="center";
M.insertCell(1).innerHTML=O.Text+(O.Distance>0?" -- ("+Math.round((100*O.Distance))/100+" miles) "+parseInt(O.Time/60)+" minutes":"");M.cells[1].noWrap=true}}return"<table>"+Q.innerHTML+"</table>"}}g_DrivingDirections=new DrivingDirections();
