﻿function DrivingDir(){
	
this.UpdateDirUI = function(){
	var cb = $get("bShowDir");
	
	$get("tdHome").style.display="none";
	$get("tdWork").style.display="none";
	$get("tdOther").style.display="none";
	$get("divDirections").innerHTML = "";

	
	if(cb.checked) {
		var ddl = $get("ddlLocation");
		var Type = ddl[ddl.selectedIndex].value
		$get("td"+Type).style.display = "block";
	} 
	
}

this.GetDir = function(ID){
	LastAddress = $get(ID).value
	$get("divDirections").innerHTML = "Calculating....Please wait."
	$get("butGoHome").enabled = false;
	$get("butGoWork").enabled = false;
	$get("butGoOther").enabled = false;
	var VisitorID = $get("hEncryptedVisitorID").value;

	var PropAddress = $get("hAddress").value;
	if (PropAddress=="{Address Witheld}")
	{
	$get("divDirections").innerHTML ="Not available; property address withheld.";
	return;
	}
	
	MyAjaxService.DrivingDirectionsFromAddr(
		VisitorID,
		ID,
		LastAddress, 
		MakeFloat($get("hLatitude").value),
		MakeFloat($get("hLongitude").value),
		this.DirectionsCallBack, 
		FailedCallback); 					
}

this.DirectionsCallBack = function(Res)
{

	var Title = "<b>Driving Directions</b><br>From: " + LastAddress + "<br>To: " + $get("hAddress").value;

	Res = Res.replace(/;/gi,"<br>")
	$get("divDirections").innerHTML = Title + "<br><br>" + Res;
	
	$get("butGoHome").enabled = true;
	$get("butGoWork").enabled = true;
	$get("butGoOther").enabled = true;
}

}