<!--
function addPanel(container) {
	container.insertBefore(container.panels[container.last], getDesc(container, GET_ATT, 'name', 'actuator'));
	container.last++;
	display(container.removeButton, (container.last <= container.min) ? false : true);
	display(container.addButton, (container.last >= container.max) ? false : true);
}
	 
function initCasPanel(container) {
	container.count = parseInt(container.getAttribute("count"));	
	container.min = parseInt(container.getAttribute("min"));
	container.max = parseInt(container.getAttribute("max"));
	for(var i=1; i<=container.max; i++) {
		var panel = getDesc(container, GET_ATT, 'name', container.id +i);
		panel.removeChild(getDesc(panel, GET_ID, 'last'+i));
	}	
	container.panels = new Array(container.max);
	container.last = container.max;
	var act = document.createElement('DIV');
	act.setAttribute('name', 'actuator');
	act.setAttribute('align', 'center');
	container.appendChild(act);
	var addButton = document.createElement('A');
	addButton.className = 'panelLink';
	addButton.setAttribute('href', "javascript:addPanel(document.getElementById('" + container.id + "'));");
	addButton.appendChild(document.createTextNode('Click here to add another ' + container.id.replace(/_/g, ' ')));
	act.appendChild(addButton);
	container.addButton = addButton;
	var removeButton = document.createElement('A');
	removeButton.className = 'panelLink';
	removeButton.setAttribute('href', "javascript:removePanel(document.getElementById('" + container.id + "'));");
	removeButton.appendChild(document.createTextNode('Click here to remove last ' + container.id.replace(/_/g, ' ')));
	act.appendChild(removeButton);
	container.removeButton = removeButton;
	for(var i=container.max; i > container.count; i--)
		removePanel(container, false);
	if(container.count >= container.max) {
		display(container.removeButton, (container.last <= container.min) ? false : true);
		display(container.addButton, (container.last >= container.max) ? false : true);
	}
}

function hidePanel(container) {
	while(container.last > 0) 
		removePanel(container, false);
	display(container, false);
}		

function initializeCasPanels() {
	var div = document.getElementsByTagName('DIV');
	for(var i=0; i<div.length; i++)
		if(div[i].getAttribute('type') == 'caspanel')
			initCasPanel(div[i]);
}

function removePanel(container, prompt) {
	if(prompt && !confirm('Data in this section will be lost if removed. Proceed?'))
		return;
	var panel = container.removeChild(getDesc(container, GET_ATT, 'name', container.id + container.last));
	container.panels[container.last-1] = panel;
	container.last--;
	display(container.removeButton, (container.last <= container.min) ? false : true);
	display(container.addButton, (container.last >= container.max) ? false : true);
}

function showPanel(container) {
	addPanel(container);
	display(container, true);
}

function checkBoxTrigger(el, container) {
	if(el.checked)
		hidePanel(container);
	else
		showPanel(container);
}				

function display(el, bool) { el.style.display = (bool) ? 'inline' : 'none'; }

var GET_FIRST  	=	1;
var GET_LAST   	=	2;
var GET_ID      =	4;
var GET_ATT     =	8;
var GET_ALL   	= 16;

function getDesc(_c, _f, _s, _v) {
	if(!_c || !_c.hasChildNodes())
		return null;
	var Lc;
	var Ll = _c.childNodes.length;
	for(var i=0; i<Ll; i++) {
		Lc = _c.childNodes[(_f & GET_LAST) ? Ll-1-i : i];
		if(Lc.nodeType != 1) 
			continue;
		if((_f & GET_ID) == GET_ID) {
			if(Lc.id == _s && (_v == null || _v == Lc.tagName))
				return Lc;
		}				
		else if((_f & GET_ATT) == GET_ATT) {
			var La = Lc.getAttribute(_s);
			if(La != null && (_v == null || La == _v))
				return Lc;
		}		
		else if(_s && (Lc.tagName == _s))
			return Lc;
		if((_f & GET_ALL) == GET_ALL) {
			var Lt = getDesc(Lc, _f, _s, _v);
			if(Lt != null)
				return Lt;
		}		
	}
	return null;
}

var browser = new Browser();	
function Browser() {
	this.isIE = (document.all) ? true : false;
	this.isNS = (document.layers) ? true : false;
}

function resetForm() {
	if(confirm("All data is lost when the form is reset. Proceed?"))
		return true;
	return false;
}		

var errors;
function addError(el, msg) {
	errors.count++;
	var error = document.createElement('A');
	error.className = 'error';
	error.id = 'error' + errors.count;
	error.setAttribute('href', 'javascript:getError("' + el.id + '", "' + error.id + '");');
	error.appendChild(document.createTextNode(el.id.replace(/_/g, ' ') + ':   ' + msg));
	errors.appendChild(error);
}

function getError(el, err) {
	err = document.getElementById(err);
	err.className = 'errorVisited';
	el = document.getElementById(el);
	el.focus();
}	

function isEmpty(el, postError) {
	if(postError == null)
		postError = true;
	el.value = trim(el.value);
	if(el.value != null && el.value != "")
		return false;
	if(postError)	
		addError(el, 'Value cannot be empty.');
	return true;
}

function isEmptyBoolean(el, postError) {
	if(postError == null)
		postError = true;
	if(el[0].checked || el[1].checked)
		return false;
	if(postError)
		addError(el[0], 'You must select either yes or no.');
	return true;	
}

function trim(str) { return str.replace(/^\s+/,'').replace(/\s+$/,''); }	

function isValid(type, el, postError) {
	var reg, msg;
	postError = (postError == null || postError == true) ? true : false;

	switch(type) {
		case 'EMAIL':	
			reg = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
			msg = 'Invalid email address.';
			break;
		case 'MM/DD/YYYY':
			reg = /^\d{2}\/\d{2}\/\d{4}$/;
			msg = 'Invalid date.';
			break;
		case 'MM/YYYY':
			reg = /^\d{2}\/\d{4}$/;
			msg = 'Invalid date.';
		 	break;
		case 'YEAR':
			$reg = /^[0-9]{4}$/;
			$msg = 'Invalid year.';
		 	break; 	
		case 'PHONE':
			reg = /^\d{3}-\d{3}-\d{4}$/;
			msg = 'Invalid phone number.';
			break;
		case 'ZIP':
			reg = /^\d{5}$/;
			msg = 'Invalid zip code.';
			break;
		case 'WHOLENUM':
			reg = /^(0|(([1-9][0-9]{0,2})(([0-9]{3})*|(,[0-9]{3})*)))$/;
			msg = 'Invalid number - use (xxxxxxxx or xx,xxx,xxx).';
			break;
		case 'MONEY':
			reg = /^((([1-9][0-9]{0,2})(([0-9]{3})*|(,[0-9]{3})*)(\.[0-9]{2})?)|(0?\.[0-9]{2}))$/;
			msg = 'Invalid dollar amount - use (xxxxxx.xx or xxxxxx or .xx).';
			break;	
	}
	if(reg.test(el.value))
		return true;
	if(postError)
		addError(el, msg);
	return false;	
}			 			
//-->
