function NewWinForPrint(objpath)
{
	window.open(objpath, "_blank", "toolbar=no,location=no,scrollbars=yes,resizable=no,width=800,height=700,top=0,left=0");
}

function NewWinIpix(objpath)
{
	window.open(objpath, "_blank", "toolbar=no,location=no,scrollbars=auto,resizable=no,width=410,height=362,top=0,left=0");
}

function NewWinPrintformular(objpath)
{
	window.open(objpath, "_blank", "toolbar=no,location=no,scrollbars=auto,resizable=no,width=410,height=390,top=0,left=0");
}

function relocate(adr)
{
	if (adr != "")
		newWindow = window.open(adr, '_blank');
}

function relocate2(adr)
{
	if (adr != "")
		newWindow = window.open(adr, '_self');
}

function openWindow(url, width, height)
{
	winname = "popup"
	var trails = "width=" + width + ",height=" + height + ",toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no";
	newWindow = window.open(url, winname, trails)
}


function CheckFlash(minVersion)
{
	var flashVersionMajor = swfobject.getFlashPlayerVersion().major;
	if (flashVersionMajor >= minVersion)
		return true;
	else
		return false;
}

function ShowFlash(id, flashpath, name, width, height, version, bgcolor, language, offerInstall, wmode, videoPath, videoPathLarge, defaulttype, defaulturl, xml_file, thumbnailWidth, thumbnailHeight, imageHeight)
{
	var redirectUrl = null;

	if (offerInstall)
		redirectUrl = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";

	if (flashpath.indexOf("?") > -1)
		flashpath += "&withoutAttach=true";
	else
		flashpath += "?withoutAttach=true";

	var flashVars = {};
	var params = {};

	if (wmode.length > 0)
		params["wmode"] = wmode;
	else
		params["wmode"] = "transparent";

	if (language.length > 0)
		flashVars["language"] = language;

	if (videoPath.length > 0)
		flashVars["video_url"] = videoPath;

	if (videoPathLarge.length > 0)
		flashVars["video_url_large"] = videoPathLarge;

	if (defaulttype.length > 0)
		flashVars["defaulttype"] = defaulttype;

	if (defaulturl.length > 0)
		flashVars["defaulturl"] = defaulturl;

	if (xml_file.length > 0)
	{
		flashVars["xml_file"] = xml_file; //*** Testimonials ***
		flashVars["xmlurl"] = xml_file; //*** Flash PlayList ***
	}

	if (thumbnailWidth != null && thumbnailWidth.length > 0)
		flashVars["thumbnail_width"] = thumbnailWidth;

	if (thumbnailHeight != null && thumbnailHeight.length > 0)
		flashVars["thumbnail_height"] = thumbnailHeight;

	if (imageHeight != null && imageHeight.length > 0)
		flashVars["image_height"] = imageHeight;

	flashpath = flashpath.replace(/&amp;/g, "&");

	//alert(flashpath + "\r\n" + id + "\r\n" + width + "\r\n" + height + "\r\n" + version + "\r\n" + redirectUrl + "\r\n" + flashVars + "\r\n" + params);

	swfobject.embedSWF(flashpath, id, width, height, version, redirectUrl, flashVars, params);
}

function openPopup(mypage, myname, w, h, scroll, toolbar)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var d = new Date();
	mypage += "&ts=" + d.getYear() + d.getMonth() + d.getDate() + d.getHours() + d.getMinutes() + d.getSeconds() + d.getMilliseconds();
	winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable=false,toolbar=' + toolbar;
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4)
	{
		win.window.focus();
	}
}

