function jump() {
	if (location.href.search(/#termine/) > 0) location.href='#termine';
}

function showWait() {
	document.getElementById('wait').style.visibility = 'visible';
}

function getURL(wert) {
	window.location = wert;
}

/**************************************************/
/* DIV-Layer Switch für Regionsinfos und Portalbeschreibungen - Anfang */
/**************************************************/

function switchRegionsinfos(mode) {
	if (mode) {
		document.getElementById("angebote").style.display = "none";
		document.getElementById("regionsinfos").style.display = "block";
	} else {
		document.getElementById("angebote").style.display = "block";
		document.getElementById("regionsinfos").style.display = "none";
	}
}
	
/**************************************************/
/* DIV-Layer Switch für Regionsinfos und Portalbeschreibungen - Ende */
/**************************************************/

function showFlightWait() {
	window.scrollTo(0, 0);
	$('waiting-div-placeholder').innerHTML = $('waiting-div').innerHTML;
	$('waiting-div').innerHTML = "";
	$('flug-wait').style.visibility = "visible";
	$('left').style.display = "none";
}

function detectBrowserType() {
	if(document.ids) x='netscape';
	else if( document.all && !document.getElementById ) x='ie';
	else if( window.opera && !document.createElement ) x='opera';
	else if( window.opera && window.getComputedStyle )  {
			  if(document.createRange) x='opera';
				else if(window.navigate) x='opera';
								 else x='opera';                   }
	else if( window.opera && document.compatMode ) x='opera';
	else if( window.opera && document.releaseEvents ) x='opera';
	else if( document.contains && !window.opera ) x='konqueror';
	else if(window.pkcs11&&window.XML) x='firefox';
	else if( window.getSelection && window.atob ) x='netscape';
	else if( window.getSelection && !document.compatMode ) x='netscape';
	else if( window.clipboardData && document.compatMode ) x='ie';
	else if( window.clipboardData ) x='ie';
	else if( document.getElementById && !document.all ) x='opera';
	else if( document.images && !document.all ) x='netscape';
	else if(document.clientWidth&&!window.RegExp) x='konqueror';
	else x='???';
	
	return x;
}

/**************************************************/
/* DIV-Layer Switch für Regionsinfos und Portalbeschreibungen - Ende */
/**************************************************/

function showOrte(textOpen, textClose) {
	if (document.getElementById("filter-orte").style.display == "none") {
		Effect.BlindDown('filter-orte', {duration: 0.4});
		document.getElementById("filter-orte-switch").className = "detail-open";
		document.getElementById("filter-orte-switch").innerHTML = textClose;
	} else {
		Effect.BlindUp('filter-orte', {duration: 0.4});
		document.getElementById("filter-orte-switch").className = "detail-closed";
		document.getElementById("filter-orte-switch").innerHTML = textOpen;
	}
}

/**************************************************/
/* Damit Formulare nicht mit Enter abgeschickt werden können */
/**************************************************/

function sendForm(form) {
	form.onsubmit = function() {};
	form.submit();
}

/**************************************************/
/* Anzeigen des Feldes für einen Aktion-Code */
/**************************************************/
function showActionCode(show) {
	loginMod = document.getElementById("login-mod");
	registerMod = document.getElementById("register-mod");
	
	if (show) {
		var elems = document.getElementsByTagName("tr");
		var laenge = elems.length;
		for(var i = 0; i < laenge; i++) {
			var elem = elems[i];
			if (elem.className.indexOf("coins-coupon-tr") != -1) {
				if (ow_isIE()) elem.style.display = 'block';
				else elem.style.display = 'table-row';
			}
		}
		document.getElementById("coins-coupon-link").href = "javascript:showActionCode(false)";
		document.getElementById("coins-coupon-link").innerHTML = "Keinen Aktions-Code verwenden";
		document.getElementById("coins-coupon-active").value = 1;
	} else {
		var elems = document.getElementsByTagName("tr");
		var laenge = elems.length;
		for(var i = 0; i < laenge; i++) {
			var elem = elems[i];
			if (elem.className.indexOf("coins-coupon-tr") != -1) elem.style.display = 'none';
		}
		document.getElementById("coins-coupon-link").href = "javascript:showActionCode(true)";
		document.getElementById("coins-coupon-link").innerHTML = "Aktions-Code eingeben";
		document.getElementById("coins-coupon-active").value = 0;
	}
	
	if (loginMod != undefined) loginMod.style.height = (registerMod.offsetHeight - 1) + "px";
}

/**************************************************/
/* Anzeigen der erweiterten Registrierung */
/**************************************************/
function showFullRegistrationForm(show) {
	loginMod = document.getElementById("login-mod");
	registerMod = document.getElementById("register-mod");
	
	if (show) {
		var elems = document.getElementsByTagName("tr");
		var laenge = elems.length;
		for(var i = 0; i < laenge; i++) {
			var elem = elems[i];
			if(elem.className == "register-full-form-tr") {
				if (ow_isIE()) elem.style.display = 'block';
				else elem.style.display = 'table-row';
			}
		}
		document.getElementById("register-full-form-link").href = "javascript:showFullRegistrationForm(false)";
		document.getElementById("register-full-form-link").innerHTML = "Schnelle Registrierung";
		document.getElementById("full-registration").value = 1;
	} else {
		var elems = document.getElementsByTagName("tr");
		var laenge = elems.length;
		for(var i = 0; i < laenge; i++) {
			var elem = elems[i];
			if(elem.className == "register-full-form-tr") elem.style.display = 'none';
		}
		document.getElementById("register-full-form-link").href = "javascript:showFullRegistrationForm(true)";
		document.getElementById("register-full-form-link").innerHTML = "Erweiterte Registrierung";
		document.getElementById("full-registration").value = 0;
	}
	
	if (loginMod != undefined) loginMod.style.height = (registerMod.offsetHeight - 1) + "px";
}

addListener = function(oNode, sEventType, fnCallback) {
	if(document.addEventListener) {
		oNode.addEventListener(sEventType, function(oEvent) {
			fnCallback(oEvent);
		}, false);
	} else if(document.attachEvent) {
		oNode.attachEvent("on" + sEventType, function() {
			fnCallback();
		});
	}
}

function refreshLoginRegisterModules() {
	loginMod = document.getElementById("login-mod");
	registerMod = document.getElementById("register-mod");
	if (loginMod != undefined) loginMod.style.height = (registerMod.offsetHeight - 1) + "px";
}

addListener(window, 'load', refreshLoginRegisterModules); 

/**************************************************/
/* Anzeigen aller Kommentare */
/**************************************************/
function showAllComments(show) {
	var elems = document.getElementsByTagName("tr");
	var laenge = elems.length;
	for(var i = 0; i < laenge; i++) {
		var elem = elems[i];
		if(elem.className == "other-comment") {
			if (show) {
				if (ow_isIE()) elem.style.display = 'block';
				else elem.style.display = 'table-row';
			} else {
				elem.style.display = 'none';
			}
		}
	}
	
	document.getElementById("show-all-comments").style.display = "none";
}

var dom = false, ie = false;
var lastFocus;

function focusInit(f) {
	if (f.addEventListener) {
		dom = true;
		f.addEventListener("focus", CheckFocus, true);
	} else if(f.attachEvent) {
		ie=true;
		els = f.getElementsByTagName("input");
		for(i=0; i<els.length; i++) {
			els[i].attachEvent("onfocus", CheckFocus);
		}
	}
}

function CheckFocus(event) {
	if(dom) lastFocus = event.target;
	else if(ie) lastFocus = event.srcElement;
}

// Keycode
var keycode;

/**************************************************/
/* Hoteldetails aufklappen */
/**************************************************/
function showHotelDetail(hotel, ref, id, getHotelData) {
	if ($("hoteldetail" + hotel)._isOpen == null) {
//		document.getElementById("hoteldetail" + hotel).style.display = "";
		
		document.getElementById("a-detail" + hotel).className = "detail-open";
		
		$("hoteldetail" + hotel).makeClipping();
		$("hoteldetail" + hotel).style.padding = '0px';
		
		if (!getHotelData) {
			$("hoteldetail" + hotel).style.display = "";
			Effect.BlindDown("hoteldetailInner" + hotel, {duration: 0.3, afterUpdate: function(effect) {
					effect.element.setStyle({display: 'block'});
				}});
		} else {
			new Ajax.Updater(id, '/getHotelText.php?ref=' + escape(ref) + '&sid=' + Math.random(), {method: 'post', onComplete: function() {
				$("hoteldetail" + hotel).style.display = "";
				
				Effect.BlindDown("hoteldetailInner" + hotel, {duration: 0.3, afterUpdate: function(effect) {
						effect.element.setStyle({display: 'block'});
					}});
			}});
		}
		
		$("hoteldetail" + hotel)._isOpen = true;
	} else {
		document.getElementById("a-detail" + hotel).className = "detail-closed";
		
		Effect.BlindUp("hoteldetailInner" + hotel, {duration: 0.3, afterFinish: function(effect) {
				document.getElementById("hoteldetail" + hotel).style.display = "none";
			}});
		
		$("hoteldetail" + hotel)._isOpen = null;
	}
}

/**************************************************/
/* Autocompletion der Hotels bzw. Regionen */
/**************************************************/
AjaxCurrentRequests = {};

function searchRegion(hotel) {
	if (keycode >= 37 && keycode <=40) return false;
	
	Ajax.Responders.register({
		onCreate: function(request) {
			if (request.options.onlyLatestOfClass && AjaxCurrentRequests[request.options.onlyLatestOfClass]) {
				// if a request of this class is already in progress, attempt to abort it before launching this new request
				try { AjaxCurrentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}
			}
			// keep note of this request object so we can cancel it if superceded
			AjaxCurrentRequests[request.options.onlyLatestOfClass] = request;
		},
		onComplete: function(request) {
			if (request.options.onlyLatestOfClass) {
				// remove the request from our cache once completed so it can be garbage collected
				AjaxCurrentRequests[request.options.onlyLatestOfClass] = null;
			}
		}
	});
	
	document.getElementById("loading").style.display = "inline";
	
	new Ajax.Updater('regions', '/getRegions.php', {
		method: 'post',
		parameters: {q: document.getElementsByName('regionSearch')[0].value, h: hotel, sid: Math.random()},
		onComplete: function(transport, param) {
			if (document.getElementById("regions").style.display != 'block') {
				document.getElementById("regions").style.display = 'none'
				
				Effect.BlindDown('regions', {duration: 0.3, afterUpdate: function (effect) {effect.element.style.display = 'block';}});
			}
			
			document.getElementById("loading").style.display = "none";
		},
		onlyLatestOfClass: true
	});

	setRegion("", 0);
}

function selectRegion(region, regionType, regionId) {
	document.getElementsByName('regionSearch')[0].value = region;
	setRegion(regionType, regionId);
	Effect.BlindUp('regions', {duration: 0.3});
}

var windows = {};

function openMessageForm(user, tpl) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 390, zIndex: 100, resizable: false, title: "Nachricht schreiben", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=messages&user=' + escape(user) + '&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openInvitationForm(user, tpl) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 345, zIndex: 100, resizable: false, title: "Benutzer einladen", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=invitation&user=' + escape(user) + '&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openLoginForm(tpl, fName) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 345, zIndex: 100, resizable: false, title: "Login", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=user&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId + '&f=' + fName, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openWeatherForecast(id, city, tpl) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 613, height: 305, zIndex: 100, resizable: false, title: "Wettervorhersage f&uuml;r " + city, showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=weather&id=' + id + '&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openRaffleForm(raffleCode, tpl, participationText, alreadyParticipatedText) {
	if (!$('agb').checked) {
		alert("Bitte bestätigen sie zuerst die AGBs!");
		return;
	}
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 345, zIndex: 100, resizable: false, title: "Gewinnspiel", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=raffle&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId + '&raffleCode=' + raffleCode + '&participationText=' + participationText + '&alreadyParticipatedText=' + alreadyParticipatedText, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openCommentForm(tpl, contentType, contentId) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 345, zIndex: 100, resizable: false, title: "Bewertung", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=comments&contentType=' + escape(contentType) + '&contentId=' + contentId + '&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function openAbuseForm(tpl) {
	Windows.overlayShowEffectOptions = {duration: 0};
	Windows.overlayHideEffectOptions = {duration: 0.2};
	
	win = new Window({className: "window", width: 530, height: 345, zIndex: 100, resizable: false, title: "Bewertung", showEffect: Element.show, hideEffect: Effect.BlindUp, hideEffectOptions: {duration: 0.4}, draggable: true, wiredDrag: false, destroyOnClose: true, recenterAuto: false, onShow: function(winTemp) {
			winIdTemp = winTemp.getId();
			if (windows[winIdTemp].oT != null) winTemp.setLocation(windows[winIdTemp].oT, windows[winIdTemp].oL);
		}});
	
	winId = win.getId();
	windowNumber = windows.length;
	
	windows[winId] = win;
	
	windows[winId].oL = null;
	windows[winId].oT = null;
	
	win.setAjaxContent('/ajax/procs/index.php?action=abuse&url=' + escape(location.href) + '&tpl=' + tpl + '&tid=' + portalId + '&winId=' + winId, {method: 'post', onCreate: function(transport) {
			win.setHTMLContent('<div class="window-content">Lade...</div>');
			win.showCenter(false)}
		}, true, false);
	
	win.windowNumber = windowNumber;
}

function closeWindow(winId) {
	Windows.close(winId);
	return false;
}

function sendRequest(winId, wysiwygField, action, mode) {
	windows[winId].oL = $(winId).offsetLeft;
	windows[winId].oT = $(winId).offsetTop;
	
	Element.extend($(winId).getElementsByTagName('form')[0]);
	
	if (wysiwygField != "") {
		FCK = $(wysiwygField + '___Frame').contentWindow.FCK;
		FCK.UpdateLinkedField();
	}
	
	windows[winId].setAjaxContent('/ajax/procs/index.php?action=' + action + '&mode=' + mode + '&tid=' + portalId + '&' + $(winId).getElementsByTagName('form')[0].serialize(), {method: 'post'}, false, false);
}

// Bilder in den WYSIWYG-Editor einfügen
function editorInsertImage(field, url, align) {
	FCK = $(field + '___Frame').contentWindow.FCK;
	oImage = FCK.CreateElement('IMG');
	oImage.src = url;
	if (align != "") {
		oImage.align = align;
		oImage.className = "a-" + align;
	}
}

function updateUserStatus(tpl) {
	updateUserInfo(tpl);
	
	if ($('m-user') != undefined) $('m-user').style.display = "none";
	
	try {
		refreshNotepad(tpl);
		refreshOffers(tpl, offerUrl);
	} catch(e) {}
}

function updateUserInfo(tpl) {
	new Ajax.Updater('user-status', '/ajax/procs/index.php?action=user&mode=userStatus&tpl=' + tpl + '&tid=' + portalId, {
			onComplete: function() {
					$('user-status').className = "user-status-complete";
				}
		});
}

function refreshOffers(tpl, url) {
	if ($('offers-div')) {
		var newDate = new Date;
		new Ajax.Updater('offers-div', '/ajax/procs/index.php?action=offers&url=' + url + '&tpl=' + tpl + '&tid=' + portalId + '&sid=' + newDate.getTime(), {evalScripts: true});
	}
}

function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function mapLoggedIn() {
	getMovie("map2").userLoggedIn();
}

/* flight */
function getSelectValue(obj) {
	with (obj) return options[selectedIndex].value;
}

function refreshFlightData() {
	var rp = flightPrice;
	
	// TCI
	if ($('tci') != undefined) {
		showHideRows("tci-row", $('tci').checked);
		if ($('tci').checked) rp += parseFloat(ptci);
	}

	// CC
	if (getSelectValue($('payment')).indexOf("CC_") != -1) ccSelected = true;
	else ccSelected = false;
	showHideRows("cc-row", ccSelected);
	if (ccSelected) {
		rp += parseFloat(creditCardCost);
		$('payment-owner').innerHTML = "Kreditkartenhalter";
		$('payment-type').innerHTML = "Kreditkartennummer";
	} else {
		$('payment-owner').innerHTML = "Kontoinhaber";
		$('payment-type').innerHTML = "Kontonummer";
	}

	// Tickets
	var delivery = getSelectValue($('delivery'));
	var ticketPrice = 0;
	if (tickets[delivery]["type"] == "PAX") ticketPrice = paxCount * tickets[delivery]["price"];
	else ticketPrice = tickets[delivery]["price"];
	$('ticket-price').innerHTML = ticketPrice;
	rp += parseFloat(ticketPrice);
	
	$('sum-price-span').innerHTML = rp;
	$('pd').value = rp;
}

function showHideRows(className, show) {
	var elems = document.getElementsByTagName("tr");
	var laenge = elems.length;
	for(var i = 0; i < laenge; i++) {
		var elem = elems[i];
		if(elem.className.indexOf(className) != -1) {
			if (show) {
				if (ow_isIE()) elem.style.display = 'block';
				else elem.style.display = 'table-row';
			} else {
				elem.style.display = 'none';
			}
		}
	}
}

function ajaxRateContent(rating, winId) {
	for(i=1; i<=6; i++) {
		if (i <= rating) className = 'rated';
		else className = 'unrated';
		
		$('rating' + i + '-' + winId).className = className;
	}

	$('rating-' + winId).value = rating;
}

function ajaxRateContentMouseOver(rating, winId) {
	for(i=1; i<=6; i++) {
		if (i <= rating) className = 'rated-mouse';
		else className = 'unrated-mouse';
		
		$('rating' + i + '-' + winId).className = className;
	}
}

function ajaxRateContentMouseOut(winId) {
	for(i=1; i<=6; i++) {
		if (i <= $('rating-' + winId).value) className = 'rated';
		else className = 'unrated';
		
		$('rating' + i + '-' + winId).className = className;
	}
}

function setCharCount(textarea, id, maxCount) {
		$(id).innerHTML = maxCount - textarea.value.length;
}

function getPosition(obj) {
	var pos = { x:0, y:0 };
	
	do {
		pos.x += obj.offsetLeft;
		pos.y += obj.offsetTop;
	} while (obj = obj.offsetParent);
	
	return pos;
}

function showInMap(g) {
	getMovie("map2").loadXML(g, true);
}

function openFullscreenSlideshow(id) {
	window.open('/popups/slideshow.php?id=' + id, '', 'fullscreen=yes,scrollbars=no,resizable=yes,statusbar=no');
}

/* navigation */
var hideNavigation = new Array();
var navigationContent = new Array();

function showMenu(menu, dynamic, module) {
	if (!dynamic) { // || $('mainnav' + menu + '-inner').innerHTML != ""
		showMenu2(menu);
	} else {
		if (navigationContent[menu] == null) {
			navigationContent[menu] = true;
			var url = '/ajax/procs/index.php?action=Menu&module=' + module + '&menu=' + menu;
			new Ajax.Request(url, {
				method: 'get',
				onSuccess: function(transport) {
					if (transport.responseText != "") {
						var mainnav = document.createElement('div');
						mainnav.className = "mainnav";
						mainnav.setAttribute('id', 'mainnav' + menu);
						
						var mainnavInner = document.createElement('div');
						mainnavInner.className = "inner";
						mainnavInner.setAttribute('id', 'mainnav' + menu + '-inner');
						
						$('main-content').appendChild(mainnav);
						$('mainnav' + menu).appendChild(mainnavInner);
						
						$('mainnav' + menu).style.display = "none";
						
						$('mainnav' + menu + '-inner').innerHTML = transport.responseText;
						
						Event.observe('mainnav' + menu, 'mouseover', function() {
							showMenu(menu, true, module);
						});
						
						Event.observe('mainnav' + menu, 'mouseout', function() {
							hideMenu(menu);
						});
						
						showMenu2(menu);
					}
				}
			}); 
		} else {
			showMenu2(menu);
		}
	}
}

function showMenu2(menu) {
	clearTimeout(hideNavigation[menu]);
	positionMenus();
	hideAllOther(menu);

	if (document.getElementById("mainnav" + menu) != null) {
//		if (document.getElementById("mainnav" + menu).style.visibility != "visible" & document.getElementById("mainnav" + menu).innerHTML != "") Effect.BlindDown("mainnav" + menu, {duration: 0.3});
		document.getElementById("mainnav" + menu).style.display = "block";
		document.getElementById("mainnav" + menu).style.visibility = "visible";
	}
}

function hideMenu(menu) {
	hideNavigation[menu] = setTimeout("reallyHideMenu(" + menu + ")", 300);
}

function reallyHideMenu(menu) {
	if (document.getElementById("mainnav" + menu) != null) {
		document.getElementById("mainnav" + menu).style.visibility = "hidden";
//		if (window.Effect) Effect.BlindUp("mainnav" + menu, {duration: 0});
	}
}

function hideAllOther(menu) {
	for(i=0; i<menucount; i++) {
		if (i != menu & document.getElementById("mainnav" + i) != null) {
			document.getElementById("mainnav" + i).style.visibility = "hidden";
//			if (window.Effect) Effect.BlindUp("mainnav" + i, {duration: 0});
		}
	}
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function scrollElementToViewport(id, f, offset) {
	var vp = $(id).viewportOffset();
	var pos = $(id).cumulativeOffset();
	var viewportHeight = document.viewport.getHeight();
	var dim = $(id).getDimensions();
	
	if (dim.height > viewportHeight) new Effect.ScrollTo(id, {duration: 0.4});
	else if (vp.top + f * dim.height > viewportHeight) new Effect.ScrollTo(id, {offset: -(pos.top - (pos.top - viewportHeight) - f * dim.height) + offset, duration: 0.4});
}
