﻿jQuery(function() {
	initCommentForm();
});

function initCommentForm() {
	if (jQuery("div.commentForm").length > 0) {
		var submit = jQuery("input[type='button']");
		if (jQuery(submit).length > 0) {
			jQuery(submit).bind("click", function() {
				var success = true;
				var author = jQuery("div.commentForm input[name='author']");
				var email = jQuery("div.commentForm input[name='email']");
				var text = jQuery("div.commentForm textarea[name='text']");
				
				if (jQuery(author).val().length == 0) {
					jQuery(author).css("backgroundColor", "#FFDDE2");
					success = false;
				}
				
				if (jQuery(email).val().length == 0) {
					jQuery(email).css("backgroundColor", "#FFDDE2");
					success = false;
				}
				
				if (jQuery(text).val().length == 0) {
					jQuery(text).css("backgroundColor", "#FFDDE2");
					success = false;
				}
				
				if (success == true) {
					document.forms[0].submit();
				}				
			});
		}		
	}
}
