﻿/// <reference path="VeJavaScriptIntellisenseHelper.js" />


var map						= null;
var currentPanel	= null;
var panels				= [];
var lastLatitude	= 0;
var lastLongitude	= 0;
var timerID				= null;
var options_have_changed = true;
var AutoMove        = false;
var timerTrafficID= null;
var timerPoiID		= null;
var timerLodID      = null;
var timerAccomodationTypesID=null;
var timerAvailableTourTypesID=null;
var CustomInfoBoxTimerID=null;
var bShowTours      = true;
var bAllowSearch    = false;
var rlat					=0;
var rlon					=0;
var obliqueAvailable	= false;
var obliqueActive			= false;
var waitControl=null;

var routeStartLatitude=0;
var routeStartLongitude=0;

var routeDestinationLatitude=0;
var routeDestinationLongitude=0;

var tmcShapeLayer=null;
var poiShapeLayer=null;
var accomodationShapeLayer=null;
var tourShapeLayer=null;
var tourlineShapeLayer=null;
var popupShape;
var le=0;
var counter=0;
var customShowMyMessageRefCount=0;
var customShowMyMessageTimerID=null;
var lastHighlightedPinID=null;
var lastHighlightedPinImageIndex=0;
var currentOnDemandID="";
var onDemandContentTimerID=null;
var isFirefox=false;

function GetWindowWidth(){var width=0;if(typeof(window.innerWidth)=='number'){width=window.innerWidth;}else if(document.documentElement&&document.documentElement.clientWidth){width=document.documentElement.clientWidth;}else if(document.body&&document.body.clientWidth){width=document.body.clientWidth;}if(!width||width<100){width=100;}return width;}
function GetWindowHeight(){var height=0;if(typeof(window.innerHeight)=='number'){height=window.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){height=document.documentElement.clientHeight;}else if(document.body&&document.body.clientHeight){height=document.body.clientHeight;}if(!height||height<100){height=100;}return height;}

function GetMap()
{

if (typeof(CustomPrePreStartup)=="function") CustomPrePreStartup();
var head = document.getElementsByTagName("head")[0];
var s = document.createElement('script');
s.id = 'VEScript';
s.type = 'text/javascript';
s.src = "http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=de-de";
head.appendChild(s);

setTimeout("DelayGetMap()",2000);
}   

function DelayGetMap()
{
	try 
	{
		
		// If the browser is Firefox get the version number
		var ffv ="";
		var ffn = "Firefox/"
		var ffp = navigator.userAgent.indexOf(ffn);
		if (ffp != -1)
		{ isFirefox=true;
		 ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
		 }
		// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
		if (ffv >= 1.5)
		{
		Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
		}
		map = new VEMap('divMap');
		ReplaceVEStrings();
		
	}
	catch(err)
	{

		if (le < 60)
		{
			le++;
			setTimeout("DelayGetMap()",1000);
		}
		else
		{
		alert("Das Virtual-Earth Modul konnte nicht geladen werden. Bitte führen Sie einen Reload aus.");
		}
		return;
	} 


	Body_OnLoad();  
}   

function ReplaceVEStrings()
{

L_DashboardBirdsEyeText_Text="Vogelperspektive aktivieren";
L_NavActionObliqueToolTip_Text="Auf Vogelperspektive umschalten";
L_NavActionShowObliqueToolTip_Text="Auf Vogelperspektive umschalten";
L_NavActionRoadToolTip_Text="Auf Straßenkarte umschalten";
L_NavActionAerialToolTip_Text="Auf Satellitenkarte umschalten";
L_NavActionHybridToolTip_Text="Auf Hybridkarte umschalten";
L_NavActionObliqueRotationToolTip_CW_Text="Kamera im Uhrzeigersinn rotieren";
L_NavActionObliqueRotationToolTip_CCW_Text="Kamera gegen den Uhrzeigersinn rotieren";
}
// ----------------------------------------------------------------------------
function Body_OnLoad()
{
var i=0;
if (document.getElementById("RoutingPanel")!=null)		{panels[i] = document.getElementById("RoutingPanel");i++;}
if (document.getElementById("LodgingPanel")!=null)	{panels[i] = document.getElementById("LodgingPanel");i++;}
if (document.getElementById("RentacarPanel")!=null)	{panels[i] = document.getElementById("RentacarPanel");i++;}
if (document.getElementById("TopicPanel")!=null)			{panels[i] = document.getElementById("TopicPanel");i++;}
if (document.getElementById("WeatherPanel")!=null)		{panels[i] = document.getElementById("WeatherPanel");i++;}
if (document.getElementById("TrafficPanel")!=null)		{panels[i] = document.getElementById("TrafficPanel");i++;}
if (document.getElementById("TourPanel")!=null)				{panels[i] = document.getElementById("TourPanel");i++;}
if (document.getElementById("HolidayPlanerPanel")!=null)				{panels[i] = document.getElementById("HolidayPlanerPanel");i++;}

if (typeof(CustomPreStartup)=="function") CustomPreStartup();
try
{
if (typeof(PostStartup)=="function") PostStartup();
}catch(e){}

tmcShapeLayer=new VEShapeLayer();
map.AddShapeLayer(tmcShapeLayer);

poiShapeLayer=new VEShapeLayer();
map.AddShapeLayer(poiShapeLayer);

accomodationShapeLayer=new VEShapeLayer();
map.AddShapeLayer(accomodationShapeLayer);

tourShapeLayer=new VEShapeLayer();
map.AddShapeLayer(tourShapeLayer);

tourlineShapeLayer=new VEShapeLayer();
map.AddShapeLayer(tourlineShapeLayer);
if (typeof(CustomPostStartup)=="function") CustomPostStartup();


map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);	


