if (typeof vcc != "object")
	vcc = new Object();
	
if (typeof vcc.dl != "object")
	vcc.dl = new Object();
	
vcc.dl.map = null;
vcc.dl.bDirections = false;

vcc.dl.aDealers = [];

vcc.dl.sLanguage = "";
vcc.dl.sMarket = "";
vcc.dl.bMiles = false;
vcc.dl.bUseMap = true;
vcc.dl.aAllPoints = []
vcc.dl.marketCenterPoint = { latitude: 0, longitude: 0 };
vcc.dl.directionsStart = null;
vcc.dl.directionsEnd = null;
vcc.dl.texts = [];
vcc.dl.mapCulture = "en-US";

/*
sales: 1
workshop: 2
shop: 4
gas: 8
carrental: 16
usedcarsales: 32
fleetsales: 64
usedcartradein: 128
dropinservice: 256
collectleavebeforeafteropenhours: 512
twentyfourhourservicenumber: 1024
approvedrepairer: 2048
volvodealer: 4096
*/

vcc.dl.Dealer = function(iId, iLat, iLong, sTitle, aAddresses, sPhone, sFax, sEmail, sWebsite, bitServices, aUrls, dblDistance) {
	this.id = iId;
	this.geocode = { latitude: iLat, longitude: iLong };
	this.shapeId = null;
	this.title = sTitle;
	this.address = aAddresses;
	this.phone = sPhone;
	this.fax = sFax;
	this.email = sEmail;
	this.website = sWebsite;
	this.distance = dblDistance;
	if (bitServices != null) {
		this.services = {
			sales: 1 & bitServices,
			workshop: 2 & bitServices,
			shop: 4 & bitServices,
			gas: 8 & bitServices,
			carrental: 16 & bitServices,
			usedcarsales: 32 & bitServices,
			fleetsales: 64 & bitServices,
			usedcartradein: 128 & bitServices,
			dropinservice: 256 & bitServices,
			collectleavebeforeafteropenhours: 512 & bitServices,
			twentyfourhourservicenumber: 1024 & bitServices,
			approvedrepairer: 2048 & bitServices,
			volvodealer: 4096 & bitServices
		};
	}
	if (aUrls != null) {
		this.urls = {
			testdriverequest: aUrls[0],
			brochurerequest: aUrls[1],
			servicebooking: aUrls[2],
			usedcarlocator: aUrls[3]
		};
	}
}

function DirectionsCallBack(route) {
	if (route && route.RouteLegs) {
		var oDirections = document.getElementById("directions");
		var sDistanceUnit = vcc.dl.bMiles ? " mi" : " km";
		var sDirections = "<table id=\"directions-table\"><tr><th colspan=\"2\">" + vcc.dl.getText("DrivingDirectionsResultDirections") + "</th><th>" + vcc.dl.getText("DrivingDirectionsResultDistance") + "</th><th>" + vcc.dl.getText("DrivingDirectionsResultTime") + "</th></tr>";
		var iTurns = 0;
		for (var i = 0; i < route.RouteLegs.length; i++) {
			var leg = route.RouteLegs[i];
			for (var j = 0; j < leg.Itinerary.Items.length; j++) {
              var turn = leg.Itinerary.Items[j];
              var iTime = turn.Time/60;
              sDirections += "<tr><td><strong>" + ++iTurns + ".</strong></td><td>" + turn.Text + "</td><td>" + turn.Distance.toFixed(1) + sDistanceUnit + "</td><td>" + iTime.toFixed(1) + " min</td>" + "</tr>\n";
           }
		}
		var iTotalTime = route.Time/60;
		sDirections += "<tr><td></td><td class=\"total\">" + vcc.dl.getText("DrivingDirectionsResultTotal") + "</td><td><span class=\"distance\">" + route.Distance.toFixed(1) + sDistanceUnit + "</span></td><td><span class=\"distance\">" + iTotalTime.toFixed(1) + " min</span></td></tr></table>";
		oDirections.innerHTML = sDirections;
	}	
}

