/*
 * Toggle all checkboxes contained within a form
 *
 * @name     toggleCheckboxes
 * @param    ignore  Checkboxes to ignore
 * @example  $("#myform").toggleCheckboxes();
 * @example  $("#myform").toggleCheckboxes("[@name=ignorethis]");
 *
 */
jQuery.fn.toggleCheckboxes = function(ignore)
{
	ignore = ignore || [];
	return this.each(
		function()
		{
			jQuery("input[@type=checkbox]", this).not(ignore).each(
				function()
				{
					this.checked = !this.checked;
				}
			)
		}
	)
}




/*
 * Check all checkboxes contained within a form
 *
 * @name     checkCheckboxes
 * @param    ignore  Checkboxes to ignore
 * @example  $("#myform").checkCheckboxes();
 * @example  $("#myform").checkCheckboxes("[@name=ignorethis]");
 *
 */
jQuery.fn.checkCheckboxes = function(ignore)
{
	ignore = ignore || [];
	return this.each(
		function()
		{
			jQuery("input[@type=checkbox]", this).not(ignore).each(
				function()
				{
					this.checked = true;
				}
			)
		}
	)
}

/*
 * UnCheck all checkboxes contained within a form
 *
 * @name     unCheckCheckboxes
 * @param    ignore  Checkboxes to ignore
 * @example  $("#myform").unCheckCheckboxes();
 * @example  $("#myform").unCheckCheckboxes("[@name=ignorethis]");
 *
 */
jQuery.fn.unCheckCheckboxes = function(ignore)
{
	ignore = ignore || [];
	return this.each(
		function()
		{
			jQuery("input[@type=checkbox]", this).not(ignore).each(
				function()
				{
					this.checked = false;
				}
			)
		}
	)
}

/*
 * Makes checkboxes behave like a radio button group
 *   i.e. only one can be selected at a time
 *
 * @name     radioCheckboxGroup
 * @param    name  field name
 * @example  $.radioCheckboxGroup("fieldname");
 *
 */
jQuery.radioCheckboxGroup = function(name)
{
	var x = jQuery("input[@name=" + name + "]");
	x.click(
		function()
		{
			// uncheck every other box with the same name
			x.not(this).each(
				function()
				{
					this.checked = false;
				}
			).end();
		}
	);
}










/*
 * Restore a pre-selected selection of checkboxes (almost like an undo)
 *   i.e. the knobhead client ticks a load of shit and forgets what the defaulst were
 *
 * @name     resetCheckboxes
 * @param    name  field name
 * @example  $.restCheckboxes(coloursArray);
 * @author	stuart sillitoe for pulse8
 */
jQuery.fn.resetCheckboxes = function(coloursArray)
{
	return this.each(
		function()
		{
			for (i=0;i<coloursArray.length;i++)
			{
				jQuery("input[@value=" + coloursArray[i] + "]", this).each(
					function()
					{
						this.checked = true;
					}
				)
			}
		}
	)
}