function updateComment(commentForm, parentIDX){
	var commentForm = "#"+commentForm+" :input";
	
	$j.ajax({
		url: "index.php?name=Comment&method=save&parentIDX="+parentIDX,
		type: "POST",
		async: false,
		data: $j(commentForm)
	});
	
	window.opener.location.reload();
}

function showHideComments(nodeIDX, module) {	
	$j.ajax({
		url: "index.php?name=Comment&method=showHideComments&module="+module+"&nodeIDX="+nodeIDX+"&retBool=true&parentIDX="+nodeIDX,
		type: "GET",
		async: false,
		success: function(bShowContainer) {
			// Container is visible, so hide it
			if(bShowContainer == "true") {
				$j("#CommentContainer").hide();
				$j.ajax({url: "index.php?name=Comment&method=showHideComments&module="+module+"&nodeIDX="+nodeIDX+"&parentIDX="+nodeIDX, type: "GET"});
				$j("#commentBarImage").attr('src',"images/navigation/s_left.gif");
			}
			
			// Container is hiding, so show it
			else if(bShowContainer == "false") {
				$j("#CommentContainer").load("index.php?name=Comment&parentIDX="+nodeIDX).show();
				$j.ajax({url: "index.php?name=Comment&method=showHideComments&module="+module+"&nodeIDX="+nodeIDX+"&parentIDX="+nodeIDX, type: "GET"});
				$j("#commentBarImage").attr('src',"images/navigation/s_down.gif");
			}
		}
	});
}

function commentPreFormValidation(){
	var parentIDX = $j("#parentIDX").val();
	var sc_code = $j("#sc_code").val();
	var rtvalue = "";
	
	if(sc_code != ""){
		$j.ajax({
			type: "GET",
			async: false,
			url: "index.php?name=Comment&method=checkCaptcha&sc_code="+sc_code+"&parentIDX="+parentIDX,
			dataType: "html",
			success: function(response){
				if(response == 'false'){
					rtvalue = Common.getLocale(objLC.js_captchaError,'js_captchaError');
				}
				else if(response == 'true'){
					rtvalue = true;
				}
			}
		});
	}
	
	return rtvalue;
}

function sendComment(nodeIDX, targetElement) {
	if(document.getElementById('sc_code')){
		$bPass = jQuery.validationAide.validateForm("#commentForm", null, {showInlineMessages:false, showSummary:true}, commentPreFormValidation);
	}
	else{
		$bPass = jQuery.validationAide.validateForm("#commentForm", null, {showInlineMessages:false, showSummary:true})
	}
	
	if($bPass){
		var commentForm = $j("#commentForm :input").serialize();
		var resp = null;
		$j.ajax({
			url: "index.php?name=Comment&parentIDX="+nodeIDX+"&method=save",
			type: "POST",
			async: false,
			data:commentForm,
			success: function() {
				$j.ajax({
					url: "index.php?name=Comment&parentIDX="+nodeIDX,
					type: "POST",
					async: false,
					success: function(response) {
						resp = response;
						$j("#CommentContainer").html(resp);
					}
				});
				
			}
		});
	
		$j("#comment_count").html($j(".comment_container").length);
	}
}

function deleteComment(nodeIDX, parentIDX, elementIDX, confirmText){
	var deleteNewsComment = confirm(confirmText);
	
	if(deleteNewsComment){
		$j.ajax({
			url: "index.php?name=Comment&method=delete&parentIDX="+parentIDX+"&nodeIDX="+nodeIDX,
			type: "GET",
			async: false
		});
		
		$j(elementIDX).remove();
	}
	$j("#comment_count").html($j(".comment_container").length);
}

function editComment(nodeIDX, parentIDX){
	url = "index.php?name=Comment&method=update&parentIDX="+parentIDX+"&nodeIDX="+nodeIDX

	window.open(url, '_blank', 'toolbar=no, location=0, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, address=no, width=500, height=400');
}

function closeCommentForm(){
	window.opener.location.reload();
	window.close();
}
