if (!SIGI) throw("SIGI.Form depends on the following scripts. Please make sure these are included.\nSIGI.js, SIGI.Validation.js");
	
function FormObject(mainForm) {
	this.Base();	
	this.InstanceID = null;
	this.oldDoPostBack = null;
	this.mainForm = mainForm;
	this.isDoPostBack = false;
	
	if (window.__doPostBack != null) this.oldDoPostBack = window.__doPostBack;
	window.__doPostBack = this.context(this.DoPostBack);

	if (this.mainForm != null) {
		if (this.mainForm.__InstanceID != null) {
		    this.InstanceID = this.mainForm.__InstanceID.value;
		}

		this.allowBrowserNavigation = true;
		if (this.mainForm.__AllowBrowserNavigation != null) {
            if (this.mainForm.__AllowBrowserNavigation.value == "false")
            this.allowBrowserNavigation = false;
        }
		
		SIGI.attachEvent(this.mainForm, "onsubmit", this.context(this._onsubmit));
		this.setScrollPosition();
	}
}
FormObject.inherits(SIGI.Base);
FormObject.prototype.saveScrollPosition = function() {
	var contentDiv = document.getElementById("PageContentArea");
	if (contentDiv != null) {
		var input = document.getElementById("__ScrollTop");
		if (input != null) {
			input.value = contentDiv.scrollTop;
		}
	}
}
FormObject.prototype.setScrollPosition = function() {
	var contentDiv = document.getElementById("PageContentArea");
	if (contentDiv != null) {
		var input = document.getElementById("__ScrollTop");
		if (input != null) {
			try {
				contentDiv.scrollTop = input.value;
			} catch(ex) {}
		}
	}
}
FormObject.prototype.saveFormChanged = function() {
	var input = document.getElementById("__FormChanged");
	if (input != null) {
		input.value = this.isChanged();
	}
}
FormObject.prototype._onsubmit = function() {
    //this.DoPostBack(this.mainForm.name, "");
    event.returnValue = false;
    return false;
}
FormObject.prototype.DoPostBack = function(eventTarget, eventArgument) {

    this.isDoPostBack = true;

    if (this.mainForm != null) {
        this.mainForm.action = SIGI.formatURL(this.mainForm.action);
    }

    this.enableElements(this.mainForm);
    this.saveFormChanged();
    this.saveScrollPosition();
    SIGI.showPageTransition();
    if (this.oldDoPostBack != null) {
        this.oldDoPostBack((eventTarget != null ? eventTarget : ""), eventArgument);
    } else {
        if (this.mainForm != null) this.mainForm.submit();
    }
}
FormObject.prototype.isChanged = function() {
	return this.isFormChanged(this.mainForm);
}
FormObject.prototype.isFormChanged = function (form) {
	for (var i=0; i < form.elements.length; i++) {
		var element = form.elements[i];
		if (SIGI.isChanged(element)) return true;
	}
	return false;
}
FormObject.prototype.enableElements = function(form) {
    for (var i = 0; i < form.elements.length; i++) {
        var element = form.elements[i];
        if (element.disabled) {
            if ((!element.enableOnSubmit) && (toBoolean(this.enableOnSubmit(form))))
                SIGI.enable(element);

            if (toBoolean(element.enableOnSubmit))
                if ($SIGIfind(element.id)) {
                if ($SIGIfind(element.parentNode.id))
                    $SIGIfind(element.parentNode.id).set_enabled(true);
                else
                    $SIGIfind(element.id).set_enabled(true);
            }
            else
                SIGI.enable(element);
        }
    }
    return false;
}

FormObject.prototype.enableOnSubmit = function(form) {

    return toBoolean(form.getAttribute("enableOnSubmit"));
}

SIGI.FormObject = FormObject;
FormObject = null;