/*********************************************
 * Intersim Popup Klasse
/*********************************************/
var Popup = Class.create({

	// Konstruktor
	initialize : function(triggerId, popupId, dType, dat) {
		// Trigger (z.B. ein Icon) hier wird der mousclick event gesetzt
		this.trigger 	= $(triggerId);
		// Popup control
		this.popup	 	= $(popupId);
		// Datentyp (ajax, element)
		this.dataType 	= dType;
		// Daten ajax => url, elemnent => elmentId
		this.data 		= dat;
		
		this.removeMouseClickListener();
		// mouseclick Event setzen
		this.addMouseClickListener();

		// Position von Popup
		this.trigger.absolutize();		
		if(this.trigger.height == undefined)
			this.trigger.height = 0;
		if(this.trigger.width == undefined)
			this.trigger.width = 0;
			
		this.setPosition((this.trigger.offsetTop + this.trigger.height) - this.trigger.height, (this.trigger.offsetLeft + this.trigger.width) - this.trigger.width);
		this.trigger.relativize();

		
		// Mouseout Event (popup) entfernen
		this.trigger.className = this.trigger.className + ' PopupTrigger';
		this.popup.style.display = 'none';
		this.popup.style.position = 'absolute';
		this.popup.className = 'Popup';
	},
	
	// Posiition setzen
	setPosition : function(topPos, leftPos) {
		topPos = topPos.toString();
		leftPos = leftPos.toString();

		if(topPos.indexOf('px') == -1)
			topPos += 'px';
		if(leftPos.indexOf('px') == -1)
			leftPos += 'px';

		this.popup.style.top = topPos;
		this.popup.style.left = leftPos;
	},
	
	
	// Mouse out event. (hier koennen eigene methoden eingehaengt werden)
	onAfterFade : function(fn) {
		this.popup.observe("popup:onAfterFade", fn);
	},
	
	// mouseclick Registrierung loeschen
	removeMouseClickListener : function() {
		this.trigger.stopObserving('click');
	},
	
	// Mouseout Registrierung loeschen
	/*removeMouseOutListener : function() {
		this.popup.stopObserving('mouseout');
	},*/
	
	// Button OK Click event (schliessen)
	mouseButtonClick : function() {
		var self = this; 

		this.popup.fade({
			afterFinish : function() {
			self.popup.fire("popup:onAfterFade");
			self.addMouseClickListener();		
			}				
		});
	},
	
	// Mousout event
	/*mouseOut : function(e) {
		
		var self = this;
		this.trigger.relativize();
		if(!this.isChild(this.popup, e.relatedTarget) && this.popup != (e.relatedTarget)) {
			
			this.popup.fade( {  
				beforeStart : function() {
					self.removeMouseOutListener();
				},
				afterFinish : function() {

				}
			});
		}
	},*/

	/*// Mouseout event registrieren
	addMouseOutListener : function() {	
		this.popup.observe('mouseout', this.mouseOut.bind(this));
	},*/

	// mouseclick Event registrieren
	addMouseClickListener : function() {
		this.trigger.observe('click', this.mouseClick.bind(this));
	},

	// Mouseouver event
	mouseClick : function() {

		var self = this;	
		// Events 
		//this.addMouseOutListener();
		this.removeMouseClickListener();

		// Popup fuellen (wenn type und data vorhanden sind)
		switch(this.dataType.toLowerCase()) {
			case 'ajax':
					new Ajax.Request(this.data + "&tm=" + new Date().getTime(), {
					 method: 'get',
					 onSuccess: function(transport) {
						
						var arrVal;

						self.popup.innerHTML = transport.responseText;
						arrVal = $('ajaxChecked').innerHTML.split(',');
						
						if(arrVal.length > 0) {
							var arrIpt = self.popup.getElementsBySelector('input');
							arrIpt.each(function(ipt) {
								arrVal.each(function(val) {
									if (val == ipt.value) {
										ipt.checked = true;	
									}					 
								});
							});
					 	}
					 }});
				break;
		
			case 'element':
				this.popup.innerHTML = $(self.data).innerHTML;	
			break;
		}
		
		// Position von Popup
		//this.trigger.absolutize();		
		if(this.trigger.height == undefined)
			this.trigger.height = 0;
		if(this.trigger.width == undefined)
			this.trigger.width = 0;
			
		//this.popup.style.top  = (this.trigger.offsetTop + this.trigger.height) - this.trigger.height + 'px';
		//this.popup.style.left = (this.trigger.offsetLeft + this.trigger.width) - this.trigger.width + 'px';
		
		// Anzeigen
		this.popup.show();
	},
	
	isChild : function (startNode, objSearch) {
		
		retVal = false;
		var self = this;
		
		startNode.childElements().each(function(node) {

			if(retVal == false) {
				if(node == objSearch) {
					retVal = true;	
				}	
				else
				{
					retVal = self.isChild(node, objSearch);
				}
			}										 
		})
		return retVal;
	},
	
	// Anzahl Childs bis zum bestimmten Objekt zaehlen
	getChildCount : function(startNode, searchObj) {
		var count = 0;
		for(var x = 0; x < startNode.length; x++)  {
			if(startNode[x] == searchObj) {
				count += 1;
				break;
			}
			count += this.getChildCount(startNode[x].childNodes, searchObj) + 1;
		}  
		return count;				
	}
});
/*********************************************/

