var MARKER_OUTSIDE = 1;
var ZOOMLEVEL_HOTELS = 12;
var ZOOMLEVEL_TOURIST = 9;
var ZOOMLEVEL_LAYERSWITCH = 5;

function showSidebar(){
	if($('loading'))
		$('loading').style.display = 'none';
	if($('sidebar').style.display == "none" || $('sidebar').style.display == ""){
	    	
    	//$('sidebar').style.top = $('cockpit').offsetHeight + "px";
        //$('sidebar').style.left = ($('cockpit').getWidth() +5)+ "px";
        //$('sidebar').style.height = $('client_container').style.height;
        $('sidebar').style.maxHeight = $('client_container').getHeight() + 'px';
//        if($('map').style.left == "" || $('map').style.left == 0){
//        	$('map').style.left = $('sidebar').getWidth();
       	//nav.div.style.left = $('sidebar').getWidth()+'px';
       	//$('sidebar_help').style.top = $('')
       	
//        }
        $('sidebar').style.display="inline";
        //alert($('map').offsetWidth + " => " + ($('map').offsetWidth - $('sidebar').offsetWidth));
        //$('map').style.width = ($('map').offsetWidth - $('sidebar').offsetWidth) + "px";
        //$('map').style.width = ($('map').offsetWidth - 300) + "px";
        //$('client_container').style.width=$('client_container').offsetWidth -300 + "px";
        map.updateSize();
	}	
}

function drawMap(str,id,lon,lat,popupcontent,product_type,zoom){
	if(typeof product_type == "undefined"){
		product_type=false;
	}
	if(typeof zoom == "undefined"){
		zoom=false;
	}
	var found=false;
	//alert("Drawing: "+str);
/*	for(var i=0;i<vectors.features.length;i++){
		if(vectors.features[i].geometry.id_dataident == id){
			found = true;
			lastFeatureAdded(vectors.features[i]); //overwrite property, see xajax_addmap()
		}
	}
*/
	if(!found){
		var wkt = new OpenLayers.Format.WKT();
		var poly = wkt.read(str);
		poly.geometry.id_dataident = id;
		poly.geometry.product_type = product_type;
		poly.geometry.lon = lon;
		poly.geometry.lat = lat;
		poly.geometry.popupcontent = popupcontent;
		//var control = drawControls['polygon'];
		//control.drawFeature(poly.geometry);
		//var the_feature = lastFeatureAdded();
		poly.style = {
		fillColor: "#ee9900",
        fillOpacity: 0.4, 
        hoverFillColor: "white",
        hoverFillOpacity: 0.8,
        strokeColor: "#000000",
        strokeOpacity: 1,
        strokeWidth: 2,
        strokeLinecap: "round",
        hoverStrokeColor: "red",
        hoverStrokeOpacity: 1,
        hoverStrokeWidth: 0.2,
        pointRadius: 6,
        hoverPointRadius: 1,
        hoverPointUnit: "%",
        pointerEvents: "visiblePainted"
							    };
		 vectors.addFeatures([poly]);
		 lastFeatureAdded(poly);
        //control.layer.addFeatures([feature]);
        //control.featureAdded(feature);
		if(zoom){
			map.zoomToExtent(poly.geometry.getBounds());
			map.zoomOut(1);
		}
	}else{
		alert("map is already drawed");
	}
	//alert('done');
	
}
var notified = false;
function drawPoint(str,id,lon,lat,popupcontent){
	//found = false;

	var lonlat = new OpenLayers.LonLat(lon,lat);
	var size = new OpenLayers.Size(200,50);
	var markerSize = new OpenLayers.Size(20,34);
	var offset = new OpenLayers.Pixel(-(markerSize.w/2), -markerSize.h);
	var icon = new OpenLayers.Icon('/img/markers/ORANGE.png',markerSize,offset);
	var data = {lonlat: lonlat,popupSize: size, popupContentHTML: popupcontent, icon: icon };
	var myMarker = new OpenLayers.Feature(markers,lonlat,data);
	var theMarker = myMarker.createMarker();
	markers.addMarker(theMarker);
	
	if(!theMarker.onScreen() && !notified){
		xajax_notify(MARKER_OUTSIDE);
		notified = true;
	}
	return theMarker;
	//map.addPopup(myMarker.createPopup(true));
	/*
	var size = new OpenLayers.Size(20,34);
	var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
	var icon = new OpenLayers.Icon('/img/markers/ORANGE.png',size,offset);
	var myMarker = new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon);
	markers.addMarker(myMarker);
	
	popup = new OpenLayers.Popup.Anchored("pointpopup"+id,
		                   new OpenLayers.LonLat(lon,lat),
		                   new OpenLayers.Size(200,50),
		                   popupcontent,
		                   myMarker,
		                   false);
	//popup.setOpacity(0.1);
	popup.setBackgroundColor('');
		
	map.addPopup(popup);
	*/
}

function makeAnchoredPopup(lon,lat,popupcontent){
	/*
	var lonlat = new OpenLayers.LonLat(lon,lat);
	var size = new OpenLayers.Size(200,50);
	*/
	var markerSize = new OpenLayers.Size(20,34);
	var offset = new OpenLayers.Pixel(-(markerSize.w/2), -markerSize.h);
	var icon = new OpenLayers.Icon('/img/markers/ORANGE.png',markerSize,offset);
	/*
	var data = {lonlat: lonlat,popupSize: size, popupContentHTML: popupcontent, icon: icon };
	var myMarker = new OpenLayers.Feature(markers,lonlat,data);
	var theMarker = myMarker.createMarker();
	markers.addMarker(theMarker);
	*/
	searchpopup = new OpenLayers.Popup.AnchoredBubble("searchpopup",
		                   new OpenLayers.LonLat(lon,lat),
		                   new OpenLayers.Size(220,130),
		                   popupcontent,
		                   icon,
		                   false);
	map.addPopup(searchpopup,true);
	//window.setTimeout("map.removePopup(searchpopup);",5000);
}

function removeTrails(){
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.isTrail && (!vectors.features[i].attributes.isAuto || map.getZoom() < 9)) {
			if(vectors.features[i].attributes.hasPoints){
				for(j=markers.markers.length - 1;j>=0;j--){
					if(markers.markers[j].id_trail == vectors.features[i].attributes.id_trail){
						markers.markers[j].protected = false;
						markers.removeMarker(markers.markers[j]);
					}
				}
			}
			vectors.features[i].attributes.protected = false;
			vectors.removeFeatures(vectors.features[i]);
			$('searchgeo').value="";
		}
	}	
}

function addTrail(trail_id,trail_geom,trail_bbox){
	trails_save.push({id:trail_id,geom:trail_geom,bbox:trail_bbox,points:new Array()});
}

function addTrailPoint(id_trail,id_point,p_x,p_y,p_name){
	for(i=0;i<trails_save.length;i++){
		if(trails_save[i].id == id_trail){
			trails_save[i].points.push({id:id_point,x:p_x,y:p_y,desc:p_name});
		}
	}
}

function drawTrails(trails){
	for(var i = 0;i<trails.length;i++){
		for(var j=TrailSave.length-1;j>=0;j--){
			if(TrailSave[j][1] == trails[i][0]){
				drawTrail(TrailSave[j][0],TrailSave[j][1],TrailSave[j][2],TrailSave[j][3],TrailSave[j][4],TrailSave[j][5],TrailSave[j][6]);
			}
		}
	}
	$('mapedo_clearall').style.display="block";
}
var TrailSave = new Array();
function drawTrail(geom,id,hasPoints,selectFeature,doRemoveTrails,zoom,product_type,saveTrail){
	if(typeof(doRemoveTrails) == "undefined"){
		doRemoveTrails = true;
	}
	if(typeof(saveTrail) == "undefined"){
		saveTrail = false;
	}
	if(typeof(product_type) == "undefined"){
		product_type = "";
	}
	if(typeof(zoom) == "undefined"){
		zoom = true;
	}
	if(doRemoveTrails){
		removeTrails();
	}
	if(saveTrail){
		TrailSave.push([geom,id,hasPoints,selectFeature,doRemoveTrails,zoom,product_type]);
	}
	var wkt = new OpenLayers.Format.WKT();
	var linestring = wkt.read(geom);
	linestring.attributes.protected=true;
	linestring.attributes.isTrail=true;
	linestring.attributes.product_type=product_type;
	linestring.attributes.isAuto=false;
	linestring.attributes.hasPoints=hasPoints;
	linestring.attributes.id_trail=id;
	//linestring.events.register('mouseover', linestring, function(evt) { alert('MouseOver!'); OpenLayers.Event.stop(evt); });
	vectors.addFeatures([linestring]);
	lastFeatureAdded(linestring);
	if(zoom){
		map.zoomToExtent(linestring.geometry.getBounds());
	}
	if(typeof selectFeature == "undefined" || selectFeature == 1){
		showMapsOnLine(linestring);
	}
}

var trail_style = {
			fillColor: "#00AA00",
	        fillOpacity: 0.2, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "#00FF00",
	        strokeOpacity: 0.8,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
								    };
function drawTrailMap(trail){
		if(map.getZoom() >= ZOOMLEVEL_TOURIST){
			var found = false;
			
			//check if trails bbox is inside viewport
			
			//draw trail
			var wkt = new OpenLayers.Format.WKT();
			var linestring = wkt.read(trail.geom);
			if(linestring){
				linestring.attributes.protected=true;
				linestring.attributes.isTrail=true;
				linestring.attributes.isAuto=true;
				linestring.attributes.id_trail = trail.id;
				linestring.style = trail_style;
				//check if trail is already drawed
				var inViewport = map.getExtent().intersectsBounds(linestring.geometry.getBounds());
				for(var i= vectors.features.length -1;i>=0;i--){
					if(vectors.features[i].attributes.isTrail && vectors.features[i].attributes.id_trail == trail.id) {
						found = true;
						if(!inViewport){
							//delete trail from map
		    				vectors.features[i].attributes.protected = false;
		    				vectors.removeFeatures(vectors.features[i]);
						}
					}
				}	
				
				if(!found && inViewport){
					vectors.addFeatures([linestring]);
				}
			}
			//lastFeatureAdded(linestring);
		}else{
			//delete trails from map
			for(var i= vectors.features.length -1;i>=0;i--){
				if(vectors.features[i].attributes.isTrail && vectors.features[i].attributes.isAuto) {
					vectors.features[i].attributes.protected = false;
					vectors.removeFeatures(vectors.features[i]);
				}
			}	
		}
}

function showTrailPointDetails(lon,lat,txt){
	//alert("Showing "+txt+" at "+lon+","+lat);
	var elem = $('trailpointpopup');
	elem.innerHTML = txt;
	elem.style.left = lon+"px";
	elem.style.top = lat+"px";
	elem.style.display = "block";
	elem.show();
	
}

function drawTrailPoint(lon,lat,txt,id_trail){
	var size = new OpenLayers.Size(10,17);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var icon = new OpenLayers.Icon('/img/markers/RED.png',size,offset);
    marker = new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon);
    marker.PopupText = txt;
    marker.events.register('mouseover', marker, function(evt) { showTrailPointDetails(evt.clientX+10,evt.clientY+10,evt.object.PopupText); OpenLayers.Event.stop(evt); });
    marker.events.register('mouseout', marker, function(evt) {window.setTimeout("$('trailpointpopup').hide();",1000); OpenLayers.Event.stop(evt); });
    marker.protected = true;
    marker.id_trail = id_trail;
    markers.addMarker(marker);
    
}

function showAllSearchMatches(){
	//alert('min lon: '+maxValues[0]+' max lon: '+maxValues[1]+' min lat: '+maxValues[2]+' max lat: '+maxValues[3]);
	//map.zoomToExtent(new OpenLayers.Bounds(maxValues[0], maxValues[2], maxValues[1], maxValues[3]));
	map.zoomToExtent(markers.getDataExtent);
}

function activate(obj){
	obj.style.color = "#000000";
	if(obj.type == "text"){
		obj.value="";
	}
}
var changedFields = new Array();
function clearChangedFields(){
	changedFields = new Array();
}
function changedField(obj){
	var name = obj.name;
	if(obj.name=='datalang[]')
		name = 'datalang';
	else if(obj.name=='tpcat[]'){
		name = 'tpcat';
	} else if(obj.name=='distributor[]'){
		name = 'distributor';
	}
	
	
	changedFields.push(name);
	$('changedFields').value = changedFields.join(",");
	switch(obj.name){
		case 'price':
		case 'availdate_yyyy':
		case 'availdate_mm':
		case 'availdate_dd':
		case 'delivery_status':
		case 'shippingcost':
		case 'distributor':
			changedFields.push('distributor');
			changedFields.push('shippingcost');
			changedFields.push('delivery_status');
			changedFields.push('availdate_dd');
			changedFields.push('availdate_mm');
			changedFields.push('availdate_yyyy');
			changedFields.push('price');
	}
}
var ns4;
var op5;
var op6;
var agt;
var mac;
var ie; 
var mac_ie;
var ie7;
var p;

function sniffBrowsers() {
	ns4 = document.layers;
	op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1);
	op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1);
	agt=navigator.userAgent.toLowerCase();
	mac = (agt.indexOf("mac")!=-1);
	//ie = (agt.indexOf("msie") != -1); 
	mac_ie = mac && ie;
	ie7 = false;
	ie = (document.all) ? 1 : 0;
	p = (ie) ? "filter" : "MozOpacity";

}


