var DelconversationOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '350px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// 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,t_profile_id) {
		// this.show è il text che viene richiamato nell'html
		this.overlay.scriptUrl = "http://" + location.hostname + "/overlay_manager/cancella_conversazione";
		var actionString = 't_profile_id='+ t_profile_id;	
		//alert(actionString);
		// definisce cosa fare nello step 2, in realtà chiama step 2
		this.overlay.setContentByAjax(actionString, null, null, this);
		};	

		this.stepTwo = function (overlay, t_profile_id) {
		this.overlay.scriptUrl = "http://" + location.hostname + "/gui_manager/cancella_conversazione";
		var actionString = 't_profile_id='+ t_profile_id;
		//alert(actionString);
		//this.overlay.stepTwo(actionString, null, null, this);
		this.overlay.getResultByAjax(actionString, this, this.reloadConversation);
	};
	
	this.reload = function (obj, result) {
		var parsed_result = Utilities.jsonParse(result);
		OverlayConfiguration.delconversation.overlay.hide();
		//alert(parsed_result);
		
		var responseText = parsed_result.header + parsed_result.body;
		obj.show(null, responseText, null);
		
		if(parsed_result.result=='OK'){
			reload_ajax('http://'+ location.hostname + '/message/chronology/' + parsed_result.params.t_profile_id + '/1?method=chronology','cronologia');
		}
		
		
		
		//UserActions.modified[parsed_result.params.t_profile_id] = obj.overlay.isSuccessResponse(parsed_result.result);
		
	};
		
	this.reloadConversation = function (obj, data) {
		OverlayConfiguration.delconversation.overlay.hide();
		// del ok
		if(String(data['result']) == "OK"){	
			reload_ajax('http://'+ location.hostname + '/message/chronology/' + data.params.t_profile_id + '/1?method=chronology','cronologia');
			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.delconversation = new DelconversationOverlay('textOverlay');
OverlayManager.delconversation = function (args) {
	OverlayConfiguration.delconversation.stepOne('delconversation', args[0]);
};