/*********************************************
* Search Klasse
*********************************************/
var ImmoSearch = Class.create({

	filterChanged : function() {
		Search.changed = true;
	},
	
	reset : function() {
	
		new Ajax.Updater('objectType', "/platform/apps/immosearch/request.asp?act=reset", {
			evalScripts : true,
			onComplete: function() {
				$('sell').checked = false;
				$('rent').checked = false;
				$('living').checked = false;
				$('indus').checked = false;
				Search.uncheck('roomFrom', 'radio');
				Search.uncheck('roomTo', 'radio');
				Search.uncheck('sellFrom', 'radio');
				Search.uncheck('sellTo', 'radio');
				Search.uncheck('rentFrom', 'radio');
				Search.uncheck('rentTo', 'radio');
				Search.uncheck('livDimensionFrom', 'radio');
				Search.uncheck('livDimensionTo', 'radio');
				Search.uncheck('indDimensionFrom', 'radio');
				Search.uncheck('indDimensionTo', 'radio');
				Search.uncheck('tblCanton', 'checkbox');
				$('divRoom').style.display = 'block';
				Search.GetCount();
				Listview.calcHeight();
			}
		});
	},
	
	uncheck : function(parentId, type) {
	
		if($(parentId) != null) {
			$(parentId).getElementsBySelector('[type="' + type + '"]').each(function(itm) {
					itm.checked =false;	
			});	
		}
	},
	
	// Checked werte (Checkbox) lesen
	getChecked : function (parentId, type, sep) {
		var strVal = '';
	
		if($(parentId) != null) {
			$(parentId).getElementsBySelector('[type="'+type+'"]').each(function(itm) {
				if(itm.checked) {
					strVal += itm.value;
					if(type != 'radio') strVal += sep;
				}
			});
		}
		return strVal;		
	},
	
	toJson : function() {
		var ret = '';
		var strCanton = '';
		var strLivDimensionFrom = '';
		var strLivDimensionTo = '';
		var strIndDimensionFrom = '';
		var strIndDimensionTo = '';
		var strRoomFrom = '';
		var strRoomTo = '';
		var rentChecked = '';
		var sellChecked = '';
		var sellFrom = '';
		var sellTo = '';
		var rentFrom = '';
		var rentTo = '';
		var livingChecked = '';
		var indusChecked = '';
		var livingType = '';
		var indusType = '';
		var plzSearch = $('AmbitSearchPlzId').value;
		var regionSearch = isNaN(parseInt($('RegionSearchChooseId').value)) ? 0 : parseInt($('RegionSearchChooseId').value);
		var cantonSearch = isNaN(parseInt($('CantonSearchChooseId').value)) ? 0 : parseInt($('CantonSearchChooseId').value);
		var plzWidth = isNaN(parseInt($('AmbitSearchKmId').value)) ? 0 : parseInt($('AmbitSearchKmId').value);
	
		strCanton 			= Search.getChecked('tblCanton', 'checkbox', ',');
		strRoomFrom			= Search.getChecked('roomFrom', 'radio', ',');
		strRoomTo			= Search.getChecked('roomTo', 'radio', ',');
		
		if (!Common.isNull('sellFrom')) sellFrom 	= Search.getChecked('sellFrom', 'radio', ',');
		if (!Common.isNull('sellTo')) sellTo 		= Search.getChecked('sellTo', 'radio', ',');
		if (!Common.isNull('rentFrom')) rentFrom 	= Search.getChecked('rentFrom', 'radio', ',');
		if (!Common.isNull('rentTo')) rentTo 		= Search.getChecked('rentTo', 'radio', ',');
	
		if (Common.isNull('rent')) rentChecked = false;
		else rentChecked = $('rent').checked;
		
		if (Common.isNull('sell')) sellChecked = false;
		else sellChecked = $('sell').checked;
		
		if (Common.isNull('living')) livingChecked = false;
		else livingChecked = $('living').checked;
		
		if (Common.isNull('indus')) indusChecked = false;
		else indusChecked = $('indus').checked;
	
		if (livingChecked == indusChecked || livingChecked) {
			if (!Common.isNull('livDimensionFrom'))  strLivDimensionFrom = Search.getChecked('livDimensionFrom', 'radio', ',');
			if (!Common.isNull('livDimensionTo'))  strLivDimensionTo = Search.getChecked('livDimensionTo', 'radio', ',');
		}
		if (livingChecked == indusChecked || indusChecked) {
			if (!Common.isNull('indDimensionFrom')) strIndDimensionFrom	= Search.getChecked('indDimensionFrom', 'radio', ',');
			if (!Common.isNull('indDimensionTo')) strIndDimensionTo	= Search.getChecked('indDimensionTo', 'radio', ',');
		}
		//if (
	
		if (indusChecked == true && livingChecked == false) {
			$('divRoom').style.display = 'none';
			strRoomFrom = '';
			strRoomTo = '';
			livingType = '';
		}
		else
			$('divRoom').style.display = 'block';
	
		if (indusChecked == false && livingChecked == true) {
			indusType = '';	
		}
	
		if(!Common.isNull('indusType')) indusType = Search.getChecked('indusType', 'checkbox', ';');
		if(!Common.isNull('livingType')) livingType = Search.getChecked('livingType', 'checkbox', ';');
			
		if (rentChecked == false && sellChecked == true) {
			rentFrom = '';
			rentTo = '';
		}
		if(rentChecked == true && sellChecked == false) {
			sellFrom = '';
			sellTo = '';
		}
		
		return {	
			canton 				: strCanton, 
			roomFrom			: strRoomFrom, 
			roomTo				: strRoomTo,
			livDimensionFrom	: strLivDimensionFrom,
			livDimensionTo		: strLivDimensionTo,
			indDimensionFrom	: strIndDimensionFrom,
			indDimensionTo		: strIndDimensionTo,
			rentChecked			: rentChecked,
			sellChecked			: sellChecked,
			sellFrom			: sellFrom,
			sellTo				: sellTo,
			rentFrom			: rentFrom,
			rentTo				: rentTo,
			livingChecked		: livingChecked,
			indusChecked		: indusChecked,
			indusType			: indusType,
			livingType			: livingType,
			plzSearch			: plzSearch,
			plzWidth			: plzWidth,
			regionSearch		: regionSearch,
			cantonSearch		: cantonSearch
		};
	},
	
	Search : function(data) {

		var params = Search.toJson();
		params.data = data;
		$('loader').show();
		new Ajax.Updater('searchResult', "/platform/apps/immosearch/request.asp?act=search", {
			method: 'post',
			evalScripts : true,
			parameters: params,
			onComplete: function() {
				$('loader').hide();
				Listview.calcHeight();
			}
		});	
	},
	
	// Anzahl 
	GetCount : function() {
		var arr = $('objectType').getElementsBySelector('[objcount]');
		var arrVal = new Array();
		var showTotal = 0;
		var total = 0;
		var bCount = true;
		
		// Anzahl Objekte im Suchergebnis (Es werde nur die angeklickten Objektarten gezaehlt)
		for (var x = 0; x < arr.length; x++) {
			if(arr[x].checked == true) {
				// Es kann sein, das die gleichen Objekte in der "Wohnen" und "Gewerbe" Tabelle erscheinen
				// Wenn dies der Fall ist, wird die Anzahl Objekte für diesen Typ nur einmal gezaehlt.
				// z.B. "Parkmoeglichkeiten"
				for(var y = 0; y < arrVal.length; y++) {
					if(arrVal[y] == arr[x].value) {
						bCount = false;	
					}	
				}
				if(bCount) {	
					arrVal[arrVal.length] = arr[x].value;
					showTotal += parseInt(arr[x].readAttribute('objcount'));
				}

			}		
			bCount = true;
		}
		
		// Alle Objektarten zaehlen
		bCount = true;
		for(var x = 0; x < arr.length; x++) {
			for(var y = 0; y < arrVal.length; y++) {
				if(arrVal[y] == arr[x].value) {
					bCount = false;	
				}	
			}
			if(bCount) {	
				arrVal[arrVal.length] = arr[x].value;
				total += parseInt(arr[x].readAttribute('objcount'));
			}
			bCount = true;
		}
		
		// Wenn keine Objektarten ausgewaehlt sind, wird totale Anzahl Objekte angezeigt
		if(showTotal == 0) showTotal = total;
		$('showButton').value = $('resBtnCount').innerHTML + ' (' + showTotal + ')';
	},
	
	//Suche updaten
	UpdateSearch : function() {

		if(Search.changed) {			
			$('loader').show();
			Search.changed = false;
			new Ajax.Updater('objectType', "/platform/apps/immosearch/request.asp?act=updatesearch&tm=" + new Date().getTime(), {
				method: 'post',
				evalScripts : true,
				parameters: Search.toJson(),
				onComplete: function() {
					$('loader').hide();
					Search.GetCount();
				}
			});
		}
	}
	
});

