var openStandortInfoBallon = null;
var isPrintPage = false;
var isSanifair = false;
var isStandortHome = false;

function openDWK(url,breite,hoehe){
	details = window.open(url,'details','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=no,top=0,left=0,width='+ breite + ',height=' + hoehe);
	details.focus();
}

////////////////////////////////////////////////////////////
// getDocSize(window)

function showIsBusy(isBusy) {
	if(isBusy) {
		try {
			if($('#busy').size() == 0) {
				$('#divControl').append('<span id="busy" style="position:relative; z-index:200;"><img src="'+resourceFolder+'/busy.gif"></span>');
				$('#busy').css("position", "relative");
				$('#busy').css("top", ($('#divControl').height()/2)+"px");
				$('#busy').css("left", ($('#divControl').width()/2)+"px");
			}
		} catch(e) {
			;
		}
	} else {
		try {
			$('#busy').remove();
		} catch(e) {
			;
		}		
	}
}

function getDocSize(w)
{
    if(!w) w = window;
    var s = new Object();

    if (typeof document.height != 'undefined')
    {
        s.width =  w.document.width;
        s.height = w.document.height;
    }
    else
    {
        var obj = getBody(w);
        s.width = obj.scrollWidth;
        s.height = obj.scrollHeight;
    }
    return s;
}

////////////////////////////////////////////////////////////
// getWinSize(window)
function getWinSize(win)
{
    if(!win) win = window;
    var s = new Object();
    if(typeof win.innerWidth != 'undefined')
    {
        s.width = win.innerWidth;
        s.height = win.innerHeight;
    }
    else
    {
         var obj = getBody(win);
         s.width = parseInt(obj.clientWidth);
         s.height = parseInt(obj.clientHeight);
    }
    return s;
}
////////////////////////////////////////////////////////////
// offset(window)
function pageOffset(win)
{
    if(!win) win = window;
    var pos = {left:0,top:0};

    if(typeof win.pageXOffset != 'undefined')
    {
         // Mozilla/Netscape
         pos.left = win.pageXOffset;
         pos.top = win.pageYOffset;
    }
    else
    {
         var obj = getBody(win);
         pos.left = obj.scrollLeft;
         pos.top = obj.scrollTop;
    }
    return pos;
}


////////////////////////////////////////////////////////////
// Der IE hat 2 verschiedene Objekte f�r den strict und quirks Mode.
function getBody(w)
{
    return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}  


