var karteWin;
function openWin() {
	if ((typeof popupWin == "object") && (! (karteWin.closed))) {
		karteWin.close();
	}
	karteWin = window.open("/karte.html","karteWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=520,height=350,dependent=no,left=200,top=200");
}

var popupWin;
function openPic(pfad,breite,hoehe) {
	if ((typeof popupWin == "object") && (! (popupWin.closed))) {
		popupWin.close();
	}
	popupWin = window.open("/bild.php?pfad="+pfad+"&breite="+breite+"&hoehe="+hoehe,"popupWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+breite+",height="+hoehe+",dependent=no,left=200,top=200");
}

var helpWin;
function help(hilfe) {
	if ((typeof helpWin == "object") && (! (helpWin.closed))) {
		helpWin.close();
	}
	if(hilfe == 1) {
		var pfad = "/cookie.html";
		var breite = 200;
		var hoehe = 250;
	}
	helpWin = window.open(pfad,"helpWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+breite+",height="+hoehe+",dependent=no,left=200,top=200");
}

function abschicken(senden) {
	if(senden) {
		document.forms[0].senden.value=1;
	}
	document.forms[0].submit();
}

var grundrissWin;
function grundrissPopup(pic,bildtext,objektId,typ) {
	if ((typeof grundrissWin == "object") && (! (grundrissWin.closed))) {
		grundrissWin.close();
	}
	if(typ == 1) {
		var breite = 460;
		var hoehe = 520;
		var datei = "/ansicht";
		var scroll = 0;
	} else {
		var breite = 760;
		var hoehe = 610;
		var datei = "/grundriss";
		var scroll = 1;
	}
	grundrissWin = window.open(datei+".php?photo="+pic+"&bildtext="+bildtext+"&objektId="+objektId+"","PicPopUp","toolbar=0,location=0,status=0,menubar=0,scrollbars="+scroll+",resizable=0,width="+breite+",height="+hoehe+",dependent=no,left=10,top=10");
}

function checkBoxes(elementId,check) {
    var checkboxes = $('checkList').select('.subList');
    if(elementId == "alle" && $(elementId).checked == true) {
        checkboxes.each(function(s) {
            s.checked = false;
        });
        changeList();
    } else if(elementId == "alle" && $(elementId).checked == false) {
        $("alle").checked = true;
    } else if(elementId != "alle" && $(elementId).checked == false) {
        var count = 0;
        checkboxes.each(function(s) {
            if(s.checked == true) count++;
        });
        if(count == 0) $("alle").checked = true;
        changeList();
    } else {
        $("alle").checked = false;
        changeList();
    }
}
function changeList(set_id,path,formular) {
	new Ajax.Updater("objektliste", "/ajax_objektliste.php", {
		parameters: $("checkList").serialize(true)
	});
}

// Lightbox
// BASE
var	UserAgent =	{};

if (navigator.userAgent.indexOf('AppleWebKit') > -1) {
	UserAgent.WEBKIT = true;
}
else if	(navigator.userAgent.indexOf('Opera') >	-1)	{
	UserAgent.OPERA	= true;
	UserAgent.VERSION =	navigator.userAgent.match(/Opera.(\d)/)[1];
}
else if	(navigator.userAgent.indexOf('KHTML') >	-1)	{
	UserAgent.KHTML	= true;
}
else if	(navigator.userAgent.indexOf("Gecko") >	-1)	{
	UserAgent.GECKO	= true;
}
else if	(navigator.userAgent.indexOf("MSIE") > -1) {
	UserAgent.MSIE = true;
	if (window.XMLHttpRequest) {
		UserAgent.VERSION = 7;
	}
	else {
		UserAgent.VERSION = 6;
	}
}

Position.getViewPortBounds =
	function() {
	var	left;
	var	top;
	var	width;
	var	height;

	if (UserAgent.OPERA || UserAgent.WEBKIT) {
		left = self.pageXOffset;
		top	= self.pageYOffset;
		width = window.innerWidth;
		height = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		left = document.documentElement.scrollLeft;
		top	= document.documentElement.scrollTop;
		width =	document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
	else if (document.body) {
		left = document.body.scrollLeft;
		top = document.body.scrollTop;
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}

	return { left: left, top: top, width: width, height: height	};
};

function fotogr(url,bild_id,width,height,el,parent_id,is_user){
	if(el == "detailbild") {
		var pfad = "bild_popup.php?picture="+bild_id+".jpg&amp;offer_id="+parent_id;
		$(el).innerHTML = "";
		var temp = "";
		if(is_user) temp += "<a href=\""+pfad+"\" class=\"lbOn\" id=\"galerieLink\" target=\"_blank\">";
		temp += "<img src=\""+url+"\" alt=\"\" width=\""+width+"\" height=\""+height+"\" border=\"0\">";
		if(is_user) temp += "</a>";
		$(el).innerHTML = temp;
		if(is_user) neueBox = new lightbox($('galerieLink'));
	} else {
		$(el).innerHTML = "";
		new Ajax.Updater(el, "bild.php?pfad="+url, {
		});
	}
}
function lb_ajax(url,el,el2,formular){
	new Ajax.Updater(el2, url, {
		parameters: $(formular).serialize(true),
		onComplete: function(){
			//$(el).style.backgroundColor = "#fff";
			$('senden').style.display = "none";
			$('abbrechen').style.display = "none";
			$('schliessen').style.display = "block";
	    }
	});
}
function lb_ajax2(url,el,el2,formular){
	new Ajax.Updater(el2, url, {
		parameters: $(formular).serialize(true),
		evalScripts:true,
		onComplete: function(){
			//$(el).style.backgroundColor = "#fff";
			/*$('senden').style.display = "none";
			$('abbrechen').style.display = "none";
			$('schliessen').style.display = "block";*/
	    }
	});
}

var Overlay = {
	start:
	function(options) {
		this.options = options || {};
		if (UserAgent.MSIE)	{
			var	selects	= document.getElementsByTagName('select');
			for	(i = 0;	i <	selects.length;	i++) {
				selects[i].style.visibility	= 'hidden';
			}
		}
		if (!this.overlay) {
			this.refreshDisplayEL = this.refreshDisplay.bind(this);
			this.overlay = document.createElement('div');
			this.overlay.id = 'overlay';
			this.overlay.className = 'overlay';
			document.body.appendChild(this.overlay);
		}

		Element.setStyle(this.overlay, { visibility: 'hidden', width: '0', height: '0', display: '' });
		this.refreshDisplay();
		Element.setStyle(this.overlay, { visibility: '' });		
		Event.observe(window, 'resize', this.refreshDisplayEL);
		Event.observe(window, 'scroll', this.refreshDisplayEL);
	},
	
	stop:
	function() {
		Event.stopObserving(window, 'resize', this.refreshDisplayEL);
		Event.stopObserving(window, 'scroll', this.refreshDisplayEL);
		Element.hide(this.overlay);
		if (UserAgent.MSIE)	{
			var	selects	= document.getElementsByTagName('select');
			for	(i = 0;	i <	selects.length;	i++) {
				selects[i].style.visibility	= '';
			}
		}
	},

	refreshDisplay:
	function() {
		var	vB = Position.getViewPortBounds();
		Element.setStyle(this.overlay, { width: (vB.left + vB.width) + 'px', height: (vB.top + vB.height) + 'px' });
		if (this.options.dialog) {
			var left = (vB.left + ((vB.width - this.options.dialog.offsetWidth) / 2));
			var top = (vB.top + ((vB.height - this.options.dialog.offsetHeight) / 2));
			if (left < 0) left = 0;
			if (top < 0) top = 0;
			Element.setStyle(this.options.dialog, { left:  left + 'px', top: top + 'px' });
		}
	}
};

function showLightbox () {
	var	pos = Position.getViewPortBounds();
	var hoehe = Element.getHeight("lightbox");
	var breite = Element.getWidth("lightbox");

	var top = (pos.height - hoehe)/2;
	var left = (pos.width - breite)/2;
	
	if (UserAgent.MSIE && UserAgent.VERSION == 6)	{
		left = left + pos.left;
		top = top + pos.top;
	}
	Element.setStyle('lightbox', { left:  left + 'px', top: top + 'px' });
	
	showLoading ('none');
	$('lightbox').style.zIndex = "10000";
	
}
function stopLighbox() {
	parent.Overlay.stop();
	parent.$('lightbox').style.display='none';
	parent.$('lbContent').remove();
}

function showLoading (display) {
	var	pos = Position.getViewPortBounds();
	var hoehe = Element.getHeight("loading");
	var breite = Element.getWidth("loading");

	var top = (pos.height)/2;
	var left = (pos.width)/2;
	
	if (UserAgent.MSIE && UserAgent.VERSION == 6)	{
		left = left + pos.left;
		top = top + pos.top;
	}
	Element.setStyle('loading', { left:  left + 'px', top: top + 'px' });
	
	$('loading').style.display = display;	
}