map.AttachEvent("onchangemapstyle", Map_OnChangeMapStyle);
map.AttachEvent("onchangeview", Map_OnChangeView);
map.AttachEvent("onclick",ToggleMenu);
map.AttachEvent("onmousedown",Map_OnMouseDown);
map.AttachEvent("onmouseover",Map_OnMouseOver);
map.AttachEvent("onmouseout",Map_OnMouseOut);
map.AttachEvent('oninitmode', ChangeMode);
 
if (typeof (WebForm_CallbackComplete) == "function")
{
 WebForm_CallbackComplete =  WebForm_CallbackComplete_SyncFixed
}
Body_OnResize();
AddMyControl();


ReplaceVEStrings();
}

// ----------------------------------------------------------------------------
function Map_OnMouseDown(e)
{

if (typeof(CustomMouseDown)=="function") CustomMouseDown();
try{var latlong=map.PixelToLatLong(new VEPixel(e.mapX,e.mapY));rlat=latlong.Latitude;rlon=latlong.Longitude;}catch(ex){}
if (e.elementID!=null)
{
popupShape=map.GetShapeByID(e.elementID);
DoFindOnDemandContent(popupShape.Id);
map.HideInfoBox();
}
else HideCustomInfoBox();
}
function Map_OnMouseOver(e){}
function Map_OnMouseOut(e){}

 
 
 //---------------------------------
function AddAJAXPin(layer,pinID,latlon, iconUrl, iconStyle)
{
var pin = new VEShape(VEShapeType.Pushpin,latlon);
//pin.SetDescription("...");
pin.SetCustomIcon(iconUrl);
pin.Id=pinID;
layer.AddShape(pin);
return(pin.GetID());
} 

// ----------------------------------------------------------------------------
function ShowPinProgressBar(shape)
{
var latlong=shape.GetPoints();
var px=map.LatLongToPixel(latlong[0]);
$("#PinProgressBar").css("left",px.x+map.GetLeft()-10).css("top",px.y+map.GetTop()-8).css("display","block");
}

function HidePinProgressBar(){$("#PinProgressBar").css("display","none");}


// ----------------------------------------------------------------------------
function Map_OnChangeMapStyle(e)
{
if (map.GetMapStyle()==VEMapStyle.Road)
{
map.DetachEvent("onchangemapstyle", Map_OnChangeMapStyle);
map.SetMapStyle(VEMapStyle.Shaded);
map.AttachEvent("onchangemapstyle", Map_OnChangeMapStyle);
}
}
// ----------------------------------------------------------------------------
function Map_OnChangeView(e)
{
if (typeof(CustomOnChangeView)=="function"){CustomOnChangeView();return;}


if(AutoMove == false){    
try
{
var center=map.GetCenter();
if (center.Latitude!=lastLatitude||center.Longitude!=lastLongitude)
{
lastLatitude=center.Latitude;
lastLongitude=center.Longitude;
if (timerID!=null)
window.clearTimeout(timerID);
if (map.GetMapStyle()!="o")
if (document.getElementById("WeatherPanel")!=null)
timerID = window.setTimeout("DoFindWeather()",2000);
}
}catch (e){}
	
try
{
// update traffic data
if (timerTrafficID!=null)
window.clearTimeout(timerTrafficID);

if (document.getElementById("TrafficPanel")!=null)
if (map.GetMapStyle()!="o")
timerTrafficID = window.setTimeout("DoFindTmc()",2000);
}catch (e){}

// update poi data	
try
{

if (timerPoiID!=null)window.clearTimeout(timerPoiID);
if (map.GetMapStyle()!="o")
timerPoiID=window.setTimeout("DoFindPois()",2000);
}catch (e){}

options_have_changed = true;
// update lodging data	
try{
    if(bShowLodging){        
        if (timerLodID!=null)window.clearTimeout(timerLodID);
        if (map.GetMapStyle()!="o")
            timerLodID=window.setTimeout("DoFindLodging()",2000);                    
    }
}catch (e){}	
	CenterMessage();		
}
AutoMove = false;


}



// ----------------------------------------------------------------------------
function Body_OnResize()
{
if (typeof (CustomBodyOnResize) == "function"){
    CustomBodyOnResize();    
}
else{
var o;
var width;
var height;
var x;
var y;
try{
// layouttabelle resizen
document.getElementById(layoutTableClientID).style.height=(GetWindowHeight()-layoutTableVOffset) + "px";
document.getElementById(contentLayoutTableClientID).style.height=(GetWindowHeight()-(contentToBodyOffset)) + "px";
// Karte resizen
width = GetWindowWidth()-panelClosedOffset;
if (document.getElementById(panelContainerTableClientID).style.display!="none") width=GetWindowWidth()-panelOpenOffset;
map.Resize(width,GetWindowHeight()-mapToBodyOffset);
//map.Resize(width,GetWindowHeight()-contentToBodyOffset);
ShowPanel(currentPanel);
}catch (e) {}
}
}


function delay(gap){
 var then,now;
 then=new Date().getTime();
 now=then;
 while((now-then)<gap) {
  now=new Date().getTime();
 }
}