var MshTranslationProperties = new function(){
	this._properties = new Object();
	this._properties['de'] = new Object();
	this._properties['de']['serwayskids']='Serways KiDS';
	this._properties['de']['kraftstoff'] = 'Kraftstoff';
	this._properties['de']['geldautomat'] = 'Geldautomat'; 
	this._properties['de']['babywickelraum'] = 'Baby-Wickelraum'; 
	this._properties['de']['backshop'] = 'Backshop'; 
    this._properties['de']['jacobs'] = 'Jacobs';
    this._properties['de']['dallmayr'] = 'Dallmayr';
    this._properties['de']['gusticus'] = 'Gusticus';	
	this._properties['de']['regenbogenshop'] = 'Regenbogenshop'; 
	this._properties['de']['fernfahrerdusche'] = 'Duschen'; 
	this._properties['de']['kindergerechteswc'] = 'Kindergerechtes WC'; 
	this._properties['de']['bakeaway'] = 'Bakeaway'; 
	this._properties['de']['telefax'] = 'Fax-Service'; 
    this._properties['de']['lavazza'] = 'Lavazza Kaffeebar';	
	this._properties['de']['terasse'] = 'Terrasse'; 
	this._properties['de']['burgerking'] = 'BurgerKing'; 
	this._properties['de']['gastronomie'] = 'Gastronomie'; 
	this._properties['de']['service'] = 'Service'; 
	this._properties['de']['tanken'] = 'Tanken';
	this._properties['de']['kaffeebar'] = 'Kaffeebar'; 
	this._properties['de']['amex'] = 'Amex'; 
	this._properties['de']['aral'] = 'Aral'; 
	this._properties['de']['rastshop'] = 'Rastshop'; 
	this._properties['de']['segafredo'] = 'Segafredo Kaffeebar'; 
	this._properties['de']['einkaufen'] = 'Einkaufen'; 
	this._properties['de']['online'] = 'Online'; 
	this._properties['de']['hundebar'] = 'Hundeerfrischungsservice'; 
	this._properties['de']['axxe'] = 'Axxe'; 
	this._properties['de']['eckard'] = 'Eckard'; 
    this._properties['de']['total'] = 'Total';	
	this._properties['de']['freeflow'] = 'Freeflow'; 
	this._properties['de']['behinderten_wc'] = 'Behinderten-WC'; 
	this._properties['de']['snackvitrine'] = 'Snackvitrine'; 
	this._properties['de']['eurocard'] = 'Eurocard'; 
	this._properties['de']['fax'] = 'Telefax'; 
	this._properties['de']['lkwdiesel'] = 'LKW Diesel'; 
	this._properties['de']['wlan'] = 'WLAN';
	this._properties['de']['kinderspielplatz'] = 'Spielplatz'; 
	this._properties['de']['muenztelefon'] = 'M&uuml;nztelefon'; 
	this._properties['de']['tankshop'] = 'Tankshop'; 
	this._properties['de']['internetorwlan'] = 'Internetzugang'; 
    this._properties['de']['internet'] = 'Homepage';	
	this._properties['de']['picknick'] = 'Picknick';
	this._properties['de']['autogas'] = 'Autogas'; 
	this._properties['de']['nichtraucher'] = 'Raucherraum'; 
	this._properties['de']['offen24h'] = 'Offen 24h'; 
	this._properties['de']['schnellimbiss'] = 'Schnellimbiss'; 
	this._properties['de']['drs'] = 'Rufsystem DRS'; 
    this._properties['de']['kapelle'] = 'Autobahn Kapelle';	
	this._properties['de']['esso'] = 'Esso';
	this._properties['de']['fruehstueckincl'] = 'Fr&uuml;hst&uuml;ck incl.';  
	this._properties['de']['sanifair'] = 'Sanifair'; 
	this._properties['de']['behindertengerecht'] = 'Behindertengerecht'; 
	this._properties['de']['maestro'] = 'Maestro'; 
	this._properties['de']['kinderspielecke'] = 'Spielecke'; 
	this._properties['de']['diners'] = 'Diners'; 
	this._properties['de']['kartentelefon'] = 'Kartentelefon'; 
	this._properties['de']['visa'] = 'Visa'; 
	this._properties['de']['serways'] = 'Serways';
	this._properties['de']['shell'] = 'Shell';
    this._properties['de']['vignetteat'] = 'Vignettenverkaufsstelle (AT)';	
    this._properties['de']['vignettedk'] = 'Vignettenverkaufsstelle (DK)';    
    this._properties['de']['vignettech'] = 'Vignettenverkaufsstelle (CH)';
	this._properties['de']['avia'] = 'Avia';
    this._properties['de']['agip'] = 'Agip';	
    this._properties['de']['omv'] = 'OMV';    
    this._properties['de']['tamoil'] = 'Tamoil';    
    this._properties['de']['kaffebar'] = 'Kaffee';    
    this._properties['de']['behindertentelefon'] = 'Behindertentelefon';    
    this._properties['de']['barilla'] = 'Barilla';    
    this._properties['de']['nordsee'] = 'Nordsee';
    this._properties['de']['mcdonalds'] = 'McDonalds';
    this._properties['de']['gusti_snack'] = 'Gusticus Snack';
    this._properties['de']['westfalen'] = 'Westfalen';     
	this._properties['de']['aral'] = 'Aral';
	this._properties['de']['toggleMapInformation'] = 'Mit hilfe des roten Pfeiles k&ouml;nnen Sie die Karte vergr&ouml;&szlig;ern und verkleinern. Wenn Sie mehr Informationen zur Route ben&ouml;tigen klicken Sie einfach auf den roten Pfeil.';
	this._properties['de']['print'] = 'bt_drucken.gif';
	this._properties['de']['hightway'] = 'auf der';
	this._properties['de']['dirFrom'] = 'Richtung ';
	this._properties['de']['dirTo'] = 'nach';
	this._properties['de']['from'] = 'bei';
	this._properties['de']['to'] = 'nach';
	this._properties['de']['length'] = 'L&auml;nge';
	this._properties['de']['lengthFrom'] = 'von';
	this._properties['de']['avgSpeed'] = 'Durchschnittsgeschwindigkeit:';
	this._properties['de']['adblue'] = 'AdBlue®';
	this._properties['de']['sucheverfeinernTxt'] = 'Sie m&ouml;chten Ihre Reiseplanung ver&auml;ndern oder Ihr Ergebnis verfeinern?';
	this._properties['de']['sucheverfeinernTxt1'] = 'Markieren Sie einfach Ihre Wunschkriterien und los geht\'s.'
	this._properties['de']['weatherHeader'] = 'Das Wetter an diesem Standort:';
	this._properties['de']['temperatureHeader'] = 'Temperatur:';
	this._properties['de']['humidityHeader'] = 'Luftfeuchtigkeit:';
	this._properties['de']['found']='gefunden.';
	this._properties['de']['change'] = '&Auml;ndern';
	this._properties['de']['journey'] = 'Fahrt:';
	this._properties['de']['approx'] = 'ca.';
	this._properties['de']['hours'] = 'Stunden';
	this._properties['de']['minutes'] = 'Minuten';
	this._properties['de']['journeyFrom'] = 'Von';
	this._properties['de']['journeyTo'] = 'nach';
	this._properties['de']['printOnlyOneTxt'] = 'Sie können nur eine Reiseplanung drucken.';
	this._properties['de']['saveOnlyOneTxt'] = 'Sie können nur eine Reiseplanung speichern.';
	this._properties['de']['railwaystation'] = 'Bahnhof';
	this._properties['de']['airport'] = 'Flughafen';
	this._properties['de']['stadium'] = 'Stadion';
	this._properties['de']['hospital'] = 'Krankenhaus';
	this._properties['de']['displayResultTxt'] = 'Meinten Sie vielleicht:';
	this._properties['de']['displayResultTxt1'] = 'Keine Treffer gefunden';
	this._properties['de']['displayStandorteResultTxt'] = 'Keine Standorte gefunden';
	this._properties['de']['journeyProposal'] = 'Reisevorschlag';
	this._properties['de']['all'] = 'alle';
	this._properties['de']['break'] = 'Pause:';
	this._properties['de']['breakProposal'] = 'Für Ihre Reiseplanung schlagen wir folgende Pausen vor:';
	this._properties['de']['standort'] = 'Standort';
	this._properties['de']['standorte'] = 'Standorte';
	this._properties['de']['telefonTankstelle']='Telefon Tankstelle';
	this._properties['de']['karteEinblenden']='alle Karten einblenden';
	this._properties['de']['karteAusblenden']='alle Karten ausblenden';
	this._properties['de']['stau']='Stau';
	this._properties['de']['journeyInputFieldErrorMsg']='Stadt, Strasse, Land';
	this._properties['de']['noBreaks']='Leider liegt auf dieser Route kein Standort';
	this._properties['de']['noSanifairBreaks']='Leider liegt auf dieser Route kein SANIFAIR';
	
	this._properties['en'] = new Object();
	this._properties['en']['serwayskids']='Serways KiDS';
	this._properties['en']['kraftstoff'] = 'Fuel';
	this._properties['en']['geldautomat'] = 'Cash dispenser'; 
	this._properties['en']['babywickelraum'] = 'Baby changing room'; 
	this._properties['en']['backshop'] = 'Backshop'; 
    this._properties['en']['jacobs'] = 'Jacobs';
    this._properties['en']['dallmayr'] = 'Dallmayr';
    this._properties['en']['gusticus'] = 'Gusticus';	
	this._properties['en']['regenbogenshop'] = 'Regenbogenshop'; 
	this._properties['en']['fernfahrerdusche'] = 'Showers'; 
	this._properties['en']['kindergerechteswc'] = 'Child-accessible toilets'; 
	this._properties['en']['bakeaway'] = 'Bakeaway'; 
	this._properties['en']['telefax'] = 'Fax service'; 
    this._properties['en']['lavazza'] = 'Lavazza coffee bar';	
	this._properties['en']['terasse'] = 'Terrace'; 
	this._properties['en']['burgerking'] = 'BurgerKing'; 
	this._properties['en']['gastronomie'] = 'Hospitality'; 
	this._properties['en']['service'] = 'Service'; 
	this._properties['en']['tanken'] = 'Refuelling';
	this._properties['en']['kaffeebar'] = 'coffee bar'; 
	this._properties['en']['amex'] = 'Amex'; 
	this._properties['en']['aral'] = 'Aral'; 
	this._properties['en']['rastshop'] = 'Service shop'; 
	this._properties['en']['segafredo'] = 'Segafredo coffee bar'; 
	this._properties['en']['einkaufen'] = 'Shopping'; 
	this._properties['en']['online'] = 'Online'; 
	this._properties['en']['hundebar'] = 'Dog refreshment service'; 
	this._properties['en']['axxe'] = 'Axxe'; 
	this._properties['en']['eckard'] = 'Eckard'; 
    this._properties['en']['total'] = 'Total';	
	this._properties['en']['freeflow'] = 'Freeflow'; 
	this._properties['en']['behinderten_wc'] = 'Disabled toilets'; 
	this._properties['en']['snackvitrine'] = 'Snackvitrine'; 
	this._properties['en']['eurocard'] = 'Eurocard'; 
	this._properties['en']['fax'] = 'Fax'; 
	this._properties['en']['lkwdiesel'] = 'Diesel-fuelled lorries'; 
	this._properties['en']['wlan'] = 'WLAN';
	this._properties['en']['kinderspielplatz'] = 'Play area'; 
	this._properties['en']['muenztelefon'] = 'Payphone'; 
	this._properties['en']['tankshop'] = 'Service station shop'; 
	this._properties['en']['internetorwlan'] = 'Internet access'; 
    this._properties['en']['internet'] = 'Homepage';	
	this._properties['en']['picknick'] = 'Picnic';
	this._properties['en']['autogas'] = 'Liquified gas'; 
	this._properties['en']['nichtraucher'] = 'Smoker\'s area'; 
	this._properties['en']['offen24h'] = 'Open 24 hours'; 
	this._properties['en']['schnellimbiss'] = 'Fast food outlet'; 
	this._properties['en']['drs'] = 'Service call system'; 
    this._properties['en']['kapelle'] = 'Motorway chapel';	
	this._properties['en']['esso'] = 'Esso';
	this._properties['en']['fruehstueckincl'] = 'Breakfast included';  
	this._properties['en']['sanifair'] = 'Sanifair'; 
	this._properties['en']['behindertengerecht'] = 'Accessible for the disabled'; 
	this._properties['en']['maestro'] = 'Maestro'; 
	this._properties['en']['kinderspielecke'] = 'Play corner'; 
	this._properties['en']['diners'] = 'Diners'; 
	this._properties['en']['kartentelefon'] = 'Card-operated telephone'; 
	this._properties['en']['visa'] = 'Visa'; 
	this._properties['en']['serways'] = 'Serways';
	this._properties['en']['shell'] = 'Shell';
    this._properties['en']['vignetteat'] = 'Tax disc sales outlet (AT)';	
    this._properties['en']['vignettech'] = 'Tax disc sales outlet (CH)';    
    this._properties['en']['vignettedk'] = 'Tax disc sales outlet (DK)';    
	this._properties['en']['avia'] = 'Avia';
    this._properties['en']['agip'] = 'Agip';	
    this._properties['en']['omv'] = 'OMV';    
    this._properties['en']['tamoil'] = 'Tamoil';    
    this._properties['en']['kaffebar'] = 'Coffee';    
    this._properties['en']['behindertentelefon'] = 'Disabled telephone';    
    this._properties['en']['barilla'] = 'Barilla';    
    this._properties['en']['nordsee'] = 'Nordsee';
    this._properties['en']['mcdonalds'] = 'McDonalds';
    this._properties['en']['gusti_snack'] = 'Gusticus Snack';
    this._properties['en']['westfalen'] = 'Westfalen';     
	this._properties['en']['aral'] = 'Aral';
	this._properties['en']['toggleMapInformation'] = 'You can use the red arrow to enlarge and minimise the map.  If you require more information related to your route, simply click on the red arrow.';
	this._properties['en']['print'] = 'bt_drucken_en.gif';
	this._properties['en']['hightway'] = 'on the';
	this._properties['en']['dirFrom'] = 'direction ';
	this._properties['en']['dirTo'] = 'to';
	this._properties['en']['from'] = 'from';
	this._properties['en']['to'] = 'to';
	this._properties['en']['length'] = 'length';
	this._properties['en']['lengthFrom'] = 'from';
	this._properties['en']['avgSpeed'] = 'average speed';
	this._properties['en']['adblue'] = 'AdBlue®';
	this._properties['en']['sucheverfeinernTxt'] = 'Would you like to alter your journey specifications or refine your results?';
   	this._properties['en']['sucheverfeinernTxt1'] = 'Simply click on your desired criteria and you\'re ready to go.';
   	this._properties['en']['weatherHeader'] = 'The weather in this location:';
   	this._properties['en']['temperatureHeader'] = 'Temperature:';
   	this._properties['en']['humidityHeader'] = 'Humidity:';
	this._properties['en']['found']='found.';
	this._properties['en']['change'] = 'Change';
	this._properties['en']['journey'] = 'Journey';
	this._properties['en']['approx'] = 'approx.';
	this._properties['en']['hours'] = 'hours';
	this._properties['en']['minutes'] = 'minutes';
	this._properties['en']['journeyFrom'] = 'From';
	this._properties['en']['journeyTo'] = 'to';
	this._properties['en']['printOnlyOneTxt'] = 'You can only print a journey plan.';
	this._properties['en']['saveOnlyOneTxt'] = 'You can only save a journey plan.';
	this._properties['en']['railwaystation'] = 'railway station';
	this._properties['en']['airport'] = 'airport';
	this._properties['en']['stadium'] = 'stadium';
	this._properties['en']['hospital'] = 'hospital';
	this._properties['en']['displayResultTxt'] = 'Did you mean: ';
	this._properties['en']['displayResultTxt1'] = 'No hits found';
	this._properties['en']['displayStandorteResultTxt'] = 'No locations found';
	this._properties['en']['journeyProposal'] = 'Journey Proposal: ';
	this._properties['en']['all'] = 'every';
	this._properties['en']['break'] = 'breaks:';
	this._properties['en']['breakProposal'] = 'We suggest the following breaks for your journey:';
	this._properties['en']['standort'] = 'location';
	this._properties['en']['standorte'] = 'locations';
	this._properties['en']['telefonTankstelle']='Telephone petrolstation';
	this._properties['en']['karteEinblenden']='show maps';
	this._properties['en']['karteAusblenden']='hide maps';
	this._properties['en']['stau']='Traffic jam';
	this._properties['en']['journeyInputFieldErrorMsg']='City, Street, Country';
	this._properties['en']['noBreaks']='No Standort on this route';
	this._properties['en']['noSanifairBreaks']='No SANIFAIR on this route';
	
	this.getValue=function(inKey, inLanguage){
		var theLanguage = (inLanguage == 'undefined') ? getLanguage() : inLanguage;
		
		if (undefined == this._properties[theLanguage][inKey]){
			//return 'no properties found for key ' + inKey + ' in language ' + theLanguage;
			return inKey;
		}else{
			return this._properties[theLanguage][inKey];
		}		
	} 
}

