function toggleElementVisibility(el) {
	var elem = $(el);
	if (typeof(elem) !="undefined") {
		if (elem.style.display=='none')
			elem.style.display = 'block';
		else
			elem.style.display = 'none';
	}
}
var box;
var form;
var iframe;

function openLayer() {
	// Hintergrundbox
	iframe = new Element('iframe', {
		'styles': {
			'position': 'absolute',
			'top': '0px',
			'left': '0px',
			'width': window.getScrollWidth() + 'px',
			'height': window.getScrollHeight() + 'px',
			'z-index': '99'
		}
	});
	iframe.setOpacity(0.1);
	iframe.injectInside(document.body);
	box = new Element('div', {
		'styles': {
			'background-color': '#333333',	// light dark color or png image
			'position': 'absolute',
			'top': '0px',
			'left': '0px',
			'width': window.getScrollWidth() + 'px',
			'height': window.getScrollHeight() + 'px',
			'z-index': '100'
		}
	});
	
	box.injectInside(document.body);
	box.setOpacity(0.7);
	// Flashs ausblenden
	var flashs = $$('object', 'embed');
	for (var i=0; i<flashs.length; i++) {
		flashs[i].style.visibility = 'hidden';
	}
}
function closeLayer() {
	form.remove();
	box.remove();
	if (iframe)
		iframe.remove();
	// Flashs einblenden
	var flashs = $$('object', 'embed');
	for (var i=0; i<flashs.length; i++) {
		flashs[i].style.visibility = 'visible';
	}
}
function showAjaxForm(src) {
	if (getBrowserData()=="Firefox3") {
		window.location.href = "/login.php";
		return null;
	}
	openLayer();
	// Formular Laden
	if (!window.ie6) {
		var top = (window.getHeight()/2)-200;
	}
	else {
		var top = window.getScrollTop()+(window.getHeight()/2)-200;
	}
	// position: fixed ist n�tig damit die Cursor in den eingabefeldern
	// erscheinen (FFox)
	// Allerdings versteht der IE 6 position: fixed nicht
	form = new Element('div', {
		'styles': {
			'width': '500px',
			'padding': '10px 10px',
			'background-color': '#FFF',
			'position': 'fixed',
			'top': top+'px',
			'left': (window.getWidth()/2)-250+'px',
			'z-index': '101',
			'border': '1px solid #999'
		},
		'id': 'loginForm'
	});
	if (window.ie6) {
		form.setStyle('position', 'absolute');
	}
	form.injectAfter(box);
	form.setOpacity(1);
	new Ajax(src, {
			method: 'get',
			update: 'loginForm',
			onComplete: function(x) {
				if (!window.ie6) {
					form.setStyle('top', (window.getHeight()/2)-(form.getSize().size.y/2));
				}
				else {
					form.setStyle('top', window.getScrollTop()+(window.getHeight()/2)-(form.getSize().size.y/2));
				}
				if ((window.ie6 || window.ie7) && $("mode")) {
					$("mode").remove();
				}
				$("loginForm").addEvent('submit', function(e) {
					e = new Event(e).stop();
					this.send({
						onComplete: function(result) {
							var res = new Json.evaluate(result);
							if (res.error) {
								$("errorMsg").setText(res.error);
								$("errorMsg").setStyle('display', 'block');
							}
							else if (res.redirect) {
								window.location.href = res.redirect;
							}
						}
					});
				});
				// Cursor auf Benutzername-Feld Positionieren
				if ($("uname")) {
					// $("uname").setStyle('z-index', '102');
					$("uname").focus();
				}
			}
		}).request();
}
function showAjaxFormNew(src) {
	openLayer();
	// Formular Laden
	if (!window.ie6) {
		var top = (window.getHeight()/2)-200;
	}
	else {
		var top = window.getScrollTop()+(window.getHeight()/2)-200;
	}
	// position: fixed ist n�tig damit die Cursor in den eingabefeldern
	// erscheinen (FFox)
	// Allerdings versteht der IE 6 position: fixed nicht
	form = new Element('div', {
		'styles': {
			'width': '500px',
			'padding': '10px 10px',
			'background-color': '#FFF',
			'position': 'fixed',
			'top': top+'px',
			'left': (window.getWidth()/2)-250+'px',
			'z-index': '101',
			'border': '1px solid #999'
		},
		'id': 'loginForm'
	});
	if (window.ie6) {
		form.setStyle('position', 'absolute');
	}
	form.injectAfter(box);
	form.setOpacity(1);
	new Request.HTML(src, {
			method: 'get',
			update: 'loginForm',
			onComplete: function(x) {
				if (!window.ie6) {
					form.setStyle('top', (window.getHeight()/2)-(form.getSize().size.y/2));
				}
				else {
					form.setStyle('top', window.getScrollTop()+(window.getHeight()/2)-(form.getSize().size.y/2));
				}
				if ((window.ie6 || window.ie7) && $("mode")) {
					$("mode").remove();
				}
				$("loginForm").addEvent('submit', function(e) {
					e = new Event(e).stop();
					this.send({
						onComplete: function(result) {
							var res = new Json.evaluate(result);
							if (res.error) {
								$("errorMsg").setText(res.error);
								$("errorMsg").setStyle('display', 'block');
							}
							else if (res.redirect) {
								window.location.href = res.redirect;
							}
						}
					});
				});
				// Cursor auf Benutzername-Feld Positionieren
				if ($("uname")) {
					// $("uname").setStyle('z-index', '102');
					$("uname").focus();
				}
			}
		}).send();
}

