+function rcube_mail_ui()
+{
+ this.popups = {
+ markmenu: {id:'markmessagemenu'},
+ replyallmenu: {id:'replyallmenu'},
+ forwardmenu: {id:'forwardmenu', editable:1},
+ searchmenu: {id:'searchmenu', editable:1},
+ messagemenu: {id:'messagemenu'},
+ listmenu: {id:'listmenu', editable:1},
+ dragmessagemenu:{id:'dragmessagemenu', sticky:1},
+ groupmenu: {id:'groupoptionsmenu', above:1},
+ mailboxmenu: {id:'mailboxoptionsmenu', above:1},
+ composemenu: {id:'composeoptionsmenu', editable:1, overlap:1},
+ // toggle: #1486823, #1486930
+ uploadmenu: {id:'attachment-form', editable:1, above:1, toggle:!bw.ie&&!bw.linux },
+ uploadform: {id:'upload-form', editable:1, toggle:!bw.ie&&!bw.linux }
+ };
+
+ var obj;
+ for (var k in this.popups) {
+ obj = $('#'+this.popups[k].id)
+ if (obj.length)
+ this.popups[k].obj = obj;
+ else {
+ delete this.popups[k];
+ }
+ }
+}
+
+rcube_mail_ui.prototype = {
+
+show_popup: function(popup, show, config)
+{
+ var obj;
+ // auto-register menu object
+ if (!this.popups[popup] && (obj = $('#'+popup)) && obj.length)
+ this.popups[popup] = $.extend(config, {id: popup, obj: obj});
+
+ if (typeof this[popup] == 'function')
+ return this[popup](show);
+ else
+ return this.show_popupmenu(popup, show);
+},
+
+show_popupmenu: function(popup, show)
+{
+ var obj = this.popups[popup].obj,
+ above = this.popups[popup].above,
+ ref = rcube_find_object(popup+'link');
+
+ if (typeof show == 'undefined')
+ show = obj.is(':visible') ? false : true;
+ else if (this.popups[popup].toggle && show && this.popups[popup].obj.is(':visible') )
+ show = false;
+
+ if (show && ref) {
+ var parent = $(ref).parent(),
+ win = $(window),
+ pos = parent.hasClass('dropbutton') ? parent.offset() : $(ref).offset();
+
+ if (!above && pos.top + ref.offsetHeight + obj.height() > win.height())
+ above = true;
+ if (pos.left + obj.width() > win.width())
+ pos.left = win.width() - obj.width() - 30;
+
+ obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) });
+ }
+
+ obj[show?'show':'hide']();
+
+ if (bw.ie6 && this.popups[popup].overlap) {
+ $('select').css('visibility', show?'hidden':'inherit');
+ $('select', obj).css('visibility', 'inherit');
+ }
+},
+
+dragmessagemenu: function(show)
+{
+ this.popups.dragmessagemenu.obj[show?'show':'hide']();
+},
+
+forwardmenu: function(show)
+{
+ $("input[name='forwardtype'][value="+(rcmail.env.forward_attachment ? 1 : 0)+"]", this.popups.forwardmenu.obj)
+ .prop('checked', true);
+ this.show_popupmenu('forwardmenu', show);
+},
+
+uploadmenu: function(show)
+{
+ if (typeof show == 'object') // called as event handler
+ show = false;
+
+ // clear upload form
+ if (!show) {
+ try { $('#attachment-form form')[0].reset(); }
+ catch(e){} // ignore errors
+ }
+
+ this.show_popupmenu('uploadmenu', show);
+
+ if (!document.all && this.popups.uploadmenu.obj.is(':visible'))
+ $('#attachment-form input[type=file]').click();
+},
+
+searchmenu: function(show)
+{
+ var obj = this.popups.searchmenu.obj,
+ ref = rcube_find_object('searchmenulink');
+
+ if (typeof show == 'undefined')
+ show = obj.is(':visible') ? false : true;
+
+ if (show && ref) {
+ var pos = $(ref).offset();
+ obj.css({left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
+
+ if (rcmail.env.search_mods) {
+ var n, all,
+ list = $('input:checkbox[name="s_mods[]"]', obj),
+ mbox = rcmail.env.mailbox,
+ mods = rcmail.env.search_mods;
+
+ if (rcmail.env.task == 'mail') {
+ mods = mods[mbox] ? mods[mbox] : mods['*'];
+ all = 'text';
+ }
+ else {
+ all = '*';
+ }
+
+ if (mods[all])
+ list.map(function() {
+ this.checked = true;
+ this.disabled = this.value != all;
+ });
+ else {
+ list.prop('disabled', false).prop('checked', false);
+ for (n in mods)
+ $('#s_mod_' + n).prop('checked', true);
+ }
+ }
+ }
+ obj[show?'show':'hide']();
+},
+
+set_searchmod: function(elem)
+{
+ var all, m, task = rcmail.env.task,
+ mods = rcmail.env.search_mods,
+ mbox = rcmail.env.mailbox;
+
+ if (!mods)
+ mods = {};
+
+ if (task == 'mail') {
+ if (!mods[mbox])
+ mods[mbox] = rcube_clone_object(mods['*']);
+ m = mods[mbox];
+ all = 'text';
+ }
+ else { //addressbook
+ m = mods;
+ all = '*';
+ }
+
+ if (!elem.checked)
+ delete(m[elem.value]);
+ else
+ m[elem.value] = 1;
+
+ // mark all fields
+ if (elem.value != all)
+ return;
+
+ $('input:checkbox[name="s_mods[]"]').map(function() {
+ if (this == elem)
+ return;
+
+ this.checked = true;
+ if (elem.checked) {
+ this.disabled = true;
+ delete m[this.value];
+ }
+ else {
+ this.disabled = false;
+ m[this.value] = 1;
+ }
+ });
+},
+
+listmenu: function(show)
+{
+ var obj = this.popups.listmenu.obj,
+ ref = rcube_find_object('listmenulink');
+
+ if (typeof show == 'undefined')
+ show = obj.is(':visible') ? false : true;
+
+ if (show && ref) {
+ var pos = $(ref).offset(),
+ menuwidth = obj.width(),
+ pagewidth = $(document).width();
+
+ if (pagewidth - pos.left < menuwidth && pos.left > menuwidth)
+ pos.left = pos.left - menuwidth;
+
+ obj.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
+ // set form values
+ $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop('checked', true);
+ $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC');
+ $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC');
+ $('input[name="view"][value="thread"]').prop('checked', rcmail.env.threading ? true : false);
+ $('input[name="view"][value="list"]').prop('checked', rcmail.env.threading ? false : true);
+ // list columns
+ var found, cols = $('input[name="list_col[]"]');
+ for (var i=0; i<cols.length; i++) {
+ if (cols[i].value != 'from')
+ found = jQuery.inArray(cols[i].value, rcmail.env.coltypes) != -1;
+ else
+ found = (jQuery.inArray('from', rcmail.env.coltypes) != -1
+ || jQuery.inArray('to', rcmail.env.coltypes) != -1);
+ $(cols[i]).prop('checked', found);
+ }
+ }
+
+ obj[show?'show':'hide']();
+
+ if (show) {
+ var maxheight=0;
+ $('#listmenu fieldset').each(function() {
+ var height = $(this).height();
+ if (height > maxheight) {
+ maxheight = height;
+ }
+ });
+ $('#listmenu fieldset').css("min-height", maxheight+"px")
+ // IE6 complains if you set this attribute using either method:
+ //$('#listmenu fieldset').css({'height':'auto !important'});
+ //$('#listmenu fieldset').css("height","auto !important");
+ .height(maxheight);
+ };
+},
+
+open_listmenu: function(e)
+{
+ this.listmenu();
+},
+
+save_listmenu: function()
+{
+ this.listmenu();
+
+ var sort = $('input[name="sort_col"]:checked').val(),
+ ord = $('input[name="sort_ord"]:checked').val(),
+ thread = $('input[name="view"]:checked').val(),
+ cols = $('input[name="list_col[]"]:checked')
+ .map(function(){ return this.value; }).get();
+
+ rcmail.set_list_options(cols, sort, ord, thread == 'thread' ? 1 : 0);
+},
+
+body_mouseup: function(evt, p)
+{
+ var i, target = rcube_event.get_target(evt);
+
+ for (i in this.popups) {
+ if (this.popups[i].obj.is(':visible') && target != rcube_find_object(i+'link')
+ && !this.popups[i].toggle
+ && (!this.popups[i].editable || !this.target_overlaps(target, this.popups[i].id))
+ && (!this.popups[i].sticky || !rcube_mouse_is_over(evt, rcube_find_object(this.popups[i].id)))
+ ) {
+ window.setTimeout('rcmail_ui.show_popup("'+i+'",false);', 50);
+ }
+ }
+},
+
+target_overlaps: function (target, elementid)