function getStyleObject(objectId, doc) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
    } else {
	return false;
    }
} 

function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
} 

function findImage(name, doc) {
	var i, img;
	for (i = 0; i < doc.images.length; i++) {
    	if (doc.images[i].name == name) {
			return doc.images[i];
		}
	}
	for (i = 0; i < doc.layers.length; i++) {
    	if ((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
    	}
	}
	return null;
}

function getImage(name) {
	if (document.layers) {
    	return findImage(name, document);
	}
	return null;
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}


function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}


function getImageLeft(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
    	if (img.container != null)
			return img.container.pageX + img.x;
		else
			return img.x;
  	} else {
		return getElementLeft(myImage);
	}
	return -1;
}

function getImageTop(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		if (img.container != null)
			return img.container.pageY + img.y;
		else
			return img.y;
	} else {
		return getElementTop(myImage);
	}
	return -1;
}

function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}



function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}

function moveXY(myObject, x, y) {
	obj = getStyleObject(myObject)
	if (ns4) {
		obj.top = y;
 		obj.left = x;
	} else {
		if (op5) {
			obj.pixelTop = y;
 			obj.pixelLeft = x;
		} else {
			obj.top = y + 'px';
 			obj.left = x + 'px';
		}	
	}
}

function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	if (op5 || op6) elem.style.className = myClass;
	else elem.className = myClass;
}

function changeBGColour(myObject, colour) {
	if (ns4) {
		var obj = getObjNN4(document, myObject);
		obj.bgColor=colour;
	} else {
		var obj = getStyleObject(myObject);
		if (op5) {
			obj.background = colour;	
		} else {
			obj.backgroundColor = colour;
		}	
	}
}