var ImmoCommon = Class.create({
							  
	isNull : function(objId) {
		return $(objId) == null;	
	},
	
	txtLength : function(objId) {
		return $(objId).value.length;	
	},
	
	addErrorClass : function(objId) {
		if($(objId).className.indexOf('errorInput') == -1)
			$(objId).className = ' errorInput';	
	},
	
	removeErrorClass : function(objId) {
		$(objId).className = $(objId).className.replace(' errorInput', '');		
	}

});

function ShowDiv(id, bOpen) {
	$("pa_" + id).onclick = function() {ShowDiv(id, !bOpen)};
	$('MB_window').style.height = '';
	if ($(id).style.display == "none") {
		Effect.BlindDown(id,{ duration: 0.8 });
		Effect.Appear(id,{ duration: 0.8, from: 0.4, to: 1.0 });
	}
	else {
		Effect.BlindUp(id,{ duration: 0.8 });
		Effect.Appear(id,{ duration: 0.8, from: 1.0, to: 0.4 });
	}
	setTimeout("SetNodeHeight('MB_window')",800);
}

/*********************************************/

/*********************************************
* Compare Klasse
*********************************************/
var ImmoCompare = Class.create({

	remove : function(objref) {
	
		new Ajax.Updater('MB_content', '/platform/apps/immosearch/request.asp?act=delcomp', {
			method : 'post',
			parameters : { objref : objref }
		});
	},
	
	changeTo : function(view) {
		
		new Ajax.Updater('MB_content', '/platform/apps/immosearch/request.asp?act=compdata&view=' + view, {
  	    	evalScripts : true,
			method : 'post'
		});
	}
});

