function EncryptDialog(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.dialog = document.createElement('div');
	this.dialog.id = 'encrypt_dialog';
	this.dialog.className  = 'picker cryptodialog';
	this.dialog.style.top  = (findPosY(textArea)+20)+'px';
	this.dialog.style.left = (findPosX(textArea)+80)+'px';

	this.textArea.form.parentNode.appendChild(this.dialog);

	this.dialog.innerHTML =
             '<div id="encrypt_dialog_header" class="cryptoheader">'+
             ' <img src="' + DOKU_BASE + 'lib/images/close.png" width="16" height="16" align="right" alt="" id="encrypt_dialog_close" class="close"/>' +
	     LANG.plugins.crypto['encrypt_dialog_title'] +
	     '</div>' +
             '<div>' +
	     ' <table>' +
     	     '  <tr>' +
     	     '   <th>' + LANG.plugins.crypto['input_secret'] + ':</th>' +
	     '   <td><input type="password" class="edit" id="encrypt_dialog_password1"' + this.password + ' tabindex="1"/></td>' +
	     '  </tr>' +
     	     '  <tr>' +
     	     '   <th>' + LANG.plugins.crypto['repeat_secret'] + ':</th>' +
	     '   <td><input type="password" class="edit" id="encrypt_dialog_password2"' + this.password + ' tabindex="2"/></td>' +
	     '  </tr>' +
	     '  <tr>' +
     	     '   <td colspan="2"><button id="encrypt_dialog_button_encrypt" tabindex="3">' + LANG.plugins.crypto['encrypt_button'] + '</button></td>' +
	     '  </tr>' +
     	     ' </table>' +
	     '</div>';

	// attach event handlers
	drag.attach(this.dialog, $('encrypt_dialog_header'));
	var dialog = this;

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

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

		return true;
	};

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

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

		return true;
	};

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

		return true;
	};

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

	$('encrypt_dialog_button_encrypt').onclick = function() {
		var selection = getSelection(dialog.textArea);
		var text = selection.getText();
		if ($('encrypt_dialog_password1').value == $('encrypt_dialog_password2').value) {
			dialog.sack.setVar("call",   "crypto_encrypt");
			dialog.sack.setVar("secret", $('encrypt_dialog_password1').value);
			dialog.sack.setVar("data",   getSelection(dialog.textArea).getText());
			dialog.sack.onCompletion = function() {
				pasteText(selection, dialog.sack.response);
				$('encrypt_dialog_close').onclick();
			};

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

			dialog.sack.runAJAX();
		} else {
			alert(LANG.plugins.crypto['encrypt_secrets_dont_match']);
		}
	};
};