vcc.dl.createMap = function() {
	if (document.getElementById("map") == null)
		return;

	vcc.dl.map = new VEMap("map");
	var mapOptions = new VEMapOptions();
	mapOptions.EnableBirdsEye = false;
    vcc.dl.map.LoadMap(null, null, null, null, null, null, null, null, mapOptions);
    
    if (vcc.dl.bMiles)
		vcc.dl.map.SetScaleBarDistanceUnit(VEDistanceUnit.Miles)
	else
		vcc.dl.map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers)
    vcc.dl.map.SetMouseWheelZoomToCenter(false);
    vcc.dl.map.ClearInfoBoxStyles();
    
    var oDirectionsTextarea = document.getElementById("directions-textarea");
    if (oDirectionsTextarea != null)
		eval(oDirectionsTextarea.innerText);
    
    if (vcc.dl.bDirections) {
		if (vcc.dl.directionsStart != null && vcc.dl.directionsEnd != null) {
			var aPoints = new Array(new VELatLong(vcc.dl.directionsStart.latitude, vcc.dl.directionsStart.longitude), new VELatLong(vcc.dl.directionsEnd.latitude, vcc.dl.directionsEnd.longitude));
			var options = new VERouteOptions();
			options.DrawRoute = true;
			options.SetBestMapView = true;
			options.RouteCallback = DirectionsCallBack;
			if (!vcc.dl.bMiles)
				options.DistanceUnit = VERouteDistanceUnit.Kilometer;
			vcc.dl.map.GetDirections(aPoints, options);
		}
    } else {    
		//Add dealers to map
		if (vcc.dl.aDealers.length == 0) {
			//No dealers found - center on market centerpoint
			vcc.dl.map.SetCenterAndZoom(new VELatLong(vcc.dl.marketCenterPoint.latitude, vcc.dl.marketCenterPoint.longitude), 5);
			vcc.dl.showErrorBox(vcc.dl.getText("ErrorNoDealerFound"));
		} else {
			vcc.dl.centerMapOnDealers();
			vcc.dl.addDealersToMap();
			if (vcc.dl.aDealers.length == 1)
				vcc.dl.map.SetZoomLevel(14);
		}		
	    
		//Attach to map events
		vcc.dl.map.AttachEvent("onmouseover", vcc.dl.onMapOver);
		vcc.dl.map.AttachEvent("onmouseout", vcc.dl.onMapOut);
		vcc.dl.map.AttachEvent("onclick", vcc.dl.onMapClick);
		vcc.dl.map.AttachEvent("onstartzoom", vcc.dl.onStartZoom);
		vcc.dl.map.AttachEvent("onendzoom", vcc.dl.onEndZoom);
		vcc.dl.map.AttachEvent("onstartpan", vcc.dl.onStartPan);
		vcc.dl.map.AttachEvent("onendpan", vcc.dl.onEndPan);
		vcc.dl.map.AttachEvent("onchangeview", vcc.dl.onChangeView);
	}
	
	//Add reference to dealer locator CSS, AFTER link to mapcontrol.css
	vcc.dl.addStyleSheet("/_layouts/VolvoCars.Web.Sites/CSS/GlobalDealerLocator.css?v=" + vcc.sAppVersion);
}

vcc.dl.centerMapOnDealers = function() {
	if (vcc.dl.aDealers.length == 0)
		return;
	for (var i = 0; i < vcc.dl.aDealers.length; i++) {
		var dealer = vcc.dl.aDealers[i];		
		vcc.dl.aAllPoints[vcc.dl.aAllPoints.length] = new VELatLong(dealer.geocode.latitude, dealer.geocode.longitude);
	}
	vcc.dl.map.SetMapView(vcc.dl.aAllPoints);
}

vcc.dl.showErrorBox = function(sErrorText) {
	var oError = document.getElementById("error-popup");
	if (oError == null) {
		//Create error layer
		oError = document.createElement("div");
		oError.id = "error-popup";
		if (vcc.ie)
			oError.className = "oldschool";
		var oMap = document.getElementById("map");
		oMap.parentNode.appendChild(oError);
	}
	oError.innerHTML = "<div onclick=\"vcc.dl.fadeOutElement('error-popup');\">"+ sErrorText + "</div>";
	oError.style.display = "block";
	var iHeight = vcc.getH(oError);
	oError.style.top = parseInt((400 - iHeight) / 2) + "px";
	setTimeout("vcc.dl.fadeOutElement('error-popup')", 5000);
}

