/**
* DataTables
*/

YAHOO.namespace ("Sqli.Widgets"); 

YAHOO.Sqli.Widgets.Window = function(url, title, callbackOpen, callbackOk,callbackCancel,hideOnOk, libOk, libCancel){
	this._url = url;
	this._title = title;
	this._formId = null;
	this._callbackOpen = callbackOpen;
	this._buttons = null;
	this._dlg = new YAHOO.widget.SimpleDialog(YAHOO.util.Dom.generateId(), 
				{ visible:false, close: false, 
				fixedcenter:true, modal:true, draggable:false });
	

	this._callbackSuccess = function(o){
		var dlg = o.argument._dlg;
		var test = true;
		var handleCancel = function() {
			
			if(callbackCancel != null)
	    		test = callbackCancel.call();
			if(test != false)
			{
				dlg.setBody("");
				this.hide();
			}
		}
		var handleOk = function(){
			callbackOk.call();
			if(hideOnOk == null || (hideOnOk != null && hideOnOk == true)){
				dlg.setBody("");
				this.hide();
			}
		}
		
		if(libOk == null)
			libOk = "Ok";

		if(libCancel == null)
			libCancel = "Annuler";
		
		if(libCancel=='hide')
			this._buttons = [{ text:libOk, handler:handleOk }];	
		else
			this._buttons = [{ text:libOk, handler:handleOk },{ text:libCancel, handler:handleCancel }];
		
		dlg.setHeader(o.argument.title);
		dlg.setBody(o.responseText);
		
		dlg.cfg.queueProperty("buttons", this._buttons);
		
		dlg.render(document.body);
	    dlg.show();
	    
	    if(o.argument.callback != null)
	    	o.argument.callback.call();
	    
		return false;
	}
 	
 	this._callbackFailure = function(o){
		YAHOO.Sqli.Utils.Tools.error("Impossible de récupérer les données !");
	}
 	
 	this.show = function() {
 		
 		
 		if(this._formId != null){
 			var formObject = document.getElementById(this._formId); 
			YAHOO.util.Connect.setForm(formObject); 
 		}
 			
 		YAHOO.util.Connect.asyncRequest('POST', this._url , 
 			{success : this._callbackSuccess,
 			failure : this._callbackFailure, 
 			argument:{title: this._title,
 					 callback: this._callbackOpen,
 					 _dlg: this._dlg}});
	}
 	
	this.close = function() {
		this._dlg.setBody("");
		this._dlg.hide();
	}
	
	
	
	this.setFormId = function(formId){
		this._formId = formId;
	}
	
	this.setUrl = function(url){
		this._url = url;
	}
}
