var fixedDialouges = Array ();
var quicklistLoaded = false;

var formTips = {
	"easySearchForm":
	{
		"postalcode": "Geben Sie hier die Postleitzahl oder den Ortsnamen an, in dessen Nähe Sie eine Location für Ihre Tagung suchen.",
		"range": "Wählen Sie hier die maximale Reichweite aus, die die Location vom Suchort entfernt sein soll.",
		"countrycode": "Wählen Sie, in welchem Land Sie nach Tagungshotels suchen."
	},
	"extendedSearchForm":
	{
		"postalcode": "Geben Sie hier die Postleitzahl oder den Ortsnamen an, in dessen Nähe Sie eine Location für Ihre Tagung suchen.",
		"range": "Wählen Sie hier die maximale Reichweite aus, die die Location vom Suchort entfernt sein soll.",
		"countrycode": "Wählen Sie, in welchem Land Sie nach Tagungshotels suchen."
	},
	"hotelAccountInformationForm":
	{
		"hotelname": "Geben Sie hier den Namen Ihres Hotels ein<br />(Beispiel: &quot;Waldhotel am Weiher&quot;)",
		"userEmail": "Bitte geben Sie in diesem Feld die E-Mailadresse an, unter der wir Ihren technischen Kontakt erreichen.",
		"userPassword": "Geben Sie in diesem Feld ein Kennwort mit mindestens 6 Zeichen ein"
	},
	"userAccountInformationForm":
	{
		"userLogin": "Bitte geben Sie einen Namen ein, unter dem Ihr Benutzerkonto geführt werden soll, unter diesem Namen können Sie sich nach Aktivierung Ihres Kontos im System anmelden.",
		"userEmail": "Bitte geben Sie in diesem Feld die E-Mailadresse für Ihr Benutzerkonto an.",
		"userPassword": "Geben Sie in diesem Feld ein Kennwort mit mindestens 6 Zeichen ein"
	},
	"myHotel_handleBasedata":
	{
		"ratebb_price": "Geben Sie bitte den Preis für eine Übernachtung im Einzelzimmer inkl. Frühstück ein"
	}
};

	
	function saveUserQuicklist ()
	{
		$.ajax({
			url: "/ajaxrequest/saveUserQuicklist?isAjaxRequest=1",
			dataType: "json", 
			success: function(data) 
			{
				$.growlUI(data.dialougeCaption, data.dialougeText);
				
				//window[data.callback] (data.ammount);
				//return false;
			}
		});
	}

function blockAjaxButton (linkElement)
{
	var buttonToBlock = $(linkElement).parents("div");
	
	var blockElement = hCreateNewElement ("div", {"class": "ajaxBlockButton", "id": "block_" + $(linkElement).attr ("id")});
	$("#frame").append (blockElement);
	
	var elementPosition = $(buttonToBlock).position ();
	var leftPosition = elementPosition.left;
	var topPosition = elementPosition.top;
	if ($(buttonToBlock).css ("margin-top") != "auto")
	{
		topPosition += parseInt ($(buttonToBlock).css ("margin-top").replace ("px", ""));
	}
	
	var elementWidth = $(buttonToBlock).width ();
	var elementHeight = $(buttonToBlock).height ();
	
	$(blockElement).css ({
		"opacity": 0.5,
		"left": leftPosition + "px",
		"top": topPosition + "px",
		"width": elementWidth + "px",
		"height": elementHeight + "px"
	});
	
	return blockElement;
}

function unblockAjaxButton (linkElement)
{
	$("#block_" + $(linkElement).attr ("id")).remove ();
}

function openRegion (regionId)
{
	$.ajax({
		url: '/view/regions/plz-bereich-' + regionId + '.html',
		success: function(data) 
		{
			var boxObject = fixedDialouges["regionBox"];
	
			boxObject.setCaption ("Postleitzahlenbereich " + regionId);
			var boxDialougeElement = boxObject.dialougeElement;
			
			dialougeManager.openDialouge ("regionDisplayBox");
			
			boxObject.setContent (data + "<div style=\"text-align: center;\"><button class=\"button\">Schließen</button>");
			dialougeWidth = $(boxObject.contentElement).find ("img").width () + 10;
			dialougeHeight = $(boxObject.contentElement).find ("img").height () + 100;
			$(boxObject.contentElement).find ("button").bind ("click", function ()
			{
				dialougeManager.closeDialouge ("regionDisplayBox");
				unlockScreen ();
			});
			
			boxObject.setSize (dialougeWidth, dialougeHeight);
			boxObject.updateBounds ();
			boxObject.centerDialouge ();
		}
	});
}

