function hidePictRowCover(obj) {
	obj.style.backgroundImage = '';
}

function showPictRowCover(obj, theImage) {
	obj.style.backgroundImage = 'url("' + theImage + '")';
}

function movePictRowRight(id, imageWidth, minX) {
	var pictRow = document.getElementById('pictRow_'+id);
	
	var pictRowLeft = parseInt(pictRow.style.left) - imageWidth;
	document.getElementById('pictRowBtnRight_'+id).style.display = 'none';
	
	$('#pictRow_'+id).animate({
	    left: '-='+imageWidth
	  }, 500, function() {
	  	if (pictRowLeft > minX) {
			document.getElementById('pictRowBtnRight_'+id).style.display = '';
		}
		document.getElementById('pictRowBtnLeft_'+id).style.display = '';
	  });
}

function movePictRowLeft(id, imageWidth) {
	var pictRow = document.getElementById('pictRow_'+id);
	
	var pictRowLeft = parseInt(pictRow.style.left) + imageWidth;
	document.getElementById('pictRowBtnLeft_'+id).style.display = 'none';
	
	$('#pictRow_'+id).animate({
	    left: '+='+imageWidth
	  }, 500, function() {
		if (pictRowLeft < 0) {
			document.getElementById('pictRowBtnLeft_'+id).style.display = '';
		}
		document.getElementById('pictRowBtnRight_'+id).style.display = '';
	  });
}


function movePageGalleryRight(id, imageWidth, minX) {
	var pageGallery = document.getElementById('pageGallery_'+id);
	
	var pageGalleryLeft = parseInt(pageGallery.style.left) - imageWidth;
	
	$('#pageGallery_'+id).animate({
	    left: '-='+imageWidth
	  }, 500, function() {
	  });
}

function movePageGalleryLeft(id, imageWidth) {
	var pageGallery = document.getElementById('pageGallery_'+id);
	
	var pageGalleryLeft = parseInt(pageGallery.style.left) + imageWidth;
	
	$('#pageGallery_'+id).animate({
	    left: '+='+imageWidth
	  }, 500, function() {
	  });
}



function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var calendars = new Object();
var myCalendar;
var waitWhileLoading = false;


function calendarinfos(date, showDate) {
	this.date = date;
	this.showDate = showDate;
}


function contact(addressId) {
	myWindow = window.open("contact.php?addressId="+addressId+"&language="+currentLanguage, "ContactWindow","resizable=0,scrollbars=0,status=0,toolbar=0,width=400,height=250");
	myWindow.focus();
}

function newAjaxObject() {
	var req = null;

	try{
		req = new XMLHttpRequest();
	}
	catch (ms){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (nonms){
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed){
				req = null;
			}
		} 
	}

	if (req == null)
		alert("Error creating request object!");
		
	return req;
}

			
function hideDivs() {
	for (var i=0; i<=hideDivs.arguments.length; i++) {
		if (document.getElementById(hideDivs.arguments[i])) { 
			document.getElementById(hideDivs.arguments[i]).style.display = "none";
		}
	}
}

						

function showDate(whichDate, calendarId) {
	myCalendar.showDate = whichDate;
	getCalendar();
}


function setDate(theDate, calendarId, readableDate) {
	if (!waitWhileLoading) {
		
		if (document.getElementById("calendarLink_"+calendarId+"_"+myCalendar.date)) {
			if (document.forms[myCalendar.formName].elements[myCalendar.currentFieldName].value.substr(0,6) == myCalendar.showDate) {
				document.getElementById("calendarLink_"+calendarId+"_"+myCalendar.date).style.backgroundColor = "#ccc";
			} else {
				document.getElementById("calendarLink_"+calendarId+"_"+myCalendar.date).style.backgroundColor = "#e0e0e0";
			}
		}
		document.forms[myCalendar.formName].elements[myCalendar.currentFieldName].value = theDate;
		myCalendar.date = theDate;
		document.getElementById(myCalendar.formName+"_"+myCalendar.calendarTitle+"_link").innerHTML = readableDate;
		
		document.getElementById("calendarLink_"+calendarId+"_"+theDate).style.backgroundColor = "#666";
	}
}