function disableLink(elem) {
	elem.href = 'javascript:void(0)';
	// alert(elem);
}

function replaceLink(elem, link) {
	elem.href = link;
}

function showLogin(elem,rootPath) {
	elem.href = 'javascript:void(0)';
	showAjaxForm(rootPath+'/login.php?mid=102&mode=overlay');
}
function openWindow(elem, address, width, height, scrolling) {
	elem.href = 'javascript:void(0)';
	var scroll = "no";
	if (scrolling==true)
  		scroll = "yes";
  	preview = window.open(address, '', "width="+width+",height="+height+",scrollbars="+scroll);
  	preview.focus();
}
function closeLogin() {
	closeLayer();
}
function openOverlayMessage(htmlMsg) {
	if ($('noScriptOverlayFrame')) {
		$('noScriptOverlayFrame').remove();
	}
	if ($('noScriptOverlay')) {
		$('noScriptOverlay').remove();
	}
	openLayer();
	var msgBox = new Element('div', {
		'styles': {
			'position': 'fixed',
			'top': '0px',
			'left': '100px',
			'right': '100px',
			'width': 'auto',
			'height': '90px',
			'z-index': '101',
			'background-color': '#FFF'
		}
	});
	msgBox.injectInside(document.body);
	msgBox.setHTML(htmlMsg);
	msgBox.setOpacity(0.9);
}
var oldBackground;
function highlightText(key) {
	var elem = document.getElementById(key);
	if (!elem) {
		elem = document.getElementById(key.toUpperCase());
	}
	if (elem) {
		if (elem.style.backgroundColor!='yellow') {
			oldBackground = elem.style.backgroundColor;
			elem.style.backgroundColor = 'yellow';
		}
		else {
			elem.style.backgroundColor = oldBackground;
		}
	}
	else {
		// alert("Element "+key+" nicht gefunden");
	}
	// document.body.innerHTML = searchText;
}