// ----------------------------------------------------------------------------
function ShowPanel(name,setAsCurrent)
{

	if(typeof(CustomShowPanel)=="function")
	{
	CustomShowPanel(name,setAsCurrent);
	return;
	}
	var visiblePanels = 0;	
	var yRunner				= 104;
	var allHeight			= 0;	
		
	if (setAsCurrent==true)
		currentPanel = name;
    
	// sichtbare Panels zählen	
	for(var ii = 0;ii<panels.length;ii++)
	{
		if (panels[ii].style.display=="block")
			visiblePanels++;
	}

	if (document.getElementById(name)!=null)
		if (document.getElementById(name).style.display=="none")
			visiblePanels++;

	allHeight=GetWindowHeight()-panelVOffset;//116;//+60;//-(96+32);

	var lastVisiblePanel=null;
	
	for(var ii=0;ii<panels.length;ii++)
	{
		panels[ii].style.top=yRunner + "px";
		panels[ii].style.height="24px";
		panels[ii].style.left=4;

		
		if (panels[ii].id==name)
		{	
			panels[ii].style.height=(allHeight-((visiblePanels)*28))+"px";
			panels[ii].style.display="block";
			yRunner+=(allHeight-((visiblePanels)*28));
		}
		else 
		{
			if (panels[ii].style.display=="block")
				yRunner+=28;
		}
		if (panels[ii].style.display!="none")
		{
		lastVisiblePanel=panels[ii];
		lastVisiblePanel.style.marginBottom="4px";		
		}
	}
	
	if (lastVisiblePanel!=null)
	lastVisiblePanel.style.marginBottom="0px";


	// Dashboard positionieren
	// sichtbare Panels zählen
	for(var ii = 0;ii<panels.length;ii++)
	{
		if (panels[ii].style.display=="block")
			visiblePanels++;
	}

	if (document.getElementById("AdPanel")!=null)
	{
		document.getElementById("AdPanel").style.left	= (visiblePanels==0 ? "4px" : "268px");
	
		if (obliqueAvailable==false&&obliqueActive==false)	document.getElementById("AdPanel").style.top		= "194px";	
		if (obliqueAvailable==true&&obliqueActive==false)	document.getElementById("AdPanel").style.top		=  "260px" ;	
		if (obliqueAvailable==true&&obliqueActive==true)		document.getElementById("AdPanel").style.top		= "380px";	
	}
}

// ----------------------------------------------------------------------------
function HidePanel(name)
{
	document.getElementById(name).style.display = "none";
	
	for(var ii = 0;ii<panels.length;ii++)
	{
		if (panels[ii].style.display=="block")
		{
			ShowPanel(panels[ii].id,true);		
			return;
		}
	}
	
	ShowPanel(null,true);
	
	HidePanelContainer();
}

// ----------------------------------------------------------------------------
function ReceiveLanguage(arg)
{
return;
	var languageRows=arg.split('\n');
	var languageColumns;
	var objects;


	// Bezeichnungen austauschen
	for(var ii=0;ii<languageRows.length-1;ii++)
	{
		languageColumns = languageRows[ii].split(',');
		languageColumns[1]=languageColumns[1].substring(0,languageColumns[1].length-1);
		
		objects=document.getElementsByName(languageColumns[0]);
		if (objects.length!=0)
		for(var j=0;j<objects.length;j++)
			{
				try
					{
						objects[j].innerHTML=languageColumns[1];
					}
					catch (e)
					{
						try
						{
							objects[j].innerText=languageColumns[1];
						}
						catch (e)
						{
							try
							{
								objects[j].value=languageColumns[1];
							}
							catch (e){ }
						}
					}			
			}
	
		//
		//
		var o=document.getElementById(languageColumns[0]);
		if (o!=null)
		o.innerText=languageColumns[1];
	}
	
try
{
document.getElementById('RouteDayLabel').innerHTML= DisplayWeekDay('cboRouteStartDay','cboRouteStartMonth','cboRouteStartYear');
document.getElementById('FlightDayLabel').innerHTML= DisplayWeekDay('cboFlightStartDay','cboFlightStartMonth','cboFlightStartYear');
document.getElementById('RailRoadDayLabel').innerHTML= DisplayWeekDay('cboRailRoadStartDay','cboRailRoadStartMonth','cboRailRoadStartYear');
document.getElementById('DayLabel').innerHTML= DisplayWeekDay('cboStartDay','cboStartMonth','cboStartYear');
}catch(e){}	
	// Watermarks neu setzen, wenn Textfeld leer
	//CheckShowWatermark(document.getElementById("txtStreet"),document.getElementById('LocationStreetWatermarkText').value);
	//CheckShowWatermark(document.getElementById("txtZipcode"),document.getElementById('LocationZipcodeWatermarkText').value);
	//CheckShowWatermark(document.getElementById("txtCity"),document.getElementById('LocationCityWatermarkText').value);
	
	
}

//-------------------------------------------------------------------------------------
function HighlightPushpin(id, isHighlighted)
{ return;
	for(var ii=0;ii<map.pushpins.length;ii++)
	{
		if (map.pushpins[ii].ID==id)
		{
			var title=map.pushpins[ii].Title;
			var details=map.pushpins[ii].Details;
			var lat=map.pushpins[ii].LatLong.Latitude;
			var lon=map.pushpins[ii].LatLong.Longitude;
			var iconurl=map.pushpins[ii].Iconurl;
			
			map.DeletePushpin(id);
			iconurl=iconurl.substring(0,iconurl.indexOf('.') -(isHighlighted==true ? 0 : 1)) +
																 (isHighlighted==true ? "h" : "") +
																 iconurl.substring(iconurl.indexOf('.'));
			var pin=new VEPushpin(id,new VELatLong(lat,lon),iconurl,title,details);  
			map.AddPushpin(pin);
			return;
		}
	}
}


function Pause(millis) 
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); } 
while(curDate-date < millis);
} 

function SwapContent(name1,name2)
{
var o1=document.getElementById(name1);
var o2=document.getElementById(name2);
var s=o1.value;
o1.value=o2.value;
o2.value=s;
	
}




