// Vor allem Dreamweaver Funktionen
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openWindow(href,width,height){
  window.open(href,'_blank','width='+parseInt(width)+',height='+parseInt(height));
  return false;
}

function changeLocation(href)
{
	window.location = href;
}

function showBox(width, height, url) {
	Shadowbox.open({
        player:     'iframe',
        content:    url,
        width:      width,
        height:     height
    });
}

function showPropertyBook() {
	showBox(922, 329, "/group/swf-show.php?src=/flash/x-flash/pr-katalog2010.swf&w=920&h=327&noPadding=1&bgcolor=FFFFFF");
}

function detectLocation()
{
	try{
	str = window.location.toString();
	str = str.split('/');
	if (!str[3]) return '';
	return str[3];
	}
	catch(e){
		return '';
	}
}

function detectSubLocation()
{
	try{
	str = window.location.toString();
	str = str.split('/');
	if (!str[4]) return '';
	return str[4];
	}
	catch(e){
		return '';
	}
}

function showProperty(e)
{
	window.open(e.getElementsByTagName('a')[0].href,'_blank');
//	window.location = e.getElementsByTagName('a')[0].href;
}

function preloadPictures() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadPictures.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function preloadPictures_lay() { //v1.0
	if(document.images){
		var a=preloadPictures_lay.arguments;
		var newLay = document.createElement("div");
		newLay.style.position = 'absolute';
		newLay.style.top = '-500px';
		newLay.style.width = '500px';
		var images = '';
		
		for(var i=0; i < a.length; i++)
		if (a[i].indexOf("#")!=0){
			images += '<img src="'+a[i]+'" alt="" height="1" width="1" />';
		}
		newLay.innerHTML = images;
		document.getElementsByTagName('body')[0].appendChild(newLay);
	}
}

function statisticTracker(leads)
{
	if (typeof(leads) == 'undefined') leads = 0;
	
	// Partner ID erkennen
	wpid = window.location.toString().match(/wpid=[0-9]*/gi);
	try{wpid = wpid.toString().substr(5);}catch(e){wpid='';}
	if (typeof(wpid) == 'undefined' || !wpid) wpid = '';
	
	return '<iframe src="http://w00887f9.dd8328.kasserver.com/js/wptracker.php?wpid='+wpid+'&leads='+leads+'&cusrc='+encodeURIComponent(window.location.toString())+'" style="display:none"></iframe>';
}

function myVoid()
{
	// Empty
}

var group;
var coordinates;
var drag;
var dragLayer;
var dragElement;
var layerTimeout;
var layerLastX = 0.5;
var layerLastY = 0.5;

function dragLayerInit_dynamic(layerId, dragHandlerId)
{
	// Variablen initialisieren
	coordinates = ToolMan.coordinates();
	drag = ToolMan.drag();
	
	// Layer initialisieren
	dragLayer = document.getElementById(layerId);
	dragElement = document.getElementById(dragHandlerId);
	group = drag.createSimpleGroup(dragLayer, dragElement);
	// Listener für Beendigung des Draggens
	group.register("dragend", function(dragEvent) {
		try{
			// Position speichern
			var element = dragEvent.group.element;
			saveLayerPosition_dynamic(element);
		}catch(e){};
	});

	// Größe des Handlers einstellen
	resizeLayerHandler_dynamic(layerId, dragHandlerId);
}

function disableLayer_dynamic(id)
{
	// Sichtbarkeit aus
	document.getElementById(id).style.display='none';
	
	// Copyright Positionierung
	newCopyrightPosition();
	
	// Kommando an Session übergeben
	ajaxSuccess = myVoid;
	ajaxTimeout = myVoid;
	makePOSTRequest("/ajax/tools/dragdrop_dynamic.php", "cmd=close&layer="+id);
}

function saveLayerPosition_dynamic(element)
{
	// Copyright Positionierung
	newCopyrightPosition();
	
	// Position abspeichern
	ajaxSuccess = myVoid;
	ajaxTimeout = myVoid;
	makePOSTRequest("/ajax/tools/dragdrop_dynamic.php", "cmd=savePos&layer="+element.getAttribute('id')+"&layer_x="+parseInt(element.style.left)+"&layer_y="+parseInt(element.style.top));
}

function resizeLayerHandler_dynamic(layerId, dragHandlerId)
{
	source = document.getElementById(layerId);
	target = document.getElementById(dragHandlerId);
	
	target.style.width = source.offsetWidth+"px";
	target.style.height = source.offsetHeight+"px";
	//target.style.border = '1px solid red';
}

function showElement(id, show)
{
	document.getElementById(id).style.display = (show) ? 'block' : 'none';
}

function removeShadowboxLeftOvers() {
	try {
		document.getElementById('removeFromShadowbox').innerHTML = '';
	} catch (e) {
	};
}

