	<!--// --><![CDATA[//><!--
	String.prototype.startsWith = function(s){
		return (this.match("^"+s) == s);
	}
	String.prototype.compareTo = function(s){
		return this == s ? 0 : (this < s ? -1 : 1);
	}
	
	function showMoreObjects(idNum){
		var unfoldedId = "more-objects-unfolded"+idNum;
		var foldedId = "more-objects-folded"+idNum;
		document.getElementById(unfoldedId).style.display = "block"; 
		document.getElementById(foldedId).style.display = "none";
		return false;	
	}
	
	function hideMoreObjects(idNum){
		document.getElementById("more-objects-unfolded"+idNum).style.display = "none"; 
		document.getElementById("more-objects-folded"+idNum).style.display = "block";
		return false;		
	}
	
	function showLinkAjax(eId, _url){
		// TODO check if this results in a memory leak an client-side,
		// maybe use jquery to perform AJAX directly.
		// Spring.addDecoration(new Spring.AjaxEventDecoration({
		// url : _url,
		// elementId: eId,
		// event: "onmouseup",
		// params: {fragments: "lastviewed,recommendations"}
		// }));
		$('#'+eId).click(function(){
			$.get(_url, null, function(data){
	        	$('#last-visits').replaceWith(data);
	    	});	
		});
	}
	
	function switchVisibility(hideId, showId){
		document.getElementById(showId).style.display = "block";
		document.getElementById(hideId).style.display = "none"; 
	}
	
	function showRegion(id){
		document.getElementById(id).style.visibility = 'visible';
	}
	function hideRegion(id){
		document.getElementById(id).style.visibility = 'hidden';
	}
	
	function doRegionSelection(idNum, update){
		var element = document.getElementById("region-select"+idNum);
		var input = document.getElementById("region-input"+idNum);
		if(element.style.visibility == 'hidden'){
			element.style.visibility = 'visible';
			input.disabled = false;
		}
		if(update){
			updateRegionSelectByMap();
		}
	}
	
	function toggleRegionSelection(idNum){
		var element = document.getElementById("region-select"+idNum);
		var input = document.getElementById("region-input"+idNum);
		if(element.style.visibility == 'hidden'){
			element.style.visibility = 'visible';
			input.disabled = false;
		} else{
			element.style.visibility = 'hidden';
			input.disabled = true;
		}
		updateRegionSelectByMap();
		clearRegionInputText();
	}
	
	function clearRegionInputText(){
		$('#regionInput').val(function(){
			return $(this).attr("title");
		});
	}
	
	function updateRegionSelectByMap(){
		var regions = new Array();
		$('input:not(:disabled)[type="hidden"][name="location"]').each(function(){
			var name = $(this).attr('title');
			var id = $(this).val();
			var o = new Object();
			o.name = name;
			o.id = id;
			regions[regions.length] = o;
		});
		regions.sort(function(a, b){return a.name.localeCompare(b.name);});
		updateRegionSeletionTable(regions);
	}
	
	function updateRegionSeletionTable(regions){
		$('.selected-region-item').remove();
		var selectAll = true;
		$.each(regions, function(index, obj) { 
			selectAll = false;
			var value = obj.name;
			var name = obj.name;
			var id = obj.id;
			var count = '';
			var idx = value.lastIndexOf('(');
			if(idx != -1){
				name = value.substring(0, idx);
				count = value.substring(idx+1,value.length-1);
			}
			$('#selected-regions-table').append('<tr class="selected-region-item"><td>'+name+'<span class="r'+id+'"> ('+count+')</span></td><td></td></tr>');
		});
		if(selectAll){
			var name = 'Alle';
			var id = $('#selectedRegion').val();
			$('#selected-regions-table').append('<tr class="selected-region-item"><td>'+name+'<span class="r'+id+'"></span></td><td></td></tr>');
		}	
	}
	
	function updateRegionSelectList(){
		var regions = new Array();
		$('input:checked[type="checkbox"][name="location"]').each(function(){
				var name = $(this).attr('title');
				var id = $(this).val();
				var o = new Object();
				o.name = name;
				o.id = id;
				regions[regions.length] = o;
		});
		regions.sort(function(a, b){return a.name.localeCompare(b.name);});
		updateRegionSeletionTable(regions);
	}
	
	function checkSelectAll(input){
		var title = input.title; 
		if(title.startsWith("Alle")){
			var doCheck = true;
			$('input:checked[type="checkbox"][name="location"][title!="'+title+'"]').each(function(){
				$(this).attr("checked", "");
				doCheck = false;
			});
			if(doCheck){
				input.checked = true;
			}
		}else{
			$('input:checked[type="checkbox"][name="location"][title^="Alle"]').each(function(){
				$(this).attr("checked", "");
			});	
		}
	}
	function submitForm (formId) {
		var form = document.getElementById(formId);
		if(form != null){
			form.submit();
		}
	}
	
	function serializeForm(formId, ignoreField1, ignoreField2) {
		var form = $('#'+formId);
		return jQuery.param(serializeFormArray(form, ignoreField1, ignoreField2));
	}
	
	var rselectTextarea = /select|textarea/i;
	var rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i;
	
	function serializeFormArray(arr, ignoreField1, ignoreField2) {
		return $(arr).map(function() {
			return this.elements ? jQuery.makeArray(this.elements) : this;
		})
		.filter(function() {
			return this.name && !this.disabled && 
			     this.name != ignoreField1 && this.name != ignoreField2 && 
			     this.title != $(this).val() && // ignore fields which have the
												// same title and value
			     !$(this).hasClass($(this).val()) && // ignore fields which
														// have a class equal to
														// the value
				(this.checked || rselectTextarea.test(this.nodeName) ||
						rinput.test(this.type));
		})
		.map(function( i, elem ) {
			var val = jQuery(this).val();
			return val == null ?
				null :
				jQuery.isArray(val) ?
					jQuery.map( val, function( val, i ) {
						return { name: elem.name, value: val };
					}) :
					{ name: elem.name, value: val };
		}).get();
	}
	
	function serializeFormToSingleParam(formId, paramName, ignoreField1, ignoreField2) {
		var result = "";
		var form = $('#'+formId);
		var arr = serializeFormArray(form, ignoreField1, ignoreField2);
		arr.sort(function(o1, o2){
			return o1.name.compareTo(o2.name);
		});
		var propertyName = "";
		var propertySeparator = "";
		jQuery.each( arr, function() {
			add( this.name, this.value );
		});
		function add( name, value ) {
			if (propertyName == name) {
				// if another value for current property
				result = result + "," + value;
			} else {
				// if new property
				propertyName = name;
				var propertyCode;
				if (propertyName == "location") {
					propertyCode = "loc";
				} else if (propertyName == "locationsString") {
					propertyCode = "lcs";
				} else if (propertyName == "buy") {
					propertyCode = "buy";
				} else if (propertyName == "livingSpaceMax") {
					propertyCode = "lsx";
				} else if (propertyName == "livingSpaceMin") {
					propertyCode = "lsn";
				} else if (propertyName == "priceMax") {
					propertyCode = "prx";
				} else if (propertyName == "priceMin") {
					propertyCode = "prn";
				} else if (propertyName == "roomCountMax") {
					propertyCode = "rcx";
				} else if (propertyName == "roomCountMin") {
					propertyCode = "rcn";
				} else if (propertyName == "selectedRegion") {
					propertyCode = "srg";
				} else if (propertyName == "searchCategory") {
					propertyCode = "sca";
				} else if (propertyName == "sortBy") {
					propertyCode = "srt";
				} else if (propertyName == "typeId") {
					propertyCode = "typ";
				} else if (propertyName == "timeStamp") {
					propertyCode = "tst";
				}
				result = result + propertySeparator + propertyCode + encodeURIComponent(value);
				propertySeparator = ";";
			}
		}
		if(result.length > 0){
			result = paramName + "=" + result; 
		}
		return result;
	}
	
	function concatIfNotEmpty(string, prefix){
		var result = "";
		if(string != ""){
			result = prefix+string;
		}
		return result;
	}
	
	function getNextParamSeparator(url){
		var result = "?";
		if(url.indexOf('?') != -1){
			result = "&";
		}	
		return result;
	}
	
	function appendGetParams(url, paramStr, ignoreParamNamesStr){
		var result = url;
		var index = url.indexOf('?');
		var sep = '?';
		if(index != -1){
			result = url.substring(0, index);
			var urlParamStr = url.substring(index+1);
			var urlParams = urlParamStr.split('&');
			var ignoreParamNames = ignoreParamNamesStr.split(',');
			for(var i=0; i<urlParams.length; i++){
				var ignoreParam = false;
				var urlParamName = urlParams[i].split('=')[0];
				for(var j=0; j<ignoreParamNames.length; j++){
					if(ignoreParamNames[j] == urlParamName){
						ignoreParam = true;
						break;
					}	
				}
				if(!ignoreParam){
					result = result + sep + urlParams[i];
					sep = '&';
				}	
			}
		}
		if(paramStr.length > 0) {
		     result = result + sep + paramStr;
		}
		return result;
	}
	
	<!-- START Tooltip Handling -->
	function addMapToolTips(){
		$("map > area").tooltip({ 
		  positionLeft: false,
		  track: true,
			delay: 0,
			showURL: false,
			top: -9,
			right: 0
		});
	};
	<!-- ENDE Tooltip Handling -->	
	
	
	<!-- START Google-Maps -->	
	function loadGMaps(address) {
	      if (GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById("map"));
	        map.setCenter(new GLatLng(52, 10), 5);

	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());

	        geocoder = new GClientGeocoder();
	        geocoder.getLatLng(address, 
	          function(point) {
	            if (point) {
	              map.setCenter(point, 13);
	              var marker = new GMarker(point);
	              map.addOverlay(marker);
	              marker.openInfoWindowHtml(address);
	            }
	          }
	        );
	      }
	}
	<!-- ENDE Google-Maps -->	
	
	<!-- START internal tracking  -->
	function getTrackingParams(pageName){
		var ref = document.referrer;
		var self = /http.*?immopionier\.de.*/i;
		if(!ref || ref.match(self)){
			ref = "";
		}
		var userAgent = navigator.userAgent;
		if(!userAgent){
			userAgent = "";
		}
		ref = encodeURIComponent(ref);
		userAgent = encodeURIComponent(userAgent);
		pageName = encodeURIComponent(pageName);
		return "tr="+ref+"&tua="+userAgent+"&tpn="+pageName+"&trnd="+Math.round(Math.random()*100000);	
	}
	<!-- END internal tracking  -->

	// --><!]]>

