var GB_ROOT_DIR = "./js/greybox/";

//Dhtml Suite
DHTML_SUITE_THEME = 'blue';
DHTML_SUITE_THEME_FOLDER = 'js/dhtmlsuite/themes/';

var ID_MAP_HEADER = "mapheader";
var ID_TOOL_CHOOSE_PANEL = "TTchoosePanel";
var ID_CHOOSE_LIST_ADDRESSES = "chooseListAddresses";
var ID_CHOOSE_LIST = "chooseList";                   
var POI_GROUP_LINK_CONTAINER = "poiGroupLinkContainer";
var ALL_POI_GROUP_DATA_CONTAINER = "allPoiGroupDataContainer";

var mapManager = null; 
var graphicManager = null;

var arrayAllMapEntities = new Array(); //array contenente tutte le mappe dei singoli poi;
var arrayAllGroupEntityLayer = new Array(); //array che contiene tutti i shape layer delle entitą compresi i MieiLuoghi;

var currentPositionOnClickEvent = null; //variabile che contiene le coordinate (LatLong) nel momento in cui un utente vuole usare le funzionalitą del popupMenu; 

var ID_INFORMATION_PANEL = "informationPanel";
var ID_POI_USER_ADVICE_LIST_PANEL = "poiUserAdviceListPanel";

var ID_ERROR_BODY = "errorBody";
var ID_IMAGE_LOAD = "VGGloading";

var ID_ITINERARY = "itinerary"; 

var timeOutWaitPanel = 0;
var timeOutInformationPanel = 0;

var geocoder = new GClientGeocoder();
var textCollection;//collection di TextBox da parserizzare;
var textGoogleSearchCollection;
//-----

function getPositionTopScroll(This){return (getPositionTop(This) - getById('VGGsubLeftColumn').scrollTop);}

function showHideBox( idTitle, idBox) {  
var box = getById( idBox );
var title = getById( idTitle );
if (box.className=='boxClose') {
box.className = 'boxOpen';
title.className = 'titleOpen';
}
else {
box.className = 'boxClose';
title.className = 'titleClose';
}
}

function showHideElement(idTitle, idElement) {
var title = getById( idTitle );
var element = getById(idElement);
if(element.style.display=="block") {        
closeElement(idElement);
title.className = 'titleClose';
} 
else {   
openElement(idElement);   
title.className='titleOpen';
} 
}

function showHideSideBar() {
var VGGleftColumn = getById( 'VGGsubLeftColumn' );
var imgSideBarShowHide = getById( 'imgSideBarShowHide' );
if(VGGleftColumn==null||imgSideBarShowHide==null )return;
if(VGGleftColumn.style.display == 'none' ) {
VGGleftColumn.style.display = 'block';
imgSideBarShowHide.src = 'images/ico_arrow1inverse.gif';
getById( 'VGGcontentcolumn' ).className='VGGcontentcolumnOpen';
getById( 'VGGsubContentWrapper' ).className='VGGsubContentWrapper';
}
else {
VGGleftColumn.style.display='none';
imgSideBarShowHide.src='images/ico_arrow1.gif';
getById('VGGcontentcolumn').className='VGGcontentcolumnClose';
getById('VGGsubContentWrapper').className='VGGsubContentWrapperMaximized';   
}
resizeMap();
}