$(function ()
{
	// The tips for region maps are realized, using the chilltip-plugin
	$("area,.functionLinkImage,.hotelFeatures img,.ctip").addClass ("chillTip");
	
	/**
	 * The onclick-event of body will let the dialouge manager close all opened dialouges. To prevent
	 * this behaviour, you have to cancel the bubbling of click event on your dialouge or element. 
	 
	   2010-09-30 - s.mohrenstecher@hosting-production.de: Not needed, because all dialouges can be closed by buttons now
	
	$("body").click (function (event) { 
		dialougeManager.closeAllDialouges ();		
	});*/
	
	/**
	 * Assign bubbletips to form elements
	 * 
	 * The following section will detect each form field with class btip and lookup it's id related
	 * to the form it's contained in the lookuptable for form field description. If a description is
	 * found, a bubbletip event will be assigned to focus-event for the input field.
	 * 
	 * (Notice: Form elements can be "input" or "select" - Buttons, realized with "button" are ignored
	 *  with intent)
	 */
		
	var btips = $("input.btip,select.btip");
	var blurEventType = "blur";

	for (var i=0; i<btips.length; i++)
	{
		var formId = $(btips[i]).parents("form").attr ("id");
		if (formId != null && formId != undefined && formId != "")
		{
			var elementId = $(btips[i]).attr("id");
			if (elementId != null && elementId != undefined && elementId != "")
			{
				var elementInformation = hCreateNewElement ("div", {"id": "tip_" + formId + "_" + elementId});
				$(elementInformation).html (formTips[formId][elementId]);
				$(btips[i]).bubbletip ($(elementInformation), {
					"deltaDirection": "left",
					bindShow: 'focus',
					bindHide: blurEventType,
					delayHide: 0,
					animationDuration: 0
				});
			}					
		}
	}

	/**
	 * Creation of Dialouges, needed through the processes of the website. The dialouges, such als
	 * user login are only created and addicted to their respective activation buttons if they 
	 * are realy needed.
	 */
	
	if (document.getElementById ("menuLogin") != null)
	{
		/**
		 * Creation of dialouge for user login, only if the user is not logged in yet
		 */
		var dialouge_userLogin = new hDialouge ({
			"dialougeId": "userLogin",
			"isOnlyDialouge": true,				
			"dialougeKind": "raw",
			"effects": [hDialougeEffects.fadeIn],
			"size": {
				"width": 300,
				"height": 100
			}
		});	
		dialouge_userLogin.alignWithDomElement ($("#menuLogin"), hDialougeAlign.beneathleft, -12, 0);
		dialouge_userLogin.dialougeFromElement ("loginBox", "loginBox");
		
		dialougeManager.readyDialouge ("userLogin");


		$("#cancelloginbutton").click (function (event) {
			dialougeManager.closeDialouge ("userLogin");
			return false;
		});

		$("#userLoginForm").find ("input.password").bind ("keypress", function (event) {
			if (event.keyCode == 13) {
				loginUser ();
			}
		});
		
		$("#loginbutton").click (loginUser);

		$("#menuLogin a").bind ("click", function (event) {
			dialougeManager.openDialouge ("userLogin");
			return false;
		});
	}
	
	if (document.getElementById ("ajax_quickListLink") != null)
	{
		/**
		 * Creation of dialouge for quicklist, only if the display-button is available
		 */
		
		var quicklistHeight = 300;
		var quicklistWidth = 300;
		
		var dialouge_quickList = new hDialouge ({
			"dialougeId": "quickList",
			"dialougeKind": "raw",
			"bubblesClickEvent": true,
			"size": {
				"width": quicklistWidth,
				"height": quicklistHeight
			}		
		});
		
		dialouge_quickList.createDialouge ("Merkliste", "");
		dialouge_quickList.alignWithDomElement ($("#ajax_quickListLink"), hDialougeAlign.beneathleft, -12, 0);
		
		quicklistContent = hCreateNewElement ("div", {"id": "quicklistContent"});
		$(quicklistContent).css ({
			"width": quicklistWidth + "px",
			"height": (quicklistHeight - 77) + "px",
			"overflow-y": "scroll"
		});
		$(dialouge_quickList.dialougeElement).append (quicklistContent);
		
		quicklistFunctions = "<div id=\"quicklistDialougeFunctions\"><button class=\"button\" style=\"float: left; margin: 0px; width: 125px;\" id=\"saveQuicklist\">speichern</button><button class=\"button\" style=\"float: right; margin: 0px; width: 125px;\" id=\"emptyQuicklist\">leeren</button><br /><button class=\"button\" style=\"float: left; margin: 0px; width: 290px; margin-top: 10px;\" id=\"closeQuicklist\">schließen</button></div>";
		$(dialouge_quickList.dialougeElement).append (quicklistFunctions);
		
		$(dialouge_quickList.dialougeElement).find ("#closeQuicklist").bind ("click", function () {
			dialougeManager.closeDialouge ("quickList");
		});
		$(dialouge_quickList.dialougeElement).find ("#emptyQuicklist").bind ("click", function () {
			deleteQuicklistEntry ("all");
		});
		$(dialouge_quickList.dialougeElement).find ("#saveQuicklist").bind ("click", saveUserQuicklist);

		$("#ajax_quickListLink").bind ("click", function () {
			// Load the quicklist, if available and insert it into the quicklist-container
			fillQuicklist ();
			dialougeManager.openDialouge ("quickList");

			return false;
		});
	}
	
	/**
	 * Contactform Management
	 */ 
	
	var dialouge_contactForm = new hDialouge ({
		"dialougeId": "contactFormDialouge",
		"dialougeKind": "raw",
		"size": {
			"width": 640,
			"height": 500
		},
		"isOnlyDialouge": true,
		"locksUI": true,
		"effects": [hDialougeEffects.fadeIn, hDialougeEffects.fadeOut]
	});
	
	dialouge_contactForm.createDialouge ("Kontaktanfrage", "");
	
	var contactFormContainer = '<iframe src="" frameborder="0" border="0" width="640" height="500"></iframe>';

	$(dialouge_contactForm.dialougeElement).append (contactFormContainer);
	dialougeManager.readyDialouge ("contactFormDialouge");
	dialouge_contactForm.centerDialouge ();
	
	$(".contactBizzotelLink").bind ("click", function () {
		dialougeManager.openDialouge ("contactFormDialouge");
		$("#contactFormDialouge").find ("iframe").attr ("src", "");
		$("#contactFormDialouge").find ("iframe").attr ("src", this.href + "?isContactAjaxRequest=1");
		
		var currentTopPosition = 0 - ($("#contactFormDialouge").height() /2) + document.documentElement.scrollTop;
		$("#contactFormDialouge").css ("margin-top", currentTopPosition + "px");
		return false;
	});

	/**
	 * Make the terms info open if a dialouge
	 */
	if (document.getElementById ("termsLink") != "null")
	{		
		$("#termsLink").bind ("click", function () {						
			$("#termsOfUse").css ("background", "url('/view/gfx/revised/various/big-ajax-loader.gif') center center no-repeat");
			$("#termsOfUse").html ("");
			dialougeManager.openDialouge ("termsDialouge");						
			
			$.ajax({
				url: $(this).attr ("href") + "?isAjaxRequest=1",
				success: function(data) 
				{
					$("#termsOfUse").html (data);
					$("#termsOfUse").css ("background", "transparent");
				}
			});
						
			return false;
		});

		var termsWidth = 640;
		var termsHeight = 480;
		
		var dialouge_terms = new hDialouge ({
			"dialougeId": "termsDialouge",
			"dialougeKind": "raw",
			"size": {
				"width": termsWidth,
				"height": termsHeight
			},
			"isOnlyDialouge": true,
			"locksUI": true,
			"effects": [hDialougeEffects.fadeIn, hDialougeEffects.fadeOut]
		});
		
		dialouge_terms.createDialouge ("Nutzungsbestimmungen", "");
		
		var termsContainer = hCreateNewElement ("div", {"id": "termsOfUse"});
		$(termsContainer).css ({
			"width": "620px",
			"height": "444px",
			"background": "url('/view/gfx/revised/various/big-ajax-loader.gif') center center no-repeat",
			"overflow-y": "scroll",
			"padding-left": "20px"
		});		
		
		//dialouge_terms.alignWithDomElement ($("#termsLink"), hDialougeAlign.aboveright, 0, 0);
		$(dialouge_terms.dialougeElement).append (termsContainer);
		dialougeManager.readyDialouge ("termsDialouge");
		dialouge_terms.centerDialouge ();

		quicklistFunctions = "<div id=\"termsofUseDialougeFunctions\" style=\"text-align: center; width: 100%;\"><button class=\"button\" style=\"margin: 0px; width: 125px;\" id=\"closeTermsDialouge\">schließen</button></div>";
		$(dialouge_terms.dialougeElement).append (quicklistFunctions);
		$(dialouge_terms.dialougeElement).find ("#closeTermsDialouge"). bind ("click", function () {
			dialougeManager.closeDialouge ("termsDialouge");
			unlockScreen ();
		});
	}

	$("#ajax_quickListLink").bind ("click", function () {
		// Load the quicklist, if available and insert it into the quicklist-container
		fillQuicklist ();
		dialougeManager.openDialouge ("quickList");

		return false;
	});
	
	/**
	 * Links with class ajaxButtonLink will be executed via ajax. The responding script will define
	 * a callback-function to be executed on success 
	 */
	$(".ajaxButtonLink").bind ("click", function ()
	{
		var myself = this;
		blockAjaxButton (myself);
		
		try
		{
			$.ajax({
				url: this.href,
				dataType: "json", 
				success: function(data) 
				{
					$.growlUI(data.dialougeCaption, data.dialougeText);
					unblockAjaxButton (myself);
					
					window[data.callback] (data.ammount);
					return false;
				}
			});
		}
		catch (err)
		{
			alert (err);
		}
		
		return false;
	});

	/**
	 * Append the "isAjaxRequest" GET-Parameter to all ajaxButtonLinks. This will make the scripts display an
	 * empty frame, increasing the performance of the whole request
	 */
	var ajaxButtonLinks = $(".ajaxButtonLink");
	for (var index=0; index<ajaxButtonLinks.length; index++)
	{
		$(ajaxButtonLinks[index]).attr ("href", $(ajaxButtonLinks[index]).attr ("href") + "?isAjaxRequest=1");
	}
	
	$(".quicklistLink").bind ("click", function () {
		fillQuicklist ();
	});
	
	// The information box is a fixed dialouge, with changing content - We will create it by calling
	// "buildupInformationbox"
	fixedDialouges["informationBox"] = buildupInformationbox ();
	fixedDialouges["regionBox"] = buildupRegionbox ();

	$("#link_extendedSearch").bind ("click", function (event) {
		$("#hotelSearchBox").animate ({
			height: "500px"
		}, 500, null, null);
		$("#link_extendedSearch").css ("font-weight", "bold");
		$("#link_quickSearch").css ("font-weight", "normal");
		$("#extendedSearchForm").css ("display", "block");
		$("#easySearchForm").css ("display", "none");
		return false;
	});

	$("#link_quickSearch").bind ("click", function (event) {
		$("#hotelSearchBox").animate ({
			height: "180px"
		}, 500, null, null);
		$("#link_extendedSearch").css ("font-weight", "normal");
		$("#link_quickSearch").css ("font-weight", "bold");
		$("#extendedSearchForm").css ("display", "none");
		$("#easySearchForm").css ("display", "block");
		return false;
	});
	
	$(".hotelGalleryImage").bind ("click", function () {
		ajaxBlockElement (document.getElementById ("mainImage"));
		$("#mainImage").load (function () {
			ajaxUnblockElement (this);
		});
		$("#mainImage").attr ("src", this.href);
		$("#mainImageLink").attr ("href", this.href.replace ("thumbnail", ""));
		
		return false;
	});
	
	$("#mainImageContainer a").lightBox ();
	
	// Inputfields with class "COF" will be cleared on focus, if their content is equal to their title-attribute. On blur, the title attribute
	// will be restored
	$(".COF").bind ("focus", function () {
		if (document.getElementById (this.id).value == $(this).attr ("title"))
		{
			document.getElementById (this.id).value = "";
		}
	});
	$(".COF").bind ("blur", function () {
		if (document.getElementById (this.id).value == "")
		{
			document.getElementById (this.id).value = $(this).attr ("title");
		}
	});
	
	$("#chooseAlternateReservationContact").bind ("click", function ()
	{
		if (this.checked == true)
		{
			$("#alternateReservationContact").css ("display", "block");
		}
		else
		{
			$("#alternateReservationContact").css ("display", "none");
		}
	})
	
	$("#chooseBillingContact").bind ("click", function ()
	{
		if (this.checked == true)
		{
			$("#alternateBillingContact").css ("display", "block");
		}
		else
		{
			$("#alternateBillingContact").css ("display", "none");
		}
	})
	
	$(".openFeatureCheckbox").bind ("click", function () {
		if (this.checked == true)
		{
			$("#furtherInformation_" + this.id).css ("display", "block");
			if ($("#subfurtherInformation_" + this.id) != null)
			{
				$("#subfurtherInformation_" + this.id).css ("display", "block");
			}
		}
		else
		{
			$("#furtherInformation_" + this.id).css ("display", "none");
			if ($("#subfurtherInformation_" + this.id) != null)
			{
				$("#subfurtherInformation_" + this.id).css ("display", "block");
			}
		}	
	});
	
});

	function tellContactSended ()
	{
		dialougeManager.closeDialouge ("contactFormDialouge");
		informationBox ("Mitteilung erfolgreich versendet", "Ihre Mitteilung wurde erfolgreich versendet", "OK", unlockScreen);	
	}
	
	function fillQuicklist ()
	{
		$("#quicklistContent").html ("");
		var dialouge_quickList = dialougeManager.getDialouge ("quickList");
		$(dialouge_quickList.dialougeElement).css ("background", "url('/view/gfx/revised/various/big-ajax-loader.gif') no-repeat center center #fff");
		$(dialouge_quickList.dialougeElement).find ("#emptyQuicklist").css ({
			"display": "none",
			"opacity": 0
		});
		
		$.ajax({
			url: '/merkliste/ajax/?isAjaxRequest=1',
			success: function(data) 
			{
				$("#quicklistContent").html (data);
				$(dialouge_quickList.dialougeElement).css ("background", "#ffffff");
				quicklistLoaded = true;
				$(dialouge_quickList.dialougeElement).find("#emptyQuicklist").css ("display", "block");
				$(dialouge_quickList.dialougeElement).find("#emptyQuicklist").animate ({"opacity": 1}, 500);				
			}
		});
	}

	function deleteQuicklistEntry (entryId)
	{
		var listElementToDelete = $("#quicklistEntry_" + entryId);
		if (listElementToDelete == null)
		{
			hDebugger.addDebugNotice ("deleteQuicklistEntry", "quicklistEntry " + entryId + " not found!");
		}
		else
		{
			$.ajax({
				url: '/ajaxrequest/deleteQuicklistEntry/' + entryId + '/?isAjaxRequest=1',
				success: function (data) 
				{
					updateQuicklist (data);
				}
			});
	
			if (entryId == "all")
			{
				$("#quicklistContent li").animate ({
					"opacity": 0
				}, 500, null, function () {
					$("#quicklistContent li").css ("display", "none");
				});
			}
			else
			{
				$(listElementToDelete).animate ({
					"opacity": 0
				}, 500, null, function () {
					$(listElementToDelete).css ("display", "none");
				});
			}
		}
	}

