﻿var colpanEnabled = true;
var colpanHasCheckbox = false;
var colpanCheckbox, colpanExpand, colpanCollapse;
var colpanOldObjs = 0;
var colpanOldObj = new Array();
var colpanOldImg = new Array();

function initCollapsingPanel(checkboxId, imgExpand, imgCollapse) {
	if ((!document.getElementById) && (!document.getElementsByTagName)) {
		alert('It appears you are using an old or non-mainstream web browser.  To use this page, please use a recent version of any popular web browser, including Microsoft IE, Firefox, Netscape, Opera, etc.');
		colpanEnabled = false;
		return false;
	}
	
	if (checkboxId.length > 0) {
		var chkid;
		var cary = document.getElementsByTagName('input');
		var citems = cary.length;

		for (var c=0; c<citems; c++) {
			if (cary[c].type == 'checkbox') {
				chkid = cary[c].id;
				if (chkid.indexOf(checkboxId) >= 0) {
					colpanHasCheckbox = true;
					colpanCheckbox = document.getElementById(chkid);
					c = citems + 1;
				}
			}
		}
	}
	
	colpanExpand = imgExpand;
	colpanCollapse = imgCollapse;
};

function CollapsePanelToggle(id) {
	if (!colpanEnabled) {
		return false;
	}
	
	var obj = document.getElementById(id);
	var img = document.getElementById(id + '_Img');

	if (obj.style.display == 'none') {
		obj.style.display = 'block';
		img.src = colpanCollapse;
	}
	else {
		obj.style.display = 'none';
		img.src = colpanExpand;
	}
	
	var notthere = true;

	if (colpanOldObjs > 0) {
		for (var i=0; i<colpanOldObjs; i++) {
			if (colpanOldObj[i] === obj) {
				notthere = false;
			}
			else {
				if (colpanHasCheckbox) {
					if (colpanCheckbox) {
						if (colpanCheckbox.checked) {
							colpanOldObj[i].style.display = 'none';
							colpanOldImg[i].src = colpanExpand;
						}
					}
				}
			}
		}
	}

	if (notthere) {
		colpanOldObjs++;
		colpanOldObj.length = colpanOldObjs;
		colpanOldObj[colpanOldObjs - 1] = obj;
		colpanOldImg.length = colpanOldObjs;
		colpanOldImg[colpanOldObjs - 1] = img;
	}
};