function OpenNoMenu(url, width, height)
{
	window.open(url, 'nomenu', 'width=' + width + ',height=' + height + ',resizable=yes,copyhistory=0,top=' + (((screen.height - 600) / 2) - 50) + ',left=' + (((screen.width - 800) / 2) - 5) + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no');
	return false;
}

function sort_haendler()
{
	document.sorting.submit();
}

function edb_sort_haendler()
{
	document.selection.submit();
}

function cdb_sort_haendler()
{
	document.selection.submit();
}

function addEntries()
{
	document.entries.submit();
}

function removeEntries()
{
	document.entries.submit();
}

function removeAllEntries()
{
	document.allentries.submit();
}

function StartPositioning()
{
	try
	{
		if (window.innerHeight || document.body.clientHeight)
			document.inter = window.setInterval('SetPosition();', 10);
	}
	catch (ex)
	{
	}
}

function StopPositioning()
{
	try
	{
		window.clearInterval(document.inter);
	}
	catch (ex)
	{
	}
}

function SetPosition()
{
	try
	{
		var enddiv = document.getElementById('enddiv');
		var icondiv = document.getElementById('icondiv');
		var iconheight = document.getElementById('iconenddiv').offsetTop - document.getElementById('iconstartdiv').offsetTop;
		var calcTop = 0;

		if (window.innerHeight)
			calcTop = window.innerHeight - iconheight + window.pageYOffset - 16;
		else
			calcTop = document.body.clientHeight - iconheight + document.body.scrollTop - 16;

		if (enddiv.offsetTop < calcTop)
			icondiv.style.top = calcTop;
		else
			icondiv.style.top = enddiv.offsetTop;
	}
	catch (ex)
	{
	}
}

function PrintPage()
{
	if (self.print)
	{
		self.print();
	}
	else if ((navigator.appName.search("Microsoft") != -1) && (navigator.appVersion.search("4.0") != -1))
	{
		var OLECMDEXECOPT_PROMPTUSER = 1;
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);
		WebBrowser1.outerHTML = '';
	}
	else
	{
		alert("Ihr Browser kann leider nicht automatisch drucken. Bitte benutzen Sie STRG + P")
	}
}

function CheckFormItem(formName, elementName, elementValue, conditionElement)
{
	if (document.forms[formName] != null && document.forms[formName].elements[elementName] != null)
	{
		if (conditionElement == null || (document.forms[formName].elements[conditionElement] != null && document.forms[formName].elements[conditionElement].value != ""))
		{
			for (var i = 0; i < document.forms[formName].elements[elementName].length; i++)
			{
				if (elementValue == null || elementValue == document.forms[formName].elements[elementName][i].value)
					document.forms[formName].elements[elementName][i].checked = true;
			}
		}
	}
}

function ShowSpecialPopup()
{
	var divText = document.getElementById("specialpopup");
	if (divText != null)
	{
		var index = document.cookie.indexOf("specialpopup=");
		if (index >= 0)
			divText.style.display = "none";
	}
}

function mobileServiceCheckFieldsIn()
{
	var compulsoryFieldsIn = new Array();
	compulsoryFieldsIn[0] = 'stdIn0';
	compulsoryFieldsIn[1] = 'stdIn1';
	compulsoryFieldsIn[2] = 'stdIn3';
	compulsoryFieldsIn[3] = 'stdIn18';
	compulsoryFieldsIn[4] = 'extIn4';

	var checkOK = true;

	for (var i = 0; i < compulsoryFieldsIn.length; i++)
	{
		var cfObj = document.getElementById(compulsoryFieldsIn[i]);
		if (cfObj != null)
		{
			if (cfObj.type.toLowerCase() == 'text')
			{
				if (cfObj.value.match(/^\s*$/)) checkOK = false;
			}
			else if (cfObj.type.toLowerCase() == 'radio' || cfObj.type.toLowerCase() == 'checkbox')
			{
				var tmpObj = document.getElementsByName(cfObj.name);
				var tmpCheck = false;
				for (var j = 0; j < tmpObj.length; j++)
				{
					if (tmpObj[j].checked == true)
					{
						tmpCheck = true;
						break;
					}
				}
				checkOK = tmpCheck;
			}
			else if (cfObj.type.toLowerCase().indexOf('select') >= 0)
			{
				if (compulsoryFieldsIn[i] == 'stdIn12' && cfObj.selectedIndex == 0)
					checkOK = false;
			}
		}

		if (!checkOK)
			break;
	}

	if (checkOK)
		document.getElementById('subscribe').submit();
	else
		window.alert("Bitte fuellen Sie alle mit einem * markierten Felder aus.");
}

function mobileServiceCheckFieldsOut()
{
	var checkOK = true;
	if (document.getElementById('stdOut3').value.match(/^\s*$/))
		checkOK = false;

	if (checkOK)
		document.getElementById('unsubscribe').submit();
	else
		window.alert('Bitte fuellen Sie das E-Mail Feld aus.');
}

function showBlock(id)
{
	var elem = document.getElementById(id);
	if (elem != null)
	{
		elem.style.display = "block";
	}
}

function showInline(id)
{
	var elem = document.getElementById(id);
	if (elem != null)
	{
		elem.style.display = "inline";
	}
}

function showNone(id)
{
	var elem = document.getElementById(id);
	if (elem != null)
	{
		elem.style.display = "none";
	}
}

function onLoad1()
{
	showInline('showbackbutton');
	showInline('showbackbuttonTop');
}

function onLoad2()
{
	showInline('showbackbutton');
	showInline('showbackbuttonTop');
}

function onLoad3()
{
	showInline('showbackbutton');
	showInline('showbackbuttonTop');
}