function changeImage(target, source) {
	var imageObj;
	
	if (ns4) {
		imageObj = getImage(target);
		if (imageObj) imageObj.src = eval(source).src; 
	} else {
		imageObj = eval('document.images.' + target);
		if (imageObj) imageObj.src = eval(source).src; 
	}
}

	function initMenu(){
		moveXY('subs1_0',0, getElementHeight('menu1') - 1);
		moveXY('subs2_0',getElementWidth('menu1')+3,getElementHeight('menu2') - 1);
		moveXY('sub1_1',0,0);
		moveXY('subs1_1',getElementWidth('sub1_1')-10,0);
		
		for(var i=2;i<=7;i++){
			moveXY('sub1_'+i,0,calculateHeights(i-1,'sub1_'));
			moveXY('subs1_'+i,getElementWidth('sub1_'+i)-10,calculateHeights(i-1,'sub1_'));
		}
		moveXY('icons',getElementLeft('menu1') + getElementWidth('menu1') + getElementWidth('menu2')+20,getElementTop('menu1')-10);
	}
	
	function calculateHeights(untilID,prefix){
		var ret=0;
		for(var i=1;i<=untilID;i++){
			ret = ret + getElementHeight(prefix + i);
		}
		return ret;
	}
	
	
	function showSub(id){
		changeObjectVisibility('subs'+id,"visible");
	}
	
	function hideSub(id){
		changeObjectVisibility('subs'+id,"hidden");
	}
	
	function getBBOX(){
		if(typeof map != "undefined"){
			var bounds = map.getExtent();
			return bounds.toBBOX();
			//return bounds.toGeometry();
		}
		return false;
	}
	var picSave = new Array();
	var elemSave = new Array();
	
	function handleMouse(params){
		if (typeof params.saveStatus == "undefined") {
    		params.saveStatus = true;
  		}	
  		if (typeof params.group == "undefined") {
    		params.group = 0;
  		}	
  		
		var elem = params.elem;
		elem.group = params.group;
		if(document.images){
			var filename = params.elem.src.substring(0,params.elem.src.search(/-[a-z0-9]+\.png/) + 1);
			if(filename.substring(0,4) != "http") {
				filename = "http://www.mapedo.de/img/icons/"+filename;
			}
			//alert("filename1: "+filename);
			var newpic = new Image();
			newpic.src = filename + 'standard.png.gif';
			picSave.push(newpic);
			newpic = new Image();
			newpic.src = filename + 'relief.png.gif';
			picSave.push(newpic);
			newpic = new Image();
			newpic.src = filename + 'tief.png.gif';
			picSave.push(newpic);
		}
		if (typeof params.onclick == "undefined") {
    		onclick = false;
  		}
		if(!elem.onmouseout)
			elem.onmouseout = new Function('mouseOut(this);');
	//	if(!elem.onmouseover){
			elem.onmouseover = new Function('mouseOver(this,"'+params.tooltip+'");');
			
	//	}
		
		if(!elem.onmouseup)
			elem.onmouseup = new Function('mouseUp(this);');
		if(params.onclick!=false){
			if(params.saveStatus)
				elem.onclick = new Function('checkClick(this);'+params.onclick);
			else
				elem.onclick = new Function(params.onclick);
		}else{
			if(!elem.onmousedown)
			elem.onmousedown = new Function('mouseDown(this);');
		}
		elemSave.push(elem);
		//mouseOver(params.elem,params.tooltip);
	}
	
	function checkClick(elem){
		if(elem.checkClick)
			elem.checkClick = !elem.checkClick;
		else
			elem.checkClick = true;
		
		if(elem.checkClick)
			mouseDown(elem);
		else
			mouseUp(elem);
	}
	function mouseOut(elem){
		if(!elem.checkClick){
			var filename = elem.src.substring(0,elem.src.search(/-[a-z0-9]+\.png/) + 1);
			if(filename.substring(0,4) != "http") {
				filename = "http://www.mapedo.de/img/icons/"+filename;
			}
			//alert("filename2: "+filename);
			elem.src = filename + 'standard.png.gif';
		}
		$('tooltip').style.display='none';
	}
	
	function mouseDown(elem){
		if(elem.group > 0){
			for(var i=0;i<elemSave.length;i++){
				if(elemSave[i].group == elem.group && elemSave[i].id != elem.id){
					//elemSave[i].checkClick = false;
					mouseUp(elemSave[i]);
				}
			}
		}
		var filename = elem.src.substring(0,elem.src.search(/-[a-z0-9]+\.png/) + 1);
		if(filename.substring(0,4) != "http") {
			filename = "http://www.mapedo.de/img/icons/"+filename;
		}
		//alert("filename3: "+filename);
		elem.src = filename + 'tief.png.gif';
		
	}
	
	function mouseUp(elem){
		var filename = elem.src.substring(0,elem.src.search(/-[a-z0-9]+\.png/) + 1);
		//alert(filename.substring(0,4));
		if(filename.substring(0,4) != "http") {
			filename = "http://www.mapedo.de/img/icons/"+filename;
		}
		//alert("filename4: "+filename);
		elem.src = filename + 'standard.png.gif';
		elem.checkClick = false;
	}
	
	function mouseOver(elem,tooltip){
		if(!elem.checkClick){
			var filename = elem.src.substring(0,elem.src.search(/-[a-z0-9]+\.png/) + 1);
			if(filename.substring(0,4) != "http") {
				filename = "http://www.mapedo.de/img/icons/"+filename;
			}
			//alert("filename5: "+filename+ " aus "+elem.src);
			elem.src = filename + 'relief.png.gif';
		}
		if(typeof tooltip != "undefined" && tooltip != "undefined"){
			$('tooltip').innerHTML = tooltip;
			$('tooltip').style.display='';
		}

	}
	
	function makeAmountEditable(id){
		var amount = $('amount_'+id).innerHTML;
		$('amount_'+id).innerHTML = '<input name="field_amount_'+id+'" id="field_amount_'+id+'" type="text" size="2" value="'+amount+'">';
		$('makeAmountEditable_'+id).value = 'OK';
		$('makeAmountEditable_'+id).onclick = new Function('makeAmountStatic('+id+')');
	}
	
	function makeAmountStatic(id){
		document.forms.cartform.id_article.value = id;
		document.forms.cartform.action.value = 'updateAmount';
		xajax_processFormData(xajax.getFormValues('cartform'));
		var amount = $('field_amount_'+id).value;
		$('amount_'+id).innerHTML = amount;
		$('makeAmountEditable_'+id).value = 'Ändern';
		$('makeAmountEditable_'+id).onclick = new Function('makeAmountEditable('+id+')');
		
	}
	
	function showPaymethodForm(id){
		$('paymethodform1').style.display='none';
		$('paymethodform3').style.display='none';
		if(id!=2)
			$('paymethodform'+id).style.display='block';
		switch(id){
			case "1":
				$('pay_key').value = $('pay1').value;
				document.orderformular.action = 'https://payport.novalnet.de/ssl_payport';
				break;
			case "3":
				$('pay_key').value = $('pay3').value;
				document.orderformular.action = 'https://payport.novalnet.de/ssl_payport';
				break;
			case "2":
				//document.orderformular.action = "https://www.mapedo.de/?p=order";
				document.orderformular.action = "/?p=order";
				
				//$('orderform').action = "/?p=order";
				break;
		}
		
	}
	
	function header_mouse_down(elem){
		//var filename = elem.src.substring(0,elem.src.search(/\_[a-z0-9]+\.png/) + 1);
		var status = elem.style.background.match(/\_([a-z0-9]+)\.png/);
		if(status[1] == "grau" || status[1] == "mo"){
			//elem.src = filename + 'rot.png';
			elem.style.background = "url('/img/header/button_rot.png')";
			elem.style.color = '#ffffff';
			status = 'rot';
			activateStep(2);
		}else{
			//elem.src = filename + 'maus.png';
			elem.style.background = "url('/img/header/button_mo.png')";
			elem.style.color = '#666666';
			status = 'maus';
		}
		elem.status = status;
	}
	
	function header_mouse_over(elem){
		//var filename = elem.src.substring(0,elem.src.search(/\_[a-z0-9]+\.png/) + 1);
		//button = elem.id;
		if(elem.status == undefined)
			var status = 'grau';
		else
			var status = elem.status;
		if(status == 'grau'){
			elem.style.background = "url('/img/header/button_mo.png')";
			elem.style.color = '#666666';
			elem.status = 'maus';
		}
	}
	
	function header_mouse_out(elem){
		//var filename = elem.src.substring(0,elem.src.search(/\_[a-z0-9]+\.png/) + 1);
		if(elem.status == undefined)
			var status = 'maus';
		else
			var status = elem.status;
		if(status == 'maus'){
			//elem.src = filename + 'grau.png';
			elem.style.background = "url('/img/header/button_grau.png')";
			elem.style.color = '#ffffff';
			elem.status = 'grau';
		}
	}
	
	function activateStep(step){
		//deactiveSteps();
		switch(step){
			case 1:
				break;
			case 2:
				$('select_step1_1').className='activated_select';
				for(var i=1;i<=2;i++){
					$('select_step2_'+i).className='activated_select';
				}
				
			case 3:
				for(var i=1;i<=2;i++){
					$('select_step3_'+i).className='activated_select';
				}
			case 4:
				
				break;
		}
		for(var i=2;i<=3;i++){
			$('pfeil'+i).src = '/img/header/pfeilrot.gif';
			$('line_'+i+'_top').src = '/img/header/begrenzungslinierot.gif';
			$('line_'+i+'_bottom').src = '/img/header/begrenzungslinierot.gif';
			$('header_hint_'+i).className = 'header_hint activated';
		}
		$('header_hint_4').className = 'header_hint activated';
		
	}

	function deactiveSteps(){
		for(var i=1;i<=4;i++){
			if(i>1)$('pfeil'+i).src = '/img/header/pfeilgrau.png';
			$('line_'+i+'_top').src = '/img/header/begrenzungsliniegrau.png';
			$('line_'+i+'_bottom').src = '/img/header/begrenzungsliniegrau.png';
			$('header_hint_'+i).className = 'header_hint greyed';
		}
		for(var i=1;i<=3;i++){
			$('select_step2_'+i).className='greyed';
		}
		$('select_step1').className='greyed'; 
		/*
		switch(step){
			case 1:
				break;
			case 2:
				for(var i=1;i<=3;i++){
					$('select_step2_'+i).className='greyed';
				}
				break;
			case 3:
				break;
			case 4:
				break;
		}
		*/
	}
	
	var iconSave = Array();
	
	iconSave[0] = 'blank';
	iconSave[1] = 'topokarte';
	iconSave[2] = 'freizeit';
	iconSave[3] = 'seekarte';
	iconSave[4] = 'flugkarte';
	iconSave[5] = 'verwaltungskarte';
	iconSave[6] = 'wissenschaftskarte';
	iconSave[7] = 'atlaskarte';
	iconSave[8] = 'freizeit';
	iconSave[9] = 'historische_karten';
	iconSave[97] = 'plano';
	iconSave[98] = 'print';
	iconSave[99] = 'digital';
	iconSave[100] = 'wandern';
	iconSave[101] = 'radtouren';
	iconSave[102] = 'mountainbiken';
	iconSave[103] = 'inlineskaten';
	iconSave[104] = 'kanu_kajak';
	iconSave[105] = 'angeln';
	iconSave[106] = 'klettern';
	iconSave[107] = 'ski';
	iconSave[108] = 'gesundheit';
	iconSave[109] = 'kultur';
	iconSave[110] = 'freizeitkarte';
	iconSave[111] = 'religion';
	iconSave[112] = 'essen_trinken';
	iconSave[113] = 'reiten';
	iconSave[114] = 'amtliche_kartographie';
	iconSave[115] = 'freizeit';
	iconSave[116] = 'touristische_ziele';
	iconSave[117] = 'binnengewaesser';
	iconSave[118] = 'motorrad';
	iconSave[119] = 'militaer';
	iconSave[120] = 'seekarte';
	iconSave[121] = 'flugkarte';
	iconSave[122] = 'verwaltungskarte';
	iconSave[123] = 'wissenschaftskarte';
	iconSave[124] = 'atlaskarte';
	iconSave[125] = 'historische_karten';
	iconSave[126] = 'strassenkarte';
	
	function showCatImg(elem){
		if(elem){
			
			switch(elem.name){
				case 'tpcat_type':
				case 'tpcat_form':
					var value = elem.options[elem.options.selectedIndex].value;
					if(value=='0')value=0;
					var new_img = iconSave[value];
					
					break;
				case 'tpcat_intent':
					var value = elem.options[elem.options.selectedIndex].value;
					var new_img = iconSave[value];
					break;
				case 'tpcat':
				case 'tpcatb':
					var value = elem.options[elem.options.selectedIndex].value;
					if(value.indexOf('-')){
						var myVal = value.split('-');
						new_val = myVal[1];
					}else{
						new_val = value;
					}
					var new_img = iconSave[new_val];
					$('catImg_'+elem.name).title = iconTextSave[new_val];
			}
			//alert('/img/header/icons/'+new_img+'.png');
			$('catImg_'+elem.name).src = '/img/header/icons/'+new_img+'.png';
			
		}
	}
	var AdmMode;
	
	function searchAdm(e){
		if(AdmMode > 0){
	        var lonlat = map.getLonLatFromViewPortPx(e.xy);
	        alert("You clicked " + lonlat.lon + ", " + lonlat.lat);
	        xajax_searchAdm(lonlat.lon,lonlat.lat,AdmMode); 
    	}
	}
	
	function switchSelectAdm(mode){
		/*map.removeControl(MouseDefaults);
		var options = {onClick:function (evt){setGeoAdm(evt,mode)}}
		var MouseDefaults = new OpenLayers.Control.MouseDefaults();
		map.addControl(MouseDefaults);
		*/
		map.events.unregister("click",map, searchAdm);
		if(mode>0){
			AdmMode = mode;
			map.events.register("click", map, searchAdm);
		}else{
			admMode = 0;
		}
	}
	
	function showTooltip(text){
		$('tooltip').innerHTML = text;
		$('tooltip').style.display='';
	}
	function hideTooltip(){
		$('tooltip').innerHTML = '';
		$('tooltip').style.display='none';
	}
	
	function _fireEvent(elem,event){
		if( document.createEvent ) {
		  var evObj = document.createEvent('MouseEvents');
		  evObj.initEvent( event, true, false );
		  elem.dispatchEvent(evObj);
		} else if( document.createEventObject ) {
		  elem.fireEvent(event);
		}
	}
	
	function zoomToFeature(feature){
		/*
		while(!feature.onScreen() && map.isValidZoomLevel(map.zoom - 1)){
			map.zoomTo(map.zoom - 1);
		}
		*/
	}
	
	function refreshFilters(elem){
		/*
		switch(elem.options[elem.options.selectedIndex].value){
			case 'article':
				$('select_step3_2').selectedIndex = 0;	
				$('select_step3_1').disabled = false;
				$('select_step3_2').disabled = true;
				
			break;
			case 'guide':
				$('select_step3_1').selectedIndex = 0;	
				$('select_step3_1').disabled = true;
				$('select_step3_2').disabled = false;
			break;
			case '0':
				$('select_step3_1').disabled = false;
				$('select_step3_2').disabled = false;
			break;
		}
		*/
		xajax_refreshFilters(xajax.getFormValues('searchform'),elem.name);
	}
	
	function addOption(id,val,text,selected){
		option = new Option(text, val, false, selected);
		var pos = $(id).length;
		$(id).options[pos] = option;
		if(selected){
			$(id).selectedIndex = pos;
		}
		if($('dropdownmenu').menuopenfor == id){
			createMenu(id);
		}
	}
	
	function addOptgroup(field_id,optgroup_id,label){
		myList = $(field_id);
		var optgroup = document.createElement('optgroup');
		optgroup.label = label;
		optgroup.id = optgroup_id;
		myList.appendChild(optgroup);
		if($('dropdownmenu').menuopenfor == field_id){
			createMenu(field_id);
		}
	}
	
	function addOptionToOptgroup(id_optgroup,val,text,selected,desc){
		if(typeof desc == "undefined"){
    		desc = false;
    	}
		
		var myList = $(id_optgroup);
		
		//myList.appendChild(optionNew);
		//myList.options[myList.options.length] = new Option(text,val,false,selected);
		var oOption = document.createElement("option");
		var txt = document.createTextNode(text);
		oOption.appendChild(txt);
		if(desc){
			var span_desc = document.createElement('span');
			span_desc.className = 'opt_desc';
			var txt_desc = document.createTextNode(desc);
			span_desc.appendChild(txt_desc);
			oOption.appendChild(span_desc);
		}
		
		oOption.selected = selected;
		oOption.value = val;
		myList.appendChild(oOption);
		//select.appendChild(optG)
		var id = myList.up(0).id;
		if($('dropdownmenu').menuopenfor == id){
			createMenu(id);
		}
	}
	
	function clearOptions(id){
		$(id).innerHTML = "";
	}
	
	var popupSave = Array();
	function addPopup(popup){
		popupSave.push(popup)
	}
	var OnKeyRequestBuffer = 
    {
        bufferText: false,
        bufferTime: 500,
        
        modified : function(strId, strAction)
        {
                setTimeout('OnKeyRequestBuffer.compareBuffer("'+strId+'","'+xajax.$(strId).value+'","'+strAction+'");', this.bufferTime);
        },
        
        compareBuffer : function(strId, strText, strAction)
        {
          /*  if(strText == xajax.$(strId).value && strText == this.bufferText){
            	OnKeyRequestBuffer.makeRequest(strId, strAction);
            }
        */	if (strText == xajax.$(strId).value && strText != this.bufferText)
            {
                this.bufferText = strText;
                OnKeyRequestBuffer.makeRequest(strId, strAction);
            }
            
        },
        
        makeRequest : function(strId, strAction)
        {
   			xajax_search(xajax.getFormValues('searchform'));	
        }
    }
    
   	var OnKeyRequestBufferSearch = 
    {
        bufferText: false,
        bufferTime: 500,
        
        modified : function(strId)
        {
                
        		setTimeout('OnKeyRequestBufferSearch.compareBuffer("'+strId+'","'+xajax.$(strId).value+'");', this.bufferTime);
        },
        
        compareBuffer : function(strId, strText)
        {
            if (strText == xajax.$(strId).value && strText != this.bufferText && strText.length > 3)
            {
                this.bufferText = strText;
                
                OnKeyRequestBufferSearch.makeRequest(strId);
                $('startOverlay').hide();
                $('sidebar_help').hide();
                makeSuggestWait();
                $('sidebar_helper').hide();
                
            }else{
            	$('suggest_div').hide();
            	
            }
        },
        
        makeRequest : function(strId)
        {
            xajax_suggest(xajax.$(strId).value);
        }
    }
    var suggest_blocked=false;
    function showSuggest(){
    	if(!suggest_blocked){
    		$('suggest_div').style.display = "block";
    	}
    }
    
    function hideSuggest(){
    	$('suggest_div').hide();
    }
    
    function makeSuggestWait(){
    	if($('suggest_div').innerHTML == "") {
    		$('suggest_div').innerHTML = "<br><div align\"center\"><img src=\"/img/ajax-loader.gif\"></div><br><br><br>";
    	}else{
    		$('suggest_div').innerHTML = "<div align\"center\"><img src=\"/img/ajax-loader.gif\"></div>"+$('suggest_div').innerHTML;
    	}
    	showSuggest();
    }
    
    function sug(id,type,x,y){
    	var zoomTo = true;
    	if(typeof type == "undefined"){
    		type = "a";
    	}
    	if(typeof x == "undefined" || typeof y == "undefined"){
    		zoomTo = false;
    	}
    	clearTourist();
    	clearHotels();
    	removeTrails();
    	switch(type){
    		case 'a':
    			msgmode = "search";
    			xajax_getDirectView(id);
    			break;
    		case 'm':
    			msgmode = "search";
    			$('q').value="";
    			xajax_searchAt(id,'poi');
    			break;
    		case 'r':
    			msgmode = "search";
    			$('q').value="";
    			xajax_searchAt(id,'river');
    			break;
    		case 's':
    			$('q').value="";
    			msgmode = "search";
    			
    			xajax_searchAt(id,'alt');
    			break;
    		case 't':
    			$('q').value="";
    			msgmode = "search";
    			xajax_searchAt(id,'trail');
    			break;
    	}
    	//used by suggest div
    	if(zoomTo){
    		map.setCenter(new OpenLayers.LonLat(x,y));
    		drawPoint("",null,x,y,"")
    	}
    	$('suggest_div').hide();
    }
    
    function saveTourist(data){
    	tourist_save = data;
    }
    
    function addTourist(x,y,id,level,forceDraw){
    	if(typeof forceDraw == "undefined"){
    		forceDraw = false;
    	}
    	//alert('adding id '+id+' at '+x+','+y);
    	var inViewport = map.getExtent().contains(x,y);
    	for(var i=0;i<vectors.features.length;i++){
    		var f = vectors.features[i];
    		if(f.attributes.id_touristinfo == id && !f.attributes.forceDraw){
    			if(map.getZoom() < ZOOMLEVEL_TOURIST || !inViewport){
    				f.attributes.protected = false;
    				vectors.removeFeatures(f);
    			}else{
    				return false;
    			}
    		}
    	}
    	if(forceDraw || (map.getZoom() >= 6 && inViewport)){
    		switch(level){
    			case 1:
    				break;
    			case 2:
    				if(map.getZoom() < 7){
    					return;
    				}
    				break;
    			case 3:
    				if(map.getZoom() < 8){
    					return;
    				}
    				break;
    			case 4:
    				if(map.getZoom() < 9){
    					return;
    				}
    				break;
    		}
	    	var style_obj1 = {
	               externalGraphic:"http://www.mapedo.de/img/icons/i.gif",
	               graphicWidth: 20,
	               graphicHeight: 20
	           };
		/*	var style_obj = OpenLayers.Feature.Vector.style;
			style_obj.default.externalGraphic = "http://www.mapedo.de/img/icons/i.gif";
			style_obj.default.graphicWidth = 20;
			style_obj.default.graphicHeight = 20;
		*/	
			var Point = new OpenLayers.Feature.Vector(
			new OpenLayers.Geometry.Point(x,y),{protected:true,id_touristinfo:id,forceDraw:forceDraw},style_obj1);
			vectors.addFeatures([Point]);
			if(foundPartner){ //set by xajax_searchPartner()
				//$('results_partner').style.display='';
				//$('results_heading_partner').style.display='block';
				$('results_container_partner').show();
			}
    	}else{
    		/*
    		if($('results_partner')){
    			//$('results_partner').style.display='none';
    			$('results_partner').fade();
    		}
    		if($('results_heading_partner')){
    			//$('results_heading_partner').style.display='none';
    			$('results_heading_partner').fade();
    		}
    		*/
    		//$('results_container_partner').fade();
    	}

    }    
    
    function highlightHotel(id){
    	for(var i=0;i<vectors.features.length;i++){
    		var f = vectors.features[i];
    		if(f.attributes.id_hotel == id){
    			var style_obj1 = {
		               externalGraphic:"http://dev.mapedo.de/img/markers/BLUE.png",
		               graphicWidth: 18,
		               graphicHeight: 30
		           };
		          f.attributes.highlighted=true;
		        vectors.drawFeature(f,style_obj1);
    		}
    	}
    }
    function highlightTourist(id){
    	for(var i=0;i<vectors.features.length;i++){
    		var f = vectors.features[i];
    		if(f.attributes.id_touristinfo == id){
    			var style_obj1 = {
		               externalGraphic:"http://dev.mapedo.de/img/markers/BLUE.png",
		               graphicWidth: 18,
		               graphicHeight: 30
		           };
		          f.attributes.highlighted=true;
		        vectors.drawFeature(f,style_obj1);
    		}
    	}
    }
    
    function addHotel(x,y,id,forceDraw){
    	if(typeof forceDraw == "undefined"){
    		forceDraw = false;
    	}
    	//alert('adding id '+id+' at '+x+','+y);
    	var inViewport = map.getExtent().contains(x,y);
    	for(var i=0;i<vectors.features.length;i++){
    		var f = vectors.features[i];
    		if(f.attributes.id_hotel == id && !f.attributes.forceDraw){
    			if(map.getZoom() < ZOOMLEVEL_HOTELS || !inViewport){
    				f.attributes.protected = false;
    				vectors.removeFeatures(f);
    			}else{
    				//alert("not drawing, feature is ok, zoomlevel: "+map.getZoom());
    				
    				return false;
    			}
    		}
    	}
    	if(map.getZoom() >= ZOOMLEVEL_HOTELS || forceDraw){
    	//	alert("drawing..."+x+","+y);
    		
		    	var style_obj1 = {
		               externalGraphic:"http://dev.mapedo.de/img/H.gif",
		               graphicWidth: 18,
		               graphicHeight: 30
		           };
    		
			var Point = new OpenLayers.Feature.Vector(
			new OpenLayers.Geometry.Point(x,y),{protected:true,id_hotel:id,forceDraw:forceDraw},style_obj1);
			vectors.addFeatures([Point]);
			
    	}else{
    		//alert("not drawing, zoomlevel: "+map.getZoom());
    	}

    }
    
    function zoomToTrail(elem){
    	var id = elem.value;
    	if(id>0){
    		xajax_showTrail(id);
    	}
    }
    
    function zoomToCntry(elem){
    	var id_cntry = elem.value;
    	//if(id_cntry > 0){
    		xajax_zoomTo(2,id_cntry,xajax.getFormValues('searchform'));
    	//}
    }
    function zoomToRegion(elem){
    	var id_reg = elem.value;
    	xajax_zoomTo(3,id_reg,xajax.getFormValues('searchform'));
    }
    var selectedResultItem;
    function sidebar_selectItem(id,noSelect,scroll){
    	hideSuggest();
    	if(typeof scroll == "undefined"){
    		scroll = true;
    	}
    	//xajax_getArticleInfo(id);
    	//$('itemDetails').selectedId = id;
    	/*
    	if($('article_details').selectedId != id){
    		$('article_details').hide();
    	}
    	*/
    	selectedResultItem = id;
    	$$('.searchResultEntry_selected').invoke('removeClassName','searchResultEntry_selected');
    	if(noSelect != false){
    		var control = drawControls['select'];
	    	for(var i=0;i<vectors.features.length;i++){
	    		var myFeature = vectors.features[i];
	    		if(myFeature.geometry.id_dataident == id ){
	    			control.select(myFeature);
	    		}
	    	}
    	}
    	if($('li'+id)){
    		$('li'+id).addClassName('searchResultEntry_selected');
    		if(scroll)
    			$('li'+id).scrollIntoView();
    	}
    	
    }
    function sidebar_unselectItem(id){
    	if($('li'+id)){
    		$('li'+id).removeClassName('searchResultEntry_selected');
    	}
    }
    
    function sidebar_selectTrail(id){
    	var control = drawControls['select'];
    	for(var i=0;i<vectors.features.length;i++){
    		var myFeature = vectors.features[i];
    		if(myFeature.attributes.isTrail && myFeature.attributes.id_trail == id){
    			control.select(myFeature);
    		}
    	}
    }
    
    /**
    *	Called by OpenLayers Popup
    *
    */
    function onFeatureRemove(id_metadata){
    	if($('result_item_'+id_metadata)){
    		$('result_item_'+id_metadata).parentNode.removeChild($('result_item_'+id_metadata));
    	}
    	if($('mo'+id_metadata)){
    		$('mo'+id_metadata).parentNode.removeChild($('mo'+id_metadata));
    	}
    }
    
    function hideFilter(i){
    	var myFilter = $('filter_block_'+i);
    	myFilter.style.display = 'none';
    	var mySwitch = $('showFilter'+i);
    	if(mySwitch){
    		mySwitch.src = '/img/header/'+i+'-plus.gif';
    		setOp(mySwitch,50);
    		switch (i){
    			case 1:
    				$('q').value='';
    				break;
    			case 2:
    				$('searchgeo').value="";
    				break;
    			case 3:
    				$('route').selectedIndex = 0;
    				$('searchgeo').value="";
    				break;
    		}	
    	}
    }
    
    function showFilter(i){
    	var suffix;
    	var myFilter = $('filter_block_'+i);
   		myFilter.style.display = (myFilter.style.display == 'none' || myFilter.style.display == '')?'inline':(i>3)?'none':'inline';
    	switch(i){
    		case 0:
    			//hide all
    			hideFilter(2);
    			hideFilter(3);
    			hideFilter(4);
    			hideFilter(5);
    		case 1:
    			hideFilter(2);
    			hideFilter(3);
    			break;
    		case 2:
    			//hideFilter(1);
    			hideFilter(3);
    			hideFilter(4);
    			hideFilter(5);
    			break;
    		case 3:
    			//hideFilter(1);
    			hideFilter(2);
    			hideFilter(4);
    			hideFilter(5);
    			$('hiddentpcat').value = "2-0";
    			break;
    		case 4:
    			hideFilter(2);
    			hideFilter(3);
    			hideFilter(5);
    			break;
    		case 5:
    			hideFilter(2);
    			hideFilter(3);
    			hideFilter(4);
    			break;
    	}
    	var mySwitch = $('showFilter'+i);
    	if(mySwitch){
	    	var gfx = mySwitch.src.search(/\-plus\.gif/);
	    	if(gfx < 0){
	    		if(i > 3){
	    			suffix = '-plus.gif';
	    			setOp(mySwitch,50);
	    		}else{
	    			suffix = '-minus.gif';
	    			setOp(mySwitch,100);
	    		}
	    		
	    		switch (i){
	    			/*
	    			case 1:
	    				$('q').value='';
	    				break;
	    			case 2:
	    				
	    				break;
	    			case 3:
	    				$('route').selectedIndex = 0;
	    				break;
	    			*/
	    			case 4:
	    				$('select_region').selectedIndex = 0;
	    				$('select_country').selectedIndex = 0;
	    				break;
	    			case 5:
	    				$('select_step1').selectedIndex = 0;
	    				$('select_step3_1').selectedIndex = 0;
	    				$('select_step3_2').selectedIndex = 0;
	    				$('select_step2_1').selectedIndex = 0;
	    				$('select_step2_2').selectedIndex = 0;
	    				break;
    			}
	    	}else{
	    		suffix = '-minus.gif';
	    		setOp(mySwitch,100);
	    		var options = new Array('');
	    		xajax_getHelp('showFilter'+i);
	    	}

	    	mySwitch.src = '/img/header/'+i+''+suffix;
    	}
    }
    
    function showSearchResults(){
    
    	$('cart_container').style.display = 'none';
    	$('article_details_sidebar').style.display = 'none';
    	$('search_container').style.display = '';
    	$('sidebar_searchresults').style.display = '';
    	$('head_cart').style.backgroundColor = '#b3b2b2';
    	$('head_search').style.backgroundColor = '#9C221B';
    	$('search_leftcorner').style.background = "url(/img/eckelinksoben_rot.gif)";
    	$('search_rightcorner').style.background = "url(/img/eckerechtsoben_rot.gif)";
    	$('cart_leftcorner').style.background = "url(/img/eckelinksoben.gif)";
    	$('cart_rightcorner').style.background = "url(/img/eckerechtsoben.gif)";
    	$('q').blur();
    	searchResultsAvailable = true;
    	data = saveSearchState();
    	addGoBack(new Array('searchResults',data[0],data[1],data[2]));
    }
    function showCart(){
    	if($('sidebar').style.display == "none" || $('sidebar').style.display == ""){
	    	/*
	    	$('sidebar').style.top = $('cockpit').offsetHeight + "px";
	        $('sidebar').style.left = ($('cockpit').offsetWidth - 250) + "px";
	        $('sidebar').style.height = $('client_container').style.height;
	        $('sidebar').style.maxHeight = $('client_container').style.height;
	        //$('sidebar').style.overflow = 'hidden'; //wegen search_result_mouseover deaktiviert
	        
	        $('sidebar').style.display="inline";
	        
	        //alert($('map').offsetWidth + " => " + ($('map').offsetWidth - $('sidebar').offsetWidth));
	        //$('map').style.width = ($('map').offsetWidth - $('sidebar').offsetWidth) + "px";
	        $('map').style.width = ($('map').offsetWidth - 250) + "px";
	        $('showRoomOverlay').show();
	        $('showRoomOverlay').style.width = ($('showRoomOverlay').offsetWidth - 250) + "px";
	        $('showRoomOverlay').hide();
	        
	        map.updateSize();
	        */
		}	
		$('sidebar_searchresults').show();
    	$('search_container').style.display = 'none';
    	if($('article_details_sidebar').style.display != "none"){
    		$('article_details_sidebar').hide();
    		//searchResultsAvailable = true;
    	}
    	$('cart_container').style.display = '';
    	$('head_cart').style.backgroundColor = '#9C221B';
    	$('head_search').style.backgroundColor = '#b3b2b2';
    	$('search_leftcorner').style.background = "url(/img/eckelinksoben.gif)";
    	$('search_rightcorner').style.background = "url(/img/eckerechtsoben.gif)";
    	$('cart_leftcorner').style.background = "url(/img/eckelinksoben_rot.gif)";
    	$('cart_rightcorner').style.background = "url(/img/eckerechtsoben_rot.gif)";
    }

    
    function removeFeature(id,featuretype){
    	if(typeof featuretype == "undefined"){
    		featuretype = 'map';
    	}
    	switch(featuretype){
    		case 'map':
	    		//close the vector map
		        for(var i=0;i<vectors.features.length;i++){
		    		var myFeature = vectors.features[i];
		    		if(myFeature.geometry.id_dataident == id && id > 0 && myFeature.geometry.id_dataident > 0){
		    		/*	if(OpenLayers.Util.indexOf(vectors.selectedFeatures, myFeature) > -1) {
		    				control.unselect(myFeature);
		    			}
		    		*/
		    		deselect(myFeature);
		    		vectors.removeFeatures(myFeature);
		    		i--; //feature array is being reorderd on delete, jump back to catch the next entry
		    		onFeatureRemove(id);
		    		}
		    	}
    			break;
    		case 'trail':
    			for(var i=0;i<vectors.features.length;i++){
		    		var myFeature = vectors.features[i];
		    		if(myFeature.attributes.isTrail && myFeature.attributes.id_trail == id){
		    			myFeature.attributes.protected = false;
			    		deselect(myFeature);
			    		vectors.removeFeatures(myFeature);
			    		i--; //feature array is being reorderd on delete, jump back to catch the next entry
			    		onFeatureRemove(id);
		    		}
		    	}
		    	//remove markers on trail, too
		    	for(var i=0;i<markers.markers.length;i++){
		    		var myMarker = markers.markers[i];
		    		if(myMarker.id_trail && myMarker.id_trail == id){
		    			myMarker.protected = false;
			    		markers.removeMarker(myMarker);
			    		i--; //feature array is being reorderd on delete, jump back to catch the next entry
		    		}
		    	}
    			break;
    	}
    	
    }
    
    function detailsShowMap(id,zoomto,select){
    	if(typeof $('search_details_eye').activeEye == "undefined" || $('search_details_eye').activeEye === true){
    		removeFeature(id);
    		$('search_details_eye').src = "/img/icons/auge.gif";
    		$('search_details_eye').activeEye = false;
    	}else{
    		xajax_showMap(id,zoomto,select);
    		$('search_details_eye').src = "/img/icons/augex.gif";
    		$('search_details_eye').activeEye = true;
    	}
    }
    
    var eventids;
    function showEventDetails(id){
    	/*
		for(var i=0;i<eventids.length;i++)    	{
			$('details_'+eventids[i]+'_full').hide();
			$('details_'+eventids[i]+'_short').show();
		}
		*/
    	$$('.EventFull').invoke('hide');
    	$$('.EventShort').invoke('show');
		$('details_'+id+'_full').show();
		$('details_'+id+'_short').hide();
    }
    var infolinkids;
    function showInfolinkDetails(id){
    	/*
		for(var i=0;i<infolinkids.length;i++)    	{
			$('infodetails_'+infolinkids[i]+'_full').hide();
			$('infodetails_'+infolinkids[i]+'_short').show();
		}
		*/
    	$$('.LinkFull').invoke('hide');
    	$$('.LinkShort').invoke('show');
		$('infodetails_'+id+'_full').show();
		$('infodetails_'+id+'_short').hide();
    }
    