function hoverButtonOn(left, content, right) {
	left.style.background = 'url(/images/buttons/ergebnisse_button_pressed_left.jpg) no-repeat';
	content.style.background = 'url(/images/buttons/ergebnisse_button_pressed_bg.jpg) repeat-x';
	right.style.background = 'url(/images/buttons/ergebnisse_button_pressed_right.jpg) no-repeat top left';
}
function hoverButtonOff(left, content, right) {
	left.style.background = 'url(/images/buttons/ergebnisse_button_left.jpg) no-repeat';
	content.style.background = 'url(/images/buttons/ergebnisse_button_bg.jpg) repeat-x';
	right.style.background = 'url(/images/buttons/ergebnisse_button_right.jpg) no-repeat top left';
}
function getQueries(input, rootPath) {
	if (input.length>2) {
		var branchenAjax = new Json.Remote('/_ajax/getQueries.php', {
			autoCancel: 'true',
			onComplete: function(jsonObj) {
				if (jsonObj.length>0) {
					var html = '<ul class="hidden_list">';
					html+='<a href="#" style="position: absolute; top: 3px; right: 3px; color: red" onclick="$(\'querySuggBox\').style.display=\'none\'">x</a>';
					$('querySuggBox').style.display = 'block';
					for (var i=0; i<jsonObj.length; i++) {
						html+= '<li class="clickable" onclick="location.href = \''+rootPath+'web/all/'+jsonObj[i].name+'.1.html\';">'+jsonObj[i].name+'</li>';
					}
					html+= "</ul>";
					$('querySuggBox').innerHTML = html; 
				}
				else {
					$('querySuggBox').style.display = 'none';
				}
			}
		}).send({'inp': input, 'mode': 'json'});
	}
	else {
	 	$('querySuggBox').style.display = 'none';
	}
}

function getCities(input) {
	if (input.length>2) { 
		var url = '/_ajax/getOrte.php?mode=json&code='+$('fuzzyCountry').value+'&inp='+encodeURI(input);
		new Json.Remote(url, { method: 'get', autoCancel: 'true', onComplete:
				function(jsonObj) { 
					$('citySuggBox').style.display = 'block';
					$('fuzzyCid').value = "";
					var html = '<ul class="hidden_list" style="position: relative">';
					if (jsonObj.cities.length>0) { 
						for (var i=0; i<jsonObj.cities.length; i++) { 
							var cityName = jsonObj.cities[i].name.replace(/'/,"`");
							html+= '<li class="clickable" onclick="$(\'fuzzyCid\').value=\''+jsonObj.cities[i].id+'\'; $(\'fuzzyCity\').value = \''+cityName+'\'; $(\'citySuggBox\').empty(); $(\'citySuggBox\').style.display = \'none\'; showAddress(\''+jsonObj.cities[i].plz+' '+cityName+','+$('fuzzyCountry').value+'\',12)">'+jsonObj.cities[i].plz+' '+jsonObj.cities[i].name+'</li>'; 
						} 
					}
					html+='<div class="clickable" style="font-weight: bold; position: absolute; top: 2px; right: 2px; color: red;" onclick="$(\'citySuggBox\').style.display = \'none\'">x</div>';
					html+= "</ul>";
					$('citySuggBox').innerHTML = html;
					
					$('fuzzyCity').addEvent('blur', function(e1) {
						window.setTimeout("$('citySuggBox').style.display = 'none';",300);
					});
				}			
			}).send(); 
	} 
}
function getCats(input) {
	if (input.length>2) { 
		var url = '/_ajax/getBranchen.php';
		new Json.Remote(url, { method: 'get', autoCancel: 'true', onComplete:
				function(jsonObj) { 
					$('catSuggBox').style.display = 'block';
					$('fuzzyBid').value = "";
					var html = '<ul class="hidden_list" style="position: relative">';
					if (jsonObj.length>0) { 
						for (var i=0; i<jsonObj.length; i++) { 
							var catName = jsonObj[i].name.replace(/'/,"`");
							html+= '<li class="clickable" onclick="$(\'fuzzyBid\').value=\''+jsonObj[i].id+'\'; $(\'fuzzyCat\').value = \''+catName+'\'; $(\'catSuggBox\').empty(); $(\'catSuggBox\').style.display = \'none\';">'+jsonObj[i].name+'</li>'; 
						} 
					}
					html+='<div class="clickable" style="font-weight: bold; position: absolute; top: 2px; right: 2px; color: red;" onclick="$(\'catSuggBox\').style.display = \'none\'">x</div>';
					html+= "</ul>";
					$('catSuggBox').innerHTML = html;
					
					$('fuzzyCat').addEvent('blur', function(e1) {
						window.setTimeout("$('catSuggBox').style.display = 'none';",300);
					});
				}			
			}).send({'inp': encodeURI(input), 'mode': 'json', 'code': $('fuzzyCountry').value}); 
	} 
}

function getBrowserData() {
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = '';
	var fullVersion  = 0; 
	var majorVersion = 0;

	// In Internet Explorer, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
	 browserName  = "Microsoft Internet Explorer";
	 fullVersion  = parseFloat(nAgt.substring(verOffset+5));
	 majorVersion = parseInt(''+fullVersion);
	}

	// In Opera, the true version is after "Opera"
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
	 browserName  = "Opera";
	 fullVersion  = parseFloat(nAgt.substring(verOffset+6));
	 majorVersion = parseInt(''+fullVersion);
	}

	// In Firefox, the true version is after "Firefox"
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
	 browserName  = "Firefox";
	 fullVersion  = parseFloat(nAgt.substring(verOffset+8));
	 majorVersion = parseInt(''+fullVersion);
	}

	// In most other browsers, "name/version" is at the end of userAgent
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
 		browserName  = nAgt.substring(nameOffset,verOffset);
 		fullVersion  = parseFloat(nAgt.substring(verOffset+1));
 		if (!isNaN(fullVersion)) majorVersion = parseInt(''+fullVersion);
 		else {fullVersion  = 0; majorVersion = 0;}
	}

	// Finally, if no name and/or no version detected from userAgent...
	if (browserName.toLowerCase() == browserName.toUpperCase() || fullVersion==0 || majorVersion == 0 ) {
 		browserName  = navigator.appName;
 		fullVersion  = parseFloat(nVer);
 		majorVersion = parseInt(nVer);
	}
	return browserName+fullVersion;
}
var abortRotation = false;
function startThumbRotation(img) {
	abortRotation = false;
	getNextThumb(img);
}