function removepopupmenu(e)
{
  var menu = document.getElementById('popupmenu').style.display='none';
}

function ToggleMenu(e)
{
if (e.leftMouseButton==true) hidemenu(e);if (e.rightMouseButton==true) popupmenu(e);
//document.getElementById('idgeo').value = e.latLong.Latitude + "," + e.latLong.Longitude;;

}

function popupmenu(e)
{
var menu = document.getElementById('popupmenu');
menu.style.display='block';
menu.style.left = window.event.clientX-60;
menu.style.top = window.event.clientY-30;
}

function hidemenu(e)
{
try
{
var menu = document.getElementById('popupmenu');
menu.style.display='none';
rlat=e.view.LatLong.Latitude;
rlon=e.view.LatLong.Longitude;
}catch (e) {}
}


function TogglePanelContainer()
{
	var p;
	var visiblePanels=GetVisiblePanelCount();

	p = document.getElementById(panelContainerTableClientID);
	

	if (visiblePanels>0)
		p.style.display=(p.style.display=="" ? "none" : "");
	else 
		p.style.display="none";

	Body_OnResize();
}

function ShowPanelContainer()
{
	var p;	
	p = document.getElementById(panelContainerTableClientID);
	
	p.style.display="";
	
	p = document.getElementById(panelContainerTableCellClientID);
	
	if (p!=null) p.style.display="";

	Body_OnResize();
}

function HidePanelContainer()
{
	var p;
	var visiblePanels=GetVisiblePanelCount();
	
	if (visiblePanels>0) return;

	p = document.getElementById(panelContainerTableClientID);
	
	p.style.display="none";
	
	p = document.getElementById(panelContainerTableCellClientID);
	
	if (p!=null) p.style.display="none";

	Body_OnResize();
}


function GetVisiblePanelCount()
{
	var visiblePanels=0;

	for(var ii = 0;ii<panels.length;ii++)
	{
		if (panels[ii].style.display=="block")
			visiblePanels++;
	}
	
	return visiblePanels;
}

var msgControl;

function AddMyControl()
{
	msgControl = document.createElement("div");
	msgControl.style.top ="10px";
	msgControl.style.left = "10px";
	msgControl.style.width = "240px";
	msgControl.style.height = "120px";
	msgControl.style.zIndex="32000";
	
	msgControl.style.border = "2px solid black";
	msgControl.style.background = "#FFFFE6";
	msgControl.style.backgroundImage="url(images/ResultPageHeaderBackground.gif)";
	msgControl.style.backgroundRepeat="repeat-x";
	msgControl.style.fontFamily="Arial";
	msgControl.style.fontSize="12px";
	msgControl.style.padding="8px";
	msgControl.id="";
	
	msgControl.innerHTML = "...";
	msgControl.style.display="none";
	map.AddControl(msgControl);
	
	
	
	waitControl = document.createElement("div");
	waitControl.style.top ="10px";
	waitControl.style.left = "10px";
	waitControl.style.width = "32px";
	waitControl.style.height = "32px";
	waitControl.style.zIndex="32000";
	//waitControl.style.border = "2px solid black";
	//waitControl.style.background = "#FFFFE6";
	waitControl.style.backgroundImage="url(images/img_loading_orange.gif)";
	waitControl.id="waitControl";
	
	waitControl.innerHTML = "";
	waitControl.style.display="none";
	map.AddControl(waitControl);
	
	//map.AddControl(document.getElementById("imgCross"));
}

//-------------------------------------------------------------------------------------
function ShowMyMessage()
{
	if (typeof(CustomShowMyMessage)=="function")
		CustomShowMyMessage();
	else
	{
    if(arguments[1]){
        arguments[1].innerHTML="<br><span style='width:400px; padding-left:70px;' class='StdTextGray'>" + arguments[0] + "</span>";
    }
    else{
        msgControl.innerHTML="<table width='100%'><tr><td align='right'><img src='images/x.gif' style='cursor:hand' onclick='HideMessage()'/></td></tr></table>" + arguments[0];
	
	    CenterMessage();

	    msgControl.style.display="";
    }	
  }
}

//-------------------------------------------------------------------------------------
function HideMessage()
{
	msgControl.style.display="none";
}


//-------------------------------------------------------------------------------------
function CenterMessage()
{

 var mapWidth		= document.getElementById("divMap").style.posWidth;
 var mapHeight	= document.getElementById("divMap").style.posHeight;

 var messageWidth		= msgControl.style.posWidth;
 var messageHeight	=msgControl.style.posHeight;

 
 msgControl.style.left=(GetWindowWidth()-messageWidth)/2;
 msgControl.style.top=(GetWindowHeight()-messageHeight)/2;
 
}


function ShowWaitControl(){CenterWaitConrol();waitControl.style.display="";}
function HideWaitControl(){waitControl.style.display="none";}
function CenterWaitConrol(){ waitControl.style.left=GetWindowWidth()-72; waitControl.style.top=GetWindowHeight()-112;}

function EventHandlerOnClick(e)
{

	if (e!=null)
	{
			try{document.getElementById(e.currentTarget.id + "_" + map.GUID).onmouseover();} catch (e){}
	} else
	{
			document.getElementById(window.event.srcElement.id).onmouseover();
	}
}