function calendar(id, fromDateFieldName, untilDateFieldName, calendarTitle, calendarDivId, formName) {
	this.id					= id;
	this.fromDateFieldName 	= fromDateFieldName;
	this.untilDateFieldName = untilDateFieldName;
	this.calendarTitle		= calendarTitle;
	this.calendarDivId		= calendarDivId;
	this.formName			= formName;
	this.minDateFromToday	= 0;
	
	if (calendarTitle=='From') {
		this.date 			= document.forms[formName].elements[fromDateFieldName].value;
		this.theLimit 		= 'lowerLimit';
		this.currentFieldName = fromDateFieldName;
	} else {
		this.date 			= document.forms[formName].elements[untilDateFieldName].value;
		this.theLimit 		= 'upperLimit';
		this.currentFieldName = untilDateFieldName;
	}
	this.showDate 			= this.date.substr(0,6);
	
	this.getUrl = getAjaxCalendarUrl;
}


function getAjaxCalendarUrl() {
	var requestValues 	= "calendarId="+this.id;
	requestValues 		+= "&calendarTitle="+this.calendarTitle;
	requestValues 		+= "&theLimit="+this.theLimit;
	requestValues 		+= "&minDateFromToday="+this.minDateFromToday;
	requestValues 		+= "&rangeMin="+document.forms[this.formName].elements[this.fromDateFieldName].value;
	requestValues 		+= "&rangeMax="+document.forms[this.formName].elements[this.untilDateFieldName].value;
	requestValues 		+= "&showDate="+this.showDate;
	requestValues 		+= "&language="+shortLanguage;
	window.status = requestValues;
	return requestValues;
}


function showCalendar(id, fromDateFieldName, untilDateFieldName, calendarTitle, formName, calendarDivId) {
	myCalendar = new calendar(id, fromDateFieldName, untilDateFieldName, calendarTitle, calendarDivId, formName);
	getCalendar();
}


