var DelmessOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '350px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Imposta la modalità debug
	// this.overlay.debugMode = true;
	
	// Stabilisce per quanto tempo resta visibile la finestra prima di essere chiusa
	// this.overlay.visibleFor = 3;
	
	// Metodo di connessione
	this.overlay.connectionMethod = 'POST';
	
	// Identifica un overlay a più passi
	this.overlay.stepOverlay = true;
	
	// Se true nasconde il terzo passo della finestra, default false
	// this.hideAfterLoad = false;
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	this.stepOne = function (overlay, message_id, t_profile_id, method) {
		//this.show è il text che viene richiamato nell'html
		this.overlay.scriptUrl = "http://" + location.hostname + "/overlay_manager/cancella_messaggio";

		// var actionString = 'profile_id=' + profile_id + '&t_profile_id=' + t_profile_id + '&abuse_id=' + abuse_id;
		var actionString = 'message_id=' + message_id + '&t_profile_id='+ t_profile_id + '&method='+ method;		

		// definisce cosa fare nello step 2, in realtà chiama step 2
		this.overlay.setContentByAjax(actionString, null, null, this);
	};		

	this.stepTwo = function (overlay, message_id, t_profile_id, method) {	
		this.overlay.scriptUrl = "http://" + location.hostname + "/gui_manager/cancella_messaggio";
		var actionString = 'message_id=' + message_id + '&t_profile_id='+ t_profile_id+ '&method=' + method;
		//this.overlay.stepTwo(actionString, null, null, this);
		this.overlay.getResultByAjax(actionString, this, this.reload);
	};
	
	this.reload = function (obj, data) {
		OverlayConfiguration.delmess.overlay.hide();
		// del ok
		if(String(data['result']) == "OK"){
			//OverlayConfiguration.genericMessage.overlay.hide();			
			if(data['params']['webkit']){
				reload_ajax('http://' +conf.baseUrl+ '/webkit/mybox/1?method=' + data['params']['method'], data['params']['method']);
			}else{
				
				var messageCounter = document.getElementById('messageCounter').value;
				var currentPage = document.getElementById('currentPage').value;
				// se ci sono più messaggi faccio reload ajax, altrimenti ricarico l'intera pagina
				if(Number(messageCounter) > 1){ 
					reload_ajax('http://' +conf.baseUrl+ '/message/'+ data['params']['method'] +'/' + currentPage + '?method='+data['params']['method'], data['params']['method']);
				}
				else if(Number(messageCounter) == 1 && Number(currentPage) > 1){
					reload_ajax('http://' +conf.baseUrl+ '/message/'+ data['params']['method'] +'/' + (currentPage - 1) + '?method='+data['params']['method'], data['params']['method']);
				}
				else{
					location.href = 'http://' +conf.baseUrl+ '/message/'+ data['params']['method'];
				}
			}			
			
			
			save = 'yes';
		}
		// del ko
		else{			
			OverlayManager.show('genericMessage', 'Attenzione', data['params']['error'], 'rosso');			
			save = 'no';
		}
		
		//var t=setTimeout(function(){OverlayConfiguration.kiss.changeProfile1(document.getElementById('currentIndex').value, document.getElementById('currentPage').value, 'kiss', save);}, changeProfileTime);
	};
};

OverlayConfiguration.delmess = new DelmessOverlay('textOverlay');
OverlayManager.delmess = function (args) {
	OverlayConfiguration.delmess.stepOne('delmess', args[0], args[1], args[2]);
};