function previewComment(numberToCome) {
	if (validateCommentForm()) {
		var sb = new StringBuilder();

		sb.Append('<div class="commententry"><p class="author"><a href="#' + numberToCome + '" name="' + numberToCome + '">#' + numberToCome + '</a> - ');
		if ($F('commentWebsite') != "") {
			sb.Append('<a href="' + $F('commentWebsite') + '" target="_blank">');
		}

		sb.Append($F("commentName"));

		if ($F('commentWebsite') != "") {
			sb.Append('</a>');
		}
		
		sb.Append(' On, when you press Post comment!');
		
		sb.Append('</p>');
		sb.Append('<div class="commentbody"><p>' + $F("commentComment").replace(/\n/g, '<br />') + '</p></div>');
		
		$("commentPreview").innerHTML = sb.ToString();
		new Effect.Highlight('commentPreview', {startcolor:'#ffba00', endcolor:'#333333', restorecolor:'#333333'})
		window.location = "#acreatecomment";
	}
}

function postComment(nodeId) {
	if (validateCommentForm()) {
		$("commentPreview").innerHTML = "";
		Form.disable(document.forms[0]);
		Element.show("divLoadingComment");
		Element.hide("divCreateComment");
		CPalm.Website.AjaxService.InsertNewCommentAndGetAllCommentsAsHtml(nodeId, $F("commentName"), $F("commentEmail"), $F("commentWebsite"), $F("commentComment"), InsertNewCommentAndGetAllCommentsAsHtml_callback);
	}
}

function InsertNewCommentAndGetAllCommentsAsHtml_callback(res)
{
	if (res.error != null)
	{
		alert(res.error.Message);
	}
	else
	{
		$("allComments").innerHTML = res.value;
		new Effect.Highlight('lastInserted', {startcolor:'#ffba00', endcolor:'#333333', restorecolor:'#333333'})
		Form.enable(document.forms[0]);
		clearCommentForm();
		window.location = "#acreatecomment";
		Element.show("divCreateComment");
		Element.hide("divLoadingComment");
		
	}
}

function clearCommentForm()
{
	$("commentName").value		= "";
	$("commentEmail").value		= "";
	$("commentWebsite").value	= "";
	$("commentComment").value	= "";
}

function validateCommentForm() {
	if ($F('commentName') == "") {
		alert("Please type your name!");
		$('commentName').focus();
		return false;
	}

	if ($F('commentWebsite') != "") {
		if ($F('commentWebsite').indexOf("http://") == -1) {
			$('commentWebsite').value = "http://" + $F('commentWebsite');
		}
		if (isUrl($F('commentWebsite')) == false) {
			alert("Please write a valid URL!");
			$('commentWebsite').focus();
			return false;
		}
	}

	if ($F('commentComment') == "") {
		alert("Please write a comment!");
		$('commentComment').focus();
		return false;
	}

	return true;
}