function getLanguage(){
	
	if(!lang)
		lang = "de";
	else if(lang != "en" && lang != "de")
		lang = "en";
	return lang;
}

function ucFirst(str) {
    if(str.length > 1) {
        return str.substring(0,1).toUpperCase() + str.substring(1, str.length);
    } else {
        return str.toUpperCase();
    }
}

function MshStandortOption(){
	this._optionObj = new Object();
	
	this.init = function(inOptionObj){
	
		//all options init
		this._optionObj['id'] = '0';
		this._optionObj['name'] = '';
		this._optionObj['x'] = '0';
		this._optionObj['y'] = '0';
		
		for(var theKey in inOptionObj){
			this._optionObj[theKey] = inOptionObj[theKey];
		}
	};
	
	this.getLabel=function(inKey, inLanguage){
		
	}
	
	this.getValue = function(inKey){
		return this._optionObj[inKey];
	};
	
	this.setValue = function(inKey, inValue){
		this._optionObj[inKey] = inValue;
	};
	
	this.getKeys=function(inOnlyActive){
		var theResults = new Array();
		for(var theKey in this._optionObj){
			if (inOnlyActive == 1 && this._optionObj[theKey] == 'true'){
				theResults.push(theKey);
			}
			if (inOnlyActive == 0 && this._optionObj[theKey] == 'false'){
				theResults.push(theKey);
			}
			if (inOnlyActive == undefined){
				theResults.push(theKey);
			}
		}
		return theResults;
	};
	
	this.setXMLToArray = function (inXML){

		var theOptionObj = new Object();
		if (inXML.hasChildNodes()){
			for (var i=0;i<inXML.childNodes.length;i++){
				theOptionObj[inXML.childNodes[i].nodeName] = IWXMLHelper.getNodeValue(inXML.childNodes[i]);
					//alert(inXML.childNodes[i].nodeName);
			}
		}
		
		this.init(theOptionObj);
	};
	
	this.getAllAsParamString=function(){
		var theResult = '';
		for(var theKey in this._optionObj){
			theResult += theKey + '=' + this._optionObj[theKey] + '&';
		}
		
		theResult = theResult.substr(0, theResult.length-1);
		
		return theResult;
	};
	
	this.compare=function(inOtherOption){
		var theResult = new Object();
		theResult.isFailed = false;
		theResult.failedOption = new Array();

		var theOptionKeys = inOtherOption.getKeys(1); //checked options
		var theOptionKeys2 = this.getKeys(1); //attributes the standort has

		var bat = false;
		var bar = false;
		var hotel = false;
		var kiosk = false;
		
		var serwayskids = false;
		var spielplatz = false;
		var spielecke = false;
		//serwayskids 'or'
		for (i=0;i<theOptionKeys.length;i++){
			if(theOptionKeys[i] == "serwayskids")
				serwayskids = true;
			if(theOptionKeys[i] == "kinderspielplatz")
				spielplatz = true;
			if(theOptionKeys[i] == "kinderspielecke")
				spielecke = true;	
			if(theOptionKeys[i] == "bat")
				bat = true;
			if(theOptionKeys[i] == "bar")
				bar = true;
			if(theOptionKeys[i] == "hotel")
				hotel = true;
			if(theOptionKeys[i] == "kiosk")
				kiosk = true;
		}
		for (i=0;i<theOptionKeys.length;i++){
			var isKeyFound = false;
			if(serwayskids && (spielplatz || spielecke)) {
				if(theOptionKeys[i] == "serwayskids" || theOptionKeys[i] == "kinderspielplatz" || theOptionKeys[i] == "kinderspielecke")
					continue;
			}
			if(bat || bar || hotel || kiosk){
				if(theOptionKeys[i] == "bat" || theOptionKeys[i] == "bar" || theOptionKeys[i] == "hotel" || theOptionKeys[i] == "kiosk")
					continue;
			}
			for (j=0;j<theOptionKeys2.length;j++){
				if (theOptionKeys[i] == theOptionKeys2[j]){
					isKeyFound = true;
					break;
				}
			}
			if (!isKeyFound){
				theResult.failedOption.push(theOptionKeys[i]);
				theResult.isFailed = true;
				break;
			}
		}
		
		if(!theResult.isFailed && serwayskids && (spielplatz || spielecke)) {
			var found = false;
			for (j=0;j<theOptionKeys2.length;j++){
				if (theOptionKeys2[j] == "serwayskids" || (spielplatz ? theOptionKeys2[j] == "kinderspielplatz" : false) || (spielecke ? theOptionKeys2[j] == "kinderspielecke" : false)) {
					found = true;
					theResult.isFailed = false;
					break;
				}
			}
			if (!found){
				theResult.isFailed = true;
			}
		}
		
		if(!theResult.isFailed && bat){
			var found = false;
			for (j=0;j<theOptionKeys2.length;j++){
				if(theOptionKeys2[j] == "bat"){
					found = true;
					theResult.isFailed = false;
					break;
				}
			}
			if (!found){
				theResult.isFailed = true;
			}
		}
		
		if(!theResult.isFailed && bar){
			var found = false;
			for (j=0;j<theOptionKeys2.length;j++){
				if(theOptionKeys2[j] == "bar"){
					found = true;
					theResult.isFailed = false;
					break;
				}
			}
			if (!found){
				theResult.isFailed = true;
			}
		}
		if(!theResult.isFailed && hotel){
			var found = false;
			for (j=0;j<theOptionKeys2.length;j++){
				if(theOptionKeys2[j] == "hotel"){
					found = true;
					theResult.isFailed = false;
					break;
				}
			}
			if (!found){
				theResult.isFailed = true;
			}
		}
		if(!theResult.isFailed && kiosk){
			var found = false;
			for (j=0;j<theOptionKeys2.length;j++){
				if(theOptionKeys2[j] == "kiosk"){
					found = true;
					theResult.isFailed = false;
					break;
				}
			}
			if (!found){
				theResult.isFailed = true;
			}
		}
		
		//Kraftstoff
		if (!theResult.isFailed && inOtherOption.getValue('kraftstoffValue')!=undefined){
			//only if until now no failure
			theOptionKeys = inOtherOption.getValue('kraftstoffValue').split(',');
			if (this.getValue('kraftstoff') != null){
				theOptionKeys2 = this.getValue('kraftstoff').split(',');	
			}else{
				//strange
				theOptionKeys = new Array();
			}
			
			if (inOtherOption.getValue('kraftstoffValue') != '' && theOptionKeys.length > 0){
				for (i=0;i<theOptionKeys.length;i++){
					var isKeyFound = false;
					
					for (j=0;j<theOptionKeys2.length;j++){
						if (theOptionKeys[i].toLowerCase() == theOptionKeys2[j].toLowerCase()){
							isKeyFound = true;
							break;
						}
					}
					if (!isKeyFound){
						theResult.failedOption.push(theOptionKeys[i].toLowerCase());
						theResult.isFailed = true;
						break;
					}
				}			
			}		
		}
		
		return !theResult.isFailed;
	};
	
	this.createCheckbox = function(theKey) {
	        theOnClick = 'MshStandortFactory.getOptions().setValue(\''+theKey+'\',(document.getElementById(\''+theKey+'_option\').checked ? \'true\' : \'false\'));MshStandortFactory.display(true);';
	        html = '<div class="standortOption"><input class="checkbox" type="checkbox" value="1" id="'+ theKey +'_option" name="'+ theKey +'_option" onclick="' + theOnClick + '">' + MshTranslationProperties.getValue(theKey, getLanguage()) + '</input></div>';
	        return html
	}
	
	this.getType = function(key) {
	   if(key == "backshop")
	       return "Rasten";
	   if(key == "backaway")
           return "Rasten";
       if(key == "barilla")
           return "Rasten";
       if(key == "burgerking")
           return "Rasten";
       if(key == "lavazza")
           return "Rasten";
       if(key == "nordsee")
           return "Rasten";
       if(key == "segafredo")
           return "Rasten";
       if(key == "visa")
           return "Rasten";
       if(key == "eurocard")
           return "Rasten";
       if(key == "mastercard")
           return "Rasten";
       if(key == "amex")
           return "Rasten";
       if(key == "diners")
           return "Rasten";
        return "Service";
	}
	
	this.buildHTML=function(jqueryObject){
	
		//new category
		jqueryObject.html('<p>' + MshTranslationProperties.getValue('sucheverfeinernTxt', getLanguage()) + '<br />'+ MshTranslationProperties.getValue('sucheverfeinernTxt1', getLanguage()) +'</p><div id="optionCategory"></div>');
		$("#optionCategory").append('<div id="optionCategoryRasten" class="optionCategory"><div class="title">' + MshTranslationProperties.getValue('gastronomie', getLanguage()) + '</div></div>');
		$("#optionCategory").append('<div id="optionCategoryTanken" class="optionCategory"><div class="title">' + MshTranslationProperties.getValue('tanken', getLanguage()) + '</div></div>');
		$("#optionCategory").append('<div id="optionCategoryService" class="optionCategory"><div class="title">' + MshTranslationProperties.getValue('service', getLanguage()) + '</div></div>');
		
		for(var theKey in this._optionObj){
			if (theKey != 'name' && theKey != 'id' && theKey != 'x' && theKey != 'y'){
			
			    if(theKey == 'kraftstoffValue'){
			
				} else if (theKey != 'kraftstoff' && theKey != 'eurorastpark' && theKey!='ece' && theKey!='serwayskidsspielmoeglichkeit' && theKey!='serwayskidsspielplatz') {
					$('#optionCategory'+this.getType(theKey)).append(this.createCheckbox(theKey));
				} else if (theKey == 'kraftstoff' && this._optionObj['kraftstoff'] != null){
					//kraftstoff special
					
					var theKraftstoff = this._optionObj['kraftstoff'].split(', ');
					
					if (theKraftstoff.length > 0){
						for (var i=0;i<theKraftstoff.length;i++){
							var theOnClick = 'var theOldKraftstoff = MshStandortFactory.getOptions().getValue(\'kraftstoffValue\');';
							theOnClick += 'var theNewKraftstoff = \'\';';
							theOnClick += 'if (!document.getElementById(\''+theKraftstoff[i]+'_option\').checked){';
							theOnClick += 'var kk = theOldKraftstoff.split(\',\');';
							theOnClick += 'for (var i=0;i<kk.length;i++){';
							theOnClick += 'if (kk[i] != \''+ theKraftstoff[i] +'\'){';
							theOnClick += 'theNewKraftstoff += kk[i] + \',\';';
							theOnClick += '}';
							theOnClick += '}';
							theOnClick += 'theNewKraftstoff = theNewKraftstoff.substr(0, theNewKraftstoff.length-1);';
							theOnClick += '}else{';
							theOnClick += 'theNewKraftstoff = theOldKraftstoff + (theOldKraftstoff == \'\' ? \'\' : \',\') + \''+theKraftstoff[i]+'\'';
							theOnClick += '}';
							theOnClick += '';
							theOnClick += '';
							theOnClick += '';
							theOnClick += '';
							theOnClick += '';
							theOnClick += 'MshStandortFactory.getOptions().setValue(\'kraftstoffValue\',theNewKraftstoff);';
							theOnClick += 'MshStandortFactory.display(true);';
							//theOnClick += '$(\'#standort-info-frame-btm\').html(MshStandortFactory._counter+" "+(MshStandortFactory._counter == 1 ? "Standort" : "Standorte")+" gefunden. &Auml;ndern " + \'<a onclick="toggleMap();return false;" href="#"><img src="../resources/de.rast.serways.web.map.SerwaysHomePage/img/pfeil_sw_rechts_small.gif" alt="" id="toggleMapImage2"/></a>\');';
							
		
							
							$("#optionCategoryTanken").append('<div class="standortOption"><input class="checkbox" type="checkbox" value="1" id="'+ theKraftstoff[i] +'_option" name="'+ theKraftstoff[i] +'_option" onchange="' + theOnClick + '">' + MshTranslationProperties.getValue(theKraftstoff[i], getLanguage()) + '</input></div>');
						}
					}
				}
			}
		}
	}
	
}


