﻿// SEARCH FORM CONTAINER
// Used for dynamic loading form control and required scripts/styles
Type.registerNamespace("FM");

FM.SFormContainer= function(element) {
	FM.SFormContainer._current= this;

	// Properties
	this.Context= "";
	this._service= FM._ResourceLoader.getResourceLoaderService();
	
	this.onFormLoadedDelegate= null;
	this.onCreateCallback= null;
	this._Result= null;
	
	//
	this.gridID= null;
	if (element.id != "_error") {
		this._currentForm= $create(FM.DataForm, null, null, null, element);
		this._currentForm.initForm();
	}
}

FM.SFormContainer.prototype= {

	dispose : function() {
		if (this._currentForm) { this._currentForm.dispose(); this._currentForm= null; } 
	},
	
	Search : function(resultsByRequest) {
		if (!this._grid) this._grid= fmgetgrid();
		var xmlData= this._currentForm.buildXml(false);
		if (resultsByRequest && xmlData.length == 0) xmlData= "[ResultsByRequestOnly]";
		this._grid.SetParameter("_XMLFormFilter", xmlData);
		this._grid.Select();
	},
	
	Reset : function(resultsByRequest) {
		this._currentForm.Reset();
		this.Search(resultsByRequest);
	},

	EndFunc: function() {
	}
}

FM.SFormContainer.registerClass('FM.SFormContainer', null, Sys.IDisposable);
FM.SFormContainer.getCurrent= function () { return FM.SFormContainer._current; }

Sys.Application.notifyScriptLoaded();