function newCopyrightPosition()
{
	try{
		/*
			Bestimmen der Position des Suchcopyrights
			Vergleich mit Body-Height
			Entscheidung
		*/
		oriCopy = document.getElementById('copyright');
		oriBody = document.getElementById('outer');
		
		newFoot = document.getElementById('newFooter');
		
		// Prüfen ob es einen Layer gibt, der auch angezeigt wird!
		try{
			if (typeof(dragLayer) != 'undefined' && dragLayer.style.display!='none'){
				// Prüfen ob der Draglayer wirklich weiter unten liegt!
				copyBottom = absTop(oriCopy)+oriCopy.offsetHeight;
				layBottom = absTop(dragLayer)+dragLayer.offsetHeight;
				
				if (copyBottom < layBottom){
					oriCopy = dragLayer;
				}
			}
		}catch(e){}
		
		copyBottom = absTop(oriCopy)+oriCopy.offsetHeight;
		
		bodyHeight = oriBody.offsetHeight;
		
		//newFoot.innerHTML = copyBottom+' &gt; '+bodyHeight;
		if (copyBottom > bodyHeight){
			//newFoot.style.borderTop = '1px solid red';
			newFoot.style.bottom = 'auto';
			newFoot.style.top = copyBottom+'px';
		}else{
			//newFoot.style.borderTop = '1px solid green';
			newFoot.style.top = 'auto';
			newFoot.style.bottom = 0;
		}
	}catch(e){}
}

function setCookieInfo(key, value) {
	document.cookie = ( key + "=" + encodeURIComponent(value) );
}

function getCookieInfo(key) {
	//alert(document.cookie);
}

function setSlideshowCookie(index) {
	setCookieInfo('topSlide', index);
	//document.getElementById('logo').innerHTML = document.cookie + "<p>" + new Date() + "</p>";
}

var workingOnIE6 = false;
function replaceShadedPictures() {
	// Working on IE6?
	v =  navigator.appVersion.indexOf('MSIE');
	if (v != -1) {
		v = parseInt(navigator.appVersion.substr(v+5, 1));
		if (!isNaN(v) && v <= 6) {			
			workingOnIE6 = true;
		}
	}
	
	is = document.getElementById('content').getElementsByTagName('img');
	for (var i = 0; i < is.length; i++) {
		if (pictureNodeAllowedToTransform(is[i])) {
			transformShadedPicture(is[i]);
		}
	}
}

function pictureNodeAllowedToTransform(img) {
	if (img.className.search('shadedPicture') != -1 || (img.src.search('picture/upload/team') == -1 && img.src.search('immo-pics/') == -1 && img.src.search('/suche/') == -1 && img.src.search('/objektdetails/') == -1 && img.src.search('/x-pics/') == -1 && img.src.search('ma-dvd-bestellbutt') == -1 && img.src.search('/bt-') == -1) && img.src.search('ma-lifestyle-') == -1 && img.src.search('blind.gif') == -1) {
		return true;
	}
	return false;
}

function transformShadedPicture(node) {
	try {
		var imageWidth = node.offsetWidth;
		var imageHeight = node.offsetHeight;

		// Schatten Start erzeugen
		var starter = document.createElement('span');
		starter.className = 'shaded start';
		starter.style.width = (imageWidth - 15) + 'px';
		
		// Schatten Ende erzeugen
		var end = document.createElement('span');
		end.className = 'shaded end';
		end.style.width = (imageWidth - 15) + 'px';
		
		// Umgebenden Node erzeugen
		var surrounder = document.createElement('span');
		surrounder.style.width = imageWidth + 'px';
		
		// Bild-Kopie erzeugen und Klassenname übertragen
		var copy = node.cloneNode(true);
		surrounder.className = copy.className;
		copy.className = 'shadedTransform';
		
		// Align entfernen
		if (typeof(copy.align) != 'undefined' && copy.align) {
			var classAdd = copy.align + 'Align';
			if (surrounder.className.search(classAdd) == -1) {
				surrounder.className += ' ' + classAdd;
			}
			copy.align = '';
		}
		
		// Nachfolgendes Break entfernen, sofern es dem Bild oder dem Eltern-Knoten des Bildes folgt
		try {
			if (node.nextSibling != null && node.nextSibling.tagName == 'BR') {
				node.parentNode.removeChild(node.nextSibling);
			}
			
			if (node.parentNode.nextSibling != null && node.parentNode.nextSibling.tagName == 'BR') {
				node.parentNode.parentNode.removeChild(node.parentNode.nextSibling);
			}
		} catch(e) {
//			document.getElementById('logo').innerHTML = e;
		}

		
		// Knoten einfügen
		surrounder.appendChild(starter);
		surrounder.appendChild(copy);
		surrounder.appendChild(end);

		// Korrektur IE6
		if (workingOnIE6) {
			surrounder.innerHTML = '<span class="shaded start" style="width:'+starter.style.width+'"></span>' + surrounder.innerHTML;
		}
		
		// Knoten an Bildstelle einhängen und Bild entfernen
		node.parentNode.replaceChild(surrounder,node);
	} catch(e) {
	}
}