function MshStandort(inMap, inResourcePath, inOption, layerNr) {

    this._map = inMap;	 	
	this._logger=log4javascript.getLogger("MshStandort");
 	this._resourcePath = inResourcePath;
	this.infoBalloon = null;
	this.option = inOption;
	this.isVisible = false;
	this.marker;
	this.weatherIconURL;
	this.weatherInfoBalloon = null;

	this._layerNr = 100;

	if(layerNr || layerNr == 0){
		this._layerNr = layerNr;
	}

    this.repaintWeather = function() {
          this._map.getOverlayManager().getLayer(101).removeOverlay(this.weatherMarker);
          this.paintWeather();
    }

    this.paintWeather = function() {
        var iconShift = 200;
        try {
           iconShift = this._map.getZoom() * this._map.getZoom() * this._map.getZoom() * this._map.getZoom()  * 1.8;
        } catch(e) {
           //alert(e);
        }
        var x = parseInt(this.option.getValue('x'))+iconShift;
        var y = this.option.getValue('y');
        var coords = new IWLCCEurope(x, y).toCoordinate();
        this.weatherMarker = new IWMarker(this._map, coords);
        this.weatherMarker.setDefaultIcon(new IWIcon(this.weatherIconURL, new IWPoint(10,10)));
        this._map.getOverlayManager().getLayer(101).addOverlay(this.weatherMarker);
        
        var listener=IWEventManager.addListener(this.weatherMarker,'onclick',function(e){
            if (!this.weatherInfoBalloon || !this.weatherInfoBalloon.isDisplayed()){
                
                try {
                var obj = this;
                 $.get("../weather", { standortId: this.getId() },
                     function(data){
            
                        var root = IWXMLHelper.parse(data).documentElement;
                        var html = "<br/><h5>" + MshTranslationProperties.getValue('weatherHeader', getLanguage()) + "</h5>"; 
                        html = html +"<b>" + MshTranslationProperties.getValue('temperatureHeader', getLanguage()) + " " +root.getElementsByTagName("temp_c")[0].attributes[0].nodeValue+"&deg;</b><br/>";
                        html = html + translate(root.getElementsByTagName("condition")[0].attributes[0].nodeValue)+"<br/>";
                        var hum = root.getElementsByTagName("humidity")[0].attributes[0].nodeValue;
                        html = html +"" + MshTranslationProperties.getValue('humidityHeader', getLanguage()) + " "+hum.substr(10, hum.length)+"<br/>";                        
                
                        obj.weatherInfoBalloon = new MMInfoBalloon(obj._map, coords, html, obj._resourcePath, new IWSize(220,150));                            
                        obj._map.addWindowOverlay(obj.weatherInfoBalloon);
                        
                        IWEventManager.addListener(obj.weatherInfoBalloon,'onclick',function(e){
                        	obj._map.removeWindowOverlay(this);
                        }.iwclosure(this));
                        
                });
                

                } catch(e) {
                    //alert(e);
                }
            } else if(this.weatherInfoBalloon.isDisplayed()) {
            	this._map.removeWindowOverlay(this.weatherInfoBalloon);
            }
        }.iwclosure(this));
    }

    this.addWeatherIcon = function(iconURL) {
        
        this.weatherIconURL = iconURL;
        this.paintWeather();
    }
		
  	this.addStandortToMap = function(inStartWithSmallImage){
		this.isVisible = true;
		this.marker = new IWMarker(this._map,this.getCoordinate());
		
		var theImageName = this.getDefaultImageName();
		var theSmallImageName = this.getDefaultSmallImageName();
		var path = window.location.pathname;

		if (inStartWithSmallImage){
			this.marker.addScaleDependentIcon(new IWIcon(this._resourcePath + theSmallImageName,new IWPoint(10,10)),new IWRange(14,16));
		}else{
			this.marker.addScaleDependentIcon(new IWIcon(this._resourcePath + theSmallImageName,new IWPoint(10,10)),new IWRange(16,16));
		}
		this.addDynamicIcon();
		
		this.marker.setDefaultIcon(new IWIcon(this._resourcePath + theImageName,new IWPoint(10,10)));

        var infoBalloonEvent = this.option.getValue('openInfoBalloonEvent');
        if(!infoBalloonEvent)
            infoBalloonEvent = "click";

		if(!isPrintPage && !isStandortHome){
			var listener=IWEventManager.addListener(this.marker,'on'+infoBalloonEvent,function(e){
				
				if (!this.infoBalloon || !this.infoBalloon.isDisplayed()){
					MshStandortFactory.closeAllOpenBallons();
					
					var html = this.getDetailInfo();
					if (typeof(standortInfoBallonSize)!='undefined' && standortInfoBallonSize && standortInfoBallonSize != null){
 						this.infoBalloon = new MMInfoBalloon(this._map, this.getCoordinate(), html, this._resourcePath, standortInfoBallonSize);
					}else{
						this.infoBalloon = new MMInfoBalloon(this._map, this.getCoordinate(), html, this._resourcePath);
					}
					
					this.infoBalloon.closeAppendFunction = function(){
						$('#standortDetails').css('display','none');
					};	
					this.infoBalloon.hasCloseAppendFunction	= true;	
					openStandortInfoBallon = this.infoBalloon;				
					this._map.addWindowOverlay(this.infoBalloon);
				}
			}.iwclosure(this));
		}

		this._map.getOverlayManager().getLayer(this._layerNr).addOverlay(this.marker);
    }; 
    
    this.addDynamicIcon = function() {
                
    }

    this.getDefaultImageName = function() {
    	if(isSanifair){
    		return 'sanifair_icon.gif';
    	}else{
	    	if(this.option.getValue('serways') == 'true'){
	    		if(($('select[name="profileSelection"]').val()=='0' || $('select[name="profileSelection"]').val()=='1')&&(this.option.getValue('serwayskids') == 'true')){
	    			return 'serways_kids_icon.png';
	    		}else if(isStandortSucheActive() && $('#serwayskids:checked').val()== 'on' && (this.option.getValue('serwayskids') == 'true')){
	    			return 'serways_kids_icon.png';
	    		}else if($('#serwayskids_option:checked').val()== '1' && (this.option.getValue('serwayskids') == 'true')){
	    			return 'serways_kids_icon.png';
	    		}else{
	    			return 'serways_icon.gif';
	    		}
	    	}else{
	    		return 'tr_icon.gif';
	    	}
    	}
    }
    
    this.getDefaultSmallImageName = function() {
    	return this.option.getValue('serways') == 'true' ? 'pin_serways.gif' : 'pin_tr.gif';        
    }

    this.removeStandortFromMap = function(){
    	try {
    		this._map.getOverlayManager().getLayer(101).removeOverlay(this.weatherMarker);
    	} catch(e) {}
    	this.isVisible = false;
        this._map.getOverlayManager().getLayer(this._layerNr).removeOverlay(this.marker);
    }; 
    
    this.isOnMap = function() {
    	return this.isVisible;
    }
    
    this.isSerways = function() {
        return this.option.getValue('serways') == 'true';
    }
    
    this.isSanifair = function() {
    	return this.option.getValue('sanifair') == 'true';
    }
    
    this.getId=function(){
    	return this.option.getValue('id');
    };

    this.getName=function(){
    	return this.option.getValue('name');
    };
        
    this.getCoordinate=function(){
    	return new IWLCCEurope(this.option.getValue('x'), this.option.getValue('y')).toCoordinate();
    };
    
    this.getSerwayskids=function(){
    	return this.option.getValue('serwayskids');
    };
    
    
    this.getLinkHTML=function(){
    	var theOutput = '';
		theOutput += '<a href="#" onclick="';
		theOutput += 'var coord = new IWLCCEurope(\'' + this.option.getValue('x') + '\', \'' + this.option.getValue('y') + '\').toCoordinate();';
		theOutput += 'map.setCenter(coord, map.getZoomByMeter(3200));'; 
		theOutput += 'return false;">' + this.getName() + '</a><br />';
		
    	return theOutput;
    };
      
	this.getDetailInfo=function(){
	 	//ajax request
		//var theUrl = '../serways/SerwaysStandortInfo?id='+this.getId();
		var theUrl = '../rast/StandortInfo?id='+this.getId()+'&sanifair='+isSanifair;
		if(typeof(infoBoxURL)!='undefined'){
			theUrl = infoBoxURL + this.getId()+"&profile="+$('select[name="profileSelection"]').val()+"&standortSucheActive="+isStandortSucheActive()+"&skchecked="+$('#serwayskids:checked').val()+"&skoptchecked="+$('#serwayskids_option:checked').val();
		}
		
		var resultText = '';
		$.ajax({
  			type: "GET",
  			url: theUrl,
  			dataType: "html",
  			async: false,
  			cache:true,
			success: function(html){
			    resultText = html;
			    cancelShow=true;
			}
	  	});
		
		return resultText;
	};   
	
}

