function show_comment_block(block, num){
	var block = document.getElementById(block);
	block.style.display = 'block';
	
	var current_block_num = document.getElementById('current_block_num');
	 var current_block = document.getElementById('comment_block_'+current_block_num.value+'');
	 current_block.style.display = 'none';	
	 
	 current_block_num.value = num;
}

function show_comment_block2(block, num, start, end, total, comm_per_page, total_comms){
	
	
	var current_block_num = document.getElementById('current_block_num');
	
	if (num != current_block_num.value){
	
		//alert(current_block_num.value);
		
		//Set block to viewable
		 var block = document.getElementById(block);
		 block.style.display = 'block';
		
		 var current_block_num = document.getElementById('current_block_num');
		 var current_block = document.getElementById('comment_block_'+current_block_num.value+'');
		 current_block.style.display = 'none';	
		 
		 current_block_num.value = num;
		 
		 
		 
		 
		 
		 //return(true);
		 
		 
		 //update the showing text
		 
		 
		 
		 var start_comm = (comm_per_page * (num-1)) + 1;
		 
		 if (num == total){
		 	var end_comm = total_comms;
		 }else{
		 	var end_comm = (comm_per_page * num);
		 }
		 
		 var showing = 'Showing ' + start_comm + '-' + end_comm + ' of ' + total_comms;
		 //alert(showing);

 		 var showing1 = document.getElementById('showing1');
		 var showing2 = document.getElementById('showing2');
		 
		 showing1.innerHTML = showing;
		 showing2.innerHTML = showing;
		 
		 //update the pagination
		 var pagination1 = document.getElementById('comment_pagination_1');
		 var pagination2 = document.getElementById('comment_pagination_2');
		 
		 
		 var max_links = (end - start) + 1;
		 
		 var pagination_text = '';
		 
		 for (x=start; x<=end; x=x+1){
		 
		 	if (x == num){
		 		pagination_text = pagination_text + '<li class="active">' + x;
		 	
		 	}else{
		 	
		 		if (x < Math.ceil(max_links/2)){
					var pstart = 1;
					var pend = max_links;
					
					//alert('ONE: ' + i + ' - ' + start + ' - ' + end);
				
				}else if(x > (total - (max_links/2))){
					var pend = total;
					var pstart = total - (max_links-1);
					
					//alert('TWO: ' + x + ' - ' + start + ' - ' + end);
				
				}else{
					//$start = $i - floor(($max_links-1)/2) + 1;
					//$end = $i + floor(($max_links-1)/2);
					var pstart = x - Math.floor((max_links-1)/2);
					var pend = x + Math.floor(max_links/2);
					
					//alert('THREE: ' + x + ' - ' + start + ' - ' + end);
				
				}
		 	
		 		pagination_text = pagination_text + '<li>';
		 		
		 		pagination_text = pagination_text + '<a href="" onclick="show_comment_block2(\'comment_block_' + x + '\', ' + x + ', ' + pstart + ', ' + pend + ', ' + total +', ' + comm_per_page + ',' + total_comms + '); return false;">' + x + '</a>';
		 	}
		 	
		 	
		 	
		 	
		 	
		 	
		 	
		 	if (x<end){
		 		pagination_text = pagination_text + '&nbsp;|&nbsp;';
		 	}
		 	pagination_text = pagination_text + '</li>';
		 
		 }
		 
		pagination_text = pagination_text + '<li> &nbsp; of ' + total + '</li>';
		
		//alert(pagination_text);
		
		pagination1.innerHTML = pagination_text;
		pagination2.innerHTML = pagination_text;
	
	} //end if num!=
}



function submit_comment(filename, type, userID, usernick){
	var tarea = $('comment-ta-sm');
	
	//alert(filename + ' ' + type + ' ' + userID + ' ' + usernick);
	

	if(userID > 0){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				commentFormSuccess(t);
			},		
			onSuccess: function(t) {
				//commentFormSuccess(t);
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		new Ajax.Request('/comment_ajax.php?userID='+encodeURIComponent(userID)+'&usernick='+encodeURIComponent(usernick)+'&comment='+encodeURIComponent(tarea.value)+'&type='+encodeURIComponent(type)+'&filename='+encodeURIComponent(filename), opt);
	}else{
		alert('You Must Login to Comment.');
	}

}


function commentFormSuccess(t){
	var commentform = document.getElementById('commentform2');
	commentform.innerHTML = t.responseText;
	var commentnum = $('commentnum');
	var num = commentnum.innerHTML;
	num = parseInt(num.replace(/\,/, ''));
	commentnum.innerHTML = addCommas(num+1);

}