$(document).ready(function() {	
			   
});

loadComments = function( articleID, postElement ){
	//params to pass to page
	var dataString = 	"articleID=" + encodeURIComponent(articleID) + 
						"&postElement=" + encodeURIComponent(postElement)
						
	var page = "/includes/components/comments/index.cfm";
	$.ajax({
		   	type: "POST",
		   	url: page,
		   	data: dataString,
			success: 
				function(data){
					$(postElement + " div.loader").fadeOut("slow",
						function(){
							$(postElement).html(data); 
						}
					);
				},
			error:
				function(xhr, ajaxOptions, thrownError){
	
				},
			beforeSend:
				function(){
					
				},	
			complete: 
				function(){

				}
				
		   });
	return false;
}

postComment = function(){
	var articleid = $("#articleid").val();
	var postElement = $("#postelement").val();
	var comment = $.trim($("#comment").val());
	
	//params to pass to page
	var dataString = 	"articleid=" + encodeURIComponent(articleid) + 
						"&postelement=" + encodeURIComponent(postElement) + 
						"&comment=" + encodeURIComponent(comment) +
						"&newcomment=true"
						
	var page = "/includes/components/comments/index.cfm";
	
	if(comment != ''){
		$.ajax({
				type: "POST",
				url: page,
				data: dataString,
				success: 
					function(data){
						$("#cbLoader").fadeOut("slow",
							function(){
								$(postElement).html(data);
								$("#comment").val(''); 
							}
						);
					},
				error:
					function(xhr, ajaxOptions, thrownError){
		
					},
				beforeSend:
					function(){
						$("#comment").css("border", "0px");
						$("#cbLoader").fadeIn();
					},	
				complete: 
					function(){
	
					}
					
			   });
		return false;
	}else{
		$("#comment").css("border", "1px solid red");
	}
}

deleteComment = function( commentID, articleID, postElement ){
	var dataString = 	"articleID=" + encodeURIComponent(articleID) + 
						"&postElement=" + encodeURIComponent(postElement) +
						"&deletecommentid=" + commentID
						
	var page = "/includes/components/comments/index.cfm";
	
	$.ajax({
		   	type: "POST",
		   	url: page,
		   	data: dataString,
			success: 
				function(data){
					$(postElement).html(data); 
				},
			error:
				function(xhr, ajaxOptions, thrownError){
	
				},
			beforeSend:
				function(){
					
				},	
			complete: 
				function(){

				}
				
		   });
	return false;
}