var MshStandortFactory = new function(){

	this._standorte = new Array();
	this._globalOptions = new MshStandortOption();
	this._bestStandorte = new Array();
	this._count = 0;
	this._routingData = null;
	
    this.createStandort = function(inMap, inResourceFolder, theOption, _layerNr) {
        return new MshStandort(inMap, inResourceFolder, theOption, _layerNr);
    }
	
	this.add=function (inStandort){
		this._standorte.push(inStandort);
	};
	
	this.addBestStandort=function(inStandort){
		this._bestStandorte.push(inStandort);
	}

	this.getBestStandorte=function(){
		return this._bestStandorte;
	}
		
	this.getAll=function(){
		return this._standorte;
	};
	
	this.getAllByRequest=function(inMap, inResourceFolder){
    	var url = 'standorteXML/?action=getAllStandorte';

        
		$.post(url, { },
		  			  
		  			  function(data){
		  				 MshStandortFactory.createStandorteByXML(data, inMap, inResourceFolder, true);
		  			  });	
	};
	
	
	this.createStandorteByXML=function(inXML, inMap, inResourceFolder, inAddToMap, inStartWithSmallImage, layerNr){
	
		var doc = IWXMLHelper.parse(inXML);
		var root = doc.documentElement;
		var theResults = new Array();
		this._routingData = new Array();
	
		if (root.getElementsByTagName("fail").length == 0) {
			
			if(root.getElementsByTagName("InputData").length != 0){
				var routingData = root.getElementsByTagName("InputData");
//				for(var i = 0; i < routingData.length; i++){
					if(routingData[0].getElementsByTagName("City")[0].childNodes[0]!=undefined){
						var city = routingData[0].getElementsByTagName("City")[0].childNodes[0].nodeValue;
						this._routingData.push({'city':city});
					} else {
						this._routingData.push({'city':''});
					}
					if(routingData[0].getElementsByTagName("Street")[0].childNodes[0]!=undefined){
						var street = routingData[0].getElementsByTagName("Street")[0].childNodes[0].nodeValue;
						this._routingData.push({'street':street});
					} else {
						this._routingData.push({'street':''});
					}
					if(routingData[0].getElementsByTagName("Country")[0].childNodes[0]!=undefined){
						var country = routingData[0].getElementsByTagName("Country")[0].childNodes[0].nodeValue;
						this._routingData.push({'country':country});
					} else {
						this._routingData.push({'country':''});
					}
					if(routingData[0].getElementsByTagName("ZipCode")[0].childNodes[0]!=undefined){
						var zipcode = routingData[0].getElementsByTagName("ZipCode")[0].childNodes[0].nodeValue;
						this._routingData.push({'zipcode':zipcode});
					} else {
						this._routingData.push({'zipcode':''});
					}
//				}
			}

			if(root.getElementsByTagName("standort").length != 0){
				var theStandortList = root.getElementsByTagName("standort");
//				var theResults = new Array();
				for (var i = 0; i < theStandortList.length; i++) {
					
			            var theOption = new MshStandortOption();
						theOption.setXMLToArray(theStandortList[i]);

						var theStandort = MshStandortFactory.createStandort(inMap, inResourceFolder, theOption, layerNr);
						
						MshStandortFactory.add(theStandort);  
			            if (inAddToMap){	
							theStandort.addStandortToMap(inStartWithSmallImage);
						}
						var coordX = theStandortList[i].getElementsByTagName("x");
			            var coordY = theStandortList[i].getElementsByTagName("y");
			            var coordNW = parseFloat(IWXMLHelper.getNodeValue(coordX[0])) + ',' +  parseFloat(IWXMLHelper.getNodeValue(coordY[0]));
			            theResults.push({'value':theStandort.getName(),'coord':coordNW, 'serways':theStandort.isSerways(), 'serwayskids':theStandort.getSerwayskids(), 'id':theStandort.getId()});
				}
			}
		}
		return theResults;		
	};
	
	this.clear=function(){
		
		if (map){
			this.closeAllOpenBallons();			
			if (this._standorte.length > 0){
				for (var i=0;i<this._standorte.length;i++){
					this._standorte[i].isVisible = false;
					try {
						this._standorte[i].removeStandortFromMap();
					} catch(e) {  }					
				}
			}			
			map.removeLayerByName("route");
			map.getOverlayManager().removeLayer(100);
			map.getOverlayManager().removeLayer(101);
			this._count = 0;
		}

		standorte4Weather = new Array();
		this._standorte = new Array();
		this._bestStandorte = new Array();
	};
	
	this.clearOptions =function(){
	
		this._globalOptions=new MshStandortOption();
	}
	
	this.getOptions=function(){
		return this._globalOptions;
	};
	
	this.buildHTML=function(jqueryObject){

        jqueryObject.html('<div id="standortOptions" class="standortOptions">');
		this._globalOptions.buildHTML($("#standortOptions"));		
	};
	
	this.getStandorte=function(){
		return this._standorte;	
	};
	
	this.getStandortById=function(id){
		
		for (var i=0;i<this._standorte.length;i++){
			if(this._standorte[i].getId() == id)
				return this._standorte[i];
		}		
	};	
	
	this.getStandorteByOption=function(){
		var theReturnValue = new Array();
		this._count = 0;
		
		if (this._standorte.length > 0){
				
			if (this._globalOptions.getKeys(1).length > 0 || this._globalOptions.getValue('kraftstoffValue') != ''){
				for (var i=0;i<this._standorte.length;i++){
					if (this._standorte[i].option.compare(this._globalOptions) && !this._standorte[i].isVisible){
						theReturnValue.push(this._standorte[i]);
						this._count++;
					}
				}	
			}else{
				for (var i=0;i<this._bestStandorte.length;i++){
					theReturnValue.push(this._bestStandorte[i]);
					this._count++;
				}
			}
		}

		return theReturnValue;
		
	};
	
	this.removeAllStandorteFromMap = function() {
		for (var i=0;i<this._bestStandorte.length;i++) {
			try {
				this._bestStandorte[i].removeStandortFromMap();
			} catch(e) {  }
		}
		for (var i=0;i<this._standorte.length;i++){
			try {
				this._standorte[i].removeStandortFromMap();
			} catch(e) {  }
		}		
	}
	
	this.display = function(clear){
		
		var theReturnValue = false;
		this._count = 0;
		
		if (map){
			this.closeAllOpenBallons();
			if(clear) {
				map.getOverlayManager().removeLayer(101);
				this.removeAllStandorteFromMap();
			}
		}
		
		var theStandortHTMLListContent = '';
		if (this._standorte.length > 0){
			var standortIdMap = {};
			if (this._globalOptions.getKeys(1).length > 0 || this._globalOptions.getValue('kraftstoffValue') != ''){
				for (var i=0;i<this._standorte.length;i++){
					var _standort = this._standorte[i];
					var standortId = _standort.getId();
					if (_standort.option.compare(this._globalOptions)  && !standortIdMap[standortId]) {
						_standort.addStandortToMap();
						theStandortHTMLListContent += _standort.getLinkHTML();
						theReturnValue = true;
						displayWeather(_standort);
						this._count++; 
						standortIdMap[standortId] = true;
					}
				}
			}else{
				for (var i=0;i<this._bestStandorte.length;i++){
					theStandortHTMLListContent += this._bestStandorte[i].getLinkHTML();
					this._bestStandorte[i].addStandortToMap();
					displayWeather(this._bestStandorte[i]);
					theReturnValue = false;
					this._count++;
				}
			}
			
		}
		
		$('#standort-info-frame-btm').html(this._count+" "+(this._count == 1 ? MshTranslationProperties.getValue('standort', getLanguage()) : MshTranslationProperties.getValue('standorte', getLanguage()))+" " + MshTranslationProperties.getValue('found', getLanguage()) + " " + MshTranslationProperties.getValue('change', getLanguage()) +
				'<a onclick="toggleMap();return false;" href="#"><img src="../resources/de.rast.serways.web.map.SerwaysHomePage/img/pfeil_sw_rechts_small.gif" alt="" id="toggleMapImage2"/></a>');
		
       	if(theStandortHTMLListContent!=''){
       		$('#routeBreaksOutput').html(theStandortHTMLListContent);
       	}else{
       		if(isSanifair){
       			$('#routeBreaksOutput').html(MshTranslationProperties.getValue('noSanifairBreaks', getLanguage()));
       		}else{
       			$('#routeBreaksOutput').html(MshTranslationProperties.getValue('noBreaks', getLanguage()));
       		}
       		
       	}
		
		return theReturnValue;
	};
	
	this.displayAll=function(){
		var theStandortHTMLListContent = '';
		this._count=0;
		if (this._standorte.length > 0){
			for (var i=0;i<this._standorte.length;i++){
				this._standorte[i].addStandortToMap();
				this._count++;
				theStandortHTMLListContent += this._standorte[i].getLinkHTML();
			}	
		}
		$('#routeBreaksOutput').html(theStandortHTMLListContent);
	}	

	this.closeAllOpenBallons = function(){
		if (openStandortInfoBallon != null){
			map.removeWindowOverlay(openStandortInfoBallon);
			openStandortInfoBallon = null;
			$('#standortDetails').css('display','none');
		}
	}
}


