﻿var theForm;

function appendHidden(name, value) {
	var h = document.createElement("input");
	h.type = "hidden";
	h.name = h.id = name;
	h.value = value;
	theForm.appendChild(h);
}

function __doPostBack(eventTarget, eventArgument) {
	if (!theForm) theForm = document.forms[0];
	if (!theForm) { alert("Form element not found"); return; }
	if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
		if (!theForm.__EVENTTARGET) appendHidden("__EVENTTARGET", eventTarget);
		else theForm.__EVENTTARGET.value = eventTarget;
		if (!theForm.__EVENTARGUMENT) appendHidden("__EVENTARGUMENT", eventArgument);
		else theForm.__EVENTARGUMENT.value = eventArgument;

		if (window.isAjaxFormSubmit) {
			if (window.theAjaxFormUrl) theForm.action = window.theAjaxFormUrl;
			Ext.Ajax.request({ form: theForm,
				success: function(response, opts) {
					Ext.get(window.theAjaxFormId).update(response.responseText, true, window.theAjaxFormSuccessFunc);
				}});
			theForm = null;
		}
		else {
			if (theForm.action != location.href) {
				if (!theForm.__POSTURL) appendHidden("__POSTURL", theForm.action);
				else theForm.__POSTURL.value = theForm.action;
				theForm.action = location;
			}
			theForm.submit();
		}
	}
}


