/* ------------------------------------------------------------
 * PROJECT        : FHSC Interface Standard
 * FILENAME       : jqcheckboxes.js
 * ------------------------------------------------------------
 * DATE CREATED   : 11 Sep 2006
 * LAST UPDATED   : 06 May 2008
 * ------------------------------------------------------------
 * AUTHOR(S)      : Kevin Scholl (http://www.ksscholl.com/)
 * ------------------------------------------------------------ */

/* ------------------------------------------------------------
 * EXTEND JQUERY PLUGINS
 * ------------------------------------------------------------ */

$.fn.checkedZ = function() {
	return this.each(function(){
		this.checked = true;
		});
	}
$.fn.uncheckedZ = function() {
	return this.each(function(){
		this.checked = false;
		});
	} 
$.fn.checkToggle = function() {
	return this.each(function() {
		this.checked = !this.checked;
		});
	}
	
$.fn.btnState = function() {
	return this.each(function() {
		var	NUM_CHECKED_BOX = 0;
		// determine how many boxes are checked...
		$(this).find("input[type='checkbox']:not(.checkboxAll)").each(function() {
			if (this.checked == true)
				NUM_CHECKED_BOX = NUM_CHECKED_BOX + 1;
			});	
		// ...and show appropriate active states of control buttons
		$(this)
			.find("img.btnDetailView")
			  .attr("src",(NUM_CHECKED_BOX == 1) ? "images/btn_detailview.gif" : "images/btn_detailview_dim.gif").end()
			.find("img.btnView")
			  .attr("src",(NUM_CHECKED_BOX == 1) ? "images/btn_view.gif" : "images/btn_view_dim.gif").end()
		});
	}
	
/* ------------------------------------------------------------
 * CHECK/UNCHECK ALL CHECKBOXES IN THE FORM
 * ------------------------------------------------------------ */

var frmCheckbox     = null;

$(document).ready(function(){
													 
  $("input[type='checkbox']").addClass("checkBox")

  $("input[type='checkbox'].checkboxAll")
		.click(function() {
			frmCheckbox = $(this).parents('form').attr('id');
			this.checked ? 
				+ $("#" + frmCheckbox + " input[@type='checkbox']:not(:disabled)").checkedZ() : 
				+ $("#" + frmCheckbox + " input[@type='checkbox']").uncheckedZ();
//			$("#" + frmCheckbox).btnState();
//			return;
		  });
		
  $("input[type='checkbox']:not(.checkboxAll)")
		.click(function() {
			frmCheckbox = $(this).parents('form').attr('id');
			if (this.checked == false)
			  $("#" + frmCheckbox + " input[@type='checkbox'].checkboxAll").attr("checked",false);
			$("#" + frmCheckbox).btnState();
		  });

  }); // end ready function
