﻿/***********************************************
* Limit number of checked checkboxes script- by JavaScript Kit (www.javascriptkit.com)
* This notice must stay intact for usage
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more
***********************************************/

function checkboxlimit(checkgroup, limit, selectionName)
{
	var checkgroup=checkgroup
	var limit=limit
	
	if (checkgroup != null)
	{
		for (var i=0; i<checkgroup.length; i++)
		{
			checkgroup[i].onclick=function()
			{
				var checkedcount=0
				for (var i=0; i<checkgroup.length; i++)
					checkedcount+=(checkgroup[i].checked)? 1 : 0
				if (checkedcount>limit)
				{
					alert("No more than "+ limit +" "+ selectionName + " can be selected")
					this.checked=false
				}
			}
		}
	}
}

function IsAtLeastChecked(checkgroup, limit) 
{
    var checkgroup = checkgroup
    var limit = limit

    if (checkgroup != null) 
    {   
        var checkedcount = 0
        for (var i = 0; i < checkgroup.length; i++) 
        {
            checkedcount += (checkgroup[i].checked) ? 1 : 0
        }

        if (checkedcount >= limit) 
        {
            return true;
        }

        return false;
    }
}


function IsChecked(checkgroup, limit) 
{
	var checkgroup = checkgroup
	var limit = limit

	if (checkgroup != null) 
	{
		if (checkgroup.length == 0) 
		{
			return true;
		}
		
		var checkedcount = 0
		for (var i = 0; i < checkgroup.length; i++) {
			checkedcount += (checkgroup[i].checked) ? 1 : 0
		}

		if (checkedcount >= limit) {
			return true;
		}

		return false;
	}

	return true;
}

