jQuery(document).ready(function(){
	commentBind();
});

function commentSubmit() {
	if (!validate('#xcapCommentForm')) {
		return false;
	}
		
	// Support both with an without tinymce
	if (window['tinyMCE'] && tinyMCE.activeEditor)
	{
		var content = tinyMCE.activeEditor.getContent();
		jQuery("#xcapComment_text").val(content);
	}
	
	jQuery("#xcapCommentForm").ajaxSubmit( {
		target :'#commentBox', // target element(s) to be updated
		// with server response
		success : function(responseText, textStatus) {
			jQuery("#commentBox a.abuse").click(function() {
				jQuery("#abuse_dialog").empty();
				var href = jQuery(this).attr("href");
				jQuery("#abuse_dialog").load(href);
				jQuery("#abuse_dialog").dialog("open");
				return false;
			});
			jQuery("#commentBox .showOnLoad").css("display", "inline");
			commentBind();
		}
	});
	
	return false;
}

function commentBind(){	
	if (jQuery("#xcapCommentForm textarea").length > 0){
		
		if (window['loadEditor']) { 
			loadEditor();
		}
		jQuery('#xcapCommentForm').submit(function() {
			commentSubmit();
			return false;
		});
	}
}	

