//Checks the number of characters in the nominated textbox against the specified limit
//field - the control to check
//countfield - the control to store the count
//maxlimit - the maximum number of characters permitted
function textCounter(field, countfield, maxlimit) 
{
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
    alert("Maximum limit of " + maxlimit + " characters has been exceeded. Information may be lost.");
  }
  else {
    countfield.value = maxlimit - field.value.length;
  }
}

//Presents confirm message box to user
function confirmDelete ( strItemName )
{
	return confirm('Are you sure you want to delete: ' + strItemName + '\n\n');
}

// 21/10/07 BPB 
// Checks/unchecks all of the checkboxes (aspxCheckBoxID) based on the value of the 'Select All' checkbox (currBox)
function CheckAllCheckBoxes(aspxCheckBoxID, currBox)
{
	var theBox = (currBox.type == "checkbox") ? currBox : currBox.children.item[0];
	xState = theBox.checked;
	
		var reg = new RegExp( aspxCheckBoxID + "$" );
		var pageElements = document.getElementsByTagName("input");
		for(i = 0; i < pageElements.length; i++) {
				elm = pageElements[i];
				if (elm.type == 'checkbox')
				{
						if (reg.test(elm.name))
						{  
								elm.checked = xState;
						}
				}
		}
}

// 21/10/07 BPB 
// This checks if all checkboxes (aspxCheckBoxID) are checked
// It then flags the 'select all' checkbox (aspxCheckBoxAllID) accordingly 
// (i.e. if not all are checked the select all wont be selected anymore)
function AllChecked(aspxCheckBoxID, aspxCheckBoxAllID) 
{
	var bAllChecked = true;
	
	var reg = new RegExp( aspxCheckBoxID + "$" );
	var pageElements = document.getElementsByTagName("input");
	for(i = 0; i < pageElements.length; i++) 
	{
			elm = pageElements[i];
			if (elm.type == 'checkbox')
			{
				if (reg.test(elm.name) && !elm.checked)
				{
						bAllChecked = false;
				}
			}
	}

	//Switch the Select All checkbox depending on if all others are now checked or not
	reg = RegExp( aspxCheckBoxAllID + "$" );
	for(i = 0; i < pageElements.length; i++) 
	{
			elm = pageElements[i];
			if (elm.type == 'checkbox')
			{
					if (reg.test(elm.name))
					{
						elm.checked = bAllChecked;
					}
			}
	}
}
