function FormAccess(formObjOrString){
	
	// ************************************************
	// FormAccess 1.91
	//
	// formAccess is a class for enabling simple access to html forms
	// Also creates a wrapper for other form actions such as disabling and submiting
	//
	// to use create an instance of the class with the form object as the parameter
	// use setValue to set any form element's value
	// use getValue to get any form element's value
	//
	// may need further work to handle multiselects
	// ************************************************
	
	if (typeof(formObjOrString) == 'object') {
		this._form = formObjOrString;
	} else {
		this._form = document.forms[formObjOrString];
	}	
	if (!this._form) {
		alert('FormAccess : a form was not successfully located');
	}
	
	
	this.getElement = function(name) {
		
		//pre-con  : true
		//post-con : gets the element defined be the name
		
		var obj = this._form.elements[name];
		
		if (!obj) {
			alert('FormAccess.getElement : "'+name+'" does not exist');
		} else {
			return obj;
		}
	}
	
	
	this.elementExists = function(name) {
		
		//pre-con  : true
		//post-con : returns boolean depending on wether the the element exists
		
		var obj = this._form.elements[name];
		if (!obj) { 
			return false
		} else {
			return true;
		}
	}
	

	this.setValue = function(name, value){
		
		//pre-con  : true
		//post-con : set the value of the form element whose name is name
		
		var obj = this._form.elements[name];
		var type = this.getType(name);
		
		if (!obj || (type == undefined)) {
			alert('FormAccess : setValue : the element could not be found : ['+name+'] = '+value);
			return '';
		}

		if (type == 'select') {
			for (var i = 0; i < obj.length; i++) {
				if (obj.options[i].value == value) {
					obj.selectedIndex = i;
				}
			}

		} else if (type == 'radio') {
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].value == value) {
					obj[i].checked = true;
				}
			}

		} else if (type == 'checkbox') {
			//assumes that value is true or false
			obj.checked = value;

		} else if (type == 'button') {
			//do nothong

		} else {
			obj.value = value;
		}
	}

	this.getValue = function(name){
		
		//pre-con  : true
		//post-con : get the value of the form element whose name is name		
		
		var obj = this._form.elements[name];
		var type = this.getType(name);
		
		if (!obj || (type == undefined)) {
			alert('FormAccess : getValue : the element could not be found : '+name);
			return '';
		}

		if (type == 'select') {
			for (var i = 0; i < obj.length; i++) {
				if (obj.options[i].selected == true) {
					return obj.options[i].value
				}
			}
			return null;
		
		} else if (type == 'radio') {
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].checked) {
					return obj[i].value;
				}
			}

		} else if (type == 'checkbox') {
			//obly returns the value of checked if it is actually checked
			
			if (obj.checked) {
				return obj.value;
			} else {
				return '';
			}

		} else if (type == 'button') {
			//return nothing

			return '';
		
		} else {
			return obj.value;
		}
	}
	
	this.setTextLabel = function(idStr, text) {
		var htmlObj = document.getElementById(idStr);
		if (!idStr) {
			alert("FormAccess.setTextLabel : '"+idStr+"' not found : text = "+text);
		} else {
			htmlObj.innerHTML = text;
		}
	}
	
	this.getNamesWild = function(searchStr) {
		//pre-con  : true
		//post-con : returns an array of element names that conform to the wild card
		//		   : eg 'ggg_*' returns an array of all the element names that begin with 'ggg_'
		
		var nameArr = Array();
		
		for (var i=0; i<this._form.elements.length; i++) {
			var name = this._form.elements[i].name;
		
			var re = new RegExp(searchStr, 'g');
			if (name && name.match(re)) {
   				nameArr.push(name);
			}
		}
		
		return nameArr;
	}
	
	this.reset = function(name) {
		var obj = this._form.elements[name];
		this.setValue(name, obj.defaultValue);
	}
	
	this.getType = function(name) {
		var obj = this._form.elements[name];

		if (obj == undefined) {
			return undefined;
		}
		
		if (obj.options) {
			return 'select';
		} else if (obj[0]) {
			return type = obj[0].type;
		} else {
			return type = obj.type;
		}
	}

	this.enabled = function(name, onOff){
		
		//pre-con  : true
		//post-con : enables or disables the input
		//		   : if the name represents a radio input then all radios in that
		//		   : groupd will be disabled/enabled
		//
		//		   : if the name is not found in the form but a button with the same
		//		   : content is found then that button will be disable or enabled.

		var type = this.getType(name);
		
		if (type == undefined) {
			//may exist as a button
			var buttons = document.body.all.tags("BUTTON");
			for (var i = 0; i<buttons.length; i++) {
				if (buttons[i].innerText == name) {
					buttons[i].disabled = !onOff;
				}
			}
			
		} else {
			var obj = this._form.elements[name];
			
			if (type == 'radio') {
				for (var i = 0; i < obj.length; i++) {
					obj[i].disabled = !onOff;
				} 
			} else {
				obj.disabled = !onOff;
			}
		}
	}

	this.setChecked = function(name, onOff) {
		
		//pre-con : true
		//post-con : the checkbox name is checked or unchecked 
		
		this.getElement(name).checked = onOff;
	}
	
	this.isChecked = function(name) {
		
		//pre-con : true
		//post-con : returns where the box is checked or not

		return this.getElement(name).checked;
	}

	this.setAction = function(url){
		
		//pre-con : true
		//post-con : sets the action of the form 		
		
		this._form.action = url;
	}

	this.submit = function(){
		
		//pre-con : true
		//post-con : submits the form
		
		this._form.submit();
	}
	
	this.styleSelectOption = function(selectName, optionValue, className) {
		//pre-con : name represents a select list and the option value exists
		//post-con : the option has the class applied to it
		
		var found = null;
		var obj = this._form.elements[selectName];
		
		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].value == optionValue) {
				found = i;
			}
		}
		
		obj.options[found].className = className;
	}
	
	this.addToSelectList = function(selectName, optionValue, optionText) {
	
		//pre-con 	: name represents a select list
		//post-con 	: the option is added to the select list
		//			: returns the option
				
		var length = this._form.elements[selectName].options.length;
		var opt = new Option(optionText, optionValue);
		
		this._form.elements[selectName].options[length] = opt;
		return opt;
	}
	
	this.changeOptionText = function(selectName, optionValue, optionText) {
		
		//pre-con : name represents a select list
		//post-con : the option alread exists in the select list
		
		var found = null;
		var obj = this._form.elements[selectName];
		
		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].value == optionValue) {
				found = i;
			}
		}
		
		obj.options[found].text = optionText;
	}
	
	this.selectOptionExists = function(selectName, optionValue) {
		var found = null;
		var obj = this._form.elements[selectName];
		
		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].value == optionValue) {
				return true;
			}
		}
		
		return false;
	}
	
	

	this.emptySelectList = function(name) {
		
		//pre-con : name represents a select list
		//post-con : empties the list
		
		this._form.elements[name].length = 0;
	}

	this.removeFromSelectList = function(selectName, optionValue) {
		var found = null;
		var obj = this._form.elements[selectName];
		
		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].value == optionValue) {
				found = i;
			}
		}
		
		obj.options[found] = null;
	}
}