/* n is the element node
   v is the opacity value, from 0 to 100. */

function op(n,v){
    v = (ie) ? "alpha(opacity="+v+")" : v/100;
    n.style[p] = v;
}

function setOp(element,val){
	new Effect.Opacity(element, 
       {duration:0,to:val/100});
}
function markSearchResult(id){
	/*
	if($('result_item_'+id)){
		$('result_item_'+id).className = "search_result_item_selected";
		$('result_item_td_'+id).style.color = "#ffffff";
	}
	*/
	$('li'+id).addClassName('searchResultEntry_selected');
}
function unmarkSearchResult(id){
	/*
	if($('result_item_'+id)){
		$('result_item_'+id).className = "search_result_item";
		$('result_item_td_'+id).style.color = "#000000";
	}
	*/
	if($('li'+id)){
		$('li'+id).removeClassName('searchResultEntry_selected');
	}
}
var highlighted_features = new Array();
var unhighlighted_features = new Array();
var HelperHidden = false;
function highlightSearchResult(id,highlightInMap){
	if(typeof highlightInMap == "undefined"){
		highlightInMap = true;
	}
	showMo(id);
	if(!HelperHidden){
		$('sidebar_helper').hide();
		HelperHidden=true;
	}
	if(highlighted_features.length > 0){
		for(var i=0;i<highlighted_features.length;i++){
			unhighlightSearchResult(highlighted_features[i]);
		}
	}
	if(highlightInMap){
		if(OpenLayers.Util.indexOf(highlighted_features,id) == -1){
			var style = {
				//fillColor: "#ee9900",
				fillColor: "#0000FF",
		        fillOpacity: 0.4, 
		        hoverFillColor: "white",
		        hoverFillOpacity: 0.8,
		        strokeColor: "#0000FF",
		        strokeOpacity: 1,
		        strokeWidth: 2,
		        strokeLinecap: "round",
		        hoverStrokeColor: "red",
		        hoverStrokeOpacity: 1,
		        hoverStrokeWidth: 0.2,
		        pointRadius: 6,
		        hoverPointRadius: 1,
		        hoverPointUnit: "%",
		        pointerEvents: "visiblePainted"
									    };
			changeStyle(id,style);
			
			for(var i=0;i<vectors.features.length;i++){
				myFeature = vectors.features[i];
				if(myFeature.geometry.id_dataident == id){
					if(!myFeature.centroid){
						var centroid = myFeature.geometry.getBounds().getCenterLonLat();
						vectors.features[i].centroid = centroid;
					}else{
						var centroid = myFeature.centroid;
					}
				}
			}
			drawArrow(centroid);
		}
	}else{
		removeArrow();
	}
	$('li'+id).addClassName('highlighted_li');
	//$('delete_eye_'+id).show();
	//obj = null;
	style = null;
	highlighted_features.push(id);
	OpenLayers.Util.removeItem(unhighlighted_features, id);
	$$('.searchResultEntry_selected').invoke('removeClassName','searchResultEntry_selected');
	
}


