MGCCbEvoNS.opened_menu 		= 0;
MGCCbEvoNS.over_menu_item 	= 0;
MGCCbEvoNS.menu_pm_userid 	= 0;
MGCCbEvoNS.mouseX			= 0;
MGCCbEvoNS.mouseY			= 0;
function getPos(el) {
    // yay readability
    for (var lx=0, ly=0;
         el != null;
         lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return {x: lx,y: ly};
}

MGCCbEvoNS.show_chat_menu = function(chatid)
{
	if (!this.opened_menu)
	{
		this.opened_menu = chatid;	
		dojo.byId('mgc_cb_evo_popup_container').innerHTML = '<div class="cbmenu">' + dojo.byId('chat_' + chatid + '_menu').innerHTML + '</div>';

	   	/* Avoid chatbox refresh during menu actions */
   		clearTimeout(this.refresh_timeout);
	}
};

MGCCbEvoNS.hide_chat_menu = function(chatid,forced)
{
   	if (this.opened_menu)
	{
		this.opened_menu = 0;
		dojo.byId('mgc_cb_evo_popup_container').innerHTML = '';

   		/* Launch chatbox auto refresh */
	   	this.chatbox_refresh('forced');
  	}
  	
  	return false;
};

MGCCbEvoNS.hilite_chat_menu_item = function(menuitem)
{
	if (this.isvb4)
	{
		menuitem.className = 'cb_vbmenu_hilite';
	}
	else
	{
		menuitem.className = 'vbmenu_hilite';
	}
   
	this.over_menu_item = 1;

	return true;
};

MGCCbEvoNS.unhilite_chat_menu_item = function(menuitem)
{
	if (this.isvb4)
	{
		menuitem.className = 'cb_vbmenu_option';
	}
	else
	{
		menuitem.className = 'vbmenu_option';
	}
   
   	this.over_menu_item = 0;

	return true;
};

MGCCbEvoNS.confirm_menu_action = function(chatid,phrase_confirm,fct_callback)
{
   	this.hide_chat_menu(chatid,1);
   	this.show_yesnodialog(phrase_confirm,fct_callback);
   	return false;
};

MGCCbEvoNS.menu_report_chat = function(chatid)
{
	this.report_chatid = chatid;
	this.hide_chat_menu(chatid,1);
	this.show_promptdialog(phrase_enter_report_reason,"",'MGCCbEvoNS.report_chat');
	return false;
};

MGCCbEvoNS.menu_edit_chat = function(chatid)
{
	this.hide_chat_menu(chatid,1);
	this.edit_chat(chatid);
	return false;
};

MGCCbEvoNS.menu_delete_chat = function(chatid)
{
	this.hide_chat_menu(chatid,1);
	this.delete_chat(chatid);
	return false;
};

MGCCbEvoNS.menu_slap_user = function(userid)
{
	if (this.already_sending)
   	{
		this.show_dialog(phrase_error_chat_in_process,'');
   	}
   	else
   	{
      	this.already_sending = 1;
      	this.send_chat_post('/slap uid ' + userid,'');
   	}
   	return false;
};

MGCCbEvoNS.menu_ban_user = function(userid)
{
   	if (this.already_sending)
   	{
   		this.show_dialog(phrase_error_chat_in_process,'');
  	}
   	else
   	{
      	this.already_sending = 1;
      	this.send_chat_post('/ban on uid ' + userid,'');
   	}
   	return false;
};

MGCCbEvoNS.menu_delete_chat_by_cmd = function(chatid)
{
   	if (this.already_sending)
   	{
   		this.show_dialog(phrase_error_chat_in_process,'');
   	}
   	else
   	{
      	this.already_sending = 1;
      	this.send_chat_post('/del chatid ' + chatid,'');
   	}
   	return false;
};

MGCCbEvoNS.menu_delete_user_chats = function(userid)
{
   	if (this.already_sending)
   	{
   		this.show_dialog(phrase_error_chat_in_process,'');
   	}
   	else
   	{
      	this.already_sending = 1;
      	this.send_chat_post('/del uid ' + userid,'');
  	}
   	return false;
};

MGCCbEvoNS.menu_ignore_user = function(userid)
{
	if (this.already_sending)
	{
		this.show_dialog(phrase_error_chat_in_process,'');
   	}
   	else
   	{
      	this.already_sending = 1;
      	this.send_chat_post('/ignore on uid ' + userid,'');
   	}
   	return false;
};

MGCCbEvoNS.menu_send_pm = function(phrase_send_pm,userid)
{
   this.menu_pm_userid = userid;
   this.show_promptdialog(phrase_send_pm,'','MGCCbEvoNS.menu_send_pm_post');
   return false;
};

MGCCbEvoNS.menu_send_pm_post = function(message_escaped)
{
	if (this.already_sending)
   	{
		this.show_dialog(phrase_error_chat_in_process,'');
   	}
   	else
   	{
   		this.already_sending = 1;
      	this.send_chat_post('/pm uid ' + this.menu_pm_userid + ' ' + unescape(message_escaped));
   	}
   	return false;
}