var MshDirectionImages = new function(){
	this.get=function(inDirection){
		var theRouteSegment = new IWRouteSegment();
	
		if (inDirection == theRouteSegment.DC_START)
					return 'start.gif';
		if (inDirection == theRouteSegment.DC_DESTINATION)
	  				return 'ziel.gif';
		if (inDirection == theRouteSegment.DC_STRAIGHTAHEAD)
	  				return 'geradeaus.gif';
		if (inDirection == theRouteSegment.DC_LEFT)
	  				return 'links.gif';
		if (inDirection == theRouteSegment.DC_HALFLEFT)
	  				return 'halb_links.gif';
		if (inDirection == theRouteSegment.DC_SHARPLEFT)
	  				return 'scharf_links.gif';
		if (inDirection == theRouteSegment.DC_RIGHT)
	  				return 'rechts.gif';
		if (inDirection == theRouteSegment.DC_HALFRIGHT)
	  				return 'halb_rechts.gif';
		if (inDirection == theRouteSegment.DC_SHARPRIGHT)
	  				return 'scharf_rechts.gif';
		if (inDirection == theRouteSegment.DC_ROUNDABOUT)
	  				return 'uturn.gif';
	   				
   			  
		return '';	
	}
}




function MshRouterClient(inMap, inResourcePath) {
  	
	this._logger=log4javascript.getLogger("MshRouterClient");
	this._routeOptions=new MMRouteOptions();
	this._geoClient=new IWGeocoderClient();
	this._routerClient= new MMRouterClient();
  	this._map = inMap;
  	this._resourcePath = inResourcePath;
	this.infoBalloon = null;
  	this._shape = null;
  	
  this.getGeoClient= function(){
  	return this._geoClient;
  };
  
  this.setShape=function(inShape){
  	this._shape = inShape;
  }
  
  this.getShape=function(){
  	return this._shape;
  }
  
  this._addStandortListener = function() {
	  
	  var _onroutestandortListener = IWEventManager.addListener(this._routerClient,'onroutestandort',function(event){
			
			try {
				var root = IWXMLHelper.parse(event).documentElement;
				MshStandortFactory.clearOptions();
				
		       	var theGlobalOptions = root.getElementsByTagName("options");
		       	
		       	MshStandortFactory.getOptions().setXMLToArray(theGlobalOptions[0]);
				MshStandortFactory.getOptions().setValue('kraftstoffValue','');
				
		       	var theBreaks = root.getElementsByTagName("break");
		       	var theBreaksContent = '';
		       	var counter = 0;
		
		       	if (theBreaks.length > 0) {
		       		for (var i = 0; i < theBreaks.length; i++) {
		       			var theOptions = theBreaks[i].getElementsByTagName('options');
		       			var theStandorte = theBreaks[i].getElementsByTagName('standort');
		       			
				       	if (theStandorte.length > 0) {
				       		for (var j = 0; j < theStandorte.length; j++) {
								var theOption = new MshStandortOption();
								theOption.setXMLToArray(theStandorte[j]);
								var theStandort = MshStandortFactory.createStandort(this._map, this._resourcePath, theOption)
								
				       			if (theStandorte[j].parentNode.tagName != 'standorte'){
				       			    counter = counter+1;
									MshStandortFactory.addBestStandort(theStandort);
				       			} else {
				       				MshStandortFactory.add(theStandort);
				       			}
				       		}
				       	}
		            }
		       	}

		       	MshStandortFactory.display();
		       	
				MshStandortFactory.buildHTML($('#infoContent3'));
				$('#standort-info-frame-btm').html(counter+" "+(counter == 1 ? "Standort" : "Standorte")+" " + MshTranslationProperties.getValue('found', getLanguage()) + " " + MshTranslationProperties.getValue('change', getLanguage()) +
						'<a onclick="toggleMap();return false;" href="#"><img src="../resources/de.rast.serways.web.map.SerwaysHomePage/img/pfeil_sw_rechts_small.gif" alt="" id="toggleMapImage2"/></a>');
				IWEventManager.removeListener(_onroutestandortListener);
				IWEventManager.trigger(this, 'onroutestandortend', event);
			
			} catch(e) {
				IWEventManager.removeListener(_onroutestandortListener);
				IWEventManager.trigger(this, 'onroutestandortend', event);
			}
			
		}.iwclosure(this));

	  return _onroutestandortListener;
  }
  
  this._addRouteListener = function(fromName, toName) {

		var _routeListener = IWEventManager.addListener(this._routerClient,'onroute',function(event){
			
			try {
				//clear old route
				this._map.removeLayerByName('route');
				
				_routeSegments=event.route;
		
				IWEventManager.trigger(this,'onredraw',null);
				var layer=new IWLayer(this._map,'route','ROUTE');
				
				this.setShape(new IWShape(event.shape));
				layer.addShape(this.getShape());
				this._map.addLayer(layer);
				this._map.setCenter(event.bounds.getCenter(),this._map.getBoundsZoomlevel(event.bounds));					
			
				var theOutput = $('#routeOutput');
				//theOutput.innerHTML = _routeSegments;
				if(_routeSegments==null||_routeSegments.length==0){
					alert('ROUTING ERROR');
				}else{
		
					var theContent = '<table cellpadding="0" cellspacing="0" border="0" >';
					var theRouteTime = '';
					var theRouteLength = '';
					for(var i=0;i<_routeSegments.length;i++){
							
							var theImage = '';
							
							if (MshDirectionImages.get( _routeSegments[i].getDirection() ) != ''){
					  			theImage = '<img src="'+this._resourcePath+'manoeverpfeile/'+MshDirectionImages.get( _routeSegments[i].getDirection())+'" alt="" title="" />';					
							}
					
							theContent += '<tr class="' + (i%2 ? 'odd' : 'even') + '"><td class="nr">'+(i+1)+'.</td><td class="image">'+theImage+'</td><td>' + _routeSegments[i].getInstruction() + '</td><td class="km">' + _routeSegments[i].getRouteLength() + '</td></tr>';
							theRouteTime = _routeSegments[i].getRouteTime();
							theRouteLength = _routeSegments[i].getRouteLength();
					}
					theContent += '</table>';

					var theSplittTime = theRouteTime.split(':');
					theContent = '<label>' + MshTranslationProperties.getValue('journey', getLanguage()) + ' '+ theRouteLength + ' &ndash; ' + MshTranslationProperties.getValue('approx', getLanguage()) + ' '+theSplittTime[0]+' ' + MshTranslationProperties.getValue('hours', getLanguage()) + ', '+theSplittTime[1]+' ' + MshTranslationProperties.getValue('minutes', getLanguage()) + '</label></div>' + theContent;
					theContent = '<div class="routeOverview"><label>' + MshTranslationProperties.getValue('journeyFrom', getLanguage()) + ' <strong>'+fromName +'</strong> ' + MshTranslationProperties.getValue('journeyTo', getLanguage()) + ' <strong>' + toName + '</strong>' +'</label>' + theContent;
					theContent = '<img id="printLogo" src="'+this._resourcePath+'serways_logo_print.gif" alt="" title="" />' + theContent;

					theOutput.html(theContent);
				}
				IWEventManager.removeListener(_routeListener);
				IWEventManager.trigger(this, 'onrouteend', event);
				try {
					toolbox.toggle();
				} catch(e) {}
			} catch(e) {
				IWEventManager.removeListener(_routeListener);
				IWEventManager.trigger(this, 'onrouteend', event);
			}
			showIsBusy(false);

		}.iwclosure(this));  
		return _routeListener;
  }
  
  this._getOptions = function(inOptions) {
	  	var options=new MMRouteOptions();
	  	options.setRoutingMode(inOptions['routingMode']);
		options.setCitySpeed(inOptions['citySpeed']);
		options.setCountryRoadSpeed(inOptions['countrySpeed']);
		options.setHighwaySpeed(inOptions['highwaySpeed']);
		options.setLanguage(getLanguage());
		options.setProfile(inOptions['profile']);
		options.setDrivingTime(inOptions['drivingTime']);
		return options;
  }
  
  this.beginRoute = function(inStart, inDest, inInterstations, inOptions){

	showIsBusy(true);
	
	var options = this._getOptions(inOptions);
	var fromName = inOptions['fromName'] ? inOptions['fromName'] : $('#startRoute').val();
	var toName = inOptions['toName'] ? inOptions['toName'] : $('#destRoute').val();
	
	this._routerClient.setRouteOptions(options);
	var start=this.parseCoordinate(inStart);
	var destination=this.parseCoordinate(inDest);
	var interstations=null;
	
	var _routeListener = this._addRouteListener(fromName, toName);
	var _onroutestandortListener = this._addStandortListener();
	
	this._routerClient.route(start,destination,interstations);
	
  };
  
  this.parseCoordinate= function(stringCoordinate){
	var coord=null;
	try{
		var chunks=stringCoordinate.split(',');
		var x=parseInt(chunks[0]);
		var y=parseInt(chunks[1]);
		
		coord=new IWCoordinate(x,y);
	}catch(e){
		throw 'Cant parse coordinate string:' + stringCoordinate;
	}
	return coord;
  } 
 	  
}

