function DecryptDialog(textArea) {
	this.visible  = true;
	this.textArea = textArea;
	this.sack     = new sack(DOKU_BASE + "lib/exe/ajax.php");

	// read cached password
	if ((JSINFO['crypto_cache_password'] == 1) && (JSINFO['crypto_password'] != undefined)) {
		this.password = ' value="' + JSINFO['crypto_password'] + '"';
	} else {
		this.password = "";
	}

	// create HTML Structure
	this.div = document.createElement('div');
	this.div.id = 'decrypt_dialog';
	this.div.className  = 'picker cryptodialog';
	this.div.style.top  = (findPosY(textArea)+20)+'px';
	this.div.style.left = (findPosX(textArea)+80)+'px';

	this.textArea.form.parentNode.appendChild(this.div);
	this.div.innerHTML =
             '<div id="decrypt_dialog_header" class="cryptoheader">'+
             ' <img src="' + DOKU_BASE + 'lib/images/close.png" width="16" height="16" align="right" alt="" id="decrypt_dialog_close" />' + 
	     LANG.plugins.crypto['decrypt_dialog_title'] +
	     '</div>' +
             '<div>' +
	     ' <table>' +
     	     '  <tr>' +
    	     '   <th>' + LANG.plugins.crypto['input_secret'] + ':</th>' +
	     '   <td><input type="password" class="edit" id="decrypt_dialog_password"' + this.password + '/></td>' +
	     '  </tr>' +
	     '  <tr>' +
     	     '   <td colspan="2"><button id="decrypt_dialog_button_decrypt">' + LANG.plugins.crypto['decrypt_button'] + '</button></td>' + 
	     '  </tr>' +
     	     ' </table>' +
	     '</div>';

	// attach event handlers
	drag.attach(this.div, $('decrypt_dialog_header'));

	var dialog = this;

	$('decrypt_dialog_password').focus();
	$('decrypt_dialog_password').onkeypress = function(event) {
		if (event.keyCode==9) {
			$('decrypt_dialog_button_decrypt').focus();
			return false;
		}

		if (event.keyCode==13) {
			$('decrypt_dialog_button_decrypt').onclick();
		}

		return true;
	};

	$('decrypt_dialog_button_decrypt').onkeypress = function(event) {
		if (event.keyCode==9) {
			$('decrypt_dialog_password').focus();
			return false;
		}

		return true;
	};

	// register destructor
	$('decrypt_dialog_close').onclick = function() {
		dialog.textArea.focus();
		dialog.textArea.form.parentNode.removeChild(dialog.div);
		dialog.visible  = false;
		dialog.div      = null;
		dialog.textArea = null;
	};

	$('decrypt_dialog_button_decrypt').onclick = function() {
		var selection = getSelection(dialog.textArea);
		var text = selection.getText();
		dialog.sack.setVar("call",   "crypto_decrypt");
		dialog.sack.setVar("secret", $('decrypt_dialog_password').value);
		dialog.sack.setVar("data",   getSelection(dialog.textArea).getText());
		dialog.sack.onCompletion = function() {
			if (dialog.sack.response) {
				pasteText(selection, dialog.sack.response);
				$('decrypt_dialog_close').onclick();
			} else {
				alert(LANG.plugins.crypto['decrypt_wrong_secret']);
			}
		};

		// cache the password
		if (JSINFO['crypto_cache_password'] == 1) {
			JSINFO['crypto_password'] = $('decrypt_dialog_password').value;
		} else {
			JSINFO['crypto_password'] = "";
		}

		dialog.sack.runAJAX();
	};
};


