function AddPagePreaks(){
	if (! (document.getElementById && document.getElementsByTagName) ) return;
	bd = $('bigdiv');
	if (!bd) return;
	tbls = bd.getElementsByTagName('table');
	for(var i = 0; i < tbls.length; i++ ){
		if (tbls[i].getElementsByTagName('tr').length > 45) {
			addPageBreak(tbls[i])
		}
	}
}
function addPageBreak( obj ) {
	var n = obj.previousSibling;
	while(n) {
		if (n.nodeName == 'H2' || n.nodeName == 'DIV') {
			jscss('add',n,'pagebreak');
			break;
		}
		n = n.previousSibling;
	}
}

addEvent(window,"load",AddPagePreaks);

var CheckBox = {
	Group : Object,
	Master : Object,
	checkAllGroups: function() {
		for( var group in this.Group ) {
			this.checkAll( group, 'all' );
			this.groupChecked( group, 'all' );
		}
	},
	checkAll: function ( group, all ) {
		inputs = document.getElementsByTagName('input');
		var flag = all == 'all' ? this.Master.checked : this.Group[group].actuator.checked;
		for (var i = 0; i < inputs.length; i++){
			if ( inputs[i].type != 'checkbox' || inputs[i].name.indexOf(group) < 0  ) continue;
			inputs[i].checked = flag;
		}
		if ( all != 'all') this.checkMaster();
	},
	groupChecked: function( group, all ) {
		inputs = document.getElementsByTagName('input');
		var flag = true;
		for (var i = 0; i < inputs.length; i++){
			if ( inputs[i].type != 'checkbox' || inputs[i].name.indexOf(group) < 0  ) continue;
			flag &= inputs[i].checked;
			if (flag) this.Group[group].numChecked++;
		}
		this.Group[group].allChecked = flag;
		this.Group[group].actuator.checked = flag;
		if ( all != 'all') this.checkMaster();
	},
	checkMaster: function() {
		var flag = true;
		for( var group in this.Group ) {
			flag &= this.Group[ group ].actuator.checked;
		}
		this.Master.checked = flag
	},
	toggle: function( group ) {
		 this.groupChecked( group );
	},
	createGroup: function (actuator, group) {
		var a = $( actuator );
		if ( !a ) return;
		a.groupName = group;
		a.onclick = function() { CheckBox.checkAll( this.groupName ); }
		this.Group[group] = { actuator: a, numChecked: 0, allChecked: false };
		
		inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++){
			if ( inputs[i].type != 'checkbox' || inputs[i].name.indexOf(group) < 0  ) continue;
			inputs[i].onclick = function() { CheckBox.toggle( this.groupName ); }
		}
		if ( a.checked ) CheckBox.checkAll( group );
	},
	init: function() {
		this.Master = $('chkSelectAll')
		if ( !this.Master ) return;
		this.Master.onclick = function () { CheckBox.checkAllGroups() };
		inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++){
			if (inputs[i].type == 'checkbox')
				inputs[i].groupName = inputs[i].name.split(':')[0];
		}
		with (this) {
			createGroup('chkWorkforce','cblWorkForce');
			createGroup('chkIncentives','cblIncentives');
			createGroup('chkEducation','cblEducation');
			createGroup('chkTelecommunications','cblTelecommunications');
			createGroup('chkLiving','cblLiving');
			createGroup('chkTransportation','cblTransportation');
			createGroup('chkTaxes','cblTaxes');
			createGroup('chkUtilities','cblUtilities');
			createGroup('chkDemographics','cblDemographics');
		}
	}
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}