﻿//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;

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 = Translate("Calculating...Please wait.", "Calcul en cours… Veuillez patienter.")
    $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 = Translate("Not Available; property address withheld.", "Non disponible. Adresse de la propriété non divulguée.")
        return;
    }

    MyAjaxService.DrivingDirectionsFromAddr(
		VisitorID,
		ID,
		LastAddress,
		MakeFloat($get("hLatitude").value),
		MakeFloat($get("hLongitude").value),
		false,
        600,
        325,
		this.DirectionsCallBack,
		FailedCallback);
}

this.DirectionsCallBack = function (Res) {

    //	Title = Translate("<b>Driving Directions</b><br>From: ","<b>Itinéraire</b><br>De: ") 
    //				+ LastAddress
    //				+ Translate("<br>To: ","<br>À: ")
    //				+ $get("hAddress").value;
    //	Res = Res.replace(/;/gi,"<br>")
    //	$get("divDirections").innerHTML = Title + "<br><br>" + Res;

    $get("divDirections").innerHTML = Res;

    $get("butGoHome").enabled = true;
    $get("butGoWork").enabled = true;
    $get("butGoOther").enabled = true;
}

}