/*********************************************
* Listview Klasse
*********************************************/
var ImmoListview = Class.create({

	calcHeight : function() {

		if ($('divRes') == null)
			return;

		var h1 = $('divRes').getHeight() + $('divContent').getHeight() + 27;
		var h2 = $('divMenuBottom').getHeight() + $('divMenuMiddle').getHeight() + $('divMenuTop').getHeight() + 32;
		if (h2 > h1) 
			h1 = h2;
		$('divMiddle').style.height = h1 + 'px';
	},
	
	getPage : function(pageNum, data) {

		if($('loader') != null)
			$('loader').show();
		new Ajax.Updater('searchResult', '/platform/apps/immosearch/request.asp?act=paging&page=' + pageNum + '&data=' +data, {
			evalScripts : true,
			onComplete : function() {
				Listview.calcHeight();
				if($('loader') != null)
					$('loader').hide();
			}
		});
	},
	
	compare : function(ctrl) {
		new Ajax.Request('/platform/apps/immosearch/request.asp?act=complist',{
			method : 'post',
			parameters : {
				objref : ctrl.value,
				comp   : ctrl.checked
			}
		});	
	},
	
	sortingChanged : function() {
		Listview.sortChanged = true;	
	},
	
	// Merken Funktion
	memorize : function(ctrl) {
		new Ajax.Request('/platform/apps/immosearch/request.asp?act=memorize', {
			method : 'post',
			parameters : {
				objref : ctrl.value, 
				mem	   : ctrl.checked
			}
		});
	},
	
	sort : function() {
		if (Listview.sortChanged) {
			if($('loader') != null) $('loader').show();
			new Ajax.Updater('searchResult', '/platform/apps/immosearch/request.asp?act=sort&tm=' + new Date().getTime(), {
				method : 'post',
				evalScripts : true,
				parameters : { 
					sortAttr : Search.getChecked('sorts', 'radio', ','),
					sortDir  : Search.getChecked('sortdir', 'radio', ','),
					data	 : $('data').innerHTML
					},
				onComplete : function() {
					Listview.sortChanged = false;
					if($('loader') != null) $('loader').hide();	
				}
			});
		}
	}				
});

