var save_height;
var global_language = "DE";
var msg = "";
var center_dialog_to = 0;
var center_dialog_active = 0;
var spec_buttons;
var specialDialogErrorTitle ="";
$.fx.speeds._default = 500;

$(document).ready(function(){
	$("#loading_dialog").dialog({
	autoOpen: false,
	modal: true,
	show: "fade",
	resizable: false,
	width: 524,
	minHeight: 150,
	closeOnEscape: false,
	open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
	
});});


function loading(openclose){	
	
	if(openclose == "finish" || openclose == "0"){
		$("#loading_dialog").dialog("close");
		
		
		
	}else{
		
		
		$("#loading_dialog").dialog( "open" );	
		
	}
	
}

function center_dialog(){
	
	clearTimeout(center_dialog_to);
		
	center_dialog_to = setTimeout('do_center_dialog()',100);

}

function do_center_dialog(){
	
	if($('.ui-widget-overlay').css('display') != 'none'){
		$('.isdialog').parent().animate({'top':(($(window).scrollTop()+$(window).height()/2)-$('.isdialog').parent().height()/2),'left':(($(window).width()/2)-$('.isdialog').parent().width()/2)},'fast',function(){});
		
	}
}



function cdialog(id,msg,dialog_buttons,etc,opt_title){	
	
	if(typeof msg == 'undefined'){
		msg = "";
	}
	
	var title = id;
	
	if(typeof opt_title != 'undefined'){ 
		title = opt_title; 
	}
	
	id = id.split(' ').join('_');
	id = id.split('&auml;').join('ae');
	id = id.split('&Auml;').join('ae');
	id = id.split('&uuml;').join('ue');
	id = id.split('&Uuml;').join('ue');
	id = id.split('&ouml;').join('oe');
	id = id.split('&Ouml;').join('oe');
	id = id.split('&szlig;').join('ss');
	
	if($("#dialog_"+id).html() != ""){$("#dialog_"+id).remove();}
	
	if($('.isdialog').css('opacity')!=1){
		
		$("body").append("<div title=\""+title+"\" style='text-align:left;' class='isdialog' id='dialog_"+id+"'><br/>"+msg+"</div>");	
	
	}else{
		
		$("body").append("<div title=\""+title+"\" class='isdialog subdialog' style='text-align:left;' id='dialog_"+id+"'><br/>"+msg+"</div>");	
		
	}
	
	if(id == "Einen_Moment_bitte"){
		$('#dialog_'+id).addClass("loading");
	}
	
	if(msg == ""){
		
		loading();
		$.post('ajax/preparedDialogs.php',{'id': id ,'etc': etc,}, 
				function(dialog_content) {
			
					$('#dialog_'+id).html(dialog_content);
					loading('finish');
					
					

					load_dialog_special(id,spec_buttons);
					spec_buttons = "";
					

						 if(id == "Login"){
							 
							 setAddressCookies();
							 
						}
					
					 center_dialog();
					
				});
	
	}else{
		
		load_dialog(id,dialog_buttons);
		
	}
	
	
	$(window).resize(function(){
		center_dialog();
	});
	
	
	$(window).scroll(function(){
		center_dialog();
	});
	
	
	
}
	


	function load_dialog(id,dialog_buttons) {
		
		if(typeof dialog_buttons == 'undefined'){
			
			dialog_buttons = {
					Ok: function() {
						$( this ).dialog( "close" );
					}
				};			
		}
		
		$( "#dialog_"+id ).dialog({
			autoOpen: false,
			modal: true,
			show: "fade",
			hide: "fade",
			resizable: false,
			width: 500,
			minHeight: 150,
			buttons: dialog_buttons,
			open: function(){center_dialog();$('.ui-dialog').css('z-index',1006);$('.ui-widget-overlay').css('z-index',1005);},
			close: function(){$("#dialog_"+id).remove();center_dialog();}
		});
		
		$( "#dialog_"+id ).dialog( "open" );		
		$("#dialog_"+id).parent().addClass("dropShadow");
		
	}
	
	function load_dialog_special(id,spec_buttons) {

	var dialog_spec_height = parseFloat($('#dialog_wrapper_'+id).css("height"))+110;
	var dialog_spec_width = parseFloat($('#dialog_wrapper_'+id).css("width"))+35;
		
		$( "#dialog_"+id ).dialog({
			autoOpen: false,
			modal: true,
			show: "fade",
			hide: "fade",
			resizable: false,
			height: dialog_spec_height,
			width: dialog_spec_width,
			buttons: spec_buttons,	
			open: function(){center_dialog();$('.ui-dialog').css('z-index',1006);$('.ui-widget-overlay').css('z-index',1005); },
			close: function(){$("#dialog_"+id).remove();center_dialog();}
		});
		if(specialDialogErrorTitle != ""){
			$( "#dialog_"+id ).dialog( "option", "title", specialDialogErrorTitle );
		}
		$( "#dialog_"+id ).dialog( "open" );		
		
		specialDialogErrorTitle = "";

			$("#dialog_"+id).parent().addClass("dropShadow");
	}
	