// ----------------------------------------------------------------------------
function CreateExtendedDetailsPanel(id)
{
	var divExtendedDetails;
	var width=(extendedDetailsPanelWidth!=null ? extendedDetailsPanelWidth : 800);
	var height=(extendedDetailsPanelHeight!=null ? extendedDetailsPanelHeight : 600);
	divExtendedDetails=document.getElementById("divExtendedDetails");
	// "<input type='button' onclick='this.parentNode.style.display=\"none\"' value=\"x\" />"+
	divExtendedDetails.innerHTML="<iframe src='ExtendedDetails.aspx?ID=" + id + "' width='" + width + "px' height='" + height + "' frameborder='0' scrolling='no'></iframe>";
	
	divExtendedDetails.style.left=(GetWindowWidth()-width)/2;
	divExtendedDetails.style.top=(GetWindowHeight()-height)/2;
	if (divExtendedDetails.style.posTop<0)
		divExtendedDetails.style.top=0;
		
	divExtendedDetails.style.width=width;
	divExtendedDetails.style.height=height;
	divExtendedDetails.style.display="block";
	
	$("#divModalOverlay").css("width",GetWindowWidth()).css("height",GetWindowHeight()).css("display","block").css("opacity","0").fadeTo("normal",0.7);

	HideCustomInfoBox();

}


function CreateExtendedDetailsTourPanel(id)
{
	var divExtendedDetails;
	var width=(extendedDetailsPanelWidth!=null ? extendedDetailsPanelWidth : 800);
	var height=(extendedDetailsPanelHeight!=null ? extendedDetailsPanelHeight : 600);
	divExtendedDetails=document.getElementById("divExtendedDetails");
	// "<input type='button' onclick='this.parentNode.style.display=\"none\"' value=\"x\" />"+
	divExtendedDetails.innerHTML="<iframe src='ExtendedTourDetails2.aspx' width='" + width + "px' height='" + height + "px' frameborder='0' scrolling='no'></iframe>";
	
	divExtendedDetails.style.left=(GetWindowWidth()-width)/2;
	divExtendedDetails.style.top=(GetWindowHeight()-height)/2;
	if (divExtendedDetails.style.posTop<0)
		divExtendedDetails.style.top=0;
		
	divExtendedDetails.style.width=width;
	divExtendedDetails.style.height=height;
	divExtendedDetails.style.display="block";
}


function TranslateRouteInstruction(t)
{
return t;
try
{
t=t.replace(/Turn LEFT/,"LINKS Abbiegen");
t=t.replace(/Turn RIGHT/,"Rechts Abbiegen");
t=t.replace(/Keep LEFT/,"LINKS Bleiben");
t=t.replace(/Keep RIGHT/,"RECHTS Bleiben");
t=t.replace(/Bear LEFT/,"LINKS Halten");
t=t.replace(/Bear RIGHT/,"RECHTS Halten");
t=t.replace(/Keep STRAIGHT/,"GERADEAUS Halten");
t=t.replace(/onto Ramp/,"auf Auffahrt");
t=t.replace(/Road name changes to/,"Strassenname wechselt auf");
t=t.replace(/onto /,"auf ");
t=t.replace(/\(North-West\)/i,"(Nordwest)");
t=t.replace(/\(NorthWest\)/i,"(Nordwest)");
t=t.replace(/\(North-East\)/i,"(Nordost)");
t=t.replace(/\(NorthEast\)/i,"(Nordost)");
t=t.replace(/\(South-West\)/i,"(S&uumldwest)");
t=t.replace(/\(SouthWest\)/i,"(S&uumldwest)");
t=t.replace(/\(South-East\)/i,"(S&uumldost)");
t=t.replace(/\(SouthEast\)/i,"(S&uumldost)");
t=t.replace(/\(West\)/i,"(Westen)");
t=t.replace(/\(East\)/i,"(Osten)");
t=t.replace(/\(North\)/i,"(Norden)");
t=t.replace(/\(South\)/i,"(S&uumlden)");
t=t.replace(/Depart on/i,"Abfahrt von");
t=t.replace(/Depart  on/i,"Abfahrt von");
t=t.replace(/Depart   on/i,"Abfahrt von");
t=t.replace(/Arrive at/i,"Ankunft an");
t=t.replace(/Local road\(s\)/i,"lokale Strasse");
}catch(e){}
return t;
}


function OpenPrintPage()
{
var center=map.GetCenter();
var zoomLevel=map.GetZoomLevel();
var mapStyle=map.GetMapStyle();
var routeStart=document.getElementById("txtRouteStart").value;
var routeEnd=document.getElementById("txtRouteEnd").value;
if (routeStart.indexOf("Startpunkt aus Karte")==0)
		routeStart="Geo:"+routeStartLatitude + ","+routeStartLongitude;

if (routeEnd.indexOf("Zielpunkt aus Karte")==0)
		routeEnd="Geo:"+routeDestinationLatitude + ","+routeDestinationLongitude;


window.open("http://80.148.41.197/PrintMap/PrintPage.aspx?Latitude=" + center.Latitude + "&Longitude=" + center.Longitude + "&ZoomFactor=" + zoomLevel + "&MapStyle=" + mapStyle + "&RouteStart=" + routeStart + "&RouteEnd=" + routeEnd,"","","");
}


//-------------------------------------------------------------------------------------
// 
function SetRouteStart(lat,lon)
{
routeStartLatitude=lat;
routeStartLongitude=lon;
document.getElementById("txtRouteStart").value="Startpunkt aus Karte";
try{map.DeletePushpin("ROUTESTARTMARKER");} catch (e) {}
var pin = new VEPushpin("ROUTESTARTMARKER" ,new VELatLong(lat,lon),"images/mapicon_start.gif","");
map.AddPushpin(pin);
ShowPanel("RoutingPanel",true);
ShowPanelContainer();
}

