var RemoveBlacklistOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '350px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Identifica un overlay a pił passi
	this.overlay.stepOverlay = true;
	
	this.wrapper = function (overlay, args) {
		var params = {
			overlay: overlay,
			aaa_fn: args[2],
			t_nick: args[1],
			t_profile_id: args[0],
			iconId: args[3]
		};
		
		this.stepOne(params);
	}
	
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	this.stepOne = function (params) {
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/overlay_manager/rimuovi_blacklist";
		
		this.overlay.setContentByAjax(Utilities.createActionString(params), null, null, this);		
	};
	
	this.stepTwo = function (t_pid, t_nick, iconId) {
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/gui_manager/rimuovi_blacklist";
	
		var params = {
			t_profile_id: t_pid,
			t_nick: t_nick,
			iconId: iconId
		};
		
		this.show(null, this.overlay.loaderContent.body, null);
		this.overlay.getResultByAjax(Utilities.createActionString(params), this, this.setBodyByResult);
	};
	
	this.setBodyByResult = function (obj, pResult) {
		var responseText = pResult.header + pResult.body;
		var data = pResult.params;
		var success = obj.overlay.isSuccessResponse(pResult.result);
		
		UserActions.modified[data.t_profile_id] = success;
		obj.show(null, responseText, null);
		
		if(success) {
			obj.removeFriend(data.t_profile_id);
			if(YAHOO.util.Dom.get(data.iconId)) obj.change(data.t_profile_id, data.t_nick, 'buddy.add', data.iconId);
			if(obj.overlay.isSuccessResponse(pResult.result) && YAHOO.util.Dom.get(data.iconId)) obj.change(data.t_profile_id, data.t_nick, 'buddy.add', data.iconId);
		}
	};
	
	this.change = function (t_pid, t_nick, aaa_fn, elId) {
		YAHOO.util.Dom.get(elId).innerHTML = '<a id="addBlackAction" title="blacklist_add_on" class="lock" href="javascript:UserActions[\'blacklist_add_on\'](\'' + t_pid + '\', \'' + t_nick + '\', \'' + aaa_fn + '\', \'' + elId + '\');"><span>' + (conf.path == 'home/video' ? 'aggiungi ai flirt' : '') + '</span></a>';				
	};
	
	this.removeFriend = function (t_pid) {
		var page = location.href.split('/');
		if(page[page.length - 2] == 'my_friends' || page[page.length - 2] == 'my_blacklist')
			try {
				var box = YAHOO.util.Dom.get('utente_' + t_pid);
				var parent = box.parentNode;
				parent.removeChild(box);
			} catch (e) {}
	};
};

OverlayConfiguration.removeblacklist = new RemoveBlacklistOverlay('textOverlay');
OverlayManager.removeblacklist = function (args) {
	OverlayConfiguration.removeblacklist.wrapper('removeblacklist', args);
};