function _getRoot(){
	var scs = document.getElementsByTagName('SCRIPT'), path = scs[scs.length-1].src;
	return path.substr(0, path.indexOf("scripts"));
}
var isOp = window.opera, isIE = document.all && !isOp, root = _getRoot();
for (var i=0, s_loc=root+"scripts/", scs=new Array("obj_pros", "dom"); i<scs.length; i++)
	document.write('<script language="javascript" src="' + s_loc + scs[i] + '.js" type="text/javascript"><\/script>');
//	***********	visual effects	*****************
function setStatus(text){
	window.status = text;
	return true;
}
function confirmReset(){
	var text = "This will reset all your changes on this page\r\nDo you want to continue?";
	if (!confirm(text))
		return false;
	else if (typeof(dirtyForm) == 'undefined' || !dirtyForm || !dirtyForm.Controls)
		return true;
	else{
		var ctls = dirtyForm.Controls, arg = arguments[0];
		if (ctls.isDirty()){
			ctls.reset();
			if (arg && arg.focus) arg.focus();
		}
		return false;
	}
}
function addFormSection(section){
	var form = getParentForm(section);
	if (form){
		sections = (form.sections) ? form.sections : new Array();
		sections[sections.length] = section;
		form.sections = sections;
	}
}
function selectList(list, ind){
	if (ind != -1){
		var opt = list.options[ind];
		if (opt) opt.selected = true;
	}
}
function setSelectByText(list, value){
	for (var i=0, opts=list.options; i<opts.length; i++)
		if (opts[i].text == value){
			list.selectedIndex = i;
			break;
		}
}
function getSelectText(list){
	with (list){
		if (selectedIndex != -1) return options[selectedIndex].text;
	}
}
function enableButton(inp, enable){
	var disable = (enable == false);
	inp.disabled = disable;
	inp.style.cursor = (disable) ? 'default' : (isIE) ? 'hand' : 'pointer';
	if (!isIE) inp.style.color = (disable) ? 'gray' : '';
}
function getEventSrc(ev){
	var ctl = (ev.target) ? ev.target : ev.srcElement;
	if (ctl){
		if (ctl.nodeType == 3) ctl = ctl.parentNode; // Safari
		return ctl;
	}
}
function checkChange(txt){
	var max = txt.getAttribute("maxlength");
	if (isNaN(max)) return;
	with (txt)
		if (value.length > max) value = value.substr(0, max);
}
function checkPaste(txt){
	var max = txt.getAttribute("maxlength"), clp = window.clipboardData;
	if (isNaN(max) || !clp) return;
	var text = clp.getData("Text");
	if (text){
		event.returnValue = false;
		document.selection.createRange().text = text;
		with (txt)
			if (value.length > max) value = value.substr(0, max);
	}
}
function checkKeyPress(ev){
	var txt = getEventSrc(ev);
	if (!txt) return true;
	var max = txt.getAttribute("maxlength");
	if (isNaN(max)) return true;
	var chars = new Array(8, 9, 37, 38, 39, 40, 46); //	8 - backspace, 9 - tab & 46 - delete 37-40 - arrows
	var charCode = (!ev.keyCode) ? ev.charCode : ev.keyCode;
	if (txt.value.length < max || chars.indexOf(charCode) != -1 || txt.selectionStart != txt.selectionEnd)
		return true;
	else{
		txt.value = txt.value.substr(0, max);
		return false;
	}
}
//	************	sections	************
function getValidators(section, isForm){
	if (typeof(Page_Validators) == 'undefined')
		return new Array();
	else if (isForm)
		return Page_Validators;
	else{
		var arr = getControls(section, "SPAN", "id", null), result = new Array();
		for (var i=0;i<arr.length;i++)
			if (Page_Validators.indexOf(arr[i]) != -1) result.expand(arr[i]);
		return result;
	}
}
function Controls(section, checkSubmit){
	this.section = section;
	var isForm = (section.tagName == "FORM");
	if (!isForm) addFormSection(section);
	this.spans = getControls(section, "span", "class", "ast");
	this.validators = getValidators(section, isForm);
	var inputs = section.getElementsByTagName("INPUT");
	this.txts = getControls(inputs, null, "type", "text");
	this.txts.expand(section.getElementsByTagName("TEXTAREA"));
	this.btns = getControls(inputs, null, "type", "button");
	this.btns.expand(getControls(inputs, null, "type", "submit"));
	this.btns.expand(getControls(inputs, null, "type", "reset"));
	this.opts = getControls(inputs, null, "type", "radio");
	this.opts.expand(getControls(inputs, null, "type", "checkbox"));
	var imgs = section.getElementsByTagName("IMG");
	this.clds = getControls(imgs, null, "class", "img_calendar");
	this.tmps = getControls(imgs, null, "class", "img_tmPicker");
	this.cells = getControls(section, "TD");
	this.cells.expand(section.getElementsByTagName("LABEL"));
	this.selects = section.getElementsByTagName("SELECT");
	this.comments = getControls(imgs, null, "class", "comment");
	if (isForm){
		if (checkSubmit){
			section.submitted = document.getElementById("hidSubmitted");
			if (section.submitted)
				section.isSubmitted = function(){
					if (this.submitted.value != "true")
						this.submitted.value = "true";
					else{
						alert("This page has already been submitted!");
						return true;
					}
					return false;
				}
		}
		this.setDefaults();
		section.Controls = this;
	}
}
Controls.prototype.setDefaults = function(){
	var sections = this.section.sections;
	if (sections){
		for (var i=0; i<sections.length; i++)
			sections[i].defaultDisabled = sections[i].disabled;
	}
	for (var i=0, txts=this.txts; i<txts.length; i++)
		txts[i].defaultValue = txts[i].value;
	for (var i=0, opts=this.opts; i<opts.length; i++)
		opts[i].defaultChecked = opts[i].checked;
	for (var i=0, selects=this.selects; i<selects.length; i++){
		var select = selects[i];
		if (!select.multiple)
			select.defaultIndex = select.selectedIndex;
		else{
			for (var j=0, opts=select.options; j<opts.length; j++)
				opts[j].defaultSelected = opts[j].selected;
		}
		if (select.onchange && select.Elements){
			for (var j=0, els=select.Elements; j<els.length; j++)
				els[j].default2Index = els[j].list2.selectedIndex;
		}
		var init = getAttributeValue(select, "init");
		if (init) try{eval(init);}catch(e){};
	}
	for (var i=0, vals=this.validators; i<vals.length; i++)
		vals[i].defaultIsValid = vals[i].isvalid;
}
Controls.prototype.isDirty = function(){
	for (var i=0, txts=this.txts; i<txts.length; i++)
		if (txts[i].defaultValue != txts[i].value) return true;
	for (var i=0, opts=this.opts; i<opts.length; i++)
		if (opts[i].defaultChecked != opts[i].checked) return true;
	for (var i=0, selects=this.selects; i<selects.length; i++){
		var select = selects[i];
		if (select.multiple){
			for (var j=0, opts=select.options; j<opts.length; j++)
				if (opts[j].defaultSelected != opts[j].selected) return true;
		}else if (select.defaultIndex != select.selectedIndex) return true;
		var _dirty = getAttributeValue(select, "checkDirty");
		if (_dirty) try{if (eval(_dirty)) return true;}catch(e){}
	}
	for (var i=0, vals=this.validators; i<vals.length; i++)
		if (vals[i].defaultIsValid != vals[i].isvalid) return true;
	return false;
}
Controls.prototype.selectChanged = function(ctl){
	if (ctl.onchange){
		var chString = ctl.onchange.toString();
		if (chString.indexOf("lle_reload") != -1 && typeof(lle_reload) == 'function'){
			lle_reload(ctl);
			for (var j=0, els=ctl.Elements; j<els.length; j++)
				with (els[j])
					selectList(list2, default2Index);
		}else if (chString.indexOf("lotb_showHide") != -1 && typeof(lotb_showHide) == 'function')
			with(chString){
				var ind = indexOf("lotb_showHide"), commaInd = indexOf(",", ind), brInd = indexOf(")", ind);
				lotb_showHide(ctl, substring(commaInd+1, brInd).trim());
			}
	}
}
Controls.prototype.reset = function(){
	for (var i=0, txts=this.txts; i<txts.length; i++)
		txts[i].value = txts[i].defaultValue;
	if (typeof(cdv) != 'undefined' && cdv && cdv.style && cdv.style.display != 'none')
		try{openCalendar(ccl.textBox.nextSibling);}catch(e){}
	for (var i=0, opts=this.opts; i<opts.length; i++)
		opts[i].checked = opts[i].defaultChecked;
	for (var i=0, selects=this.selects; i<selects.length; i++){
		var select = selects[i];
		//	reset options
		if (!select.multiple)
			selectList(select, select.defaultIndex);
		else{
			for (var j=0, opts=select.options; j<opts.length; j++)
				opts[j].selected = opts[j].defaultSelected;
		}
		this.selectChanged(select);
		var _reset = getAttributeValue(select, "reset");
		if (_reset) try{eval(_reset);}catch(e){};
	}
	var sections = this.section.sections;
	if (sections)
		for (i=0; i<sections.length; i++){
			var section = sections[i];
			if (section.defaultDisabled != section.disabled)
				enableSection(section, !section.defaultDisabled);
		}
	for (var i=0, vals=this.validators; i<vals.length; i++){
		var val = vals[i];
		if (val.isvalid != val.defaultIsValid){
			val.isvalid = val.defaultIsValid;
			ValidatorUpdateDisplay(val);
		}
	}
}
Controls.prototype.enable = function(enable){
	var disabled = !enable;
	this.section.disabled = disabled;
	//	process required labels
	for (var i=0, spans=this.spans; i<spans.length; i++)
		spans[i].style.display = (enable) ? "" : "none";
	//	process validators
	if (typeof(ValidatorEnable) == 'function')
		for (var i=0, vals=this.validators; i<vals.length; i++)
			ValidatorEnable(vals[i], enable);
	//	process text boxes
	for (var i=0, txts=this.txts; i<txts.length; i++){
		ctls_disableWithBgColor(txts[i], disabled);
		if (disabled) txts[i].value = "";
	}
	//	process buttons
	for (var i=0, btns=this.btns; i<btns.length; i++)
		enableButton(btns[i], !disabled);
	//	process calendars
	if (typeof(createCalendar) == 'function'){
		createCalendar();
		if (ccl && ccl.images)
			for (var i=0, clds=this.clds; i<clds.length; i++)
				ccl.images.enable(clds[i], enable);
	}
	//	process time pickers
	if (typeof(createTmPicker) == 'function'){
		createTmPicker();
		if (tmpk && tmpk.images)
			for (var i=0, tmps=this.tmps; i<tmps.length; i++)
				tmpk.images.enable(tmps[i], enable);
	}
	//	process options / checkboxes
	for (var i=0, opts=this.opts; i<opts.length; i++){
		opts[i].disabled = disabled;
		if (disabled) opts[i].checked = false;
	}
	//	process selects
	for (var i=0, selects=this.selects; i<selects.length; i++){
		var select = selects[i];
		ctls_disableWithBgColor(select, disabled);
		if (disabled){
			select.selectedIndex = -1;
			this.selectChanged(select);
		}
	}
	//	process cells
	for (var i=0, cells=this.cells; i<cells.length; i++){
		cells[i].disable = disabled;
		if (!isIE) cells[i].style.color = (enable) ? "" : "gray";
	}
	var tagName = this.section.tagName;
	if (!isIE && tagName && tagName!= 'TR' && tagName != 'FORM')
		this.section.style.color = (enable) ? "" : "gray";
	//	process comments
	for (i=0, cms=this.comments; i<cms.length; i++){
		cms[i].disabled = disabled;
		if (typeof(comments) != 'undefined')
			cms[i].src = (disabled) ? comments.imageDis : comments.image;
	}
}
function ctls_disableWithBgColor(ctl, disabled){
	ctl.disabled = disabled;
	if (isIE) ctl.runtimeStyle.backgroundColor = (disabled) ? '#ddddcc' : '';
}
function enableSection(section, enable){
	if (!section.Controls) section.Controls = new Controls(section);
	if (section.Controls) section.Controls.enable(enable);
}