vcc.dl.fadeOutElement = function(sElementId) {
	var oElm = document.getElementById(sElementId);
	var bUseFilters = (oElm.filters != null && oElm.filters.length > 0);
	var bUseComputedStyle = (window.getComputedStyle);
	if ((!bUseComputedStyle && !bUseFilters) || vcc.opera) {
		oElm.style.display = "none;"
		return;
	}
	var iCurrentOpacity = (bUseFilters) ? oElm.filters.item(0).opacity : parseFloat(getComputedStyle(oElm, null).getPropertyValue('opacity'));
	if (iCurrentOpacity == 0) {
		oElm.style.top = "-4000px";
		//oElm.style.display = "none;"
		if (bUseComputedStyle) oElm.style.opacity = 1;
		else oElm.filters.item(0).opacity = 100;
	} else {
		if (bUseComputedStyle) oElm.style.opacity = iCurrentOpacity - 0.1;
		else oElm.filters.item(0).opacity = iCurrentOpacity - 10;
		setTimeout("vcc.dl.fadeOutElement('" + sElementId + "')", 100);
	}
}

vcc.dl.addDealersToMap = function() {
	vcc.dl.map.Clear();
	if (vcc.dl.aDealers.length == 0) {
		vcc.dl.showErrorBox(vcc.dl.getText("ErrorNoDealerFound"));
	} else {
		var mapView = vcc.dl.map.GetMapView();
		var bottomRight = vcc.dl.map.LatLongToPixel(mapView.BottomRightLatLong);
		var mapWidth = parseInt(Math.ceil(bottomRight.x));
		var mapHeight = parseInt(Math.ceil(bottomRight.y));
		// Break the map up into a grid
		var gridSize = 30;
		var numXCells = parseInt(Math.ceil(mapWidth / gridSize));
		var numYCells = parseInt(Math.ceil(mapHeight / gridSize));

		// Create an array to store all the of grid data
		var gridCells = new Array(numXCells*numYCells);

		// Initialize the grid array with a structure to store the data
		for (var i = 0; i < numXCells; i++) {
			for (var j = 0; j < numYCells; j++) {
				gridCells[i + j * numXCells] = { latlong: new VELatLong(0,0), items: 0, dealer: 0};
			}
		}

		for (var i = 0; i < vcc.dl.aDealers.length; i++) {
			var dealer = vcc.dl.aDealers[i];			
			var latLong = new VELatLong(dealer.geocode.latitude, dealer.geocode.longitude);		
			
			var pixel = vcc.dl.map.LatLongToPixel(latLong);
			var xPixel = pixel.x;
			var yPixel = pixel.y;
			if (mapWidth >= xPixel && mapHeight >= yPixel && xPixel >= 0 && yPixel >= 0) {
				 var gridX = Math.floor(xPixel/gridSize);
				 var gridY = Math.floor(yPixel/gridSize);
				 var cell = gridX + gridY * numXCells;
				 if (gridCells[cell].items == 0) {
					gridCells[cell].latlong = latLong;
					gridCells[cell].dealer = i;
				 }
				 gridCells[cell].items++;
			}
		}
		var sClusteringHeader = vcc.dl.getText("ClusteringHeader");
		var sClusteringText = vcc.dl.getText("ClusteringText");
		for (var i = 0; i < gridCells.length; i++) {
			var cell = gridCells[i];
			if (cell.items > 0) {
				var shape = new VEShape(VEShapeType.Pushpin, cell.latlong);
				var sIconText = (cell.items > 1) ? "" : cell.dealer + 1;				
				shape.SetCustomIcon("<div class=\"pushpin_default\"><div>" + sIconText + "</div></div>");
				vcc.dl.map.AddShape(shape);
				if (cell.items == 1) {
					vcc.dl.aDealers[cell.dealer].shapeId = shape.GetID();
				} else {
					shape.SetTitle(sClusteringHeader);
					shape.SetDescription(sClusteringText);
				}
			}
		}
    }
}