function ZoomImageShow(containerDivID, imageDivID, zoomuri, title, subtitle)
{
	var divContainer = document.getElementById(containerDivID)
	var divImage = document.getElementById(imageDivID)

	if (divContainer == null || divImage == null)
	{
		//alert("<div> \"" + containerDivID + "\" oder \"" + imageDivID + " nicht gefunden ");
		return;
	}

	divImage.innerHTML = "";

	var zoomImageElem = document.createElement("img");
	zoomImageElem.setAttribute("src", zoomuri);
	zoomImageElem.setAttribute("alt", title);
	var zoomImageSubtitle = document.getElementById("ZoomImageSubtitle");
	zoomImageSubtitle.innerHTML = subtitle;

	divImage.appendChild(zoomImageElem);

	divContainer.style.display = "block";
}

function ZoomImageHide(containerDivID)
{
	var divContainer = document.getElementById(containerDivID)

	if (divContainer == null)
		return;

	divContainer.style.display = "none";
}

function cp_CheckAll(nameForm, nameCheckbox, checked)
{
	for (var i = 0; i < document.forms[nameForm].elements.length; i++)
	{
		var elem = document.forms[nameForm].elements[i];
		if (elem.name == nameCheckbox)
		{
			elem.checked = checked;
		}
	}
}

function doubleConfirm(message1, message2)
{
	var ok = confirm(message1);
	if (ok)
	{
		ok = confirm(message2);
	}

	return ok;
}

function RotateImages(imageID, imageNumber, timerMilliSeconds, arrayVariable)
{
	var image = document.getElementById(imageID);
	if (image != null)
	{
		eval("var imageArray = " + arrayVariable);

		if (imageNumber >= imageArray.length)
		{
			imageNumber = 0;
		}

		//alert(imageNumber + "\r\n" + imageArray[imageNumber].replace(/&amp;/g, "&"));

		image.src = imageArray[imageNumber].replace(/&amp;/g, "&");
		imageNumber++;

		window.setTimeout("RotateImages('" + imageID + "', " + imageNumber + ", " + timerMilliSeconds + ", '" + arrayVariable + "')", timerMilliSeconds);
	}
}

//*** Erzeugt eine Zufallsganzzahl, min & max sind als Werte möglich ***
function RandomNumber(min, max)
{
	return Math.floor(Math.random() * (max - min + 1)) + min;
}


function conferenceroomSeating()
{
	xOffset = 10;
	yOffset = 30;

	$(".seating-jquery").hover(function (e)
	{
		var id = $(this).attr("id");
		$("#" + id + "-tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");

	}, function (e)
	{
		var id = $(this).attr("id");
		$("#" + id + "-tooltip").fadeOut('fast');
	});
}


//*** EventLocation (evtLoc) - Google Maps API ***

var evtLocMarkerList = [];
var evtLocMap = null;
var evtLocGc = null;
var evtLocLastCharCode = "A".charCodeAt(0) - 1;
var evtLocImages = null;
var evtInfoWindow = null;

function evtLocInitialize(id, imagesArray)
{
	evtLocImages = imagesArray;
	//Initialize map
	evtLocMap = new google.maps.Map(document.getElementById(id), {
		zoom: 8,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.DEFAULT
		}
	});


	evtInfoWindow = new google.maps.InfoWindow();
	google.maps.event.addListener(evtLocMap, 'click', function ()
	{
		evtInfoWindow.close();
	});

	//Initialize geocoder (resolv latlng from address)
	evtLocGc = new google.maps.Geocoder();
}

function evtLocGetNextLetter()
{
	evtLocLastCharCode++;
	return String.fromCharCode(evtLocLastCharCode);
}

function evtLocTriggerDomReady()
{
	//Get all addresses from hidden address containers
	$(".EvtLocAddressContainer").each(function (index, item)
	{
		//Check whether it can be a valid address
		var name = $('.LocationName a', $(item).parent().parent()).html();
		var address = $(item).html();
		var parts = address.split(',');
		if (parts[0].length > 3 && parts[1].length > 3)
		{
			evtLocAddAddress(address + ", Deutschland", item, name);
		}
	});
}

//Zooms to the given letter in the map
function evtLocSetCenter(letter)
{
	for (var i = 0; i < evtLocMarkerList.length; i++)
	{
		if (evtLocMarkerList[i].letter == letter)
		{
			if (evtLocMarkerList[i].marker != null)
			{
				evtLocMap.setCenter(evtLocMarkerList[i].marker.position);
				evtLocMap.setZoom(14);
				evtInfoWindow.close();
				window.location.href = "#map";
			} else
			{
				evtLocFitToBounds();
			}
			break;
		}
	}
}