function setNoImageAvailable(imgObject)
{
	imgObject.src = "/view/gfx/revised/noPictureAvailable.jpg";
}

function buildupRegionbox ()
{
	var regionDialouge = new hDialouge ({
		"dialougeId": "regionDisplayBox",
		"isOnlyDialouge": true,
		"locksUI": true,
		"bubblesClickEvent": true,
		"effects": [hDialougeEffects.fadeIn, hDialougeEffects.fadeOut]
	});
	
	regionDialouge.setSize (320,0);
	regionDialouge.setHeadbarIcon ("info");
	
	var dialougeContent = document.createElement ("div");
					
	regionDialouge.simpleDialouge ("", dialougeContent);
	dialougeManager.registerDialouge (regionDialouge);				
	
	return regionDialouge;
}
function buildupInformationbox ()
{
	var handle = "temporaryInformationBox";
	
	var informationDialouge = new hDialouge ({
		"dialougeId": handle,
		"bubblesClickEvent": true,
		"isOnlyDialouge": true,
		"locksUI": true,
		"effects": [hDialougeEffects.fadeIn, hDialougeEffects.fadeOut]
	});
	
	informationDialouge.setSize (320,0);
	informationDialouge.setHeadbarIcon ("info");
	
	var dialougeContent = document.createElement ("div");
	$(dialougeContent).addClass ("informationPopupContent");
	$(dialougeContent).html ("<p></p><div><button id=\"temporaryOkButton\"></button></div>");
	
	$(dialougeContent).find ("button").bind("click", function () {
		dialougeManager.closeDialouge (handle);
		unlockScreen ();
	});
	$(dialougeContent).find ("button").addClass ("button");
					
	informationDialouge.simpleDialouge ("", dialougeContent);
	dialougeManager.registerDialouge (informationDialouge);				
	
	return informationDialouge;
}