vcc.dl.createDealerList = function(sHtml) {
	var iTotalDealers = vcc.dl.aDealers.length;
	var sOutput = "";
	if (iTotalDealers == 0) {
		sOutput = "<div class=\"search-results-error\">" + vcc.dl.getText("ErrorNoDealerFound")  + "</div>";
	} else {	
		sOutput = "<table id=\"search-results\" cellspacing=\"0\">";
		var iCurrentDealer = 1;
		for (var i = 0; i < iTotalDealers; i++) {
			var dealer = vcc.dl.aDealers[i];
			if (iCurrentDealer < iTotalDealers)
				sOutput += "<tr id=\"dealer-" + dealer.id + "\">";
			else
				sOutput += "<tr id=\"dealer-" + dealer.id + "\" class=\"last\">";
			//First column
			sOutput += "<td>";
			sOutput += "<h4>" + iCurrentDealer + ". <span class=\"name\">" + dealer.title + "</span></h4>";
			sOutput += "<div class=\"contact-info\">";
			for (var j = 0; j < dealer.address.length; j++) {
				if (dealer.address[j] != "")
					sOutput += dealer.address[j] + "<br />";
			}
			if (dealer.phone != "")
				sOutput += "{0} " +dealer.phone + "<br />";
			sOutput += "</div>";
			if (dealer.fax != "")
				sOutput += "{1} " +dealer.fax + "<br />";
			if (dealer.email != "")
				sOutput += "<div class=\"email\"><a href=\"mailto:" + dealer.email + "\">{2}</a></div>";
			if (dealer.website != "")
				sOutput += "<a href=\"" + dealer.website + "\">{3}</a><br />";
			
			sOutput += "<div class=\"service-icons\">";
			if (dealer.services.volvodealer)
				sOutput += "{dealer}";
			if (dealer.services.approvedrepairer)
				sOutput += "{repairer}";
			sOutput += "</div>";
			
			sOutput += "</td>";
			
			//Second column
			sOutput += "<td>";
			if (!vcc.opera && vcc.dl.bUseMap)
				sOutput += "<a href=\"javascript:void(0);\" onclick=\"vcc.dl.showDirForm(this," + dealer.geocode.latitude + "," + dealer.geocode.longitude + ");return false;\">{4}</a><br />";
			/*if (dealer.distance > 0)
				sOutput += "{5} " + Math.round(dealer.distance, 1) + " {22}<br />";*/
			sOutput += "</td>";
			
			//Third column
			sOutput += "<td>";
			sOutput += "<h5>{6}</h5>";
			//TODO: Don't show these if the texts are empty
			if (dealer.services.sales)
				sOutput += "{7}<br />";
			if (dealer.services.workshop)
				sOutput += "{8}<br />";
			if (dealer.services.shop)
				sOutput += "{9}<br />";
			if (dealer.services.gas)
				sOutput += "{10}<br />";
			if (dealer.services.carrental)
				sOutput += "{11}<br />";
			if (dealer.services.usedcarsales)
				sOutput += "{12}<br />";
			if (dealer.services.fleetsales)
				sOutput += "{13}<br />";
			if (dealer.services.usedcartradein)
				sOutput += "{14}<br />";
			if (dealer.services.dropinservice)
				sOutput += "{15}<br />";
			if (dealer.services.collectleavebeforeafteropenhours)
				sOutput += "{16}<br />";
			if (dealer.services.twentyfourhourservicenumber)
				sOutput += "{17}<br />";
			sOutput += "</td>";
			
			//Fourth column
			sOutput += "<td>";
			if (dealer.urls.testdriverequest != "")
				sOutput += "<a href=\"" + dealer.urls.testdriverequest + "\" target=\"_blank\">{18}</a><br />";
			if (dealer.urls.brochurerequest != "")
				sOutput += "<a href=\"" + dealer.urls.brochurerequest + "\" target=\"_blank\">{19}</a><br />";
			if (dealer.urls.servicebooking != "" && dealer.services.workshop)
				sOutput += "<a href=\"" + dealer.urls.servicebooking + "\" target=\"_blank\">{20}</a><br />";
			if (dealer.urls.usedcarlocator != "")
				sOutput += "<a href=\"" + dealer.urls.usedcarlocator + "\" target=\"_blank\">{21}</a><br />";
			sOutput += "</td>";
				
			iCurrentDealer++;
		}
		sOutput += "</table>";
	}
	var oDealerList = document.getElementById("dealerlist");
	while (oDealerList.childNodes.length > 0) {
		oDealerList.removeChild(oDealerList.childNodes[0]);
	}
	oDealerList.innerHTML = vcc.dl.parseSearchResultHtml(sOutput);
}

