﻿Lotb = function(lst, args) {
	this.lst = lst;
	this.txt = document.getElementById(args[0]);
	this.ctl = document.getElementById(args[1]);
	this.rqv = document.getElementById(args[2]);
	this.useDisplay = args[3] == 'Dynamic';
}
Lotb.init = function() {
	for (var i = 0, as = arguments[0]; i < as.length; i++) {
		var vs = as[i].split('|'), lst = document.getElementById(vs[0]);
		if (!lst || vs.length < 2) continue;
		lst.lotb = new Lotb(lst, vs.slice(1));
	}
}
Lotb.toggle = function(lst, ovalue) {
	if (lst.lotb) lst.lotb.toggle(ovalue);
}
Lotb.prototype = {
	_isO: function(lst, ovalue) {
		var isS = lst.tagName == 'SELECT';
		if (!lst.oth) {
			var opts = (isS) ? lst.options : lst.getElementsByTagName('INPUT'), i;
			if (opts.length && opts[0].type == 'checkbox') {
				var id = lst.id + '_' + ovalue;
				for (i = 0; i < opts.length; i++)
					if (opts[i].id == id) {
					lst.oth = opts[i];
					break;
				}
			} else
				for (i = 0; i < opts.length; i++)
				if (opts[i].value == ovalue) {
				lst.oth = opts[i];
				break;
			}
		}
		return (!lst.oth) ? false : (isS) ? lst.oth.selected : lst.oth.checked;
	},
	toggle: function(ovalue) {
		var lst = this.lst, txt = this.txt;
		if (!lst || !txt) return;
		var isO = Lotb.prototype._isO(lst, ovalue);
		if (this.useDisplay) {
			var display = (isO) ? '' : 'none';
			txt.style.display = display;
			if (this.ctl) this.ctl.style.display = display;
		} else {
			var visible = (isO) ? 'visible' : 'hidden';
			txt.style.visibility = visible;
			if (this.ctl) this.ctl.style.visibility = visible;
		}
		if (this.rqv) ValidatorEnable(this.rqv, isO);
		if (isO) txt.focus();
	}
}; //	this semi-colon has to be here for minifier

