function saveElement(form) {
	var els = form.elements;
	var argc = arguments.length;
	if (argc == 3) {
		var name = arguments[1];
		var value = arguments[2];
	} else if (argc == 2) {
		if (!arguments[1]) {
			throw new Error('saveElement: the specified form element was not found.');
		}
		var name = arguments[1].name;
		var value = arguments[1].value;
	} else {
		return;
	}
	if (els[name] == undefined) {
		var el;
		/*
			Note: the standard doesn't allow [] in the name of an element
			Note: if the name contains [ or ] and the element is created
					using the standard approved way, there is no way to retrieve the element 
					from the form.elements collection
			Update: any element created like this cannot be retrieved from the elements collection after
					it is appended to the form (however, its value is sent)
			el = form.ownerDocument.createElement('input');
			el.type = 'hidden';
			el.name = name;
			el.value = value;
		*/
		el = form.ownerDocument.createElement("input");
		el.type = "hidden";
		el.name = name;
		el.value = value;
		
		form.appendChild(el);
	} else {
		els[name].value = value;
	}
}

function resetElement(el, defaultValue) {
	var previousValue = el.getAttribute('previousValue');
	if (previousValue) {
		el.value = previousValue;
	} else if (defaultValue) {
		el.value = defaultValue;
	} else {
		el.value = '';
	}
}

function addElement(form) {
	var argc = arguments.length;
	if (argc == 3) {
		var name = arguments[1];
		var value = arguments[2];
	} else if (argc == 2) {
		if (!arguments[1]) {
			throw new Error('addElement: the specified form element was not found.');
		}
		var name = arguments[1].name;
		var value = arguments[1].value;
	} else {
		return;
	}
	var el = form.ownerDocument.createElement('input');
	el.type = 'hidden';
	el.name = name;
	el.value = value;
	form.appendChild(el);
}