/*********************************************
* Taf Klasse
*********************************************/
var ImmoTaf = Class.create({
	
	submit : function() {
	
		$('MB_window').style.height = '';
		$('divError2').hide();
		
		var hasError = false;
		var arr = new Array();
		arr[0] = 'txtFirstname';
		arr[1] = 'txtLastname';
		arr[2] = 'txtEmail';
		arr[3] = 'txtEmailRec';
		arr[4] = 'txtMsg';
	
		arr.each(function(item) {
			if(Common.txtLength(item) == 0) {
				hasError = true;	
				Common.addErrorClass(item);
			}
			else
				Common.removeErrorClass(item);
		});
		
		if(hasError) {
			if($('divError').style.display == 'none')
				$('divError').blindDown();
		}
		else {
			$('divError').hide();
			
			new Ajax.Request('/platform/apps/immosearch/request.asp?act=sendtaf', {
				method : 'post',
				parameters: {
					firstname : $('txtFirstname').value,
					lastname  : $('txtLastname').value,
					email	  : $('txtEmail').value,
					emailrec  : $('txtEmailRec').value,
					msg		  : $('txtMsg').value,
					objref	  : $('hidObjRef').value
					
				},
				onSuccess : function(transport) {
					if(transport.responseText.length == 0)
						Modalbox.hide();
					else {
						if($('divError2').style.display == 'none')
							$('divError2').blindDown();
					}
				} 
			});	
		}
	}			   
});

/*********************************************
* Result Klasse
*********************************************/
var ImmoResult = Class.create({
						  
	changeTo : function(viewType, data) {

		if ($('loader') != null) $('loader').show();
		
		$('searchResult').innerHTML = '';
		new Ajax.Updater('searchResult', '/platform/apps/immosearch/request.asp?act=changeview', {
			method : 'post',
			evalScripts : true,
			parameters : { viewtype : viewType, data : data },
			onComplete : function() {
				if ($('loader') != null) $('loader').hide();
			}
		});
	}
});

