/**
 * Pendant zu javascript alert, aber unter Benutzung
 * von jQuery.Dialog
 * @param msg
 * @return void
 */
function podAlert(atitle, msg)
{
	var dlg = $('#messagediv');
	dlg.html(msg);
	
	var temp = dlg.dialog(
		{	title: atitle,
			modal: true, 
			autoOpen: true,
			resizable: false,
			//height: 170, 
			width: 500,
			buttons: { "OK" : function() { $(this).dialog('close'); } },
			close: function() { $('#messagediv').dialog('destroy'); }
		});
	
	$('.ui-dialog-buttonset > button:last').addClass('ui-state-default ui-corner-all');
	$('.ui-dialog-buttonset > button:last').focus();
}

function custom_confirm(prompt, action, title)
{
	var cancelbtn = $('#confirmcancelbtn').text();
	var proceedbtn = $('#confirmproceedbtn').text();
	
	var bOptions = {};
	bOptions[cancelbtn] = function(){ $(this).dialog('close'); };
	bOptions[proceedbtn] = function(){ $(this).dialog('close'); location.href = action; };
	
	if (title === undefined) title = $('#confirmtitle').text();
	$("#confirmdiv").append('<div id="confirm" title="' + title + '">' + prompt + '</div>');
	
	
	$("#confirm").dialog(
		{
			position: 'top',
			width: 700,
			modal: true,
			resizable: false,
			
			buttons: bOptions,
			open: function (ev, ui) {},		
			close: function(ev, ui) {$(this).remove();}
		}
	);
}

function adjustLayout()
{
	$('#container').height("auto");
	$('#menu_wrapper').height("auto");

	var mHeight = $('#menu_wrapper').height();
	var cHeight = $('#container').height();

	var lHeight = $('.lowermenuwrapper').height();
	mHeight +=lHeight + 20;

	if (mHeight > cHeight)
	{
		$('#container').height(mHeight);
		$('#menu_wrapper').height(mHeight);
	}
	else
	{
		$('#menu_wrapper').height(cHeight);
	}
	
}

function readCookie(n){
	a = document.cookie;
	res = '';
	while(a != '') {
		while(a.substr(0,1) == ' ') {
			a = a.substr(1,a.length);
		}

		cookiename = a.substring(0,a.indexOf('='));
		if (a.indexOf(';') != -1) {
			cookiewert = a.substring(a.indexOf('=')+1,a.indexOf(';'));
		} else {
			cookiewert = a.substr(a.indexOf('=')+1,a.length);
		}

		if (n == cookiename) {
			res = cookiewert;
		}

		i = a.indexOf(';')+1;
		if (i == 0) {
			i = a.length;
		}
		a = a.substring(i,a.length);
	}
	return res;
}



$(function ()
{
	$('a[rel=external]').attr('target','_blank');
	
	adjustLayout();
});

