	//	Flag names Inputid + Flag + Status
	
	//	Class Definitions required
	//	Overlays for inputs InputEmpty InputInvalid
	//	Overlays for flags FlagShow
	

	//	========== OBJECT BOHForm ==========

	function BOHForm(xi_Form, xi_ButtonSet)
	{
		var	Form_elt;

		if		 (typeof(xi_Form) == 'object')	Form_elt = xi_Form;
		else if	((typeof(xi_Form) == 'string')	&& !(Form_elt = document.getElementById(xi_Form)))
				alert('new BOHForm : Could not locate form ' + xi_Form);

		if(Form_elt)
		{
			this.ID = Form_elt.id;
			this.Valid = true;
			this.Form_elt = Form_elt;	
			Form_elt.BOHForm = this;
	
			if(!(this.ButtonNm_elt = document.getElementById(this.ID + '_ButtonNm')))
				this.ButtonNm_elt = document.getElementById('ButtonNm');
			this.Buttons =		new Array();
			this.Vals =			new Array();
			this.FormVals =		new Array();
			this.Sorts =		new Array();
			this.CheckSets =	new Array();
			this.Selects =		new Array();
			this.SubRecs =		new Array();
			this.OptShowSets =	new Array();
			this.Floats =	new Array();
			this.SubRecIO_elt = document.getElementById('SubRec');
	
			if(xi_ButtonSet)	this.addButtons(xi_ButtonSet);

			this.FlagBaseClasses = new Object();
			this.Status = 'OK';
		}
	}
	
	BOHForm.prototype.addVals=		function (xi_ValSet)		
	{	for(var i = 0; i < xi_ValSet.length; i++)	this.addVal(new BOHVal(this.Form_elt, false, xi_ValSet[i])); return this; }
	BOHForm.prototype.addVal =		function (xi_BOHVal)		{ if(xi_BOHVal.Valid) this.Vals.push(xi_BOHVal);}


	BOHForm.prototype.addFormVal =	function (xi_BOHFormVal)	{ this.FormVals.push(xi_BOHFormVal); }


	BOHForm.prototype.addSorts=		function (xi_SortSet)		
	{	for(var i = 0; i < xi_SortSet.length; i++)	this.addSort(new BOHSort(this.Form_elt, false, xi_SortSet[i])); return this; }
	BOHForm.prototype.addSort =		function (xi_BOHSort)		{ if(xi_BOHSort.Valid) this.Sorts.push(xi_BOHSort); }


	BOHForm.prototype.addButtons=		function (xi_ButtonSet)		
	{	for(var i = 0; i < xi_ButtonSet.length; i++)	this.addButton(new BOHButton(this.Form_elt, false, xi_ButtonSet[i])); return this; }
	BOHForm.prototype.addButton =	function (xi_BOHButton)		{ if(xi_BOHButton.Valid) this.Buttons.push(xi_BOHButton); }


	BOHForm.prototype.addSelect =	function (xi_BOHSelect)		{ if(xi_BOHSelect.Valid) this.Selects.push(xi_BOHSelect); }


	BOHForm.prototype.addCheckSets =		function (xi_ChecSetSet)		
	{	for(var i = 0; i < xi_CheckSetSet.length; i++)	this.addCheckSet(new BOHCheckSet(this.Form_elt, false, xi_CheckSetSet[i])); return this;}
	BOHForm.prototype.addCheckSet =	function (xi_BOHCheckSet)	{ if(xi_BOHCheckSet.Valid) this.CheckSets.push(xi_BOHCheckSet); }

	BOHForm.prototype.addOptShowSets =		function (xi_OptShowSetSet, xi_Modifier)		
	{	for(var i = 0; i < xi_OptShowSetSet.length; i++)	this.addOptShowSet(new BOHOptShowSet(this.Form_elt, false, xi_Modifier, xi_OptShowSetSet[i])); return this;}
	BOHForm.prototype.addOptShowSet =	function (xi_BOHOptShowSet)	{ if(xi_BOHOptShowSet.Valid) this.OptShowSets.push(xi_BOHOptShowSet); }



	BOHForm.prototype.addSubRecs =		function (xi_SubRecSet)		
	{
		var	SubRec_obj;
		var	Current_ID;
		var Current_obj

		if(this.SubRecIO_elt) Current_ID = this.SubRecIO_elt.value;
		for(var i = 0; i < xi_SubRecSet.length; i++)
		{
			SubRec_obj = new BOHSubRec(this.Form_elt, false, xi_SubRecSet[i]);
			this.addSubRec(SubRec_obj);
			if(Current_ID && (SubRec_obj.ID == Current_ID))	Current_obj = SubRec_obj;
		}
		if(!Current_obj)	Current_obj = this.SubRecs[0];
		if(Current_obj) 	Current_obj.show();
		return this;
	}
	BOHForm.prototype.addSubRec =	function (xi_BOHSubRec)	{ if(xi_BOHSubRec.Valid) this.SubRecs.push(xi_BOHSubRec);}

	BOHForm.prototype.addFloats =		function (xi_FloatSet)		
	{	for(var i = 0; i < xi_FloatSet.length; i++)	this.addFloat(new BOHFloat(this.Form_elt, false, xi_FloatSet[i])); return this;}
	BOHForm.prototype.addFloat =	function (xi_BOHFloat)	{ if(xi_BOHFloat.Valid) this.Floats.push(xi_BOHFloat); }


	BOHForm.prototype.setFocus =	function (xi_TabStop)
	{
		var	Form_elt = this.Form_elt;
		var	Input_elt;
		var	Input_set = new Array();

		if(!xi_TabStop) xi_TabStop = 1;

		if(this.SubRec_Curr && this.SubRec_Curr.TabIn)
			this.SubRec_Curr.setFocus(xi_TabStop);
		else
		{		
			xi_TabStop--;
			
			if(Form_elt)
			{
				if( Form_elt.elements[0]!=null)
				{
					var elt;
					var max = Form_elt.elements.length;
					var	tabIndex;
					for( elt = 0; elt < max; elt++ )
					{
						Input_elt = Form_elt.elements[elt];
						if( Input_elt.type != "hidden" &&
							!Input_elt.disabled &&
							!Input_elt.readOnly &&
							Input_elt.style.visibility != 'hidden' &&
							Input_elt.style.display != 'none')
						{
							tabIndex = Input_elt.tabIndex ? Input_elt.tabIndex : 9999999;
							Input_set.push(new Array(tabIndex, Input_elt));
						}
					}
					Input_set.sort(	function ( a, b ) {if(a[0] < b[0])	return -1; else if(a[0] > b[0])	return 1; else return 0;})
					
					if(Input_set.length > xi_TabStop)
						Input_set[xi_TabStop][1].focus();
				}
			}
		}
	}

	BOHForm.prototype.validate =	function ()
	{
		var	FirstSubRecWithError;
		var	SubRec_Curr = this.SubRec_Curr;
		var	SubRec_Curr_has_error = false;
		var	SubRec;
		var	ErrorCount = 0;
		var	i;
		var rv = true;
		for(i = 0; i < this.Vals.length; i++)
		{
			//alert('validating ' + this.Vals[i].ID);
			if(!this.Vals[i].validate(FORMVAL))
			{
				ErrorCount++;
				if(SubRec = this.Vals[i].Input_elt.BOHSubRec)
				{
					if(!FirstSubRecWithError)
						FirstSubRecWithError = SubRec;
					if(SubRec_Curr && (SubRec_Curr.SubRec_elt.id == SubRec.SubRec_elt.id))
					{
						SubRec_Curr_has_error = true;
					}
				}
				rv = false;
			}
		}
		if(FirstSubRecWithError && !SubRec_Curr_has_error)
		{
			FirstSubRecWithError.show();
		}
		if(this.FormVals.length	&& !this.validateForm(FORMVAL, ErrorCount, FirstSubRecWithError, SubRec_Curr_has_error))	rv = false;
		return rv;
	}

	BOHForm.prototype.validateForm =	function (xi_ValMode, xi_ErrorCount, xi_FirstSubRecWithError, xi_SubRec_Curr_has_error)
	{
		var rv = true;

		for(var i = 0; i < this.FormVals.length; i++)
			if(!this.FormVals[i](this, xi_ValMode, xi_ErrorCount, xi_FirstSubRecWithError, xi_SubRec_Curr_has_error))	rv = false;
		return rv;
	}

	BOHForm.prototype.flag =	function (xi_FlagType, xi_NewStatus)
	{
		var	Flag_elt;
		var TypeStatus = xi_FlagType + 'Status';
		if(!this[TypeStatus])  this[TypeStatus] = 'OK';

		if(this[TypeStatus] == xi_NewStatus)
			return;
		if(this[TypeStatus] != 'OK')
		{
			// If existing status is not OK reset the flag assoc with it
			if(Flag_elt = document.getElementById(this.Form_elt.id + 'Flag' + xi_FlagType + this[TypeStatus]))
				Flag_elt.className = this.FlagBaseClasses[xi_FlagType + this[TypeStatus]];
		}
		if(xi_NewStatus != 'OK')
		{
			if(Flag_elt = document.getElementById(this.Form_elt.id + 'Flag' + xi_FlagType + xi_NewStatus))
			{
				if(!this.FlagBaseClasses[xi_FlagType + xi_NewStatus])
					this.FlagBaseClasses[xi_FlagType + xi_NewStatus] = Flag_elt.className;
				Flag_elt.className = this.FlagBaseClasses[xi_FlagType + xi_NewStatus] + ' FlagShow';
			}
		}
		this[TypeStatus] = xi_NewStatus;
	}
	
	BOHForm.prototype.submit =	function (xi_ButtonName, xi_Validate, xi_Confirm, xi_SubmitFunc)
	{
		// Call the Generic Page Validation Function.
		if(xi_Validate && !this.validate(FORMVAL))
			return false;	
		if(xi_Confirm && !confirm(xi_Confirm))
			return false;	
		if(xi_SubmitFunc && !xi_SubmitFunc(this, xi_ButtonName))	return false;
		
		if (this.ButtonNm_elt)	this.ButtonNm_elt.value = xi_ButtonName;
		else					return false;
		this.Form_elt.submit();
		return true;
	}
	//	========== Procedural Functions ==========

	function BOH_EventTarget(xi_Event)
	{
		var Target_elt;
		if (!xi_Event) xi_Event = window.event;
		if (xi_Event.target)
			Target_elt = xi_Event.target;
		else if (xi_Event.srcElement)
			Target_elt = xi_Event.srcElement;
		if (Target_elt.nodeType == 3) // defeat Safari bug
			Target_elt = Target_elt.parentNode;

		return Target_elt;
	}

	function BOH_PreventDefault(xi_Event)
	{
		if (!xi_Event) xi_Event = window.event;
		
		if (xi_Event.preventDefault)
			xi_Event.preventDefault();
		else
			xi_Event.returnValue = false;
	}



	function BOH_SubmitForm(xi_Form_id, xi_ButtonName, xi_ValueField_id, xi_Value, xi_Validate, xi_Confirm, xi_SubmitFunc )
	{
		var ValueField_elt;
		var Form_elt;
		
		if((xi_ValueField_id) && (ValueField_elt = document.getElementById(xi_ValueField_id)))
			ValueField_elt.value = xi_Value;

		if (!(Form_elt = document.getElementById(xi_Form_id)))
		{
			alert("Cannot find the required form >"+xi_Form_id+"<");
			return false;
		}
		if(Form_elt.BOHForm)
			return Form_elt.BOHForm.submit(xi_ButtonName, xi_Validate, xi_Confirm, xi_SubmitFunc);
		else
			new BOHForm(xi_Form_id).submit(xi_ButtonName, xi_Validate, xi_Confirm, xi_SubmitFunc);
	}


	function BOH_RadioValue(xi_Form_id, xi_Radio_id)
	{
		// Get the value of a radio or checkbox in a form
		var	Radio_elt =	document.forms[xi_Form_id].elements[xi_Radio_id];
		if(!Radio_elt) return "";
		var radioLength = Radio_elt.length;
		if(radioLength == undefined)
			if(Radio_elt.checked)
				return Radio_elt.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++)
			if(Radio_elt[i].checked)	return Radio_elt[i].value;
	
		return "";
	}
	function BOH_RadioSet(xi_Form_id, xi_Radio_id, xi_Value)
	{
		// Set the value of a radio or checkbox in a form
		var	Radio_elt =	document.forms[xi_Form_id].elements[xi_Radio_id];
		if(!Radio_elt) return;
		var radioLength = Radio_elt.length;
		if(radioLength == undefined)
		{
			Radio_elt.checked = (Radio_elt.value == xi_Value.toString());
			return;
		}
		for(var i = 0; i < radioLength; i++)
		{
			Radio_elt[i].checked = false;
			if(Radio_elt[i].value == xi_Value.toString())
				Radio_elt[i].checked = true;
		}
	}