//-------------------------------------------------------------------------------------
// 
function SetRouteEnd(lat,lon)
{
routeDestinationLatitude=lat;
routeDestinationLongitude=lon;
document.getElementById("txtRouteEnd").value="Zielpunkt aus Karte";
try{map.DeletePushpin("ROUTEENDMARKER");} catch (e) {}
var pin = new VEPushpin("ROUTEENDMARKER" ,new VELatLong(lat,lon),"images/mapicon_end.gif","");
map.AddPushpin(pin);
ShowPanel("RoutingPanel",true);
ShowPanelContainer();
}

//-------------------------------------------------------------------------------------
// 
function btnFindRoute_onclick()
{
var routeType;
var start;
var end;
	

routeType =	VERouteType.Quickest;
start=document.getElementById("txtRouteStart").value;
if (start.indexOf("Startpunkt aus Karte")==0) start=new VELatLong(routeStartLatitude,routeStartLongitude);
end=document.getElementById("txtRouteEnd").value;
if (end.indexOf("Zielpunkt aus Karte")==0) end=new VELatLong(routeDestinationLatitude,routeDestinationLongitude);

if (start==""||end==""||start==" "||end==" "){alert("Sie müssen einen Start- und Zielpunkt angeben.");return;}
try
{
map.DeletePushpin("ROUTESTARTMARKER");
map.DeletePushpin("ROUTEENDMARKER");
} catch (e) {}

ShowWaitControl();
var locations = new Array(start,end);
var options = new VERouteOptions;
options.DrawRoute=true;
options.SetBestMapView = false;
options.RouteCallback  = onGotRoute;
options.DistanceUnit   = VERouteDistanceUnit.Kilometer;
options.ShowDisambiguation = true;
options.RouteMode= ($("#cbWalkingMode").attr("checked")==true ? VERouteMode.Walking : VERouteMode.Driving);
map.GetDirections(locations,options);
}


function WebForm_CallbackComplete_SyncFixed()
{
for (var i = 0; i < __pendingCallbacks.length; i++)
{
callbackObject = __pendingCallbacks[i];
if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4))
{
if (!__pendingCallbacks[i].async){__synchronousCallBackIndex = -1;}
__pendingCallbacks[i] = null;
var callbackFrameID = "__CALLBACKFRAME" + i;
var xmlRequestFrame = document.getElementById(callbackFrameID);
if (xmlRequestFrame){xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);}
WebForm_ExecuteCallback(callbackObject);
}
}
}



function ShowPopup(parent,name)
{
try{
var x,y;
x=parent.offsetLeft;
y=parent.offsetTop+parent.offsetHeight;
while(parent.offsetParent!=null)
{
parent=parent.offsetParent;
if (parent.offsetLeft!=NaN) x+=parent.offsetLeft;
if (parent.offsetTop!=NaN) y+=parent.offsetTop;
}
var o=document.getElementById(name);
o.style.left=x;
o.style.top=y-(map.GetMapMode()==2 ? 120 : 0);
o.style.display="";
}catch(e){}
}

function HidePopup(name)
{
var o=document.getElementById(name);
o.style.display="none";
}

function switchme(){
    map.SetMapMode(VEMapMode.Mode3D);
}



// Date functions
function CheckDate(ry,rm,rd)
{
var d=document.getElementById(rd).value;var m=document.getElementById(rm).value;var y=document.getElementById(ry).value;
if (IsDateInPast(y,m,d))
{
	SetActualDate(ry,rm,rd);
	var o= new Date();
	y=o.getYear();
	m=o.getMonth()+1;
	d=o.getDate();
}
o=document.getElementById(rd);
if(!IsDateValid(y,m,31)) o.options[30]=null;else if (o.options[30]==null) o.options[30]=new Option(31,31,false,false);
if(!IsDateValid(y,m,30)) o.options[29]=null;else if (o.options[29]==null) o.options[29]=new Option(30,30,false,false);
if(!IsDateValid(y,m,29)) o.options[28]=null;else if (o.options[28]==null) o.options[28]=new Option(29,29,false,false);
DisplayWeekDay(rd,rm,ry);
}
function IsDateValid(y,m,d){var r;if (IsFirefox()==true) r=IsDateValidFirefox(y,m,d);else r= IsDateValidIE(y,m,d);return r;}
function IsDateValidIE(y,m,d){var o=new Date(y,m-1,d);return (o.getDate()==d&&o.getMonth()==m-1&&o.getYear()==y)?true:false;}
function IsDateValidFirefox(y,m,d){var o=new Date(y,m-1,d);return (o.getDate()==d&&o.getMonth()==m-1&&(o.getYear()+1900)==y) ? true:false;}
function IsFirefox(){var f=navigator.userAgent.indexOf("Firefox/");if (f!=-1) return true;return false;}
function IsDateInPast(y,m,d){var o=new Date();if (y<o.getYear()) return true;if (m-1<o.getMonth()) return true;if (d<o.getDate()) if (m-1==o.getMonth()) return true;return false;}
function SetActualDate(ry,rm,rd){var o=new Date();document.getElementById(ry).value=o.getYear();document.getElementById(rm).value=o.getMonth()+1;document.getElementById(rd).value=o.getDate();}


function DisplayWeekDay(cboDay,cboMonth,cboYear)
{
var u=document.getElementById("HiddenDays").value;

	var day = u.split(' ');
	var d		= document.getElementById( cboDay).value;
	var m		= document.getElementById(cboMonth).value;
	var y		= document.getElementById(cboYear).value;

  if (m < 3)
  {
   m = Number(m) + 12;
   y = Number(y) - 1;
  }

   w = (Number(y) + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) + Math.floor(2.6 * Number(m) + 1.6) + Number(d)) % 7;
  return day[w];
}