function informationBox (caption, text, buttonText, callbackFunction)
{
	var boxObject = fixedDialouges["informationBox"];

	boxObject.setCaption (caption);
	var boxDialougeElement = boxObject.dialougeElement;
	$(boxDialougeElement).find ("p").html (text);
	$(boxDialougeElement).find ("p").css ("text-align", "left");
	$(boxDialougeElement).find ("button").text (buttonText);
	
	dialougeManager.openDialouge ("temporaryInformationBox");
	
	boxObject.autoHeight ();
	boxObject.centerDialouge ();
	
	if (callbackFunction != null)
	{
		$("#temporaryOkButton").bind ("click", callbackFunction);
	}
}

/**
 * 
 * @param elementToBlock
 * @return
 */
function ajaxBlockElement (elementToBlock)
{
	var blockElement = hCreateNewElement ("div", {"id": "ajaxBlock_" + $(elementToBlock).attr("id"), "class": "ajaxBlockContainer"});
	
	if ($(elementToBlock).height() != 0)
	{
		destinationHeight = $(elementToBlock).height ();
	}
	else
	{
		destinationHeight = 75;
	}
	if ($(elementToBlock).width() != 0)
	{
		destinationWidth = $(elementToBlock).width ();
	}
	else
	{
		destinationWidth = 75;
	}

	$(blockElement).css ({
		"display": "block",
		"opacity": .5,
		"left": $(elementToBlock).offset().left + "px",
		"top": $(elementToBlock).offset().top + "px",
		"width": destinationWidth + "px",
		"height": destinationHeight + "px"
	});
	
	$("body").append (blockElement);
}

