// selectAll()
// 
function selectAll(fObj, which, pattern) { 
	if (fObj.elements.length > 0) { 
 		for (var i = 0; i < fObj.elements.length; i++) { 
 			if (fObj.elements[i].name) { 
 				if (eval('fObj.elements['+ i +'].name.match(/^'+ which +'_'+ pattern +'/i)') && 
				! fObj.elements[i].checked) { 
					fObj.elements[i].checked = true; 					
				} 
			} 			
		} 
		saveUnsaveSelection(fObj, which);  
	}
} 

function saveUnsaveSelection(fObj, which) { 
	if (fObj.elements.length > 0) { 
		eval('fObj.hidden_selections_'+ which +'.value = "";');
		var checked = '';
		for (var i = 0; i < fObj.elements.length; i++) { 
			if (eval('fObj.elements['+ i +'].name.match(/^'+ which +'/)') && fObj.elements[i].checked) {
				checked += fObj.elements[i].value +','
			}
		} 
		eval('fObj.hidden_selections_'+ which +'.value = "'+ checked.substring(0, checked.length - 1) +'";');
	} 
} 

// writeDiv() 
// This function (re)writes the "selectedx" div. It should work with different 
// web browsers. It's not called directly. It's invoked (currently) by the 
// saveUnsaveSelect(). (See the comments above for that.) 
function writeDiv(which, what) { 
	var div = 'selected'+ which; 
	if (document.getElementById) {
		var obj = document.getElementById(div);
		obj.innerHTML = what; 
	} else if (document.all) {
		var obj = document.all[div];
		obj.innerHTML = what;
	} else if (document.layers) {
		var obj = document.layers[div].document;
		obj.open();
		obj.write(what);
		obj.close();
	} 
} 

// showHideDiv() 
// This function shows or hides the "popup" div, though it doesn't actually do 
// the hiding/unhiding itself -- look at the toggleDiv() function for how that 
// part works. This function's invoked by clicking the "Add/Edit List" anchor 
// (link) under each of the four lists, and also by the "Close" anchor on the 
// popups themselves. 
function showHideDiv(which) { 
	toggleDiv('shadow'+ which); 
	toggleDiv('select'+ which); 
} 

// toggleDiv() 
// This fucntion shows or hides the div, passed to it by its ID. As with the 
// writeDiv() function above, this should work with different web browsers on 
// different operating systems, i.e., it's not crippled by being limited to 
// being run in a single browser (Internet Explorer) on a single OS (Windows). 
function toggleDiv(div) {
	if (document.getElementById) {
		var obj = document.getElementById(div);
		obj.style.display = obj.style.display ? '' : 'block';
	} else if (document.all) {
		var obj = document.all[div];
		obj.style.display = obj.style.display ? '' : 'block';
	} else if (document.layers) {
		var obj = document.layers[div];
		obj.style.display = obj.style.display ? '' : 'block';
	}	
} 

// initPage()
// This function "pops" the first list's popup when the page is initially load-
// ed. Not unsurprisingly, it's invoked only in the onload property of the body 
// tag. 
function initPage() { 
	showHideDiv('1st'); 
	saveUnsaveSelection(document.forms[0], '1st'); 
	saveUnsaveSelection(document.forms[0], '2nd'); 
	saveUnsaveSelection(document.forms[0], '3rd'); 
	saveUnsaveSelection(document.forms[0], '4th'); 
} 