vcc.dl.findDealerByShapeId = function(shapeId) {
	for (var i = 0; i < vcc.dl.aDealers.length; i++) {
		if (vcc.dl.aDealers[i].shapeId == shapeId)
			return vcc.dl.aDealers[i];
	}
	return null;
}

vcc.dl.addStyleSheet = function(sUrl) {
	if (document.createStyleSheet) {
		document.createStyleSheet(sUrl);
	} else {
		var newSS = document.createElement('link');
		newSS.rel = "stylesheet";
		newSS.href = sUrl;
		document.getElementsByTagName("head")[0].appendChild(newSS);
	}
}

vcc.dl.showLoading = function() {
	var oLoading = document.getElementById("loading");
	if (oLoading == null) {
		//Create loading layer
		oLoading = document.createElement("div");
		oLoading.id = "loading";
		oLoading.innerHTML = "<div><img src=\"_layouts/VolvoCars.Web.Sites/Images/DealerLocator/Global/loading.gif\" alt=\"\" /></div>";
		var oMap = document.getElementById("map");
		oMap.parentNode.appendChild(oLoading);
	}
	oLoading.style.display = "block";
}

vcc.dl.hideLoading = function() {
	var oLoading = document.getElementById("loading");
	if (oLoading != null) {
		oLoading.style.display = "none";
	}
}

vcc.dl.showLoadingRoute = function() {
	document.getElementById("loadinginstructions").style.display = "block";
}

vcc.dl.hideLoadingRoute = function() {
	document.getElementById("loadinginstructions").style.display = "none";
}


vcc.dl.onMapOver = function(e) {
	if (e.elementID != null) {
		var shape = vcc.dl.map.GetShapeByID(e.elementID);
		var dealer = vcc.dl.findDealerByShapeId(shape.GetID());
		if (dealer != null) {
			var oDealerInfo = document.getElementById("dealer-" + dealer.id);
			if (oDealerInfo != null) {
				//Get name
				var sName = "<a href=\"#\" onclick=\"vcc.dl.showSelectedDealer(" + dealer.id + "); return false;\">" + vcc.getElementsByAttribute("class", "name", oDealerInfo, "span", false, true)[0].innerHTML + "</a>";
				shape.SetTitle(sName);
				var sDescription = "";
				var aInfoLayers = vcc.getElementsByAttribute("class", "contact-info", oDealerInfo, "div", false, true);
				var aEmailLayers = vcc.getElementsByAttribute("class", "email", oDealerInfo, "div", false, true)
				var aIconLayers = vcc.getElementsByAttribute("class", "service-icons", oDealerInfo, "div", false, true);
				if (aInfoLayers.length > 0)
					sDescription = aInfoLayers[0].innerHTML;
				if (aEmailLayers.length > 0)
					sDescription += aEmailLayers[0].innerHTML + "<br />";
				if (aIconLayers.length > 0 && aIconLayers[0].innerHTML != "")
					sDescription += "<div class=\"service-icons\">" + aIconLayers[0].innerHTML + "</div>";
				shape.SetDescription(sDescription);
			}
		}
	}
}

vcc.dl.onMapOut = function(e) { }

vcc.dl.onMapClick = function(e) {
	if (e.elementID != null) {
		var shape = vcc.dl.map.GetShapeByID(e.elementID);
		var dealer = vcc.dl.findDealerByShapeId(shape.GetID());
		if (dealer != null) {
			vcc.dl.showSelectedDealer(dealer.id);
		}
	}
}

vcc.dl.showSelectedDealer = function(dealerId) {
	vcc.dl.highlightDealerInList(dealerId);
	var oDealerInfo = document.getElementById("dealer-" + dealerId);
	if (oDealerInfo != null) {
		scrollTo(vcc.getDocScroll().x, vcc.getY(oDealerInfo, true) - 60);
	}
}

vcc.dl.highlightDealerInList = function(iDealerId) {
	var oList = document.getElementById("search-results");
	if (oList != null) {
		var aRows = oList.getElementsByTagName("tr");
		var sDealerIdToFind = "dealer-" + iDealerId;
		for (var i = 0; i < aRows.length; i++) {
			var sCurrentClass = aRows[i].className;
			if (aRows[i].id == sDealerIdToFind) {
				aRows[i].className = (sCurrentClass.indexOf("last") > -1) ? "last highlight" : "highlight";
			} else {
				aRows[i].className = (sCurrentClass.indexOf("last") > -1) ? "last" : null;
			}
		}
	}
}