function showMo(id){
	mo_cancel();
	$('result_mo').style.top = (ypos - 20) + 'px'; //global variable, see init() and getMouseXY()
	$('result_mo').style.display="block";
	if($('mo'+id)){
		$('result_mo').innerHTML = $('mo'+id).innerHTML;
		createLinkListener();
	}else{
		$('result_mo').innerHTML = '<img src="/img/ajax-loader.gif">';
		window.setTimeout("showMo('"+id+"')",1000);
	}
	//draw arrow if element is hotel/touristinfo
	if(id.length > 4){
		if(id.substr(0,5) == "touri"){
			drawTouristArrow(id);
		}
		if(id.substr(0,5) == "hotel"){
			drawHotelArrow(id);
		}
		if(id.substr(0,5) == "trail"){
			drawTrailArrow(id);
		}
	}
}
function highlightTrail(id){
	if(OpenLayers.Util.indexOf(highlighted_features,'trail'+id) == -1){
		var style = {
			fillColor: "#0000FF",
	        fillOpacity: 0.4, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "#0000FF",
	        strokeOpacity: 1,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
								    };
		changeStyle(id,style,'trail');
		if($('litrail'+id)){
			$('litrail'+id).addClassName('highlighted_li');
		}
		style = null;
		highlighted_features.push('trail'+id);
		OpenLayers.Util.removeItem(unhighlighted_features, 'trail'+id);
	}
}
function movePopup(doUpdateArrow){
	if(typeof doUpdateArrow == "undefined"){
		doUpdateArrow = true;
	}
	$('result_mo').style.top = (ypos - 20) + 'px'; //global variable, see init() and getMouseXY()
	var new_y = ypos + ($('result_mo').getHeight() / 2) - 100;
	//$('copyright').innerHTML = new_y + " (mouse: " + ypos
	if(doUpdateArrow){
		updateArrow(new_y);
	}
}
var mo_timer;
function unhighlightSearchResult(id,highlightInMap){
	
	//obj.style.display='none';
	//if(OpenLayers.Util.indexOf(unhighlighted_features,id) == -1){
	if(typeof highlightInMap == "undefined"){
		highlightInMap = true;
	}
	if(highlightInMap){
		var style = {
			fillColor: "#ee9900",
	        fillOpacity: 0.4, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "#000000",
	        strokeOpacity: 1,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
								    };
			changeStyle(id,style);
	}
		//$('delete_eye_'+id).hide();
		if($('li'+id)){
			$('li'+id).removeClassName('highlighted_li');
		}
		style = null;
		unhighlighted_features.push(id);
		OpenLayers.Util.removeItem(highlighted_features, id);
		
	//}
	
}
function unhighlightTrail(id){
	if(OpenLayers.Util.indexOf(unhighlighted_features,'trail'+id) == -1){
		var style = {
			fillColor: "#ee9900",
	        fillOpacity: 0.4, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "#ee9900",
	        strokeOpacity: 1,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
								    };
		changeStyle(id,style,'trail');
		if($('litrail'+id)){
			$('litrail'+id).removeClassName('highlighted_li');
		}
		style = null;
		unhighlighted_features.push('trail'+id);
		OpenLayers.Util.removeItem(highlighted_features, 'trail'+id);
	}
	
}

function mo_hide()
{
	mo_timer = window.setTimeout("hidemo();",1000);
	//$('result_mo').hide();
}

function hidemo(){
	$('result_mo').hide();
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.isArrow){
			vectors.removeFeatures(vectors.features[i]);
		}else if(vectors.features[i].attributes.id_hotel && !vectors.features[i].attributes.highlighted){
			myFeature2 = vectors.features[i];
			myFeature2.style.externalGraphic = '/img/H.gif';
			vectors.drawFeature(myFeature2);	
		}else if(vectors.features[i].attributes.id_touristinfo){
			myFeature2 = vectors.features[i];
			myFeature2.style.externalGraphic = '/img/icons/i.gif';
			vectors.drawFeature(myFeature2);	
		}
	}
}

function mo_cancel(){
	
	if(mo_timer){
		 window.clearTimeout(mo_timer);
	}
	
}

var feature_index = false;
function index_features(){
	if(!feature_index){
		feature_index = new Array();
		for(var i=0;i<vectors.features.length;i++){
			if(!feature_index[vectors.features[i].geometry.id_dataident]){
				feature_index[vectors.features[i].geometry.id_dataident] = new Array();
			}
			feature_index[vectors.features[i].geometry.id_dataident].push(vectors.features[i]);
		}
	}	
	return feature_index;
}

function changeStyle(id,style,featuretype){
//	var index = index_features();
//	var myFeatures = index[id];
	var myFeature;
	if(typeof(featuretype) == "undefined"){
		featuretype = "map";
	}
	/*
	for(var i=0;i<vectors.selectedFeatures.length;i++){
		myFeature = vectors.selectedFeatures[i];
		if(myFeature.geometry.id_dataident == id){
			myFeature = null;
			return false; //do nothing if feature is currently selected
		}
	}
    */
	//alert('start drawing id: '+id);
	
	for(var i=0;i<vectors.features.length;i++){
		myFeature = vectors.features[i];
		if(featuretype == "trail" && myFeature.attributes && myFeature.attributes.isTrail && myFeature.attributes.id_trail == id){
			vectors.drawFeature(myFeature,style);
		}
		else if(myFeature.geometry.id_dataident == id && myFeature.style != style){
			vectors.features[i].style = style;
			vectors.drawFeature(myFeature,style);
		}else if(myFeature.geometry.id_dataident > 0){
			vectors.drawFeature(myFeature,myFeature.style);
		}
	}
	
	//if(OpenLayers.Util.indexOf(vectors.selectedFeatures,styleFeature) == -1){ //do nothing if feature is currently selected
		
	//}
	
	/*
	for(var i=0;i<myFeatures.length;i++){
		myFeature =myFeatures[i];
		if(myFeature.geometry.id_dataident == id && myFeature.style != style){
			vectors.drawFeature(myFeature,style);
		}
	}
	*/
	//alert('finished drawing id: '+id);
	myFeature = null;i=null;
}
function initTooltips(){
/*      $$('a[title], img[title]').invoke('observe', 'mouseover', function(evt){
          var element = evt.findElement('a,img'), text = element.getAttribute('title');
          var tooltip = new Element('div', {'class':'tooltip'}).update(text);
          element.removeAttribute('title'); element.setAttribute('_title', text);
          element.insert({'after': tooltip.setStyle({'left':element.positionedOffset().first()+'px'})});
      }).invoke('observe', 'mouseout', function(evt){
          var element = evt.findElement('a,img'), text = element.getAttribute('_title');
          element.removeAttribute('_title'); element.setAttribute('title', text);
          if (element.next().hasClassName('tooltip')) element.next().remove();
      });
*/

}

function switchLayer(layer){
	switch(layer){
		case 'topo':
			map.setBaseLayer(layer_cache_py_all);
			$('layerswitcher_topo').style.fontWeight="bold";
			$('layerswitcher_sat').style.fontWeight="normal";
			break;
		case 'satellite':
			map.setBaseLayer(sat_layer);
			$('layerswitcher_sat').style.fontWeight="bold";
			$('layerswitcher_topo').style.fontWeight="normal";
			break;
	}
}

function checkIE(obj,mode){
	if(ie){
		switch(mode){
			case 1:
				if(obj.style.width != "auto"){
					obj.originalWidth = obj.style.width;
				}
				//alert('width saved: '+obj.originalWidth);
				var originalOffsetWidth = obj.offsetWidth;
				obj.style.width = "auto";
				id = obj.id;
				//alert(obj.offsetWidth +" < " + originalOffsetWidth + " = " + obj.offsetWidth);
				/* if(obj.offsetWidth > 0 && originalOffsetWidth>0 &&obj.offsetWidth!="undefined" && originalOffsetWidth!="undefined" && obj.offsetWidth < originalOffsetWidth){
					obj.style.width = obj.originalWidth;
				}*/
				break;
			case 2:
				obj.style.width = obj.originalWidth;
				//alert('width back to: '+obj.originalWidth);
				break;
		}
	}
}


function removeFeatureViaEye(event){
	var element = event.element();
	removeFeature(element.id_metadata);
	Event.stop(event);
}
function selecttpcat(tpcat){
	$('select_step1_1').options[0].selected = true;
	$('select_step1_1b').options[0].selected = true;
	for (i = 0; i < $('select_step1_1').length; ++i){
    	if ($('select_step1_1').options[i].value == tpcat)
      		$('select_step1_1').options[i].selected = true;
	}
}

function selectfield(field,value){
	if(field == "tpcat"){
		field = "select_step1_1";
		$('select_step1_1b').options[0].selected = true;
	}
	if($(field)){
		var elem = $(field);
	}else{
		if(document.getElementsByName(field)){
			var elem = document.getElementsByName(field)[0];
		}
	}
	if(elem && elem.options && elem.options.length > 1){
		for (i = 0; i < elem.options.length; i++){
			//alert(elem.options + " und " + elem.options[i]);
			var elemoptions = elem.options;
    		if (elem.options && elem.options[i]){
    			if(elem.options[i].value == value){
	    			elem.options[i].selected = true;
		      		if($(elem.id+'_text')){
		      			$(elem.id+'_text').innerHTML = elem.options[i].innerHTML;
		      		}
		      		
      				return true;
    			}
    		}else{
    			alert("Fehler: "+elem.options + " und " + elem.options[i]);
    		}
		}
	}else{
		//alert('Nur eine Option!' + elem.options.length);
		window.setTimeout("selectfield('"+field+"','"+value+"')",1000);
	}
}

function createMenu(id){
	var elem = $(id);
	var textelem = $(id+"_text");
	var top = textelem.viewportOffset().top + textelem.getHeight();
	var left = textelem.viewportOffset().left;
	if(document.documentElement.clientWidth){ //ie6, standard-conform mode
		var maxWidth = document.documentElement.clientWidth;
	}else if(document.body.clientWidth){ //ie6, quirksmode
		var maxWidth = document.body.clientWidth;
	}else{ //mozilla
		var maxWidth = window.innerWidth;
	}
	var menu = $('dropdownmenu');
	$(id+"_arrow").onclick=null;
	menu.menuopenfor = id;
	menu.style.top =  "0px";
	menu.style.left =  "0px";
	menu.innerHTML = "";
	var G=elem.getElementsByTagName('optgroup');
	var Opts;
	//console.log('options: '+elem.length);
	//alert('options: '+elem.length+' optgroups: '+G.length);
	var menulist = document.createElement('ul');
	menulist.className = "DDoptlist_top";
	var index=1;
	if(G.length){
		for (var i=0;i<G.length;i++){
			Opts = G[i].getElementsByTagName('option');
			var Gli = document.createElement('li');
			
			Gli.innerHTML = G[i].label;
			Gli.className = "DDMenuGroup";
			optlist = document.createElement('ul');
			optlist.className = "DDoptlist";
			for(var j=0;j<Opts.length;j++){
				
				var Oli = document.createElement('li');
				
				Element.extend(Oli);
				Oli.addClassName("DDMenuItem");
				var ali = document.createElement('a');
				Element.extend(ali);
				ali.href = "#";
				ali.innerHTML = Opts[j].innerHTML;
				if(index == elem.selectedIndex){
					Oli.style.backgroundColor="#c6c6c6";
				}
				Oli.textfieldvalue = Opts[j].innerHTML;
				Oli.numIndex = index;
				index++;
				Oli.onclick = function(){$(id).selectedIndex = this.numIndex;$(id+"_text").innerHTML = this.textfieldvalue;$(id).onchange();}
				Oli.appendChild(ali);
				optlist.appendChild(Oli);
			}
			Gli.appendChild(optlist);
			menulist.appendChild(Gli);
		}
		menu.appendChild(menulist);
	}else{
		Opts = elem.getElementsByTagName('option');
		index = 0;
		for(var j=0;j<Opts.length;j++){
			var Oli = document.createElement('li');
			Element.extend(Oli);
			Oli.addClassName("DDMenuItem");
			var ali = document.createElement('a');
			Element.extend(ali);
			ali.href="#";
			ali.innerHTML = Opts[j].innerHTML;			
			if(index == elem.selectedIndex){
				Oli.style.backgroundColor="#c6c6c6";
			}
			Oli.textfieldvalue = Opts[j].innerHTML;
			Oli.numIndex = index;
			
			index++;
			Oli.onclick = function(){$(id).selectedIndex = this.numIndex;$(id+"_text").innerHTML = this.textfieldvalue;$(id).onchange();hideDropdown();}
			//ali.onmouseout = function(){this.style.backgroundColor="#ffffff";}
			Oli.appendChild(ali);
			menulist.appendChild(Oli);
		}
		menu.appendChild(menulist);
	}
	if(menu.style.display == "none"){
		menu.show();
	}
	//calculate new position
	//alert(maxWidth+" - "+left+" < "+getElementWidth('dropdownmenu')+": "+(maxWidth - left < getElementWidth('dropdownmenu')));
	if(maxWidth - left < menu.getWidth()){
		left = left - menu.getWidth() + textelem.getWidth() + 20;
	}
	if(getElementHeight('dropdownmenu') < 300){
		menu.style.overflowY = "auto";
	}else{
		menu.style.overflowY = "scroll";
		menu.style.overflowX = "hidden";
	}
	menu.style.minWidth = (textelem.getWidth()-6)+'px';
	menu.style.top =  top+"px";
	menu.style.left =  left+"px";
	
	eventCount = 0;
	document.onclick = hideDropdown;
}
var eventCount=0;
function hideDropdown(Event){
	if(eventCount > 0){
		if($('dropdownmenu'))$('dropdownmenu').hide();
		if($('select_step1_1_arrow'))$('select_step1_1_arrow').onclick = function(){createMenu('select_step1_1')};
		if($('landing_select_arrow'))$('landing_select_arrow').onclick = function(){createMenu('landing_select')};
		if($('select_step1_1b_arrow'))$('select_step1_1b_arrow').onclick = function(){createMenu('select_step1_1b')};
		if($('select_region_cat_arrow'))$('select_region_cat_arrow').onclick = function(){createMenu('select_region_cat')};
		if($('select_region_arrow'))$('select_region_arrow').onclick = function(){createMenu('select_region')};
		if($('routecat_arrow'))$('routecat_arrow').onclick = function(){createMenu('routecat')};
		if($('route_arrow'))$('route_arrow').onclick = function(){createMenu('route')};
		if($('select_step1_arrow'))$('select_step1_arrow').onclick = function(){createMenu('select_step1')};
		if($('select_step3_1_arrow'))$('select_step3_1_arrow').onclick = function(){createMenu('select_step3_1')};
		if($('select_step2_1_arrow'))$('select_step2_1_arrow').onclick = function(){createMenu('select_step2_1')};
		if($('select_step2_2_arrow'))$('select_step2_2_arrow').onclick = function(){createMenu('select_step2_2')};
		if($('select_step3_2_arrow'))$('select_step3_2_arrow').onclick = function(){createMenu('select_step3_2')};
	}else{
		eventCount++;
	}
}
function showSearchMouseOver(event){
	unhighlightSearchResult(this.id_metadata);sidebar_selectItem(this.id_metadata);this.hide();
	event.stop();
}