function ajaxUnblockElement (elementToUnblock)
{
	$("#ajaxBlock_" + $(elementToUnblock).attr ("id")).remove ();
}

function updateQuicklist (ammount)
{
	if (ammount != null)
	{
		var textToShow = "Meine Merkliste";
		if (parseInt (ammount) > 0)
		{
			textToShow = textToShow + " (" + ammount + ")";
		}
		$("#ajax_quickListLink a").text (textToShow);
		quicklistLoaded = false;
	}
	else
	{
		blockAjaxButton (document.getElementById ('ajax_quickListLink'));
	}
}

function loginUser ()
{
	ajaxBlockElement ($("#userLogin"));
	
	var loginemail = document.forms['userLoginForm'].elements['loginemail'].value;
	var loginpassword = document.forms['userLoginForm'].elements['loginpassword'].value;
	
	if (loginemail == "" || loginpassword == "")
	{
		ajaxUnblockElement ($("#userLogin"));
		informationBox ("Fehler", "Bitte geben Sie eine gültige E-Mailadresse und ein Kennwort ein. <br />Haben Sie evtl. Ihr Kennwort vergessen? In diesem Fall können Sie <a href='/kennwortvergessen'>hier</a> ein neues Kennwort anfordern.", "OK");
	}
	else
	{
		$.ajax({
			url: '/ajaxrequest/userLoginViaAjax?isAjaxRequest=1',
			data: {
				"loginemail": loginemail,
				"loginpassword": loginpassword
			},
			success: function(data) 
			{			
				var statusDialog = $("#dynamicDialog");
				$(statusDialog).html (null);
				var loginTitle = "";
				var loginSuccess = false;

				if (data == "success")
				{
					$(statusDialog).html ("Sie wurden erfolgreich angemeldet, klicken Sie auf OK um weitergeleitet zu werden.");
					loginTitle = "Login erfolgreich";
					loginSuccess = true;
				}
				else
				{
					loginTitle = "Login fehlgeschlagen";
					$(statusDialog).html ("Sie konnten leider nicht angemeldet werden. Haben Sie evtl. Ihr Kennwort vergessen? In diesem Fall können Sie <a href='/kennwortvergessen'>hier</a> ein neues Kennwort anfordern.");					
				}

				//$("#frame").append (statusDialog);
				$(statusDialog).dialog({ 
					buttons: { 
						"Ok": function() { 
							if (loginSuccess == true)
							{
								document.location = "/redirectAfterLogin";
							}
							else
							{
								$(this).dialog("close");
							}
						} 
					},
					draggable: false,
					modal: true,
					resizable: false,
					title: loginTitle 
				});

				ajaxUnblockElement ($("#userLogin"));
				//dialougeManager.closeDialouge ("userLogin");
			}
		});
	}
	
	return false;
}

