var chat_request = true;
var base_url = 'http://' + location.hostname;
var base_url_chat_manager = base_url;
var base_domain = def_base_domain;
var application_id = def_application_id;

/******************************************/
//finestra richiesta
/******************************************/
function RequestChat(){
	this.staticWindow = function(nick){
		var pre_win = {	
			"header": wait.header,
			"body": "<center><img src='images/loading.gif' alt=''/></center>",
			"footer": ""
		};

		var post_win = {	
			"header": _('Richiesta di chat'),
			"body": "",
			"footer": ""
		};
	
		this.preStaticWindow(this, pre_win, post_win, gui_base_url + 'request_chat_tpl/' + nick, "");
	};

	this.accept = function (nick){
		RequestChat.prototype.loadingWindow(this, '/gui_manager/request_chat/' + nick);
	};
	
	this.reject = function(profile_id){
		RequestChat.prototype.loadingWindow(this, '/gui_manager/reject_chat/' + profile_id);
	};
	
	this.blacklist = function(nick){
		RequestChat.prototype.loadingWindow(this, "/gui_manager/add_blacklist/" + nick);
	};
}
RequestChat.prototype = new WindowWidget();

var request_chat = new RequestChat();
request_chat.initialize("popup_window", properties);
request_chat.setObjectName("request_chat");

/******************************************/
// recupero richieste chat
/******************************************/
var rcvMessageCallback = { 
		
	success: function(o){

		try{
			request = YAHOO.lang.JSON.parse(o.responseText);
			
			// esiste una richiesta
			if(request.length > 0){
				request_chat.staticWindow(request[0]['nick']);
			}
		}
		catch (e){
		}
	}
}

function rcvMessage(){
	YAHOO.util.Connect.asyncRequest('POST', base_url + '/client_chat/get_richieste.php?client_status=closed', rcvMessageCallback, null);  
}

function init() {
  setInterval('rcvMessage()', 15000);
}
YAHOO.util.Event.onDOMReady(init);