function mapedo_search(params,bbox,initial){
	if(typeof initial == "undefined"){
		initial = false;
	}
	msgmode = "search";
	forceMessage=true;
	suggest_blocked= true;
	$('suggest_div').hide();
	xajax_search(params,bbox,initial);
	clearHotels();
	removeTrails();
	clearTourist();
	if(typeof searchpopup_marker != "undefined"){
		//markers.removeMarker(searchpopup_marker);
	}
	if(piwikTracker && !initial){
		piwikTracker.trackGoal(5);
	}
}

function clearHotels(){
	for(var i=vectors.features.length;i>0;i--){
		var f = vectors.features[i-1];
		if(f.attributes.id_hotel && f.attributes.forceDraw){
			f.attributes.protected = false;
			vectors.removeFeatures(f);
		}
	}
}

function clearTourist(){
	for(var i=vectors.features.length;i>0;i--){
		var f = vectors.features[i-1];
		if(f.attributes.id_touristinfo){
			f.attributes.protected = false;
			vectors.removeFeatures(f);
		}
	}
}
var openResults = new Array();
var closedResults = new Array();
var ids;
var switches;
function switchVisibility(id,switch_id,product_type){
	if(typeof product_type == "undefined"){
		product_type=false;
	}
	var obj = $(id);
	var swi = $(switch_id);
	var myobj1;
	var myobj2;
	OpenLayers.Util.removeItem(closedResults, id);
	OpenLayers.Util.removeItem(openResults, id);
	if(obj.style.display=="none"){
		obj.style.display = "block";
		swi.src = "/img/swi-minus-s.gif";
		openResults.push(id);
		if(id != "results_partner"){
			removeAllTypes(); 
			for(var i=0;i<ids.length;i++){
				//myobj1 = $(ids[i]);
				//myobj2 = $(switches[i]);
				myobj1 = document.getElementById(ids[i]);
				myobj2 = document.getElementById(switches[i]);
				if(ids[i] != id && myobj1 && myobj2){
					myobj1.style.display="none";
					myobj2.src = "/img/swi-plus-s.gif";
					if(!isClosed(ids[i])){
						closedResults.push(ids[i]);
						OpenLayers.Util.removeItem(openResults, ids[i]);
					}
				}
			}
		}
		if(product_type){
			drawType(product_type);
		}
	}else{
		obj.style.display = "none";
		swi.src = "/img/swi-plus-s.gif";
		if(!isClosed(id)){
			closedResults.push(id);
		}
		if(product_type){
			removeType(product_type);
		}
	}
	switchPartnersByProductType();
}

function isOpen(id){
	return (OpenLayers.Util.indexOf(openResults,id) != -1);
}

function isClosed(id){
	return (OpenLayers.Util.indexOf(closedResults,id) != -1);
}

function loadSwitchState(ids,switches){
	/*if(!isOpen('results_group_50')){
		switchVisibility('results_group_50','viswitch_50',50);
	}*/
	for(var i=0;i<ids.length;i++){
		if(isOpen(ids[i])){ //&& ids[i]!="results_group_50"){
				//alert('switching '+ids[i]);
				switchVisibility(ids[i],switches[i],ids[i].substring(14));
		}else{
			//alert('not switching '+ids[i]);
		}
	}
	if(openResults.length==0){
		switchVisibility('results_group_50','viswitch_50',50);
	}
}
sniffBrowsers();
var MapSave = new Array();
function saveMap(str,id,lon,lat,popupcontent,product_type){
	MapSave.push(new Array(product_type,str,id,lon,lat,popupcontent));
}

function drawType(product_type){
	var the_map;
	var maps_to_draw= new Array();
	if(product_type.substr(0,5) == "trail"){
		for(var i=0;i<TrailSave.length;i++){
			the_map = TrailSave[i];
			if(the_map[6]==product_type){
				maps_to_draw.push([the_map[1],the_map[2],the_map[3],the_map[4],the_map[5],the_map[0]]);
			}
		}
	}else{
		for(var i=0;i<MapSave.length;i++){
			the_map = MapSave[i];
			if(the_map[0] == 52){
				the_map[0] = 50;
			}
			if(the_map[0] == 61){
				the_map[0] = 60;
			}
			
			if(the_map[0]==product_type){
				//drawMap(the_map[1],the_map[2],the_map[3],the_map[4],the_map[5],the_map[0]);
				maps_to_draw.push([the_map[1],the_map[2],the_map[3],the_map[4],the_map[5],the_map[0]]);
			}
		}
	}
	if(maps_to_draw.length > 0){
		if(product_type.substr(0,5) == "trail"){
			drawTrails(maps_to_draw);
		}else{
			drawMaps(maps_to_draw);
		}
		map.zoomToExtent(vectors.getDataExtent());
	}
}

function drawMaps(maps){
	//drawMap(str,id,lon,lat,popupcontent,product_type){
	var maps_to_draw = new Array();
	for(var i=0;i<maps.length;i++){
		var wkt = new OpenLayers.Format.WKT();
		var poly = wkt.read(maps[i][0]);
		poly.geometry.id_dataident = maps[i][1];
		poly.geometry.product_type = maps[i][5];
		poly.geometry.lon = maps[i][2];
		poly.geometry.lat = maps[i][3];
		poly.geometry.popupcontent = maps[i][4];
		//var control = drawControls['polygon'];
		//control.drawFeature(poly.geometry);
		//var the_feature = lastFeatureAdded();
		poly.style = {
		fillColor: "#ee9900",
	    fillOpacity: 0.4, 
	    hoverFillColor: "white",
	    hoverFillOpacity: 0.8,
	    strokeColor: "#000000",
	    strokeOpacity: 1,
	    strokeWidth: 2,
	    strokeLinecap: "round",
	    hoverStrokeColor: "red",
	    hoverStrokeOpacity: 1,
	    hoverStrokeWidth: 0.2,
	    pointRadius: 6,
	    hoverPointRadius: 1,
	    hoverPointUnit: "%",
	    pointerEvents: "visiblePainted"
							    };	
		maps_to_draw.push(poly);
	}
	
	 vectors.addFeatures(maps_to_draw);
	 lastFeatureAdded(poly);
	 $('mapedo_clearall').style.display="block";
}

function removeType(product_type){
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].geometry.product_type == product_type) {
				vectors.features[i].attributes.protected = false;
				vectors.removeFeatures(vectors.features[i]);
		}
	}		
}

function removeAllTypes(){
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].geometry.product_type != false && !vectors.features[i].attributes.isTrail) {
				vectors.features[i].attributes.protected = false;
				vectors.removeFeatures(vectors.features[i]);
		}
	}
}

function hideFilters(){
	$('filters').hide();
}

function selectTpcatLanding(elem){
	if($('select_step1_1').length > 1){
		$('select_step1_1').selectedIndex = elem.selectedIndex;
		$('select_step1_1_text').innerHTML = $('landing_select_text').innerHTML;
		showCatImg($('select_step1_1'));
		$('select_step1_1b_text').innerHTML = $('select_step1_1_text').innerHTML;
		$('select_step1_1b').selectedIndex = elem.selectedIndex;
		showCatImg($('select_step1_1b'));
	}else{
		window.setTimeout("selectTpcatLanding($('"+elem.id+"'));",50);
	}
}

function TrySearch(){
	if($('select_step1_1').selectedIndex){
		if($('select_step1_1').selectedIndex){
			if($('landing_q').value != $('q').value){
				$('q').value = $('landing_q').value;
			}
			mapedo_search(xajax.getFormValues('searchform'),getBBOX());
		}else{
			window.setTimeout("TrySearch()",50);
		}
	}else{
		alert('Bitte wählen Sie einen Einsatzzweck aus!');
	}
}

function switchPartnersByProductType(){
	for(var i=0;i<closedResults.length;i++){
		$('partner_'+closedResults[i]).style.display="none";
	}
	for(var i=0;i<openResults.length;i++){
		$('partner_'+openResults[i]).style.display="";
	}
}
var details_active_tab=false;
function detailsShowTab(product_type,targetTab){
	if($('details_'+product_type+'_content_'+targetTab)){
		for(var i=1;i<=4;i++){
			if($('details_'+product_type+'_content_'+i)){
				$('details_'+product_type+'_content_'+i).hide();
				if($('details_tab_'+i)){
					$('details_tab_'+i).className = "details_tab";
				}
			}
		}
	
		$('details_'+product_type+'_content_'+targetTab).show();
		$('details_tab_'+targetTab).className = "details_tab_active";
		if($('details_tab_content_wrapper').style.display == "none"){
			new Effect.SlideDown('details_tab_content_wrapper',{duration:0.5});
		}
		var nodes = document.getElementsByClassName('othercat_content');
		for(var i=0;i<nodes.length;i++){
			if(nodes[i].style.display != "none"){
				new Effect.SlideUp(nodes[i].id,{duration:0.5});
			}
			//nodes[i].style.display = "none";
		}
	}
}

function maybeShowBacklink(){
	//alert('searchResultsAvailable:'+searchResultsAvailable);
	if(goBackData.length > 0){
		$('details_backlink').show();
		$('details_backlink2').show();
	}
	
}
function initAddThis() 
{
	addthis.init()
}

function clearAddThis(strPrefix){
	if(typeof strPrefix == "undefined"){
		strPrefix = "Diese Seite:";
	}
	//Email:
	if($('addthis_global')){
		$('addthis_global').remove();
	}
	var addthis_global = document.createElement('a');
	addthis_global.id = "addthis_global";
	$(addthis_global).addClassName('addthis_button_email');
	//FB:
	if($('addthis_fb')){
		$('addthis_fb').remove();
	}
	var addthis_fb = document.createElement('a');
	addthis_fb.id = "addthis_fb";
	$(addthis_fb).addClassName('addthis_button_facebook_like');
	//user preferred service rank 1
	if($('addthis_r1')){
		$('addthis_r1').remove();
	}
	var addthis_r1 = document.createElement('a');
	addthis_r1.id = "addthis_r1";
	$(addthis_r1).addClassName('addthis_button_twitter');
	//more:
	if($('addthis_more')){
		$('addthis_more').remove();
	}
	var addthis_more = document.createElement('a');
	addthis_more.id = "addthis_more";
	$(addthis_more).addClassName('addthis_button_expanded');
	
	//favs:
	if($('addthis_favs')){
		$('addthis_favs').remove();
	}
	var addthis_favs = document.createElement('a');
	addthis_favs.id = "addthis_favs";
	$(addthis_favs).addClassName('addthis_button_favorites');
	
	if($('share_prefix')){
		$('share_prefix').remove();
	}
	var prefix = document.createElement('div');
	prefix.id = "share_prefix";
	prefix.style.float ="left";
	prefix.innerHTML = strPrefix;
	
	$('sharethis').appendChild(prefix);
	$('sharethis').appendChild(addthis_fb);
	$('sharethis').appendChild(addthis_r1);
	$('sharethis').appendChild(addthis_favs);
	$('sharethis').appendChild(addthis_global);
	$('sharethis').appendChild(addthis_more);
}