function getCalendar() {
	var requestValues = myCalendar.getUrl();
	waitWhileLoading = true;
	document.body.style.cursor = "wait";
	var req = newAjaxObject();
	req.open('POST', 'http://'+currentHost+'/ajaxCalendar.php', true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(requestValues);
	
	req.onreadystatechange = function() {
		switch(req.readyState) {
			case 4:
				if(req.status!=200) {
					alert("Fehler:"+req.status); 
				} else {
					jsonResult = eval('(' + req.responseText + ')');
					
					document.getElementById(myCalendar.calendarDivId).innerHTML = jsonResult["calendar"];
					document.getElementById(myCalendar.calendarDivId).style.display = "block";
					
					if (document.forms[myCalendar.formName].elements[myCalendar.currentFieldName].value) {
						tempLinkId = document.getElementById("calendarLink_"+myCalendar.id+"_"+document.forms[myCalendar.formName].elements[myCalendar.currentFieldName].value);
						if (tempLinkId) {
							tempLinkId.style.backgroundColor = "#666";
						}
					}
					waitWhileLoading = false;
					document.body.style.cursor = "auto";
					
				}
				break;
		
			default:
				return false;
				break;
		}
	};
}


function windowResized() {
	if (document.getElementById("imageGalleryCover") && document.getElementById("imageGalleryCover").style.display == "block") {
		if (document.all) {
			windowWidth = document.body.offsetWidth;
			windowHeight = document.body.offsetHeight;
		} else {
			windowWidth = window.innerWidth;
			windowHeight = window.innerHeight;
		}
		document.getElementById("imageGalleryCover").style.width = windowWidth + "px";
		document.getElementById("imageGalleryCover").style.height = windowHeight + "px";
	}
	if (userCanEditPage) {
		updateFloatingWindowPos();
	}
}

function of_initLoad() {
	window.onresize = windowResized;
	if (userCanEditPage) {
		preloadImages();
		loadEditMap();
		window.setTimeout("setEditFormFocus()", 100);
	}
	loadGoogleMapContainers();
}

function galleryImage(filename, width, height, legend) {
	this.filename 	= filename;
	this.width 		= width;
	this.height 	= height;
	this.legend 	= legend;
}

var galleryPreviousImage = "";
var galleryNextImage = "";

function showGalleryImage(pictNr) {
	galleryPreviousImage = "";
	galleryNextImage = "";
	
	document.getElementById("galleryPreviousImage").style.display 			= "none";
	document.getElementById("galleryNextImage").style.display				= "none";
	document.getElementById("galleryPreviousImageDisabled").style.display 	= "none";
	document.getElementById("galleryNextImageDisabled").style.display 		= "none";
	
	var currentPict = imagesForGallery[pictNr];
	
	document.getElementById("galleryImage").innerHTML = '<img src="images/typHuge/'+currentPict["filename"]+'" width="' + currentPict["width"] + '" height="' + currentPict["height"] + '" />';
	document.getElementById("galleryImage").style.width = currentPict["width"] + "px";
	document.getElementById("galleryImage").style.height = currentPict["height"] + "px";
	document.getElementById("galleryHeader").style.width = (currentPict["width"]-32) + "px";
	document.getElementById("galleryCloseBox").style.width = currentPict["width"] + "px";
	var galleryLegend = document.getElementById("galleryLegend");
	if (currentPict['legend'].length) {
		galleryLegend.innerHTML = currentPict['legend'];
		galleryLegend.style.width = (currentPict["width"] - 14) + "px";
		galleryLegend.style.display = '';
	} else {
		galleryLegend.style.display = 'none';
	}

	var myForm = document.forms["galleryForm"];
	
	myForm.elements["currentPict"].value = currentPict["filename"];
	myForm.elements["currentWidth"].value = currentPict["width"];
	myForm.elements["currentHeight"].value = currentPict["height"];
			
	window.status = "";
	if (pictNr>0) {
		galleryPreviousImage = pictNr-1;
		document.getElementById("galleryPreviousImage").style.display = "inline";
		var imageDummy1 = newImage("images/typHuge/"+imagesForGallery[galleryPreviousImage]["filename"]);
	} else {
		document.getElementById("galleryPreviousImageDisabled").style.display = "inline";
	}
	if ((pictNr+1)<imagesForGallery.length) {
		galleryNextImage = pictNr+1;
		document.getElementById("galleryNextImage").style.display = "inline";
		var imageDummy2 = newImage("images/typHuge/"+imagesForGallery[galleryNextImage]["filename"]);
	} else {
		document.getElementById("galleryNextImageDisabled").style.display = "inline";
	}

}

function cancelEvent(e) {
	try {
		if(!e) e = window.event;
		if(!e) e = window.Event;
		if(e) {
			e.returnValue = false;
			e.cancelBubble = true;
			e.stopPropagation();
		}
	} catch(c) {}
	return false;
}

function galleryJumpImage(which) {
	if (which=="next") {
		showGalleryImage(galleryNextImage);
	} else {
		showGalleryImage(galleryPreviousImage);
	}
}

function openGallery(pictNr) {
	if (imagesForGallery && imagesForGallery.length) {
		document.getElementById("imageGalleryCover").style.display = "block";
		document.getElementById("imageGallery").style.display = "block";
		
		var scrollPos;
		if (typeof window.pageYOffset != 'undefined') {
			scrollPos = window.pageYOffset;
		} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
			scrollPos = document.documentElement.scrollTop;
		} else if (typeof document.body != 'undefined') {
			scrollPos = document.body.scrollTop;
		}
		document.getElementById("imageGallery").style.top = scrollPos + 'px';
		
		showGalleryImage(pictNr);
		windowResized();
	}
}

function jumpOrLogin(theKey) {
	if (theKey) {
		if (typeof(logInLink)=='string') {
			window.location.href = 'http://'+currentHost+'/'+logInLink; 
		}
	} else  {
		var newWindow = window.open('http://www.screenbox.net', 'Screenbox');
		newWindow.focus();
	}
}

function enableSearchField() {
	$('#searchField').fadeIn('fast').focus();
}


function closeGallery() {
	document.getElementById("imageGalleryCover").style.display = "none";
	document.getElementById("imageGallery").style.display = "none";
}


function bannerClick(bannerId) {
	var req = newAjaxObject();
	req.open('POST', 'http://' + currentHost + '/addBannerClick.php', false);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send('bannerItemId='+bannerId);
	req.onreadystatechange = function(){};
	return true;
}

/* entschlüsselt pageAddress - E-Mails ----- */
/* ----------------------------------------- */
function UnCryptMailto(s)
{
    var n = 0;
    var r = "";
    for(var i = 0; i < s.length; i++)
    {
        n = s.charCodeAt(i);
        if(n >= 8364)
        {
            n = 128;
        }
        r += String.fromCharCode(n - 1);
    }
    return r;
}

function linkTo_UnCryptMailto(s)
{
    location.href=UnCryptMailto(s);
}
/* ----------------------------------------- */