$(function () {
	/**
	 * Ajax image upload
	 */

	var dialouge_ajaxImageUpload = new hDialouge ({
		"dialougeId": "ajaxImageUpload",
		"size": {
			"width": 400,
			"height": 250
		},
		"isOnlyDialouge": true,
		"locksUI": true,
		"bubblesClickEvent": true,
		"effects": [hDialougeEffects.fadeIn, hDialougeEffects.fadeOut]
	});
	
	dialouge_ajaxImageUpload.createDialouge ("Datei aufspielen", "");
	
	dialougeManager.readyDialouge ("ajaxImageUpload");
	dialouge_ajaxImageUpload.centerDialouge ();
	
	var informationText = "<p style=\"width: 380px; padding: 5px; text-align: left;\" >Bitte wählen Sie eine Datei von Ihrer lokalen Festplatte aus, dass an diese Position aufgespielt werden soll und klicken Sie auf &quot;Aufspielen&quot; um es auf den Server zu laden. Evtl. bereits aufgespielte Daten werden hierbei überspielt.<br/ ><br /><strong>(Bitte beachten Sie, dass die Datei 2 Megabyte nicht überschreiten darf, da ansonsten technische Probleme auftreten können)</strong></p>";
	
	dialouge_ajaxImageUpload.getContentPane().append (informationText);
	var uploadForm = '<form name="ajaxImageUploadForm" id="ajaxImageUploadForm" action="/meinhotel/bilder" method="post" enctype="multipart/form-data"><div style="text-align: center; margin-top: 5px; width: 380px !important;"><input type="file" name="fileName" id="fileName" style="width: 380px;" /></div><div style="margin-top: 5px; text-align: center"><input class="button" type="submit" value="Aufspielen" style="float: left;"/><button class=\"button\" id=\"closeUploadDialouge\" style=\"float: right;\">Abbruch</button></div></form>';
	dialouge_ajaxImageUpload.getContentPane().append (uploadForm);
	$("#ajaxImageUpload").find ("#closeUploadDialouge").bind ("click", function () {
		dialougeManager.closeDialouge ("ajaxImageUpload");
		unlockScreen ();
		return false;
	});
		
	
	$(".ajaxUploadImageLink").bind ("click", function () {
		/*
		 * Will have to check why this won't work...
		 */
		dialougeManager.openDialouge ("ajaxImageUpload");

		// Reajust the dialouge, if the browser was scrolled
		var currentTopPosition = 0 - ($("#ajaxImageUpload").height() /2) + document.documentElement.scrollTop; 
		$("#ajaxImageUpload").css ("margin-top",  currentTopPosition + "px");
		$("#ajaxImageUpload").find ("#fileName").attr ("name", this.id);
		return false;
	});
	
	$(".deleteImageLink").bind ("click", function () {
		lockScreen ();
		var decision = confirm ("Möchten Sie diese Datei wirklich entfernen?");
		if (decision == true) {
			document.location = this.href;
		} else {
			unlockScreen ();
		}
		return false;
	});
});

$(function () {
	$(".paneOpener").bind ("click", function () {
		if (this.checked == true) {
			$("#pane_" + this.id).css ("display", "block");
		} else {
			$("#pane_" + this.id).css ("display", "none");
		}
	});
});
