/*
 *  Javascript functions for accessing the comments of an object, by page
 *  Written by Jens Alm 2008 for the toddy.nu django homepage
 *
 ***********************************************************************/

function load_comment_container(page_number) {
	$("#comment_container").animate({opacity:'0%'},'fast', function(){
		$("#comment_container").load(comment_get_url, {"page_number":page_number}, function(){
			$("#comment_container").animate({opacity:'100%'},'fast');
		});
	});
}

function set_paginator(page_number, max_pages) {
	$("#comment_paginator_current_page").html(comment_page_number);			
	$("#comment_paginator_max_pages").html(comment_max_pages);	
	$("#comment_paginator_left_button").removeClass("button_active");
	$("#comment_paginator_left_button").addClass("button_inactive");		
	$("#comment_paginator_right_button").removeClass("button_active");
	$("#comment_paginator_right_button").addClass("button_inactive");		
	if (page_number > 1) {
		$("#comment_paginator_left_button").removeClass("button_inactive");
		$("#comment_paginator_left_button").addClass("button_active");		
	}
	if (page_number < max_pages){	
		$("#comment_paginator_right_button").removeClass("button_inactive");
		$("#comment_paginator_right_button").addClass("button_active");		
	}
}

function turn_to_page(page_number) {
	comment_page_number = page_number;
	load_comment_container(comment_page_number);
	set_paginator(comment_page_number, comment_max_pages);
}

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};