function sharethisinit(){
	var addthis_global = document.createElement('a');
	addthis_global.id = "addthis2_global";
	$(addthis_global).addClassName('addthis_button_email');
	//FB:
	if($('addthis2_fb')){
		$('addthis2_fb').remove();
	}
	var addthis_fb = document.createElement('a');
	addthis_fb.id = "addthis2_fb";
	$(addthis_fb).addClassName('addthis_button_facebook_like');
	//user preferred service rank 1
	if($('addthis2_r1')){
		$('addthis2_r1').remove();
	}
	var addthis_r1 = document.createElement('a');
	addthis_r1.id = "addthis2_r1";
	$(addthis_r1).addClassName('addthis_button_twitter');
	//more:
	if($('addthis2_more')){
		$('addthis2_more').remove();
	}
	var addthis_more = document.createElement('a');
	addthis_more.id = "addthis2_more";
	$(addthis_more).addClassName('addthis_button_expanded');
	
	//favs:
	if($('addthis2_favs')){
		$('addthis2_favs').remove();
	}
	var addthis_favs = document.createElement('a');
	addthis_favs.id = "addthis2_favs";
	$(addthis_favs).addClassName('addthis_button_favorites');
	
	$('details_share').appendChild(addthis_fb);
	$('details_share').appendChild(addthis_r1);
	$('details_share').appendChild(addthis_favs);
	$('details_share').appendChild(addthis_global);
	$('details_share').appendChild(addthis_more);
}

function updateAddThis(strurl,strtitle,strPrefix){
	if(typeof strPrefix == "undefined"){
		strPrefix = "Diese Seite:";
	}
	clearAddThis(strPrefix);
	/*
	addthis.button('#addthis_global', {}, {url: strurl, title: strtitle});
	addthis.button('#addthis_fb', {}, {url: strurl, title: strtitle});
	*/
	addthis.toolbox('#sharethis', {}, {url: strurl, title: strtitle});
	if($('details_share')){
		//sharethisinit();
		addthis.toolbox('#details_share',{}, {url: strurl, title: strtitle});
	}
}

function showOtherCat(id,id_metadata,type){
	hideSuggest();
	//var nodes = $$('othercat_content');
	if(typeof type == "undefined"){
		type="metadata";
	}
	if($('details_tab_content_wrapper').style.display != "none"){
		new Effect.SlideUp('details_tab_content_wrapper',{duration:0.5,afterFinish:function(){ShowOtherCat2(id,id_metadata,type);}});
	}else{
		ShowOtherCat2(id,id_metadata,type);
	}
	
}

function ShowOtherCat2(id,id_metadata,type){
	if(typeof type == "undefined"){
		type="metadata";
	}
	var nodes = document.getElementsByClassName('othercat_content');
	for(var i=0;i<nodes.length;i++){
		if(nodes[i].id != 'ocatc_'+id && nodes[i].style.display != "none"){
			new Effect.SlideUp(nodes[i].id,{duration:0.5,afterFinish:function(){
				if($('ocatc_'+id).innerHTML == ""){
					//show loading
					$('ocatc_'+id).innerHTML = '<img src="/img/ajax-loader.gif">';
					//load content
					xajax_getOtherCat(id,id_metadata,type);
				}
				SlideDown('ocatc_'+id);
			}
			});
			return;
		}else if(nodes[i].id == 'ocatc_'+id){
			if(nodes[i].style.display != "none"){
				new Effect.SlideUp(nodes[i].id,{duration:0.5});
				return;
			}
		}
		//nodes[i].style.display = "none";
	}
	if($('ocatc_'+id).innerHTML == ""){
		//show loading
		$('ocatc_'+id).innerHTML = '<img src="/img/ajax-loader.gif">';
		//load content
		xajax_getOtherCat(id,id_metadata,type);
	}
	SlideDown('ocatc_'+id);
	//$('ocatc_'+id).show();
}
var otherheights=0;
function collectHeights(el,i){
	otherheights += el.getDimensions().height;
}

function SlideDown(id){
	//calculate max height
	//alert($('sidebar').offsetHeight+" - "+$(id).parentNode.offsetTop+" - 50 = " + ($('sidebar').offsetHeight - $(id).parentNode.offsetTop - 50));
	//var max_height = $('sidebar').offsetHeight - $(id).parentNode.offsetTop;
	
	nextcats = $(id).parentNode.nextSiblings().each(collectHeights);
	var max_height = document.viewport.getHeight() - $(id).parentNode.offsetTop - otherheights -100;
	$(id).style.maxHeight = max_height+"px";
	$(id).style.overflow = "auto";
	$(id).show();
	//new Effect.SlideDown(id,{scaleMode:'box',duration:0.5,afterFinish:function(){$(id).style.overflow = "auto";}});
	//new Effect.Scale(id,100,{scaleMode: { originalHeight: max_height}});
}

var saved_vectors=new Array();
var saved_extend;
var saved_addthis;
function saveSearchState(remove){
	if(typeof remove == "undefined"){
		remove = false;
	}
	saved_selected_features = new Array();
	saved_features = new Array();
	saved_vectors=new Array(saved_features,saved_selected_features);
	saved_extend = map.getExtent();
	saved_addthis = $('sharethis');
	
	for(var i=0;i<vectors.features.length;i++){
		var myFeature = vectors.features[i];
		if(!myFeature.attributes || (myFeature.attributes && !myFeature.attributes.protected) || (myFeature.attributes && !myFeature.attributes.isArrow)){
			//var control = drawControls['select'];
			//control.unselect(myFeature);
			save_feature = myFeature.clone();
			if(OpenLayers.Util.indexOf(vectors.selectedFeatures, myFeature) > -1){
				save_feature.isSelected = true;
			}else{
				save_feature.isSelected = false;
			}
			saved_vectors[0].push(save_feature);
		}
	}
	for(var i=0;i<vectors.selectedFeatures;i++){
		saved_vectors[1].push(vectors.selectedFeatures[i].clone());
	}
	//saved_vectors[1] = vectors.selectedFeatures;//.slice();
	if(remove){
		vectors.removeFeatures(vectors.features);
	}
	hidemo();
	return new Array(saved_vectors,saved_extend,saved_addthis);
}
function rebuildSearchState(saved_v,saved_e){
	if(typeof saved_v == "undefined"){
		saved_v = saved_vectors;
	}
	if(typeof saved_e == "undefined"){
		saved_e = saved_extend;
	}
	the_features = vectors.features;
	for(var i=0;i<vectors.features.length;i++){
		var myFeature = vectors.features[i];
		if(myFeature.attributes && myFeature.attributes.id_hotel){
			myFeature.attributes.forceDraw = false;
		}
	}
	vectors.removeFeatures(the_features);
	vectors.addFeatures(saved_v[0]);
	var control = drawControls['select'];
	for(var i=0;i<saved_v[0].length;i++){
		myFeature = saved_v[0][i];
		if(myFeature.isSelected){
			var tmp = control.onSelect;
			control.onSelect = function(){};
			myFeature.originalStyle = OpenLayers.Feature.Vector.style['default'];
			control.select(myFeature);
			control.onSelect = tmp;
		}
	}
	//vectors.selectedFeatures = saved_v[1];
	
	map.zoomToExtent(saved_e);
}

var goBackData=new Array();
function goBack(){
	var data = goBackData.pop();
	if(goBackData.length > 0){
		var data = goBackData[goBackData.length - 1];
		switch(data[0]){
			case 'searchResults':
				var data = goBackData.pop();
				var mySavedState = data[1];
				var mySavedExtend = data[2];
				var mySavedAddThis = data[3];
				clearAll(true);
				rebuildSearchState(mySavedState,mySavedExtend);
				showSearchResults();
				
				$('sharethis').innerHTML = "";
				$('sharethis').appendChild(mySavedAddThis);
				break;
			case 'directView':
				var data = goBackData.pop();
				clearAll(true);
				xajax_getDirectView(data[3]);
				break;
				
			case 'directHotelView':
				var data = goBackData.pop();
				clearAll(true);
				xajax_getDirectHotelView(data[3]);
				break;
			case 'directTouristView':
				var data = goBackData.pop();
				clearAll(true);
				xajax_getDirectTouristView(data[3]);
				break;
				
			case 'directTrailView':
				var data = goBackData.pop();
				clearAll(true);
				xajax_getDirectTrailView(data[3]);
				break;
				
		}
	}
}
    
function MoveMap(x,y,zoom){
	map.setCenter(new OpenLayers.LonLat(x,y),zoom);
}

function ClearShowMap(id_metadata){
	clearAll();
	xajax_showMap(id_metadata,true);
	xajax_createPopup(id_metadata);
}

function dashboard_open_folder(id){
	$('icon_'+id).src = "/img/folderminus.jpeg";
	$('icon_'+id).onclick = function(){dashboard_close_folder(id);};
	if($(id+"_childs")){
		$(id+"_childs").show();
	}else{
		xajax_showContent(id,$('check_'+id).checked);
		
	}
}
function dashboard_close_folder(id){
	$('icon_'+id).src = "/img/folderplus.jpeg";
	$('icon_'+id).onclick = function(){dashboard_open_folder(id);};
	if($(id+"_childs")){
		$(id+"_childs").hide();
	}
}
var check_count = new Array(0,0);
function populateCheck(obj){
	var id = obj.value;
	if($(id+"_childs")){
		$$('#'+id+'_childs input').each(function(el,i){el.checked = obj.checked;});
	}else{

		if($(obj).up("div").up("td").down("input")){
			var parent_input = $(obj).up("div").up("td").down("input");
			var id_parent = parent_input.id;
			check_count = new Array(0,0);
			//$$('#'+id_parent+' input').each(function(el,i){
			$$('#'+parent_input.next('div').id+' input').each(function(el,i){
				if(el.checked){
					check_count[1]++;
				}else{
					check_count[0]++;
				}
			});
			if(check_count[0] > 0 && check_count[1] > 0){
				//parent_input.style.backgroundColor = '#c6c6c6';
				parent_input.hide();
				parent_input.next('.dummybox').show();
				parent_input.checked=true;
			}else{
				parent_input.style.backgroundColor = '#ffffff';
				if(check_count[0]==0){
					parent_input.checked=true;
				}else{
					parent_input.checked=false;
				}
			}
		}
		//$(obj).up("div").up("td").down("input").disabled=(!obj.checked && $(obj).up("div").up("td").down("input").checked);
		
	}
}
var tourist_results;
var hotel_results;
function showSubCat(id){
	hideSuggest();
	//hide other Cats
	$$('.searchResultSubCats').each(function(el,i){
		if(el.visible()){
			if(el.previousSibling && el.previousSibling.childNodes[0] && el.previousSibling.childNodes[0].src){
				el.previousSibling.childNodes[0].src='/img/pfeil_right.png';
				el.previousSibling.childNodes[0].style.width='8px';
			}
			new Effect.SlideUp(el,{duration:0.3});
		}
		if(el.id == "searchResultSubCat_tourist"){
			//remove tourist infos from map
			if(typeof tourist_results != "undefined" && tourist_results.length){
				for(var j=0;j<tourist_results.length;j++){
					for(var i=0;i<vectors.features.length;i++){
			    		var f = vectors.features[i];
			    		if(f.attributes.id_touristinfo == tourist_results[j].id && f.attributes.forceDraw){
		    				f.attributes.protected = false;
		    				vectors.removeFeatures(f);
			    		}
			    	}
				}
			}
		}else if(el.id == "searchResultSubCat_hotel"){
			//remove hotels from map
			if(typeof hotel_results != "undefined" && hotel_results.length){
				for(var j=0;j<hotel_results.length;j++){
					for(var i=0;i<vectors.features.length;i++){
			    		var f = vectors.features[i];
			    		if(f.attributes.id_hotel == hotel_results[j].id && f.attributes.forceDraw){
		    				f.attributes.protected = false;
		    				vectors.removeFeatures(f);
			    		}
			    	}
				}
			}
		}else if(el.id == "searchResultSubCat_trail"){
			//remove trails from map
			if(typeof trail_results != "undefined" && trail_results.length){
				for(var j=0;j<trail_results.length;j++){
					for(var i=0;i<vectors.features.length;i++){
			    		var f = vectors.features[i];
			    		if(f.attributes.id_trail == trail_results[j].id && f.attributes.forceDraw){
		    				f.attributes.protected = false;
		    				vectors.removeFeatures(f);
			    		}
			    	}
				}
			}
		}
	});
	//show cat
	if($('searchResultSubCat_'+id)){
		if($('searchResultSubCat_'+id).visible()){
			$('maincatpfeil_'+id).src='/img/pfeil_right.png';
			$('maincatpfeil_'+id).style.width='8px';
			new Effect.SlideUp('searchResultSubCat_'+id,{duration:0.3});
		}else{
			$('searchResultSubCat_'+id).style.height="";
			$('searchResultSubCat_'+id).style.overflow="";
			$('maincatpfeil_'+id).src='/img/pfeil_down.png';
			$('maincatpfeil_'+id).style.width='13px';
			new Effect.SlideDown('searchResultSubCat_'+id,{duration:0.3});
			if(!$('sidebar_help2').wasShown){
				$('sidebar_help').hide();
				$('sidebar_help2').style.display = "block";
				$('sidebar_help2').wasShown = true;
			}
			if(id=="tourist"){
				//add tourist infos to map
				if(tourist_results.length){
					for(var i=0;i<tourist_results.length;i++){
						addTourist(tourist_results[i].x,tourist_results[i].y,tourist_results[i].id,1,true);
					}
				}
			}else if(id=="hotel"){
				//add hotels to map
				addHotelsToMap();
			}
		}
	}
}