/*********************************************
* Detail Klasse
*********************************************/
var ImmoDetail = Class.create({

	changeTo : function(viewType, objRef) {
		new Ajax.Updater('MB_content', '/platform/apps/immosearch/request.asp?act=changedetailview', {
			method : 'post',
			evalScripts : true,
			parameters : { viewtype : viewType, objref : objRef },
			onComplete :function() {	
				Modalbox.focusableElements = Modalbox._findFocusableElements();
				Modalbox.resizeToContent();
			}
		});	
	},


	// Route berechnen
	route : function(objRef) {
	
		var hasError = false;
		var arr = new Array();
		
		arr[0] = 'txtStreet';
		arr[1] = 'txtZip';
		arr[2] = 'txtCity';
		
		arr.each(function(itm) {
			if(Common.txtLength(itm) == 0) {
				hasError = true;	
				Common.addErrorClass(itm);
			}
			else
				Common.removeErrorClass(itm);
		});
		
		$('MB_window').style.height = '';
		
		if(!hasError) {
			$('divRouteErr').blindUp();
			new Ajax.Updater('divRouteMap', '/platform/apps/immosearch/request.asp?act=calcroute', {
				method : 'post',
				evalScripts : true,
				parameters : 
				{
					street : $('txtStreet').value,
					zip	   : $('txtZip').value,
					city   : $('txtCity').value,
					objref : objRef
				},
				onComplete : function() {
					$('myRoute').style.display = "block";
				}
			});	
		}
		else {
			if($('divRouteErr').style.display == 'none')
				$('divRouteErr').blindDown();	
		}
	},
	
	toggle : function(id, img, height) {
	
		if($(id).style.height == '') {
			$(id).style.height = height + 'px';	
			$(id).style.overflow = 'hidden';	
			$(img).src = '/design/images/arrow_right.gif'; 
		}
		else {
			$(id).style.height = '';
			$(id).style.overflow = 'auto';	
			$(img).src = '/design/images/arrow_down.gif'; 
		}
	},
	
	changePicture : function(path) {
		$('imgObjPicture').src = path;	
	}
							  
});

// Screen Klasse
var ImmoScreen = Class.create({
		
	// Liefert die Aufloesung
	sendScreen : function() {
		new Ajax.Request('/platform/apps/immosearch/request.asp?act=setscreen',{
			method : 'post',
			parameters : {
				width 	: screen.width,
				height  : screen.height
			}
		});
	}							  
});