vcc.dl.eventTimer = false;

vcc.dl.onStartZoom = function(e) {
	if (vcc.dl.eventTimer != null) {
		clearTimeout(vcc.dl.eventTimer);
	}
}

vcc.dl.onEndZoom = function(e) {
	if (vcc.dl.eventTimer != null) {
		clearTimeout(vcc.dl.eventTimer);
	}
	vcc.dl.eventTimer = setTimeout("vcc.dl.zoomTimer = null; vcc.dl.ws.getDealersByGeoCode();", 1000);		
}

vcc.dl.onStartPan = function(e) {
	if (vcc.dl.eventTimer != null) {
		clearTimeout(vcc.dl.eventTimer);
	}
}

vcc.dl.onEndPan = function(e) {
	if (vcc.dl.eventTimer != null) {
		clearTimeout(vcc.dl.eventTimer);
	}
	vcc.dl.eventTimer = setTimeout("vcc.dl.panTimer = null; vcc.dl.ws.getDealersByGeoCode();", 1000);			
}

vcc.dl.bMapViewAlert = true;

vcc.dl.onChangeView = function(e) {
	if (!vcc.dl.CheckIfPlotDealers()) {
		if (vcc.dl.bMapViewAlert) {
			vcc.dl.bMapViewAlert = false;
			vcc.dl.showErrorBox(vcc.dl.getText("ErrorDealersNotPlotted"));
			vcc.dl.map.Clear();
			document.getElementById("dealerlist").innerHTML = "";
		}
	} else {
		vcc.dl.bMapViewAlert = true;
	}
}

vcc.dl.CheckIfPlotDealers = function() {
	var mapStyle = vcc.dl.map.GetMapStyle();
	var mapMode = vcc.dl.map.GetMapMode();
	if (mapStyle == "b" || mapStyle == "o" || mapMode == VEMapMode.Mode3D)
		return false;
	return true;
}

vcc.dl.getFiltering = function() {
	var oFilterList = document.getElementById("filterlist");
	var sFilter = "VisibleInDealerLocator = 1 and";
	if (oFilterList != null) {
		var re = new RegExp("_filter([^2]+)2");
		var aFilterBoxes = oFilterList.getElementsByTagName("input");		
		for (var i = 0; i < aFilterBoxes.length; i++) {
			if (aFilterBoxes[i].checked) {				
				var arMatches = re.exec(aFilterBoxes[i].id);
				var sFilterName = arMatches[1];
				sFilter += " " + sFilterName + " = 1 and";
			}
		}
	}
	return sFilter.substring(0, sFilter.length - 4);
}

vcc.dl.getMapheightInScaleUnit = function() {
	var oScaleBarDiv = vcc.getElementsByAttribute("class", "MSVE_ScaleBarBg", document.getElementById("map"), "div", false, true)[0];
	var iScaleBarWidth = vcc.getW(oScaleBarDiv);
	var oScaleDiv = vcc.getElementsByAttribute("class", "MSVE_ScaleBarLabelFg", document.getElementById("map"), "div", false, true)[0];
	var aTextParts = oScaleDiv.innerHTML.split(" ");
	if (vcc.dl.bMiles) {
		var dblScale = (aTextParts[1].indexOf("miles") > -1) ? aTextParts[0] : aTextParts[0] / 1760;
	} else {
		var dblScale = (aTextParts[1].indexOf("km") > -1) ? aTextParts[0] : aTextParts[0] / 1000;
	}
	var dblMapHeightInDistanceUnit = (vcc.getH(document.getElementById("map")) / iScaleBarWidth) * dblScale;
	var dblMapWidthInDistanceUnit = (vcc.getW(document.getElementById("map")) / iScaleBarWidth) * dblScale;
	return dblMapHeightInDistanceUnit;
}

vcc.dl.selectedDealer = null;