function repaintWeather(zoomlevel) {

    for(i=0;i<standorte4Weather.length;i++) {
        standorte4Weather[i].repaintWeather();
    }
}

var standorte4Weather = new Array();

function displayWeather(standort) {

    standorte4Weather.push(standort);
    try {
	    $.get("../weather", { standortId: standort.getId() },
	        function(data){
	        
               var root = IWXMLHelper.parse(data).documentElement;
               if(root && root.getElementsByTagName("icon")) {
	               var icon = root.getElementsByTagName("icon")[0];
	               if (typeof(icon)!='undefined'){
	                    try {
	                        var img = resourceFolder+icon.attributes[0].nodeValue.substring(10, icon.attributes[0].nodeValue.length-3)+"png";
	                        standort.addWeatherIcon(img);
	                    } catch(e) {
	                        //alert(e);
	                    }
		           }
               }
	    });
	 } catch(e) {
	   //alert(e);
	 }
}

function toggleButtonImage(button, srcOff, srcOn) {

    if(button.src.substr(button.src.length-srcOff.length, button.src.length) == srcOff) {
        button.src = button.src.substr(0, button.src.length-srcOff.length) + srcOn;
    } else {
        button.src = button.src.substr(0, button.src.length-srcOn.length) + srcOff;
    }       
}