// Klasse für Umkreis-, Regionen- und Kantonssuche
var AmbitSearch = Class.create({
	
	// Liefert die Aufloesung
	initialize : function() {
		addEvent(window, 'load', bindEventsDummy, false); 
	},
	
	// Events anbinden
	bindEvents : function() {
		// Alle Objekte erstellen
		this.AmbitTabPlz = $('AmbitTabPlz');
		this.AmbitTabRegion = $('AmbitTabRegion');
		this.AmbitTabCanton = $('AmbitTabCanton');
		this.AmbitSearchKm = $('AmbitSearchKmId');
		this.AmbitSearchKm = $('AmbitSearchKmId');
		this.RegionSearchChoose = $('RegionSearchChooseId');
		this.CantonSearchChoose = $('CantonSearchChooseId');
		// Den Tabs die IDs des REgisterinhalts übergeben
		this.AmbitTabPlz.VisibleArea = $('AmbitSearchId');
		this.AmbitTabRegion.VisibleArea = $('RegionSearchId');
		this.AmbitTabCanton.VisibleArea = $('CantonSearchId');
		this.CurrentTab = this.AmbitTabPlz;
		// Mouseover/out registrieren
		this.registerMouseEffects(this.AmbitTabPlz);
		this.registerMouseEffects(this.AmbitTabRegion);
		this.registerMouseEffects(this.AmbitTabCanton);
		// Relativieren des Autocomplete Divs
		this.AutoCompleteArea = $('AmbitSearchAutoCompleteId');
		this.AutoCompleteInput = $('AmbitSearchInputId');
		//this.absolutizeArea();
		// Events anbinden an Tabs
		this.AmbitTabPlz.onclick = function() { 
			AmbitSearch.changeTab(AmbitSearch.AmbitTabPlz);
		};
		this.AmbitTabRegion.onclick = function() {
			AmbitSearch.changeTab(AmbitSearch.AmbitTabRegion);
		};
		this.AmbitTabCanton.onclick = function() {
			AmbitSearch.changeTab(AmbitSearch.AmbitTabCanton);
		};
		// Autocompleter an die PLZ/Ort suche (Schreibt immer PLZ in hidden Field)
		new Ajax.Autocompleter(
			'AmbitSearchInputId',
			'AmbitSearchAutoCompleteId',
			'plzautocomplete.asp', { 
				minChars : 2,
				afterUpdateElement : getAmbitSelectionId
			}
		);
		// Wenn Dropdown geupdates
		this.AmbitSearchKm.onchange = function() {
			// Andere Suchen zurücksetzen
			AmbitSearch.resetSearches(false,true,true);
			Search.changed = true;
			Search.UpdateSearch();
		}
		this.RegionSearchChoose.onchange = function() {
			AmbitSearch.resetSearches(true,false,true);
			Search.changed = true;
			Search.UpdateSearch();
		}
		this.CantonSearchChoose.onchange = function() {
			AmbitSearch.resetSearches(true,true,false);
			Search.changed = true;
			Search.UpdateSearch();
		}
	},
	
	// Konstruktor
	absolutizeArea : function() {

		// Position von Popup
		this.AutoCompleteInput.absolutize();		
		if (this.AutoCompleteInput.height == undefined) this.AutoCompleteInput.height = 0;
		if (this.AutoCompleteInput.width == undefined) this.AutoCompleteInput.width = 0;
			
		this.setPosition(
			(this.AutoCompleteInput.offsetTop + this.AutoCompleteInput.height) - this.AutoCompleteInput.height,
			(this.AutoCompleteInput.offsetLeft + this.AutoCompleteInput.width) - this.AutoCompleteInput.width
		);
		this.AutoCompleteInput.relativize();
		
		this.AutoCompleteArea.style.display = 'none';
		this.AutoCompleteArea.style.position = 'absolute';
	},
	
	// Mouse Effekte registrieren
	registerMouseEffects : function(tab) {
		tab.onmouseover = function() {
			this.style.cursor = 'pointer';
		};
		tab.onmouseout = function() {
			this.style.cursor = 'default';
		};
	},
	
	// Suchen zurücksetzen
	resetSearches : function (ambit,region,canton) {
		if (ambit) {
			this.AutoCompleteInput.value = '';
			this.AmbitSearchKm.value = 0;
			$('AmbitSearchPlzId').value = '';
		}
		if (region) {
			this.RegionSearchChoose.value = 0;
		}
		if (canton) {
			this.CantonSearchChoose.value = 0;
		}
	},
	
	// Posiition setzen
	setPosition : function(topPos, leftPos) {
		topPos = topPos.toString();
		leftPos = leftPos.toString();

		if (topPos.indexOf('px') == -1) topPos += 'px';
		if (leftPos.indexOf('px') == -1) leftPos += 'px';
		
		this.AutoCompleteArea.style.top = topPos;
		this.AutoCompleteArea.style.left = leftPos;
	},
	
	// Tabs wechseln
	changeTab : function(clickedTab) {
		// Nichts tun, wenn Tab schon aktiv
		if (clickedTab.id != this.CurrentTab.id) {
			// Aktuelles Tab und Area unsichtbar machen
			this.CurrentTab.className = 'AmbitTabUnselected';
			this.CurrentTab.VisibleArea.blindUp({ duration: 0.5 });
			// Neues Tab als aktuelles zuweisen
			this.CurrentTab = clickedTab;
			this.CurrentTab.className = 'AmbitTabSelected';
			// Erst eine halbe Sekunde später ablassen
			setTimeout('changeCurrentTabDelayed()',450);
		}
	}
});

// Dummy klasse um Objektmethode aufzurufen
function bindEventsDummy() {
	AmbitSearch.bindEvents();
}

// Dummy wegen Event Delay
function changeCurrentTabDelayed() {
	AmbitSearch.CurrentTab.VisibleArea.blindDown({ duration: 0.5 });
}

// Dummy für Ajax Autocomplete Auswahl
function getAmbitSelectionId(text, li) {
	AmbitSearch.resetSearches(false,true,true);
    $('AmbitSearchPlzId').value = li.id;
	// Auf Change die Suche updaten (Anzahl Wohnungen etc.)
	Search.changed = true;
	Search.UpdateSearch();
}

var Detail 	 	= new ImmoDetail();
var Result 	 	= new ImmoResult();
var Taf 	 	= new ImmoTaf();
var Listview 	= new ImmoListview();
var Compare  	= new ImmoCompare();
var Common   	= new ImmoCommon();
var Search   	= new ImmoSearch();
var Screen   	= new ImmoScreen();
var AmbitSearch = new AmbitSearch();