vcc.dl.showDirForm = function(oLink, dblLatitude, dblLongitude) {
	var oForm = document.getElementById("drivinginstructions");
	if (oForm != null) {
		document.getElementById("driving-error").innerHTML = "";
		oForm.style.display = "block";
		var iY = vcc.getY(oLink, true) - vcc.getY("maincontent", true) - 20;
		vcc.moveTo(oForm, 400, iY);
	}
	vcc.dl.selectedDealer = new vcc.dl.Dealer(0, dblLatitude, dblLongitude);
}

vcc.dl.getText = function(sTextId) {
	var sText = vcc.dl.texts[sTextId];
	if (sText == null)
		return "";
	return sText;
}

vcc.dl.parseSearchResultHtml = function(sHtml) {
	sHtml = sHtml.replace(/\{0\}/gi, vcc.dl.getText("DealersPhone"));
	sHtml = sHtml.replace(/\{1\}/gi, vcc.dl.getText("DealersFax"));
	sHtml = sHtml.replace(/\{2\}/gi, vcc.dl.getText("DealersEmail"));
	sHtml = sHtml.replace(/\{3\}/gi, vcc.dl.getText("DealersSite"));
	sHtml = sHtml.replace(/\{4\}/gi, vcc.dl.getText("DealersLinkDrivingDirections"));
	sHtml = sHtml.replace(/\{5\}/gi, vcc.dl.getText("DealersDistance"));
	sHtml = sHtml.replace(/\{6\}/gi, vcc.dl.getText("DealersServices"));
	sHtml = sHtml.replace(/\{7\}/gi, vcc.dl.getText("ServiceSales"));
	sHtml = sHtml.replace(/\{8\}/gi, vcc.dl.getText("ServiceWorkShop"));
	sHtml = sHtml.replace(/\{9\}/gi, vcc.dl.getText("ServiceShop"));
	sHtml = sHtml.replace(/\{10\}/gi, vcc.dl.getText("ServiceGas"));
	sHtml = sHtml.replace(/\{11\}/gi, vcc.dl.getText("ServiceCarRental"));
	sHtml = sHtml.replace(/\{12\}/gi, vcc.dl.getText("ServiceUsedCarSales"));
	sHtml = sHtml.replace(/\{13\}/gi, vcc.dl.getText("ServiceFleetSales"));
	sHtml = sHtml.replace(/\{14\}/gi, vcc.dl.getText("ServiceUsedCarTradeIn"));
	sHtml = sHtml.replace(/\{15\}/gi, vcc.dl.getText("ServiceDropInService"));
	sHtml = sHtml.replace(/\{16\}/gi, vcc.dl.getText("ServiceCollectLeaveBeforeAfterOpenHours"));
	sHtml = sHtml.replace(/\{17\}/gi, vcc.dl.getText("ServiceTwentyFourHourServiceNumber"));
	sHtml = sHtml.replace(/\{18\}/gi, vcc.dl.getText("DealersLinkTestDrive"));
	sHtml = sHtml.replace(/\{19\}/gi, vcc.dl.getText("DealersLinkBrochure"));
	sHtml = sHtml.replace(/\{20\}/gi, vcc.dl.getText("DealersLinkServiceBooking"));
	sHtml = sHtml.replace(/\{21\}/gi, vcc.dl.getText("DealersLinkUsedCarLocator"));
	
	var sDealer = vcc.dl.getText("ServiceVolvoDealer");
	if (sDealer != "" && sDealer != null)
		sHtml = sHtml.replace(/\{dealer\}/gi, "<img src=\"/_layouts/VolvoCars.Web.Sites/Images/DealerLocator/Global/icon_volvodealer.gif\" alt=\"" + sDealer + "\" title=\"" + sDealer + "\" />");
	else
		sHtml = sHtml.replace(/\{dealer\}/gi, "");
	var sRepairer = vcc.dl.getText("ServiceApprovedRepairer");
	
	if (sRepairer != "" && sRepairer != null)
		sHtml = sHtml.replace(/\{repairer\}/gi, "<img src=\"/_layouts/VolvoCars.Web.Sites/Images/DealerLocator/Global/icon_authorizedrepairer.gif\" alt=\"" + sRepairer + "\" title=\"" + sRepairer + "\" />");
	else
		sHtml = sHtml.replace(/\{repairer\}/gi, "");
	return sHtml;
}

vcc.addEvent(window, "load", "vcc.dl.createMap");