function evtLocAddAddress(address, element, name)
{
	var markerOk = true;
	var myIndex = evtLocMarkerList.length;
	evtLocMarkerList.push({ marker: null, address: address, letter: "", name: name });

	var markerFound = null;
	for (var i = 0; i < myIndex; i++)
	{
		if (evtLocMarkerList[i].address == address)
		{
			markerFound = evtLocMarkerList[i];
			break;
		}
	}

	if (markerFound != null)
	{
		evtLocMarkerList[myIndex].letter = markerFound.letter;
		evtLocMarkerList[myIndex].marker = markerFound.marker;
		var px = (evtLocMarkerList[myIndex].letter.charCodeAt(0) - "A".charCodeAt(0)) * 27;
		$(element).parent().html('<div onclick="javascript:evtLocSetCenter(\'' + evtLocMarkerList[myIndex].letter + '\')" style="cursor: pointer; margin-top: -3px; width: 44px; height: 27px; background-image: url(\'' + evtLocImages["sprite"] + '\'); background-position: 0px -' + px + 'px;"></div>');
	} else
	{
		evtLocMarkerList[myIndex].letter = evtLocGetNextLetter();
		// GECODE and MARK IT
		evtLocGc.geocode({ address: address }, function (result, status)
		{
			if (status == "OK")
			{
				evtLocMarkerList[myIndex].marker = new google.maps.Marker({
					position: new google.maps.LatLng(result[0].geometry.location.lat(), result[0].geometry.location.lng()),
					map: evtLocMap,
					icon: new google.maps.MarkerImage(evtLocImages[evtLocMarkerList[myIndex].letter.toLowerCase()].replace(/&amp;/g, '&'), null, null, new google.maps.Point(19, 58)),
					shadow: new google.maps.MarkerImage(evtLocImages['shadow'].replace(/&amp;/g, '&'), null, null, new google.maps.Point(8, 20))
				});

				var onMarkerClick = function ()
				{
					var marker = this;
					var latLng = marker.getPosition();
					evtInfoWindow.setContent('<b>' + name + '</b><br />' + address.replace(', Deutschland', '').replace(/,/g, '<br />'));
					evtInfoWindow.open(evtLocMap, marker);
				};
				google.maps.event.addListener(evtLocMarkerList[myIndex].marker, 'click', onMarkerClick);

				var px = (evtLocMarkerList[myIndex].letter.charCodeAt(0) - "A".charCodeAt(0)) * 27;
				$(element).parent().html('<div onclick="javascript:evtLocSetCenter(\'' + evtLocMarkerList[myIndex].letter + '\')" style="cursor: pointer; margin-top: -3px; width: 44px; height: 27px; background-image: url(\'' + evtLocImages["sprite"] + '\'); background-position: 0px -' + px + 'px;"></div>');
			} else
			{
				evtLocGetPrevLetter();
				markerOk = false;
			}
			evtLocFitToBounds();
		});
	}
}

function evtLocFitToBounds()
{
	if (evtLocMarkerList.length == 1)
	{
		evtLocSetCenter(evtLocMarkerList[0].letter);
	} else
	{
		var bounds = new google.maps.LatLngBounds();
		for (var i = 0; i < evtLocMarkerList.length; i++)
		{
			var marker = evtLocMarkerList[i].marker;
			if (marker != null)
			{
				bounds.extend(marker.getPosition());
			}
		}
		evtLocMap.fitBounds(bounds);
	}
}

function setCookie(c_name, value, exdays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name)
{
	var i, x, y, ARRcookies = document.cookie.split(";");
	for (i = 0; i < ARRcookies.length; i++)
	{
		x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
		x = x.replace(/^\s+|\s+$/g, "");
		if (x == c_name)
		{
			return unescape(y);
		}
	}
}

/***************************
Check Meta
****************************/
function doMetaCheck(checkLength)
{
	$(document).ready(function ()
	{
		var ref = window.location.href;
		var showMetaAnyway = false;
		if (ref.indexOf("?showmeta") > -1 || ref.indexOf("&showmeta") > -1)
			showMetaAnyway = true;

		var metadescription = $("meta[name='description']").attr("content");
		var descriptionLength = metadescription.length;

		if (checkLength && (descriptionLength < 50 || descriptionLength > 160))
			alert("Achtung! MetaDescription:\n\"" + metadescription + "\"\nzu kurz/lang (" + desclength + " Zeichen).\n\nBitte 25-250 Zeichen pflegen.");
		else if (showMetaAnyway)
			alert("MetaDescription:\n\"" + metadescription + "\"");
	});
}
