Ext.BLANK_IMAGE_URL = './ext-2.2/resources/images/default/s.gif';
Ext.QuickTips.init();  // enable tooltips
Ext.Updater.defaults={ disableCaching: true};
//Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

Ext.namespace("Globals");
//Ext.namespace("Globals.Stores");
Ext.namespace('Ext.ux');


Globals.PAGESIZE = 20;
Globals.UNDEFINED_LABEL = '-- non definito --';
Globals.SUCCESS = '{success:true}';


//Globals.HOST = '127.0.0.1';
Globals.HOST = window.location.host;


var HANDLER_AJAX_FAILED = function(response){
         var result=response.responseText;
         Ext.MessageBox.alert('Errore','Errore di rete.');
 };
 
 
var HANDLER_ACTION_FAILED = function(message){
	var _w = new Ext.Window({
            title: 'Warning',
            closable:true,
            width:400,
            height:150,
            border:false,
            //plain:true,
           	//manager: MyDesktop.getDesktop().getManager(),
            modal: true,
            layout: 'fit',
            items: new Ext.Panel(
            {
            	style: 'font-size: 10pt; color: red;',
            	html: '<br/><span style="padding: 5px 5px 5px 5px;">'+message+'</span>'
            }
            ),
            bbar: [
            	{
            		text: "Close",
            		handler: function(){ _w.close(); }
            	}
            ]
        });
	_w.show();
}

var INFO_BOX = function(message){
	var _w = new Ext.Window({
            title: 'Info',
            closable:true,
            width: 400,
            height: 150,
            border:false,
            modal: true,
            layout: 'fit',
            items: new Ext.Panel(
            {
            	style: 'font-size: 10pt; color: green; text-align:center;',
            	html: '<br/>'+message
            }
            ),
            bbar: [
            	{
            		text: 'Close',
            		handler: function(){ _w.close(); }
            	}
            ]
        });
	_w.show();
}

var CONFIRM_BOX = function(message, callback){
	var _w = new Ext.Window({
            title: 'Conferma',
            closable:true,
            width:400,
            height:150,
            border:false,
            //plain:true,
           	//manager: MyDesktop.getDesktop().getManager(),
            modal: true,
            layout: 'fit',
            items: new Ext.Panel(
            {
            	style: 'font-size: 10pt; color: black; text-align:center;',
            	html: '<img style="margin: 30px 2px 2px 20px; float:left;" src="./ext-2.1/resources/images/default/window/icon-question.gif"></img>'+
            		'<div style="margin: 10px 2px 2px 30px; float:left; width: 300px;">'+message+'</div>'
            }
            ),
            bbar: [
            	{
            		text: 'Si',
            		handler: function(){ callback(); _w.close(); },
            		minWidth: 80
            	},
            	{
            		text: 'No',
            		handler: function(){ _w.close(); },
            		minWidth: 80
            	}
            ]
        });
	_w.show();
}

var WARNING_BOX = function(message){
	var _w = new Ext.Window({
            title: 'Attenzione',
            closable:true,
            width:400,
            height:150,
            border:false,
            //plain:true,
           	//manager: MyDesktop.getDesktop().getManager(),
            modal: true,
            layout: 'fit',
            items: new Ext.Panel(
            {
            	style: 'font-size: 10pt; color: orange; text-align:center;',
            	html: '<br/>'+message
            }
            ),
            bbar: [
            	{
            		text: 'Chiudi',
            		handler: function(){ _w.close(); }
            	}
            ]
        });
	_w.show();
}

var BOX_WARNING = function(message){
 Ext.Msg.show({
   title: 'Attenzione',
   msg: message,
   width: 300,
   buttons: Ext.MessageBox.OK,
   icon: Ext.MessageBox.WARNING
	});
}


function deleteRecordFromGrid(params){
	var _grid = params.grid;
	var record  = _grid.getSelectionModel().getSelected();
	if (record){
		Ext.Msg.show({
	   title:'Remove',
	   msg: 'Are you sure to remove record <b>'+record.get(params.displayField)+'</b>?',
	   buttons: Ext.Msg.YESNOCANCEL,
	   icon: Ext.MessageBox.WARNING,
	   fn: function(res){
	   		if (res!='yes')
	   			return;
	   		 Ext.Ajax.request({
			   url: params.url,
			   params: params.pkey+'='+record.get(params.pkey),
			   success: function(response){
			      	 var jsonresult = Ext.decode(response.responseText);		      	 
			      	 
			      	 if (jsonresult.success){
			      		params.grid.getStore().reload();
			      		if (params.callback){
			      			params.callback();
			      		}
					}else{
						HANDLER_ACTION_FAILED(jsonresult.data);
					}
				},
			   failure: HANDLER_AJAX_FAILED
			});
	   }
	});

	}else{
		Ext.Msg.show({
		   title:'Warning',
		   msg: 'No selection',
		   buttons: Ext.Msg.OK,
		   icon: Ext.MessageBox.WARNING
		});
	}
}