function addHotelsToMap(){
	if(typeof hotel_results != "undefined" && hotel_results.length){
		for(var i=0;i<hotel_results.length;i++){
			addHotel(hotel_results[i].x,hotel_results[i].y,hotel_results[i].id,true);
		}
	}
}
function showEntryCat(id,cat){
	hideSuggest();
	if($(id)){
		if($(id).visible()){
			$('maincatpfeil_'+cat).src='/img/pfeil_right.png';
			$('maincatpfeil_'+cat).style.width='8px';
			new Effect.SlideUp(id,{duration:0.3});
			$('sidebar_helper').hide();
		}else{
			$$('.searchResultEntries').each(function(el,i){
				if(el.visible()){
					if(el.parentNode.childNodes[0].src){
						el.parentNode.childNodes[0].src = '/img/pfeil_right.png';
						el.parentNode.childNodes[0].style.width = "8px";
					}
					new Effect.SlideUp(el,{duration:0.3});
				}
			});
			
			if($(id).innerHTML==""){
				clearVectors();
				removeTrails();
				$(id).innerHTML='<img src="/img/ajax-loader.gif">';
				if(cat == "tourist"){
					
				}else{
					xajax_searchByCat(xajax.getFormValues('searchform'),cat,getBBOX());
				}
			}else{
				clearVectors();
				removeTrails();
				drawType(cat);
			}
			if($('maincatpfeil_'+cat) && $('maincatpfeil_'+cat).src){
				$('maincatpfeil_'+cat).src='/img/pfeil_down.png';
				$('maincatpfeil_'+cat).style.width='13px';
			}
			SlideDownCat(id);
			$('sidebar_help2').hide();
			if(!$('sidebar_helper').wasShown){
				$('sidebar_helper').style.display="block";
				$('sidebar_helper').wasShown = true;
			}
		}
	}
}

function SlideDownCat(id){
	var scroll = checkScrollbars(id);
	new Effect.SlideDown(id,{duration:0.3,afterFinish:function(){
														updateScrollbars(id);
														//$(id).style.overflowY=scroll;
														}
							});
							
	
}

function checkScrollbars(id){
	var height = $(id).getHeight();
	var parent = $(id).parentNode;
	var offsetTop=0;
	while(parent != null){
		if(typeof parent.offsetTop != "undefined"){
			offsetTop = offsetTop + parent.offsetTop;
			if(parent.parentNode)
				parent = parent.parentNode;
			else
				parent = null;
		}else{
			parent = null;
		}
	}
	var max_height = document.viewport.getHeight() - offsetTop -50;
	
	if(height > max_height){
		$(id).style.maxHeight = max_height + "px";
		//$(id).addClassName('overflowYscroll');
		var scrollval="scroll";
	}else{
		//$(id).removeClassName('overflowYscroll');
		var scrollval="auto";
	}
	return scrollval;
}

function updateScrollbars(id){
	var scrollval = checkScrollbars(id);
	$(id).style.overflowY=scrollval;
}

function hide_el(el){
	el.hide();
}

function hideAllSubCats(){
	$$('.searchResultSubCats').each(function(el,i){hide_el(el);});
	$$('.searchResultEntries').each(function(el,i){hide_el(el);});
}

function getMouseovers(ids,cat){
	if(typeof cat == "undefined"){
		cat = false;
	}
	if(cat)
		xajax_getMouseovers(ids,cat);
	else
		xajax_getMouseovers(ids);
}
var MoSave = new Array();
function saveMo(id,content){
	MoSave[id]=content;
}

function getDirectView(id){
	var data = saveSearchState();
    addGoBack(new Array('searchResults',data[0],data[1],data[2]));
    xajax_getDirectView(id);
}

function openWindow(url,name){
	window.open(url,name);
}
var arrowline;
var arrow_start;
var arrow_end;
function drawArrow(arrow_target){
	if(typeof arrow_target == "undefined"){
		return false;
	}
	style = {
	        fillColor: "red",
	        fillOpacity: 1, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "red",
	        strokeOpacity: 1,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
	    };
	arrowline = new OpenLayers.Feature.Vector(
                                        new OpenLayers.Geometry.LineString());
    arrow_start = new OpenLayers.Feature.Vector(
                                        new OpenLayers.Geometry.Point());
	arrow_end = new OpenLayers.Feature.Vector(
                                        new OpenLayers.Geometry.Point());
	var lonlat = map.getLonLatFromPixel(new OpenLayers.Pixel($('result_mo').getWidth() + $('sidebar').getWidth(),ypos));
   	arrow_start.geometry.x = lonlat.lon;
    arrow_start.geometry.y = lonlat.lat;                                        
	arrowline.geometry.addComponent(arrow_start.geometry.clone(),
                                        arrowline.geometry.components.length);

	
	//lonlat = map.getLonLatFromPixel(new OpenLayers.Pixel(arrow_target_x,arrow_target_y));
   	arrow_end.geometry.x = arrow_target.lon;
    arrow_end.geometry.y = arrow_target.lat;                                        
	arrowline.geometry.addComponent(arrow_end.geometry.clone(),
                                        arrowline.geometry.components.length);
	arrowline.style = style;
	arrowline.attributes.isArrow = true;
	vectors.addFeatures([arrowline]);
}
function drawTouristArrow(id){
	id=id.substr(7);
	var myFeature = false;
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.id_touristinfo && vectors.features[i].attributes.id_touristinfo == id){
			myFeature = vectors.features[i];
		}else if(vectors.features[i].attributes.id_touristinfo ){
			//redraw Hotel
			myFeature2 = vectors.features[i];
			myFeature2.style.externalGraphic = '/img/icons/i.gif';
			vectors.drawFeature(myFeature2);	
		}
	}
	if(myFeature){
		target = myFeature.geometry;
		target.lon=target.x;
		target.lat=target.y;
		myFeature.style.externalGraphic = '/img/markers/BLUE.png';
		vectors.drawFeature(myFeature);
		drawArrow(target);
	}else{
		//remove Arrow
		for(var i= vectors.features.length -1;i>=0;i--){
			if(vectors.features[i].attributes.isArrow){
				vectors.removeFeatures(vectors.features[i]);
			}
		}	
	}
}
function drawHotelArrow(id){
	id=id.substr(5);
	var myFeature = false;
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.id_hotel && vectors.features[i].attributes.id_hotel == id){
			myFeature = vectors.features[i];
		}else if(vectors.features[i].attributes.id_hotel ){
			//redraw Hotel
			myFeature2 = vectors.features[i];
			myFeature2.style.externalGraphic = '/img/H.gif';
			vectors.drawFeature(myFeature2);	
		}
	}
	if(myFeature){
		target = myFeature.geometry;
		target.lon=target.x;
		target.lat=target.y;
//		myFeature.style.externalGraphic = '/img/H_rot.gif';
		myFeature.style.externalGraphic = '/img/markers/BLUE.png';
		vectors.drawFeature(myFeature);
		drawArrow(target);
	}else{
		//remove Arrow
		for(var i= vectors.features.length -1;i>=0;i--){
			if(vectors.features[i].attributes.isArrow){
				vectors.removeFeatures(vectors.features[i]);
			}
		}	
		
		
	}
}
function drawTrailArrow(id){
	id=id.substr(5);
	var myFeature = false;
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.id_trail && vectors.features[i].attributes.id_trail == id){
			myFeature = vectors.features[i];
		}else if(vectors.features[i].attributes.id_trail ){
			//redraw Trail
			/*
			myFeature2 = vectors.features[i];
			myFeature2.style.externalGraphic = '/img/H.gif';
			vectors.drawFeature(myFeature2);	
			*/
		}
	}
	if(myFeature){
		/*
		target = myFeature.geometry;
		target.lon=target.x;
		target.lat=target.y;
//		myFeature.style.externalGraphic = '/img/H_rot.gif';
		//myFeature.style.externalGraphic = '/img/markers/BLUE.png';
		//vectors.drawFeature(myFeature);
		drawArrow(target);
		*/
	}else{
		//remove Arrow
		for(var i= vectors.features.length -1;i>=0;i--){
			if(vectors.features[i].attributes.isArrow){
				vectors.removeFeatures(vectors.features[i]);
			}
		}	
		
		
	}
}
function updateArrow(new_start){
	if(typeof new_start == "undefined" || typeof arrow_start == "undefined" || typeof arrow_start.geometry == "undefined"){
		return false;
	}
	style = {
	        fillColor: "red",
	        fillOpacity: 1, 
	        hoverFillColor: "white",
	        hoverFillOpacity: 0.8,
	        strokeColor: "red",
	        strokeOpacity: 1,
	        strokeWidth: 2,
	        strokeLinecap: "round",
	        hoverStrokeColor: "red",
	        hoverStrokeOpacity: 1,
	        hoverStrokeWidth: 0.2,
	        pointRadius: 6,
	        hoverPointRadius: 1,
	        hoverPointUnit: "%",
	        pointerEvents: "visiblePainted"
	    };
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.isArrow){
			vectors.removeFeatures(vectors.features[i]);
		}
	}
	//vectors.removeFeatures(arrowline);
	arrowline = new OpenLayers.Feature.Vector(
                                        new OpenLayers.Geometry.LineString());
	
	var lonlat = map.getLonLatFromPixel(new OpenLayers.Pixel($('result_mo').getWidth() + $('sidebar').getWidth(),new_start));
    arrow_start.geometry.y = lonlat.lat;                                        
	arrowline.geometry.addComponent(arrow_start.geometry.clone());
	arrowline.geometry.addComponent(arrow_end.geometry.clone());
	
	arrowline.style = style;
	arrowline.attributes.isArrow = true;
	vectors.addFeatures([arrowline]);
	//$('copyright').innerHTML = $('copyright').innerHTML + " neue ypos: " + new_start;
}

function removeArrow(){
	for(var i= vectors.features.length -1;i>=0;i--){
		if(vectors.features[i].attributes.isArrow){
			vectors.removeFeatures(vectors.features[i]);
		}
	}
}

function searchLocation(lon,lat){
	var old_q = $('q').value;
	$('q').value='';
	$('searchgeo').value = ";POINT("+lon+" "+lat+")";
	mapedo_search(xajax.getFormValues('searchform'),getBBOX());
	//$('q').value = old_q;
}

function showMenuFilter(){
	if($('cpdd').style.display == "none"){
		$('alt_button_wrapper').isOpen = $('alt_button_wrapper').visible();
		$('alt_button_wrapper').hide();
		$('pfeil_expsearch').src = '/img/pfeil_down_exp.png';
		$('pfeil_expsearch').style.width ="23px";
		new Effect.SlideDown('cpdd',{duration:0.3});
		$('searchform').reset();
		if(piwikTracker){
			piwikTracker.trackGoal(4);
		}
	}else{
		$('pfeil_expsearch').src = '/img/pfeil_right_exp.png';
		$('pfeil_expsearch').style.width ="12px";
		new Effect.SlideUp('cpdd',{duration:0.3,afterFinish:function(){if($('alt_button_wrapper').isOpen){
			$('alt_button_wrapper').show();
		}}});
		hideFilter(2);
		hideFilter(3);
		hideFilter(4);
		hideFilter(5);
		var q = $('q').value;
		$('searchform').reset();
		clearSearchBox();
		$('q').value = q;
		
	}
	
}

function addGoBack(data){
	goBackData.push(data);
}

function hideAltCat(id){
	if($(id+'_wrapper').visible()){
		$('maincatpfeil_'+id).src='/img/pfeil_right.png';
		$('maincatpfeil_'+id).style.width='8px';
		new Effect.SlideUp(id+'_wrapper',{duration:0.5});
	}
	$('show'+id).onclick = function(){Event.stop(event);showAltCat(id)};
}

function showAltCat(id){
	$('maincatpfeil_'+id).src='/img/pfeil_down.png';
	$('maincatpfeil_'+id).style.width='13px';
	new Effect.SlideDown(id+'_wrapper',{duration:0.5,afterFinish:function(){
														updateScrollbars(id);
														//$(id).style.overflowY=scroll;
														}});
	
	$('show'+id).onclick = function(){Event.stop(event);hideAltCat(id)};
}

function getDirectTouristView(id){
	xajax_getDirectTouristView(id);
}
function getDirectTrailView(id){
	xajax_getDirectTrailView(id);
}
function hideSearchAlt(){
	$('alt_button_content').hide();
	$('alt_button').onclick=showSearchAlt;
	$('pfeil_alt').src = '/img/pfeil_right_exp.png';
	$('pfeil_alt').style.width ="12px";
}
function showSearchAlt(){
	$('alt_button_content').show();
	$('alt_button').onclick = hideSearchAlt;
	$('pfeil_alt').src = '/img/pfeil_down_exp.png';
	$('pfeil_alt').style.width ="18px";
}
function createLinkListener(){
	$$('.checkout').each(function(element){
		piwikTracker.addListener(element);	
	});
	
}

