﻿//Set default language and change error messages accordingly
var LanguageIndex = 0
if ($get("hLanguageCode") != "fr-ca") LanguageIndex = 1;
if ($get("hLanguageCode") == "fr-ca") LanguageIndex = 2;

var DrivingDirMsg_CalculatingPleaseWait = "|Calculating...Please wait.|Calculating...Please wait.|Calcul en cours… Veuillez patienter.".split("|")[LanguageIndex];
var DrivingDirMsg_NotAvailable = "|Not Available; property address withheld.|Not Available; property address withheld.|Non disponible. Adresse de la propriété non divulguée.".split("|")[LanguageIndex];
var DrivingDirMsg_TitleFrom = "|<b>Driving Directions</b><br>From: |<b>Driving Directions</b><br>From: |<b>Itinéraire</b><br>De: ";
var DrivingDirMsg_TitleTo = "|<br>To: |<br>To: |<br>À: ";

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 = DrivingDirMsg_CalculatingPleaseWait
	$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 = DrivingDirMsg_NotAvailable;
	return;
	}
	
	MyAjaxService.DrivingDirectionsFromAddr(
		VisitorID,
		ID,
		LastAddress, 
		MakeFloat($get("hLatitude").value),
		MakeFloat($get("hLongitude").value),
		this.DirectionsCallBack, 
		FailedCallback); 					
}

this.DirectionsCallBack = function(Res)
{

	Title = DrivingDirMsg_TitleFrom + LastAddress + DrivingDirMsg_TitleTo + $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;
}

}