// $Id
//
// This class encapsulates the problem of iterating over
// a forms elements.
//
// A formvisitor instance is used to start off the iteration.
// This class calls appropriate methods in the visitor
// to mark the various elements in the form.
// The visitor must return true to continue the iteration.

function CFormIterator(aForm) {
    this.m_form = aForm;
    return this;
}

// The FormVisitor instance provides a way to
// be notified on individual elements in the form.
// The iterator will call one of these methods
// at the appropriate time in the visitor, if
// it is defined in the visitor. The methods are
// simply the same as the type of the element.

// The visitor must return true to continue visiting.
// Anything else stops the iteration.

function _CFormIterator_iterate(aFormVisitor) {
    var els = this.m_form.elements;
    var more=true;
    for (var i=0; more && (i<els.length); i++) {
        var el = els[i];
        if (el.type) {
            if (aFormVisitor.all) {
                more = aFormVisitor.all(el, this.m_form);
            }
            else if (aFormVisitor[el.type]) {
                more = aFormVisitor[el.type](el, this.m_form);
            }
        }
    }
}

new CFormIterator(null);
CFormIterator.prototype.iterate = _CFormIterator_iterate;