function openPopUpPrintPreview() {
var content = ""; 
//MAP
content += "centermaplat=" + mapManager.GetLat() + "&centermaplong=" + mapManager.GetLong();    
content += "&zoommap=" + mapManager.GetZoomLevel();
content += "&offsetmapsquared=" + getMapRadius();
content += "&stylemap=" + mapManager.GetMapStyle();
if(mapManager.GetMapStyle() == VEMapStyle.Birdseye)      
content += "&orientation=" + mapManager.GetOrientation();

//ADDRESS
if( mapManager.HasAddressSet() ) { 
content += (content !=""?"&":"");
content += "addresslat=" + mapManager.GetAddressLat() + "&addresslong=" + mapManager.GetAddressLong() + "&addressname=" + escape(getObjValue('address_1'));
} 

//POI USER  
var showPoiUser = false;
for(var i=0; i < POIUSER_GROUPS.length; i++) {
var chk = getById(POIUSER_GROUPS[i] + '_chk');
if( chk != null && chk.checked ) { 
showPoiUser = true;
var poiUserShapeLayer = mapManager.GetShapeLayer(POIUSER_GROUPS[i]);
if((poiUserShapeLayer  != undefined) && (poiUserShapeLayer.GetVisibility() == true)) {
content += (content != "" ? "&poiuserlisthide=" : "poiuserlisthide=");
var sep = "";
for(var i=0; i < poiUserShapeLayer.GetShapeCount(); i++) {
var currentShape = poiUserShapeLayer.GetShapeByIndex(i);
if(currentShape.GetVisibility() == false) {
var shapeKey = mapManager.GetShapeKeyById(currentShape.GetID());
content += sep + (shapeKey.slice(shapeKey.indexOf("_") + 1));
sep = ",";
} 
} 
}
}  
}

content+=(content!=""?"&showPoiUser="+showPoiUser:"showPoiUser="+showPoiUser);

//POI
var contentIdEntityGroups = "";  
var sep = "";   
for(var i=0; i < POI_GROUPS.length; i++) {
var chk = getById(POI_GROUPS[i] + '_chk');
if( chk != null && chk.checked ) { 
contentIdEntityGroups += sep + (POI_GROUPS[i].slice(POI_GROUPS[i].indexOf("_") + 1)); 
sep = ",";
}
} 

if(contentIdEntityGroups != "")
content += (content != "" ? "&identitygroups=" + contentIdEntityGroups : "identitygroups=" + contentIdEntityGroups);

//ITINERARY   
if(mapManager.GetDeparture() != "" && mapManager.GetArrival() != "") {
content += (content != "" ? "&" : ""); 
content += "departure=" + mapManager.GetDeparture() + "&arrival=" + mapManager.GetArrival();
}    

var leftPosition = (screen.width) ? (screen.width - 800)/2 : 0;
var topPosition = (screen.height) ? (screen.height - 600)/2 : 0;
window.open("printPreview.do?" + content, 'popup', 'width=750, height=550, toolbar = no, scrollbars = yes, status = no, left=' + leftPosition + ', top=' + topPosition);
}

function buildDirectPageLink() {
var directPageLink = SITE_CONTEXT + 'home.do?';        
directPageLink += "mapLat=" + mapManager.GetLat();
directPageLink += "&mapLong=" + mapManager.GetLong();
directPageLink += "&mapStyle=" + mapManager.GetMapStyle();
directPageLink += (mapManager.GetOrientation() != null ? "&orientation=" + mapManager.GetOrientation() : "");
directPageLink += "&mapZoom=" + mapManager.GetZoomLevel();
var address = getObjValue('address_1');
directPageLink += (address == MESSAGES['commons.label.defaulttextobjaddress'] ? "" : "&address1=" + escape(address));

setTextBox('directPageLink', directPageLink);
setDisplayBlock('directPageLinkPanel');
if( DHTMLSuite.clientInfoObj.isMSIE ) {
setDisplayBlock('idBtnCopyDirectPageLink');
setDisplayNone('idMsgCopyDirectPageLink');
}
else {
setDisplayNone('idBtnCopyDirectPageLink');
setDisplayBlock('idMsgCopyDirectPageLink');
}
getById('directPageLink').focus();
getById('directPageLink').select();
}

function getDHTMLSuiteDynamicContent(disableWaitMessage) {
if( disableWaitMessage==null )
disableWaitMessage=false;
var dynConObj = new DHTMLSuite.dynamicContent();  
if(disableWaitMessage){
dynConObj.setWaitMessage('');
dynConObj.setWaitImage(null);
}
else
dynConObj.waitMessage = MESSAGES['message.wait']; 
return dynConObj;
}

function getMapRadius(){return getDistance(mapManager.GetTopLeftLatLong(), mapManager.GetCenter(), 'k') * 0.75;}
function latLonToRadians(point) {return point * Math.PI / 180;}//convert lat/long in degrees to radians

