// Set the default "show" mode to that specified by W3C DOM
// compliant browsers

var showMode = 'table-cell';

// However, IE5 at least does not render table cells correctly
// using the style 'table-cell', but does when the style 'block'
// is used, so handle this

if (document.all) showMode='block';

// This is the function that actually does the manipulation

function toggleVis(btn){

	var counterForChecked = 0;
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "checkbox" && inputs[i].checked == true) {
			counterForChecked++;
		}
	}

	seeMoreLink = document.getElementById("extendedTableLink");

	if (counterForChecked <= 16) {

		for (var i = 0; i < inputs.length; i++) {
			if (inputs[i].type == "checkbox" && inputs[i].checked == false) {
				inputs[i].disabled = false;
			}
		}

		// First isolate the checkbox by name using the
		// name of the form and the name of the checkbox

		btn   = document.forms['tcol'].elements[btn];

		// Next find all the table cells by using the DOM function
		// getElementsByName passing in the constructed name of
		// the cells, derived from the checkbox name

		cells = document.getElementsByName('t'+btn.name);

		// Once the cells and checkbox object has been retrieved
		// the show hide choice is simply whether the checkbox is
		// checked or clear

		mode = btn.checked ? showMode : 'none';

		// Apply the style to the CSS display property for the cells
		for(j = 0; j < cells.length; j++) {
			cells[j].style.display = mode;
		}

		seeMoreLink.style.display = "none";

		if (counterForChecked == 16) {
			for (var i = 0; i < inputs.length; i++) {
				if (inputs[i].type == "checkbox" && inputs[i].checked == false) {
					inputs[i].disabled = true;
				}
			}
			seeMoreLink.style.display = "block";
		}
	} else {
		for (var i = 0; i < inputs.length; i++) {
			if (inputs[i].type == "checkbox" && inputs[i].checked == false) {
				inputs[i].disabled = true;
			}
		}
		seeMoreLink.style.display = "block";
	}
}

function toggleVisExtended(btn){

	// First isolate the checkbox by name using the
	// name of the form and the name of the checkbox

	btn   = document.forms['tcol'].elements[btn];

	// Next find all the table cells by using the DOM function
	// getElementsByName passing in the constructed name of
	// the cells, derived from the checkbox name

	cells = document.getElementsByName('t'+btn.name);

	// Once the cells and checkbox object has been retrieved
	// the show hide choice is simply whether the checkbox is
	// checked or clear

	mode = btn.checked ? showMode : 'none';

	// Apply the style to the CSS display property for the cells
	for(j = 0; j < cells.length; j++) {
		cells[j].style.display = mode;
	}
}

function toggleCustomColumnsOnLoad(extended) {

	var inputs = document.getElementsByTagName("input");
	//	alert(inputs[19]);
	//	alert(inputs[19].value);
	//	alert(inputs[19].type);
	//	alert(inputs[19].name);
	//	alert(inputs[19].checked);
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "checkbox" && inputs[i].checked == false) {
			if (extended == false) {
				toggleVis(inputs[i].name);
			} else {
				toggleVisExtended(inputs[i].name);
			}
		}
	}
}

function openPopupWindow(filename) {
	window.open(filename,"mywindow","menubar=1,resizable=1,width=800,height=500");
}
