/* ${__APPLICATION_VERSION__} */

eds.webapp.dom.Form = function() {

	this.getFieldById = function(doc, formId, fieldId) {
		var formIndex;

		formIndex = this.getFormIndexById(doc, formId);

		return(this.getFieldByIndex(doc, formIndex, this.getFieldIndexById(doc, formIndex, fieldId)));
	}

	this.getFieldByIndex = function(doc, formIndex, fieldIndex) {
		if ( ! doc )
			return(null);

		if ( ! doc[formIndex] )
			return(null);

		return(doc[formIndex].elements[fieldIndex]);
	}

	this.getFieldIndexById = function(doc, formIndex, fieldId) {
		var form;
		var i;

		form = doc[formIndex];

		if ( ! doc )
			return(-1);

		i = 0;
		while ( i < form.elements.length ) {
			if ( form.elements[i].name == fieldId )
				return(i);

			++i;
		}

		return(-1);
	}

	this.getFormIndexById = function(doc, id) {
		var i;

		i = 0;
		while (i < doc.length ) {
			if ( doc[i].id == id )
				return(i);

			++i;
		}

		return(-1);
	}

	this.getDocument = function(win) {
		if ( ! win )
			win = window;

		if ( is.msie ) {
			return(win.document.all);

		} else {
			return(win.document.forms);

		}
	}
}