//Hack
var properties = new Array();
properties['Clear'] = "sonnig";
properties['Cloudy'] = "bewölkt";
properties['Mostly Cloudy'] = "teilweise bewölkt";
properties['Rain'] = "Regen";
function translate(str) {

    if(properties[str])
        return properties[str];
    else
        return str;
}



function convertStandortCoord(inResults){
	
	var convertedStandortCoord = new Array();
	var maxEast = 0;
	var maxWest = 10000000;
	var maxNorth = 0;
	var maxSouth = 10000000;
	jQuery.each(inResults, function(){
		
		var theCoord = this.coord.split(',');
		var coordX=parseInt(theCoord[0]);
		var coordY=parseInt(theCoord[1]);
		if(coordX < maxWest) {
		  maxWest = coordX;
		}
		if(coordX > maxEast) {
          maxEast = coordX;
        }
        if(coordY < maxSouth) {
          maxSouth = coordY;
        }
        if(coordY > maxNorth) {
          maxNorth = coordY;
        }
        var coord = new IWLCCEurope((theCoord[0]-300), theCoord[1]).toCoordinate();
        var convertedCoord = coord.getX() + ',' + coord.getY();
        convertedStandortCoord.push({'value':this.value,'coord':convertedCoord, 'serways': this.serways ? "true" : "false",'id':this.id});
	});
	
	return convertedStandortCoord;
}