function DoFindAvailableAccomodationTypes()
{
var v=map.GetMapView();
FindAvailableAccomodationTypes(v.TopLeftLatLong.Latitude + "^" + v.TopLeftLatLong.Longitude + "^" + v.BottomRightLatLong.Latitude + "^" + v.BottomRightLatLong.Longitude);
}

function ReceiveAvailableAccomodationTypes(arg)
{
var accomodationTypes=arg.split('^');
var o=document.getElementById(lodgingPanelClientID + "_cboLodgingType");
if (o==null)
 o=document.getElementById("cboLodgingType");
if (o==null) return;
var oldValue=o.value;
o.options.length=1;
for(var i=0;i<accomodationTypes.length;i++)
o.options[i+1]=new Option(accomodationTypes[i],accomodationTypes[i],false,(accomodationTypes[i]==oldValue ? true : false));
}


//-------------------------------------------------------------------------------------
function GetShapeById(shapeLayer,id){var l=shapeLayer.Annotations.length;for(var i=0;i<l;i++) if (shapeLayer.Annotations[i].Id==id) return shapeLayer.Annotations[i];return null;}
function ShowPoiDetails(id){popupShape=GetShapeById(poiShapeLayer,id);DoFindOnDemandContent(id);}
function ShowAccomodationDetails(id){popupShape=GetShapeById(accomodationShapeLayer,id);DoFindOnDemandContent(id);}

function DoFindOnDemandContent(id)
{
HidePinProgressBar();
currentOnDemandID=popupShape.Id;
ShowCustomInfoBox(popupShape,"<table style='width:210px;text-align:center;'><tr><td style='padding:32px'><img src='images/baw/ajax-loader.gif'/></td></tr></table>");
$.post("InfoBoxDetails.handler","ID="+id,ReceiveOnDemandContent);
}

function ReceiveOnDemandContent(arg)
{
if (arg!="")
{
var a=arg.substring(0,39);
var b=arg.substring(40);
if (a==currentOnDemandID)if (popupShape!=null) ShowCustomInfoBox(popupShape,b);map.HideInfoBox();}}




function ReceiveOnDemandContentOld(arg)
{
if (arg!="")
var a=arg.split('´');
if (a[0]==currentOnDemandID)
if (popupShape!=null) ShowCustomInfoBox(popupShape,a[1]);
map.HideInfoBox();
}

function DoFindOnDemandContentOld(id)
{
HidePinProgressBar();
currentOnDemandID=popupShape.Id;
ShowCustomInfoBox(popupShape,"<table style='width:210px;text-align:center;'><tr><td style='padding:32px'><img src='images/baw/ajax-loader.gif'/></td></tr></table>");
FindOnDemandContent(id);
}


function addshim(el,sid)  //add iframe shim       
{   
    if (map.GetMapMode() == VEMapMode.Mode3D)  
    {     
        var s = document.createElement("iframe");            
        s.id = sid;            
        s.frameBorder = "0";            
        s.style.position = "absolute";            
        s.style.zIndex = "1";  
        s.style.top  = el.offsetTop;            
        s.style.left = el.offsetLeft; 
        s.style.filter="Chroma(color=#ffffff)";
        s.width  = el.offsetWidth;            
        s.height = el.offsetHeight;
        s.allowtransparency = "true";  
        s.scrolling="no";
        s.className="Shim";
        el.shimElement = s;            
        el.parentNode.insertBefore(s, el);   
    }      
}

function removeshim(sid){var msh = document.getElementById(sid);if (msh!=null) msh.parentNode.removeChild(msh);msh = null;}
function ChangeMode(){if (map.GetMapMode() == VEMapMode.Mode3D){addshim(document.getElementById("CustomInfoBox"),"myCustomShim1");}else{removeshim("myCustomShim1");}}
function ShowCustomInfoBox(shape,text)
{

// set content
var boxBody=document.getElementById("CustomInfoBoxBody");
boxBody.innerHTML=text;

//calculate if the infobox appears to the left or to the right
o=document.getElementById("divMap");
var width=o.offsetWidth;
var latlong=shape.GetPoints();
var px=map.LatLongToPixel(latlong[0]);
var goLeft=true;
var goUp=true;
if (px.x<(width/2)) goLeft=false;
//(px + ", " + width/2);
//("goleft:"+goLeft);

var box=document.getElementById("CustomInfoBox");
var beak=document.getElementById("CustomInfoBoxBeak");

box.style.display="block";
if (goLeft==true)
{
	box.style.left=px.x-32+map.GetLeft()-box.offsetWidth+"px";
	beak.style.left=px.x+map.GetLeft()-32 + "px";
	beak.className="CustomInfoBoxBeakLeft";
}
else
{
	box.style.left=px.x+32+map.GetLeft()+"px";
	beak.style.left=px.x+map.GetLeft()+16+"px";
	beak.className="CustomInfoBoxBeakRight";
}

// calculate if its vertically centered or top aligned
var y=px.y+map.GetTop()-(box.offsetHeight/2);
if (y+box.offsetHeight>GetWindowHeight())
	y=px.y+map.GetTop()-box.offsetHeight+32;
box.style.top=y+"px";
beak.style.top=px.y+map.GetTop()-16+"px";

// 3d mode
if (map.GetMapMode() == VEMapMode.Mode3D) 
{
var shim=document.getElementById("myCustomShim1");
shim.style.left=box.offsetLeft+"px";
shim.style.top=box.offsetTop+"px";
shim.width=box.offsetWidth+"px";
shim.height=box.offsetHeight+"px";
shim.style.display="";
}
if (map.GetMapMode() != VEMapMode.Mode3D) beak.style.display="block";

}

