var element = null;
var steps = -50;
var dialogIsVisible = false;
var maxSteps = 10;

function moveElement() {

	var s = element.style.left;
	var n = parseInt( s );
	element.style.left = (n - 16) + "px";
	element.style.width = (steps * 35) + 90  + "px";
	element.style.height = (steps * 32) + 90  + "px";
	
	steps = steps + 1;

	if ( steps > maxSteps ) {	
		document.getElementById( "dialogContent" ).style.visibility = "visible";
		return;
	}
	setTimeout ('moveElement()',40);
}

function openDialog(content, title) {
	var dialog = document.getElementById( "dialog" );
	if ( dialogIsVisible ) {
		dialog.style.visibility = 'hidden';
		dialogIsVisible = false;
	}
	dialog.innerHTML = content;
	document.getElementById( "dialogTitle" ).innerHTML = title;
	if ( !dialogIsVisible ) {
		element = document.getElementById( "dialog" );
		element.style.left = "400px";
		element.style.width = "0px";
		element.style.height = "0px";
		element.style.visibility = 'visible';		
		steps = 0;
		moveElement();
		dialogIsVisible = true;
	}		
}

function closeDialog() {
	document.getElementById( "dialogTitle" ).innerHTML = "";
	var dialog = document.getElementById( "dialog" );
	dialog.innerHTML = "";
	dialog.style.visibility = "hidden";
	dialogIsVisible = false;
}

function openWarning(key) {	
	submitGetRequest( baseURL + "action=getMessage&key=" + key + ",CATMANAGE_DIALOG_WARN_TITLE,CATMANAGE_DIALOG_CLOSE", 				
		function(result) {	
			var list = JSON.parse( result )
			var s = '<div id="dialogContent" class="dialogContent"><div id="dialogHeader">' 
				+ '<a id="dialogTitle" style="position:absolute; left:0px; width:475px; height:20px; background-color: #cedff5; padding-left: 10px; color: #00395b; font-weight:bold; ; z-index:1" ></a>'
				+ '<img src="./images/page_close.gif" border="0" style="position:absolute; top:3px; left:465px; z-index:100" onclick="closeDialog()">'
				+ '</div><div id="helpText" style="position:absolute; top:30px; left:20px; width:400px; height:350px">'
			    + '<h2>Warnung!</h2><b>' + list[0] + '</b>'  
			    + '</div><div style="position:absolute; top:380px; left:20px; width:40px; height:20px; color: #00395b; font-weight:bold">'
			    + '<a href="#" onclick="closeDialog()" style="position:absolute; width:80px; height:20px; background-color: #cedff5; text-align: center; padding: 4px 0px 0px 0px; border: 1px solid #99BBE8; -moz-border-radius: 3px 3px 3px 3px; color: #00395b; text-decoration:none;" >' 
			    + list[2] + '</a></div></div>';
				openDialog( s, list[1] );
			}, 				
			null, true );
}

function openInformation(message, title) {
	if ( title == null ) {
		title = 'Information';
	}
	var s = '<div id="dialogContent" class="dialogContent"><div id="dialogHeader">'
		+ '<a id="dialogTitle" style="position:absolute; left:0px; width:440px; height:20px; background-color: #cedff5; padding-left: 10px; color: #00395b; font-weight:bold; z-index:1" ></a>'
		+ '<img src="./images/page_close.gif" border="0" style="position:absolute; top:3px; left:430px; z-index:100" onclick="closeDialog()"></div>'
		+ '<div id="helpText" style="position:absolute; top:30px; left:20px; width:400px; height:350px">'
        + '<h2>Information!</h2><b>' + message + '</b>'
        + '</div><div style="position:absolute; top:365px; left:20px; width:40px; height:20px; color: #00395b; font-weight:bold">'
        + '<a href="#" onclick="closeDialog()" style="position:absolute; width:80px; height:20px; background-color: #cedff5; text-align: center; padding: 4px 0px 0px 0px; border: 1px solid #99BBE8; -moz-border-radius: 3px 3px 3px 3px; color: #00395b; text-decoration:none;" >schließen</a></div></div>';
	openDialog( s, title );
}

function openException(message, title) {
	if ( title == null ) {
		title = 'Exception';
	}
	var s = '<div id="dialogContent" class="dialogContent"><div id="dialogHeader">'
		+ '<a id="dialogTitle" style="position:absolute; left:0px; width:440px; height:20px; background-color: #cedff5; padding-left: 10px; color: #00395b; font-weight:bold; ; z-index:1" ></a>'
		+ '<img src="./images/page_close.gif" border="0" style="position:absolute; top:3px; left:430px; z-index:100" onclick="closeDialog()"></div>'
		+ '<div id="helpText" style="position:absolute; top:30px; left:20px; width:400px; height:350px">'
        + '<h2>Fehler!</h2><b>' + message + '</b>'  
        + '</div><div style="position:absolute; top:365px; left:20px; width:40px; height:20px; color: #00395b; font-weight:bold">'
        + '<a href="#" onclick="closeDialog()" style="position:absolute; width:80px; height:20px; background-color: #cedff5; text-align: center; padding: 4px 0px 0px 0px; border: 1px solid #99BBE8; -moz-border-radius: 3px 3px 3px 3px; color: #00395b; text-decoration:none;" >schließen</a></div></div>';
	openDialog( s, title );
}

function openConfirm(message, title, submitHandler) {
	if ( title == null ) {
		title = 'Bestätigigung erforderlich';
	}
	var s = '<div id="dialogContent" class="dialogContent"><div id="dialogHeader"><a id="dialogTitle" style="position:absolute; left:0px; width:440px; height:20px; background-color: #cedff5; padding-left: 10px; color: #00395b; font-weight:bold; ; z-index:1" ></a><img src="./images/page_close.gif" border="0" style="position:absolute; top:3px; left:430px; z-index:100" onclick="closeDialog()"></div><div id="helpText" style="position:absolute; top:30px; left:20px; width:400px; height:350px">'
    + '<h2>Bitte best&auml;tigen!</h2><b>' + message + '</b>' + 
    '</div><div style="position:absolute; top:370px; left:1px; width:400px; height:20px; color: #00395b; font-weight:bold">' +
    '<a href="#" onclick="closeDialog(); ' + submitHandler + '" style="position:absolute; left: 20px; width:80px; height:20px; text-align: center; padding: 4px 0px 0px 0px; border: 1px solid #99BBE8; -moz-border-radius: 3px 3px 3px 3px; background-color: #cedff5; color: #00395b; text-decoration:none;" >OK</a>' +
    '<a href="#" onclick="closeDialog()" style="position:absolute; left: 120px; width:80px; height:20px; text-align: center; padding: 4px 0px 0px 0px; border: 1px solid #99BBE8; -moz-border-radius: 3px 3px 3px 3px; background-color: #cedff5; color: #00395b; text-decoration:none;" >abbrechen</a></div></div>'
	openDialog( s, title );
}