function getNextThumb(img) {
	var ajax = new Json.Remote('/_ajax/getThumb.php', {
			autoCancel: 'true',
			onComplete: function(jsonObj) {
				if (jsonObj.src.length>0) {
					img.setAttribute('src', jsonObj.src);
				}
				else {
					abortThumbRotation();
				}
			},
			onFailure: function() {
				abortThumbRotation();
			}
		}).send({'last': img.src, 'mode': 'json'});
	if (abortRotation==false) {
		window.setTimeout(function () { getNextThumb(img) }, 1000);
	}
}
function abortThumbRotation(img, thumb) {
	abortRotation = true;
	img.setAttribute('src', thumb);
}
function clc(e,t,i) {
	e.href="/redirect.php?cat="+t+"&id="+i;
	e.onmousedown="";
	return true;
}
function visiCounter(t,c,id) {
	var ret = true;
	var ajax = new Json.Remote('/_ajax/visiCounter.php').send({'t':t, 'c':c, 'id':id, 'mode':'json'});
}
function toggleReplace(id1,id2) {
	var elem1 = document.getElementById(id1);
	var elem2 = document.getElementById(id2);
	
	if (elem1.style.display=='block' || elem1.style.display=='') {
		elem1.style.display = 'none';
		elem2.style.display = 'block';
	}
	else {
		elem1.style.display = 'block';
		elem2.style.display = 'none';
	}
}
function changePic(elem,picsrc,titleElem,title) {
	$(elem).src = picsrc;
	$(elem).style.display= 'block';
	$('modulebox_starttext').style.display='none';
	$(titleElem).innerHTML = title;
}
function resetModuleBox(title) {
	$('modulebox_pic').style.display = 'none'; 
	$('modulebox_starttext').style.display = 'block';
	$('modulebox_title').innerHTML = title;
}
function checkOwnerForm(kid) {
	if ($('owner').checked) {
		window.location.href="/formEintrag.php?complete="+kid;
	}
}