/*********************************************************************************/
/**			copyright (c) PlanetCalc.com, 2007  			**/
/**		    	AjaxDialogHandler					**/
/*********************************************************************************/

function AjaxDialogHandler(url, target) {
	this.Dialog = null;
	this.Parent = parent;
	this.URL = url;
	this.Target = target;
	var me = this;

	this.onchanged = function ( controlid ) {
	}

	this.initdialog =  function (dialog) {
		this.Dialog = dialog;
		this.Dialog.SetDefaultValues();
	}

	this.oncommand = function ( buttonid ) {
		clearLastError();
		if (buttonid == "input_cancel")
			this.Dialog.Hide()
		else if (buttonid == "input_ok") {
			if ( this.Dialog.Validate() ) {
				HideDialogForLoading( this.Dialog.GetElement().id );
				BSMakePOSTRequest( this.URL, this , this.Dialog.GetValues() );
			}
		}
	}

	this.onkeypressed = function ( controlid, evt ) {
		return true;
	}                                                
	
	this.Edit = function( data ) {
		this.Dialog.SetValues( data );
		this.Dialog.Show();
	}		

	this.New = function() {
		this.Dialog.SetDefaultValues();
		this.Dialog.Show();
	}		
	this.OnError= function( text ) {
		BSAlert( text );
		me.Dialog.Hide();
	}

	this.OnResponse = function( obj ) {
		me.Dialog.Hide();
		if ( me.Target ) {
			me.Target.Reload();
		}
	}
}    

