function comments() {
	this.submitPre = function() {
		try {
			setForm(document.forms["Comments_Form"], true, false);

			if (document.forms["Comments_Form"].elements["author"].value == FormDefaults["Comments_Form"]["author"])
				throw "<p>We'd like to know who you are, so please tell us your name.</p>";
			if (document.forms["Comments_Form"].elements["text"].value == FormDefaults["Comments_Form"]["text"])
				throw "<p>Well, you actually have to write a message if you want to leave one.</p>";

			captchaDialog.show();
		}
		catch (e) {
			errorDialog.setContent(e);
			errorDialog.show();
		}
	}

	this.submit = function(button) {
		if (button == "OK") {
			var request = new swx_AjaxRequest("POST", "./modules/comments/onsubmit.php", true);
			request.setResponseHandler(4, this.submitPost);
			request.processForm(document.forms["Comments_Form"], "captcha=" + encodeURIComponent(document.forms["Comments_Captcha"].elements["captcha"].value));
		}
		else {
			setForm(document.forms["Comments_Form"], false, false);
		}
		captchaDialog.hide();
	}

	this.submitPost = function(request) {
		if (request.responseText.substr(0, 5) == "ERROR") {
			errorDialog.setContent(request.responseText.substring(5));
			errorDialog.show();
		}
		else {
			var listnode = document.getElementById("Comments_List");
		
			if (!listnode.hasChildNodes())
				listnode.innerHTML = "<h2>Comments</h2>";
			listnode.innerHTML = request.responseText + listnode.innerHTML;

			setForm(document.forms["Comments_Form"], false, true);
		}
	}

	this.submitError = function(button) {
		setForm(document.forms["Comments_Form"], false, false);
		errorDialog.hide();
	}

	var captchaDialog = new swx_Dialog("Comments_Captcha", "comments.submit", Array("Cancel", "OK"), "OK", "<p>We like robots, but not those who abuse our website for<br/>spammig. Therefore you have to pass a small test, which prooves<br/>that you're human - or no machine at least.</p><p><img alt=\"Captcha\" style=\"vertical-align:middle;\" height=\"25\" width=\"100\" src=\"./swx/captcha.php?seed=" + encodeURIComponent((new Date()).getTime()) + "\"/><br/>Please enter the code shown above here: <input name=\"captcha\" style=\"width:40px;\" type=\"text\"/></p>");
	var errorDialog = new swx_Dialog("Comments_Error", "comments.submitError", Array("OK"), "OK", "NOTE: Content will be generated later.");

	FormDefaults["Comments_Form"] = new Array();
	FormDefaults["Comments_Form"]["author"] = "Your name";
	FormDefaults["Comments_Form"]["text"] = "Your message";
}