//calculate distance
function getDistance(p1, p2, distanceUnit) {
var p1Lat = latLonToRadians(p1.Latitude);
var p1Lon = latLonToRadians(p1.Longitude);
var p2Lat = latLonToRadians(p2.Latitude);
var p2Lon = latLonToRadians(p2.Longitude);	

var R = 6371; // earth's mean radius in km
var dLat  = p2Lat - p1Lat;
var dLong = p2Lon - p1Lon;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(p1Lat) * Math.cos(p2Lat) * Math.sin(dLong/2) * Math.sin(dLong/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return (distanceUnit == 'k' ? (R * c) : (R * c * 0.6214));
}

function getCirclePoints(p1, p2){
var R = 6371; // earth's mean radius in km
var lat = (p1.Latitude * Math.PI) / 180; //rad
var lon = (p1.Longitude * Math.PI) / 180; //rad
var d = getDistance(p1, p2, 'k') / R;  // d = angular distance covered on earth's surface  //always KM!!!
var circlePoints = new Array(); 
for (x = 0; x <= 360; x++) { 
var pTemp = new VELatLong(0,0)            
brng = x * Math.PI / 180; //rad
pTemp.Latitude = Math.asin(Math.sin(lat)*Math.cos(d) + Math.cos(lat)*Math.sin(d)*Math.cos(brng));
pTemp.Longitude = ((lon + Math.atan2(Math.sin(brng)*Math.sin(d)*Math.cos(lat), Math.cos(d)-Math.sin(lat)*Math.sin(pTemp.Latitude))) * 180) / Math.PI;
pTemp.Latitude = (pTemp.Latitude * 180) / Math.PI;
circlePoints.push(pTemp);
}
return circlePoints;
}


function scrollManager() {
closeAllPanel();
if(DHTMLSuite.clientInfoObj.isFirefox)return;
var allPoiAndPoiUser = POI_GROUPS.concat(POIUSER_GROUPS);//build only one array
var allGroups = allPoiAndPoiUser.concat(POICUSTOM_GROUPS);
for(var i=0; i < allGroups.length; i++) {
var poiGroupDataContainer = getById(allGroups[i] + '_data');
if( poiGroupDataContainer!= null && poiGroupDataContainer.className != 'boxClose' ) {
var tabContainerPoi_p = AJS.$bytc('p', 'tabContainerPoi', poiGroupDataContainer);
for(var z=0; z < tabContainerPoi_p.length; z++) {
var tabContainerPoi_a = AJS.$bytc('a', null, tabContainerPoi_p[z]);
for(var j=0; j < tabContainerPoi_a.length; j++) {
if(tabContainerPoi_a[j].name == 'tabMap' && tabContainerPoi_a[j].className == 'active') {
for(var k=0; k < tabContainerPoi_a.length; k++) {
if(tabContainerPoi_a[k].name == 'tabAddress') {
eval(tabContainerPoi_a[k].href);
break;
}  
}
break;
}
}
}
}
}
}    

function clearAll() {
closeAllPanel();
setDefaultText('address_1');
setDefaultText('address_2');
checkText(1);
checkText(2);
closeElement(ID_ITINERARY);  
poiGroupResetAll();       
mapManager.ClearAll();
} 

function reset() {
clearAll();
checkMapStyle();
setInnerHTML(ID_MAP_HEADER, MESSAGES['map.label.headermap']);
}  

function setDefaultText(idElement){setTextBox(idElement, MESSAGES['commons.label.defaulttextobjaddress'], '#BFBFBF');}
function showWaitPanel(){openElement(ID_IMAGE_LOAD);}
function hideWaitPanel(){closeElement(ID_IMAGE_LOAD);}

function closeAllPanel() {
hideInformationPanel();
hidePoiUserPanel();
hideAddressesPanel();
hideDirectPageLinkPanel();
mapManager.HideInfoBox();
}

function setMapLayout(flag) {
getById('useGoogleSearch_1').value = "true";
getById('useGoogleSearch_2').value = "true";
mapManager.ClearAll();
checkMapStyle();  
poiGroupResetAll();
if(flag==0)closeElement(ID_ITINERARY);//#### indirizzo #####                                                      
}

function showInformationPanel(bodyPanel) {
hideWaitPanel();
setInnerHTML(ID_ERROR_BODY, bodyPanel);
openElement(ID_INFORMATION_PANEL);
timeOutInformationPanel = window.setTimeout(hideInformationPanel, 5000); 
}

function hideInformationPanel() {
closeElement(ID_INFORMATION_PANEL);
window.clearTimeout(timeOutInformationPanel);
}

function hidePoiUserPanel() {   
closeElement(ID_POI_USER_ADVICE_LIST_PANEL); 
closeElement(ID_TOOL_CHOOSE_PANEL);
}
function hideDirectPageLinkPanel() {setDisplayNone('directPageLinkPanel');}
function showPoiUserAdvicePanel(idElementSelected) {
closeAllPanel();
setPositionPanel(idElementSelected, ID_POI_USER_ADVICE_LIST_PANEL);
getById(ID_TOOL_CHOOSE_PANEL).className = "toolTipPoiUser";
openElement(ID_POI_USER_ADVICE_LIST_PANEL);
openElement(ID_TOOL_CHOOSE_PANEL);   
}

function hideAddressesPanel() {
closeElement(ID_CHOOSE_LIST_ADDRESSES);
closeElement(ID_TOOL_CHOOSE_PANEL);
}

function showAddressesPanel(idElementSelected) {
closeAllPanel();   
setPositionPanel(idElementSelected, ID_CHOOSE_LIST_ADDRESSES);  
getById(ID_TOOL_CHOOSE_PANEL).className = "toolTipPoiUser";
openElement(ID_TOOL_CHOOSE_PANEL);
openElement(ID_CHOOSE_LIST_ADDRESSES);
}

function lookupInformation() {
var count = 0;
closeAllPanel();
textCollection = document.getElementsByName('address'); 
textGoogleSearchCollection = document.getElementsByName('googleSearch');
for(var i=0; i < textCollection.length; i++) {
if((textCollection[i].value != "") && (textCollection[i].value != MESSAGES['commons.label.defaulttextobjaddress']))
count++;
}

if(count==0) {  
showInformationPanel(MESSAGES['error.noaddressfound']);
return;
}  

if(count==1) { 
showWaitPanel();
if(textCollection[0].value == "" || textCollection[0].value == MESSAGES['commons.label.defaulttextobjaddress']) {  
showInformationPanel("Inserire un indirizzo di partenza valido.");
return;
}          
checkMapStyle();
showAddress(textCollection[0].value, 16, mapManager.GetMapStyle());
}  
else {
initialization();  
calculateItinerary();
}  
}

function setPositionPanel(elementId, idDivToShow) {
var element = getById(elementId);
var left = getPositionLeft(element);
var top = getPositionTopScroll(element); 
top = top - 30;
left = left + 325;
getById(idDivToShow).style.top = top + "px";
getById(idDivToShow).style.left = left + "px";
getById(ID_TOOL_CHOOSE_PANEL).style.top = top + "px";
getById(ID_TOOL_CHOOSE_PANEL).style.left = left + "px";
} 

function setInfoPanel() { 
var content = "";    
var latLong = mapManager.GetCenter();   
if (mapManager.GetMapStyle()==VEMapStyle.Birdseye) {
var birdEyeImage = mapManager.GetMap().GetBirdseyeScene();
content += "<b>ID:</b> " + birdEyeImage.GetID() + "<br/>";
content += "<b>Miniature:</b> " + birdEyeImage.GetThumbnailFilename() + "<br/>";
content += "<b>Orientamento:</b> " + birdEyeImage.GetOrientation() + "<br/>";
content += "<b>Altezza immagine:</b> " + birdEyeImage.GetHeight() + " px<br/>";
content += "<b>Larghezza immagine:</b> " + birdEyeImage.GetWidth() + " px<br/>";             
content += "<b>Latitudine:</b> "+ (latLong.Latitude != null ? latLong.Latitude : "non disponibile") + "<br/>";
content += "<b>Longitudine:</b> " + (latLong.Longitude != null ? latLong.Longitude : "non disponibile") + "<br/>";
}  
else{
var latitude = (latLong.Latitude != undefined ? latLong.Latitude : "non disponibile");
var longitude = (latLong.Longitude != undefined ? latLong.Longitude : "non disponibile");       
content += "<b>Latitudine:</b> "+ latitude + "<br/>";
content += "<b>Longitudine:</b> " + longitude + "<br/>";    
}

var zoomLevel = (mapManager.GetZoomLevel() != undefined ? mapManager.GetZoomLevel() : "non disponibile");
content += "<b>Livello zoom:</b> " + zoomLevel; 
showInformationPanel(content);
hidePopupMenu();    
}

function selectDrawButton(current){
var scrathPad = getById('scratchPad');
if(scrathPad==null) return;
var hrefList = AJS.$bytc('a', null, scrathPad);
for(var i=0; i < hrefList.length; i++){
hrefList[i].className='';
}
getById(current).className = 'active';
}
function drawNothing() {
hidePopupMenu();
selectDrawButton('drawNothingBtn');
graphicManager.Reset();
mapManager.GetMap().AttachEvent("onclick", showPopupMenu);
}

function drawPoint() {
mapManager.GetMap().DetachEvent("onclick", showPopupMenu);
hidePopupMenu();
selectDrawButton('drawPointBtn');
graphicManager.DrawPoint();
}

function drawPolyline() {
mapManager.GetMap().DetachEvent("onclick", showPopupMenu);
hidePopupMenu();
selectDrawButton('drawPolylineBtn');
graphicManager.DrawPolyline();
}

function drawPolygon() {
mapManager.GetMap().DetachEvent("onclick", showPopupMenu);
hidePopupMenu();
selectDrawButton('drawPolygonBtn');
graphicManager.DrawPolygon();
}

function drawCircle() {
mapManager.GetMap().DetachEvent("onclick", showPopupMenu);
hidePopupMenu();
selectDrawButton('drawCircleBtn');
graphicManager.DrawCircle();
}

function resizeMap() {  
var mapContainer = getById("mapContainer");
if(mapContainer)
{ 
var currWidth = parseInt(mapContainer.offsetWidth); 
var currHeight = parseInt(mapContainer.offsetHeight);
if(mapManager)
{  
mapManager.ResizeTo(currWidth, currHeight);
//widthFix();
}
}
}

//### POPUP MENU ######
function showPopupMenu(e) {
if (e.rightMouseButton) {
var pixel = new VEPixel(e.mapX, e.mapY);
currentPositionOnClickEvent = mapManager.GetMap().PixelToLatLong(pixel); 
var menu = getById('popupmenu');
menu.style.display='block';
menu.style.left = e.mapX + mapManager.GetMap().GetLeft() + "px"; 
menu.style.top = e.mapY + mapManager.GetMap().GetTop() + "px";
}
}

function hidePopupMenu() {
closeElement('directPageLinkPanel');
closeElement('popupmenu');
}

function prepMenu() {
var items = getById("popupmenu").getElementsByTagName('li');
for (i=0; i<items.length; i++) {
node = items[i];
if(node.nodeName=="LI"){      
node.onmouseover = function(){this.className += " over";} //Show the submenu
node.onmouseout=function(){this.className = (this.className.indexOf('pmenu') > 0 ? "pmenu" : "");}     
}
}
}
//######## END POPUP MENU ############

function createBookmarkLink() {
title = document.title;
url = location.href;  
if (window.sidebar){// Mozilla Firefox
window.sidebar.addPanel(title, url, "");
return;
}   
else if( window.external ) {// IE Favorite        
window.external.AddFavorite( url, title);
return;
}
else if(window.opera && window.print) {// Opera Hotlist
var mbm = document.createElement('a');
mbm.setAttribute('rel', 'sidebar');
mbm.setAttribute('href', url);
mbm.setAttribute('title', title);
mbm.click();
return;
}
alert("Sorry, your browser does not support this function.");
}

function clearText(indexElement){
var element = getById("address_" + indexElement);
if(element.value != "" && element.value != MESSAGES['commons.label.defaulttextobjaddress']) 
clearTextBox("address_" + indexElement);
checkText(indexElement);
}    

//###################### RouteCallback #####################
function ShowTurns(route) {
//informazioni itinerario completo
var distanceUnit = (mapManager.GetRouteDistanceUnit() != "Mile" ? " km" : " mi");
var content = "";
/*
content += "<p><strong>Informazioni sull'itinerario:</strong></p>";
content += "<ul>";
content += "<li><strong>Distanza totale:</strong> " + route.Distance.toFixed(1) + " " + distanceUnit + "</li>";   
content += "<li><strong>Tempo totale:</strong> " + getFormattedTime(route.Time) + "</li>";
content += "</ul>";
*/ 
for(i=0; i < route.RouteLegs.length; i++) {
//singolo itinerario
var leg = route.RouteLegs[i];  

var contentItinerary = "";  
//######### first step ################
var step = leg.Itinerary.Items[0];    

var description = step.Text + ((step.Distance == null || step.Distance.toFixed(1) == 0.0) ? "" : " - <em>" + step.Distance.toFixed(1) + distanceUnit + "</em>")
+ ((step.Time == null || step.Time == 0) ? "" : " - Tempo: " + getFormattedTime(step.Time));

var footerDescription = "<p><br/><small><a href=\"javascript:mapManager.ShowShapeByID('" + step.Shape.GetID() + "');\">&raquo; Visualizza punto</a>";
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[1].Shape.GetID() + "');\">&raquo; Visualizza successivo</a>"; 
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[leg.Itinerary.Items.length - 1].Shape.GetID() + "');\">&raquo; Visualizza arrivo</a></small></p>";
footerDescription += "<br/><a class=\"linkSave\" href=\"javascript:addAddressToPoiUser(1);\">" + MESSAGES['lbl.savetopoiuser'] + "</a>";
step.Shape.Title = "<strong>" + mapManager.GetDeparture() + "</strong>";
step.Shape.Notes = '<br/>' + description + footerDescription; 
contentItinerary += '<h3 class="departure">' + description + '</h3>';
//######### end first step ################

//######### step[i] ################
contentItinerary += "<ol>";
for(j=1; j < leg.Itinerary.Items.length - 1; j++) {                                
var step = leg.Itinerary.Items[j];        

var description = step.Text + ((step.Distance == null || step.Distance.toFixed(1) == 0.0) ? "" : " - <em>" + step.Distance.toFixed(1) + distanceUnit + "</em>") 
+ ((step.Time == null || step.Time == 0) ? "" : " - Tempo: " + getFormattedTime(step.Time));    

var footerDescription = "<p><br/><small><a href=\"javascript:mapManager.ShowShapeByID('" + step.Shape.GetID() + "');\">&raquo; Visualizza punto</a>";
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[j+1].Shape.GetID() + "');\">&raquo; Visualizza successivo</a>";
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[j-1].Shape.GetID() + "');\">&raquo; Visualizza precedente</a></small></p>";

step.Shape.Title = "<strong>Punto " + j + "</strong>";
step.Shape.Notes = '<br/>' + description + footerDescription;
contentItinerary += "<li onmouseover=\"this.style.background='#E5F2C1';\" onmouseout=\"this.style.background='transparent';\" onclick=\"\">" + description + "</li>";
}
contentItinerary += "</ol>";
//######### end step[i] ################

//######### last step ################
var step = leg.Itinerary.Items[leg.Itinerary.Items.length -1];

var description = step.Text + ((step.Distance == null || step.Distance.toFixed(1) == 0.0) ? "" : " - <em>" + step.Distance.toFixed(1) + distanceUnit + "</em>") 
+ ((step.Time == null || step.Time == 0) ? "" : " - Tempo: " + getFormattedTime(step.Time)); 

var footerDescription = "<p><br/><small><a href=\"javascript:mapManager.ShowShapeByID('" + step.Shape.GetID() + "');\">&raquo; Visualizza punto</a>";
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[(leg.Itinerary.Items.length - 1)-1].Shape.GetID() + "');\">&raquo; Visualizza precedente</a>";
footerDescription += "<br/><a href=\"javascript:mapManager.ShowShapeByID('" + leg.Itinerary.Items[0].Shape.GetID() + "');\">&raquo; Visualizza partenza</a></small></p>";               
footerDescription += "<br/><a class=\"linkSave\" href=\"javascript:addAddressToPoiUser(2);\">" + MESSAGES['lbl.savetopoiuser'] + "</a>";
step.Shape.Title = "<strong>" + mapManager.GetArrival() + "</strong>";
step.Shape.Notes = '<br/>' + description + footerDescription;   
contentItinerary += '<h3 class="arrival">' + description + "</h3>";
//######### end last step ################

contentItinerary += "<p><strong>Informazioni sull'itinerario:</strong></p>";
contentItinerary += "<ul>";
contentItinerary += "<li><strong>Tipo itinerario:</strong> " + getById(ID_PREFERENCE).options[getById(ID_PREFERENCE).selectedIndex].text + "</li>";  
contentItinerary += "<li><strong>Distanza totale:</strong> " + leg.Distance.toFixed(1) + " " + distanceUnit + "</li>";   
contentItinerary += "<li><strong>Tempo totale:</strong> " + getFormattedTime(leg.Time) + "</li>";
contentItinerary += "</ul>";  
//contentItinerary += "<p><a class=\"print\" href=\"#\">Stampa l'itinerario</a> <a class=\"sendMail\" href=\"#\">Invia itinerario ad un amico</a></p>";

setInnerHTML(ID_ITINERARY, content + contentItinerary);
openElement(ID_ITINERARY);
hideWaitPanel();
}
}
//###################### end RouteCallback #####################

function showHideSelect(){getById('selectBox').className=(getById('selectBox').className=='selectBoxClose'?'selectBoxOpen':'selectBoxClose');}

function setAddress(idReference, address, useGoogleSearch) {
setTextBox('address_' + idReference, address);
getById('useGoogleSearch_' + idReference).value = (useGoogleSearch == null ? true : useGoogleSearch);
hidePoiUserPanel(); //usato per quando un utente dalla sua lista di indirizzi sceglie qualcosa;
checkText(idReference);
}  

//controlla lo stile della mappa prima di effettuare una ricerca;
function checkMapStyle() {
if(mapManager.GetMapStyle() == VEMapStyle.Birdseye){
mapManager.SetMapStyle(VEMapStyle.Shaded);
showScratchPad();
}
}

function showScratchPad(){setDisplayNone("miniMap");setDisplayBlock("scratchPad");}
function showMiniMap(){setDisplayBlock("miniMap");setDisplayNone("scratchPad");}

function manageOnBlurEvent(idElement) {
var element = getById(idElement);
if(idElement != "emailLogin") {
if(element.value == "")
setTextBox(idElement, MESSAGES['commons.label.defaulttextobjaddress'], '#BFBFBF');  
}
else {
if(element.value == "")
setTextBox(idElement, MESSAGES['lbl.emailregistration'], '#BFBFBF'); 
} 
}

function manageOnFocusEvent(idElement) {
var element = getById(idElement);
if(idElement != "emailLogin") {
if(element.value == MESSAGES['commons.label.defaulttextobjaddress'])
setTextBox(idElement, '', '');    
}
else {
if(element.value == MESSAGES['lbl.emailregistration'])
setTextBox(idElement, '', '');
}
element.focus();
}

function loadSetting(lat, lon, zoom) {
checkMapStyle();
setInnerHTML(ID_MAP_HEADER, MESSAGES['map.label.headermap']);
mapManager.GetMap().SetCenterAndZoom(new VELatLong(lat, lon), zoom);
}

function manageKeyEnter(evt, actionToEval){
var evt = (evt) ? evt : event;    
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if (charCode==13||charCode==3){
eval(actionToEval);
return false;
}  
return true;
}

function checkText(idTargetAddress) {
closeElement('addToPoiUser_'+idTargetAddress);
if(getById("address_1").value != MESSAGES['commons.label.defaulttextobjaddress'] && getById("address_1").value != "" && getById("address_2").value != MESSAGES['commons.label.defaulttextobjaddress'] && getById("address_2").value != "")
setInnerHTML("searchButton", MESSAGES['btn.searchitinerary']);
else
setInnerHTML("searchButton", MESSAGES['btn.searchaddress']); 

if(getById("address_" + idTargetAddress).value != "" && getById("address_" + idTargetAddress).value != MESSAGES['commons.label.defaulttextobjaddress'])
getById('clearButton_' + idTargetAddress).src = "images/ico_delete.gif";
else
getById('clearButton_' + idTargetAddress).src = "images/ico_cleardisable.gif";
}