function addLoadEvent(func) {
	
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}




function checkAll() {

	if (!document.getElementById) return false;
	
	var webpayroll = document.getElementById('webpayroll')
	var humanresources = document.getElementById('humanresources');
	var timeandattendance = document.getElementById('timeandattendance');
	var totalworkforce = document.getElementById('totalworkforce');

	if (webpayroll.checked != true || humanresources.checked != true || timeandattendance.checked != true) {
		webpayroll.checked = true;
		humanresources.checked = true;
		timeandattendance.checked = true;
		totalworkforce.checked = true;
	} else {
		webpayroll.checked = false;
		humanresources.checked = false;
		timeandattendance.checked = false;
		totalworkforce.checked = false;
	}
	
	
}

function uncheckTotalWorkforce() {

	if (!document.getElementById) return false;
	
	var webpayroll = document.getElementById('webpayroll')
	var humanresources = document.getElementById('humanresources');
	var timeandattendance = document.getElementById('timeandattendance');

	var totalworkforce = document.getElementById('totalworkforce');

	if (humanresources.checked != true || timeandattendance.checked != true || webpayroll.checked != true) {
		totalworkforce.checked = false;
	} else {
		totalworkforce.checked = true;
	}
	
	
}

/*
 * Create the XMLHttpRequest object
 */

var xmlhttp=false;
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}


/*
 * Adds the JavaScript to the XHTML, so it is unobtrusive
 */

function prepareForm() {
	
	if (!document.getElementById) return false; 

	var totalworkforce = document.getElementById('totalworkforce');
	totalworkforce.onclick = function() {
		checkAll();
	//	return false;
	}

	var humanresources = document.getElementById('humanresources');
	humanresources.onclick = function() {
		uncheckTotalWorkforce();
	}

	var timeandattendance = document.getElementById('timeandattendance');
	timeandattendance.onclick = function() {
		uncheckTotalWorkforce();
	}
	
	var webpayroll = document.getElementById('webpayroll');
	webpayroll.onclick = function() {
		uncheckTotalWorkforce();
	}
}


// Add the JavaScript to appropriate places so it's not obtrusive in the XHTML
addLoadEvent(prepareForm);