function HideCustomInfoBox()
{
var o=document.getElementById("CustomInfoBox");
o.style.display="none";

o=document.getElementById("CustomInfoBoxBeak");
o.style.display="none";

if (map.GetMapMode() == VEMapMode.Mode3D) 
{
o=document.getElementById("myCustomShim1");
o.style.display="none";
}
}


function ExpandExtendedDetails(id,typ, sourceControl,tab)
{
	HideCustomInfoBox();
	
extendedDetailsTab=(tab==undefined ? 0 : tab);

extendedDetailsID=typ+id;
var box=document.getElementById("CustomInfoBox");
var extendedDetails=document.getElementById("divExtendedDetails");

if (sourceControl!=null)
{
var ev=window.event;
extendedDetails.style.left=ev.clientX;
extendedDetails.style.top=ev.clientY;
extendedDetails.style.width=sourceControl.offsetWidth;
extendedDetails.style.height=sourceControl.offsetHeight;
extendedDetailsLeft=ev.clientX;
extendedDetailsTop=ev.clientY;
extendedDetailsWidth=sourceControl.offsetWidth;
extendedDetailsHeight=sourceControl.offsetHeight;
}
else
{
extendedDetails.style.left=box.offsetLeft;
extendedDetails.style.top=box.offsetTop;
extendedDetails.style.width=box.offsetWidth;
extendedDetails.style.height=box.offsetHeight;

extendedDetailsLeft=box.offsetLeft;
extendedDetailsTop=box.offsetTop;
extendedDetailsWidth=box.offsetWidth;
extendedDetailsHeight=box.offsetHeight;
}
extendedDetails.innerHTML="";
extendedDetails.style.display="block";



//calc steps
var windowWidth=GetWindowWidth();
var windowHeight=GetWindowHeight();

var leftTarget=(windowWidth-extendedDetailsPanelWidth)/2;
var rightTarget=leftTarget+extendedDetailsPanelWidth;
var topTarget=(windowHeight-extendedDetailsPanelHeight)/2;
var bottomTarget=topTarget+extendedDetailsPanelHeight;

stepperLeft=(leftTarget-extendedDetailsLeft)/5.0;
stepperRight=(rightTarget-(extendedDetailsLeft+extendedDetailsWidth))/5.0;
stepperTop=(topTarget-extendedDetailsTop)/5.0;
stepperBottom=(bottomTarget-(extendedDetailsTop+extendedDetailsHeight))/5.0;
extendedDetailsAnimCounter=0;
HideCustomInfoBox();
window.setTimeout("DelayedExpandExtendedDetails()",1);
}

var stepperLeft;
var stepperRight;
var stepperTop;
var stepperBottom;
var extendedDetailsAnimCounter=0;
var extendedDetailsLeft=0;
var extendedDetailsTop=0;
var extendedDetailsWidth=0;
var extendedDetailsHeight=0;
var extendedDetailsID="";
var extendedDetailsTab=0;
function DelayedExpandExtendedDetails()
{
var extendedDetails=document.getElementById("divExtendedDetails");


if (extendedDetailsAnimCounter<5)
{
extendedDetailsLeft+=stepperLeft;
extendedDetailsTop+=stepperTop;
extendedDetailsWidth+=-stepperLeft+stepperRight;
extendedDetailsHeight+=-stepperTop+stepperBottom;

extendedDetails.style.left=extendedDetailsLeft + "px";
extendedDetails.style.width=extendedDetailsWidth + "px";
extendedDetails.style.top=extendedDetailsTop + "px";
extendedDetails.style.height=extendedDetailsHeight + "px";
extendedDetailsAnimCounter++;
//extendedDetails.innerHTML="left,top,width,height:" + extendedDetailsLeft + "," + extendedDetailsTop + "," + extendedDetailsWidth + "," + extendedDetailsHeight + "<button onclick=\"var o=document.getElementById('divExtendedDetails');o.style.display='none';\">schliessen</button>";
window.setTimeout("DelayedExpandExtendedDetails()",30);
}
else
{
extendedDetails.innerHTML="<img id='imgExtendedDetailsWait' style='position:relative;left:280px;top:220px;' src='images/baw/ajax-loader.gif'/><iframe id='iframeExtendedDetails' onload=\"ShowExtendedDetailsContent()\" style='display:none' src='ExtendedDetails.aspx?ID=" + extendedDetailsID + "&Tab=" + extendedDetailsTab + "' width='" + extendedDetailsWidth + "px' height='" + extendedDetailsHeight + "' frameborder='0' scrolling='no'></iframe>";
}

}

function ShowExtendedDetailsContent()
{
	$("#imgExtendedDetailsWait").css("display","none");
	$("#iframeExtendedDetails").css("display","block");
	$("#divModalOverlay").css("width",GetWindowWidth()).css("height",GetWindowHeight()).css("display","block").css("opacity","0").fadeTo("normal",0.7);
}

function HideExtendedDetails()
{
	$("#divModalOverlay").fadeOut("normal");
	$("#divExtendedDetails").css("display","none");
}


function ToggleShapeLayer(layerID, element)
{
	switch(layerID)
	{
		case 0:if (element.checked) accomodationShapeLayer.Show();else accomodationShapeLayer.Hide();break;
		case 1:if (element.checked) poiShapeLayer.Show();else poiShapeLayer.Hide();break;
		case 2:if (element.checked) {tourShapeLayer.Show();tourlineShapeLayer.Show();} else  {tourShapeLayer.Hide();tourlineShapeLayer.Hide();};break;
	}
}

function AddToHolidayPlaner(o){$.post("HolidayPlaner.handler","Arg=" + o,ReceiveAddToHolidayPlaner);}
