// JavaScript Document


function showCommentForm(formId){
	
	var cForm = $('#'+formId) ;
	
	$('input.replyto',cForm).val(0);
	$('#comment_fields').slideToggle('fast', function() {
   
  	});
	
}

function addComment(){
	
	var articleid = $('#pageid').val() ;
	var author = escape($('#author').val()) ;
	var comment = escape($('#comment').val()) ;
	var captcha = escape($('#captcha_code').val()) ;
	
	var url = fullURL + '/inc/inc_articlefunctions.php?action=addcomment';
	var postBody = "pageid=" + articleid ;
		postBody += "&author=" + author ;
		postBody += "&comment=" + comment ;
		postBody += "&captcha_code=" + captcha ;		
		
		$.ajax({
			  url: url,
			  type: 'POST',
			  data: postBody,
			  success: function(responseText){
				  
				  	$('#commentsholder').html(responseText) ;
					//$('#commentadded').show() ;
					$('#author').val('');
					$('#comment').val('') ;
					//setTimeout($('#commentadded').fadeOut('slow', function() {}),5000) ;
					$('#comment_fields').slideToggle('slow', function() {
  					});
			  }
			});
		
	
}

function replyComment(commentId, formId){
	
	var cForm = $('#'+formId) ;
	var cSubject = "RE:" ;	
	
	if($('#comment_' + commentId + ' .comment_subject').length > 0){
		//alert($('#comment_' + commentId + ' .comment_subject').html())
		cSubject = "RE: " + $('#comment_' + commentId + ' .comment_subject').html();
	}
	
	$('input.replyto',cForm).val(commentId);
	$('input.comment_subject',cForm).val(cSubject);
	
	$('#comment_fields').slideToggle('fast', function() {
   
  	});
	
	
}

function addGenericComment(formId){
	
	var cForm = $('#'+formId) ;
	
	var url = fullURL + '/inc/inc_articlefunctions.php';
	
		var postData = cForm.serialize();
		
		$.ajax({
			  url: url,
			  type: 'POST',
			  data: postData,
			  success: function(responseText){
				  
				  
				  	$('#'+formId+"_outer").html(responseText) ;

					$('#' +formId + ' #author').val('');
					$('#' +formId + ' #comment').val('') ;
					
					//setTimeout($('#commentadded').fadeOut('slow', function() {}),5000) ;
					$('#' +formId + ' #comment_fields').slideToggle('slow', function() {
  					});
			  }
			});
		
	
}


function deleteComment(commentid){

	if(confirm("Do you want to delete this comment (and all replies?)")){
	
		url = fullURL + '/inc/inc_articlefunctions.php' ;
		var postBody = "action=deletecomment&commentid=" + commentid ;
		
		$.ajax({
				  url: url,
				  type: 'POST',
				  data: postBody,
				  success: function(responseText){	  
						$('#comment_' + commentid).fadeOut('slow', function() {}) ;
				  }
				});

	}
	
}
