// netMail (c) 1998-2007 Internet Connection, Inc.
window.NME=false;
window.VI=false;
window.LIMIT=20;
window.RUNNING=false;
window.COLOR={};
window.FAVICON=false;
window.EMPTY={};
if (location.href.substr(0,8) == 'https://') {
	window.BASE_HREF='https://' + document.domain + location.pathname + '/backend.cgi/';
} else {
	window.BASE_HREF='http://' + document.domain + location.pathname + '/backend.cgi/';
}
window.folview=false;
window.folcache=false;
window.folsize=false;
window.folfuture=false;
window.folunseen=false;

window.THROBBER=false;
window.TOOLBAR=false;
window.TREELIST=false;
window.HGRAB=false;
window.VGRAB=false;
window.BOXLIST=false;
window.LAYOUT=false;
window.VIEWLIST=false;
window.NEWLIST=false;
window.NEWACTOR=false;
window.INLINE_BLOCK='inline-block';
window.BLUR_TARGET=false;
window.DRAG_IMAGE=false;
window.POPLIST=false;
window.EXTOOL=false;
window.EXTOOL_BUTTON=false;
window.ATTLIST=false;
window.STATUSBOX=false;
window.ATTPICK=false;
window.contacts=false;
window._contacts_list=false;
window._labelcolors = {};
window._labelhide = {};

window.VWIDTH=false;
window.VHEIGHT=false;

window.sbwidth=0;
window.tbheight="38";
window.framewidth="6";
window.monthstr = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
window.dowstr = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
window.dowshortstr = ["Sun", "Mon","Tue","Wed","Thu","Fri","Sat"];

window.color_schemes = {};
color_schemes['Redmond'] = function() {
	COLOR.info = '#ffffe1';
	COLOR.infoText = '#000000';
	COLOR.menu = '#ffffff';
	COLOR.menuText = '#040000';
	COLOR.button = '#f0f0f0';
	COLOR.buttonText = '#040000';
	COLOR.buttonBorder = '#c4c4c0';
	COLOR.window = '#f3f5f7 #eceadb h';
	COLOR.windowText = '#000000';
	COLOR.windowLinks = '#27831b';
	COLOR.innerWindow = '#ffffff';
	COLOR.innerWindowText = '#000000';
	COLOR.grayText = '#d7dee9';
	COLOR.hilight = '#316ac5';
	COLOR.hilightText = '#ffffff';
};
color_schemes['Palo Alto'] = function() {
	COLOR.info='#ad1410';
	COLOR.infoText='#ffffff';
	COLOR.menu = '#f7f7ff';
	COLOR.menuText='#42556b';
	COLOR.window = '#08808c #37a3a7 v';
	COLOR.windowText='#eeeeee';
	COLOR.windowLinks = '#fffaa0';
	COLOR.innerWindow = '#eff3ef';
	COLOR.innerWindowText='#080c08';
	COLOR.grayText='#9c9e9c';
	COLOR.hilight='#8c1008';
	COLOR.hilightText='#ffffff';
};
color_schemes['Chicago'] = function() {
	COLOR.info='#e7eff7';
	COLOR.infoText='#000000';
	COLOR.menu = '#f7f7f7';
	COLOR.menuText='#000000';
	COLOR.window = '#c0c0c0 #efefef v';
	COLOR.windowText='#000000';
	COLOR.innerWindow = '#ffffff';
	COLOR.innerWindowText='#212421';
	COLOR.grayText='#9c9e9c';
	COLOR.hilight='#9cc3ef';
	COLOR.hilightText='#080808';
};
color_schemes['Boston'] = function() {
	COLOR.info = '#3f611e';
	COLOR.infoText = '#fcffff';
	COLOR.menu = '#ffffff';
	COLOR.menuText = '#040000';
	COLOR.button = '#40c040';
	COLOR.buttonText = '#040000';
	COLOR.window = '#46b014 #30a030 v';
	COLOR.windowText = '#fffff3';
	COLOR.windowLinks = '#f0f0ce';
	COLOR.innerWindow = '#ffffff';
	COLOR.innerWindowText = '#000000';
	COLOR.grayText = '#898989';
	COLOR.hilight = '#e5f9d4';
	COLOR.hilightText = '#296c12';
};
color_schemes['Oxford'] = function() {
	COLOR.info = '#c6e0c6';
	COLOR.infoText = '#003300';
	COLOR.menu = '#ffffff';
	COLOR.menuText = '#040000';
	COLOR.window = '#cccc99';
	COLOR.windowText = '#333333';
	COLOR.windowLinks = '#333366';
	COLOR.innerWindow = '#eeeeee';
	COLOR.innerWindowText = '#333333';
	COLOR.grayText = '#999999';
	COLOR.hilight = '#e0e0c6';
	COLOR.hilightText = '#333333';
};
color_schemes['Hotdog Stand'] = function() {
	COLOR.info = '#000000';
	COLOR.infoText = '#ffffff';
	COLOR.menu = '#ffffff';
	COLOR.menuText = '#000000';
	COLOR.button = '#c0c0c0';
	COLOR.buttonText = '#000000';
	COLOR.window = '#ffff00';
	COLOR.windowText = '#000000';
	COLOR.windowLinks = '#333333';
	COLOR.innerWindow = '#ff0000';
	COLOR.innerWindowText = '#ffffff';
	COLOR.grayText = '#808080';
	COLOR.hilight = '#000000';
	COLOR.hilightText = '#ffffff';
};


window.config=false;
window.default_pref = {};
default_pref['font_app'] = '';
default_pref['font_read'] = '';
default_pref['colorscheme'] = '';

default_pref['calview'] = 'day';
default_pref['alert_icon'] = true;
default_pref['alert_sound'] = false;
default_pref['use_gmt'] = false;
default_pref['blockimages'] = true;
default_pref['copysent'] = true;
default_pref['auto_cc'] = '';
default_pref['auto_bcc'] = '';
default_pref['view_raw'] = false;
default_pref['auto_contacts'] = true;
default_pref['auto_spell'] = false;
default_pref['edit_sig'] = '';
default_pref['autotext_0'] = '';
default_pref['autotext_1'] = '';
default_pref['autotext_2'] = '';
default_pref['autotext_3'] = '';
default_pref['autotext_4'] = '';
default_pref['edit_spell'] = true;
default_pref['edit_autosave'] = true;
default_pref['edit_cc'] = true;
default_pref['_le_autoedit'] = '0';
default_pref['edit_bcc'] = false;
default_pref['edit_vi'] = false;
default_pref['plan_day_start'] = 8;
default_pref['plan_day_end'] = 18;
default_pref['unstable'] = '';

window.logged_in = {};

function _update_and_alert() {
	if (WANT('alert_icon')) {
		icon_alert$();
	}
	if (WANT('alert_sound')) {
		sound_alert$();
	}
	_update_mail_containers();
}

function RSRC$(u) {
	if (!RSRC$._map[u]) {
		if (RSRC$._num >= RSRC$._set.length) RSRC$._num = 0;
		RSRC$._map[u] = '' + RSRC$._set[ RSRC$._num ] + '.rsrc.dmvnoc.com';
		RSRC$._num++;
	}
	return 'http://' + RSRC$._map[u] + '/netmail/' + u;
}
RSRC$._num = 0;
RSRC$._map = {};
RSRC$._set = ['a','b','c','d','e','f','g','h'];

function FOLPART$(s) {
	if (!s) s = '';
	var i,j;
	for (i = s.length-1; i >= 0; i--) {
		j=s.charAt(i);
		if (j == '/') {
			return s.substr(0, i);
		}
	}
	return s;
}
function MSGPART$(s) {
	if (!s) s = '';
	var i,j;
	for (i = s.length-1; i >= 0; i--) {
		j=s.charAt(i);
		if (j == '/') {
			i++;
			j = s.charAt(i);
			if (j == ':') return s.substr(i+1, s.length-(i+1));
			return s.substr(i, s.length-i);
		}
	}
	return s;
}
function SQUEEZE$(s,ag,r) {
	if (!s) s = '';
	if (!ag) ag = " ";
	if (!r) r = " ";
	var i,j,k;
	k = 0;
	var o = '';
	var latch = false;
	for (i = 0; i < s.length; i++) {
		j = s.charAt(i);
		if (ag.indexOf(j) == -1) {
			latch=false;
			continue;
		}
		if (latch == true) {
			k++;
			continue;
		}

		latch=true;
		if (i != k) {
			o = o + s.substr(k, i-k) + r;
		} else {
			o = o + r;
		}
		k = i+(r.length-1);
		i = k-1;
	}
	if (o == '' && k == 0) return s; // ideal: no matches
	return o + s.substr(k, s.length-k);
}
function STRIP$(s,ag) {
	if (!s) s = '';
	if (!ag) ag = "\r";
	var i,j,k;
	k = 0;
	var o = '';
	for (i = 0; i < s.length; i++) {
		j = s.charAt(i);
		if (ag.indexOf(j) == -1) continue;
		if (i != k) o = o + s.substr(k, i-k);
		k = i+1;
	}
	if (o == '' && k == 0) return s; // ideal: no matches
	return o + s.substr(k, s.length-k);
}
function TR$(s,x,y) {
	if (!s) s = '';
	var i,j,k;
	var o = '';
	for (i = 0; i < s.length; i++) {
		j=s.charAt(i);
		k = x.indexOf(j);
		if (k > -1) {
			if (o.length < i) {
				o = o + s.substr(o.length, i-o.length) + y.charAt(k);
			} else {
				o = o + y.charAt(k);
			}
		}
	}
	if (o == '') return s; // ideal: no matches
	return o + s.substr(o.length, s.length-o.length);
}
function FIRST$(s,ag) {
	if (!s) s = '';
	var i,j;
	if (!ag) ag = " \t\r\n";
	for (i = 0; i < s.length; i++) {
		j=s.charAt(i);
		if (ag.indexOf(j) > -1) break;
	}
	return s.substr(0, i);
}
function LTRIM$(s, ag) {
	var i,j;
	if (!ag) ag = " \t\r\n";
	for (i = 0; i < s.length; i++) {
		j=s.charAt(i);
		if (ag.indexOf(j) > -1) continue;
		return s.substr(i, s.length-i);
	}
	return '';
}
function RTRIM$(s,ag) {
	if (!s) s = '';
	var i,j;
	if (!ag) ag = " \t\r\n";
	for (i = s.length-1; i >= 0; i--) {
		j=s.charAt(i);
		if (ag.indexOf(j) > -1) continue;
		return s.substr(0, i+1);
	}
	return '';
}
function TRIM$(s,ag) {
	return RTRIM$(LTRIM$(s,ag),ag);
}

function tbsheight() {
	if (window._name) return parseInt(window.tbheight);
	if (window._tb_opened) return parseInt(window.tbheight) + window._tb_opened.offsetHeight;
	return parseInt(window.tbheight);
}
function isLoggedIn(who) {
	if (config && who == config['$user']) return undefined;

	var p = window;
	while (p._parentWindow && p._parentWindow != p) {
		p = p._parentWindow;
	}

	if (p.logged_in && p.logged_in['+' + who]) {
		var ad = p.logged_in['+'+who];
		if (p.logged_in['-' + who]) {
			var bd = p.logged_in['-'+who];
			if (ad >= bd) return true;
			return undefined;
		}
		var nd = new Date();
		nd = nd.getMilliseconds();
		if (ad+30000 < nd) return undefined; // might not be logged in anymore...
		return true;
	}
	return undefined;
}
function BASE64(input) {
	if (window.btoa) return window.btoa(input);
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	do {
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);

		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;

		if (isNaN(chr2)) {
			enc3 = enc4 = 64;
		} else if (isNaN(chr3)) {
			enc4 = 64;
		}
		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
				keyStr.charAt(enc3) + keyStr.charAt(enc4);
	} while (i < input.length);
	return output;
}
function _search_keydown(e) {
	e=E$(e);
	var k;
	if (e.keyCode) k = e.keyCode;
	else if (e.which) k = e.which;
	else return true;
	if (k == 27 || k == 13 || k ==10) {
		return PD$(e);
	}
	return true;
}
function _popd_position_resize() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	var c2 = popd._button;
	if (c1 && c1.parentNode && popd && popd.parentNode && c2 && c2.parentNode) {
		var aow = ((popd.offsetWidth - c2.offsetWidth)-2);
		if (aow < 1) aow = 0;
		c1.style.width = aow + 'px';
	}
}
function _popd_position_fixup() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	var c2 = popd._button;
	resizeListen(popd, "HGRAB._position+"+framewidth, tbheight, "pagewidth()-("+framewidth+"+HGRAB._position)", popd.offsetHeight, true);
	resizeHelper(_popd_position_resize);
	popd.style.visibility='visible';
}
function _popd_c2_disable_update() {
	if (window._tb_opened) {
		var popd = window._tb_opened;
		var c2 = popd._button;
		c2.value = 'Search';
		c2.disabled = true;
	}
	update_listview();
}
function _popd_c2_enable_update() {
	if (window._tb_opened) {
		var popd = window._tb_opened;
		var c2 = popd._button;
		c2.value = 'Clear';
		c2.disabled = false;
	}
	update_listview();
}
function _popd_c2_start_search() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	var fol = window._current_folder;
	window._viewoptions = {};
	window._viewoptions.search = c1.value;
	window.folview[fol] = undefined; // wee...
	fetchview(fol, window._viewoptions, _popd_c2_enable_update);
}
function _popd_c2_click() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	var c2 = popd._button;
	if (this.value == 'Clear') {
		c1.value = '';
	}

	var fol = window._current_folder;
	if (c1.value == '' || c1.value == c1.defaultvalue) {
		// remove filter
		c1.value = c1.defaultvalue;
		BGCOLOR(c1,COLOR.innerWindow);
		FGCOLOR(c1,COLOR.grayText);
		if (typeof window._viewoptions != 'undefined') {
			window._viewoptions = undefined;
			window.folview[fol] = undefined;
			fetchview(fol, {}, _popd_c2_disable_update);
		} else {
			c2.value = 'Search';
			c2.disabled = false;
		}
	} else {
		// filter on c1.value
		BGCOLOR(c1,COLOR.info);
		FGCOLOR(c1,COLOR.infoText);

		window.folsize[fol] = 0;
		update_listview(true);

		window.setTimeout(_popd_c2_start_search);
	}
	blur$();
}
function _popd_c1_keyup(e) {
	e=E$(e);
	if (!window._tb_opened) return PD$(e);
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	var c2 = popd._button;
	var k;
	if (e.keyCode) k = e.keyCode;
	else if (e.which) k = e.which;
	else return true;
	if (k == 27 || k == 13 || k ==10) {
		c2.value = (k==27) ? 'Clear' : 'Search';
		c2.onclick();
		return PD$(e);
	}
	if (c1.value == '' || c1.value == c1.defaultvalue) {
		if (typeof window._viewoptions != 'undefined') {
			c2.value = 'Clear';
			c2.disabled = false;
		} else {
			c2.value = 'Search';
			c2.disabled = true;
		}
	} else {
		c2.value = 'Search';
		c2.disabled = false;
	}
	return true;
}
function _popd_c1_focus() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	if (c1.value == c1.defaultvalue) {
		c1.value = '';
		BGCOLOR(c1,COLOR.innerWindow);
		FGCOLOR(c1,COLOR.innerWindowText);
	} else {
		if (c1.select) c1.select();
	}
}
function _popd_c1_blur() {
	if (!window._tb_opened) return;
	var popd = window._tb_opened;
	var c1 = popd._textbox;
	if (c1.value == '' || c1.value == c1.defaultvalue) {
		c1.value = c1.defaultvalue;
		BGCOLOR(c1,COLOR.innerWindow);
		FGCOLOR(c1,COLOR.grayText);
	}
}
function _searchbox_vis(text) {
	if (window._tb_opened) {
		var b = window._tb_opened;
		b.parentNode.removeChild(b);
		var popd = window._tb_opened;
		popd._textbox = undefined;
		popd._button = undefined;
		window._tb_opened = undefined;
	}
	if (text == '') return;

	var popd = document.createElement('DIV');

	var c1 = document.createElement('INPUT');
	c1.type = 'text';
	c1.defaultvalue = 'Search by '+text;
	c1.value = c1.defaultvalue;

	var c2 = document.createElement('INPUT');
	c2.type = 'button';
	c2.value = 'Search';
	c2.style.width = '5em';
	c2.onclick = _popd_c2_click;
	c2.disabled = true;

	c1.onkeydown = c1.onkeypress = _search_keydown;
	c1.onkeyup = _popd_c1_keyup;
	c1.onfocus = _popd_c1_focus;
	c1.onblur = _popd_c1_blur;
	inset$(c1);
	outset$(c2);

	BGCOLOR(c1,COLOR.innerWindow);
	FGCOLOR(c1,COLOR.grayText);

	c1.className = 'noprint';
	c2.className = 'noprint';
	popd.className = 'noprint';

	popd.appendChild(c1);
	popd.appendChild(c2);
	LAYOUT.appendChild(popd);
	popd.style.whiteSpace='nowrap';
	popd.style.visibility='hidden';
	popd._textbox = c1;
	popd._button = c2;

	window._tb_opened = popd;
	window.setTimeout(_popd_position_fixup, 10);
}

function onclose$(w,f) {
	f.__fini_fini = undefined;
	f.__fini_helper = function() {
		if (!f.__fini_fini || f.__fini_fini != true) {
			f.__fini_fini = true;
			f();
		}
		try {
			if (w) w.opener=undefined;
		} catch(e) {};
	};
	if (w.addEventListener && w.addEventListener('onunload', f.__fini_helper, false)) {
		return;
	}
	if (w.addEventListener && w.addEventListener('onbeforeunload', f.__fini_helper, false)) {
		return;
	}
	// opera doesn't support onunload... no idea why...
	f.__clear_latch = window.setInterval(function() {
		var fz = undefined;
		try {
			if (f && w && w.closed) fz=true;
		} catch(e) {
			fz = true;
		};
		if (fz && f.__clear_latch) {
			try {
				window.clearInterval(f.__clear_latch);
			} catch(e) {};
			f.__clear_latch = undefined;
			try {
				f.__fini_helper();
			} catch(e) {};
		}
	}, 100);
}

function FGCOLOR(o,c) {
	if (c.indexOf(' ') == -1) {
/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
  		o.runtimeStyle.color = c;
		return;
}
@end @*/
		o.style.color = c;
	} else {
		var co = c.split(" ");
		FGCOLOR(o,co[0]);
	}
}

function BGCOLOR_canvas_helper() {
	var pw = pagewidth();
	var ph = pageheight();

	var co = COLOR.window.split(" ");
	if (co.length == 1) co[1] = co[0];
	var x1 = document.getElementById('x1');
	var d = x1.getContext('2d');
	var i = BGCOLOR_canvas_helper.startat||0;
	if (i == 0) {
		x1.setAttribute('width', pw);
		x1.setAttribute('height', ph);
	}
	if (co[2] && co[2].substr(0,1).toLowerCase() == 'v') {
		for (; i < BGCOLOR.set.length; i++) {
			var nn = BGCOLOR.set[i];
			if (!nn.parentNode) {
				continue;
			}
	
			_ao(nn);
	
			var cg = d.createLinearGradient(0,0,0,nn.offsetHeight);
			cg.addColorStop(0, co[0]); cg.addColorStop(1, co[1]);
			d.fillStyle = cg;
			d.fillRect(0,nn._py,pw,nn._py+nn.offsetHeight);
			d.fill();
		}
	} else {
		for (; i < BGCOLOR.set.length; i++) {
			var nn = BGCOLOR.set[i];
			if (!nn.parentNode) {
				continue;
			}
	
			_ao(nn);
	
			var cg = d.createLinearGradient(0,0,nn.offsetWidth,0);
			cg.addColorStop(0, co[0]); cg.addColorStop(1, co[1]);
			d.fillStyle = cg;
			d.fillRect(nn._px,nn._py,nn._px+nn.offsetWidth,nn.offsetHeight);
			d.fill();
		}
	}
	BGCOLOR_canvas_helper.startat = i;
}

function BGCOLOR(o,c) {
	if (c.indexOf(' ') == -1) {
/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
  		if (o._filtered) o.runtimeStyle.filter = '';
  		o.runtimeStyle.backgroundColor = c;
		return;
}
@end @*/
		o.style.backgroundColor = c;
	} else if (window._can_canvas && c == COLOR.window) {
		// <canvas> systems must not leak memory here...
		o.style.backgroundColor = 'transparent';
		o.style.background = 'transparent';

		if (!BGCOLOR.set) {
			BGCOLOR.set = [];
		}
		BGCOLOR.set[ BGCOLOR.set.length ] = o;
		if (!BGCOLOR._timing) {
			BGCOLOR_canvas_helper.startat = 0;
			BGCOLOR._timing = window.setTimeout(function() {
				BGCOLOR._timing = undefined;
				if (!BGCOLOR._did_helper) {
					BGCOLOR._did_helper = true;
					resizeHelper(function() {
						BGCOLOR_canvas_helper.startat = 0;
						BGCOLOR_canvas_helper();
					});
				} else {
					BGCOLOR_canvas_helper();
				}
			}, 0);
		}

	} else {
		var co = c.split(" ");
/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
		var gt=(co[2] && co[2].substr(0,1).toLowerCase() == 'v') ? 0 : 1;
  		o._filtered=true;
		o.runtimeStyle.backgroundColor = co[1];
		o.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType="+gt
				+",StartColorStr=\"" + co[0]
				+ "\",EndColorStr=\"" + co[1] + "\")";
		return;
}
@end @*/
		o.style.backgroundColor=co[1];
	}
}

function _util_window() {
	var cn = arguments.callee._callnumber;
	if (!cn) cn=0;
	arguments.callee._callnumber = cn+1;
	var nd = new Date();
	var name = '_util_window'+cn+'_'+parseInt(nd.getMilliseconds());
	return window.open('',name,'menubar=no,toolbar=no,status=yes,location=no,width=500,height=300');
}

function nullhref() {
	var cn = nullhref.callnum;
	if (!cn)cn=0;
	nullhref.callnum = cn+1;
	var nd = new Date();
	var uu = cn+'_'+nd.getMilliseconds();
	return 'javascript:void(0);//'+uu;
}
function Queue_runqueue() {
	if (this._locklevel > 3) return this;

	var r;
	if (this._uq.length > 0) {
		r = this._uq[this._uq.length-1];
		this._uq.length--;
	} else if (this._mq.length > 0) {
		r = this._mq[this._mq.length-1];
		this._mq.length--;
	}
	if (r) {
		this.lock();
		(function(oz,agr) {
			window.setTimeout(function() {
				var zod=undefined;
				try {
					agr();
				} catch(e) {
					zod=e;
				};
				oz.unlock();
				if (typeof zod != 'undefined') throw zod;
			}, 1);
		})(this, r);
	}
	return this;
}
function Queue_lock(s) {
	if (typeof s != 'undefined') {
		if (this._locks[s]) return this;
		this._locks[s]=true;
	}
	this._locklevel++;
	return this;
}
function Queue_unlock(s) {
	if (typeof s != 'undefined') {
		if (!this._locks[s]) return this._runqueue();
		this._locks[s]=undefined;
	}
	this._locklevel--;
	if (this._locklevel < 0) throw "Unbalanced locks";
	return this._runqueue();
}
function Queue_insert(f) {
	this._uq[ this._uq.length ] = f;
	return this._runqueue();
}
function Queue_append(f) {
	this._mq[ this._mq.length ] = f;
	return this._runqueue();
}
function Queue_sizeof() {
	return this._uq.length + this._mq.length;
}
function Queue_busy() {
	if (this._uq.length > 0) return true;
	if (this._locklevel > 3) return true;
	return false;
}
function Queue_empty() {
	this._uq = [];
	this._mq = [];
}
function Queue() {
	this._uq = [];
	this._mq = [];
	this._locklevel=0;
	this._locks={};
	this._runqueue = Queue_runqueue;
	this.lock = Queue_lock;
	this.unlock = Queue_unlock;
	this.insert = Queue_insert;
	this.append = Queue_append;
	this.sizeof = Queue_sizeof;
	this.busy = Queue_busy;
	this.empty = Queue_empty;
	return this;
}
function setselection$(elm,h,t) {
	if (elm.setSelectionRange) {
		elm.focus();
		elm.setSelectionRange(h,t);
	} else if (elm.createTextRange) {
		var r = elm.createTextRange();
		r.collapse(true);
		r.moveEnd('character', t);
		r.moveStart('character', h);
		r.select();
	} else {
		elm.selectionStart=h;
		elm.selectionEnd=t;
	}
	elm._selstart = h;
	elm._selend = t;
}
function imgtag$() {
	var img = document.createElement('IMG');
	img.galleryimg = false;
	return img;
}
function imgsrc$(o,s,w,h) {
	o.border=0;
	o.style.margin = '0';
	o.style.padding = '0';
	if (!s || s == '') s = 'blank.gif';
	o.src=s;
	o.width = w;
	o.height = h;
	o.style.width=w+'px';
	o.style.height=h+'px';
	o.style.lineHeight=h+'px';
	return o;
}


function blur$() {
	if (BLUR_TARGET) BLUR_TARGET.focus();
	_fix_status();
	window.setTimeout(_fix_status,1);
}

function grep$(f,o) {
	var no = [];
	var i;
	for (i = 0; i < o.length; i++) {
		if (apply$(o[i],f)) no[no.length] = o[i];
	}
	return no;
}
function map$(f,o) {
	var no = [];
	var i;
	for (i = 0; i < o.length; i++) {
		no[no.length] = apply$(o[i], f);
	}
	return no;
}
function sed(f,r,t) {
	if (typeof f == 'undefined') f='';
	var z = f.replace(r,t);
	if (typeof z == 'undefined') return f;
	return z;
}
function _aso(o) {
	var x = 0;
	var y = 0;
	var zo = o;
	while (o && o != document.body) {
		x += o.offsetLeft-o.scrollLeft;
		y += o.offsetTop-o.scrollTop;
		o = o.offsetParent;
	}
	zo._px = x;
	zo._py = y;
}
function _aot(o) { // like ao but handles case where searching inside a <table>
	var x = 0;
	var y = 0;
	var zo = o;

	// check safari first
	_ao(zo);
	if (zo._px > 1 || zo._py > 1) {
		// this is a safari bug; we check for it like this in case apple
		// fixes it in the future (Konquerer already has it fixed)
		// this nme-specific though; we'll always use a margin of 2 or 4
		// as according to the hig
		var vw = window.__current_view_obj||undefined;
		if (vw) zo._py -= vw.scrollTop;
		return;
	}

	// the table we're talking about has a margin=2
	if (o.parentNode && o.parentNode.tagName && o.parentNode.tagName.toUpperCase() == 'TD') {
		var no = o.parentNode.previousSibling;
		for (; no; no = no.previousSibling) {
			x += no.offsetWidth+4;
		}
		no = o.parentNode.parentNode;
		if (no.tagName && no.tagName.toUpperCase() == 'TR') {
			no = no.previousSibling;
			for (; no; no = no.previousSibling) {
				var nd = no.firstChild;
				var tallest = no.offsetHeight+4;
				for (; nd; nd = nd.nextSibling) {
					var ny=nd.offsetHeight+4;
					if (ny > tallest) tallest = ny;
				}
				y += ny;
			}
		}
		no = o.parentNode.parentNode;
		while (no && no != document.body && no.tagName.toUpperCase() != 'TBODY')
			no = no.parentNode;
		o = no;
	}

	while (o && o != document.body) {
		x += o.offsetLeft-o.scrollLeft;
		y += o.offsetTop-o.scrollTop;
		o = o.offsetParent;
	}

	var vw = window.__current_view_obj||undefined;
	if (vw) zo._py -= vw.scrollTop;

	zo._px = x;
	zo._py = y;

}
function _ao(o) {
	var x = 0;
	var y = 0;
	var zo = o;
	while (o && o != document.body) {
		x += o.offsetLeft;
		y += o.offsetTop;
		o = o.offsetParent;
	}

	zo._px = x;
	zo._py = y;
}
function _gstr(elm) {
	elm._selstart= elm.selectionStart||undefined;
	elm._selend= elm.selectionEnd||undefined;
	if (typeof elm._selstart != 'undefined' && typeof elm._selend != 'undefined')
		return;
		
	if (window.getSelection) {
		var sel = window.getSelection();
		if (!sel) return;
		if (sel.startContainer && sel.startContainer == elm) {
			elm._selstart = sel.startOffset;
			elm._selend = sel.endOffset;
			return;
		}
	}
	if (document.selection) {
		try {
			var r = document.selection.createRange().duplicate();

                	var nrr = elm.createTextRange().duplicate();
                	var nsr = nrr.duplicate();
			nrr.collapse(true);
			nsr.collapse(true);
			var a1 = nrr.getBookmark();
			var a2 = nsr.getBookmark();

			var sr = r.duplicate();
			if (r.compareEndPoints('StartToEnd', r) != 0) {
				r.collapse(true);
				sr.collapse(false);
			}
			var b1 = r.getBookmark();
			var b2 = sr.getBookmark();

			elm._selstart = (b1.charCodeAt(2)-2)-(a1.charCodeAt(2) - 2);
			elm._selend = (b2.charCodeAt(2)-2)-(a2.charCodeAt(2) - 2);

		}catch(e) {
		}
	}
}
function map_collection(f) {
	var mailbox = window._current_folder;
	var mdata = folcache[mailbox];
	var vr = folview[mailbox];
	if (!vr || !mdata) return;
	for (i in window._select_group) {
		if (window._select_group[i]) {
			var msg = mdata[vr[i]];
			apply$(msg, f);
		}
	}
}
function get_auto_contacts() {
	if (!config) return undefined;
	var p = window;
	while (p._parentWindow && p._parentWindow != p) {
		p = p._parentWindow;
	}
	if (!p.logged_in) return undefined;

	var j;
	var nl = {};
	for (j in p.logged_in) {
		try {
			if (j.substr(0, 1) == '-') continue;
			var who = j.substr(1, j.length-1);
			if (!isLoggedIn(who)) continue;
			var b = who + '@' + config['$domain'];

			var str = '<' + QC(b) + '> (logged in now)';
			contacts_apply_cl(nl, '', b, str);

		} catch(e) {};
	}
	return nl;
}
function get_contacts() {
	var p = window;
	while (p._parentWindow && p._parentWindow != p) {
		p = p._parentWindow;
	}
	if (p._contacts_list) {
		return p._contacts_list;
	}
	return {};
}
function map_contactsByAddress(ee,f) {
	var p = window;
	while (p._parentWindow && p._parentWindow != p) {
		p = p._parentWindow;
	}
	if (p.contacts) {
		var i;
		ee = ee.toLowerCase();
		for (i = 0; i < p.contacts.length; i++) {
			if (!p.contacts[i]) continue;
			var cm = p.contacts[i];
			var cm = cm['email;internet']||cm.email||'';
			if (VC(cm).toLowerCase() == ee) {
				apply$(p.contacts[i], f);
			}
		}
	}
}
function map_contactsByID(id, f) {
	var p = window;
	while (p._parentWindow && p._parentWindow != p) {
		p = p._parentWindow;
	}
	if (p.contacts) {
		var j;
		for (j = 0; j < p.contacts.length; j++) {
			if (p.contacts[j] && p.contacts[j].ID == id) {
				apply$(p.contacts[j], f);
				break;
			}
		}
	}
}

var noticex, noticey;
function _notice_cleartimer() {
	_notice_setup.timer = undefined;
	notice$('');
}
function _notice_setup() {
	var px = noticex-parseInt(STATUSBOX.offsetWidth/2);
	var pw = pagewidth()-STATUSBOX.offsetWidth;
	if (px < 0) px = 0;
	else if (px > pw) px = pw;

	var py = noticey-parseInt(STATUSBOX.offsetHeight/2);
	var ph = pageheight()-STATUSBOX.offsetHeight;
	if (py < 0) py = 0;
	else if (py > ph) py = ph;

	STATUSBOX.style.top = py+'px';
	STATUSBOX.style.left = px+'px';
	STATUSBOX.style.visibility='visible';
	STATUSBOX._opaq=0.0;
	STATUSBOX._dir=0.5;
	if (_notice_setup.timer)
		window.clearTimeout(_notice_setup.timer);
	_notice_setup.timer = window.setTimeout(_notice_cleartimer,2000);
}
function notice$(s) {
	if (s == '') {
		if (_notice_setup.timer)
			window.clearTimeout(_notice_setup.timer);
		STATUSBOX.style.visibility='hidden';
		return;
	}
	while (STATUSBOX.firstChild) STATUSBOX.removeChild(STATUSBOX.firstChild);
	STATUSBOX.appendChild(document.createTextNode(s));
	STATUSBOX.style.visibility='hidden';
	STATUSBOX.style.display='block';
	window.setTimeout(_notice_setup, 10);
}
function textedit$insert(t,s) {
	_gstr(t);
	var a1 = t._selstart;
	var a2 = t._selend;
/*@cc_on @*/
/*@if (@_jscript_version < 5.7) {
	var i;
	var x = 0;
	for (i = 0; i < t.value.length; i++) {
		if (t.value.substr(i, 1) != '\r') {
			if (x == t._selstart) {
				a1 = i;
			}
			if (x == t._selend) {
				a2 = i;
			}
			x++;
		}
	}
  }
@end @*/

	var cv = t.value;
	t.value = cv.substr(0, a1) + s + cv.substr(a2);
	setselection$(t, t._selend+s.length, t._selend+s.length);
}

function _tx_onkey() {
	if (this.value == this._last_value) return;
	this._last_value = this.value;
	this._bound_func(this.value);
}
function _tx_onAC(ac) {
	if (ac.indexOf('vCard') > -1) {
		this.vcard_name = ac;
	} else {
		this.autocomplete = ac;
	}
	return this;
}
function _tx_bindto(f) {
	this._bound_func = f;
	return this;
}
function textedit$(value, lines) {
	var tx;
	if (lines > 1) {
		tx = document.createElement('TEXTAREA');
		tx.setAttribute('ROWS', ""+lines);
		tx.rows=lines;
	} else {
		tx = document.createElement('INPUT');
		tx.type = 'text';

	}
	tx.style.width = '100%';
	tx.style.margin = '0';
	tx.style.padding = '0';
	BGCOLOR(tx,COLOR.innerWindow);
	FGCOLOR(tx,COLOR.innerWindowText);
	tx._bound_func = true$;
	tx._last_value = value;
	tx.bindTo = _tx_bindto;
	tx.onchange = tx.oninput = tx.onkeydown = tx.onkeyup = tx.onkeypress = _tx_onkey;
	tx.AC = _tx_onAC;
	inset$(tx);
	tx.value = value;
	return tx;
}
var _autocomp;
var _autocomp_hits;
function _autocomplete_zero() {
	_autocomp = [];
	_autocomp_hits = {};
}
function _autocomplete_add_sub(s, t1, t2) {
	var i;
	for (i = 0; i < s.length; i++) {
		var j = s[i];
		if (!j) j = '';
		j = (j + '').toLowerCase();

		var xk = -1;
		if (typeof t2 != 'undefined') {
			xk = j.indexOf('"' + t2);
		}
		if (xk == -1 && typeof t2 != 'undefined') {
			xk = j.indexOf('<' + t1);
		}
		if (xk == -1 && (typeof t2 != 'undefined') && t2.indexOf(' ') == -1) {
			xk = j.indexOf('<' + t2);
		}
		if (xk == -1 && (typeof t1 != 'undefined') && t1.indexOf(' ') == -1) {
			xk = j.indexOf('<' + t1);
		}
		if (xk > -1) {
			if (!_autocomp_hits[j]) {
				_autocomp_hits[j] = true;
				_autocomp[_autocomp.length] = j;
			}
		}
	}
}
function _autocomplete_add(s, t1, t2) {
	var i;
	if (typeof t1 != 'undefined') t1 = t1.toLowerCase();
	if (typeof t2 != 'undefined') t2 = t2.toLowerCase();
	if (typeof t1 == 'undefined' && typeof t2 == 'undefined')
		return;
	if (t1 == '' && t2 == '')
		return;

	if (typeof t1 != 'undefined' && (t1.length > 0)) {
		var k1 = t1.substr(0, 1).toLowerCase();
		if (typeof s[k1] != 'undefined') {
			_autocomplete_add_sub(s[k1], t1, t2);
		}
	}
	if (typeof t2 != 'undefined' && (t2.length > 0)) {
		var k2 = t2.substr(0, 1).toLowerCase();
		if (typeof s[k2] != 'undefined') {
			_autocomplete_add_sub(s[k2], t1, t2);
		}
	}

}

var dom_autocomplete;
var dom_keyholder;

function _xtc_ondblclick() {
	(function(fah) {
		window.setTimeout(function() {
			var xt = fah._boundto;
			var no = fah.options[fah.selectedIndex].value;
			if (fah._eatme > -1) {
				xt.value = LTRIM$(RTRIM$(xt.value.substr(0, fah._eatme), " ,") + ', ' + no + ', ',
					" ,");
					
				fah._eatme = -1;
				fah.style.display = 'none';
				setselection$(xt, xt.value.length, xt.value.length);

				_autocomplete_zero();
			}
		}, 10);
	})(this);
}
function _xtc_focus() { this._active = true; }
function _xtc_blur() { this._active = false; }
function _xty_update() {
	try {
		if (this._forwardpost) this._forwardpost(this.value);

		var xtc = dom_autocomplete;
		var xt = this;

		if (xtc._boundto && xtc._boundto != this) {
			try {
				xtc._eatme = -1;
				xtc.style.display = 'none';
			} catch(e){};
		}

		xtc._boundto = this;

		_gstr(xt);
		// get last word in xt
		if (xt._selstart && xt._selstart == xt._selend) {
			if (xt._selstart == xt._lastselstart && xt._selend == xt._lastselend
			&& xt.value == xt._lastvalue) {
				// wear goggles
				return true;
			}

			xt._lastselstart = xt._selstart;
			xt._lastselend = xt._selend;
			xt._lastvalue = xt.value;

			var t = xt.value;
			if (!t) t = '';
			var nt = t;
			t = t.substr(0, xt._selstart);
			if (t.match(/,[ ]*$/)) {
				xtc.style.display = 'none';
				xtc._eatme = -1;
				return true;
			}
			var t1, t2;
			var aa = _addrlist(t);
			var head;
			if (aa.length > 0) {
				t = aa[aa.length-1];
				t1 = t[0];
				t2 = t[1];
				head = t[2];
			} else {
				t1 = t;
				t2 = undefined;
				head = 0;
			}

			if (xtc._lt1 == t1 && xtc._lt2 == t2) {
				xtc._eatme = head;
				return true;
			}

			xtc._lt1 = t1; xtc._lt2 = t2;
			_autocomplete_zero();

			var pl = get_auto_contacts();
			var gl = get_contacts();
			if (pl) _autocomplete_add(pl, t1, t2);
			_autocomplete_add(gl, t1, t2);
			if (_autocomp && _autocomp.length > 0) {
				_aot(xt);

				xtc.style.display = '';
				xtc.style.position = 'absolute';
				xtc.style.top = (xt._py+xt.offsetHeight)+'px';
				xtc.style.left = xt._px+'px';
				xtc.style.margin = '0px';
				xtc.style.padding = '0px';
				xtc.style.width = xt.offsetWidth+'px';
				xtc.style.zIndex = '9';
				while (xtc.firstChild) xtc.removeChild(xtc.firstChild);
				var i;
				for (i = 0; i < _autocomp.length; i++) {
					var nj = document.createElement('OPTION');
					nj.value = _autocomp[i];
					nj.appendChild(document.createTextNode(_autocomp[i]));
					xtc.appendChild(nj);
				}
				xtc._eatme = head;
			} else {
				xtc._eatme = -1;
				xtc.style.display = 'none';
			}
		}
	} catch(e) {
		//window.alert("e="+e);
	};

	return true;
}

function addrtextentry$(pv) {
	var xty = textedit$(pv);
	var xtc;
	if (dom_autocomplete && dom_autocomplete.parentNode) {
		xtc = dom_autocomplete;
	} else {
		xtc = document.createElement('SELECT');
		xtc.setAttribute('size', '4');
		xtc.style.zIndex='25';
		xtc.style.position = 'absolute';
		xtc.style.display = 'none';
		inset$(xtc);
		LAYOUT.appendChild(xtc);
		dom_autocomplete = xtc;
	}
	xtc._boundto = xty;
	// xxx circular

	xtc.ondblclick = _xtc_ondblclick;
	xtc.onfocus = _xtc_focus;
	xtc.onblur = _xtc_blur;
	xty.onmouseup = xty.onkeydown = xty.onkeyup = xty.oninput = xty.onchange = _xty_update;
	return xty;
}
function UNSTABLE(z) {
	return (WANT('unstable').toLowerCase().indexOf(z) > -1) ? true : undefined;
}
function WANT(p) {
	if (typeof config == 'undefined' || typeof config.prefs == 'undefined')
		return undefined;
	if (typeof config.prefs[p] == 'undefined') {
		if (typeof default_pref[p] == 'undefined') {
			// this is a bug
			throw "no default pref: "+p;
		}
		if (default_pref[p] && default_pref[p] == false) return undefined;
		return default_pref[p];
	}
	if (config.prefs[p] && config.prefs[p] == false) return undefined;
	return config.prefs[p];
}
function localtime(d) {
	if (WANT('use_gmt')) {
		if (d.toUTCString) return d.toUTCString();
		return d.toGMTString();
	}
	if (d.toLocaleString) return d.toLocaleString();
	return d.toString();
}
function localyearmonth(nd) {
	if (WANT('use_gmt')) {
		return nd.getUTCFullYear() + '-' + (nd.getUTCMonth()+1);
	} else {
		return nd.getFullYear() + '-' + (nd.getMonth()+1);
	}
}
function localtimeonly(nd) {
	var h,m,s,t;
	if (WANT('use_gmt')) {
		h = nd.getUTCHours();
		m = nd.getUTCMinutes();
		s = nd.getUTCSeconds();
		if (h < 10) h = '0' + h + '';
		t='';
	} else {
		h = nd.getHours();
		m = nd.getMinutes();
		s = nd.getSeconds();
		if (h == 0) {
			h = '12';
			t = 'am';
		} else if (h < 12) {
			t = 'am';
		} else {
			if (h > 12) h = h - 12;
			t = 'pm';
		}
	}
	if (m < 10) m = '0' + m + '';
	if (s < 10) s = '0' + s + '';
	return h + ':' + m + ':' + s + '' + t;
}
function localdate(nd) {
	var dow,year,month,date;
	if (WANT('use_gmt')) {
		dow = nd.getUTCDay();
		year = nd.getUTCFullYear();
		month = nd.getUTCMonth();
		date = nd.getUTCDate();
	} else {
		dow = nd.getDay();
		year = nd.getFullYear();
		month = nd.getMonth();
		date = nd.getDate();
	}
	return dowstr[dow] + ", " + monthstr[month] + " " + date + " " + year;
}


function _add_printbutton() {
	toolsep();
	ungrey$(tool(RSRC$('images/tools/stock_print.png'), 'Print', function() {
		window.print();
	}));
	toolsep();
}
function _ungrey_tools() {
	var o;
	for (o = TOOLBAR.firstChild; o; o = o.nextSibling) {
		if (o.tagName && o.tagName.toUpperCase() == 'A') {
			ungrey$(o);
		}
	}
	for (o = EXTOOL.firstChild; o; o = o.nextSibling) {
		if (o.tagName && o.tagName.toUpperCase() == 'A') {
			ungrey$(o);
		}
	}
	_resize_toolbar();
}
function _resize_toolbar() {
	if (!TOOLBAR || !TOOLBAR.firstChild || !TOOLBAR.firstChild.nextSibling) return;

	var pw = pagewidth()-70;
	var o;
	var maybe = true;
	var lp = 0;
	var au;
	if (EXTOOL.firstChild) au = EXTOOL.firstChild;
	for (o = TOOLBAR.firstChild.nextSibling; o; o = o.nextSibling) {
		if (!o.tagName || o.tagName.toUpperCase() != 'A') continue;

		_ao(o);
		var nw = o.offsetWidth;
		if (o._px+nw < pw) {
			lp = o._px+nw+2;
			continue;
		}
		maybe = false; // not a chance

		var g = o;
		o = o.previousSibling;
		g.parentNode.removeChild(g);

		var aa = document.createElement('A');
		aa.tabIndex = -1;
		aa.style.display = 'block';
		aa.style.cursor = 'default';
		FGCOLOR(aa,COLOR.menuText);
		BGCOLOR(aa,COLOR.menu);
		aa._use_width = nw;

		aa.style.paddingLeft = '1px';
		aa.style.paddingRight = '4px';
		aa.style.paddingTop = '2px';
		aa.style.paddingBottom = '2px';
		aa.style.textDecoration = 'none';
		var imgsrc = '';
		if (g.firstChild && g.firstChild.tagName && g.firstChild.src) {
			imgsrc = g.firstChild.src;
		}
		aa._src = imgsrc;
		aa._text = g._text;
		aa.appendChild(imgsrc$(imgtag$(), imgsrc, 16,16));
		var span = document.createElement('SPAN');
		span.style.paddingLeft='2px';
		span.appendChild(document.createTextNode(aa._text));
		aa.appendChild(span);

		aa.href = nullhref();
		aa._fn = g._fn;
		aa.onclick = _dg_fn_click;
		aa._iwidth = g._width;
		aa._iheight = g._height;
		aa.onmouseover = _dg_onmouseover;
		aa.onmousedown = false$;
		aa.onmouseout = _dg_onmouseout;
		if (g._ungrey) {
			aa._ungrey = g._ungrey;
		} else {
			aa._ungrey=true;
			greyout$(aa);
		}
		g._indirect = aa;

		if (au)
			EXTOOL.insertBefore(aa, au);
		else
			EXTOOL.appendChild(aa);
		if (o.data && o.previousSibling) {
			// seperator
			aa._prev_sep = true;
			o = o.previousSibling;
			o.parentNode.removeChild(o.nextSibling);
		}
	}
	if (maybe && maybe == true && EXTOOL.firstChild) {
		var g = EXTOOL.firstChild;
		if (lp + g._use_width < pw) {
			// okay, can extract and reintroduce into toolbar
			EXTOOL.removeChild(g);
			if (g._prev_sep) toolsep();
			var cc = tool(g._src, g._text, g._fn, g._iwidth, g._iheight);
			if (g._ungrey) ungrey$(cc);
			window.setTimeout(_resize_toolbar, 1);
			g._indirect = cc;
		}
	}
	if (EXTOOL.firstChild) {
		// make sure the tool/tag is visible
		EXTOOL_BUTTON.style.display = '';
		if (EXTOOL._active && EXTOOL._active == true) {
			EXTOOL.style.display = 'block';
		} else {
			EXTOOL.style.display = 'none';
		}
	} else {
		// make sure the tool/tag is invisible
		EXTOOL_BUTTON.style.display = 'none';
		EXTOOL.style.display = 'none';
	}
}
function greyout$(dg) {
	while (dg && dg._indirect) dg = dg._indirect;

	if (!dg._ungrey) return;
	dg._ungrey=undefined;
	dg.disabled=true;
	opacity$(dg,0.2); // start out greyed out
	dg.onclick = false$;

	if (dg.tagName && dg.tagName.toUpperCase() == 'A' && !dg._buttonme) {
		dg.onmouseover = true$;
		dg.onmouseout = true$;
	}

	// _fn is still intact...
}
function firstaction$(dg) {
	while (dg && dg._indirect) dg = dg._indirect;
	firstaction$.active = dg;
	return dg;
}
function _dg_fn_click(e) {
	e = E$(e);
	if (e) {
		noticex = e.clientX;
		noticey = e.clientY;
	}
	if (this._fn) this._fn();
	blur$();
	return false;
}
function _dg_onmouseover() {
	_fix_status();
	BGCOLOR(this,COLOR.hilight);
	FGCOLOR(this,COLOR.hilightText);
	return true;
}
function _dg_onmouseout() {
	BGCOLOR(this,COLOR.menu);
	FGCOLOR(this,COLOR.menuText);
	return true;
}
function ungrey$(dg) {
	while (dg && dg._indirect) dg = dg._indirect;
	if (dg._ungrey) return dg;
	dg._ungrey=true;
	dg.disabled=false;
	opacity$(dg,1.0);

	dg.onclick = _dg_fn_click;
	if (dg.tagName && dg.tagName.toUpperCase() == 'A' && !dg._buttonme) {
		dg.onmouseover = _dg_onmouseover;
		dg.onmouseout = _dg_onmouseout;
	} else {
		outset$(dg);
		if (COLOR.button) {
			BGCOLOR(dg,COLOR.button);
			FGCOLOR(dg,COLOR.buttonText);
		} else {
			BGCOLOR(dg,COLOR.window);
			FGCOLOR(dg,COLOR.windowText);
		}
	}

	
	return dg;
}
function new_action(imgsrc,fn) {
	if (!NEWACTOR) return;

	imgsrc$(NEWACTOR.firstChild, imgsrc, 24,24);
	NEWACTOR._fn=fn;

	ungrey$(NEWACTOR);
}
function toolsep() {
	if (TOOLBAR._lastsep) return;
	TOOLBAR.appendChild(document.createTextNode('\xa0\xa0\xa0'));
	TOOLBAR._lastsep=true;
}
function action(op) {
	var o;
	for (o = TOOLBAR.firstChild; o; o = o.nextSibling) {
		if (o.tagName && o.tagName.toUpperCase() == 'A') {
			if (o._text == '') continue;
			if (o._text == op) return o._fn;
		}
	}
	for (o = EXTOOL.firstChild; o; o = o.nextSibling) {
		if (o.tagName && o.tagName.toUpperCase() == 'A') {
			if (o._text == op) return o._fn;
		}
	}
	for (o = NEWLIST.firstChild; o; o = o.nextSibling) {
		if (o.tagName && o.tagName.toUpperCase() == 'A') {
			if (o._text && ('New:'+o._text) == op) return o._fn;
		}
	}
	return function(){};
}

function _dg_disonmousedown() {
	if (this.disabled) return false;
	try { inset$(this, true); } catch(e) {};
	return false;
}
function _dg_disonmouseup() {
	if (this.disabled) return false;
	try { outset$(this); } catch(e) {};
	return false;
}

function tool(imgsrc, text, fn, w, h) {
	if (!w) w = 24;
	if (!h) h = 24;

	if (text != '') {
		text = text + '\xa0';
	}
	var dg = document.createElement('A');
	dg.tabIndex = -1;
	dg.style.display = INLINE_BLOCK;
	dg._fn=fn;

	if (TOOLBAR) TOOLBAR._lastsep=undefined;

	outset$(dg);

	if (COLOR.button) {
		BGCOLOR(dg,COLOR.button);
		FGCOLOR(dg,COLOR.buttonText);
	} else {
		BGCOLOR(dg,COLOR.window);
		FGCOLOR(dg,COLOR.windowText);
	}

	dg.style.borderWidth = '1px';

	dg.style.paddingTop = '1px';
	dg.style.paddingBottom = '1px';
	dg.style.paddingLeft = '2px';
	dg.style.paddingRight = '2px';
	dg.style.cursor = 'default';
	dg.appendChild(document.createTextNode(text));
	if (TOOLBAR) TOOLBAR.appendChild(dg);

	var ag = imgsrc$(imgtag$(),imgsrc,w,h);
	dg._width=w;
	dg._height=h;
	
	ag.style.verticalAlign='middle';
	ag.style.paddingTop='1px';
	ag.style.paddingBottom='1px';
	dg.insertBefore(ag, dg.firstChild);

	dg.onmousedown = _dg_disonmousedown;
	dg._buttonme = true;
	dg.onmouseup = dg.onmouseout = _dg_disonmouseup;

	dg._text = text;
	dg.disabled=true;
	opacity$(dg,0.2); // start out greyed out

	return dg;
}
function QC(s) {
	if (typeof s == 'undefined') s = '';
	var t = s.replace(/[>"\\]/g, function(x) {
			return "\\" + x;
		});
	if (typeof t == 'undefined') t = s;
	return t;
}
function VQ(s) {
	if (typeof s == 'undefined') s = '';
	//xxx
	var t = s.replace(/[^a-zA-Z0-9@,. +-]/g, function(x) {
		var a = x.charCodeAt(0);
		var b = '';
		// convert to octal
		while (a > 8) {
			b = b + '' + (a % 8);
			a = parseInt(a / 8);
		}
		b = '0' + LTRIM$("" + b + '' + (a % 8), "0");
		return sed(b, /^[0]+/, "0");
	});
	if (typeof t == 'undefined') t = s;
	return t;
}
function VC(s) {
	if (typeof s == 'undefined') s = '';
	s = s+'';
	var t = s.replace(/\\([0-7][0-7][0-7]|.)/g, function(x) {
		if (x.length == 2) {
			var d = x.substr(2,1);
			if (d == 'n') return "\n";
			if (d == 'r') return "\r";
			if (d == 't') return "\t";
			return ''+d;
		}
		var a = parseInt(x.substr(1,1));
		var b = parseInt(x.substr(2,1));
		var c = parseInt(x.substr(3,1));
		return '' + String.fromCharCode(c + (b * 8) + (a * 64)) + '';
	});
	if (typeof t == 'undefined') t = s;
	return t;
}
function _array_insert_at(o,idx,x) {
	var i;
	if (o.length > 0) {
		for (i = o.length; i > idx; i--) {
			o[i] = o[i-1];
		}
		o[idx] = x;
	} else {
		o[o.length] = x;
	}
	return o;
}

function _array_insert(o,x) {
	return _array_insert_at(o,0,x);
}
function _mytz_offset() {
	var nd = new Date();
	var aa = nd.toString().match(/\(([^)]*)\)/);
	if (aa) return aa[1];

	// alright, something's wrong... the browser doesn't know
	// what time zone we're in... maybe...
	var tzoff = nd.getTimezoneOffset();

	var neg = false;
	if (tzoff < 0) {
		neg = true;
		tzoff = tzoff * -1;
	}
	var hours = parseInt(tzoff/60);
	var minutes = tzoff % 60;
	if (minutes < 10) minutes = '0' + minutes;
	if (hours < 10) hours = '0' + hours;
	if (neg) {
		return '+' + hours + '' + minutes;
	} else {
		return '-' + hours + '' + minutes;
	}
}
function hideLIST$() {
	if (!VGRAB._saved_position) {
		VGRAB._saved_position = VGRAB._position;
		VGRAB.style.display='none';
		window.setTimeout(_resizehandler,10);
		VGRAB._position=tbsheight()-parseInt(framewidth);
	}
}
function showLIST$() {
	if (VGRAB._saved_position) {
		VGRAB._position=VGRAB._saved_position;
		VGRAB.style.display='';
		VGRAB._saved_position = undefined;
		window.setTimeout(_resizehandler,10);
	}
}

function _dayim(mon,year) {
	if (mon == 0 || mon == 2 || mon == 4
			|| mon == 6 || mon == 7
			|| mon == 9 || mon == 11) return 31;
	if (mon != 1) return 30;
	if ((year % 4) == 0) {
		if ((year % 100) == 0 && (year % 400) != 0) {
			return 28;
		}
		return 29;
	}
	return 28;
}

function _nd_tostring() {
	return this._origme + '(?)';
}
function rfc822date(value) {
	var ov = value;
	// split into tokens
	var tokn = 0;
	var broken = false;
	var dt=1, mon=0, year=1980, hour=0, min=0, sec=0, tz='+0000';
	while (value.length > 0) {
		var aa;

		// strip whitespace
		value=LTRIM$(value);

		// strip comment
		aa=value.match(/^\([^"\\)]*(\\.[^\)\\]*)*\)/);
		if (aa) {
			var lm = aa[0];
			value = value.substr(lm.length, value.length-lm.length);
			continue;
		}

		if (tokn == 0) {
			tokn = 1; // optional
			aa = value.match(/^(Sun|Mon|Tue|Wed|Thu|Fri|Sat),?/i);
			if (aa) {
				// strip, we don't check to see if it's complete
				var lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
				continue;
			}
		}

		if (tokn == 1) {
			aa = value.match(/^[0-9][0-9]?/);
			var lm;
			if (aa) {
				lm = aa[0]+'';
				value = value.substr(lm.length, value.length-lm.length);
			} else {
				lm = '1';
				broken=true;
			}

			tokn = 2;
			if (lm.length > 1 && lm.substr(0,1) == '0')
				lm = lm.substr(1, 1);
			lm = parseInt(lm);
			if (lm < 1 || lm > 31) {
				lm = 1;
				broken = true;
			}
			dt = lm;
			continue;
		}
		if (tokn == 2) {
			aa = value.match(/^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i);
			if (aa) {
				lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
			} else {
				lm = 'Jan';
				broken = true;
			}
			tokn = 3;
			lm = lm.toLowerCase();
			var monl='janfebmaraprmayjunjulaugsepoctnovdec';
			var tm = monl.indexOf(lm);
			if (tm == -1) {
				// should never happen
				tm = 0;
				broken = true;
			}
			tm = parseInt(tm / 3);
			mon = tm;
			continue;
		}
		if (tokn == 3) {
			// y10k compliance :)
			aa = value.match(/^[0-9][0-9]([0-9][0-9][0-9]*)?/);
			var lm;
			if (aa) {
				lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
			} else {
				lm = '1980';
				broken=true;
			}

			tokn = 4;
			if (lm.length < 4) {
				lm = parseInt(lm);
				if (lm < 40) lm = 2000 + lm;
				else lm = 1900 + lm;
				// obsolete client, but not broken
			} else {
				lm = parseInt(lm);
			}

			year = lm;
			continue;
		}
		if (tokn == 4) {
			aa = value.match(/^[0-9][0-9]?:[0-9][0-9]?/);
			var lm;
			if (aa) {
				lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
			} else {
				lm = '00:00';
				broken = true;
			}
			tokn = 5;
			var ba = lm.split(":");
			hour = parseInt(ba[0]);
			min = parseInt(ba[1]);
			// a little counter-rationale; some systems may
			// get confused about leap seconds and give 24:00
			// maybe not _this_ system, but some systems. they
			// aren't (strictly speaking) broken; likewise,
			// others may use 23:60
			if (hour < 0) {
				hour = 0;
				broken = true;
			} else if (hour > 24) {
				hour = 24;
				broken = true;
			}
			if (min < 0) {
				min = 0;
				broken = true;
			} else if (min > 60) {
				min = 60;
				broken = true;
			}
			continue;
		}
		if (tokn == 5) {
			aa = value.match(/^:[0-9][0-9]?/);
			var lm;
			if (aa) {
				lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
			} else {
				lm = ':00';
				// but not broken (rfc822)
			}
			tokn=6;
			lm = parseInt(lm.substr(1, lm.length-1));
			if (lm < 0) {
				sec = 0;
				broken = true;
			} else if (lm > 60) {
				sec = 60;
				broken = true;
			} else {
				sec = lm;
			}
			continue;
		}
		if (tokn == 6) {
			// the time zone
			var lm;
			aa = value.match(/^(GMT)?[+-][0-9][0-9][0-9][0-9]*/);
			if (aa) {
				lm = aa[0];
				value = value.substr(lm.length, value.length-lm.length);
				if (lm.substr(0,3).toUpperCase() == 'GMT') {
					// blah...
					lm = lm.substr(3, lm.length-3);
				}
				tz = lm;
			} else {
				aa = value.match(/^(BST|CDT|CET|CST|EDT|EET|EST|GMT|HKT|IST|JST|LCL|MDT|MET DST|METDST|MET|MST|PDT|PST|UTC|UT)/i);
				if (aa) {
					// holy shit
					lm = aa[0];
					value = value.substr(lm.length, value.length-lm.length);
					lm = lm.toUpperCase();
					var lm1 = lm.substr(0,1);
					var lm2 = lm.substr(1,1);
					if (lm1 == 'B') { // british summer
						tz = '+0100';
					} else if (lm1 == 'C') {
						if (lm2 == 'D') {
							tz = '-0500'; // us central daylight (822)
						} else if (lm2 == 'E') {
							tz = '+0100'; // central european
						} else {
							tz = '-0600'; // us central standard (822)
						}
					} else if (lm1 == 'E') {
						if (lm2 == 'D') {
							tz = '-0400'; // us eastern daylight (822)
						} else if (lm2 == 'E') {
							tz = '+0200'; // eastern european
						} else {
							tz = '-0500'; // us eastern standard (822)
						}
					} else if (lm1 == 'G') {
						tz = '+0000';
					} else if (lm1 == 'H') { // hong kong
						tz = '+0800';
					} else if (lm1 == 'I') { // no idea; either isreal standard or india standard
						// my corpus says isreal is more common
						tz = '+0200';
					} else if (lm1 == 'J') { // japan standard
						tz = '+0900';
					} else if (lm1 == 'L') { // lsmtp is retarded
						tz = '+0000';
					} else if (lm1 == 'M') {
						if (lm.length > 3) {
							tz = '+0200';
						} else if (lm2 == 'E') {
							tz = '+0100'; // middle european
						} else if (lm2 == 'D') {
							tz = '-0600'; // us mountain daylight (822)
						} else {
							tz = '-0700'; // us mountain standard (822)
						}
					} else if (lm1 == 'P') {
						if (lm2 == 'D') {
							tz = '-0700'; // us pacific daylight (822)
						} else {
							tz = '-0800'; // us pacific standard (822)
						}
					} else {
						tz = '+0000'; // UT or UTC (822)
					}
				} else {
					tz = '+0000';
					// probably
					broken=true;
				}
			}
		}
		// no more useful...
		break;
	}
	if (tokn < 5) broken=true; // probably

	// time zone calculation
	var tza = tz.substr(0, 1);
	if (tza == '+' || tza == '-') {
		tz = tz.substr(1, tz.length-1);
	}
	var tzh, tzm;
	if (tz.length > 2) {
		tzm = tz.substr(tz.length-2, 2);
		tzh = tz.substr(0, tz.length-2);
	} else {
		tzh = tz;
		tzm = '0';
	}
	tzh = parseInt(tzh);
	tzm = parseInt(tzm);
	
	// -- means we're _behind_ GMT
	if (tza == '-') {
		hour += tzh;
		min += tzm;
	} else {
		hour -= tzh;
		min -= tzm;
	}
	// correct minutes
	while (min < 0) {
		min += 60;
		hour--;
	}
	while (min > 59) {
		min -= 60;
		hour++;
	}
	// correct hours
	while (hour < 0) {
		hour += 24;
		dt--; // date
	}
	while (hour > 23) {
		hour -= 24;
		dt++;
	}

	// okay, correct date backwards
	while (dt < 1) {
		mon--; if (mon < 0) { mon = 11; year--; }
		dt += _dayim(mon,year);
	}
	// and now forwards
	while (dt >= _dayim(mon,year)) {
		dt -= _dayim(mon,year);
		mon++; if (mon > 11) { mon = 0; year++; }
	}

	// where are my pants?
	var nd = new Date();
	nd.setUTCFullYear(year,mon,dt);
	nd.setUTCHours(hour, min, sec);
	if (broken) {
		nd._isbroken = true;
		nd._origme=ov;
		nd.toString = _nd_tostring;
	}
	return nd;
}
function H$(h) {
	var hex = "0123456789ABCDEF";
	var a1 = hex.substr(h % 16,1);
	h = parseInt(h / 16);
	var a2 = hex.substr(h % 16,1);
	return a2 + '' + a1;
}
function IB$() {
	var b;
	if (INLINE_BLOCK == 'inline-block') {
		b = document.createElement('A');
		b.style.display = INLINE_BLOCK;
		b.style.textDecoration = 'none';
		b.href = nullhref();
	} else {
		b = document.createElement('BUTTON');
		if (b.setAttribute) b.setAttribute('type', 'button');
		b.style.textAlign = 'left';
		b.style.borderTop = 'none';
		b.style.borderLeft = 'none';
		b.style.borderBottom = 'none';
		b.style.borderRight = 'none';
		b._box = document.createElement('DIV');
		b._box.style.textAlign='left';
		b._box.style.display='block';
		b._box.style.border = 'none';
		b._box.style.textDecoration = 'none';
		b._box.style.margin = '0';
		b._box.style.padding = '0';
		b.appendChild(b._box);
	}
	return b;
}
function cescape(s) {
	if (typeof s == 'undefined') s = '';
	var t = s.replace(/[^a-zA-Z0-9]/g, function(x) {
			return '*' + H$(x.charCodeAt(0));
		});
	if (typeof t == 'undefined') t = s;
	return t;
}
function XH() {
	var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function _scrollto_and_update2() {
	_listview_scrollto();
	window.__lv2 = undefined;
	window.__pv2 = undefined;
	update_listview2();
}
function _receive_mailbox_summary(f, viewrel, o, locked) {
	return function(set) {
		var wasu=undefined;
		var isnowu=undefined;

		if (typeof window.folcache[f] == 'undefined') window.folcache[f] = {};
		var fc = window.folcache[f];

		try {
			var q;

			if (window._current_folder && window.__selected_object > -1 && f == window._current_folder) {
				if (typeof fc[viewrel[ window.__selected_object ]] == 'undefined') wasu = true;
			}

			for (q = 0; q < set.length; q++) {
				var no = set[q];
				if (typeof viewrel[o] == 'undefined') continue;

				fc[ viewrel[o] ] = no;
				o++;
			}

			if (window._current_folder && window.__selected_object > -1 && f == window._current_folder) {
				if (typeof fc[viewrel[ window.__selected_object ]] == 'undefined') isnowu = true;
			}

			if (RUNNING) {
				update_listview(true);
				if (wasu && !isnowu) {
					fetchmail.qq.append(_scrollto_and_update2);
				}
				if (window._current_folder && window._current_folder == f) {
					_update_mail_containers();
				}
			}
			status$('');

		} catch(e) {
			//window.alert("f="+f+"e="+e+",o="+o+"\n"+fc);
		};

		if (locked) {
			fetchmail.qq.unlock();
			try {
				unbusy$();
			} catch(e) {};
		}
	};
}
function fetchview(f,oj,fin) {
	if (!fetchmail.qq) fetchmail.qq = new Queue();

	fetchmail.qq.lock();
	if (oj && oj.search) {
		status$('Searching for "' + oj.search + '"');
	} else {
		status$('Fetching headers for ' +f);
	}
	busy$();
	httpmail.mailbox.messages.onerror = function(e) {
		try {
			status$('');
			unbusy$();
		}catch(e) {};
		fetchmail.qq.unlock();
		try {
			if (fin) fin();
		} catch(e) {};
	};
	httpmail.mailbox.messages.onreply = function(set) {
		var fp=undefined;
		if (window._current_folder && f == window._current_folder && window.__selected_object > -1
		&& window.folview && window.folview[f] && window.folview[f][window.__selected_object]) {
			fp = window.folview[f][window.__selected_object];
		}
		try {
			window.folsize[f] = set[0]; // total
			window.folunseen[f] = set[1]; // unseen
			window.folview[f] = set[2]; // relation
			status$('');
			unbusy$();
		} catch(e) {};
		if (fp) {
			try {
				var q;
				var d;
				var vf = window.folview[f];
				for (q = 0; q < vf.length; q++) {
					var no = vf[q];

					if (no != fp)
						continue;
	
					fp = undefined;
					d = q - window.__selected_object;
					window.__selected_object = q;
					if (window._select_group) {
						var j;
						var tg = {};
						var fail=false;
						for (j in window._select_group) {
							if (window._select_group[j]) {
								if (j+d < 0) {
									// wow
									tg = {};
									tg[q]=true;
									fail=true;
									break;
								} else {
									tg[j+d] = true;
								}
							}
						}
						if (fail && fail == true)
							window._first_select += d;
						window._select_group = tg;
					} else {
						window._select_group = {};
						window._select_group[q]=true;
						window._first_select = q;
					}
					break;
				}
			} catch(e) {};
		}
		if (set[3] && set[3].length > 0) {
			var zig = _receive_mailbox_summary(f, set[2], 0);
			zig(set[3]);
		}
		fetchmail.qq.unlock();
		try {
			if (fin) fin();
		} catch(e) {};
	};
	httpmail.mailbox.messages(f, oj, window.LIMIT);
}
function fetchmail(f,o, nl) {
	if (!fetchmail.qq) fetchmail.qq = new Queue();
	if (!fetchmail.calls) fetchmail.calls=0;
	fetchmail.calls++;

	if (!window.folview[f] || (typeof folsize[f] == 'undefined')) {
		// okay ,this is a bit more serious
		var cg = (typeof window._viewoptions == 'undefined') ? {} : window._viewoptions;
		fetchview(f, cg, function() {
			fetchmail(f,o,nl);
		});
		return;
	}

	//xxx ick...
	fetchmail.qq.insert(function() {
		if (o < 0) o = 0;
		if (!nl) nl=LIMIT;

		if (!f)f='INBOX';
		if (!folcache[f]) {
			folcache[f]={};
		}

		var viewrel = window.folview[f];
		if (!viewrel) return;

		var fg=folcache[f];
		var need=false;
		if (folsize[f]) {
			var i;
			for (i = 0; i < nl && o < viewrel.length; i++) {
				if (!fg[viewrel[o]]) {
					need=true;
					break;
				}
				o++;
			}
		}
		if (need==true) {
			var findme = [];
			var seeth = 0;
			for (i = 0; i < nl && (i+o < viewrel.length); i++) {
				if (viewrel[i+o]) seeth++;
				findme[findme.length] = viewrel[i+o] || undefined;
			}
			if (seeth == 0) {
				// nothing todo...
				if (RUNNING) {
					_update_mail_containers();
					update_listview();
				}
				return;
			}

			fetchmail.qq.lock();
			status$('Fetching message summary for ' +f);
			busy$();

			//httpmail.mailbox.summary.onerror //setup during const
			httpmail.mailbox.summary.onreply = _receive_mailbox_summary(f, viewrel, o, true);
			httpmail.mailbox.summary(findme);
		}
	});
}


function _view3_helper(table) {
	var fw = parseInt(framewidth);
	if (table && table.offsetHeight < 2) return;
	var view = window.__current_view_obj;
	view.style.overflow = 'auto';
	resizeHelper(function() {
		var hh = (pageheight() - (VGRAB._position+fw));
		var vv = (pagewidth() - (HGRAB._position+fw));
		if (table) {
			hh -= (table.offsetHeight+(fw-1));
		}
		hh -= 8; vv -= 8; // the 4px
		try { view.style.width = vv + 'px'; } catch(e) {};
		try { view.style.height = hh+'px'; } catch(e) {};
	}, true);
}
function _hide_popups() {
	ATTLIST.style.display = 'none';
	POPLIST.style.display = 'none';
	EXTOOL.style.display = 'none';
	NEWLIST.style.display = 'none';

	ATTLIST._active=false;
	EXTOOL._active=false;
	NEWLIST._active=false;
	document.onclick = true$;

	var xtc = dom_autocomplete;
	if (xtc && xtc._boundto) {
		xtc.style.display='none';
		xtc._eatme=-1;
	}

	blur$();
	return false;
}
function update_view3m(h, ha, htag) {
	ATTLIST.style.display = 'none';
	ATTPICK.style.display = 'none';
	while (ATTPICK.firstChild) ATTPICK.removeChild(ATTPICK.firstChild);

	if (!htag) htag = 'DIV';
	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);

	_hide_popups();
	ATTPICK.style.display = 'none';

	var view = document.createElement(htag);
	var tbody;
	if (ha) {
		var satop = document.createElement('DIV');
		var table = document.createElement('TABLE');
		tbody = document.createElement('TBODY');
		table.appendChild(tbody);
		(function(sax) {
			resizeHelper(function() {
				var vv = (pagewidth() - (HGRAB._position+parseInt(framewidth)));
				if (sax && sax.parentNode) {
					try {sax.style.width = vv + 'px'; }catch(e){};
				}
			}, true);
		})(satop);
		satop.className = 'unbox';
		satop.style.overflow='hidden';
		BGCOLOR(satop,COLOR.window);
		FGCOLOR(satop,COLOR.windowText);
		satop.style.borderBottom='1px outset ' + FIRST$(COLOR.window);
		ha(tbody);
		satop.appendChild(table);
		VIEWLIST.appendChild(satop);
	}

	view.className = 'unbox';
	view.style.padding = '4px';
	view.style.margin = '0';
	view.style.overflow = 'hidden';
	view.position='absolute';
	view.style.top='0px';
	BGCOLOR(view,COLOR.innerWindow);
	FGCOLOR(view,COLOR.innerWindowText);
	view.style.left='0px';
	if (WANT('font_read') != '') {
		view.style.fontFamily = WANT('font_read');
	}
	if (typeof h == 'string') {
		view.innerHTML = h;
	} else {
		while (view.firstChild) view.removeChild(view);
		h(view);
	}
	window.__current_view_obj = view;
	_view3_helper(ha ? tbody : undefined);

	VIEWLIST.appendChild(view);

}
function _head(table, key, value) {
	var tr = document.createElement('TR');
	var tdk = document.createElement('TD');
	var tdv = document.createElement('TD');
	tdk.style.textAlign='right';
	tdk.style.fontWeight='bold';
	tdk.style.whiteSpace='nowrap';
	tdk.style.verticalAlign='top';
	tdk.style.cursor = 'default';
	tdk.style.width = '5em';
	if (key == '') {
		tdk.appendChild(document.createTextNode("\xa0"));
	} else {
		tdk.appendChild(document.createTextNode(key+':\xa0'));
	}
	tdv.style.display = 'block';
	tdv.style.verticalAlign='top';
	tdv.style.whiteSpace='normal';
	tdv.style.paddingRight = '54px';
	tr.appendChild(tdk);
	tr.appendChild(tdv);
	table.appendChild(tr);
	if (value.tagName || value.data) {
		tdv.appendChild(value);
	} else {
		tdv.appendChild(document.createTextNode(value));
	}
	return tr;
}
function notmetoo(s) {
	var ax = _addrlist(TRIM$(s||'', " ,"));
	var outs = '';
	var i;
	for (i = 0; i < ax.length; i++) {
		var ag = ax[i];
		if (ag[0] == WANT('my_email') || ag[1] == WANT('my_name')) continue;
		if (outs != '') outs += ', ';
		outs += '"' + QC(ag[1]) + '" <' + QC(ag[0]) + '>';
	}
	return outs;
}
function _addrjoin(addr, text, head) {
	var ag = [];
	ag[0] = addr;
	ag[1] = text;
	ag[2] = head;
	return ag;
}
function _addrlist(value) {
	var ax = [];
	var aa;
	var text='', addr='';
	var head = 0;
	var pos = 0;
	while (value.length > 0) {
		// left-hand trim
		aa=value.match(/^[\t\r\n ][\t\r\n ]*/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			continue;
		}

		aa=value.match(/^"[^"\\"]*(\\.[^"\\]*)*"/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			text = sed(lm.substr(1,lm.length-2), /\\(.)/, "$1");
			continue;
		}
		aa=value.match(/^\([^"\\)]*(\\.[^\)\\]*)*\)/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			var azt = sed(lm.substr(1,lm.length-2), /\\(.)/, "$1")+'';
			if (azt.toLowerCase() == 'address group') {
				addr = "\"" + QC(text) + "\" (Address Group)";
				text += " (Address Group)";
			} else {
				text = azt;
			}
			continue;
		}
		aa=value.match(/^<[^"\\>]*(\\.[^>\\]*)*>/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			addr = sed(lm.substr(1,lm.length-2), /\\(.)/, "$1");
			continue;
		}
		aa=value.match(/^[^\t\r\n @][^\t\r\n @]*@[a-zA-Z0-9.-]*/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			addr = sed(lm, /\\(.)/, "$1");
			continue;
		}
		aa=value.match(/^[;,][;,]*/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			if (text=='') text = addr;
			if (addr=='') addr = text;
			if (text=='' && addr=='') continue;
			ax[ax.length] = _addrjoin(addr, text,head);
			text='';
			addr='';
			head = pos;
			continue;
		}
		aa=value.match(/^[^\t\r\n ]*/);
		if (aa) {
			var lm = aa[0];
			pos += lm.length;
			value = value.substr(lm.length, value.length-lm.length);
			text = LTRIM$(text + " " + lm);
			continue;
		}
	}
	if (text != '' || addr != '') {
		if (text=='') text = addr;
		if (addr=='') addr = text;
		ax[ax.length] = _addrjoin(addr,text,head);
	}
	return ax;
}

function _a_mailto_click(e) {
	MAILTO(this.title,this);
	blur$();
	return PD$(E$(e));
}
function _urlexpand2help(dx, value) {
	var re = /([a-zA-Z0-9:.+=-]+@[a-zA-Z0-9.-]+)(.*)/;
	for (;;) {
		var aa = re.exec(value);
		if (aa && aa.length > 1) {
			var urlseg = aa[0];
			var right = aa[aa.length-1];
			var left = value.substr(0, value.length - urlseg.length);
			urlseg = urlseg.substr(0, urlseg.length - right.length);
			dx.appendChild(document.createTextNode(left));

			var ah = document.createElement('A');
			ah.href = nullhref();
			ah.onmousedown = false$;
			ah.onclick = _a_mailto_click;
			linkstatus$(ah,'Send a message to ' + urlseg);
			ah.setAttribute('title',urlseg);
			ah.title=urlseg;
			ah.appendChild(document.createTextNode(urlseg));
			dx.appendChild(ah);
			if (urlseg.indexOf('@') == -1 || (config && urlseg.substr(urlseg.indexOf('@')+1) == config['$domain'])) {
				if (isLoggedIn(FIRST$(urlseg,"@"))) {
					var img = imgsrc$(imgtag$(), RSRC$('images/stock_callout.png'), 16,16);
					img.alt='Online';
					img.setAttribute('ALT','Online');
					dx.appendChild(img);
				}
			}

			value = right;
		} else {
			dx.appendChild(document.createTextNode(value));
			break;
		}
	}
}

function _calclickpop(e) {
	apply$(_calfeed_popf, _drop_may_popup, e, this, _attachment_tailf);
	blur$();
}
function _rssclickpop(e) {
	apply$(_rssfeed_popf, _drop_may_popup, e, this, _attachment_tailf);
	blur$();
}
function urlexpand(value) {
	var dx = document.createElement('SPAN');
	var qzre = /^(feed|rss|rdf):/i;
	var re = /((feed|rss|rdf):)?(webcal|https?|ftp):\/\/[^)?# ,"'<>]*(\?[^)"' #<>]*)?(#[^)" '<>]*)?(.*)/;
	for (;;) {
		var aa = re.exec(value);
		if (aa && aa.length > 2) {
			var urlseg = aa[0];
			var right = aa[aa.length-1];
			var left = value.substr(0, value.length - urlseg.length);
			urlseg = urlseg.substr(0, urlseg.length - right.length);
			_urlexpand2help(dx,left);
			var ah = document.createElement('A');
			if (urlseg.substr(0,6).toLowerCase() == 'webcal' && UNSTABLE('planner')) {
				ah.href = nullhref();
				ah._feedurl = urlseg;
				BGCOLOR(ah,COLOR.info);
				FGCOLOR(ah,COLOR.infoText);
				ah.style.textDecoration = 'none';
				ah.style.display = 'block';
				var img = imgsrc$(imgtag$(), RSRC$('images/stock_web-calendar.png'), 16,16);
				img.setAttribute('VALIGN', 'bottom');
				ah.onclick = _calclickpop;
				linkstatus$(ah, urlseg);
				ah.appendChild(img);
				if (_cal_issub(urlseg)) {
					ah.appendChild(document.createTextNode('\xa0This is a calendar that you are already subscribed to'));
				} else {
					ah.appendChild(document.createTextNode('\xa0This is a calendar that you can have netMail subscribe to'));
				}
			} else if (qzre.exec(urlseg)) {
				ah.href = nullhref();
				ah._feedurl = urlseg;
				BGCOLOR(ah,COLOR.info);
				FGCOLOR(ah,COLOR.infoText);
				ah.style.textDecoration = 'none';
				ah.style.display = 'block';
				var img = imgsrc$(imgtag$(), RSRC$('images/stock_news.png'), 16,16);
				img.setAttribute('VALIGN', 'bottom');
				ah.onclick = _rssclickpop;
				linkstatus$(ah, urlseg);
				ah.appendChild(img);
				if (_rss_issub(urlseg)) {
					ah.appendChild(document.createTextNode('\xa0This is a news feed you are already subscribed to'));
				} else {
					ah.appendChild(document.createTextNode('\xa0This is a news feed you can have netMail subscribe to'));
				}
			} else {
				ah.href = urlseg;
				ah.appendChild(document.createTextNode(urlseg));
				ah.target = '_new';
			}
			dx.appendChild(ah);
			value = right;
		} else {
			_urlexpand2help(dx,value);
			break;
		}
	}

	return dx;
}
function addrexpand(value, ok) {
	var ax = _addrlist(value);
	var i;
	var dx = document.createElement('SPAN');
	for (i = 0; i < ax.length; i++) {
		var a1 = ax[i][0];
		var a2 = ax[i][1];

		if (i != 0) {
			dx.appendChild(document.createTextNode(", "));
		}

		if (a1.indexOf('@') == -1 && a1 == a2) {
			dx.appendChild(document.createTextNode(ax[i][1]));
		} else {
			var addr = TRIM$(a1);
			var text = TRIM$(a2);
			var da = document.createElement('A');
			var qa = sed(addr, "'", "\\'");
			da.href=nullhref();
			da.onmousedown = false$;
			da.onclick = _a_mailto_click;
			linkstatus$(da,'Send a message to ' + addr);
			if ((!ok) && COLOR.windowLinks) {
				FGCOLOR(da,COLOR.windowLinks);
			}
			da.setAttribute('title',addr);
			da.title=addr;
			da.appendChild(document.createTextNode(text));
			dx.appendChild(da);
			if (addr.indexOf('@') == -1 || (config && addr.substr(addr.indexOf('@')+1) == config['$domain'])) {
				if (isLoggedIn(FIRST$(addr,"@"))) {
					var img = imgsrc$(imgtag$(), RSRC$('images/stock_callout.png'), 16,16);
					img.alt='Online';
					img.setAttribute('ALT','Online');
					dx.appendChild(img);
				}
			}
		}
	}
	return dx;
}
function _xh_upward_orig() {
	// take us up...
	window._struc_level = undefined;
	window.__lv2 = undefined;
	window.__pv2 = undefined;
	update_listview2();
}
function xh_headers(table, headpart, vieww) {
	var head = headpart.parsedContent;

	var f = window._current_folder;
	var qxre = /^\/*((feed|rss|rdf|atom):)?https?:\/\//i;
	if (f && qxre.exec(f)) {
		// wow...
		_head(table, 'Summary',  head.subject);
		if (head.date) {
			ld = localtime(rfc822date(head.date));
			_head(table, "Published",ld);
		}
		if (window._detached)
			document.title = 'netMail news "' + head.subject + '"';
	} else if (f == 'Notes') {
		if (head.from)
			_head(table, "Author", addrexpand(head.from));
		if (head.date) {
			ld = localtime(rfc822date(head.date));
			_head(table, "Last modified",ld);
		}
		if (head.subject)
			_head(table, "Subject", head.subject);
		else
			_head(table, "Subject", "[No Subject]");
		var s = sed(head.subject||'', /^((Re|Fw)(\[[1-9][0-9]*\])?[: ][ ]*)*/i, "");
		if (!s && head.from) s = 'From: ' + head.from;
		if (!s && head.to) s = 'To: ' + head.to;
		if (!s && head.cc) s = 'CC: ' + head.cc;
		if (!s && ld) s = 'Sent: ' + ld;
		if (!s) s = '[No Subject]';
		if (window._detached)
			document.title = 'netMail note "' + s + '"';
	} else {
		if (head.from)
			_head(table, "From", addrexpand(head.from));
		else
			_head(table, "From", "not listed");
		if (head.to) _head(table, "To", addrexpand(head.to));
		if (head.cc) _head(table, "CC", addrexpand(head.cc));
		if (!head.to && !head.cc)
			_head(table, "CC", "recipients not shown");
		if (head.bcc) _head(table, "BCC", addrexpand(head.bcc));
		var ld;
		if (head.date) {
			ld = localtime(rfc822date(head.date));
			_head(table, "Date",ld);
		}
		if (head.subject)
			_head(table, "Subject", head.subject);
		else
			_head(table, "Subject", "[No Subject]");
		var s = sed(head.subject||'', /^((Re|Fw)(\[[1-9][0-9]*\])?[: ][ ]*)*/i, "");
		if (!s && head.from) s = 'From: ' + head.from;
		if (!s && head.to) s = 'To: ' + head.to;
		if (!s && head.cc) s = 'CC: ' + head.cc;
		if (!s && ld) s = 'Sent: ' + ld;
		if (!s) s = '[No Subject]';
		if (window._detached)
			document.title = 'netMail message "' + s + '"';
	}
	if (window._parentWindow && headpart._realpath != '/h') {
		var span = document.createElement('SPAN');
		var aa = document.createElement('A');
		aa.href = nullhref();
		aa.onclick = _xh_upward_orig;
		if (COLOR.windowLinks) {
			FGCOLOR(aa,COLOR.windowLinks);
		}
		linkstatus$(aa, 'View original message');
		aa.appendChild(document.createTextNode('another message'));
		span.appendChild(document.createTextNode('This message was attached to '));
		span.appendChild(aa);
		_head(table, "", span);
	}

	if (vieww._unblockme) {
		vieww._unblockme(table);
	} else {
		vieww._table = table;
	}

	// resize; (the table changed size)
	window.setTimeout(function() {
		_view3_helper(table);
	},10);
}
function xh_bodypart_raw(div, obj) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var xh = XH();
	try {
		xh.open('GET', BASE_HREF+'chunked/message.fetch/' + cescape(mailbox) + '/' + cescape(message)
				+ '/' + obj.part + '/' + obj.encoding, true);
	} catch(e) { return; };

	xh.onreadystatechange = function() {
		try {
			if (xh.readyState != 4) return;
			var t = xh.responseText;
			if (!t) {
				unbusy$();
				return;
			}
			while (div.firstChild) div.removeChild(div.firstChild);
			var g = STRIP$(t).split("\n");
			var i;
			for (i = 0; i < g.length; i++) {
				div.appendChild(urlexpand(g[i]));
				div.appendChild(document.createElement('BR'));
			}
		} catch(e) {
		};

		unbusy$();
	};
	busy$();
	try {
		xh.send(undefined);
	} catch(e) {
		unbusy$();
	};
}
function xh_bodypart_plain(div, obj) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var xh = XH();
	window.top.CURRENT_OBJECT = obj;
	try {
		xh.open('GET', BASE_HREF+'chunked.text/message.fetch/' + cescape(mailbox) + '/' + cescape(message)
				+ '/' + obj.part + '/' + obj.encoding + '/' + obj.charset, true);
	} catch(e) { return; };

	xh.onreadystatechange = function() {
		try {
			if (xh.readyState != 4) return;
			var g = STRIP$(xh.responseText).split("\n");
			var i;
			var para = '';
			var pala = -1;
			var pgset = document.createElement('DIV');
			for (i = 0; i < g.length; i++) {
				var ts = sed(g[i], /\t/g, "        ");
				var gs = LTRIM$(ts);
				var al = ts.length - gs.length;

				if (typeof ts == 'undefined') ts = '';
				if (al != pala || ts == '' || gs.match(/^[^a-z0-9]/)) {
					if (pala != -1) {
						var pg = document.createElement('DIV');
						pg.style.marginLeft = (pala/2.0) + 'em';
						var aga = SQUEEZE$(para);
						if (!aga.match(/[^ ]/)) aga = '\xa0';
						pg.appendChild(urlexpand(aga));
						pgset.appendChild(pg);
					}
					para = '';
					pala = al;
				}
				if (para != '') para = para + ' ';
				para = para + ts;
			}
			if (para != '') {
				var pg = document.createElement('DIV');
				pg.style.marginLeft = (pala/2.0) + 'em';
				var aga = SQUEEZE$(para);
				if (!aga.match(/[^ ]/)) aga = '\xa0';
				pg.appendChild(urlexpand(aga));
				pgset.appendChild(pg);
			}
			while (div.firstChild)
				div.removeChild(div.firstChild);
			div.appendChild(pgset);
			window.setTimeout(function() {
				div.style.height = pgset.offsetHeight+'px';
			},10);
		} catch(e) {
			//window.alert("exception:"+e);
		};

		unbusy$();
	};
	busy$();
	try {
		xh.send(undefined);
	} catch(e) {
		unbusy$();
	};
}
function _xh_bodypart_chunkhelper(fn) {
	return function(div, title) {
		var obj = this;
		var mailbox = obj._folder;
		var message = MSGPART$(obj._object_base);
		try {
			var xh = XH();
			var uu = BASE_HREF+'chunked/message.fetch/' + cescape(mailbox) + '/' + cescape(message);
			if (obj.part) uu += '/' + obj.part; else uu += '/';
			if (obj.encoding) uu += '/' + obj.encoding; else uu += '/';
			if (obj.charset) uu += '/' + obj.charset; else uu += '/';
			xh.open('GET', uu,true);
	
			xh.onreadystatechange = function() {
				if (xh.readyState != 4) return;
				var t = xh.responseText;
				if (!t) t = '';
				apply$(obj, fn, div, xh.responseText);
				unbusy$();
			};

			busy$();
			try {
				xh.send(undefined);
			} catch(ne) {
				unbusy$();
			};
		} catch(e) {};
	};
}
function apply$() {
	var i;
	if (arguments[1].apply) {
		var j = [];
		for (i = 2; i < arguments.length; i++) {
			j[j.length] = arguments[i];
		}
		return arguments[1].apply(arguments[0], j);
	}

	var s = '';
	var aa = arguments;
	var obj = aa[0];
	var ca = arguments.caller;
	var cn = arguments.callee._callnumber;
	if (!cn) cn=0;
	arguments.callee._callnumber = cn+1;
	var nd = new Date();
	var name = '_apply'+cn+'_'+nd.getMilliseconds()+'$';

	obj[ca + '' + name] = aa[1];
	var s = 'x=obj.'+ca+''+name+'(';
	for (i = 2; i < aa.length; i++) {
		if (i > 2) s = s + ',';
		s = s + 'aa['+i+']';
	}
	s = s + ');';
	var x;
	eval(s);
	obj[ca + '' + name] = undefined;

	return x;
}
function cs(r,tag,f) {
	if (!r) return;
	if (r.tagName && r.tagName.toUpperCase) {
		if (tag == '*' || r.tagName.toUpperCase() == tag) f(r);
	}
	if (r.firstChild) {
		r = r.firstChild;
		for (; r; r = r.nextSibling) cs(r,tag,f);
	}
}
function scripttag(s) {
	var code='';
	cs(s,'SCRIPT',function(y) {
		var q = sed(sed(y.innerHTML,/^[ \t\r\n]*<!--[ \t\r\n]*/, ""), /[ \t\r\n]*-->[ \t\r\n]*$/, "");
		code=code+q+"\n;\n";
		return true;
	});
	if (code != '') {
		apply$(s,function(z) { eval(z); }, code);
	}
}
function xh_bodypart_html_unblocked(div, obj) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var xh = XH();
	xh.open('GET', BASE_HREF+'chunked.html/message.fetchHTML/' + cescape(mailbox) + '/' + cescape(message)
			+ '/' + obj.part + '/' + obj.encoding + '/unblock', true);
	xh.setRequestHeader('Base-HREF', BASE_HREF);
	xh.onreadystatechange = function() {
		if (xh.readyState != 4) return;
		div.innerHTML = xh.responseText;
		scripttag(div);
		unbusy$();
	};
	busy$();
	xh.send(undefined);
}
function xh_bodypart_html(div, obj, vieww) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var xh = XH();
	var ub = '/unblock';
	if (WANT('blockimages')==true) ub = '';
	var qxre = /^\/*((feed|rss|rdf|atom):)?https?:\/\//i;
	if (qxre.exec(obj._folder)) {
		// unblock images...
		ub='/unblock';
	}

	xh.open('GET', BASE_HREF+'chunked.html/message.fetchHTML/' + cescape(mailbox) + '/' + cescape(message)
			+ '/' + obj.part + '/' + obj.encoding + ub, true);
	xh.setRequestHeader('Base-HREF', BASE_HREF);
	xh.onreadystatechange = function() {
		if (xh.readyState != 4) return;
		if (xh.responseText.indexOf('blank.gif') > -1) {
			// we could offer to unblock this image
			var f = function(t) {
				var d = document.createElement('A');
				d.href=nullhref();
				d.appendChild(document.createTextNode('Show images on remote servers'));
				if (COLOR.windowLinks) {
					FGCOLOR(d,COLOR.windowLinks);
				}
				linkstatus$(d, 'Show images on remote servers');
				var tr = _head(vieww._table, "", d);
				d.onclick = function() {
					xh_bodypart_html_unblocked(div,obj);
					tr.parentNode.removeChild(tr);
					_view3_helper(t);
					return false;
				};
			};
			if (vieww._table) {
				f(vieww._table);
			} else {
				vieww._unblockme = f;
			}
		}
		div.style.paddingLeft = '0';
		div.style.paddingRight = '0';
		div.style.marginTop = '0';
		div.style.paddingTop = '0';
		div.innerHTML = xh.responseText;
		scripttag(div);
		unbusy$();
	};
	busy$();
	xh.send(undefined);
}

function _mimeicon(tt) {
	if (!tt) tt='';
	if (tt.match(/^message[=\/]rfc822/)) return RSRC$('images/stock_mail-unread.png');
	if (tt.match(/^text[=\/]html/)) return RSRC$('images/mime/gnome-mime-text-html.png');
	if (tt.match(/[=\/]v-?calendar/)) return RSRC$('images/mime/gnome-mime-text-x-vcalendar.png');
	if (tt.match(/[=\/]x-v-?calendar/)) return RSRC$('images/mime/gnome-mime-text-x-vcalendar.png');
	if (tt.match(/[=\/]v-?card/)) return RSRC$('images/mime/gnome-mime-text-x-vcard.png');
	if (tt.match(/[=\/]x-v-?card/)) return RSRC$('images/mime/gnome-mime-text-x-vcard.png');
	if (tt.match(/^text[=\/]rtf/)) return RSRC$('images/mime/gnome-mime-application-rtf.png');
	if (tt.match(/^text[=\/]richtext/)) return RSRC$('images/mime/gnome-mime-application-rtf.png');
	if (tt.match(/^text[=\/]enriched/)) return RSRC$('images/mime/gnome-mime-application-rtf.png');
	if (tt.match(/^text[=\/]sgml/)) return RSRC$('images/mime/gnome-mime-application-rtf.png');
	if (tt.match(/^text[=\/]/)) return RSRC$('images/mime/gnome-mime-text-x-txt.png');
	if (tt.match(/^audio[=\/]/)) return RSRC$('images/mime/gnome-mime-audio-ac3.png');
	if (tt.match(/^image[=\/]/)) return RSRC$('images/mime/gnome-mime-application-x-sql.png');
	if (tt.match(/[=\/]pdf$/)) return RSRC$('images/mime/gnome-mime-application-pdf.png');
	if (tt.match(/[=\/]x-pdf$/)) return RSRC$('images/mime/gnome-mime-application-pdf.png');
	if (tt.match(/^application[=\/]msword/)) return RSRC$('images/mime/gnome-mime-application-msword.png');
	if (tt.match(/^application[=\/]ms-?excel/)) return RSRC$('images/mime/gnome-mime-application-vnd.ms-excel.png');
	if (tt.match(/^application[=\/]vnd.ms-?excel/)) return RSRC$('images/mime/gnome-mime-application-vnd.ms-excel.png');
	if (tt.match(/^application[=\/]ms-?powerpoint/)) return RSRC$('images/mime/gnome-mime-application-vnd.ms-powerpoint.png');
	if (tt.match(/^application[=\/]vnd.ms-?powerpoint/)) return RSRC$('images/mime/gnome-mime-application-vnd.ms-powerpoint.png');
	if (tt.match(/^application[=\/]x-(us|g?)tar$/)) return RSRC$('images/mime/gnome-mime-application-x-compress.png');
	if (tt.match(/^application[=\/]x-gzip/)) return RSRC$('images/mime/gnome-mime-application-x-compress.png');
	if (tt.match(/^application[=\/]x-bzip2?/)) return RSRC$('images/mime/gnome-mime-application-x-compress.png');
	if (tt.match(/^application[=\/]x-compress/)) return RSRC$('images/mime/gnome-mime-application-x-compress.png');
	if (tt.match(/^application[=\/]zip/)) return RSRC$('images/mime/gnome-mime-application-x-compress.png');
	return RSRC$('images/mime/gnome-mime-application-x-shellscript.png');
}
function xh_bodypart_image(div, obj, title) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var tn = document.createElement('DIV');
	var aa = document.createElement('A');
	var img = document.createElement('IMG');
	var tt = TR$(obj.mimeType, "/", "=");
	var rawurl = BASE_HREF+'chunked.' + tt + '/message.fetch/' + cescape(mailbox) + '/' + cescape(message)
			+ '/' + obj.part + '/' + obj.encoding;
	if (obj.filename) rawurl += '/' + obj.filename;

	var thumburl = BASE_HREF+'chunked.image=jpeg/message.fetchTHUMBNAIL/'
			+ cescape(mailbox) + '/' + cescape(message)
			+ '/' + obj.part + '/' + obj.encoding;
	img.src = thumburl;
	img.border=0;
	aa.href=rawurl;
	aa.title = title;
	aa.target='_new';
	aa.appendChild(img);
	linkstatus$(aa,'Download "'+title+'"');
	aa.appendChild(document.createElement('BR'));
	aa.appendChild(document.createTextNode(title));
	tn.appendChild(aa);
	tn.style.textAlign ='center';
	div.className = 'attached';
	div.appendChild(tn);

	div.href=rawurl;
	div.target='_new';
	div.title = title;
}
function xh_bodypart_other(cm, cn, div, obj, title) {
	if (window.mimeview[cm]) {
		var az = window.mimeview[cm];
		var ag;
		if (az[cn]) {
			ag = az[cn];
		} else if (az['*']) {
			ag = az[cn];
		}
		if (ag) {
			apply$(obj,ag,div,title);
			return;
		}
	}
	// otherwise
	xh_bodypart_attached(div, obj, obj);
}
function xh_bodypart_attached(div, obj, title) {
	var mailbox = obj._folder;
	var message = MSGPART$(obj._object_base);

	var tt = TR$(obj.mimeType, "/", "=");
	var url = BASE_HREF+'chunked.' + tt + '/message.fetch/' + cescape(mailbox) + '/' + cescape(message)
			+ '/' + obj.part + '/' + obj.encoding;
	if (obj.filename) url += '/' + obj.filename;

	var o = document.createElement('A');
	o.title=title;
	o.href=url;
	o.target='_new';
	linkstatus$(o, 'Download "'+title+'"');
	var otitle = title;
	if (title.length > 60) {
		title = title.substr(0, 57) + '...';
	}

	var img = imgsrc$(imgtag$(), _mimeicon(tt), 16,16);
	o.appendChild(img);
	o.appendChild(document.createTextNode(title));

	div.className = 'attached';
	div.appendChild(o);
}
function listview_sortby$(fn) {
	var fol = window._current_folder;
	if ((typeof fn == 'undefined') || fn == '') {
		if (typeof window._viewoptions != 'undefined') {
			window._viewoptions.order = undefined;
			if (typeof window._viewoptions.search == 'undefined') {
				window._viewoptions = undefined;
			}
			fetchview(fol, window._viewoptions, function() { update_listview(); });
		}
	} else {
		if (typeof window._viewoptions == 'undefined') window._viewoptions = {};
		if ((typeof window._viewoptions.order == 'undefined') || window._viewoptions.order != fn) {
			window._viewoptions.order = fn;
			fetchview(fol, window._viewoptions, function() { update_listview(); });
		}
	}
}
function _cg_onmouseover() {
	if (this._statustext) {
		var s = this._statustext;
		window.status = s;
	}
	BGCOLOR(this,COLOR.hilight);
	FGCOLOR(this,COLOR.hilightText);
	return true;
}
function _cg_onmouseout() {
	_fix_status();
	BGCOLOR(this,COLOR.menu);
	FGCOLOR(this,COLOR.menuText);
	return true;
}
function _attpick_press() {
	inset$(ATTPICK);
	return true;
}
function _attpick_release() {
	outset$(ATTPICK);
	return true;
}
function _attpick_timeoutclick() {
	ATTLIST._active=false;
	document.onclick = true$;
	ATTLIST.style.display = 'none';
}
function _attpick_doconclick(e) {
	e = E$(e);
	if (e.which > 1) return true;
	window.setTimeout(_attpick_timeoutclick,13);
	return false;
}
function _attpick_deferred() {
	_hide_popups();
	ATTLIST.style.display = 'block';
	ATTLIST._active=true;
	document.onclick = _attpick_doconclick;
}
function _attpick_clicker() {
	_ao(this);
	ATTLIST.style.top = (1+this._py + this.offsetHeight) + 'px';
	ATTLIST.style.right = '0px';
	if (ATTLIST._active && ATTLIST._active==true) return _hide_popups();
	window.setTimeout(_attpick_deferred, 10);
	blur$();
	return false;
}
function update_listview2() {
	if (!window._current_view) return;
	if (window._current_view != 'list') return;
	if (window.__selected_object == -1) {
		// okay, zap window below
		if (window._current_folder && window._current_folder != '') {
			document.title = 'netMail '+window._current_folder;
		} else {
			document.title = 'netMail';
		}
		update_view3m('');
		return;
	}
	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);
	ATTPICK.style.display = 'none';

	var f = window._current_folder;
	var mdata = folcache[f];
	var vr = window.folview[f];
	if (!vr || !mdata) return;

	var nh = window.__selected_object;

	var msg = mdata[ vr[nh] ];
	if (!msg) {
		// err...
		window.__lv2 = undefined;
		fetchmail(f, nh, 1);
		return;
	}

	if (window.__lv2 && window.__lv2 == msg) return;
	window.__lv2 = msg;

	document.title = 'netMail reading "' + msg.subject + '"';

	if (msg.className != 'message/rfc822') {
		if (window._raw_view) {
			// okay
			document.title = 'netMail raw view "' + msg.subject + '"';
			update_view3m(function(body) {
				var fao = {};
				fao._folder = f;
				fao._object_base = msg.id;
				fao.encoding = '8';
				fao.part = '1:';
				body.style.fontFamily = 'monospace';
				body.style.whiteSpace = 'pre';
				xh_bodypart_raw(body, fao);
			});
			return;
		}

		// hrm... let's look up the mimeview
		var ka = (msg.className+'').split('/');
		if (ka.length == 2) {
			var cm = ka[0].toLowerCase();
			if (window.mimeview[cm]) {
				var cn = ka[1].toLowerCase();

				var az = window.mimeview[cm];
				var ag;
				if (az[cn]) {
					ag = az[cn];
				} else if (az['*']) {
					ag = az[cn];
				}
				if (ag) {
					var pr = {};
					pr._folder = f;
					pr._object_base = msg.id;
					pr._message = msg;
					var title = msg.summary;
					if (!title) title = msg.subject;
					if (!title) title = 'Untitled';

					var f1 = function(co) {
						apply$(pr,ag,co,title);
					};
					if (ag._heading) {
						update_view3m(f1, function(l) {
							apply$(pr, ag._heading, l, msg);
						});
					} else {
						update_view3m(f1);
					}
				}
			}
		}
		return;
	}

	var level;
	if (!window._struc_level) {
		level = '/';
	} else {
		level = window._struc_level;
	}

	//httpmail.message.structure.onerror = // in const section
	httpmail.message.structure.onreply = function(str) {
		var parts = [];
		var zeros = {};
		var nzeros = [];

		var headers = str[0];
		var nonmime = str[1];
		var i;
		var raw1,raw2;
		for (i = 2; i < str.length; i++) {
			var dg = str[i].path+'';
			if (dg == level+'h') {
				raw1 = str[i];
			} else if (dg == level+'b') {
				raw2 = str[i];
			}
			var aa = dg.match(/(.*)\/\/*0$/);
			if (aa) {
				var ag = [];
				ag[0] = str[i].mimeType+'text/plain';
				ag[1] = {};
				ag[2] = [];
				zeros[ aa[1] ] = ag;
				nzeros[ nzeros.length ] = aa[1];
				continue;
			}
			parts[parts.length] = str[i];
		}
		if (!headers) {
			update_view3m('<I>INTERNAL ERROR</I>');
			return;
		}
		if (!raw1) raw1 = str[0];
		if (!raw2) raw2 = str[1];
		headers._realpath = headers.path;

		if (window._raw_view) {
			document.title = 'netMail raw view "' + msg.subject + '"';
			var ab1 = raw1.part.split(/:/);
			var ab2 = raw2.part.split(/:/);
			var ab = ab1[0] + ':' + ab2[1];
			update_view3m(function(body) {
				var fao = {};
				fao._folder = f;
				fao._object_base = msg.id;
				fao._message = msg;
				fao.encoding = '8';
				fao.part = ab;
				body.style.fontFamily = 'monospace';
				body.style.whiteSpace = 'pre';
				xh_bodypart_raw(body, fao);
			});
			unbusy$();
			return;
		}

		if (parts.length == 0) {
			parts[0] = nonmime;
		}
		while (ATTLIST.firstChild)
			ATTLIST.removeChild(ATTLIST.firstChild);

		function _attachment(imgsrc,text, href,jsclick) {
			var cg = document.createElement('A');
			cg.tabIndex = -1;
			cg.style.display = 'block';
			cg.style.cursor = 'default';
			FGCOLOR(cg,COLOR.menuText);
			BGCOLOR(cg,COLOR.menu);
			cg.style.paddingLeft = '1px';
			cg.style.paddingRight = '4px';
			cg.style.paddingTop = '2px';
			cg.style.paddingBottom = '2px';
			cg.style.textDecoration = 'none';

			var vaim = imgsrc$(imgtag$(), imgsrc, 16,16);
			vaim.style.verticalAlign = 'middle';
			cg.appendChild(vaim);

			var span = document.createElement('SPAN');
			span.style.paddingLeft='2px';
			span.appendChild(document.createTextNode(text));
			cg.appendChild(span);

			if (jsclick) {
				cg.onclick = function(e) {
					window.setTimeout(_hide_popups, 15);
					jsclick();
					return PD$(E$(e));
				};
				cg.href = nullhref();
				cg._statustext = 'Download "' + text + '"';
			} else {
				cg.onclick = function(e) {
					window.setTimeout(_hide_popups, 15);
					PP$(E$(e));
					return true;
				};
				if (href.indexOf('/chunked-download') > -1) {
					(function(xx) {
				 	// msie download function simply must work...
/*@cc_on @*/
/*@if (@_jscript_version < 5.7) {
  						xx.target = '_blank';
  						return;
}
@end @*/
						xx.target = 'INVISIBLE';
					})(cg);
				} else {
					cg.target = '_blank';
				}
				cg.href=href;
				cg._statustext = href;
			}
			cg.onmousedown = false$;
			cg.onmouseover = _cg_onmouseover;
			cg.onmouseout = _cg_onmouseout;
			ATTLIST.appendChild(cg);
		};

		var attachcount = 0;
		for (;;) {
			var _didalt = undefined;
			for (i = 0; i < parts.length; i++) {
				var pr = parts[i];
				var path = (pr.path||'/');
				pr._realpath = path;
	
				if (path.substr(0,level.length) == level) {
					path = path.substr(level.length, path.length-level.length);
					if (path.indexOf('/') > -1) {
						// deeper leaf
						continue
					}
				} else {
					continue;
				}
	
				// headers for the current level (i think)
				if (path.substr(path.length-2, 2) == '/h' || path == 'h') {
					headers = pr;
					continue;
				}
	
				if (!pr.isAttached && pr.mimeType.match(/^(text|image)\//i)) {
					if (pr.multipart) {
						if (pr.multipart == 'alternative') {
							if (_didalt && !pr.mimeType.match(/\/html/i)) continue;
							_didalt=true;
							pr._isalt=true;
						} else if (pr.multipart == 'related' && pr.mimeType.match(/^image\//i)) {
							continue;
						} else if (pr.multipart == 'related') {
							pr._isalt=true;
						}
					}
					if (pr._isalt && pr.mimeType.match(/\/html/i)) {
						var nj;
						for (nj = 0; nj < i; nj++)
							if (parts[nj]._isalt) parts[nj]._todo = undefined;
					}
					pr._todo = true;
				} else if (pr.mimeType == 'message/external-body') {
					if (!pr.cidpart) pr._todo = true;
					
				} else if (pr.mimeType == 'message/delivery-status') {
					pr._todo = true;

				} else if (pr.multipart && pr.multipart == 'report' && pr.mimeType == 'message/feedback-report') {
					// shitpuppies...
					pr.mimeType = 'text/plain';
					pr._todo = true;

				} else if ((pr.isAttached || pr.mimeType == 'message/rfc822') && !pr.cidpart) {
					var xn = pr.size;
					if (!pr.filename) {
						pr.filename = 'ATT' + TR$(pr._realpath||'', "/", "-") + '.DAT';
					}
					var xcg = pr.filename;
					if (xn) {
						if (xn > 1048576) {
							xn = parseInt(xn / 1048576);
							xcg = xcg + ' (' + xn + ' Mbytes)';
						} else if (xn > 1024) {
							xn = parseInt(xn / 1024);
							xcg = xcg + ' (' + xn + ' Kbytes)';
						} else {
							xcg = xcg + ' (' + xn + ' bytes)';
						}
					}

					var tt = TR$(pr.mimeType, "/", "=");
					var url;
					if (tt == 'message=rfc822') {
						(function(zpath) {
							_attachment(_mimeicon(tt), xcg, '', function() {
								RUNNING=true;
								viewwindow$('mailview', function(g) {
									g._struc_level = zpath + '/';
								});
							});
						})(pr.path);
					} else {
						url = BASE_HREF+'chunked-download.' + tt + '/message.fetch/'
						+ cescape(f) + '/' + cescape(MSGPART$(msg.id))
						+ '/' + pr.part + '/' + pr.encoding + '/' + pr.filename;
						_attachment(_mimeicon(pr.mimeType), pr.filename, url);
					}
					attachcount++;
	
				}
			}
			break;
		}

		// here we go...
		var vieww = function(o) {
			var i;
			var didc=0;
			for (i = 0; i < parts.length; i++) {
				var pr = parts[i];
				if (!pr._todo) continue;
				if (didc > 0) {
					var hr = document.createElement('HR');
					o.appendChild(hr);
				}

				didc++;

				var co = document.createElement('DIV');
				co.className = 'bodypart';

				var xcg = (pr.path||'/');
				if (pr.filename) {
					xcg = pr.filename;
				}
				var xn = pr.size;
				if (xn) {
					if (xn > 1048576) {
						xn = parseInt(xn / 1048576);
						xcg = xcg + ' (' + xn + ' Mbytes)';
					} else if (xn > 1024) {
						xn = parseInt(xn / 1024);
						xcg = xcg + ' (' + xn + ' Kbytes)';
					} else {
						xcg = xcg + ' (' + xn + ' bytes)';
					}
				}
				var natype = pr.mimeType||'application/octet-stream';
				var na = natype.split("/",2);
	
				var cm = na[0].toLowerCase();
				var cn = na[1].toLowerCase();
	
				pr._folder = f;
				pr._object_base = msg.id;
				pr._message = msg;
				if (cm == 'text') {
					co.innerHTML = '<CENTER><I>Loading message body</I></CENTER>';
					if (cn == 'html') {
						xh_bodypart_html(co, pr, arguments.callee);
					} else {
						xh_bodypart_plain(co, pr);
					}
				} else if (cm == 'image') {
					xh_bodypart_image(co, pr, xcg);
				} else {
					xh_bodypart_other(cm, cn, co, pr, xcg);
				}

				o.appendChild(co);
			}
		};
		update_view3m(vieww, function(l) {
			xh_headers(l, headers, vieww);

			if (attachcount) {
				ATTPICK.appendChild(imgsrc$(imgtag$(),RSRC$('images/gnome-fs-directory.png'),48,48));
				if (COLOR.button) {
					BGCOLOR(ATTPICK,COLOR.button);
					FGCOLOR(ATTPICK,COLOR.buttonText);
					outset$(ATTPICK,true);
				} else {
					FGCOLOR(ATTPICK,COLOR.windowText);
					BGCOLOR(ATTPICK,COLOR.window);
					ATTPICK.style.border = 'none';
				}
				ATTPICK.onmousedown = _attpick_press;
				ATTPICK.onmouseup = _attpick_release;
				ATTPICK.onclick = _attpick_clicker;
				window.setTimeout(function() {
					resizeHelper(function() {
						ATTPICK.style.display = '';
						ATTPICK.style.position = 'absolute';
						ATTPICK.style.top = (((VGRAB._position+parseInt(framewidth))) + (l.offsetHeight-54))+'px';
						ATTPICK.style.left = (pagewidth()-54)+'px';
						ATTPICK.style.height = '50px';
						ATTPICK.style.width = '50px';
					}, true);
				},10);
			} else {
				ATTPICK.style.display = 'none';
				while (ATTPICK.firstChild) ATTPICK.removeChild(ATTPICK.firstChild);
			}
		});
		status$('');
		unbusy$();
	};
	status$('Fetching message body');
	busy$();
	httpmail.message.structure(f, MSGPART$(msg.id));
}
function COL() {
	var col = [];
	if (!window._current_folder) return col;
	var mailbox = window._current_folder;
	var viewrel = folview[mailbox];
	var so = window.__selected_object;
	if (window._select_group) {
		for (i in window._select_group) {
			if (window._select_group[i] && viewrel[i]) {
				// get listview collection
				col[col.length] = viewrel[i];
			}
		}
		if (col.length == 0 && so > -1 && viewrel[so]) {
			col[0] = viewrel[so];
		}
	} else if (so > -1 && viewrel[so]) {
		col[0] = viewrel[so];
	}
	return col;
}
function update_listview_cols() {
	if (!window._current_view) return;
	if (window._current_view != 'list') return;
	var i, j;
	var list = window.__list_view_list;
	var cols = window.__list_view_cols;
	var pos = window.__list_view_table;
	if (!list._grow) return;
	for (j = 0; j < list._grow.length; j++) {
		var row = list._grow[j];
		if (row._hidden) continue;

		var td = row.firstChild;
		for (i = 0; td; i++) {
			td.style.width = pos[i]+'px';
			td = td.nextSibling;
		}
	}
}
function msg_flag_toggle(msg, flag, neu) {
	var fl = msg.flags||'';
	if (fl.indexOf(flag) > -1)
		msg_flag_disable(msg,flag, neu);
	else
		msg_flag_enable(msg,flag, neu);
}
function msg_flag_setto(msg, fl, neu) {
	var co = function(mailbox, id) {
		//httpmail.message.setFlags.onerror = function(e) { // const
		httpmail.message.setFlags.onreply = function(z) {
			msg_flag_setto._busy--;
			if (msg_flag_setto._busy<0)msg_flag_setto._busy=0;

			var viewrel = folview[mailbox];
			var fc = folcache[mailbox];
			var nid = mailbox + '/:' + z;
			var oid = mailbox + '/:' + id;
			if (fc && fc[oid]) {
				fc[nid] = fc[oid];
				fc[nid].id = nid;
				fc[nid]._folder = mailbox;
				fc[nid]._object_base = nid;
				fc[nid].flags = fl;
			}
			var i, j;
			if (viewrel) {
				for (i = 0; i < viewrel.length; i++) {
					if (viewrel[i] == id) {
						viewrel[i] = nid;
						break;
					}
				}
			}

			if (ping_monitor$ && ping_monitor$._ov) ping_monitor$._ov[mailbox]=0;
			if (neu) neu();
			status$('');
		};
		msg_flag_setto._busy++; 
		try {
			status$('Updating message flags...');
			httpmail.message.setFlags(mailbox, id, fl);
		} catch(e) {
			status$('');
		};
		var viewrel = folview[mailbox];
		var fc = folcache[mailbox];
		var oid = mailbox + '/:' + id;
		if (fc && fc[oid]) fc[oid].flags = fl;
	};

	if (typeof msg == 'string') {
		var mgx = MSGPART$(msg);
		var mgb = FOLPART$(msg);
		co(mgb, mgx);
	} else if (msg._folder && msg._object_base) {
		co(msg._folder, MSGPART$(msg._object_base));
	} else {
		co(msg.mailbox, MSGPART$(msg.id));
	}
}
function msg_flag_disable(msg, flag, neu) {
	var fl = STRIP$(msg.flags||'', flag);
	msg_flag_setto(msg, fl, neu);
}
function msg_flag_enable(msg, flag, neu) {
	var fl = STRIP$(msg.flags||'', flag) + flag;
	msg_flag_setto(msg, fl, neu);
}

function _listview_markread() {
	if (window.__selected_object < 0) return;

	// mark the message as seen immediately
	var mailbox = window._current_folder;
	var viewrel = folview[mailbox];
	if (window.__selected_object >= viewrel.length) return;

	var msgid = viewrel[window.__selected_object];
	var mgx = mailbox + '/:' + MSGPART$(msgid);
	if (!mgx.match(/:2,[A-R]*S/)) {
		folunseen[window._current_folder]--;
		if (folcache[mailbox]) {
			msg_flag_enable(mgx, 'S');

			var mdata = folcache[mailbox];
			if (mdata[msgid]) {
				var msg = mdata[msgid];
				msg.flags = STRIP$(msg.flags||'', 'S')+'S';
				update_listview();
			}
		} else {
			msg_flag_enable(mgx, 'S', function() {
				update_listview();
			});

		}
		_update_mail_containers();
	}
}
function _listview_dblclick(e) {
	window.__selected_object=this._row;
	window._first_select = this._row;
	_listview_markread();
	viewwindow$();
	blur$();
	return false;
}
function _listview_start_timeoutread(o) {
	if (_listview_start_timeoutread._timeout) {
		window.clearTimeout(_listview_start_timeoutread._timeout);
		_listview_start_timeoutread._timeout = undefined;
	}

	if (window._current_provider == 'contactsview'
		|| window._current_provider == 'notesview') return;

	var cur_mailbox = window._current_folder;

	if (!folview[cur_mailbox] || !o) return;

	(function(mailbox, msgid, thisrow) {
		_listview_start_timeoutread._timeout = window.setTimeout(function() {
			_listview_start_timeoutread._timeout = undefined;
			if (mailbox != window._current_folder) return;
			if (!folview[mailbox]) return;
			var fv = folview[mailbox];

			if (window.__selected_object < 0 || window.__selected_object >= fv.length)
				return;

			if (fv[ window.__selected_object ] != msgid) return;

			var mgx = mailbox + '/:' + MSGPART$(msgid);
			if (mgx.match(/:2,[A-R]*S/)) return;

			folunseen[mailbox]--;

			if (folcache[mailbox] && folcache[mailbox][msgid]) {
				msg_flag_enable(mgx, 'S');

				var msgobj = folcache[mailbox][msgid];
				msgobj.flags = STRIP$(msgobj.flags||'', 'S')+'S';

				update_listview();
				_update_mail_containers();
			} else {
				msg_flag_enable(mgx, 'S', function() {
					update_listview();
					_update_mail_containers();
				});
			}
		}, 2000);
	})(cur_mailbox, folview[cur_mailbox][o._row], o._row);
}
function _listview_click(e) {
	e = E$(e);
	if (e.clientX || e.clientY) {
		noticex = e.clientX;
		noticey = e.clientY;
	}

	if (window.__selected_object == this._row) {
		blur$();
		return PD$(e);
	}
	var mod;
	if (e.modifiers)mod=e.modifiers; else mod=0;

	var isset;
	if (e.shiftKey || (mod & 4)) {
		_listview_motion(true, this._row);
		blur$();
		return PD$(e);

	} else if (e.ctrlKey || (mod & 2)) {
		if (window._select_group[ this._row ]) {
			window._select_group[ this._row ] = undefined;
		} else {
			window._select_group[ this._row ] = true;
		}
		isset = window._select_group;
		window._first_select = this._row;
	} else {
		isset = {};
		isset[ this._row ] = true;

		window._first_select = this._row;
		window._select_group = isset;

		// mark the message as seen in 5 seconds
		_listview_start_timeoutread(this);
	}

	window.__selected_object=this._row;
	_ungrey_tools();
	icon_alert_cancel$();
	update_listview2();

	var aa;
	var nlist = this.parentNode.parentNode;
	if (!nlist._grow) return PD$(e);

	var x;
	for (x = 0; x < nlist._grow.length; x++) {
		var nr = nlist._grow[x];
		for (aa = nr.firstChild; aa; aa = aa.nextSibling) {
			if (aa.tagName && (aa.tagName.toUpperCase() == 'BUTTON' || aa.tagName.toUpperCase() == 'A')) {
				if (isset[ aa._row ]) {
					BGCOLOR(aa,COLOR.hilight);
					FGCOLOR(aa,COLOR.hilightText);
				} else {
					FGCOLOR(aa,COLOR.innerWindowText);
					BGCOLOR(aa,COLOR.innerWindow);
				}
			}
		}
	}
	blur$();
	// update view
	return PD$(e);
}
function _listview_scrollto() {
	if (!window._current_view) return;
	if (window._current_view != 'list') return;

	var list = window.__list_view_list;
	if (!list._grow) return;
	var so = window.__selected_object;
	if (so < 0) so = 0;

	var h = window.__list_view_line_size;
	var hso = h*so;
	if (hso < list.scrollTop) {
		list.scrollTop = hso;
		update_listview();
		return;
	}
	hso = (h+1)*so;
	var hh = ((VGRAB._position-(h+tbsheight()))-2)-h;
	if (hso > list.scrollTop+hh) {
		list.scrollTop = hso-hh;
		update_listview();
		return;
	}
}
function _listview_updsel() {
	var dp;
	if (window._select_group) {
		dp = window._select_group;
	} else {
		dp = {};
		if (window.__selected_object) dp[window.__selected_object] = true;
	}

	var list = window.__list_view_list;
	if (!list._grow) return;

	var x, ok, aa;
	for (x = 0; x < list._grow.length; x++) {
		var nr = list._grow[x];
		if (!nr.firstChild) continue;
		for (aa = nr.firstChild; aa; aa = aa.nextSibling) {
			if (aa.tagName && (aa.tagName.toUpperCase() == 'BUTTON' || aa.tagName.toUpperCase() == 'A')) {
				if (dp[aa._row] && dp[aa._row] == true) {
					BGCOLOR(aa,COLOR.hilight);
					FGCOLOR(aa,COLOR.hilightText);
				} else {
					FGCOLOR(aa,COLOR.innerWindowText);
					BGCOLOR(aa,COLOR.innerWindow);
				}
			}
		}
	}
}
function _listview_motion(shift, newpos) {
	var cg = _listview_motion;
	if (cg && cg._ti)
		window.clearTimeout(cg._ti);

	var curpos = window.__selected_object;
	var md = folsize[window._current_folder];
	if (newpos >= md) newpos = md-1;
	if (curpos >= md) curpos = md-1;
	if (curpos < 0) curpos = 0;
	if (newpos < 0) newpos = 0;

	if (typeof window._select_group == 'undefined') window._select_group = {};

	var i, a, b, v;
	if (shift) {
		var third;
		if (typeof window._first_select == 'undefined') {
			window._first_select = window.__selected_object;
			third = curpos;
		} else {
			third = window._first_select;
		}

		if (third < curpos && curpos < newpos) {
			a = curpos+1; b = newpos; v = true; // moving down
		} else if (third > curpos && curpos > newpos) {
			a = newpos; b = curpos-1; v = true; // moving up

		} else if (third < curpos && curpos > newpos) {
			// moving up from down
			a = newpos+1; b = curpos; v = false;
		} else if (third > curpos && curpos < newpos) {
			// moving down from up
			a = curpos; b = newpos-1; v = false;

		} else if (curpos < newpos) {
			// otherwise wear goggles
			a = curpos; b = newpos; v = true;
		} else {
			a = newpos; b = curpos; v = true;
		}
	} else {
		// alternate;
		window._select_group = {};
		a = newpos; b = newpos; v = true;
		window._first_select = undefined;
	}

	if (v && v == true) {
		for (i = a; i <= b; i++) {
			window._select_group[i] = true;
		}
	} else {
		for (i = a; i <= b; i++) {
			window._select_group[i] = undefined;
		}
	}
	window._select_group[newpos]=true;
	if (window.__selected_object == -1) _ungrey_tools();

	window.__selected_object = newpos;

	var ag = {};ag._row = newpos;
	_listview_updsel();
	_listview_scrollto();

	cg._ti = window.setTimeout(function() {
		icon_alert_cancel$();
		update_listview2();
		_listview_scrollto();

		_listview_start_timeoutread(ag);
	}, (shift ? 500 : 50));
}

function _zapcache(f, nz) {
	var p = window;
	while (p._parentWindow && p._parentWindow != p)
		p = p._parentWindow;
	if (p != window) {
		var m = {
			'\b': '\\b',
			'\t': '\\t',
			'\n': '\\n',
			'\f': '\\f',
			'\r': '\\r',
			'"' : '\\"',
			'\\': '\\\\'
		};
		if (/["\\\x00-\x1f]/.test(f)) {
			f = f.replace(/([\x00-\x1f\\"])/g, function(a, b) {
				var c = m[b];
				if (c) {
					return c;
				}
				c = b.charCodeAt();
				return '\\u00' +
					Math.floor(c / 16).toString(16) + (c % 16).toString(16);
					
			});
		}
		// send _zapcache upward...
		p.setTimeout('_zapcache("' + f + '",true);',1);
		return;
	}

	var vo = (typeof window._viewoptions == 'undefined') ? {} : window._viewoptions;
	if (f == window._current_folder) {
		fetchview(f, vo, function() {
			fetchmail.qq.append(function() {
				window.__lv2 = undefined;
				window.__pv2 = undefined;
				update_listview();
				_listview_scrollto();
			});
		});
	} else {
		fetchview(f, {}, true$);
	}

	if (ping_monitor$ && ping_monitor$._ov)
		ping_monitor$._ov[f] = 0;
}
function _listview_dragop(starget, popup) {
	// check starget, if it's a new message, we might have to do something else...
	if (!starget.suppress_move) {
		popup.append(RSRC$("images/stock_move.png"), "Move", function(target, set) {
			if (window._current_folder && ping_monitor$ && ping_monitor$._ov)
				ping_monitor$._ov[window._current_folder]=0;
			httpmail.mailbox.moveto.onreply = function(count) {
				try {
					if (count != 1) {
						notice$(count+" messages moved");
					} else {
						notice$(count+" message moved");
					}
					_zapcache(target,true);
					_removaccel(set,count);
				} catch(e) {
				};
				unbusy$();
			};
			busy$();
			try {
				httpmail.mailbox.moveto(target,set);
			} catch(e) {
				unbusy$();
			};
		});
	}
	popup.append(RSRC$("images/stock_copy.png"), "Copy", function(target, set) {
		httpmail.mailbox.copyto.onreply = function(count) {
			try {
				if (count != 1) {
					notice$(count+" messages copied");
				} else {
					notice$(count+" message copied");
				}
				_zapcache(target);
				update_listview();
			} catch(e) {
			};
			unbusy$();
		};
		busy$();
		try {
			httpmail.mailbox.copyto(target,set);
		} catch(e) {
			unbusy$();
		};
	});
	popup.append(RSRC$("images/stock_undo.png"), "Cancel");
};

function update_listview(nof) {
	if (!window._current_view) return;
	if (window._current_view != 'list') return;

	var i, j;

	var list = window.__list_view_list;
	var cols = window.__list_view_cols;
	var pos = window.__list_view_table;
	var h = window.__list_view_line_size;
	if (!window._select_group) window._select_group = {};

	var f = window._current_folder;
	var fs = folsize[f] || 0;
	var mdata = folcache[f] || {};
	var viewrel = folview[f] || {};

	var stop = list.scrollTop;
	var top = parseInt(stop / h);
	var htop = top*h;

	if ((typeof window.folsize[f] == 'undefined')
	||(typeof window.folview[f] == 'undefined')
	||(typeof window.folcache[f] == 'undefined')) {
		fetchmail(f, 0, LIMIT);
		return;
	}
	if (fs == 0) {
		// okay, remove selection
		window._select_group = {};
		window._first_select = undefined;
		window.__selected_object = -1;
		window.setTimeout(function() {
			update_listview2();
		},10);
	} else if (window.__selected_object >= fs) {
		window._first_select = undefined;
		window.__selected_object = fs-1;
	}

	var ps = (fs * h);

	// meat padding
	var y=htop;
	if (top > 0) {
		top--;
		y -= h;
	}

	if (top > 0) {
		var gtop;
		if (list._gtop) {
			gtop = list._gtop;
		} else {
			gtop = document.createElement('DIV');
			gtop.appendChild(document.createTextNode('\xa0'));
			gtop.style.backgroundColor = FIRST$(COLOR.innerWindow);

			gtop.style.margin = '0';
			gtop.style.padding = '0';

			if (list.firstChild)
				list.insertBefore(gtop, list.firstChild);
			else
				list.appendChild(gtop);
			list._gtop = gtop;
		}
		gtop.style.height = y + 'px';
		gtop.style.lineHeight = y + 'px';
	} else if (list._gtop) {
		list._gtop.style.height = '0px';
		list._gtop.style.lineHeight = '0px';
		y = 0;
	}

	if (!list._grow) {
		list._grow = [];
	}

	var nrow = 0;
	var needf;
	for (j = top; j < (top+LIMIT) && j < fs; j++) {
		var msg = undefined;;
		if (viewrel && (typeof viewrel[j] != 'undefined')) {
			msg = mdata[viewrel[j]];
		}
		if (!msg) {
			// err, we'll need a fetchmail
			if (typeof needf == 'undefined') needf = j;
			msg = EMPTY;
		}

		var txt;

		var row;
		if (list._grow[nrow]) {
			row = list._grow[nrow];
			if (row._hidden) {
				row._hidden=undefined;
				row.style.display = '';
			}
		} else {
			row = document.createElement('DIV');
			row.style.overflow = 'hidden';
			row.style.whiteSpace = 'nowrap';
			list._grow[nrow] = row;
			if (list._gbottom) {
				list.insertBefore(row, list._gbottom);
			} else {
				list.appendChild(row);
			}
		}
		nrow++;
		
		if (!row._cols || row._cols != cols.length) {
			while (row.firstChild) row.removeChild(row.firstChild);
			row._cols = cols.length;
			for (i = 0; i < cols.length; i++) {
				var td = IB$();
				td.tabIndex = -1;
				td.style.cursor = 'default';
				td.style.textAlign = 'left';
				td.onmouseover = _fix_status;
				td.ondblclick = _listview_dblclick;
				td.onclick = _listview_click;
				if (window[ window._current_provider ].noMoveFrom) {
					td.onmousedown = true$;
				} else {
					dragsource$(td, _listview_dragop);
				}
				td.style.whiteSpace = 'nowrap';
				td.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
				td.style.textDecoration='none';
				td.style.verticalAlign='bottom';
				td.style.overflow='hidden';
				td.style.margin='0';
				td.style.padding='0';
				td.style.lineHeight = h+'px';
				td.style.height = h+'px';
				row.appendChild(td);
			}
		}

		var td = row.firstChild;
		var lastfixed=true;
		for (i = 0; i < cols.length; i++) {
			td._row = j;
			if (window.__selected_object == j || (window._select_group && window._select_group[j])) {
				BGCOLOR(td,COLOR.hilight);
				FGCOLOR(td,COLOR.hilightText);
			} else {
				FGCOLOR(td,COLOR.innerWindowText);
				BGCOLOR(td,COLOR.innerWindow);
			}

			td.style.width = pos[i]+'px';

			var txt=undefined;
			if (cols[i].column) {
				// might replace onclick(!)
				txt = cols[i].column(td, msg);
			} else {
				txt = msg[ cols[i].toString().toLowerCase() ];
			}

			var axd = td;
			if (axd._box) axd = axd._box;

			if (txt && (txt.data || txt.tagName)) {
				while (axd.firstChild) axd.removeChild(axd.firstChild);
				if (!lastfixed) {
					axd.appendChild(document.createTextNode("\xa0"));
				}
				axd.appendChild(txt);
				if (txt._title) td.title = txt._title;
				else td.title = '';

			} else if (txt && txt != '' && txt != '\xa0') {
				if (!td.title || td.title != txt) {
					while (axd.firstChild) axd.removeChild(axd.firstChild);
					if (!lastfixed) {
						axd.appendChild(document.createTextNode("\xa0"));
					}
					axd.appendChild(document.createTextNode(txt));
				}
				td.title = txt;
			} else if (td.title) {
				td.title = '';
				while (axd.firstChild) axd.removeChild(axd.firstChild);
				axd.appendChild(document.createTextNode('\xa0'));

			} else if (!axd.firstChild) {
				axd.appendChild(document.createTextNode('\xa0'));
			}

			if (msg._is_unread && msg._is_unread == true)
				td.style.fontWeight='bold';
			else
				td.style.fontWeight='normal';
			td = td.nextSibling;

			if (cols[i].width) {
				lastfixed = true;
			} else {
				lastfixed = undefined;
			}

		}
		y += h;
	}
	for (; nrow < list._grow.length; nrow++) {
		var fr = list._grow[nrow];
		fr.style.display = 'none';
		fr._hidden=true;
	}
	// bottom padding
	var vh = ((VGRAB._position-(tbsheight()))-2)-h;
	if (y < ps || ps < vh) {
		var gbottom;
		if (list._gbottom) {
			gbottom = list._gbottom;
		} else {
			gbottom = document.createElement('DIV');
			gbottom.style.backgroundColor = FIRST$(COLOR.innerWindow);
			gbottom.appendChild(document.createTextNode('\xa0'));
			list.appendChild(gbottom);
			list._gbottom = gbottom;
		}
		if (ps < vh) {
			list._gbottom.style.height = (vh-ps) + 'px';
		} else {
			gbottom.style.height = (ps-y) +'px';
		}
	} else if (list._gbottom) {
		list._gbottom.style.height = '0px';
	}
	// restore this guy
	list.scrollTop = stop;

	// something went wrong...
	// make sure we've got the data...
	if (!nof && (typeof needf != 'undefined')) {
		fetchmail(f, needf-LIMIT, LIMIT*3);
	}
}
function coreview(pv) {
	dom_keyholder = undefined;
	window.status = '\xa0 ';

	while (BOXLIST.firstChild) BOXLIST.removeChild(BOXLIST.firstChild);
	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);

	ATTPICK.style.display = 'none';
	_searchbox_vis('');

	var xtc = dom_autocomplete;
	if (xtc && xtc._boundto) {
		xtc.style.display='none';
		xtc._eatme=-1;
	}

	hideLIST$();
	window._current_view = 'core';
	window._current_provider = pv;
	window.__lv2 = undefined;
	window.__pv2 = undefined;
	if (!window._name) {
		window._current_folder = '';
	}

	var ex = window[pv];
	if (!ex) return;
	ex.view();
}

function _vcf_loc_helper(hf) {
	if (this.source) {
		// err... xxx make it possible to subscribe here..?
		var av = document.createElement('DIV');
		var bv = document.createElement('SPAN');
		_plan_colorize(bv, window._labelcolors[ this.source ]);
		bv.appendChild(document.createTextNode('\xa0\xa0\xa0'));
		av.appendChild(bv);
		av.appendChild(document.createTextNode('\xa0' + this.source));

		av.style.whiteSpace = 'nowrap';
		av.style.cursor = 'default';

		hf("Source", av);
		return;
	}

	var zo = document.createElement('SELECT');
	var idx = 0;
	var ll = _planobj_label(this);
	for (i in window._labelcolors) {

		if (i.match(/^https?:\/\//) || i.match(/^webcal:/)) {
			// we don't _really_ want to be in here...
			continue;
		}

		var av = document.createElement('OPTION');
		av._labelid = i;
		_plan_colorize(av, window._labelcolors[i]);
		av.appendChild(document.createTextNode('\xa0\xa0\xa0' + _labelcolor_src(i)));
		zo.appendChild(av);
		if (i == ll) {
			_plan_colorize(zo, window._labelcolors[i]);
			zo.selectedIndex = idx;
		}
		idx++;
	}
	zo._object = this;
	zo.onchange = zo.onkeydown = zo.onkeyup = function() {
		var o = this.options[this.selectedIndex]._labelid;
		var b = this._object;
		b.labels = [ o ];
		_plan_colorize(zo, window._labelcolors[o]);
	};
	hf("Label", zo);
}
function _vcf_dt_helper(hf) {
	var cg = document.createElement('DIV');
	cg.innerHTML = this.start + ' - ' + this.end;
	hf('Time', cg);
}
function _vcf_onsend_helper() {
	// xxx let's turn this into a vCalendar
	return undefined;
}

function meetform(n) {
	// events are actually composer "forms"
	if (!n) n = {};
	if (!n._mailto && !n._cc) {
		// include ourselves...
		n._mailto = '"' + QC(WANT('my_name')) + '" <' + QC(WANT('my_email')) + '>';
	}
	if (!n.labels) {
		n.labels = ['Work'];
	}
	n.FORM = 'meetform';
	composer(n);
}
meetform.onSend = _vcf_onsend_helper;
meetform.noSignature = true;
meetform.subjectString = "Summary";
meetform.fromString = "Organizer";
meetform.recipString = 'Attendees';
meetform.noDraftSupport = true;
meetform.recipCCString = 'Cc';
meetform.headers = [ // ??? xxx
	"Location",
	_vcf_loc_helper,
	_vcf_dt_helper
];

function eventform(n) {
	// events are actually composer "forms"
	if (!n) n = {};
	n.FORM = 'eventform';
	composer(n);
}
eventform.onSend = _vcf_onsend_helper;
eventform.noAddressing = true;
eventform.noSignature = true;
eventform.fromString = '';
eventform.subjectString = "Summary";
eventform.headers = [
	"Location",
	_vcf_loc_helper,
	_vcf_dt_helper
];


function planview(f) {
	coreview("planview");
}
function _planmonth_initial(zf) {
	var dd = new Date();
	if (dd.getUTCMonth() == 0) {
		dd.setUTCMonth(11);
		dd.setUTCFullYear(dd.getUTCFullYear()-1);
	} else {
		dd.setUTCMonth(dd.getUTCMonth()-1);
	}
	return _planmonth(dd,zf);
}
function _planmonth(d,zf) {
	if (!_planmonth.qq) {
		_planmonth.qq = new Queue();
	}
	if (typeof d == 'undefined') return; // you are not helpful
	try {
		localyearmonth(d);
	} catch(e) {
		throw("e="+e+", caller=" + d);
	};
	var nk = 'MONTHDATA:' + localyearmonth(d);
	var np = window;
	while (np && np.parent && np.parent != np) np = np.parent;
	if (np[nk]) {
		if (zf) zf(np[nk]);
		return;
	}

	_planmonth.qq.append(function() {
		var mo,yo;
		if (WANT('use_gmt')) {
 			mo = d.getUTCMonth()+1;
	 		yo = d.getUTCFullYear();
		} else {
 			mo = d.getMonth()+1;
	 		yo = d.getFullYear();
		}

		var smo = mo;
		var syo = yo;

		var k = 'MONTHDATA:' + yo + '-' + mo;
		var p = window;
		while (p && p.parent && p.parent != p) p = p.parent;

		if (p[k]) {
			if (zf) zf(p[k]);
			return;
		}

		if (mo == 12) { mo = 1; yo++; } else mo++;
		var k1 = 'MONTHDATA:' + yo + "-" + mo;
		if (mo == 12) { mo = 1; yo++; } else mo++;
		var k2 = 'MONTHDATA:' + yo + "-" + mo;

		httpmail.calendar.fetch.onreply = function(r) {
			try {
				p[k] = r[0];
				if (r.length == 3) {
					p[k1] = r[1];
					p[k2] = r[2];
				}
				if (zf) zf(p[k]);
			} catch(e) {};
			unbusy$();
			status$('');
			_planmonth.qq.unlock();
		};

		_planmonth.qq.lock();
		if (p[k1] && p[k2]) {
			httpmail.calendar.fetch(syo, smo, 1);
		} else {
			httpmail.calendar.fetch(syo, smo, 3);
		}
		busy$();
		status$('Fetching calendar data');
	});
}
function _labelcolors_pick() {
	var cn;
	if (!_labelcolors_pick.cn) {
		cn = 0;
	} else {
		cn = _labelcolors_pick.cn;
	}
	_labelcolors_pick.cn = cn+1;

	function avrg(a,b,k) { return a + Math.round((b-a)*k); }
	if (!_labelcolors_pick.cw) {
		_labelcolors_pick.cw = [
			[255,0,0,	0,100,100],
			[255,51,0,	15, 100, 100],
			[255,102,0,	30, 100, 100],
			[255,128,0,	45, 100, 100],
			[255,153,0,	60, 100, 100],
			[255,178,0,	75, 100, 100],
			[255,204,0,	90, 100, 100],
			[255,229,0,	105, 100, 100],
			[255,255,0,	120, 100, 100],
			[204,255,0,	135, 100, 100],
			[153,255,0,	150, 100, 100],
			[51,255,0,	165, 100, 100],
			[0,204,0,	180, 100, 80],
			[0,178,102,	195, 100, 70],
			[0,153,153,	210, 100, 60],
			[0,102,178,	225, 100, 70],
			[0,51,204,	240, 100, 80],
			[25,25,178,	255, 100, 70],
			[51,0,153,	270, 100, 60],
			[64,0,153,	285, 100, 60],
			[102,0,153,	300, 100, 60],
			[153,0,153,	315, 100, 60],
			[204,0,153,	330, 100, 80],
			[229,0,102,	345, 100, 90]
		];
	}

	var d = (((cn % 24) + (cn % 48) + (cn % 96) + (cn % 192) + (cn % 384)) % 24);
	var c1 = _labelcolors_pick.cw[d];
	var c2 = _labelcolors_pick.cw[(d+1) % 24];
	var k = (cn % 15) / 15.0;

	var r0 = avrg(c1[0],c2[0],k);
	var g0 = avrg(c1[1],c2[1],k);
	var b0 = avrg(c1[2],c2[2],k);

	var s0 = avrg(c1[4],c2[4],k);
	var v0 = avrg(c1[5],c2[5],k);

	var sx = [ 0.25, 0.5, 0.1, 0.5 ];
	var vx = [ 1.0, 0.25, 1.0, 1.0 ];

	function rgbs(r,g,b,s,v) {
		var mx = Math.max(Math.max(r,g),b);
		var mn = Math.min(Math.min(r,g),b);

		v = v * 255;

		var k = (mx > 0) ? (v / mx) : 0;

		r = Math.round(v-(v-r*k)*s); if (r > 255) r = 255;
		g = Math.round(v-(v-g*k)*s); if (g > 255) g = 255;
		b = Math.round(v-(v-b*k)*s); if (b > 255) b = 255;

		return '#' + H$(r) + '' + H$(g) + '' + H$(b);
	}

	var z = (k > 0.5) ? 2 : 0;
	var uc1 = rgbs(r0,g0,b0, sx[z], vx[z]);
	var uc2 = rgbs(r0,g0,b0, sx[1], vx[1]);

	return [uc1, uc2, uc2];
}
function _plan_colorize(div,co) {
	if (!co) return;
	div.style.backgroundColor = co[0];
	div.style.border = '1px solid ' + co[1];
	div.style.color = co[2];
}

function _rssfeed_popf(sign, popup) {
	if (_rss_issub(this._feedurl)) {
		popup.append('blank.gif', 'Unsubscribe', function(z) {
			var url = z._feedurl;
			_rss_unsub([url]);
			_rss_sub.qq.append(function() {
				window.__lv2 = undefined;
				window.__pv2 = undefined;
				window._labelhide[url] = undefined;
				window._labelcolors[url] = undefined;
				update_listview2();
				notice$('Unsubscribed from '+z._feedurl);
			});
		});
	} else {
		popup.append('blank.gif', 'Subscribe', function(z) {
			var url = z._feedurl;
			_rss_sub([url]);
			_rss_sub.qq.append(function() {
				window.__lv2 = undefined;
				window.__pv2 = undefined;
				update_listview2();
				notice$('Subscribed to '+z._feedurl);
			});
		});
	}
	popup.append(RSRC$('images/stock_undo.png'), 'Cancel');
}
function _calfeed_popf(sign, popup) {
	if (_cal_issub(this._feedurl)) {
		popup.append('blank.gif', 'Unsubscribe', function(z) {
			var url = z._feedurl;
			_cal_unsub([url]);
			_cal_sub.qq.append(function() {
				window.__lv2 = undefined;
				window.__pv2 = undefined;
				window._labelhide[url] = undefined;
				window._labelcolors[url] = undefined;
				update_listview2();
				notice$('Unsubscribed from '+z._feedurl);
			});
		});
	} else {
		popup.append('blank.gif', 'Subscribe', function(z) {
			var url = z._feedurl;
			_cal_sub([url]);
			_cal_sub.qq.append(function() {
				window.__lv2 = undefined;
				window.__pv2 = undefined;
				update_listview2();
				notice$('Subscribed to '+z._feedurl);
			});
		});
	}
	popup.append(RSRC$('images/stock_undo.png'), 'Cancel');
}
function _plan_popf(sign, popup) {
	if (this._label != this._displayName) {
		popup.append(RSRC$('images/stock_delete.png'), 'Unsubscribe', function(z) {
			if (confirm("Are you sure you want to unsubscribe from\n" + z._displayName
					+ " <URL:" + z._label + ">")) {
				_cal_unsub([ z._label ]);
				_cal_sub.qq.append(function() {
					planview.inner_view();
					window._labelhide[z._label] = undefined;
					window._labelcolors[z._label] = undefined;
					notice$('Unsubscribed from ' + z._label);
				});
			}
		});
	}
	if (window._labelhide[ this._label ]) {
		popup.append(RSRC$('images/stock_macro-watch-variable.png'), 'Show', function(z) {
			window._labelhide[ z._label ] = undefined;
			planview.inner_view();
			notice$(z._displayName + ' is now visible');
		});
	} else {
		popup.append(RSRC$('images/stock_macro-stop-watching.png'), 'Hide', function(z) {
			window._labelhide[ z._label ] = true;
			planview.inner_view();
			notice$(z._displayName + ' is now hidden');
		});
	}
	popup.append(RSRC$('images/stock_undo.png'), 'Cancel');
};

function _av_clicker(e) {
	apply$(_plan_popf, _drop_may_popup, e, this, _attachment_tailf);
	blur$();
}
function _plan_legend() {
	if (!window.__pv2) return;
	var pv = window.__pv2;
	if (!pv.parentNode) {
		window.__pv2 = undefined;
		return;
	}

	var i;
	while (pv.firstChild) pv.removeChild(pv.firstChild);
	for (i in window._labelcolors) {
		var av = document.createElement('A');
		av.tabIndex = -1;
		av.style.textDecoration = 'none';
		av.href = nullhref();
		av._label = i;

		var bv = document.createElement('SPAN');
		_plan_colorize(bv, window._labelcolors[i]);
		bv.appendChild(document.createTextNode('\xa0\xa0\xa0'));
		av.appendChild(bv);
		var ij = _labelcolor_src(i);
		if (i != ij) {
			var img = imgsrc$(imgtag$(), RSRC$('images/stock_web-calendar.png'), 16,16);
			img.setAttribute('VALIGN', 'top');
			av.appendChild(document.createTextNode('\xa0' + ij));
			av.appendChild(img);
		} else {
			av.appendChild(document.createTextNode('\xa0' + i));
		}
		av._displayName = ij;
		av.onmouseover = _fix_status;
		av.onclick = _av_clicker;

		av.style.whiteSpace = 'nowrap';
		if (window._labelhide[ i ]) {
			FGCOLOR(av,COLOR.grayText);
		} else {
			FGCOLOR(av,COLOR.innerWindowText);
		}
		av.style.cursor = 'default';
		pv.appendChild(av);
		pv.appendChild(document.createElement('BR'));
	}
}

function _labelcolor_src(src) {
	if (src.match(/^https?:\/\//) || src.match(/^webcal:/)) {
		var aa = src.match(/~([^\/][^\/]*)/);
		if (aa) return aa[1];
		aa = src.match(/:\/\/([^\/][^\/]*)/);
		if (aa) return aa[1];
	}
	return src;
}
function _planobj_label(obj, def) {
	if (obj._labelcache) return obj._labelcache;
	if (!def) def = 'Personal';

	var ll;
	if (obj.source) {
		ll = obj.source;
	} else if (obj.labels) {
		ll = obj.labels[0]||'';
		if (!ll) ll = '';
		var lj = ll.indexOf("\\,");
		if (lj > -1) ll = ll.substr(0, lj);
		lj = ll.indexOf(",");
		if (lj > -1) ll = ll.substr(0, lj);
		if (ll == '') ll = def;
	} else {
		ll = def;
	}
	obj._labelcache = ll;
	return ll;
}
function _planstyle(div, obj, prio) {
	var txt;
	if (obj.summary && obj.location) {
		txt = obj.summary + " @ " + obj.location;
	} else if (obj.summary) {
		txt = obj.summary;
	} else if (obj.location && obj.description) {
		txt = "@ " + obj.location + ", " + obj.description;
	} else if (obj.description) {
		txt = obj.description;
	} else {
		txt = "Event";
	}
	div.style.textDecoration = 'none';
	div.setAttribute('title', txt);
	if (prio) {
		if (txt.length > 20) txt = txt.substr(0, 18) + '...';
	} else {
		// anything we want to do here?
	}
	div.appendChild(document.createTextNode(txt));
	var ll = _planobj_label(obj);
	if (!window._labelcolors[ll]) {
		window._labelcolors[ll] = _labelcolors_pick();
		_plan_legend();
	}
	_plan_colorize(div, window._labelcolors[ll]);
}
function _plancolsplit(table, col) {
	// okay, once per row of table
	var ncolown = -1;
	cs(table, 'TD', function(q) {
		if (q._colown && q._colown > ncolown)
			ncolown = q._colown;
	});
	ncolown++;
	cs(table, 'TR', function(q) {
		if (q._setvalue) {
			var user = undefined;
			cs(q,'TD',function(p) {
				if (user) return;
				if (typeof p._colnum != 'undefined' && p._colnum > col) {
					user = p;
				}
			});
			var td = _planrender_cell(col,ncolown,q._setvalue)
			if (user)
				user.parentNode.insertBefore(td,user);
			else
				q.appendChild(td);
		} else {
			// increase colspan of this column's heading (because we've got a new column)
			cs(q,'TD',function(p) {
				if (typeof p._colnum != 'undefined' && p._colnum == col) {
					var as = p.getAttribute('COLSPAN');
					if (!as) as = 1;
					as = parseInt(as)+1;
					p.setAttribute('COLSPAN', as+'');
				}
			});
		}
	});
}
function _aa_pd_full(e) {
	return PD$(E$(e));
}
function _aa_eventform() {
	eventform(this._event);
}
function _planrender2(table, col, set, lay, evtoday) {
	var mav = {};
	var i, j, k;
	var ev;
	for (i = 0; i < evtoday.length; i++) {
		ev = evtoday[i];
		ev._startsat = '';
		ev._slength = 0;

		if (window._labelhide[ _planobj_label(ev) ]) {
			ev._skipme = true;
		} else {
			ev._skipme = undefined;
		}
	}
	for (j = -1; j < set.length; j++) {
		var c = 0;
		for (i = 0; i < evtoday.length; i++) {
			ev = evtoday[i];
			if (ev._skipme) continue;
			if (!ev.js_end) {
				if (j == -1) {
					ev._startsat = '';
					ev._slength++;
					c++;
				}
				// all day event...
				continue;
			} else if (j == -1) {
				// ignore all-day slot
				continue;
			}

			var sbn = false;
			var ebn = false;
			var san = false;
			var ean = false;
			if (ev.js_start_today && ev.js_end_today) {
				var sa = ev._sa;
				var ea = ev._ea;
				if (sa == set[j]) {
					san = true;
				} else if (ea == set[j]) {
					ean = true;
				} else {
					for (k = 0; k < j; k++) {
						if (sa == set[k]) sbn = true;
						if (ea == set[k]) { ebn = true; break; }
					}
				}
			} else if (ev.js_start_today) {
				var sa = ev._sa;
				for (k = 0; k <= j; k++) {
					if (sa == set[k]) { sbn = true; break; }
				}
				if (sa == set[j]) san = true;
			} else if (ev.js_end_today) {
				var ea = ev._ea;
				for (k = 0; k < j; k++) {
					if (ea == set[k]) { ebn = true; break; }
				}
				if (ea == set[j]) ean = true;
				sbn = true;
			} else {
				sbn = true;
			}
			if (san) {
				ev._startsat = set[j];
				ev._slength++;
			} else if (ean) {
				ev._slength++;
			} else {
				if (ebn && ebn == true) continue;
				if (sbn && sbn == true) {
					ev._slength++;
				} else {
					continue;
				}
			}
			c++;
		}
		if (lay[col][4] < c) {
			// okay, need to resize this column
			lay[col][4] = c;
			_plancolsplit(table, col);
		}
	}
	for (i = 0; i < evtoday.length; i++) {
		ev = evtoday[i];
		if (ev._skipme) continue;

		if (ev._occupied) {
			var oc = ev._occupied;
			while (oc && oc != document.body) {
				if (oc == table) break;
				oc = oc.parentNode;
			}
			if (oc && oc == table) {
				// still attached to the layout
				continue;
			}
		}

		var aa = document.createElement('A');
		aa.tabIndex = -1;
		aa.style.height = '100%';
		aa.style.display = 'block';
		aa.style.overflow = 'hidden';
		aa._event = ev;
		aa.href = nullhref();
		aa.onmouseover = _fix_status;
		aa.onclick = _aa_pd_full;
		aa.ondblclick = _aa_eventform;

		var tr, td, ltd;
		if (ev._startsat == '') {
			tr = table.firstChild.nextSibling; // tr+tr
			td = undefined;
			ltd = undefined;
			cs(tr, 'TD', function(q) {
				if (typeof q._colnum != 'undefined' && q._colnum == col) {
					ltd = q;
					if (q._occupant) return;
					td = q;
				}
			});
			if (!td) {
				throw 'should never happen (column should already be resized)';
			}
			td._occupant = ev;
			while (td.firstChild) td.removeChild(td.firstChild);
			_planstyle(aa, ev, true);
			td.appendChild(aa);
			continue;
		}
		
		if (ev._slength <= 0) {
			// err, i'm not sure what can cause this...
			// but it seems to be harmless
			continue;
		}

		var cj = ev._startsat;
		tr = undefined;
		cs(table, 'TR', function(q) {
			if (q._setvalue && q._setvalue == cj) {
				if (tr) {
					throw "already have a tr! what's going on?";
					throw "q="+q+", cj="+cj;
				}
				tr = q;
			}
		});
		if (!tr) {
			// i'm not sure what can cause this...
			throw 'couldnot find a tr with setvalue='+cj;
		}
		td = undefined;
		ltd = undefined;
		cs(tr, 'TD', function(q) {
			if (typeof q._colnum != 'undefined' && q._colnum == col) {
				ltd = q;
				if (q._occupant) return;
				td = q;
			}
		});
		if (!td) {
			throw 'should never happen (column should already be resized)';
		}
		td._occupant = ev;
		while (td.firstChild) td.removeChild(td.firstChild);
		_planstyle(aa, ev);
		td.appendChild(aa);

		if (ev._slength > 1) {
			// alright,
			td.setAttribute('ROWSPAN', ev._slength);
			var killme = [];
			for (tr = tr.nextSibling; tr; tr = tr.nextSibling) {
				cs(tr, 'TD', function(q) {
					if (q._colown && q._colown == td._colown)
						killme[killme.length] = q;
				});
			}
			for (j = 0; j < killme.length && j < ev._slength-1; j++) {
				td = killme[j];
				if (td._occupant) break;
				td._occupant=true;
				td.parentNode.removeChild(td);
			}
		}
	}
	//xxx
}
function _planrender_cell(colnum, colx, sv) {
	var td = document.createElement('TD');
	td._colnum = colnum;
	td._colown = colx;
	td.style.whiteSpace = 'normal';
	td.style.overflow = 'hidden';
	var aa = document.createElement('A');
	aa.tabIndex = -1;
	aa.href = nullhref();
	aa.onmouseover = _fix_status;
	aa.appendChild(document.createTextNode('\xa0'));
	aa.style.textDecoration = 'none';
	FGCOLOR(aa,COLOR.innerWindowText);
	aa.style.display = 'block';
	aa.style.cursor = 'default';
	td.appendChild(aa);
	td.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
	td._rep = sv;

	aa.onclick = function(e) { e=E$(e);
		var tr = td.parentNode;
		var tbody = tr.parentNode;
		cs(tbody,'TD',function(q) {
			if (q._insel) {
				q._insel = undefined;
				FGCOLOR(q,COLOR.innerWindowText);
				BGCOLOR(q,COLOR.innerWindow);
			}
		});
		window.__dragsel_start = undefined;
		window.__dragsel = undefined;
		window.__dragset = undefined;
		return PD$(e);
	};
	td.onmousedown = aa.onmousedown = function(e) { e=E$(e);
		var tr = td.parentNode;
		var tbody = tr.parentNode;
		cs(tbody,'TD',function(q) {
			if (q._insel) {
				q._insel = undefined;
				FGCOLOR(q,COLOR.innerWindowText);
				BGCOLOR(q,COLOR.innerWindow);
			}
		});
		window.__dragsel_start = sv; // the td
		window.__dragsel = undefined;
		window.__dragset = undefined;
		return PD$(e);
	};
	aa.onmousemove = function(e) { e=E$(e);
		if (window.__dragsel_start) {
			window.__dragsel = window.__dragsel_start;
			window.__dragsel_start = undefined;
		}
		if (window.__dragsel) {
			var tbody = td.parentNode.parentNode;
			var lit = undefined;
			window._dragset = [];
			cs(tbody,'TR',function(r) {
				var wasl = lit;
				cs(r,'TD',function(q) {
					if (typeof q._rep == 'undefined') return;

					if (q._colown != td._colown) {
						if (q._insel) {
							q._insel = undefined;
							FGCOLOR(q,COLOR.innerWindowText);
							BGCOLOR(q,COLOR.innerWindow);
						}
						return;
					}

					if (q._rep == window.__dragsel || q._rep == td._rep) {
						if (!wasl) {
							lit = true;
						}
					}
					if (q._occupant) return;

					if (lit) {
						BGCOLOR(q,COLOR.hilight);
						FGCOLOR(q,COLOR.hilightText);
						window._dragset[window._dragset.length] = q._rep;
						q._insel = true;
					} else {
						q._insel = undefined;
						FGCOLOR(q,COLOR.innerWindowText);
						BGCOLOR(q,COLOR.innerWindow);
					}

					if (q._rep == window.__dragsel && q._rep == td._rep) {
						lit = undefined;
					} else if (wasl && (q._rep == window.__dragsel || q._rep == td._rep)) {
						lit = undefined;
					}
				});
			});
		}
		return true;
	};
	aa.ondblclick = function(e) {
		if (window._dragset) {
			var ds = window.__dragset;
			// okay, its selected xxx
		}
	};
	td.onmouseup = aa.onmouseup = function(e) { e=E$(e);
		window.__dragsel_start = undefined;
		if (window.__dragsel) {
			// swallow click
			window.__dragsel = undefined;
			return PD$(e);
		} else {
			window.__dragset = undefined;
			return true;
		}
	};

	return td;
}
function _planrender_set(table, set, lay) {
	function _add_setrow(tr, txt) {
		var td = document.createElement('TD');
		if (txt.match(/^(12:.*:.*am|0?[1-7]:.*:.*am|1[89]:.*:.*|0?[6789]:.*:.*pm|1[01]:.*:.*pm)$/)) {
			FGCOLOR(td,COLOR.grayText);
		} else {
			FGCOLOR(td,COLOR.innerWindowText);
		}
		td.style.verticalAlign = 'bottom';
		BGCOLOR(td,COLOR.innerWindow);
		td.style.cursor = 'default';
		td.style.textAlign = 'right';
		td.appendChild(document.createTextNode(txt));
		tr._setvalue = txt;
		tr.appendChild(td);

		var j;
		for (j = 0; j < lay.length; j++) {
			td = _planrender_cell(j,j+1,txt);
			td.style.borderLeft = '1px dotted ' + COLOR.grayText;
			tr.appendChild(td);
		}
	}


	var i, j;
	if (table.firstChild) {
		// we've been through this before
		var rown = 0;
		i = 0;

		cs(table, 'TR', function(tr) {
			if (!tr._setvalue) return;

			while (i < set.length && tr._setvalue != set[i]) {
				var ntr = document.createElement('TR');
				ntr._setvalue = set[i];
				_add_setrow(ntr, set[i]);
				table.insertBefore(ntr, tr);
				i++;
			}
			i++;
		});
		while (i < set.length) {
			var tr = document.createElement('TR');
			tr._setvalue = set[i];
			_add_setrow(tr, set[i]);
			table.appendChild(tr);
			i++;
		}
	} else {
		var tr, td;
		tr = document.createElement('TR');
		td = document.createElement('TD');
		td.appendChild(document.createTextNode('\xa0'));
		td.setAttribute('WIDTH', '9%');
		tr.appendChild(td);
		for (i = 0; i < lay.length; i++) {
			td = document.createElement('TD');
			outset$(td);
			td.style.cursor = 'default';
			td.style.textAlign = lay[i][3];
			td.setAttribute('WIDTH', lay[i][2]);
			td._colnum = i;
			td.setAttribute('COLSPAN', '1');

			td.appendChild(document.createTextNode(lay[i][1]));
			tr.appendChild(td);
		}
		table.appendChild(tr);

		tr = document.createElement('TR');
		table.appendChild(tr);
		td = document.createElement('TD');
		td.appendChild(document.createTextNode('\xa0'));
		tr.appendChild(td);
		for (i = 0; i < lay.length; i++) {
			td = document.createElement('TD');
			td.appendChild(document.createTextNode('\xa0'));
			td._colnum = i;
			td._colown = (i+1);
			td.style.borderLeft = '1px dotted ' + FIRST$(COLOR.grayText);
			td.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
			tr.appendChild(td);
		}

		for (i = 0; i < set.length; i++) {
			tr = document.createElement('TR');
			table.appendChild(tr);
			_add_setrow(tr, set[i]);
		}
	}

}
function _planrender(table, lay)
{
	var set = [];
	var i;
	if (WANT('use_gmt')) {
		for (i = 0; i < 24; i++) {
			var nd = new Date();
			nd.setUTCHours(i);
			nd.setUTCMinutes(0);
			nd.setUTCSeconds(0);
			nd.setUTCMilliseconds(0);
			set[i] = localtimeonly(nd);
		}
	} else {
		for (i = 0; i < 24; i++) {
			var nd = new Date();
			nd.setHours(i);
			nd.setMinutes(0);
			nd.setSeconds(0);
			nd.setMilliseconds(0);
			set[i] = localtimeonly(nd);
		}
	}

	_planrender_set(table, set, lay);

	function _set_mergin(s) {
		var j;
		var h = s.substr(0, 2);
		var rest = 'a' + s.substr(2, s.length-2);
		var trip = 0;
		for (j = 0; j < set.length; j++) {
			if (s == set[j]) {
				// already have this one _exactly_
				return set;
			}
			if (set[j].substr(0,2) != h) {
				if (trip) {
					_array_insert_at(set, j, s);
					_planrender_set(table, set, lay);
					return set;
				}
				continue;
			}
			if (WANT('use_gmt'))
				trip = 1;
			else if (s.substr(s.length-2,2) == set[j].substr(set[j].length-2,2))
				trip = 1;
			var rr = 'a' + set[j].substr(2, set[j].length-2);
			if (rest < rr) {
				_array_insert_at(set, j, s);
				_planrender_set(table, set, lay);
				return set;
			}
		}
		if (trip) {
			set[set.length] = s;
			_planrender_set(table, set, lay);
			return set;
		}
		// we didn't see it. something is wrong
		// this should never be reached
		throw "Should never happen (setmergin saw '"+s+"')";
		return set;
	}

	for (i = 0; i < lay.length; i++) {
		var jtx = lay[i][0];
		var tjy = localdate(jtx);
		(function(jt, jtstr, colnum) {
			_planmonth(jt, function(md) {
				var ad = md[ jt.getUTCDate() ]; 
				if (!ad || !ad.length) return;
				var ai;
				for (ai = 0; ai < ad.length; ai++) {
					var ev = ad[ai];

					ev.js_start = new Date(ev.unix_start * 1000.0);
					if (localdate(ev.js_start) == localdate(jt)) {
						ev.js_start_today = true;

						ev._sa = localtimeonly(ev.js_start);
						_set_mergin(ev._sa);
					}

					if (ev.unix_end && ev.unix_end != ev.unix_start) {
						ev.js_end = new Date(ev.unix_end * 1000.0);
						if (localdate(ev.js_end) == localdate(jt)) {
							ev._ea = localtimeonly(ev.js_end);
							_set_mergin(ev._ea);

							ev.js_end_today = true;
						}
					}
				}
	
				_planmonth.qq.append(function() {
					_planrender2(table, colnum, set, lay, ad);
				});
			});
		})(jtx, tjy, i);
	}
}

planview.inner_view = function() {
	// personal colors first (always)
	if (config['FEED$cal']) {
		var x;
		var j = config['FEED$cal'].split("\n");
		for (x = 0; x < j.length; x++) {
			var y = j[x];
			if (y == '') continue;
			if (!window._labelcolors[y]) window._labelcolors[y] = _labelcolors_pick();
		}
	}

	// ick, need to refactor calview... it's not quite so general purpose...
	update_view3m(function(body) {
		if (_planmonth.qq) {
			_planmonth.qq.empty();
		}

		var h2 = document.createElement('DIV');
		h2.style.cursor = 'default';
		h2.style.fontWeight = 'bold';
		h2.style.fontSize = '150%';
		FGCOLOR(h2,COLOR.grayText);
		h2.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
		h2.style.marginBottom = '4px';
		h2.style.paddingLeft = '4px';

		var pt;
		if (window._plan_time) {
			pt = window._plan_time;
		} else {
			pt = new Date;
		}
		body.appendChild(h2);
		if (WANT('calview') != 'month') {
			h2.style.marginBottom = '4px';
		}

		if (WANT('calview') == 'week') {
			// draw small minimonth view in upper right
			var gy = document.createElement('DIV');
			gy.style.whiteSpace = 'nowrap';

			var gyt = document.createElement('TABLE');
			gy.appendChild(gyt);

			var hf;
			if (WANT('use_gmt')) {
				hf = function(t) {
					return window.dowshortstr[t.getUTCDay()] + ' ' + t.getUTCDate();
				};
			} else {
				hf = function(t) {
					return window.dowshortstr[t.getDay()] + ' ' + t.getDate();
				};
			}

			var lay = [];

			var gd = document.createElement('DIV');
			gd.style.cssFloat = 'right';
			var tg = _calmaker(function() {
				this._forwardpost = function(aa) {
					while (gyt.firstChild) gyt.removeChild(gyt.firstChild);

					var gytb = document.createElement('TBODY');
					gyt.appendChild(gytb);

					var nj, nt;
					nt = aa._fdow;
					for (nj = 0; nj < 7; nj++) {
						lay[nj] = [ nt, hf(nt), '13%', 'center', 1 ];
						nt = new Date(nt.valueOf() + 86400000.0);
					}
					while (h2.firstChild) h2.removeChild(h2.firstChild);
					h2.appendChild(document.createTextNode('Week starting '
							+ localdate(aa._fdow)));

					while (gytb.firstChild) gytb.removeChild(gytb.firstChild);
					_planrender(gytb, lay);
				};
				this._weekview = true;
			});
			gd.appendChild(tg);
			body.appendChild(gd);
			body.appendChild(gy);

			gy.style.paddingLeft = '4px';
			gy.style.paddingRight = '4px';
			window.setTimeout(function() {
				resizeHelper(function() {
					gy.style.marginRight = gd.offsetWidth + 'px';
				}, true);
			}, 10);
		} else if (WANT('calview') == 'day') {
			// draw small minimonth view in upper right
			var gy = document.createElement('DIV');
			var gd = document.createElement('DIV');
			gd.style.cssFloat = 'right';
			gy.style.whiteSpace = 'nowrap';

			var gyt = document.createElement('TABLE');
			gy.appendChild(gyt);

			var tg = _calmaker(function() {
				this._forwardpost = function(aa) {
					while (gyt.firstChild) gyt.removeChild(gyt.firstChild);

					var gytb = document.createElement('TBODY');
					gyt.appendChild(gytb);

					while (h2.firstChild)
						h2.removeChild(h2.firstChild);

					var s = localdate(aa._date);
					h2.appendChild(document.createTextNode(s));
					while (gytb.firstChild) gytb.removeChild(gytb.firstChild);
					_planrender(gytb, [[ aa._date, s, '91%', 'left', 1 ]]);
				};
			});
			gd.appendChild(tg);
			body.appendChild(gd);
			body.appendChild(gy);

			gy.style.paddingLeft = '4px';
			gy.style.paddingRight = '4px';
			window.setTimeout(function() {
				resizeHelper(function() {
					gy.style.marginRight = gd.offsetWidth + 'px';
				}, true);
			}, 10);
		} else {
			// draw a big month
			var table = _calmaker(function(tbody) {
				var tr = document.createElement('TR');
				var i;
				for (i = 0; i < 7; i++) {
					var td = document.createElement('TD');
					td.style.padding = '1px';
					td.style.cursor = 'default';
					td.style.textAlign='center';
					td.style.fontSize = '80%';
					td.style.border = '1px solid ' + COLOR.grayText;
					td.appendChild(document.createTextNode(window.dowstr[i]));
					tr.appendChild(td);
				}
				tbody.appendChild(tr);

				this.style.width = '80%';
				this._forwardpost = function(aa) {
					var s = localdate(aa._date);
					while (h2.firstChild) h2.removeChild(h2.firstChild);
					h2.appendChild(document.createTextNode(s));
				};
			}, function(jt) {
				var td = this.parentNode; // the td
				td.style.border = '1px solid ' + COLOR.grayText;
				td.setAttribute('WIDTH', '14%');
				td.setAttribute('VALIGN', 'top');
				td.style.overflow = 'hidden';
				td.style.width = '14%';
				this.style.height = '8ex';
				this.ondblclick = function() {
					config.prefs.calview = 'day';
					planview.inner_view();
				};
				var aa = this;
				aa.style.overflow = 'hidden';
				_planmonth(jt, function(md) {
					if (!md) return;
					var ad = md[ jt.getUTCDate() ]; 
					if (!ad || !ad.length) return;
					var ai;
					for (ai = 0; ai < ad.length && ai < 4; ai++) {
						if (window._labelhide[ _planobj_label(ad[ai]) ]) {
							continue;
						}
						var ag = document.createElement('DIV');
						ag.style.whiteSpace='nowrap';
						ag.style.overflow='hidden';
						ag.style.fontSize = '80%';
						_planstyle(ag, ad[ai], true);
						aa.appendChild(ag);
					}
				});
			});
			var gd = document.createElement('CENTER');
			gd.appendChild(table);
			body.appendChild(gd);
		}
	});
};
planview.view = function() {
	new_action(RSRC$('images/tools/stock_new-appointment.png'), function() {
		eventform();
	});

	document.title = 'netMail - Planner';
	ungrey$(tool(RSRC$('images/tools/stock_calendar-view-day.png'), 'Day', function() {
		config.prefs.calview = 'day';
		planview.inner_view();
	}));
	ungrey$(tool(RSRC$('images/tools/stock_calendar-view-work-week.png'), 'Week', function() {
		config.prefs.calview = 'week';
		planview.inner_view();
	}));
	ungrey$(tool(RSRC$('images/tools/stock_calendar-view-month.png'), 'Month', function() {
		config.prefs.calview = 'month';
		planview.inner_view();
	}));
	if (WANT('view_raw')) {
		tool(RSRC$('images/tools/stock_view-html-source.png'), 'View Source', _view_source);
	}
	planview.inner_view();
};
function _calmaker(flagf, f_tfn) {
	var nowdate = new Date();

	var nd;
	if (window._plan_time) nd = window._plan_time;
	else nd = nowdate;

	var ndate,nyear,nmonth;
	var pdate,pyear,pmonth;
	var dow,date,year,month;
	var pt;
	if (WANT('use_gmt')) {
		dow = nd.getUTCDay();
		year = nd.getUTCFullYear();
		month = nd.getUTCMonth();
		date = nd.getUTCDate();

		nyear = nowdate.getUTCFullYear();
		nmonth = nowdate.getUTCMonth();
		ndate = nowdate.getUTCDate();
		if (window._plan_time) {
			pt = window._plan_time;
			pyear = nd.getUTCFullYear();
			pmonth = nd.getUTCMonth();
			pdate = nd.getUTCDate();
		} else {
			pt = nowdate;
			pyear = nyear;
			pmonth = nmonth;
			pdate = ndate;
		}
	} else {
		dow = nd.getDay();
		year = nd.getFullYear();
		month = nd.getMonth();
		date = nd.getDate();

		nyear = nowdate.getFullYear();
		nmonth = nowdate.getMonth();
		ndate = nowdate.getDate();

		if (window._plan_time) {
			pt = window._plan_time;
			pyear = nd.getFullYear();
			pmonth = nd.getMonth();
			pdate = nd.getDate();
		} else {
			pt = nowdate;
			pyear = nyear;
			pmonth = nmonth;
			pdate = ndate;
		}
	}

	if (WANT('use_gmt')) {
		// back pt up 
		pt = new Date(pt.valueOf() - (pt.getUTCDay() * 86400000.0));
		pt.setUTCHours(0);pt.setUTCMinutes(0);pt.setUTCSeconds(0);pt.setUTCMilliseconds(0);
	} else {
		pt = new Date(pt.valueOf() - (pt.getDay() * 86400000.0));
		pt.setHours(0);pt.setMinutes(0);pt.setSeconds(0);pt.setMilliseconds(0);
	}

	var sw; { // calendar "starts" on day-of-week "sw"
		var sd = date;
		sw = dow;
		while (sd > 1) {
			sd--; sw--;
			if (sw < 0) sw = 6;
		}
	};
	// how many days in previous month?
	var sm;
	if (month == 0) sm = 31;
	else sm = _dayim(month-1,year);

	var tm = _dayim(month,year);

	// get starting position
	var cm = 1;
	var sj = sw; while (sj > 0) {
		sj--; sm--; cm--;
	}

	// start it off
	var table = document.createElement('TABLE');
	table._active  = undefined;

	var tbody = document.createElement('TBODY');
	var tr = document.createElement('TR');
	var td = document.createElement('TD');
	td.setAttribute('COLSPAN', '7');
	td.colspan = 7;
	table.appendChild(tbody);

	tbody.appendChild(tr);
	tr.appendChild(td);

	td.style.textAlign = 'center';
	td.style.fontWeight = 'bold';
	td.style.cursor = 'default';
	td.appendChild(document.createTextNode(monthstr[month]));

	if (flagf) apply$(table, flagf, tbody);

	// first row
	var i;
	window._was_plan_pick = undefined;
	var wvw = 0;
	while (cm <= tm) {
		wvw++;
		tr = document.createElement('TR');
		var fdow;
		for (i = 0; i < 7; i++) {
			td = document.createElement('TD');
			var um, uy=year;
			var ud;
			if (cm < 1) {
				um = month-1;
				if (um < 0) {
					um = 11;
					uy--;
				}
				ud = sm;
				sm++;
			} else if (cm > tm) {
				ud = (cm - tm);
				um = month+1;
				if (um == 12) {
					um = 0;
					uy++;
				}
			} else {
				um = month;
				ud = cm;
			}

			td.style.padding = '1px';
			td.style.cursor = 'default';
			td.style.textAlign='right';

			var aa = document.createElement('A');
			aa.tabIndex = -1;
			aa.style.textAlign='right';
			aa.style.textDecoration = 'none';
			aa.style.cursor = 'default';

			var rd = new Date(uy, um, ud, 0, 0, 0, 0);
			aa._date = rd;
			aa._cm = cm;
			aa._week = wvw;

			if (i == 0) fdow = rd;
			aa._fdow = fdow;

			if (table._weekview && fdow.valueOf() == pt.valueOf()) {
				BGCOLOR(td,COLOR.hilight);
				BGCOLOR(aa,COLOR.hilight);
				FGCOLOR(aa,COLOR.hilightText);
				aa.style.border = '1px solid ' + COLOR.hilight;

				if (!table._active)
					table._active = aa;

				if (ndate == ud && nmonth == um && nyear == uy) {
					aa._today = true;
				}

			} else if (!table._weekview && (pdate == ud && pmonth == um && pyear == uy)) {
				BGCOLOR(td,COLOR.hilight);
				BGCOLOR(aa,COLOR.hilight);
				FGCOLOR(aa,COLOR.hilightText);
				aa.style.border = '1px solid ' + COLOR.hilight;
				window._was_plan_pick = aa;
				if (ndate == ud && nmonth == um && nyear == uy) {
					aa._today = true;
				}

				table._active = aa;
			} else {
				if (cm < 1 || cm > tm) {
					FGCOLOR(aa,COLOR.grayText);
				} else {
					FGCOLOR(aa,COLOR.innerWindowText);
				}

				if (ndate == ud && nmonth == um && nyear == uy) {
					aa.style.border = '1px solid ' + COLOR.innerWindowText;
					aa._today = true;
				} else {
					aa.style.border = '1px solid ' + COLOR.innerWindow;
				}
			}

			aa.style.display='block';
			aa.href = nullhref();
			aa.onmouseover = _fix_status;
			aa.onclick = function(e) {
				e = E$(e);
				if (e) {
					noticex = e.clientX;
					noticey = e.clientY;
				}
				if (window._was_plan_pick && window._was_plan_pick == this)
					return PD$(e);

				if (table._weekview) {
					// alternate...
					var na = this;
					cs(table, 'A', function(f) {
						if (!f || !f._fdow) return;

						if (f._fdow.valueOf() == f._date.valueOf())
							table._active = f;

						if (na._week == f._week) {
							BGCOLOR(f.parentNode,COLOR.hilight);
							BGCOLOR(f,COLOR.hilight);
							FGCOLOR(f,COLOR.hilightText);
							f.style.border = '1px solid ' + COLOR.hilight;
						} else {
							BGCOLOR(f.parentNode,COLOR.innerWindow);
							BGCOLOR(f,COLOR.innerWindow);
							if (f._cm < 1 || f._cm > tm) {
								FGCOLOR(f,COLOR.grayText);
							} else {
								FGCOLOR(f,COLOR.innerWindowText);
							}
							if (f._today && f._today == true) {
								f.style.border = '1px solid '+ COLOR.innerWindowText;
							} else {
								f.style.border = '1px solid '+ COLOR.innerWindow;
							}
						}
					});
					window._plan_time = this._date;
					blur$();

					if (table._forwardpost)
						table._forwardpost(this);
	
					return PD$(e);
				}

				table._active = this;

				BGCOLOR(this.parentNode,COLOR.hilight);
				BGCOLOR(this,COLOR.hilight);
				FGCOLOR(this,COLOR.hilightText);
				this.style.border = '1px solid ' + COLOR.hilight;

				if (window._was_plan_pick) {
					var wp = window._was_plan_pick;
					BGCOLOR(wp.parentNode,COLOR.innerWindow);
					BGCOLOR(wp,COLOR.innerWindow);
					if (wp._cm < 1 || wp._cm > tm) {
						FGCOLOR(wp,COLOR.grayText);
					} else {
						FGCOLOR(wp,COLOR.innerWindowText);
					}
					if (wp._today && wp._today == true) {
						wp.style.border = '1px solid '+ COLOR.innerWindowText;
					} else {
						wp.style.border = '1px solid '+ COLOR.innerWindow;
					}
				}

				window._was_plan_pick = this;
				window._plan_time = this._date;
				blur$();

				if (table._forwardpost)
					table._forwardpost(table._active);

				return PD$(e);
			};
			aa.appendChild(document.createTextNode(""+ud));
			td.appendChild(aa);

			var zzf;
			if (f_tfn) {
				zzf = apply$(aa, f_tfn, rd);
			}

			if (zzf) {
				aa._fn = zzf;
			} else {
				aa._fn = function() { return undefined; };
			}

			cm++;
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
	}
	// setup space for legend
	tr = document.createElement('TR');
	td = document.createElement('TD');
	td.setAttribute('COLSPAN', '7');
	tr.appendChild(td);
	tbody.appendChild(tr);
	window.__pv2 = td;

	if (table._active && table._forwardpost)
		table._forwardpost(table._active);

	_plan_legend();

	return table;
}

function setupview(f) {
	coreview("setupview");
}
setupview.view = function() {
	// remove the toolbar contents
	while (TOOLBAR.firstChild) TOOLBAR.removeChild(TOOLBAR.firstChild);
	while (EXTOOL.firstChild) EXTOOL.removeChild(EXTOOL.firstChild);
	TOOLBAR._lastsep=undefined;
	firstaction$.active = undefined;

	var newset = {};
	for (i in default_pref) {
		newset[i] = WANT(i);
	}
	for (i = 0; i < window.mailboxes.length; i++) {
		var j = window.mailboxes[i];
		if (j.className) j = j.name;
		if (config.prefs && config.prefs['hidefol:'+j]) {
			newset['hidefol:'+j] = 1;
		}
	}
	function func_save() {
		var i;
		for (i in default_pref) {
			config.prefs[i] = newset[i];
		}
		for (i = 0; i < window.mailboxes.length; i++) {
			var j = window.mailboxes[i];
			if (j.className) j = j.name;
			config.prefs['hidefol:'+j] = newset['hidefol:'+j];
		}
		(function(ns) {
			httpmail.config.set.onerror = function() {
				status$('Could not update configuration!');
				unbusy$();
			};
			httpmail.config.set.onreply = function() {
				start$splash();
				notice$('Settings saved');
				unbusy$();
			};
			busy$();
			try {
				httpmail.config.set(config);
			} catch(e) {
				unbusy$();
			};
		})(config);
	}
	function func_undo() {
		start$splash();
		notice$('Settings reverted');
	}

	var saveme = tool(RSRC$('images/tools/stock_save.png'), 'Save Settings', func_save);
	var undome = tool(RSRC$('images/tools/stock_undo-history.png'), 'Cancel', func_undo);
	toolsep();

	var chpass = tool(RSRC$('images/tools/gnome-lockscreen.png'), 'Change Password',
			function() {
				var utext = document.getElementById('ux1');
				while (utext.firstChild) utext.removeChild(utext.firstChild);
				utext.appendChild(document.createTextNode("Old\xa0Password:"));

				utext = document.getElementById('ux2');
				while (utext.firstChild) utext.removeChild(utext.firstChild);
				utext.appendChild(document.createTextNode("New\xa0Password:"));

				utext = document.getElementById('ux0');
				if (utext && !utext._nox) {
					var a0 = document.createElement('tr');
					utext.parentNode.insertBefore(a0, utext.nextSibling);
					utext._nox=true;
					var az0 = document.createElement('td');
					az0.style.cursor = 'default';
					az0.setAttribute('valign', 'top');
					az0.appendChild(document.createTextNode('Confirm\xa0Password:'));
					while (a0.firstChild) a0.removeChild(a0.firstChild);
					a0.appendChild(az0);
					az0 = document.createElement('td');
					az0.setAttribute('valign','middle');
					var az1 = null;
/*@cc_on @*/
/*@if (1) {
  					az1 = document.createElement('<input type="password">');
}
@end @*/
					if (!az1) {
						az1 = document.createElement('input');
						az1.setAttribute('type','password');
					}

					az1.setAttribute('autocomplete','no');
					az1.setAttribute('name','np3');
					az1.id = 'np3';
					az1.name = 'np3';
					az1.style.width = '100%';
					az0.appendChild(az1);
					a0.appendChild(az0);
					a0 = document.getElementById('rs1');
					a0.rowspan='4';
					a0.setAttribute('rowspan','4');
					a0 = document.getElementById('rs2');
					a0.rowspan='4';
					a0.setAttribute('rowspan','4');
				}

				utext = document.getElementById('ux3');
				while (utext.firstChild) utext.removeChild(utext.firstChild);
				var a1 = document.createElement('INPUT');
				a1.type = 'button';
				a1.value = 'Cancel';
				a1.onclick = function() {
					opacity$(LAYOUT, 1.0);
					_login_animate();
				};
				utext.appendChild(a1);

				a1 = document.createElement('INPUT');
				a1.type = 'submit';
				a1.value = 'Change Password';
				a1.onclick = function(e) { 
					PD$(E$(e));
					try {
						var np1 = document.getElementById('np1').value;
						var np2 = document.getElementById('np2').value;
						var np3 = document.getElementById('np3').value;
						var xnp1 = document.getElementById('np1');
						var xnp2 = document.getElementById('np2');
						var xnp3 = document.getElementById('np3');
						xnp1.disabled=true;
						xnp2.disabled=true;
						xnp3.disabled=true;

						if (config && config['$user']) {
							var ac = document.cookie;
							var ass = 'AUTHORIZATION=' + BASE64(config['$user'] + ':' + np1);
							var j = ac.indexOf(ass);
							if (j != -1 && (ac.length == j+ass.length || ac.substr(j+ass.length, 1) == ';')) {
								// okay
							} else {
								window.alert("Password incorrect");
								xnp1.disabled=false;
								xnp2.disabled=false;
								xnp3.disabled=false;
								xnp1.focus();
								xnp1.select();
								return false;
							}
						}

						if (np2 != np3) {
							window.alert("Passwords do not match!");
							xnp1.disabled=false;
							xnp2.disabled=false;
							xnp3.disabled=false;
							xnp2.focus();
							xnp2.select();
							return false;
						}
						if (!confirm("Are you sure you want to change your password?")) {
							window.setTimeouot(function() {
								opacity$(LAYOUT, 1.0);
								_login_animate();
							}, 10);
							return false;
						}

						/* XXX
						 */
					} catch(e) {
						try {
							opacity$(LAYOUT, 1.0);
						} catch(e2) {};
						return false;
					};
					httpmail.config.setPassword.onerror = function(e) {
						try {
							opacity$(LAYOUT, 1.0);
						} catch(e2) {};
					};
					var r;
					try {
						r = httpmail.config.setPassword(np1,np2);
					} catch(e2) {};
					if (!r) {
						window.alert("Could not change password on server");
					} else {
						window.alert("Password changed successfully!");
					}
					try {
						opacity$(LAYOUT, 1.0);
					} catch(e2) {};
					try {
						_login_animate();
					} catch(e2) {};
					return false;
				};
				utext.appendChild(a1);

				a1 = document.getElementById('password');
				if (a1) {
					a1.disabled=false;
					a1.setAttribute('type', 'password');
					a1.value = '';
					a1.name = 'np2';
					a1.id = 'np2';
				} else {
					a1 = document.getElementById('np2');
					a1.disabled=false;
				}

				a1 = document.getElementById('np3');
				a1.disabled=false;

				a1 = document.getElementById('username');
				if (a1) {
					var aj1 = null;
/*@cc_on @*/
/*@if (1) {
  					aj1 = document.createElement('<input type="password">');
}
@end @*/
					if (!aj1) {
						aj1 = document.createElement('input');
						aj1.setAttribute('type','password');
					}
					a1.parentNode.insertBefore(aj1, a1);
					a1.parentNode.removeChild(a1);
					a1 = aj1;
					a1.disabled=false;
					a1.value = '';
					a1.name = 'np1';
					a1.id = 'np1';
				} else {
					a1 = document.getElementById('np1');
					a1.disabled=false;
				}


				var lb = document.getElementById('loginbox');
				lb.style.top = '0px';
				lb._pos = 0;
				lb._h = lb.offsetHeight;
				lb.style.backgroundColor = '';
				lb.style.visibility = 'visible';
/*@cc_on @*/
/*@if (1) {
				lb.runtimeStyle.visibility='visible';
}
@end @*/
				window.setTimeout(function() {
					opacity$(LAYOUT, 0.5);
					var a0x = document.getElementById('np1');
					a0x.focus();
					a0x.select();
				},90);
			});
	if (document.domain.toLowerCase() != 'demo.internetconnection.net') {
		ungrey$(chpass);
	}

	toolsep();
	document.title = 'netMail - Settings';

	if (TREELIST) {
		// this is a new view without a treelist entry...
		var nb = TREELIST.firstChild;
		while (nb) {
			if (nb.tagName && nb.tagName.toUpperCase() == 'A') {
				FGCOLOR(nb,COLOR.innerWindowText);
				BGCOLOR(nb,COLOR.innerWindow);
			}
			nb = nb.nextSibling;
		}
	}

	update_view3m(function(body) {
		BGCOLOR(body,COLOR.innerWindow);
		FGCOLOR(body,COLOR.innerWindowText);

		body.onclick = function() {
			var xtc = dom_autocomplete;
			if (xtc && xtc._boundto) {
				xtc.style.display='none';
				xtc._eatme=-1;
			}
		};

		var c1 = document.createElement('INPUT');
		var c2 = document.createElement('INPUT');

		function _cf() {
			var s = arguments[0];
			var d = document.createElement('SPAN');
			d.appendChild(document.createTextNode(s+' . . .'));
			d.style.cursor = 'default';
			d.style.fontWeight = 'bold';
			d.style.fontStyle = 'italic';
			d.style.borderBottom = '1px dotted ' + FIRST$(COLOR.innerWindow);
			d.style.marginTop = '4px';
			body.appendChild(d);

			var y = document.createElement('DIV');
			y.style.marginBottom = '16px';
			body.appendChild(y);

			var i;
			for (i = 1; i < arguments.length; i++) {
				var f = arguments[i];
				var z = document.createElement('DIV');
				z.style.paddingLeft = '16px';
				z.style.paddingRight = '34px';
				z.style.marginTop = '6px';
				if (f.data || f.tagName) {
					z.appendChild(f);
				} else {
					z.appendChild(f());
				}
				y.appendChild(z);
			}
			return y;
		}
		function _cf_bigtext(a,b) {
			var z = document.createElement('DIV');

			var d = document.createElement('LABEL');
			d.style.cursor = 'default';
			d.style.whiteSpace = 'nowrap';

			var f = newset[b];
			var y = textedit$(f, 7);
			y.onfocus = function(e) {
				var xtc = dom_autocomplete;
				if (xtc && xtc._boundto) {
					xtc.style.display='none';
					xtc._eatme=-1;
				}
			};
			y.name = b;
			y.onkeydown = y.onkeyup = y.oninput = y.onchange = function() {
				var n = this.name;
				newset[n] = this.value;
				c1.disabled=false; c2.disabled=false;
				ungrey$(saveme);
				ungrey$(undome);
				return true;
			};
			d.appendChild(document.createTextNode(a+': '));
			d.onclick = function() { y.focus(); };
			z.appendChild(d);
			z.appendChild(y);
			return z;
		}
		function _cf_text(a,b) {
			var z = document.createElement('DIV');

			var d = document.createElement('LABEL');
			d.style.cursor = 'default';
			d.style.whiteSpace = 'nowrap';

			var f = newset[b];
			var y = textedit$(f);
			y.onfocus = function(e) {
				var xtc = dom_autocomplete;
				if (xtc && xtc._boundto) {
					xtc.style.display='none';
					xtc._eatme=-1;
				}
			};
			y.name = b;
			z.disable = function() {
				y.disabled=true;
			};
			y.onkeydown = y.onkeyup = y.oninput = y.onchange = function() {
				var n = this.name;
				newset[n] = this.value;
				c1.disabled=false; c2.disabled=false;
				ungrey$(saveme);
				ungrey$(undome);
				return true;
			};
			d.appendChild(document.createTextNode(a+': '));
			d.onclick = function() { y.focus(); };
			z.appendChild(d);
			z.appendChild(y);
			return z;
		}
		function _cf_addr(t,b) {
			var z = document.createElement('DIV');

			var d = document.createElement('LABEL');
			d.style.cursor = 'default';

			var f = newset[b];
			var y = addrtextentry$(f);
			y._name = b;
			y._forwardpost = function(v) {
				var n = this._name;
				newset[n] = v;
				c1.disabled=false; c2.disabled=false;
				ungrey$(saveme);
				ungrey$(undome);
			};
			d.appendChild(document.createTextNode(t + ': '));
			d.onclick = function() { y.focus(); };
			z.appendChild(d);
			z.appendChild(y);
			return z;
		}
		function _cf_choice(t,a,sv, oc) {
			var z = document.createElement('DIV');

			var d = document.createElement('LABEL');
			d.style.cursor = 'default';

			var f = newset[a];
			var y = document.createElement('SELECT');
			y._name = a;
			y.onchange = y.onkeydown = y.onkeyup = function(e) {
				var n = this._name;
				e = E$(e);

				if (this.selectedIndex > -1) {
					var v = undefined;
					try {
						v = this.options[this.selectedIndex].value;
					} catch(ve) {};
					if (typeof v == 'undefined') return true;
					try {
						newset[n] = v;
						c1.disabled=false; c2.disabled=false;
						ungrey$(saveme);
						ungrey$(undome);
						if (oc) oc(v);
					} catch(ve) {};
				}
				return true;
			};
			var ni;
			for (ni = 0; ni < sv.length; ni++) {
				var oo = sv[ni];
				var oa = document.createElement('OPTION');
				if (typeof oo == 'string') {
					oa.appendChild(document.createTextNode(oo));
					oa.value = oo;
				} else if (oo.length == 2 && (typeof oo[0] == 'string' && typeof oo[1] == 'string')) {
					oa.appendChild(document.createTextNode(oo[1]));
					oa.value = oo[0];
				} else {
					apply$(y,oo,oa);
				}
				if (f == oa.value) {
					oa.setAttribute('SELECTED','selected');
					oa.setAttribute('CHECKED','checked');
				}
				y.appendChild(oa);
				if (f == oa.value) {
					(function(aox) {
						window.setTimeout(function() {
							y.selectedIndex = aox;
						},10);
					})(ni);
				}
			}
			d.appendChild(document.createTextNode(t + ': '));
			d.onclick = function() { y.focus(); };
			z.appendChild(d);
			z.appendChild(y);
			return z;
		}
		function _cf_bool(a,b, neg) {
			var z = document.createElement('DIV');

			var d = document.createElement('LABEL');
			d.style.cursor = 'default';

			var y = document.createElement('INPUT');
			y.type = 'checkbox';

			y.name = b;
			y.onchange = function() {
				var xtc = dom_autocomplete;
				if (xtc && xtc._boundto) {
					xtc.style.display='none';
					xtc._eatme=-1;
				}

				var n = this.name;
				if (neg) {
					newset[n] = this.checked ? 0 : 1;
				} else {
					newset[n] = this.checked ? 1 : 0;
				}
				c1.disabled=false; c2.disabled=false;
				ungrey$(saveme);
				ungrey$(undome);
				return true;
			};
			y.onclick = function() { 
				c1.disabled=false; c2.disabled=false;
				ungrey$(saveme);
				ungrey$(undome);
			};
			y.onfocus = function(e) {
				var xtc = dom_autocomplete;
				if (xtc && xtc._boundto) {
					xtc.style.display = 'none';
					xtc._eatme = -1;
				}
			};
			y.value = b;
			d.appendChild(document.createTextNode(a));
			d.onclick = function() { y.click(); };
			z.appendChild(y);
			z.appendChild(d);
			window.setTimeout(function() {
				if (newset[b]) {
					y.checked = neg ? false : true;
				} else {
					y.checked = neg ? true : false;
				}
			}, 10);
			return z;
		}

		var mytz = _mytz_offset();
		var Xa1 = _cf_text('My full name', 'my_name');
		var Xa2 = _cf_text('My email address', 'my_email');
		if (document.domain.toLowerCase() == 'demo.internetconnection.net'
		|| (config && config['cf_locked'])) {
			Xa1.disable();
			Xa2.disable();
		}
		_cf('About me', Xa1, Xa2,
			_cf_bool("Display date/time in GMT (Greenwich Mean Time) instead of local time (" + mytz + ")", 'use_gmt')
		);

		function _update_scheme_preview(f,v) {
			f.innerHTML = colorscheme_html$(v);
		}

		var schemebox = document.createElement('DIV');
		schemebox.className = 'right';
		schemebox.style.width = '123px';
		schemebox.style.paddingRight = '8px';

		_update_scheme_preview(schemebox, newset['colorscheme']);
		body.appendChild(schemebox);

		_cf('Display preferences',
			_cf_choice('Application font', 'font_app', [
					function(ao) {
						ao.style.fontStyle = 'italic';
						ao.value = '';
						ao.appendChild(document.createTextNode('Browser Default'));
					},
					[ 'serif', 'Serif' ],
					[ 'sans-serif', 'Sans-Serif' ]
				]),
			_cf_choice('Message-read font', 'font_read', [
					function(ao) {
						ao.style.fontStyle = 'italic';
						ao.value = '';
						ao.appendChild(document.createTextNode('Browser Default'));
					},
					[ 'serif', 'Serif' ],
					[ 'sans-serif', 'Sans-Serif' ],
					[ 'monospace', 'Monospace' ]
				]),
			_cf_choice('Color scheme', 'colorscheme', [
					function(ao) {
						ao.style.fontStyle = 'italic';
						ao.value = '';
						ao.appendChild(document.createTextNode('Browser Default'));
					},
					'Redmond',
					'Chicago',
					'Boston',
					'Oxford',
					'Palo Alto',
					'Hotdog Stand'
				], function(tcz) {
					_update_scheme_preview(schemebox, tcz);
				})
		);
		var br = document.createElement('BR');
		br.style.clear = 'both';
		body.appendChild(br);

		var ag = document.createElement('DIV');
		inset$(ag);
		var ay = _cf('Display folders',ag);
		ag.style.height = '12ex';
		ag.style.overflow = 'auto';
		var i;
		for (i = 0; i < window.mailboxes.length; i++) {
			var n = window.mailboxes[i];
			if (n.className) n = n.name;
			var aa = _cf_bool(n, 'hidefol:'+n, true);
			if (n == 'Contacts' || n == 'Planner' || n == 'Trash' || n == 'INBOX'
			|| n == 'Sent Items') {
				// builtin-protected
				aa.firstChild.disabled=true;
			}
			ag.appendChild(aa);
		}
		var az = document.createElement('DIV');
		az.style.marginTop = '2px';
		az.style.paddingLeft = '16px';
		az.style.marginBottom = '8px';
		az.appendChild(document.createTextNode("Unchecked folders above will not be visible."));
		ay.appendChild(az);

		var al1 = _cf_bool('Flash the browser/window icon', 'alert_icon');
		var al2 = _cf_bool('Play an alert sound', 'alert_sound');

		_cf('When new messages arive', al1, al2);
		if (can_java$() != true) al2.disabled=true;
/*@cc_on @*/
/*@if (1) {
  		al1.disabled=true;
}
@end @*/
		_cf('When I read a message',
			_cf_bool('Block images/keep the sender from tracking message read', 'blockimages'));
		_cf('When I send a message',
			_cf_bool('Copy it to my Sent Items', 'copysent'),
			_cf_bool('Add the recipients to my address book', 'auto_contacts'),
			_cf_bool('Warn me if there are any misspellings', 'auto_spell'),
			_cf_addr('Always CC the following address', 'auto_cc'),
			_cf_addr('Always BCC the following address', 'auto_bcc'),
			_cf_bigtext('Include my signature', 'edit_sig'));

//_cf_bool("Check spelling as I type", "edit_spell"),
		_cf("When I'm composing a message",
			_cf_bool("Let me enter an explicit CC address", "edit_cc"),
			_cf_bool("Let me enter an explicit BCC address", "edit_bcc")
			);

		var az = document.createElement('DIV');
		if (typeof newset['_le_autoedit'] == 'undefined') {
			newset['_le_autoedit'] = '0';
		} else if (typeof newset['_le_autoedit'] < 0) {
			newset['_le_autoedit'] = '0';
		} else if (typeof newset['_le_autoedit'] > 4) {
			newset['_le_autoedit'] = '0';
		}
		function _fixup_az() {
			var nz = parseInt(newset['_le_autoedit']);
			while (az.firstChild) az.removeChild(az.firstChild);
			az.appendChild(_cf_bigtext('Autoreply #' + (nz+1), 'autotext_'+nz));
		}
		_cf("Autoreplies", 
				_cf_choice('Edit autoreply', '_le_autoedit', [
						[ '0', 'Autoreply #1' ],
						[ '1', 'Autoreply #2' ],
						[ '2', 'Autoreply #3' ],
						[ '3', 'Autoreply #4' ],
						[ '4', 'Autoreply #5' ]
					], function(v) {
						newset['_le_autoedit'] = v;
						_fixup_az();
					}), az);
		_fixup_az();

		var Xa3 = _cf_text("Enable experimental features", "unstable");
		if (document.domain.toLowerCase() == 'demo.internetconnection.net') {
			Xa3.disable();
		}

		_cf("Advanced Options",
			_cf_bool("Edit messages using VI (experienced UNIX users)", "edit_vi"),
			_cf_bool("Let me choose to view the raw message source", "view_raw"),
			Xa3);

		var ce = document.createElement('CENTER');

		c1.type = 'button';
		c1.onclick = function(e) {
			e=E$(e);
			if (e) {
				noticex = e.clientX;
				noticey = e.clientY;
			}
			
			func_save();
			return PD$(e);
		};
		c1.value = 'Save Settings';
		c1.disabled=true;

		c2.type = 'button';
		c2.onclick = function(e) {
			e=E$(e);
			if (e) {
				noticex = e.clientX;
				noticey = e.clientY;
			}
			
			func_undo();
			return PD$(e);
		};
		c2.value = 'Cancel';
		c2.disabled=true;

		ce.appendChild(c1);
		ce.appendChild(c2);
		c1.style.margin = '2px';
		c2.style.margin = '2px';
		ce.style.paddingBottom = '8px';
		body.appendChild(ce);
	});
};


function MAILTO(s,m) {
	if (!m)m=this;
	var as = {};
	if (s.indexOf('?') > -1) {
		var j = s.indexOf('?');
		var x = s.substr(j+1,s.length-j).split(/[&;]/);
		var i;
		for (i in x) {
			var kv = i.split("=");
			if (kv.length != 2) continue;
			var k = (kv[0]||'').toLowerCase();
			if (k == 'subject') {
				as.title = kv[1]||'';
			} else if (k == 'cc') {
				as._cc = kv[1]||'';
			} else if (k == 'bcc') {
				as._bcc = kv[1]||'';
			}
		}
		s = s.substr(0,j);
	}
	as._mailto = s;
	as.FORM = composer;
	composer(as);
}
function contacteditor(n) {
	if (window._name) {
		// ooh, okay
		window._composer_style = n;
		coreview('contacteditor');
	} else {
		viewwindow$('contacteditor', function(g) {
			g._composer_style = n;
		});
	}
}
function _vcard_viewedit(div, oob, hasmail, isedit, tail) {
	var mailbox = oob._folder;
	var message = MSGPART$(oob._object_base);
	function _whead(tb, k, v, ev) {
		var tk = document.createElement('TD');
		var tv = document.createElement('TD');
		var te = document.createElement('TD');
		var tr = document.createElement('TR');
		tr.appendChild(tk);
		tr.appendChild(tv);
		tr.appendChild(te);
		tb.appendChild(tr);
		tk.appendChild(document.createTextNode(k+':'));
		tk.style.fontWeight = 'bold';
		// XXX
		tk.style.color = '#666';
		tk.style.whiteSpace = 'nowrap';
		tk.style.cursor = 'default';
		tk.style.verticalAlign = 'top';
		tk.style.textAlign = 'right';
		tk.style.paddingLeft = '16px';
		tv.style.width = '80%';

		if (!isedit) {
			tv.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
		}

		if (v.data || v.tagName) {
			tv.appendChild(v);
		} else if (isedit) {
			var ay = v||'';
			v = textedit$(ay);
			tv.appendChild(v);
		} else {
			tv.appendChild(document.createTextNode(v));
		}
		if (ev) {
			te.appendChild(ev);
		}
		return v;
	}
	httpmail.message.fetchVCARD.onreply = function(obj) {
		oob._container = obj;

		var mlm = undefined;
		if (obj.role && obj.role.match && obj.role.match(/MAILING-?LIST/i)) {
			mlm = true;
		}

		if (!hasmail) {
			hasmail = window._vg_hack_compose;
			if (hasmail && hasmail.parentNode && hasmail.previousSibling) {
				// awesome
			} else {
				window._vg_hack_compose = undefined;
				hasmail = undefined;
			}
		}


		var table = document.createElement('TABLE');
		var tbody = document.createElement('TBODY');
		table.appendChild(tbody);

		var fn = VC(obj.fn||'');
		var email;
		var h2 = document.createElement('DIV');
		h2.style.fontWeight = 'bold';
		h2.style.fontSize = '150%';
		FGCOLOR(h2,COLOR.grayText);
		h2.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
		h2.style.marginBottom = '4px';
		h2.style.paddingLeft = '4px';
		if (isedit && fn=='') {
			if (mlm) {
				h2.appendChild(document.createTextNode('New Address Group'));
			} else {
				h2.appendChild(document.createTextNode('New Contact'));
			}
		} else if (fn == '') {
			if (mlm) {
				h2.appendChild(document.createTextNode('Untitled Address Group'));
			} else {
				h2.appendChild(document.createTextNode('Untitled Contact'));
			}
		} else {
			h2.appendChild(document.createTextNode(fn));
		}
		div.appendChild(h2);
		div.appendChild(table);

		if (mlm) {
			if (isedit) {
				_whead(tbody, 'Display Name', VC(obj.fn||'')).bindTo(function(value) {
					obj.fn = value;
					while (h2.firstChild) h2.removeChild(h2.firstChild);
					if (value == '') {
						h2.appendChild(document.createTextNode('New Address Group'));
					} else {
						h2.appendChild(document.createTextNode(value));
					}
				}).AC('vCard.DisplayName');
			} else {
				_whead(tbody, 'Display Name', VC(obj.fn||''));
			}
		} else if (isedit) {
			var sj = (obj.n||'').split(";");
			while (sj.length < 3) {
				_array_insert(sj, '');
			}
			var a2 = document.createElement('BUTTON');
			var a3 = textedit$(fn);
			a2.appendChild(document.createTextNode('Take from name'));
			a2.onclick = function() {
				a3.value = SQUEEZE$(sj[sj.length-2] + ' ' + sj[sj.length-1] +' ' + sj[sj.length-3]);
				obj.fn = a3.value;
				while (h2.firstChild) h2.removeChild(h2.firstChild);
				if (a3.value == '') {
					h2.appendChild(document.createTextNode('New Contact'));
				} else {
					h2.appendChild(document.createTextNode(a3.value));
				}
			};
			a3.bindTo(function(value) {
				obj.fn = value;
				while (h2.firstChild) h2.removeChild(h2.firstChild);
				if (value == '') {
					h2.appendChild(document.createTextNode('New Contact'));
				} else {
					h2.appendChild(document.createTextNode(value));
				}
			}).AC('vCard.DisplayName');
			_whead(tbody, 'First Name', sj[sj.length-2]).bindTo(function(value) {
				sj[sj.length-2] = value;
				obj.n = sj.join(";");
			}).AC('vCard.FirstName').focus();
			_whead(tbody, 'Last Name', sj[sj.length-3]).bindTo(function(value) {
				sj[sj.length-3] = value;
				obj.n = sj.join(";");
			}).AC('vCard.LastName');
			_whead(tbody, 'Middle Initial', sj[sj.length-1]).bindTo(function(value) {
				sj[sj.length-1] = value;
				obj.n = sj.join(";");
			}).AC('vCard.MiddleName');
			_whead(tbody, 'Display as', a3, a2);
		}

		if (isedit) {
			_whead(tbody, 'Organization', VC(obj.org||'')).bindTo(function(value) {
				obj.org = value;
			}).AC('vCard.Company');
		} else if (obj.org) {
			if (!obj.org) obj.org = '';
			if (obj.org.indexOf(';') > -1) {
				var tm = document.createElement('DIV');
				var so = obj.org.split(/;/);
				var i;
				for (i = 0; i < so.length; i++) {
					if (i) tm.appendChild(document.createElement('BR'));
					tm.appendChild(document.createTextNode(VC(so[i])));
				}
				_whead(tbody, 'Organization', tm);
			} else {
				_whead(tbody, 'Organization', VC(obj.org));
			}
		}

		email = obj['email;internet'];
		if (!email) email = obj.email;
		if (mlm) {
			//xxx
			if (isedit) {
				var ax = _addrlist(TRIM$(email||'', " \r\n,"));
				var i;
				var outs = '';
				for (i = 0; i < ax.length; i++) {
					var ag = ax[i];
					if (outs != '') outs += '\n';
					outs += '"' + QC(ag[1]) + '" <' + QC(ag[0]) + '>';
				}
				var z = textedit$(outs||'', 12);
				_whead(tbody, 'Email Addresses', z).bindTo(function(value) {
					var tv = SQUEEZE$(value, "\r\n", ", ");
					obj['email;internet'] = tv;
					obj.email = tv;
				});
			} else if (email) {
				_whead(tbody, 'Email Addresses', addrexpand(email||'',true));
			}

		} else if (isedit) {
			_whead(tbody, 'Email Address', email||'').bindTo(function(value) {
				obj.email = value;
				obj['email;internet'] = value;
				if (hasmail) {
					if (value == '') {
						greyout$(hasmail);
					} else {
						ungrey$(hasmail);
					}
				}
			}).AC('vCard.Email');
		} else if (email) {
			_whead(tbody, 'Email Address', addrexpand(email||'',true));
		}

		if (mlm) {
			// do I even want anything here?

		} else if (isedit) {
			if (!obj.adr) obj.adr='';
			var so = obj.adr.split(/;/);
			while (so.length < 5) {
				_array_insert(so, '');
			}
			var n = so.length;
			var str = '';
			var i;
			for (i = 0; i < n - 5; i++) {
				str += so[i]+'\n';
			}
			var y = textedit$(str||'', 3);
			_whead(tbody, 'Destination Indicator', y).bindTo(function(value) {
				var aq = new Array();
				aq[0] = so[n-5];
				aq[1] = so[n-4];
				aq[2] = so[n-3];
				aq[3] = so[n-2];
				aq[4] = so[n-1];

				var az = (value||'').split("\n");
				for (n = 0; n < az.length; n++) {
					so[n] = az[n];
				}
				so[n] = aq[0]; n++;
				so[n] = aq[1]; n++;
				so[n] = aq[2]; n++;
				so[n] = aq[3]; n++;
				so[n] = aq[4]; n++;
				so.length = n; // trim if necessary
				obj.adr = so.join(";");
			}).AC('vCard.Department');
			_whead(tbody, 'Street Address', so[n-5]).bindTo(function(value) {
				so[n-5] = value;
				obj.adr = so.join(";");
			}).AC('vCard.Business.StreetAddress');
			_whead(tbody, 'City/Locality', so[n-4]).bindTo(function(value) {
				so[n-4] = value;
				obj.adr = so.join(";");
			}).AC('vCard.Business.City');
			_whead(tbody, 'State/Province', so[n-3]).bindTo(function(value) {
				so[n-3] = value;
				obj.adr = so.join(";");
			}).AC('vCard.Business.State');
			_whead(tbody, 'Postal/ZIP Code', so[n-2]).bindTo(function(value) {
				so[n-2] = value;
				obj.adr = so.join(";");
			}).AC('vCard.Business.Zipcode');
			_whead(tbody, 'Country', so[n-1]).bindTo(function(value) {
				so[n-1] = value;
				obj.adr = so.join(";");
			}).AC('vCard.Business.Country');

		} else if (obj.adr) {
			var so = obj.adr.split(/;/);
			while (so.length < 4) {
				_array_insert(so, '');
			}
			var dm = document.createElement('DIV');
			var i;
			var any = false;
			for (i = 0; i < so.length - 4; i++) {
				if (so[i] || any) {
					if (any) dm.appendChild(document.createElement('BR'));
					dm.appendChild(document.createTextNode(VC(so[i])));
					any=true;
				}
			}
			if (any) dm.appendChild(document.createElement('BR'));
			dm.appendChild(document.createTextNode(VC(so[so.length-4] + ", " + so[so.length-3] + " " + so[so.length-2])));
			dm.appendChild(document.createElement('BR'));
			dm.appendChild(document.createTextNode(VC(so[so.length-1])));
			_whead(tbody, 'Postal Address', dm);
		}
		if (obj.tel || isedit) {
			var ay = _whead(tbody, 'Telephone Number', VC(obj.tel||''));
			if (isedit) ay.bindTo(function(value) {
				obj.tel = value;
			}).AC('vCard.Business.Phone');
		}

		if (obj.caluri || isedit) {
			var izt;
			var yy;
			if (_cal_issub(obj.caluri)) {
				obj.__old_caluri = obj.caluri;
				izt = true;
			}else {
				izt = undefined;
			}
			if (isedit && UNSTABLE('planner')) {
				yy = document.createElement('SPAN');

				var ay = document.createElement('INPUT');
				ay.type = 'checkbox';
				ay._checked = izt ? true : false;
				ay.checked = ay._checked;
				window.setTimeout(function() {
					ay.checked = ay._checked;
				}, 10);
				ay.onchange = function() {
					(function(yz) {
						window.setTimeout(function() {
							obj.__cal_subscribe = yz.checked ? true : undefined;
						},1);
					})(this);
				};
				obj.__cal_subscribe = izt;
				var al = document.createElement('LABEL');
				al.style.cursor = 'default';
				al.appendChild(document.createTextNode('Subscribe'));
				linkstatus$(al, 'Toggle subscribe of web calendar');
				al._ay = ay;
				al.onclick = function(e) {
					var ny = this._ay;
					if (ny.checked) {
						ny.checked = false;
						obj.__cal_subscribe = undefined;
					} else {
						ny.checked = true;
						obj.__cal_subscribe = true;
					}
				};

				yy.appendChild(ay);
				yy.appendChild(al);
			} else if (izt) {
				yy = imgsrc$(imgtag$(), RSRC$('images/stock_web-calendar.png'), 16,16);
				yy.setAttribute('VALIGN','bottom');
			} else {
				yy = undefined;
			}

			var ay = _whead(tbody, 'Calendar URL', VC(obj.caluri||''), yy);
			if (isedit) {
				ay.bindTo(function(value) {
					obj.caluri = value;
				});
			}
		}

		if (obj.fburl || isedit) {
			var ay = _whead(tbody, 'Free/Busy URL', VC(obj.fburl||''));
			if (isedit) ay.bindTo(function(value) {
				obj.fburl = value;
			});
		}

		if (isedit) {
			var z = textedit$(obj.notes||'', mlm?5:12);
			_whead(tbody, 'Notes', z).bindTo(function(value) {
				obj.notes = value;
			});
		} else if (obj.notes) {
			_whead(tbody, 'Notes', obj.notes);
		}

		if (tail) tail(div);
	};
	if (oob._container) {
		httpmail.message.fetchVCARD.onreply(oob._container);
	} else if (message) {
		httpmail.message.fetchVCARD(mailbox,message);
	} else {
		httpmail.message.fetchVCARD.onreply(oob);
	}
}
contacteditor.view = function(object) {
	var as = window._composer_style;

	if (object) {
		// got everything we need
	} else if (as) {
		object = as;
	} else {
		// zero (compose fresh)
		object = {};
	}

	while (TOOLBAR.firstChild) TOOLBAR.removeChild(TOOLBAR.firstChild);
	while (EXTOOL.firstChild) EXTOOL.removeChild(EXTOOL.firstChild);
	TOOLBAR._lastsep=undefined;
	firstaction$.active = undefined;

	var saveme_func = function() {
		var zz;
		var data = new Object();
		for (zz in object._container) {
			if (zz == '__old_caluri') continue;
			if (zz == '__cal_subscribe') continue;
			if (typeof object._container[zz] == 'string') {
				data[zz] = object._container[zz];
			}
		}

		// unsubscribe old calendar at some point in the near future...
		// opener will run reload contacts in a moment, thus subscribing
		if (object.__old_caluri) {
			if (object.__old_caluri != data.caluri && object.__old_caluri != '') {
				_cal_unsub([ object.__old_caluri ]);
			}
		} else if (object._container.__old_caluri) {
			if (object._container.__old_caluri != data.caluri && object._container.__old_caluri != '') {
				_cal_unsub([ object._container.__old_caluri ]);
			}
		}
		if (data.caluri && (object.__cal_subscribe || object._container.__cal_subscribe)) {
			_cal_sub([ data.caluri ]);
		}

		if (object._object_base) {
			_zapcache('Contacts');
			var path = '/Contacts/:' + MSGPART$(object._object_base);
			try {
				httpmail.contacts.update.onerror=false$;
				httpmail.contacts.update(path, data);
				window.close();
			} catch(e) {
				window.alert("There may have been a problem updating the contact\n");
			};
		} else {
			_zapcache('Contacts');
			try {
				httpmail.contacts.update.onerror=false$;
				httpmail.contacts.create(data);
				window.close();
			} catch(e) {
				window.alert("There may have been a problem updating the contact\n");
			};
		}
	};
	firstaction$(ungrey$(tool(RSRC$('images/tools/stock_save.png'), 'Save Changes', saveme_func)));

	document.title = 'netMail - Contact Editor';
	if (window._current_folder) {
		object._folder = 'Contacts';
	} else {
		object._folder = window._current_folder;
	}

	update_view3m(function(body) {
		_vcard_viewedit(body, object, undefined, true, function(xb) {
			var ce = document.createElement('CENTER');
			var c1 = document.createElement('INPUT');
			var c2 = document.createElement('INPUT');

			c1.type = 'button';
			c1.onclick = function(e) {
				e=E$(e);
				if (e) {
					noticex = e.clientX;
					noticey = e.clientY;
				}
				
				saveme_func();
				return PD$(e);
			};
			c1.value = 'Save Contact';
	
			c2.type = 'button';
			c2.onclick = function(e) {
				window.close();
				return PD$(E$(e));
			};
			c2.value = 'Cancel';

			ce.appendChild(c1);
			ce.appendChild(c2);
			c1.style.margin = '2px';
			c2.style.margin = '2px';
			ce.style.paddingBottom = '8px';
			ce.style.clear = 'both';
			xb.appendChild(ce);
		});
	});
};

function _sigstr() {
	if (WANT('edit_sig') == '') return '';
	return "\n--\n" + WANT('edit_sig') + '\n';
}

function composer_op(n) {
	if (n == 0) {
		composer({});

	} else if (!window._name) {
		viewwindow$('composer', function(g) {
			g._composer_style = n;
		});

	} else if (n == 1 || n == 2 || n == 4) {
		var mailbox = window._current_folder;
		var viewrel = folview[mailbox];
		var message = MSGPART$(viewrel[window.__selected_object]);

		if (n == 4) {
			// resume
			httpmail.message.resume.onerror = false$;
			httpmail.message.resume.onreply = function(set) {
				composer(set);
			};
			httpmail.message.resume(mailbox, message);

		} else {
			// reply or reply-to-all
			httpmail.message.reply.onreply = function(set) {
				if (n == 2) {
					// reply-to-all
					if (WANT('edit_cc')) {
						set._cc = set._extra_cc;
						set._cc = notmetoo(set._cc);
					} else {
						set._mailto += ', ' + set._extra_cc;
						set._mailto = notmetoo(set._mailto);
					}
				}
				// add an extra line to make top-replies easier
				set._body = _sigstr() + "\n" + set._body;
				composer(set);
			};
			httpmail.message.reply(mailbox, message);
		}
	} else if (n == 3) {
		// forward
		var col = COL();
		if (col.length == 0) return;
		httpmail.message.forwardSet.onreply = function(set) {
			composer(set);
		};
		httpmail.message.forwardSet(col);
	}
}
function composer(n) {
	
	if (window._name) {
		// ooh, okay
		window._composer_style = n;
		coreview('composer');
	} else {
		viewwindow$('composer', function(g) {
			g._composer_style = n;
		});
	}
}
function _attachment_popf(sign, popup) {
	popup.append(RSRC$('images/stock_delete.png'), 'Detach', function(z) {
		var aa = z[0];
		var object = z[1];
		var na = [];
		var i;
		for (i = 0; i < object._attached.length; i++) {
			if (i != aa._attachid)
				na[na.length] = object._attached[i];
		}
		object._attached = na;
		aa.parentNode.removeChild(aa);
		if (na.length == 0) {
			var ac = z[2];
			// remove attachment bar
			ac.parentNode.parentNode.parentNode.removeChild(ac.parentNode.parentNode);
		}
		notice$('Removed attachment');
	});
	popup.append(RSRC$('images/stock_undo.png'), 'Cancel');
};

function _attachment_tailf(f) {
	if (f) f(this);
}
function _spellcheck(not_e, closure, t, sp) {
	t = STRIP$(_spellcheck.bodyobject?_spellcheck.bodyobject.value:'');

	if (!_spellcheck.active) {
		if (closure) closure(t);
		return;
	}

	var aa = _spellcheck.active;
	_spellcheck.active=undefined;
	_spellcheck._finished=true;
	greyout$(aa);

	var x;
	var qre = /^On (Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 0123][0-9] [ 0-2][0-9]:[ 0-6][0-9]:[ 0-6][0-9] [0-9][0-9][0-9][0-9]*, [^\n]* wrote:/;
	var re = /^[a-zA-Z\'-]+/;
	var words = [];
	var owords = [];
	var sawnl = true;
	for (x = 0; x < t.length;) {
		var rest = t.substr(x,t.length-x);
		var az = re.exec(rest);
		if (!az) {
			if (t.substr(x, 1) == '\n') {
				sawnl = true;
			} else if (sawnl) {
				var tc = t.substr(x,2);
				if (tc == '> ') {
					// skip entire line (quoted)
					x++; while (x < t.length && t.substr(x,1) != '\n') x++;
					sawnl = true;
					continue;
				}
				if (tc == '--') {
					// skip signature
					var sigstr = '\n' + WANT('edit_sig');
					if (t.substr(x+2,sigstr.length) == sigstr) {
						// skip entire signature
						x += sigstr.length+2;
						sawnl = undefined; // but will probably be reset!
						continue;
					}
					// fall through
				}
				sawnl = undefined;

			} else {
				sawnl = undefined;
			}

			x++;
			continue;
		}
		if (az[0] && az[0] != '') {
			if (az[0] == 'On') {
				var ay = qre.exec(rest);
				if (ay && (t.length == (ay[0].length+x) || t.substr(ay[0].length+x, 1) == '\n')) {
					x += ay[0].length;
					sawnl = true;
					continue;
				}
			}


			var inp = false;
			if (config.wordlist && config.wordlist.length) {
				var j;
				for (j = 0; j < config.wordlist.length; j++) {
					if (config.wordlist[j] == az[0]) {
						inp=true;
						break;
					}
				}
			}
			if (inp != true) {
				words[words.length] = [ x, az[0] ];
				owords[owords.length] = az[0];
			}
		}
		x += (az[0].length+1);
	}
	var fxn = (function(la) {
		return function() {
			_spellcheck._finished=undefined
			_spellcheck.active=la;
			ungrey$(la);
		};
	})(aa);

	var set;
	try {
		httpmail.spellcheck.onerror=false$;
		set = httpmail.spellcheck(owords);
	} catch(e) {
		set = undefined;
	}

	if (typeof set == 'undefined') {
		window.alert("Spellcheck engine isn't responding.\nSpellcheck has been cancelled!");
		fxn();
		return;
	}

	var todo = [];
	for (i = 0; i < set.length; i++) {
		var sg = set[i];
		var wv = words[i];
		if (sg.length == 1 && sg[0] == wv[1]) continue;
		todo[todo.length] = [ false, wv[0], wv[1], sg ];
	}


	if (todo.length == 0) {
		_spellcheck._finished=true;
		if (!closure) {
			window.alert("No mispellings found!");
			fxn();
		} else {
			fxn();
			closure(t);
		}
		return;
	}

	// okay, do popup...
	sp = _util_window();
	sp.document.title = 'Check Spelling';

	sp.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	sp.document.writeln('<?xml version="1.0" encoding="UTF-8"?>');
	var cw=FIRST$(COLOR.window);
	sp.document.writeln('<html><head><title>Check Spelling</title><style>select,option{background:'+cw+';color:'+COLOR.windowText+';}');
	sp.document.writeln('button{width:9em;}');
	sp.document.writeln('</style><script>');
	sp.document.writeln('function pagewidth() { return window.innerWidth || document.documentElement.clientWidth; }');
	sp.document.writeln('function pageheight() { return window.innerHeight || document.documentElement.clientHeight; }');
	sp.document.writeln('function setmeup() {');
	sp.document.writeln("var ax = document.all?document.all['ax']:document.getElementById('ax');");
	sp.document.writeln("var ay = document.all?document.all['ay']:document.getElementById('ay');");
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln("if(ax && ay && az) {");
	sp.document.writeln("ax.style.width = ((pagewidth()-(ax.offsetLeft*2))-(ay.offsetWidth+8))+'px';");
	sp.document.writeln("az.style.height = (((pageheight()-(ax.offsetTop)))-8)+'px';");
	sp.document.writeln('}');
	sp.document.writeln('window.onresize=setmeup;');
	sp.document.writeln('window.focus();');
	sp.document.writeln('};');
	sp.document.writeln('window._sug_for = function(c) {');
	sp.document.writeln('window.__current_word = c;');
	sp.document.writeln("var au = document.all?document.all['au']:document.getElementById('au');");
	sp.document.writeln("if (au) { while (au.firstChild) au.removeChild(au.firstChild); au.appendChild(document.createTextNode(c)); }");
	sp.document.writeln('};');
	sp.document.writeln('window._clear_select = function() {');
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln('if (az) { az.disabled=false;while (az.firstChild)az.removeChild(az.firstChild); az.selectedIndex=-1;}');
	sp.document.writeln('};');
	sp.document.writeln('window._get_select = function() {');
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln('if (az && az.selectedIndex > -1) return az.options[az.selectedIndex].value');
	sp.document.writeln('return undefined;');
	sp.document.writeln('};');
	sp.document.writeln('window._insert_select = function(t) {');
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln('if (az) {');
	sp.document.writeln('var o = document.createElement("OPTION");o.value=t;o.appendChild(document.createTextNode(t));');
	sp.document.writeln('o.ondblclick=_replace;az.appendChild(o);');
	sp.document.writeln('}');
	sp.document.writeln('};');
	sp.document.writeln('window._select_first = function() {');
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln('if (az) {');
	sp.document.writeln('az.selectedIndex=0;');
	sp.document.writeln('}');
	sp.document.writeln('};');
	sp.document.writeln('window._no_select = function(why) {');
	sp.document.writeln("var az = document.all?document.all['az']:document.getElementById('az');");
	sp.document.writeln('if (az) {');
	sp.document.writeln('_insert_select(why);az.firstChild.style.fontStyle="italic";az.disabled=true;');
	sp.document.writeln('}');
	sp.document.writeln('};');
	sp.document.writeln('</'+'script><body onload="window.focus();setmeup();window._loadwords();" onmouseup="window._sync_select();"><div style="font-weight:bold;background:'+cw+';color:'+COLOR.windowText+';border:1px solid '+COLOR.windowText+';padding:4px;">Suggestions for: "<span id="au"></span>"</div>');
	sp.document.writeln('<p style="padding:0px;"><div id="ax" style="position:absolute;bottom:4px;left:4px;"><select disabled="disabled" size="12" style="width:100%;" id="az" onmouseup="window._sync_select();" onchange="window._sync_select();"></select></div>');
	sp.document.writeln('<div id="ay" style="position:absolute;bottom:4px;right:4px;">');
	sp.document.writeln("<button onclick=\"if (confirm('Are you sure you want to add '+String.fromCharCode(34)+window.__current_word+String.fromCharCode(34)+' to your dictionary?')) _add_word();\">Add Word</button><br/>");
	sp.document.writeln('<br/>');
	sp.document.writeln('<button class="aw" onclick="_ignore();">Ignore</button><br/>');
	sp.document.writeln('<button class="aw" onclick="_ignore(1);">Ignore all</button><br/>');
	sp.document.writeln('<br/>');
	sp.document.writeln('<button class="aw" onclick="_replace();">Replace</button><br/>');
	sp.document.writeln('<button class="aw" onclick="_replace(0,1);">Replace All</button><br/>');
	sp.document.writeln('<br/>');
	sp.document.writeln("<button onclick=\"_change(prompt('What do you want to replace '+String.fromCharCode(34)+window.__current_word+String.fromCharCode(34)+' with?', window.__current_word));\">Change to...</button><br/>");

	sp.document.writeln('</div></p></body></html>');

	sp._words = t;
	sp._origwords = sp._words;
	sp._todo = todo;
	sp._work_on = function(n) {
		var todo = sp._todo[n];
		var wl = todo[3];
		sp._sug_for(todo[2]); // just for fun
		_spellcheck._current_word = todo[2];
		_spellcheck._current_wordnum = n;

		sp._set_select( todo[1], todo[1]+(todo[2].length) );
		if (wl.length == 0) {
			sp._clear_select();
			sp._no_select("No suggestions");
		} else {
			sp._clear_select();
			var j;
			for (j = 0; j < wl.length; j++) {
				if (wl[j] == '') continue;
				sp._insert_select(wl[j]);
			}
			sp._select_first();
		}

		_spellcheck._finished=undefined;
	};
	sp._work_next = function() {
		var n = _spellcheck._current_wordnum;
		var tz = sp._todo[n];
		if (typeof tz != 'undefined') {
			tz[0] = true;
			n++;
			while (n < sp._todo.length) {
				tz = sp._todo[n];
				if (tz[0] && tz[0] == true) {
					n++;
				} else {
					sp._work_on(n);
					return;
				}
			}
			n = 0;
			while (n < sp._todo.length) {
				tz = sp._todo[n];
				if (tz[0] && tz[0] == true) {
					n++;
				} else {
					sp._work_on(n);
					return;
				}
			}
		}
		// all done!
		_spellcheck._finished=true;
		if (!closure) {
			try { window.focus(); } catch(e) {};
			window.alert("No more mispellings found");
		} else {
			closure(sp._words);
			closure = undefined;
		}

		_spellcheck.active=aa;
		ungrey$(aa);

		sp.close();
	};
	sp._loadwords = function() {
		sp._sug_for('');
		sp._no_select("Loading...");
		sp._work_on(0);
	};
	sp._add_word = function() {
		sp._sync_select();

		if (!config.wordlist) config.wordlist = [];
		config.wordlist[ config.wordlist.length ] = _spellcheck._current_word;
		//xxx
		httpmail.config.set.onerror = function() {
			sp._ignore(1);
		};
		httpmail.config.set.onreply = function() {
			sp._ignore(1);
		};
		try {
			httpmail.config.set(config);
		} catch (e) {
			sp._ignore(1);
		};
	};
	sp._ignore = function(all) {
		if (all) {
			var i;
			for (i = 0; i < sp._todo.length; i++) {
				var j = sp._todo[i];
				if (j[0] && j[0] == true) continue;
				if (j[2] == _spellcheck._current_word) {
					// set ignore
					j[0] = true;
				}
			}
		}
		sp._work_next();
	};
	sp._fix_word = function(n, j) {
		var tz = sp._todo[n];
		var yt = tz[1];
		sp._sync_replace(yt, yt+(tz[2].length), j );
		tz[0]=true;
		yt += j.length;

		var dt = j.length - tz[2].length;

		var i;
		// fix pointers...
		for (i = 0; i < sp._todo.length; i++) {
			tz = sp._todo[i];
			if (tz[1] >= yt) tz[1] += dt;
		}
	};
	sp._replace = function(noe,all) {
		var s = sp._get_select();
		if (all) {
			var i;
			for (i = 0; i < sp._todo.length; i++) {
				var j = sp._todo[i];
				if (j[0] && j[0] == true) continue;
				if (j[2] == _spellcheck._current_word) {
					sp._fix_word(i, s);
				}
			}
		} else {
			sp._fix_word(_spellcheck._current_wordnum, s);
		}
		sp._work_next();
	};
	sp._change = function(j) {
		if (j && j != '' && j != _spellcheck._current_word) {
			sp._fix_word(_spellcheck._current_wordnum, j);
			sp._work_next();
		}
		window.setTimeout(function() {
			sp._sync_select();
		},10);
	};

	sp._set_select = function(s,f) {
		if (!_spellcheck.bodyobject)return;
		_spellcheck._select_start=s;
		_spellcheck._select_finish=f;
		setselection$(_spellcheck.bodyobject, s, f);
	};
	sp._sync_select = function() {
		var s = _spellcheck._select_start||0;
		var f = _spellcheck._select_finish||0;
		setselection$(_spellcheck.bodyobject, s, f);
	};
	sp._sync_replace = function(s,f,c) {
		var t = sp._words||'';
		t = t.substr(0,s) + c + t.substr(f,t.length-f);
		sp._words = t;
		try {
			if (_spellcheck.bodyobject) _spellcheck.bodyobject.value = t;
		} catch(e_ignored) {};
	};

	onclose$(sp, function() {
		if (_spellcheck) {
			_spellcheck.active=aa;
			if (aa && _spellcheck.active) ungrey$(_spellcheck.active);
			var wl = sp._words;
			(function(aza) {
				 window.setTimeout(function() {
					if (closure && (_spellcheck._finished || confirm("You have cancelled the spelling check\nDo you want to send this message anyway?"))) {
						try { closure(wl); } catch(e) {
							//window.alert("TRY FAIL?"+e.message);
						};
					}
				}, 10);
			})(wl);
		}
	});
	sp.document.close();
	window.setTimeout(function() {
		try {
			sp.focus();
		} catch(e) {};
	}, 10);
	try {
		sp.focus();
	} catch(e) {};
}
function _tryadd_contacts(obj) {
	var str = obj._mailto||'';
	str += ', ' + (obj._cc||'');
	str += ', ' + (obj._bcc||'');
	str = TRIM$(str, " ,");
	var ax = _addrlist(str);
	var i;
	for (i = 0; i < ax.length; i++) {
		var aa = ax[i];
		var hit = undefined;;
		map_contactsByAddress(aa[0], function() { hit = true; });
		map_contactsByAddress(aa[1], function() { hit = true; });
		if (hit) return;

		// add some contacts...
		try {
			var na = {};
			na.fn = aa[1] || aa[0];
			na.email = aa[0];
			httpmail.contacts.create.onerror=false$;
			httpmail.contacts.create(na);
		} catch(e){};
	}
}
composer.view = function(object) {
	var as = window._composer_style;

	if (object) {
		// got everything we need
		if (as && (typeof as.FORM != 'undefined'))
			object.FORM=as.FORM;

	} else if (as && (typeof as.FORM != 'undefined' || typeof as._mailto != 'undefined')) {
		// slipp
		object = as;

	} else if (as >= 0 && as <= 4) {
		composer_op(as); // eek...
		return;
	} else {
		// zero (compose fresh)
		object = {};
	}

	if (TOOLBAR) {
		while (TOOLBAR.firstChild) TOOLBAR.removeChild(TOOLBAR.firstChild);
		while (EXTOOL.firstChild) EXTOOL.removeChild(EXTOOL.firstChild);
		TOOLBAR._lastsep=undefined;
		firstaction$.active = undefined;
	}

	var form;
	if (object.FORM) {
		form = window[object.FORM];
	} else {
		form = composer; // eh?
	}
	if (!form) form = composer;
	if (!form) form = {};

	var text = object._body||'';
	if (!form.noSignature) {
		if (text == '') {
			text = _sigstr();
			object._body = text;
		}
	}

	var subject = textedit$(object.title||'');
	var to = undefined;
	var cc = undefined;
	var bcc = undefined;

	if (!form.noAddressing) {
		to = addrtextentry$(object._mailto||'');

		if (form.noCC) {
			object._cc = undefined;
		} else {
			if (WANT('auto_cc')) {
				var s1 = (object._cc||'') + ', ' + WANT('auto_cc');
				object._cc = LTRIM$(s1, " ,");
			}
			cc = addrtextentry$(object._cc||'');
		}
		if (form.noBCC) {
			object._bcc = undefined;
		} else {
			if (WANT('auto_bcc')) {
				var s2 = (object._bcc||'') + ', ' + WANT('auto_bcc');
				object._bcc = LTRIM$(s2, " ,");
			}
			bcc = addrtextentry$(object._bcc||'');
		}
	}

	var attachcontainer = document.createElement('DIV');
	function _attachme(i) {
		var o = object._attached[i];
		var aa = document.createElement('A');
		aa.tabIndex = -1;
		aa.style.display='block';
		aa._attachid = i;
		aa.href = nullhref();
		aa.onclick = function(e) {
			apply$(_attachment_popf, _drop_may_popup, e, [aa,object,attachcontainer], _attachment_tailf);
		};
		if (COLOR.windowLinks) {
			FGCOLOR(aa,COLOR.windowLinks);
		}
		linkstatus$(aa,o.displayname||'');

		var img = imgsrc$(imgtag$(), _mimeicon('unknown'), 16,16);
		aa.appendChild(img);
		aa.appendChild(document.createTextNode(o.displayname));
		attachcontainer.appendChild(aa);
	}

	var i;
	if (object._attached) {
		for (i = 0; i < object._attached.length; i++) {
			_attachme(i);
		}
	}

	var sendop;
	if (form.onsend) {
		sendop = form.onsend;
	} else if (form.onSend) {
		sendop = form.onSend;
	} else {
		sendop = function() {
			if (WANT('auto_contacts')) {
				_tryadd_contacts(this);
			}

			try {
				var r;
				httpmail.send.onerror=false$;
				if (WANT('copysent')) {
					r = httpmail.send(this, '/Sent Items');
				} else {
					r = httpmail.send(this);
				}
				if (r) {
					return true;
				} else {
					window.alert("Cannot deliver a message with no recipients...");
					try {
						if (to) to.focus();
						if (cc) cc.focus();
						if (bcc) bcc.focus();
					} catch(e2) {};
				}
			} catch(e) {
				window.alert("There was trouble sending the message, please try again... "+e);
			};
			return undefined;
		};
	}

	var actually_send = function(bodytxt) {
		object._from = '"' + QC(WANT('my_name')) + '" <' + QC(WANT('my_email')) + '>';
		object._body = STRIP$(bodytxt);
		object.title = subject.value;

		if (config && config['cf_force_signature']) {
			object._body = object._body + "\n\n" + config['cf_force_signature'];
		}

		if (!form.noAddressing) {
			object._mailto = to.value;
			if (cc) object._cc = cc.value;
			if (bcc) object._bcc = bcc.value;
		}

		if (form.gather) apply$(object, form.gather);

		try { window._parentWindow.focus(); } catch(e) {};
		//XXX
		var ox,oy,ow,oh;
		try {
			ox = window.screenX;
			oy = window.screenY;
			ow = window.innerWidth || window.width;
			oh = window.innerHeight || window.height;
		} catch(e2) {};
		try {
			if (ox || oy) window.moveTo(6000,6000);
			if (ow && oh) window.resizeTo(100,100);
		} catch(e2) {};

		if (apply$(object, sendop)) {
			try {
				if (object._onsend) {
					// may have done more
					var f = object._onsend[1];
					if (f && f != '')
						_zapcache(f);
				}
			} catch(e2) {}; // gibberish protect
			try {
				window.moveTo(ox,oy);
			} catch (e2) {};
			try {
				window.resizeTo(ow,oh);
			} catch (e2) {};
			window.close();
		}
		try {
			window.moveTo(ox,oy);
		} catch (e2) {};
		try {
			window.resizeTo(ow,oh);
		} catch (e2) {};
	};

	if (form.noAddressing) {
		firstaction$(ungrey$(tool(RSRC$('images/tools/stock_save.png'), 'Save Now', function() {
			var subjectstr = (form.subjectString || 'Subject').toLowerCase();
			if (subject.value == '' && !confirm("Are you sure you want to save this with an empty " + subjectstr + "?")) {
				return;
			}
			if (form.body) {
				actually_send(object._body);
	
			} else if (WANT('edit_vi')) {
				object._marked_up = 1;
				if (window.top._vi_force_copyout)
					window.top._vi_force_copyout();
				actually_send(object._body);
			} else if (WANT('auto_spell')) {
				object._marked_up = 0;
				_spellcheck.message = object;
				_spellcheck(0, actually_send);
			} else {
				object._marked_up = 0;
				actually_send(STRIP$(_spellcheck.bodyobject.value));
			}
		})));
	} else {
		firstaction$(ungrey$(tool(RSRC$('images/tools/stock_mail-send.png'), 'Send Now', function() {
			var subjectstr = (form.subjectString || 'Subject').toLowerCase();
			if (subject.value == '' && !confirm("Are you sure you want to send a message with an empty " + subjectstr + "?")) {
				return;
			}

			if (form.body) {
				actually_send(object._body);
	
			} else if (WANT('edit_vi')) {
				object._marked_up = 1;
				if (window.top._vi_force_copyout)
					window.top._vi_force_copyout();
				actually_send(object._body);
			} else if (WANT('auto_spell')) {
				object._marked_up = 0;
				_spellcheck.message = object;
				_spellcheck(0, actually_send);
			} else {
				object._marked_up = 0;
				actually_send(STRIP$(_spellcheck.bodyobject.value));
			}
		})));
	}

	if (!form.noAddressing && !form.noDraftSupport) {
		ungrey$(tool(RSRC$('images/tools/stock_save.png'), 'Save Draft', function() {
			object._from = '"' + QC(WANT('my_name')) + '" <' + QC(WANT('my_email')) + '>';
			object._mailto = to.value;
			if (cc) object._cc = cc.value;
			if (bcc) object._bcc = bcc.value;
			if (WANT('edit_vi')) {
				if (window.top._vi_force_copyout) window.top._vi_force_copyout();
			} else {
				object._body = _spellcheck.bodyobject.value;
			}
			object.title = subject.value;
			object._marked_up = 0;
			var r;
			try {
				httpmail.mailbox.post.onerror=false$;
				r = httpmail.mailbox.post("Drafts", object);
				if (r) {
					_zapcache('Drafts');
					window.close();
				} else {
					window.alert("There was trouble saving the message, please try again... "+e);
				}
			} catch(e) {
				window.alert("There was trouble saving the message, please try again... "+e);
			};
		}));
	}

	if (form.toolbar) {
		form.toolbar();
	}
	
	var edithead = function(head) {
		head.style.width='100%';
		head.parentNode.style.width='100%';

		if (form.fromString) {
			if (form.fromString != '') {
				_head(head, form.fromString, WANT('my_name'));
			}
		} else {
			_head(head, "From", WANT('my_name'));
		}

		if (!form.noAddressing) {
			if (form.recipString) {
				_head(head, form.recipString, to);
			} else {
				_head(head, "To", to);
			}
			if (WANT('edit_cc')||object._cc||form.recipCCString) {
				_head(head, form.recipCCString||"Cc", cc);
			}
			if (WANT('edit_bcc')||object._bcc||form.recipBCCString) {
				_head(head, form.recipBCCString||"Bcc", bcc); 
			}
		}

		if (form.subjectString) {
			_head(head, form.subjectString, subject);
		} else {
			_head(head, 'Subject', subject);
		}

		if (form.headers) {
			var nj;
			for (nj = 0; nj < form.headers.length; nj++) {
				var sna = form.headers[nj];
				if (typeof sna == 'string') {
					var za = textedit$(object[sna]||'');
					(function(zqa) {
						za.bindTo(function(v) {
							object[zqa] = v;
						});
					})(sna);
					_head(head, sna, za);
				} else {
					apply$(object, sna, function(k,v) {
						_head(head,k+'',v);
					});
				}
			}
		}

		if (!form.noStorage) {
			if (object._attached && object._attached.length > 0) {
				_head(head, 'Attached', attachcontainer);
			}
	
			var at_b = tool(RSRC$('images/tools/stock_attach.png'), 'Attach', function() {
				var att = _util_window();
				att.document.title = 'netMail Attach File';
				greyout$(at_b);
	
				att.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
				att.document.writeln('<?xml version="1.0" encoding="UTF-8"?>');
				att.document.writeln('<html><body onload="window.focus();"><form target="iframe" action="upload.cgi/' + att.name + '" method="POST" enctype="multipart/form-data" onsubmit="x_x_d();">');
				att.document.writeln('<iframe name="iframe" style="position:absolute;top:0;left:-42px;width:4px;height:7px;" src="javascript:\'\'"></iframe>');
				att.document.writeln('<div style="font-weight:bold;background:'+FIRST$(COLOR.window)+';padding:4px;border:1px solid '+COLOR.windowText+';">Attaching a file ...</div>');
				att.document.writeln('<p style="padding:4px;">');
				att.document.writeln("If the file you're attaching is large, you may want to compress the file with <a href=\"http://www.info-zip.org/\" target=\"_new\">a popular file compression tool</a> before uploading it to netMail.");
				att.document.writeln('</p><p style="padding:4px;">');
				att.document.writeln('Select the file you wish to attach using the file-picker below. If you do not want to attach a file, select <i>Cancel</i> instead.</p>');
				att.document.writeln('<center><input onchange="window.setTimeout(function(){document.forms[0].submit();},10);" type="file" name="file" /><input type="button" onclick="window.close();" value="Cancel"/></center>');
				att.document.writeln('<script>function d() { window.setTimeout(function() { document.form.elements[0].disabled=true; document.form.elements[1].disabled=true; },10); }</'+'script>');
				att.document.writeln('</form></body></html>');
				onclose$(att, function() {
					ungrey$(at_b);
				});
				att['_finish'+att.name] = function(fn, orig_fn) {
					ungrey$(at_b);
	
					window.setTimeout(function() {
						att.close();
					},10);
	
					var nx = {};
					nx.displayname = orig_fn;
					nx.internalname = fn;
					if (!object._attached) object._attached = [];
					var j = object._attached.length;
					object._attached[j] = nx;
					_attachme(j);
					if (j == 0) {
						_head(head, "Attached", attachcontainer);
					}
				};
				window.setTimeout(function() {
					att.document.close();
				}, 10);

				try {
					att.focus();
				} catch(e) {};
			});
			if (document.domain.toLowerCase() != 'demo.internetconnection.net') {
				ungrey$(at_b);
			}
		}
	
		if (!form.body) {
			if (!WANT('edit_vi')) {
				var sp_b = tool(RSRC$('images/tools/stock_spellcheck.png'), 'Check Spelling', _spellcheck);
				_spellcheck.active=sp_b;
				_spellcheck.message = object;
				ungrey$(sp_b);
			} else {
				_spellcheck.active=undefined;
				_spellcheck.message = undefined;
			}
		}
	};

	if (form.title) {
		var s = form.title;
		if (typeof s == 'string') {
			document.title = 'netMail - ' + s;
		} else {
			document.title = 'netMail - ' + s();
		}
	} else {
		document.title = 'netMail - New Message';
	}

	if (form.body) {
		update_view3m(function(bd) { apply$(object, form.body, bd); }, edithead);
		
	} else if (WANT('edit_vi')) {
		update_view3m(function(body) {
			body.style.width='100%';
			body.setAttribute('frameborder', '0');
	
			window.top._nooverlay = true;
			window.top._emacsen = false;
			window.top._nospelling = !WANT('auto_spell');
			window.top._vi_send_body = object._body;
			window.top._palette = [ COLOR.innerWindowText, COLOR.innerWindow ];
	
			body.src = 'edit.htm';

			window._vi_recv_finished = function(y) {
				if (y && y == true) {
					object._marked_up = 1;
					if (window.top._vi_force_copyout)
						window.top._vi_force_copyout();
					actually_send(object._body);
				} else {
					// good bye
					window.close();
				}
			};
			window._vi_recv_copyout = function(v) {
				object._body = v;
				text = v;
			};
			window._vi_recv_focus = function() {
				if (dom_autocomplete) {
					dom_autocomplete.style.display = 'none';
				}
			};
			body._pass_focus = function() {
				if (window.top._vi_pass_focus) window.top._vi_pass_focus();
			};
		}, edithead, 'IFRAME');
	} else {
		update_view3m(function(body) {
			body.style.border = 'none';
			body.style.margin = '0px';
			body.onkeydown = body.onkeypress = body.onkeyup = function(e) {
				e = E$(e);
				if (!e) return true;
				PP$(e);
				var nt = e.type;

				if (this._timeout) {
					window.clearTimeout(this._timeout);
					this._timeout = undefined;
				}
/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
  if (nt == 'keydown') nt='keypress';
  else if (nt == 'keypress') nt = '';
}
@end @*/
				if (e.which == 9 || e.keyCode == 9 || e.charCode == 9) {
					if (e.modifiers || e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)
						return true;
					if (nt == 'keypress') {
						if (e.preventDefault) e.preventDefault();
						e.cancelBubble=true;
						textedit$insert(body, "\t");
						return false;
					}
				}
				if (nt == 'keyup') {
					try {
						_gstr(body);
						if (typeof body._selstart != 'undefined'
						&& typeof body._selend != 'undefined'
						&& body._selend == body._selstart) {
							body._cxpos = body._selstart;
						}
					} catch(e) {};
				}
				return true;
			};
			body.onblur = function(e) {
				if (this._timeout) return true;
				this._timeout = window.setTimeout(function() {
					dom_keyholder = undefined;
					this._timeout = undefined;
				},20);
				return true;
			};
			body.onfocus = function(e) {
				if (this._timeout) {
					window.clearTimeout(this._timeout);
					this._timeout = undefined;
				}
				var xtc = dom_autocomplete;
				if (xtc && xtc._boundto) {
					xtc.style.display='none';
					xtc._eatme=-1;
				}

				if (dom_keyholder) return true;
				dom_keyholder = true;

				this._timeout = window.setTimeout(function() {
					if (typeof body._cxpos == 'undefined') {
						setselection$(body, 0,0);
					} else {
						setselection$(body, body._cxpos, body._cxpos);
					}
				},10);
				return true;
			};
			body.onmousedown = body.onmouseup = body.onclick = function(e) {
				PP$(e);
				if (this._timeout) {
					window.clearTimeout(this._timeout);
					this._timeout = undefined;
				}
				return true;
			};

			body.value = text;
			_spellcheck.bodyobject = body;
			if (object._mailto && object._mailto != '' && object.title && object.title != '') {
				body.focus();
				window.setTimeout(function() {
					setselection$(body, 0,0);
				},10);
			}

			function _ihelper(n,bt) {
				textedit$insert(bt, WANT('autotext_' + n));
				bt.focus();
			}

			(function(xbt) {
				toolsep();
				var i;
				var zf = function() { _ihelper(this._x, xbt); };
				for (i = 0; i < 5; i++) {
					var zs = WANT('autotext_'+i);
					if (zs == '') continue;

					var tl = tool('', (i+1), zf);
					tl._x = i;
					tl.setAttribute('ACCESSKEY', ''+(i+1)+'');
					tl.title = zs;
					tl.setAttribute('title',tl.title);
					ungrey$(tl);
				}
			})(body);
		}, edithead, 'TEXTAREA');
	}
	if (typeof to != 'undefined' && (!object._mailto || object._mailto == '')) {
		to.focus();
	} else if (!object.title || object.title == '') {
		subject.focus();
	}
};


var _dragables = [];
function _drop_may_popup(e, col, target) {
	e = E$(e);
	PD$(e);

	while (POPLIST.firstChild) POPLIST.removeChild(POPLIST.firstChild);
	POPLIST._count=0;
	POPLIST.append = function(imgsrc,text, fn) {
		POPLIST._count++;
		var cg = document.createElement('A');
		cg.tabIndex = -1;
		cg.style.display = 'block';
		cg.style.cursor = 'default';
		FGCOLOR(cg,COLOR.menuText);
		BGCOLOR(cg,COLOR.menu);

		cg.style.paddingLeft = '1px';
		cg.style.paddingRight = '4px';
		cg.style.paddingTop = '2px';
		cg.style.paddingBottom = '2px';
		cg.style.textDecoration = 'none';

		cg.appendChild(imgsrc$(imgtag$(), imgsrc, 16,16));
		var span = document.createElement('SPAN');
		span.style.paddingLeft='2px';
		span.appendChild(document.createTextNode(text));
		cg.appendChild(span);

		cg._fn = fn;
		cg.onclick = function() {
			(function(xfn) {
				window.setTimeout(function() {
					apply$(col, target, xfn);
				}, 12);
			})(this._fn);
			POPLIST.style.display = 'none';
			blur$();
			return false;
		};
		cg.href=nullhref();
		cg.onmouseover = function() {
			_fix_status();
			BGCOLOR(this,COLOR.hilight);
			FGCOLOR(this,COLOR.hilightText);
			return true;
		};
		cg.onmouseout = function() {
			BGCOLOR(this,COLOR.menu);
			FGCOLOR(this,COLOR.menuText);
			return true;
		};
		POPLIST.appendChild(cg);
		return this;
	};
	noticex = e.clientX;
	noticey = e.clientY;

	var zfn = this;
	apply$(col, zfn, target, POPLIST);
	if (POPLIST._count == 0) {
		window.setTimeout(function() {
			apply$(col, target);
		}, 12);
	} else {
		POPLIST.style.position = 'absolute';
		POPLIST.style.display = 'block';
	
		var pw = POPLIST.offsetWidth+2;
		var px = e.clientX - parseInt(pw/2);
		if (px < 0) px = 0;
		if (px + pw >= pagewidth()) {
			px = pagewidth()-pw;
		}
		var ph = POPLIST.offsetHeight+2;
		var py = e.clientY - parseInt(ph/2);
		if (py < 0) py = 0;
		if (py + ph >= pageheight()) {
			py = pageheight()-ph;
		}
		POPLIST.style.top = py+'px';
		POPLIST.style.left = px+'px';
		POPLIST.style.zIndex = '5';
	}
	
	return false;
}



function dragsource$(o,f) {
	var sf = function(x, y) {
		var i, gx;
		if (!window._drag) {
			window.__selected_object = this._row;

			var col = COL();
			if (col.length > 1) {
				imgsrc$(DRAG_IMAGE, RSRC$('images/gtk-dnd-multiple.png'), 32,32);
			} else {
				imgsrc$(DRAG_IMAGE, RSRC$('images/gtk-dnd.png'), 32,32);
			}

			DRAG_IMAGE.style.cursor = 'default';
			for (i = 0; i < _dragables.length; i++) {
				gx = _dragables[i][1];
				if (!gx) gx = {};
				if (!gx.can) gx.can = true$;
				if (gx == f) {
					_dragables[i][2] = false;
				} else if (gx.can(col)) {
					_dragables[i][2] = true;
					gx = _dragables[i][0];
					_aso(gx);
					gx._px2 = gx._px+gx.offsetWidth;
					gx._py2 = gx._py+gx.offsetHeight;
				} else {
					_dragables[i][2] = false;
				}
			}
		}
		DRAG_IMAGE.style.left = (x-16) + 'px';
		DRAG_IMAGE.style.top = (y-16) + 'px';
		if (window._last_drag_target) {
			var lg = window._last_drag_target[0];
			if (x >= lg._px && x <= lg._px2 && y >= lg._py && y <= lg._py2) return;
			lg.style.borderTop = lg._old_borderTop;
			lg.style.borderLeft = lg._old_borderLeft;
			lg.style.borderRight = lg._old_borderRight;
			lg.style.borderBottom = lg._old_borderBottom;
		}
		for (i = 0; i < _dragables.length; i++) {
			if (_dragables[i][2] == false) continue;

			gx = _dragables[i][0];
			if (x < gx._px || x > gx._px2) continue;
			if (y < gx._py || y > gx._py2) continue;

			gx._old_borderTop = gx.style.borderTop;
			gx._old_borderLeft = gx.style.borderLeft;
			gx._old_borderRight = gx.style.borderRight;
			gx._old_borderBottom = gx.style.borderBottom;

			dotted$(gx);

			window._last_drag_target = _dragables[i]
			return;
		}
		window._last_drag_target = undefined;
	};
	sf.mouseup = function(e) {
		DRAG_IMAGE.style.left = '-42px';
		DRAG_IMAGE.style.top = '42px';
		if (window._last_drag_target) {
			var lg = window._last_drag_target[0];
			var lf = window._last_drag_target[1];
			window._last_drag_target = undefined;

			// restore styling
			lg.style.borderTop = lg._old_borderTop;
			lg.style.borderLeft = lg._old_borderLeft;
			lg.style.borderRight = lg._old_borderRight;
			lg.style.borderBottom = lg._old_borderBottom;
			apply$(f, _drop_may_popup, e, COL(), lf);
		}
	};
	drag$(o,sf);
}
function dragtarget$(o,f) {
	_dragables[_dragables.length]=[o,f,false];
}

function _kh(e) {
try { /* msie treats failure as a hint to stop using the keyhandlers...
	 */

	if (dom_keyholder) return true;

	e=E$(e);
	if (!e) return true;
	var k;
	if (e.keyCode) k = e.keyCode;
	else if (e.which) k = e.which;
	else return true;

	var mod;
	if (e.modifiers)mod=e.modifiers; else mod=0;

	var shift
	if (e.shiftKey || (mod & 4)) shift=true;

	if ((!e.DOM_VK_UP && (k==30||k==38||k==57373)) || (e.DOM_VK_UP && e.DOM_VK_UP==k)) {
		if (e.charCode && e.charCode == e.keyCode) return true;

		if (dom_autocomplete && !dom_autocomplete._active) {
			if (e._upev) return true;
			window.setTimeout(function() {
				if (dom_autocomplete && dom_autocomplete._eatme > -1) {
					dom_autocomplete.focus();
					if (dom_autocomplete.selectedIndex <= 0)
						dom_autocomplete.selectedIndex=0;
				}
			}, 10);
			return true;
		} else if (dom_autocomplete) {
			if (e._upev) return true;
			if (dom_autocomplete.selectedIndex < 1) {
				window.setTimeout(function() {
					if (dom_autocomplete && dom_autocomplete._boundto) {
						dom_autocomplete._boundto.focus();
					}
				}, 10);
			}
			return true;
		} else {
			if (e._upev) return true;
			if (!window._current_view) return true;
			if (window._current_view != 'list') return true;
			if (!shift) {
				if (mod || e.altKey || e.ctrlKey || e.metaKey) return true;
			}
			if (window.__selected_object > 0) {
				_listview_motion(shift, window.__selected_object - 1);
				return false;
			}
		}

	} else if (k == 47) {
		// slash
		if (e.charCode && e.charCode != 47) return true;
		if (dom_autocomplete) return true;
		if (!window._current_view) return true;
		if (window._current_view != 'list') return true;
		if (!window._tb_opened) return true;
		window.setTimeout(function(e) {
			if (window._tb_opened) {
				var popd = window._tb_opened;
				if (popd._textbox && popd.parentNode)
					popd._textbox.focus();
			}
		},10);
		return false;

	} else if (k == 91 || k == 93) {
		if (e.charCode && e.charCode != 91 && e.charCode != 93) return true;
		if (dom_autocomplete) return true;
		if (!window._current_view) return true;
		if (window._current_view != 'list') return true;
		if (shift || mod || e.altKey || e.ctrlKey || e.metaKey) return true;

		var mailbox = window._current_folder;
		if (!folview[mailbox]) return true;

		var viewrel = folview[mailbox];
		var mdata = undefined;
		if (folcache[mailbox]) {
			mdata = folcache[mailbox];
		}

		var i = window.__selected_object;
		if (k == 91) {
			i--;
			for (; i >= 0; i--) {
				if (i < 0) break;
				if (mdata && typeof mdata[ viewrel[i] ] != 'undefined'
				&& typeof mdata[ viewrel[i] ].flags != 'undefined') {
					if (mdata[ viewrel[i] ].flags.indexOf('S') == -1) break;
					continue;
				}
				if (!viewrel[i].match(/\/[^\/:]*:2,[A-R]*S/)) {
					break;
				}
			}
			if (i < 0) {
				i = viewrel.length-1;
				for (; i >= window.__selected_object; i--) {
					if (mdata && typeof mdata[ viewrel[i] ] != 'undefined'
					&& typeof mdata[ viewrel[i] ].flags != 'undefined') {
						if (mdata[ viewrel[i] ].flags.indexOf('S') == -1) break;
						continue;
					}
					if (!viewrel[i].match(/\/[^\/:]*:2,[A-R]*S/)) {
						break;
					}
				}
			}
		} else {
			i++;
			for (; i < viewrel.length; i++) {
				if (mdata && typeof mdata[ viewrel[i] ] != 'undefined'
				&& typeof mdata[ viewrel[i] ].flags != 'undefined') {
					if (mdata[ viewrel[i] ].flags.indexOf('S') == -1) break;
					continue;
				}
				if (!viewrel[i].match(/\/[^\/:]*:2,[A-R]*S/)) {
					break;
				}
			}
			if (i == viewrel.length) {
				for (i = 0; i < window.__selected_object; i++) {
					if (mdata && typeof mdata[ viewrel[i] ] != 'undefined'
					&& typeof mdata[ viewrel[i] ].flags != 'undefined') {
						if (mdata[ viewrel[i] ].flags.indexOf('S') == -1) break;
						continue;
					}
					if (!viewrel[i].match(/\/[^\/:]*:2,[A-R]*S/)) {
						break;
					}
				}
			}
		}
		_listview_motion(0,i);
		return false;

	} else if (k == 65) { // alt+a (select all)
		if (dom_autocomplete) return true;
		if (e._upev) return true;
		if (mod || e.altKey || e.ctrlKey || e.metaKey) {
			if (!window._current_view) return true;
			if (window._current_view != 'list') return true;
			if (window._current_folder && window._current_folder != '') {
				var md = folsize[window._current_folder];
				var i;
				window._select_group = {};
				for (i = 0; i < md; i++) {
					window._select_group[i] = true;
				}
				_listview_updsel();
				return false;
			}
			
		}

	} else if (k == 32) {
		if (e._upev) return true;
		if (dom_autocomplete && dom_autocomplete._active) {
			window.setTimeout(function() {
				if (dom_autocomplete)
					dom_autocomplete.ondblclick();
			},100);
			return true;
		}
		if (!window._current_view) return true;
		if (window._current_view != 'list') return true;
		if (mod || shift || e.altKey || e.ctrlKey || e.metaKey) return true;
		// still here?
		_listview_markread();
		_listview_motion(0, window.__selected_object-1); //cruise?
		return true;

	} else if (k == 46) {
		if (e.charCode && e.charCode == e.keyCode) return true;

		if (dom_autocomplete) return true;
		if (e._upev) return true;
		_deletefunc(true);

	} else if (k == 33 || k == 36) {
		if (e.charCode && e.charCode == e.keyCode) return true;

		//pageup and home
		if (dom_autocomplete) return true;
		if (e._upev) return true;
		if (!window._current_view) return true;
		if (window._current_view != 'list') return true;
		if (!shift) {
			if (mod || e.altKey || e.ctrlKey || e.metaKey) return true;
		}
		if (!folsize || !window._current_folder || window._current_folder == ''
				|| !folsize[ window._current_folder]) return true;
		if (!window.__list_view_list) return true;
		var fg = folsize[ window._current_folder ];
		if (window.__selected_object < 0) return true;
		var sg = window.__selected_object - window.__list_view_list._pagesize;
		if (k == 36 || sg < 0) sg = 0; // home _always_ moves to "0"
		_listview_motion(shift, sg);
		return false;
	} else if (k == 34 || k == 35) {
		if (e.charCode && e.charCode == e.keyCode) return true;

		//pagedown and "end"
		if (dom_autocomplete) return true;
		if (e._upev) return true;
		if (!window._current_view) return true;
		if (window._current_view != 'list') return true;
		if (!shift) {
			if (mod || e.altKey || e.ctrlKey || e.metaKey) return true;
		}
		if (!folsize || !window._current_folder || window._current_folder == ''
				|| !folsize[ window._current_folder]) return true;
		if (!window.__list_view_list) return true;
		var fg = folsize[ window._current_folder ];
		if (window.__selected_object == (fg-1)) return true;
		var sg = window.__selected_object + window.__list_view_list._pagesize;
		if (k == 35 || sg >= (fg-1)) sg = fg-1;
		_listview_motion(shift, sg);
		return false;
	} else if ((!e.DOM_VK_DOWN && (k==31||k==40||k==57374)) || (e.DOM_VK_DOWN && e.DOM_VK_DOWN==k)) {
		if (e.charCode && e.charCode == e.keyCode) return true;

		if (dom_autocomplete && !dom_autocomplete._active) {
			if (e._upev) return true;
			window.setTimeout(function() {
				if (dom_autocomplete && dom_autocomplete._eatme > -1) {
					dom_autocomplete.focus();
					if (dom_autocomplete.selectedIndex <= 0)
						dom_autocomplete.selectedIndex=0;
				}
			}, 10);
			return true;
		} else if (!dom_autocomplete) {
			if (e._upev) return true;
			if (!window._current_view) return true;
			if (window._current_view != 'list') return true;
			if (!shift) {
				if (mod || e.altKey || e.ctrlKey || e.metaKey) return true;
			}
			if (!folsize || !window._current_folder || window._current_folder == ''
					|| !folsize[ window._current_folder]) return true;
			var fg = folsize[ window._current_folder ];
			if (window.__selected_object < (fg-1)) {
				_listview_motion(shift, window.__selected_object+1);
				return false;
			}
		}
	} else if (k == 9 || k == 13 || k == 10) {
		if ((k==13 || k == 10) && (e.ctrlKey || (mod & 2))) {
			if (e._upev) return true;
			if (e.preventDefault) e.preventDefault();
			e.cancelBubble=true;
			if (typeof firstaction$.active != 'undefined') {
				var fa = firstaction$.active;
				if (fa.onclick) fa.onclick();
				else if (fa._fn) fa._fn();
				else fa();
			}
			return true;
		}

		if (dom_autocomplete && dom_autocomplete._active) {
			if (e._upev) return false;
			if (e.preventDefault) e.preventDefault();
			e.cancelBubble=true;
			window.setTimeout(function() {
				if (dom_autocomplete)
					dom_autocomplete.ondblclick();
			},100);
			return false;
		}
	} else if (dom_autocomplete && dom_autocomplete._active && dom_autocomplete._boundto) {
		if (e._upev) return true;
		window.setTimeout(function() {
			if (dom_autocomplete && dom_autocomplete._boundto) {
				dom_autocomplete._boundto.focus();
			}
		}, 10);
	}

	return true;
}catch(e){ return true; };
	return true;
}
function _ku(e) {
	e=E$(e);
	if (!e) e={};
	e._upev=true;
	return _kh(e);
}
function _listview_cols_drag(o, w) {
	var fw = parseInt(framewidth);
	var avail = (pagewidth()-(HGRAB._position+fw));

	var lo = undefined;
	var wid = window.__list_view_table;
	var dw = w - wid[o._colno];
	wid[o._colno] = w;
	o.style.width = w + 'px';

	o = o.nextSibling;
	while (o) {
		if (o.tagName && (o.tagName.toUpperCase() == 'A' || o.tagName.toUpperCase() == 'BUTTON')) {
			lo = o;
			if ((wid[o._colno] - dw) >= 8) {
				wid[o._colno] -= dw;
				o.style.width = wid[o._colno] + 'px';
				break;
			}
		}
		o = o.nextSibling;
	}
	var i;
	for (i = 0; i < (wid.length-1); i++) {
		avail -= wid[i];
	}
	if (avail < 8) avail = 8; // eh...
	wid[wid.length-1] = avail;
	if (lo) {
		o = lo.nextSibling;
		while (o) {
			if (o.tagName && (o.tagName.toUpperCase() == 'A' || o.tagName.toUpperCase() == 'BUTTON')) {
				lo = o;
			}
			o = o.nextSibling;
		}
		lo.style.width = wid[wid.length-1] + 'px';
	}

	update_listview_cols();
}
function listview(pv, f, cols) {
	dom_keyholder = undefined;
	window.status = '\xa0 ';

	window._current_provider = pv;

	ATTPICK.style.display = 'none';
	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);
	showLIST$();

	window.__lv2 = undefined;
	window.__pv2 = undefined;
	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);
	showLIST$();

	var xtc = dom_autocomplete;
	if (xtc && xtc._boundto) {
		xtc.style.display='none';
		xtc._eatme=-1;
	}

	window._current_view = 'list';
	window._current_folder = f;
	window._first_select = undefined;
	window.__selected_object=-1;
	window._select_group = {};
	window._viewoptions = undefined;

	document.title = 'netMail '+f;
	clearResizeListeners();

	var i;
	var num_float = 0;
	var used_width = 0;
	for (i = 0; i < cols.length; i++) {
		if (cols[i].width)
			used_width += cols[i].width;
		else
			num_float++;
	}
	var fw = parseInt(framewidth);
	var avail = (pagewidth()-(HGRAB._position+fw));
	var chunk = (avail - used_width);
	var bw = parseInt(chunk / num_float);
	var rest = (chunk-((1+bw)*(num_float-1)));//border(1)

	var heading = document.createElement('DIV');
	heading.style.overflow='hidden';
	heading.style.whiteSpace='nowrap';
	var pos = [];
	var lastfixed = false;
	for (i = 0; i < cols.length; i++) {
		var td = IB$();
		td.tabIndex = -1;
		outset$(td);
		td.style.verticalAlign='bottom';
		td.style.textAlign = 'left';
		td.style.overflow='hidden';
		td.style.cursor='default';
		td._colno = i;

		var txt;
		if (cols[i].heading) {
			txt = cols[i].heading(td);
		} else {
			txt = cols[i].toString();
		}
		if (!txt) txt = '\xa0';
		var axd = td;
		if (axd._box) axd = axd._box;

		if (!lastfixed && i > 0) {
			axd.appendChild(document.createTextNode('\xa0'));
		}
		if (cols[i].width) {
			td.style.width = cols[i].width + 'px';
			pos[pos.length] = cols[i].width;
			lastfixed=true;
		} else {
			td.style.width = bw + 'px';
			if (i == cols.length-1) {
				pos[pos.length] = (bw-sbwidth);
			} else {
				pos[pos.length] = bw;
			}
			if (i == cols.length-2) {
				bw=rest;
			}
			if (lastfixed == true) {
				lastfixed = false;
			} else {
				// grab on the left-side
				drag$(td, function(x,y) {
					var g = this.previousSibling;
					while (g) {
						if (g.tagName && (g.tagName.toUpperCase() == 'A'
								|| g.tagName.toUpperCase() == 'BUTTON')) break;
						g = g.previousSibling;
					}
					_ao(g);
					x -= (g._px);
					_listview_cols_drag(g, x);
					return false;
				});
				td._leftdrag = td.onmousedown;
			}
			if (i < (cols.length-1) && !cols[i+1].width) {
				// grab on the right-side
				drag$(td, function(x,y) {
					_ao(this);
					x -= (this._px);
					_listview_cols_drag(this, x);
					return false;
				});
				td._rightdrag = td.onmousedown;
			}
		}

		td.onmouseover = _fix_status;
		td.onmousemove = function(e) {
			try {
				e=E$(e);
				var lx1 = this.offsetLeft+HGRAB._position+fw;
				var lx2 = lx1+this.offsetWidth;
				if (e.clientX < (lx1+4) && this._leftdrag) {
					this.style.cursor = 'col-resize';
					this.onmousedown = this._leftdrag;
				} else if (e.clientX > (lx2-4) && this._rightdrag) {
					this.style.cursor = 'col-resize';
					this.onmousedown = this._rightdrag;
				} else {
					this.style.cursor = 'default';
					this.onmousedown = false$;
				}
			} catch(e) {};
			return true;
		};
		td._direct_mouseup = true;
		if (cols[i].onclick) {
			td._clickhandler = cols[i].onclick;
			td.onclick = function(e) {
				try {
					this._clickhandler();
				} catch(e) {};
				this.focus();
				return PD$(E$(e));
			};
		} else {
			td.onclick = function(e) {
				blur$();
				return PD$(E$(e));
			};
		}
		if (txt && (txt.data || txt.tagName))
			axd.appendChild(txt);
		else
			axd.appendChild(document.createTextNode(txt));
		heading.appendChild(td);
	}

	while (BOXLIST.firstChild) BOXLIST.removeChild(BOXLIST.firstChild);
	BOXLIST.appendChild(heading);
	var h = heading.offsetHeight;
	for (i = heading.firstChild; i; i = i.nextSibling) {
		i.style.height = h+'px';
		i.style.lineHeight = h+'px';
	}

	var list = document.createElement('DIV');
	list.style.overflow = 'auto';

	var lh = function() {
		if (window._listscrolling)
			window.clearTimeout(window._listscrolling);
		window._listscrolling = window.setTimeout(function() {
			update_listview();
		}, 50);
		return true;
	}
	scrollWatch(list, lh);

	list.style.backgroundColor = COLOR.innerWindow;
	list.style.position='relative';
	list.style.top='0px';
	list.style.left='0px';

	window.__list_view_list = list;
	window.__list_view_cols = cols;

	window.__list_view_table = pos;
	window.__list_view_line_size = h;
	window.__list_view_heading = heading;

	resizeHelper(function() {
		_listview_cols_drag(window.__list_view_heading.firstChild, window.__list_view_table[0]);

		list.style.width = (pagewidth() - (HGRAB._position+parseInt(framewidth)))+'px';

		update_listview_cols();

		var hh = (VGRAB._position-(h+tbsheight()))-2;
		if (hh > 0) {
			list.style.height = hh+'px';
			list._pagesize = parseInt(hh/h)-1;
			LIMIT = list._pagesize+6;
			if (LIMIT < 20) LIMIT = 20;

			if (lh) lh();
		} else {
			list.style.height = '0px';
		}
	}, true);
	BOXLIST.appendChild(list);
	update_listview();

	var ex = window[pv];
	if (!ex) return;
	ex.view();
}
function _view_source() {
	if (window._name) {
		if (window._raw_view) {
			window._raw_view = undefined;
		} else {
			window._raw_view = true;
		}
		window.__lv2 = undefined;
		window.__pv2 = undefined;
		update_listview2();
	} else {
		viewwindow$(window._current_provider, function(g) {
			g._raw_view = true;
		});
	}
}
function contactsview(f) {
	var c1 = {};
	c1.width = 22;
	c1.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_contact.png'),16,16);
	};
	c1.column = function(td,msg) {
		if (!msg || !msg.id) return imgsrc$(imgtag$(),'blank.gif',16,16);
		if (msg .role && msg.role.match && msg.role.match(/MAILING-?LIST/i)) {
			return imgsrc$(imgtag$(),RSRC$('images/stock_contact-list.png'),16,16);
		} else {
			return imgsrc$(imgtag$(),RSRC$('images/stock_contact.png'),16,16);
		}
	};
	var c2 = {};
	c2.heading = function(td){ return 'Full Name'; };
	c2.column = function(td,msg){ if (msg && msg.subject) return msg.subject; return '';};
	c2.onclick = function() { listview_sortby$(undefined); };

	var c3 = {};
	c3.heading = function(td){ return 'Organization'; };
	c3.column = function(td,msg){ if (msg && msg.org) return msg.org; return '';};
	c3.onclick = function() { listview_sortby$('org'); };

	_searchbox_vis('contact name');
	listview("contactsview", f, [ c1, c2, c3 ]);
}
contactsview.accept = true$;
contactsview.noMoveTo = true;
contactsview.containerIcon = 'stock_addressbook';
contactsview.view = function() {
	new_action(RSRC$('images/tools/stock_contact.png'), function() {
		contacteditor();
	});
	var vg = tool(RSRC$('images/tools/stock_mail-compose.png'), 'Compose', function() {
		var to = '';
		map_collection(function() {
			map_contactsByID(this.id, function() {
				if (to != '') to = to + ', ';
				if (this.role && this.role.match && this.role.match(/MAILING-?LIST/i)) {
					to = to + '"' + QC(VC(this.fn)) + '" (Address Group)';
				} else {
					to = to + '"' + QC(VC(this.fn)) + '" <'
						+ QC(VC(this.email)) + '>';
				}
			});
		});
		var obj = {};
		obj._mailto = to;
		obj.title = '';
		obj.FORM = composer;
		composer(obj);
	});
	tool(RSRC$('images/tools/stock_contact.png'), 'Edit Contact/Group', function() {
		var mailbox = window._current_folder;
		var mdata = folcache[mailbox];
		var nh = window.__selected_object;
		var viewrel = folview[mailbox];
		var msg = mdata[viewrel[nh]];
		msg._folder = mailbox;
		msg._object_base = msg.id;
		contacteditor(msg);
	});
	if (WANT('view_raw')) {
		tool(RSRC$('images/tools/stock_view-html-source.png'), 'View Source', _view_source);
	}
	window._vg_hack_compose = vg;
	window._current_view = 'list';
	update_listview2();
};
function _update_mail_containers() {
	if (window._name) return;

	var i;
	for (i = 0; i < window._html_mailboxes.length; i++) {
		var mb = window._html_mailboxes[i];
		if (mb._viewer && mb._viewer.status) {
			apply$(mb, mb._viewer.status, mb._ident);
		}
	}
}
function rssview(f) {
	var c1 = {};
	c1.width = 22;
	c1.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_news.png'),16,16);
	};
	c1.column = function(td, msg) {
		// draw icon if new v. not-new
		if (!msg || !msg.id) return imgsrc$(imgtag$(),'blank.gif',16,16);
		var imgs;
		msg._is_unread=true;
		var oi = 'blank.gif';
		if (msg.flags && msg.flags.indexOf('S') > -1) {
			imgs = 'blank.gif';
			msg._is_unread=false;
		} else {
			imgs = RSRC$('images/stock_news.png');
		}
		var img = imgtag$();
		td.onclick = function(e) {
			msg._is_unread=!msg._is_unread;
			if (!msg_flag_setto._busy) {
				if (msg._is_unread) {
					imgsrc$(img,RSRC$('images/stock_news.png'),16,16);
				} else {
					imgsrc$(img,oi,16,16);
				}
				var g = td;
				while (g) {
					if (g.tagName && g.tagName.toUpperCase && (g.tagName.toUpperCase() == 'A'
								|| g.tagName.toUpperCase() == 'BUTTON')) {
						g.style.fontWeight = (msg._is_unread ? 'bold' : '');
					}
					g = g.nextSibling;
				}
			}
			if (msg._is_unread) {
				msg_flag_disable(msg, 'S');
				folunseen[window._current_folder]++;
			} else {
				msg_flag_enable(msg, 'S');
				folunseen[window._current_folder]--;
			}
			window.setTimeout(_update_mail_containers, 10);
			// err...
			_listview_start_timeoutread._timeout = undefined;
			blur$();
			return PD$(E$(e));
		};
		return imgsrc$(img,imgs,16,16);
	};
	var c3 = {};
	c3.width = 22;
	c3.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
	};
	c3.column = function(td, msg) {
		var img = imgtag$();

		if (msg.id && msg.flags && msg.flags.indexOf('F') > -1) {
			td._urgent=true;
			imgsrc$(img,RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
		} else {
			imgsrc$(img,'blank.gif',16,16);
			td._urgent=false;
		}
		td.onclick = function(e) {
			this._urgent = !this._urgent;
			if (this._urgent) {
				msg_flag_enable(msg, 'F', function() { update_listview(); });
			} else {
				msg_flag_disable(msg, 'F', function() { update_listview(); });
			}
			update_listview();

			blur$();
			return PD$(E$(e));
		};
		return img;
	};

	var c4 = {};
	c4.heading = function(td,msg){return 'Received';};
	c4.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		var d = new Date(msg.received*1000);
		return localtime(d);
	};
	var c5 = {};
	c5.heading = function(td,msg){return 'Summary';};
	c5.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		return msg.subject;
	};

	_searchbox_vis('sender or subject');
	listview("rssview", f, [ c1, c3, c4, c5 ]);
}
rssview.status = function(f) {
	if (typeof folunseen[f] == 'undefined') {
		// ignore status change for a moment
	} else if (folunseen[f] && folunseen[f] > 0) {
		var cc = folunseen[f];
		this.setInfo(cc);
	} else {
		this.setInfo();
	}
};
rssview.containerIcon = 'stock_news';
rssview.view = function() {
	tool(RSRC$('images/tools/stock_mail-forward.png'), 'Forward', function() {
		composer_op(3);
	});
	window._current_view = 'list';
	update_listview2();
};
function mailview(f) {
	var c1 = {};
	c1.width = 22;
	c1.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_mail-unread.png'),16,16);
	};
	c1.column = function(td, msg) {
		// draw icon if new v. not-new
		if (!msg || !msg.id) return imgsrc$(imgtag$(),'blank.gif',16,16);
		var imgs;
		msg._is_unread=true;
		var oi = RSRC$('images/stock_mail-open.png');
		if (msg.flags && msg.flags.indexOf('R') > -1) {
			imgs = RSRC$('images/stock_mail-replied.png');
			oi = RSRC$('images/stock_mail-replied.png');
			if (msg.flags.indexOf('S') > -1) {
				msg._is_unread=false;
			}
		} else if (msg.flags && msg.flags.indexOf('P') > -1) {
			imgs = RSRC$('images/stock_mail-forwarded.png');
			oi = RSRC$('images/stock_mail-forwarded.png');
			if (msg.flags.indexOf('S') > -1) {
				msg._is_unread=false;
			}
		} else if (msg.flags && msg.flags.indexOf('S') > -1) {
			imgs = RSRC$('images/stock_mail-open.png');
			msg._is_unread=false;
		} else {
			imgs = RSRC$('images/stock_mail-unread.png');
		}
		var img = imgtag$();
		td.onclick = function(e) {
			msg._is_unread=!msg._is_unread;
			if (!msg_flag_setto._busy) {
				if (msg._is_unread) {
					imgsrc$(img,RSRC$('images/stock_mail-unread.png'),16,16);
				} else {
					imgsrc$(img,oi,16,16);
				}
				var g = td;
				while (g) {
					if (g.tagName && g.tagName.toUpperCase && (g.tagName.toUpperCase() == 'A'
								|| g.tagName.toUpperCase() == 'BUTTON')) {
						g.style.fontWeight = (msg._is_unread ? 'bold' : '');
					}
					g = g.nextSibling;
				}
			}
			if (msg._is_unread) {
				msg_flag_disable(msg, 'S');
				folunseen[window._current_folder]++;
			} else {
				msg_flag_enable(msg, 'S');
				folunseen[window._current_folder]--;
			}
			window.setTimeout(_update_mail_containers, 10);
			// err...
			if (_listview_start_timeoutread._timeout)
				window.clearTimeout(_listview_start_timeoutread._timeout);
			_listview_start_timeoutread._timeout = undefined;
			blur$();
			return PD$(E$(e));
		};
		return imgsrc$(img,imgs,16,16);
	};
	var c2 = {};
	c2.width = 22;
	c2.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_attach.png'),16,16);
	};
	c2.column = function(td, msg) {
		if (msg.contenttype && msg.contenttype.indexOf('multipart/mixed') > -1) {
			return imgsrc$(imgtag$(),RSRC$('images/stock_attach.png'),16,16);
		}
		return imgsrc$(imgtag$(),'blank.gif',16,16);
	};
	var c3 = {};
	c3.width = 22;
	c3.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
	};
	c3.column = function(td, msg) {
		var img = imgtag$();

		if (msg.id && msg.flags && msg.flags.indexOf('F') > -1) {
			td._urgent=true;
			imgsrc$(img,RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
		} else {
			imgsrc$(img,'blank.gif',16,16);
			td._urgent=false;
		}
		td.onclick = function(e) {
			this._urgent = !this._urgent;
			if (this._urgent) {
				msg_flag_enable(msg, 'F', function() { update_listview(); });
			} else {
				msg_flag_disable(msg, 'F', function() { update_listview(); });
			}
			update_listview();

			blur$();
			return PD$(E$(e));
		};
		return img;
	};

	var c4 = {};
	c4.heading = function(td,msg){return 'Received';};
	c4.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		var d = new Date(msg.received*1000);
		return localtime(d);
	};
	c4.onclick = function() { listview_sortby$(); };
	var c5 = {};
	c5.heading = function(td,msg){return 'From';};
	c5.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		return msg.fromText;
	};
	_maybesort(c5,'from');

	var c6 = {};
	c6.heading = function(td,msg){return 'Subject';};
	c6.column = function(td,msg){
		if (!msg || !msg.id) return '';
		return msg.subject;
	};
	_maybesort(c6,'subject');

	_searchbox_vis('sender or subject');
	listview("mailview", f, [ c1, c2, c3, c5,c6, c4 ]);
}
mailview.containerIcon = 'stock_icon';
mailview.status = function(f) {
	if (typeof folunseen[f] == 'undefined') {
		// ignore status change for a moment
	} else if (folunseen[f] && folunseen[f] > 0) {
		var cc = folunseen[f];
		this.setInfo(cc);
	} else {
		this.setInfo();
	}
};
function _removaccel(col, count) {
	var nd = [];
	var i;
	var fol = window._current_folder;
	var rdata = window.folview[fol];
	var check = 0;
	var unseen = 0;
	var lc = -1;
	if (rdata) {
		for (i = 0; i < rdata.length; i++) {
			if (window._select_group[i]) {
				if (lc == -1) lc = i;
				if (!rdata[i]) continue;
				if (!rdata[i].match(/\/[^\/:]*:2,[A-R]*S/)) {
					unseen++;
				}
				check++;
				continue;
			}
			nd[nd.length] = rdata[i];
		}
	}
	if (lc > -1) window.__selected_object = lc;

	if (check == count) {
		window._select_group = {};
		window._select_group[window.__selected_object]=true;

		// hurray!
		folview[fol] = nd;

		folsize[fol] = folsize[fol] - check;
		folunseen[fol] = folunseen[fol] - unseen;
		if (ping_monitor$ && ping_monitor$._ov) ping_monitor$._ov[fol]=0;

		update_listview();
		fetchmail.qq.append(function() {
			window._select_group = {};
			window._select_group[window.__selected_object]=true;
			if (ping_monitor$ && ping_monitor$._ov) ping_monitor$._ov[fol]=0;
	
			_listview_scrollto();
			update_listview2();
			icon_alert_cancel$();
		});
	} else {
		// wasn't able to delete everything...
		window._select_group = {};
		window._select_group[window.__selected_object]=true;
		_zapcache(window._current_folder);
		icon_alert_cancel$();
	}
}
function _maybesort(c,fn) {
	c.onclick = function() {
		var fol = window._current_folder;
		// xxx this limit (3000 msg) is arbitrary- based on load (somewhat)
		if (fol && window.folsize[fol] && window.folsize[fol] < 3000) {
			listview_sortby$(fn);
		}
	};
	return c;
}
function _deletefunc(ask) {
	var col = COL();
	if (col.length == 0) return;
	if (ask && col.length > 1) {
		if (!confirm("Are you sure you want to delete " + col.length + " items?")) {
			return;
		}
	}
	httpmail.message.remove.onerror = function(e) {
		unbusy$();
	};
	// move selection to top of (ahem) selection
	var i;
	var j=-1;
	if (window._select_group) {
		for (i in window._select_group) {
			if (j > -1 && i > j) continue;
			if (window._select_group[i] && window._select_group[i] == true)
				j = i;
		}
	}
	if (j > -1) window.__selected_object = j;

	var x, aa;
	if (window.__list_view_list) {
		var nlist = window.__list_view_list;
		for (x = 0; x < nlist._grow.length; x++) {
			var nr = nlist._grow[x];
			for (aa = nr.firstChild; aa; aa = aa.nextSibling) {
				if (aa.tagName && aa.tagName.toUpperCase && (aa.tagName.toUpperCase() == 'A'
							|| aa.tagName.toUpperCase() == 'BUTTON')) {
					if (aa._row == window.__selected_object
					|| (window._select_group && window._select_group[ aa._row ])) {
						aa.style.textDecoration = 'line-through';
					}
				}
			}
		}
	}

	if (window._current_folder && ping_monitor$ && ping_monitor$._ov)
		ping_monitor$._ov[window._current_folder]=0;
	httpmail.message.remove.onreply = function(count) {
		try {
			if (count != 1) {
				notice$(count+" messages deleted");
			} else {
				notice$(count+" message deleted");
			}
	
			_zapcache('Trash',true);
			_removaccel(col,count);
		} catch(e) {};
		try {
			var x, aa;
			if (window.__list_view_list) {
				var nlist = window.__list_view_list;
				for (x = 0; x < nlist._grow.length; x++) {
					var nr = nlist._grow[x];
					for (aa = nr.firstChild; aa; aa = aa.nextSibling) {
						if (aa.tagName && aa.tagName.toUpperCase && (aa.tagName.toUpperCase() == 'A'
									|| aa.tagName.toUpperCase() == 'BUTTON')) {
							aa.style.textDecoration = 'none';
						}
					}
				}
			}
		} catch(e) {};
		unbusy$();
	};
	busy$();
	try {
		httpmail.message.remove(col);
	} catch(e) {
		unbusy$();
	};
}
mailview.view = function() {
	new_action(RSRC$('images/tools/stock_mail-compose.png'), function() {
		composer_op(0);
	});
	tool(RSRC$('images/tools/stock_mail-reply.png'), 'Reply', function() {
		composer_op(1);
	}).setAttribute('ACCESSKEY', "R");
	tool(RSRC$('images/tools/stock_mail-reply-to-all.png'), 'Reply to All', function() {
		composer_op(2);
	});
	tool(RSRC$('images/tools/stock_mail-forward.png'), 'Forward', function() {
		composer_op(3);
	});
	if (WANT('view_raw')) {
		tool(RSRC$('images/tools/stock_view-html-source.png'), 'View Source', _view_source);
	}
	if (window._current_folder == 'INBOX') {
		toolsep();
		if (!config.prefs || !config.prefs['hidefol:Archive']) {
			tool(RSRC$('images/tools/stock_folder.png'), 'Archive', function() {
				var col = COL();
				if (col.length == 0) return;
				httpmail.message.archive.onerror = function(count) {
					unbusy$();
				};
				httpmail.message.archive.onreply = function(count) {
					try {
						if (count != 1) {
							notice$(count+" messages archived");
						} else {
							notice$(count+" message archived");
						}
						_zapcache('INBOX'); _zapcache('Archive');
					} catch(e) {
					};
					unbusy$();
				};
				busy$();
				try {
					httpmail.message.archive(col);
				} catch(e) {
					unbusy$();
				};
			}).setAttribute('ACCESSKEY', 'K');
		}
		if (!config.prefs || !config.prefs['hidefol:SPAM']) {
			tool(RSRC$('images/tools/stock_spam.png'), 'Spam', function() {
				var col = COL();
				if (col.length == 0) return;
				if (window._current_folder && ping_monitor$ && ping_monitor$._ov)
					ping_monitor$._ov[window._current_folder]=0;
				httpmail.message.markspam.onerror = function(e) {
					unbusy$();
				};
				httpmail.message.markspam.onreply = function(count) {
					try {
						if (count != 1) {
							notice$(count+" messages junked");
						} else {
							notice$(count+" message junked");
						}
	
						_zapcache('SPAM',true);
						_removaccel(col,count);
					} catch(e) {
					};
					unbusy$();
				};
				busy$();
				try {
					httpmail.message.markspam(col);
				} catch(e) {
					unbusy$();
				};
			});
		}
		tool(RSRC$('images/tools/stock_delete.png'), 'Delete', function() {
			_deletefunc();
		});
	} else if (window._current_folder == 'SPAM') {
		toolsep();
		tool(RSRC$('images/tools/stock_not-spam.png'), 'Not Spam', function() {
			var col = COL();
			if (col.length == 0) return;
			if (window._current_folder && ping_monitor$ && ping_monitor$._ov)
				ping_monitor$._ov[window._current_folder]=0;
			httpmail.message.notspam.onerror = function(e) {
				unbusy$();
			};
			httpmail.message.notspam.onreply = function(count) {
				try {
					if (count != 1) {
						notice$(count+" messages recovered");
					} else {
						notice$(count+" message recovered");
					}
					_zapcache('INBOX',true);
					_removaccel(col,count);
				} catch(e) {};
				unbusy$();
			};
			busy$();
			try {
				httpmail.message.notspam(col);
			} catch(e) {
				unbusy$();
			};
		});
		tool(RSRC$('images/tools/stock_delete.png'), 'Delete', function() {
			_deletefunc();
		});
	} else if (window._current_folder == 'Trash') {
		toolsep();
		ungrey$(tool(RSRC$('images/tools/stock_trash_full.png'), 'Empty Trash', function() {
			if (folsize['Trash'] == 1) {
				if (!confirm("Are you sure you want to delete this message permanently?")) {
					return;
				}
			} else if (folsize['Trash'] > 1) {
				if (!confirm("Are you sure you want to delete these "
				+ (folsize['Trash'].length) + " messagex permanently?")) {
					return;
				}
			} else {
				return;
			}
			// expunge
			httpmail.expunge.onerror = function(count) {
				unbusy$();
			};
			httpmail.expunge.onreply = function(count) {
				try {
					_zapcache(window._current_folder);
					notice$("Trash emptied");
				} catch(e) {};
				unbusy$();
			};
			busy$();
			try {
				httpmail.expunge();
			} catch(e) {
				unbusy$();
			};
		}));
	} else {
		toolsep();
		tool(RSRC$('images/tools/stock_delete.png'), 'Delete', function() {
			_deletefunc();
		});
	}
	window._current_view = 'list';
	update_listview2();
};
function notesview(f) {
	// mime/gnome-mime-text-x-txt.png
	var c1 = {};
	c1.width = 22;
	c1.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/mime/gnome-mime-text-x-txt.png'),16,16);
	};
	c1.column = function(td, msg) {
		if (!msg || !msg.id) return imgsrc$(imgtag$(),'blank.gif',16,16);
		return imgsrc$(imgtag$(),RSRC$('images/mime/gnome-mime-text-x-txt.png'),16,16);
	};
	var c2 = {};
	c2.heading = function(td,msg){return 'Last Modified';};
	c2.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		var d = new Date(msg.received*1000);
		return localtime(d);
	};
	c2.onclick = function() { listview_sortby$(); };

	var c3 = {};
	c3.heading = function(td,msg){return 'Subject';};
	c3.column = function(td,msg){
		if (!msg || !msg.id) return '';
		return msg.subject;
	};
	c3.onclick = function() { listview_sortby$('subject'); };

	_searchbox_vis('subject');
	listview("notesview", f, [ c1, c3, c2 ]);
}
notesview.accept = true$;
notesview.containerIcon = 'stock_notes';
notesview.noMoveTo = true;
notesview.view = function() {
	new_action(RSRC$('images/tools/stock_new.png'), function() {
		var obj = {};
		obj.title = '';
		obj.FORM = 'notesview';
		composer(obj);
	});
	tool(RSRC$('images/tools/stock_mail-compose.png'), 'Edit', function() {
		// resume
		var mailbox = window._current_folder;
		var viewrel = folview[mailbox];
		var message = MSGPART$(viewrel[window.__selected_object]);

		httpmail.message.resume.onerror = false$;
		httpmail.message.resume.onreply = function(set) {
			var obj = {};
			obj.title = set.title;
			obj.FORM = 'notesview';
			obj._body = set._body;
			composer(obj);
		};
		httpmail.message.resume(mailbox, message);
	}).setAttribute('ACCESSKEY', 'R');
	tool(RSRC$('images/tools/stock_delete.png'), 'Delete', function() {
		_deletefunc();
	});
	window._current_view = 'list';
	update_listview2();
};
notesview.noAddressing=true;
notesview.onSend = function() {
	var r;
	try {
		httpmail.mailbox.post.onerror=false$;
		r = httpmail.mailbox.post("Notes", this);
		if (r) {
			_zapcache('Notes');
			window.close();
		} else {
			window.alert("There was trouble saving the note, please try again... "+e);
		}
	} catch(e) {
		window.alert("There was trouble saving the note, please try again... "+e);
	};
};
notesview.noDraftSupport=true;
notesview.noSignature = true;
notesview.fromString = 'Author';


function sentmailview(f) {
	var c1 = {};
	c1.width = 22;
	c1.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_mail-open.png'),16,16);
	};
	c1.column = function(td, msg) {
		// draw icon if new v. not-new
		if (!msg || !msg.id) return imgsrc$(imgtag$(),'blank.gif',16,16);

		var imgs;
		if (msg.references) {
			imgs = RSRC$('images/stock_mail-replied.png');
		} else {
			imgs = RSRC$('images/stock_mail-open.png');
		}
		return imgsrc$(imgtag$(),imgs,16,16);
	};
	var c2 = {};
	c2.width = 22;
	c2.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_attach.png'),16,16);
	};
	c2.column = function(td, msg) {
		if (msg.contenttype && msg.contenttype.indexOf('multipart/mixed') > -1) {
			return imgsrc$(imgtag$(),RSRC$('images/stock_attach.png'),16,16);
		}
		return imgsrc$(imgtag$(),'blank.gif',16,16);
	};
	var c3 = {};
	c3.width = 22;
	c3.heading = function(td) {
		return imgsrc$(imgtag$(),RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
	};
	c3.column = function(td, msg) {
		if (msg.id && msg.flags && msg.flags.indexOf('F') > -1) {
			return imgsrc$(imgtag$(),RSRC$('images/stock_mail-flag-for-followup.png'),16,16);
		}
		return '';
	};

	var c4 = {};
	if (f == 'Drafts') {
		c4.heading = function(td,msg){return 'Last Modified';};
	} else {
		c4.heading = function(td,msg){return 'Sent';};
	}
	c4.column = function(td,msg){
		if (!msg || !msg.id || !msg.received) return '';
		var d = new Date(msg.received*1000);
		return localtime(d);
	};
	c4.onclick = function() { listview_sortby$(); };

	var c5 = {};
	c5.heading=function(td,msg){return 'To';};
	c5.column=function(td,msg){if (!msg || !msg.id)return '';return msg.to;};
	_maybesort(c5,'to');

	var c6 = {};
	c6.heading=function(td,msg){return 'Subject';};
	c6.column=function(td,msg){if (!msg || !msg.id)return '';return msg.subject;};
	_maybesort(c6,'subject');

	_searchbox_vis('recipient or subject');
	listview("sentmailview", f, [ c1, c2, c3,c5,c6,c4 ]);
}
sentmailview.accept = false$;
sentmailview.noMoveFrom = true;
sentmailview.containerIcon = 'stock_folder';
sentmailview.status = function(f) {
	if (f == 'Drafts' && (typeof folsize[f] != 'undefined')) {
		var cc = folsize[f];
		if (cc && cc > 0) {
			this.setInfo(cc);
		} else {
			this.setInfo();
		}
	}
};
sentmailview.view = function() {
	new_action(RSRC$('images/tools/stock_mail-compose.png'), function() {
		composer_op(0);
	});
	if (window._current_folder == 'Drafts') {
		tool(RSRC$('images/tools/stock_mail-reply.png'), 'Resume', function() {
			composer_op(4);
		}).setAttribute('ACCESSKEY', 'R');
		tool(RSRC$('images/tools/stock_delete.png'), 'Delete', function() {
			_deletefunc();
		});
	} else {
		tool(RSRC$('images/tools/stock_mail-reply.png'), 'Follow-up', function() {
			composer_op(2);
		}).setAttribute('ACCESSKEY', 'R');
		tool(RSRC$('images/tools/stock_mail-forward.png'), 'Forward', function() {
			composer_op(3);
		});
	}
	if (WANT('view_raw')) {
		tool(RSRC$('images/tools/stock_view-html-source.png'), 'View Source', _view_source);
	}
	window._current_view = 'list';
	update_listview2();
};
function pagewidth() {
	return window.innerWidth || document.documentElement.clientWidth;
}
function pageheight() {
	return window.innerHeight || document.documentElement.clientHeight;
}
function _resizehandler() {
	if (!window._printing) {
		var i;
		for (i = 0; i < window._rh_known.length; i++) {
			var fn=window._rh_known[i];
			fn();
		}
	}

	if (window._name) {
		var p = window._parentWindow;
		while (p._parentWindow && p._parentWindow != p) p = p._parentWindow;
		p.VWIDTH = pagewidth();
		p.VHEIGHT = pageheight();
	}
}
function scrollWatch(obj, fn) {
/*@cc_on @*/
/*@if (1) {
  	obj.onscroll = fn;
	return;
}
@end @*/
	if (obj.addEventListener && obj.addEventListener('scroll', fn, false)) {
		// mozilla doesnt need this CRAP either...
		return;
	}

	// this is disgusting...
	obj._last_scroll = obj.scrollTop;
	obj._onscroll_helper = fn;

	if (!window._sh_known) {
		window._sh_known = [];
		window.setInterval(function() {
			var i;
			for (i = 0; i < window._sh_known.length; i++) {
				var o = window._sh_known[i];
				if (o._last_scroll != o.scrollTop) {
					o._last_scroll = o.scrollTop;
					o._onscroll_helper();
				}
			}
		}, 100);
	}

	window._sh_known[ window._sh_known.length ] = obj;
}

function resizeHelper(fn, istemp) {
	if (!window._rh_known) {
		window._rh_known=[];
	}
	window._rh_known[window._rh_known.length]=fn;
	if (istemp && istemp==true)fn._temporary=true;
	fn();
}
function resizeListen(o,x,y,w,h,istemp) {
	if (!window._rh_known) {
		window._rh_known=[];
	}
	
	var fn;
	o.style.position='absolute';
	o.style.overflow='hidden';
	eval('fn=function(){try {var me=arguments.callee;'
			+ 'me.element.style.top=(' + y + ')+"px";'
			+ 'me.element.style.left=(' + x + ')+"px";'
			+ 'me.element.style.width=(' + w + ')+"px";'
			+ 'me.element.style.height=(' + h + ')+"px";'
			+ '} catch(e) {};}');
	fn.element=o;
	if (istemp && istemp==true)fn._temporary=true;
	window._rh_known[window._rh_known.length]=fn;
	fn();
}
function clearResizeListeners() {
	if (window._sh_known) window._sh_known = [];

	if (!window._rh_known) return;

	var i;
	var j = window._rh_known;
	while (j.length > 0 && j[j.length-1]._temporary) j.length--;
	for (i = 0; i < (j.length-1);) {
		if (j[i]._temporary) {
			j[i] = j[j.length-1];
			j.length--;
		} else {
			i++;
		}
	}
}
function outset$(o) {
	var az;
	if (COLOR.button) {
		BGCOLOR(o,COLOR.button);
		FGCOLOR(o,COLOR.buttonText);
		if (COLOR.buttonBorder) {
			az = COLOR.buttonBorder + ' ' + COLOR.button;
		} else {
			az = COLOR.button;
		}
	} else {
		BGCOLOR(o,COLOR.window);
		FGCOLOR(o,COLOR.windowText);
		az = COLOR.window;
	}
	if (az.indexOf(' ') == -1) {
		o.style.borderTop = '1px outset ' + az;
		o.style.borderLeft = '1px outset ' + az;
		o.style.borderRight = '1px outset ' + az;
		o.style.borderBottom = '1px outset ' + az;
	} else {
		var co = az.split(" ");
		o.style.borderTop = '1px solid ' +co[1];
		o.style.borderLeft = '1px solid ' +co[1];
		o.style.borderBottom = '1px solid ' +co[0];
		o.style.borderRight = '1px solid ' +co[0];
	}
}
function dotted$(gx) {
	var av = FIRST$(COLOR.innerWindowText);
	gx.style.borderTop = '1px dotted ' + av;
	gx.style.borderLeft = '1px dotted ' + av;
	gx.style.borderRight = '1px dotted ' + av;
	gx.style.borderBottom = '1px dotted ' + av;
}
function inset$(o, wc) {
	var az;
	if (wc) {
		if (COLOR.button) {
			BGCOLOR(o,COLOR.button);
			FGCOLOR(o,COLOR.buttonText);
			az = COLOR.button;
		} else {
			BGCOLOR(o,COLOR.window);
			FGCOLOR(o,COLOR.windowText);
			az = COLOR.window;
		}
	} else {
		BGCOLOR(o,COLOR.innerWindow);
		FGCOLOR(o,COLOR.innerWindowText);
		az = COLOR.window;
	}
	if (az.indexOf(' ') == -1) {
		o.style.borderTop = '1px inset ' + az;
		o.style.borderLeft = '1px inset ' + az;
		o.style.borderRight = '1px inset ' + az;
		o.style.borderBottom = '1px inset ' + az;
	} else {
		var co = az.split(" ");
		o.style.borderTop = '1px solid ' +co[1];
		o.style.borderLeft = '1px solid ' +co[1];
		o.style.borderBottom = '1px solid ' +co[0];
		o.style.borderRight = '1px solid ' +co[0];
	}
}
function E$(e) {
	if (typeof e == 'undefined' && window.event) e = window.event;
	if (typeof e == 'undefined') return undefined;
	if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
	if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
	return e;
}
function PP$(e) {
	if (e) {
		if (e.stopPropagation) e.stopPropagation();
		e.cancelBubble=true;
	}
	return false;
}
function PD$(e) {
	if (e) {
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		e.cancelBubble=true;
	}
	return false;
}
function false$(){return false;}
function true$(){return true;}
function _ab(a) { if (a<0)return -a;return a;}
function drag$(o,f) {
	o.onmousedown=function(e) {
		e=E$(e);
		PD$(e);
		var sx = e.clientX;
		var sy = e.clientY;
		window._drag=false;
		(function(soc,sod,sou,som) {
			document.onmousemove=function(e) {
				e=E$(e);
				var x=e.clientX;
				var y=e.clientY;
				if (!window._drag) {
					var dx=_ab(sx-x);
					var dy=_ab(sy-y);
					if (dx < 4 && dy < 4) return true;
					if (o.style && o.style.cursor) {
						document.body.cursor=o.style.cursor;
					}
				}
				apply$(o,f,x,y);
				window._drag=true;

				return PD$(e);
			};
			document.onmouseup=function(e) {
				if (!o._direct_mouseup) {
					o.onclick=soc;
					o.ondblclick=sod;
					o.onmouseup=sou;
					o.onmousedown=som;
				}

				window.setTimeout(function() {
					o.onclick=soc;
					o.ondblclick=sod;
					o.onmouseup=sou;
					o.onmousedown=som;
				},100);
				document.body.style.cursor='';
				document.onmousemove=true$;
				document.onmouseup=true$;
				document.onclick=true$;

				if (!window._drag) return PD$(E$(e));
				if (f.mouseup) {
					apply$(o,f.mouseup,e);
				} else {
					_resizehandler();
				}
				window._drag=false;

				return true;
			};
			o.onclick=document.onmouseup;
			o.ondblclick=document.onmouseup;
			o.onmouseup=document.onmouseup;
			o.onmousedown=false$;
		})(o.onclick||true$, o.ondblclick||true$, o.onmouseup||true$, o.onmousedown||true$);
		return false;
	};
}
function contacts_apply_cl(cl, a, b, str) {
	var k1, k2;
	if (a.length == 0) {
		k1 = b.substr(0, 1).toLowerCase();
		k2 = undefined;
	} else {
		k1 = b.substr(0, 1).toLowerCase();
		k2 = a.substr(0, 1).toLowerCase();
	}
	if (typeof cl[k1] == 'undefined') {
		cl[k1] = [];
	}
	var g = cl[k1];
	g[g.length] = str;

	if (typeof k2 != 'undefined') {
		if (typeof cl[k2] == 'undefined') {
			cl[k2] = [];
		}
		g = cl[k2];
		g[g.length] = str;
	}
}

function reload_contacts(f) {
	httpmail.contacts.list.onerror = function(cl) {
		if (f) f();
	};
	httpmail.contacts.list.onreply = function(cl) {
		try {
			window.contacts = cl;
			var i;
			window._contacts_list = {};
			var urls = [];
			for (i = 0; i < cl.length; i++) {
				var n = cl[i];
				var a = VC(n.fn);
				var b;
				var str;
				if (n.role && n.role.match && n.role.match(/MAILING-?LIST/i)) {
					if (a.length == 0) continue;

					b = a;
					str = '"' + QC(a) + '" (Address Group)';
				} else {
					b = VC(n.email);
					if (b.length == 0) continue;
					if (a.length == 0) {
						str = '<' + QC(b) + '>';
					} else {
						str = '"' + QC(a) + '" <' + QC(b) + '>';
					}
				}
				contacts_apply_cl(_contacts_list, a, b, str);
			}
		} catch(e) {
		};
		if (f) f();
	};
	try {
		httpmail.contacts.list();
	} catch(e) {};
};

function update_news() {
	if (!config['FEED$rss']) return undefined;
	var j = config['FEED$rss'].split("\n");
	httpmail.feed.burn.onreply = true$;
	httpmail.feed.burn.onerror = true$;
	httpmail.feed.burn(j);
	return true;
}
function _rss_issub(url) {
	if (!config['FEED$rss']) return undefined;
	var j = config['FEED$rss'].split("\n");
	var i;
	for (i = 0; i < j.length; i++) {
		if (j[i] == url) return true;
	}
	return undefined;
}
function _rss_sub(urls) {
	if (!_rss_sub.qq) {
		_rss_sub.qq = new Queue;
	}
	_rss_sub.qq.append(function() {
		if (config['FEED$rss']) {
			var x;
			var j = config['FEED$rss'].split("\n");
			var i;
			var nu = [];
			for (x = 0; x < urls.length; x++) {
				for (i = 0; i < j.length; i++) {
					if (j[i] == urls[x]) break;
				}
				if (i < j.length) continue;
				nu[nu.length] = urls[x];
			}
			urls = nu;
		}
		if (urls && urls.length > 0) {
			httpmail.feed.subscribe.onreply = function() {
				// update config
				try {
					var y;
					var fake = config['FEED$rss']||'';
					for (y = 0; y < urls.length; y++) {
						fake = fake + ""+urls[y]+"\n";
					}
					config['FEED$rss']=fake;
				} catch(e) {
				};
				_rss_sub.qq.unlock();
			};
			_rss_sub.qq.lock();
			httpmail.feed.subscribe.onerror = function() {
				_rss_sub.qq.unlock();
			};
			httpmail.feed.subscribe(urls);
		}
	});
}
function _rss_unsub(urls) {
	if (!config['FEED$rss']) return;

	if (!_rss_sub.qq) {
		_rss_sub.qq = new Queue;
	}
	_rss_sub.qq.append(function() {
		var x;
		var j = config['FEED$rss'].split("\n");
		var i;
		var nu = [];
		var fake = "";
		for (x = 0; x < j.length; x++) {
			for (i = 0; i < urls.length; i++) {
				if (j[i] == urls[x]) break;
			}
			if (i != j.length) continue;
			nu[nu.length] = j[x];
			fake = fake + "" + j[x] + "\n";
		}
		if (urls && urls.length > 0) {
			httpmail.feed.unsubscribe.onreply = function() {
				// update config
				try {
					config['FEED$rss'] = fake;
				} catch(e) {};
				_rss_sub.qq.unlock();
			};
			httpmail.feed.unsubscribe.onerror = function() {
				_rss_sub.qq.unlock();
			};

			_rss_sub.qq.lock();
			httpmail.feed.unsubscribe(urls);
		} else {
			try {
				config['FEED$rss'] = fake;
			} catch(e) {};
		}
	});
}


function _cal_issub(url) {
	if (!config['FEED$cal']) return undefined;
	var j = config['FEED$cal'].split("\n");
	var i;
	for (i = 0; i < j.length; i++) {
		if (j[i] == url) return true;
	}
	return undefined;
}
function _cal_sub(urls) {
	if (!_cal_sub.qq) {
		_cal_sub.qq = new Queue;
	}
	_cal_sub.qq.append(function() {
		if (config['FEED$cal']) {
			var x;
			var j = config['FEED$cal'].split("\n");
			var i;
			var nu = [];
			for (x = 0; x < urls.length; x++) {
				for (i = 0; i < j.length; i++) {
					if (j[i] == urls[x]) break;
				}
				if (i < j.length) continue;
				nu[nu.length] = urls[x];
			}
			urls = nu;
		}
		if (urls && urls.length > 0) {
			httpmail.calendar.subscribe.onreply = function() {
				// update config
				try {
					var y;
					var fake = config['FEED$cal']||'';
					for (y = 0; y < urls.length; y++) {
						fake = fake + ""+urls[y]+"\n";
					}
					config['FEED$cal']=fake;
				} catch(e) {
				};
				_cal_sub.qq.unlock();
			};
			_cal_sub.qq.lock();
			httpmail.calendar.subscribe.onerror = function() {
				_cal_sub.qq.unlock();
			};
			httpmail.calendar.subscribe(urls);
		}
	});
}
function _cal_unsub(urls) {
	if (!config['FEED$cal']) return;

	if (!_cal_sub.qq) {
		_cal_sub.qq = new Queue;
	}
	_cal_sub.qq.append(function() {
		var x;
		var j = config['FEED$cal'].split("\n");
		var i;
		var nu = [];
		var fake = "";
		for (x = 0; x < j.length; x++) {
			for (i = 0; i < urls.length; i++) {
				if (j[i] == urls[x]) break;
			}
			if (i != j.length) continue;
			nu[nu.length] = j[x];
			fake = fake + "" + j[x] + "\n";
		}
		if (urls && urls.length > 0) {
			httpmail.calendar.unsubscribe.onreply = function() {
				// update config
				try {
					config['FEED$cal'] = fake;
				} catch(e) {};
				_cal_sub.qq.unlock();
			};
			httpmail.calendar.unsubscribe.onerror = function() {
				_cal_sub.qq.unlock();
			};

			_cal_sub.qq.lock();
			httpmail.calendar.unsubscribe(urls);
		} else {
			try {
				config['FEED$cal'] = fake;
			} catch(e) {};
		}
	});
}

function colorscheme_html$(v) {
	// okay this is a little weird...
	var z = window.COLOR;
	if (!v || v == '') v = '*browser default*';
	setup_colors$(v);
	var co = window.COLOR;
	window.COLOR = z;

	co.window = FIRST$(co.window);
	co.innerWindow = FIRST$(co.innerWindow);
	co.hilight = FIRST$(co.hilight);

	if (co.button) {
		co.button = FIRST$(co.button);
	} else {
		co.button = co.window;
		co.buttonText = co.windowText;
	}

	// okay, draw a "mini preview"
	return '<div style="cursor:default;background-color:' + co.innerWindow + ';border:1px dotted #000000">'
	+ '<div style="height:4px;line-height:4px;background-color:#72a1cb;font-size:3px;font-weight:bold;color:#ffffff;overflow:hidden;">this is a mini preview window</div>'
	+ '<div style="height:12px;line-height:12px;background-color:' + co.button +';color:'+ co.buttonText + ';overflow:hidden;font-size:5px;">&nbsp;New | &nbsp; Reply, Reply AllForward</div>'
	+ '<div style="float:left;border-right:2px solid ' + co.window + ';background-color:' + co.innerWindow + ';color:' + co.innerWindowText + ';height:108px;width:20px;overflow:hidden;font-size:4px;font-weight:normal;">'
	+ '<div style="background-color:' + co.hilight + ';color:'+ co.hilightText + ';">INBOX</div>'
	+ 'Drafts<br/>Sent Items<br/>Archive<br/>Fish Sticks<br/>&nbsp;&nbsp;Subfolder<br/>SPAM<br/>Trash</div>'
	+ '<div style="height:4px;line-height:4px;background-color:' + co.button + ';color:' + co.buttonText + ';overflow:hidden;font-size:5px;">Subject &nbsp; &nbsp; From &nbsp; &nbsp; To &nbsp; &nbsp; Received</div>'
	+ '<div style="height:40px;background-color:' + co.innerWindow + ';color:' + co.innerWindowText + ';overflow:hidden;font-size:4px;">'
	+ '<div style="height:5px;line-height:5px;">From geocar, Subject netMail Test</div>'
	+ '<div style="height:5px;line-height:5px;background:' + co.hilight + ';color:' + co.hilightText + ';">From bob,</div>'
	+ '<div style="height:5px;line-height:5px;">From geocar, Subject of fish sticks</div>'
	+ '<div style="height:5px;line-height:5px;">From geocar, Subject</div>'
	+ '</div>'
	+ '<div style="height:16px;line-height:5px;background-color:' + co.window + ';color:' + co.windowText + ';overflow:hidden;font-size:4px;">'
	+ '<b>From</b> Bob<br/><b>To</b> Bob<br/><b>Subject</b> I like Previews!<br/>'
	+ '</div>'
	+ '<div style="height:40px;background-color:' + co.innerWindow + ';color:' + co.innerWindowText + ';overflow:hidden;font-size:4px;">'
	+ '<div style="background-color:' + co.info + ';color:' + co.infoText + ';margin:2px;">Info Text</div>'
	+ 'Lorem ips consectetuer adipit. sent vestibulum mo l. Aenean ummrerit mauipit varius mi. Lorem ips consectetuer adipit. sent vestibulum mo l.<br/> <br/>'
	+ 'Lorem ips consectetuer adipit. sent vestibulum mo l. Aenean ummrerit mauipit varius mi.<br/>'
	+ '</div>'
	+ '<div style="clear:left;height:4px;line-height:4px;background-color:' + co.window + ';font-size:3px;font-weight:bold;color:' + co.windowText + ';overflow:hidden;">status line</div>'
	+ '</div>';
}

function recolorsite$() {
	setup_colors$();

	if (WANT('font_app') != '') {
		LAYOUT.style.fontFamily = WANT('font_app');
	} else {
		LAYOUT.style.fontFamily = '';
	}
	if (window._can_canvas) {
		var x1 = document.getElementById('x1');
		if (!x1) {
			x1 = document.createElement('canvas');
			x1.id = 'x1';
			document.body.insertBefore(x1, document.body.firstChild);
		} else {
			x1.parentNode._important=true;
			x1.getContext('2d').clearRect(0, 0, x1.getAttribute('width'), x1.getAttribute('height'));
		}

		x1.style.display='';
		x1.className = 'noprint';
		x1.style.position='absolute';
		x1.style.top = '0px';
		x1.style.left = '0px';
		x1.style.width = '';
		x1.style.height = '';

		var co = COLOR.window.split(" ");
		if (co.length == 1) co[1] = co[0];
		document.body.style.backgroundColor = co[1];
		document.documentElement.style.backgroundColor = co[1];

		x1.style.zIndex = '0';
		LAYOUT.style.zIndex = '1';
	} else {
		inset$(VIEWLIST);
		inset$(BOXLIST);
	}
	inset$(TREELIST);

	BGCOLOR(LAYOUT,COLOR.window);
	BGCOLOR(ATTPICK,COLOR.window);
	FGCOLOR(ATTPICK,COLOR.windowText);
	BGCOLOR(TOOLBAR,COLOR.window);
	HGRAB.style.backgroundColor=FIRST$(COLOR.window);
	VGRAB.style.backgroundColor=FIRST$(COLOR.window);
	BGCOLOR(STATUSBOX,COLOR.info);
	FGCOLOR(STATUSBOX,COLOR.infoText);
	STATUSBOX.style.border = '1px solid ' + COLOR.infoText;
	BGCOLOR(ATTLIST,COLOR.menu);
	FGCOLOR(ATTLIST,COLOR.menuText);
	ATTLIST.style.border = '1px outset ' + COLOR.menu;
	BGCOLOR(EXTOOL,COLOR.menu);
	FGCOLOR(EXTOOL,COLOR.menuText);
	EXTOOL.style.border = '1px outset ' + COLOR.menu;
	BGCOLOR(POPLIST,COLOR.menu);
	FGCOLOR(POPLIST,COLOR.menuText);
	POPLIST.style.border = '1px outset ' + COLOR.menu;
	BGCOLOR(NEWLIST,COLOR.menu);
	FGCOLOR(NEWLIST,COLOR.menuText);
	NEWLIST.style.border = '1px outset ' + COLOR.menu;

	var j;
	for (j = 0; j < window._html_mailboxes.length; j++) {
		var mb = window._html_mailboxes[j];
		FGCOLOR(mb,COLOR.innerWindowText);
		BGCOLOR(mb,COLOR.innerWindow);
		mb.style.borderTop = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderLeft = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderRight = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
	}

	for (j = TOOLBAR.firstChild; j; j = j.nextSibling) {
		if (j.tagName && j.tagName.toUpperCase() == 'A') {
			outset$(j);
			if (COLOR.button) {
				BGCOLOR(j,COLOR.button);
				FGCOLOR(j,COLOR.buttonText);
			} else {
				BGCOLOR(j,COLOR.window);
				FGCOLOR(j,COLOR.windowText);
			}
		}
	}
}

function layoutbuilder$(subwindow) {
	setup_colors$();

	document.onkeypress = _ku;
	document.onkeydown = _kh;
	document.onkeyup = _ku;

	if (!window._labelcolors['Personal']) {
		window._labelcolors['Personal'] = _labelcolors_pick();
	}
	if (!window._labelcolors['Work']) {
		window._labelcolors['Work'] = _labelcolors_pick();
	}

	EXTOOL_BUTTON = ungrey$(tool(RSRC$('images/arrow.png'), '', function() {
		if (EXTOOL._active && EXTOOL._active==true) return _hide_popups();
		window.setTimeout(function() {
			EXTOOL._active=true;
			EXTOOL.style.display = 'block';
			document.onclick = function() {
				window.setTimeout(function() {
					EXTOOL._active=false;
					document.onclick = true$;
					EXTOOL.style.display = 'none';
				},13);
				return false;
			};
		}, 20);
		return false;
	},11,24));

	LAYOUT = document.createElement('DIV');
	if (WANT('font_app') != '') {
		LAYOUT.style.fontFamily = WANT('font_app');
	} else {
		LAYOUT.style.fontFamily = '';
	}

	LAYOUT.id = 'layout';
	LAYOUT.style.visibility='hidden';
	resizeListen(LAYOUT,"0","0","pagewidth()", "pageheight()");
	window.onresize=_resizehandler;

	DRAG_IMAGE = imgtag$();
	DRAG_IMAGE.style.position = 'absolute';
	DRAG_IMAGE.style.zIndex = '12';
	DRAG_IMAGE.style.left = '-42px';
	DRAG_IMAGE.style.top = '42px';
	DRAG_IMAGE.width = '32';
	DRAG_IMAGE.height = '32';
	DRAG_IMAGE.className = 'noprint';
	LAYOUT.appendChild(DRAG_IMAGE);

	BLUR_TARGET = document.createElement('A');
	BLUR_TARGET.tabIndex = -1;
	BLUR_TARGET.href=nullhref();
	BLUR_TARGET.onclick=false$;
	BLUR_TARGET.style.position='absolute';
	BLUR_TARGET.style.top='-40px';
	BLUR_TARGET.style.left='40px';
	BLUR_TARGET.onfocus = _fix_status;
	BLUR_TARGET.onmouseover = _fix_status;
	BLUR_TARGET.onmouseout = _fix_status;
	BLUR_TARGET.className = 'noprint';
	LAYOUT.appendChild(BLUR_TARGET);

	var inv = document.createElement('IFRAME');
	inv.name = 'INVISIBLE';
	inv.setAttribute('name', 'INVISIBLE');
	inv.style.position = 'absolute';
	inv.src = 'about:blank';
	inv.style.top = '0px';
	inv.style.left = '-40px';
	inv.style.width = '2px';
	inv.style.height = '2px';
	inv.tabIndex = -1;
	LAYOUT.appendChild(inv);

	LAYOUT.appendChild(document.createTextNode(''));
	document.body.insertBefore(LAYOUT,document.body.firstChild);

	ATTPICK = document.createElement('BUTTON');
	ATTPICK.style.display='none';
	ATTPICK.style.zIndex = '3';
	ATTPICK.style.position = 'absolute';
	ATTPICK.style.border = 'none';
	ATTPICK.style.padding = '0px';
	ATTPICK.style.margin = '0px';

	EXTOOL_BUTTON.style.position = 'absolute';
	EXTOOL_BUTTON.style.zIndex = '2';
	EXTOOL_BUTTON.style.top = '4px';
	EXTOOL_BUTTON.style.right = '22px';
	EXTOOL_BUTTON.className = 'noprint';
	EXTOOL_BUTTON.style.display = 'none';
	LAYOUT.appendChild(EXTOOL_BUTTON);

	THROBBER = document.createElement('IMG');
	THROBBER.src=RSRC$('images/throbber-idle.png');
	THROBBER.style.position = 'absolute';
	THROBBER.style.zIndex = '2';
	THROBBER.style.top = (parseInt(tbheight/2)-8) + 'px';
	THROBBER.style.right = '3px';
	THROBBER.onmousedown = function(e) { return PD$(E$(e)); };
	THROBBER.width = '16';
	THROBBER.height = '16';
	THROBBER.className = 'noprint';
	THROBBER.ondblclick = function(e) {
		e=E$(e);
		if (e.ctrlKey || (e.modifiers && (e.modifiers & 2)))
			start$splash();
	};
	LAYOUT.appendChild(THROBBER);

	firstaction$.active = undefined;

	TOOLBAR = document.createElement('DIV');

	TREELIST = document.createElement('DIV');
	HGRAB = document.createElement('A');
	HGRAB.tabIndex = -1;
	VGRAB = document.createElement('A');
	VGRAB.tabIndex = -1;
	BOXLIST = document.createElement('DIV');
	VIEWLIST = document.createElement('DIV');

	TOOLBAR.style.whiteSpace = 'nowrap';
	TOOLBAR.style.cursor = 'default';
	TREELIST.style.cursor = 'default';
	BOXLIST.style.cursor = 'default';

	HGRAB.style.display='block';
	VGRAB.style.display='block';

	HGRAB.style.cursor='col-resize';
	VGRAB.style.cursor='row-resize';

	VGRAB.onmouseover = _fix_status;
	HGRAB.onmouseover = _fix_status;

	var i;
	resizeListen(TOOLBAR,"0","0","pagewidth()",tbheight);
	if (subwindow) {
		HGRAB._position = -parseInt(framewidth);
		VGRAB._position = tbsheight()-parseInt(framewidth); //will hide properly
	} else {
		HGRAB._position=parseInt(pagewidth()/5);
		resizeListen(TREELIST,"0",tbheight,"HGRAB._position","pageheight()-"+tbheight);
		resizeListen(HGRAB,"HGRAB._position", tbheight, framewidth, "pageheight()-"+tbheight);
		VGRAB._position=parseInt(pageheight()/2);
		resizeListen(BOXLIST,"HGRAB._position+"+framewidth, "tbsheight()", "pagewidth()-(HGRAB._position+"+framewidth+")", "VGRAB._position-tbsheight()");
		resizeListen(VGRAB,"HGRAB._position+"+framewidth, "VGRAB._position", "pagewidth()-(HGRAB._position+"+framewidth+")", framewidth);
	}
	resizeListen(VIEWLIST,"HGRAB._position+"+framewidth, "VGRAB._position+"+framewidth, "pagewidth()-(HGRAB._position+"+framewidth+")", "pageheight()-(VGRAB._position+"+framewidth+")");
	VGRAB.style.lineHeight=framewidth+'px';
	HGRAB.appendChild(document.createTextNode(''));
	VGRAB.appendChild(document.createTextNode(''));

	HGRAB.style.zIndex=4;
	VGRAB.style.zIndex=4;

	var th = parseInt(tbheight);
	if (!subwindow) {
		drag$(HGRAB, function(x,y) {
			if (x < 0) x = 0;
			if (x > pagewidth()) x=pagewidth();
			HGRAB._position=x;
			HGRAB.style.left=x+'px';
		});
		drag$(VGRAB, function(x,y) {
			if (!window._drag) th = tbsheight();
			if (y < th) y = th;
			if (y >= pageheight()) y=pageheight();
			VGRAB._position=y;
			VGRAB.style.top=y+'px';
		});
	}

	TOOLBAR.className = 'noprint';
	ATTPICK.className = 'noprint';
	TREELIST.className = 'noprint';
	HGRAB.className = 'noprint';
	VGRAB.className = 'noprint';
	BOXLIST.className = 'noprint';
	LAYOUT.appendChild(TOOLBAR);
	LAYOUT.appendChild(ATTPICK);
	LAYOUT.appendChild(TREELIST);
	LAYOUT.appendChild(HGRAB);
	LAYOUT.appendChild(BOXLIST);
	LAYOUT.appendChild(VGRAB);
	VIEWLIST.id = 'printme';
	LAYOUT.appendChild(VIEWLIST);

	TREELIST.style.overflow='auto';
	window._html_mailboxes = [];

	TOOLBAR.style.padding = '4px';

	STATUSBOX = document.createElement('DIV');
	STATUSBOX.style.zIndex = '4';
	STATUSBOX.style.cursor = 'default';
	STATUSBOX.onclick = function() { notice$(''); };
	STATUSBOX.style.display = 'none';
	STATUSBOX.style.position = 'absolute';
	STATUSBOX.style.padding = '1px';
	STATUSBOX.className = 'noprint';
	LAYOUT.appendChild(STATUSBOX);

	ATTLIST = document.createElement('DIV');
	ATTLIST.style.position = 'absolute';
	ATTLIST.style.zIndex = '5';
	ATTLIST.style.display = 'none';
	ATTLIST.className = 'noprint';
	LAYOUT.appendChild(ATTLIST);

	EXTOOL = document.createElement('DIV');
	EXTOOL.style.display = 'none';
	EXTOOL.style.position = 'absolute';
	EXTOOL.style.zIndex = '6';
	EXTOOL.style.top = (parseInt(tbheight)-4)+'px';
	EXTOOL.style.right = '4px';
	EXTOOL.className = 'noprint';
	LAYOUT.appendChild(EXTOOL);

	POPLIST = document.createElement('DIV');
	POPLIST.style.zIndex = '5';
	POPLIST.style.display = 'none';
	POPLIST.className = 'noprint';
	LAYOUT.appendChild(POPLIST);

	NEWLIST = document.createElement('DIV');
	NEWLIST.style.position = 'absolute';
	NEWLIST.style.top = (parseInt(tbheight)-4)+'px';
	NEWLIST.style.left = '4px';
	NEWLIST.style.width = '9em';
	NEWLIST.style.zIndex = '5';
	NEWLIST.style.display = 'none';
	function newlist_sep() {
		var dd = document.createElement('HR');
		dd.style.margin = '0';
		dd.style.padding = '0';
		dd.style.height = '2px';
		dd.style.lineHeight = '2px';
		NEWLIST.appendChild(dd);
	}
	function newlist_item(imgsrc, text, fn) {
		var da = document.createElement('A');
		da.tabIndex = -1;
		da.style.display = 'block';
		da.style.cursor = 'default';
		FGCOLOR(da,COLOR.menuText);
		BGCOLOR(da,COLOR.menu);
		da.style.paddingLeft = '1px';
		da.style.paddingRight = '4px';
		da.style.paddingTop = '2px';
		da.style.paddingBottom = '2px';
		da.style.textDecoration = 'none';
		da.appendChild(imgsrc$(imgtag$(), imgsrc, 16,16));

		var span = document.createElement('SPAN');
		span.style.paddingLeft='2px';
		span.appendChild(document.createTextNode(text));
		da.appendChild(span);

		da._fn = fn;
		da.onclick = function() {
			this._fn();
			blur$();
			return false;
		};
		da.href=nullhref();
		da.onmousedown = false$;
		da.onmouseover = function() {
			BGCOLOR(this,COLOR.hilight);
			FGCOLOR(this,COLOR.hilightText);
			var s = 'Create a new ' + this._text.toLowerCase() + '...';
			window.status = s;
			return true;
		};
		da.onmouseout = function() {
			_fix_status();
			BGCOLOR(this,COLOR.menu);
			FGCOLOR(this,COLOR.menuText);
			return true;
		};
		da._text = text;
		NEWLIST.appendChild(da);
		return da;
	}
	function _proto_folder(view, s1, s2, s3, icon) {
		newlist_item(RSRC$('images/' + icon + '.png'), s1, function() {
			_hide_popups();
			var fol = window.prompt('What do you want to call the new ' + s2 + '?', s3);
			if (fol && fol != '') {
				var i;
				var nfol = fol.toLowerCase();
				for (i = 0; i < window.mailboxes.length; i++) {
					var n = window.mailboxes[i];
					if (n.className) n = n.name;
	
					try {
						if (n.toLowerCase() == nfol) {
							window.alert("\""+fol+"\" already exists");
							return;
						}
					} catch(e) {};
				}
				try {
					httpmail.mailbox.create(fol, view);
				}catch(e) {
					window.alert("Server refused to create \""+fol+"\", please try again later");
					return;
				}
				add_container(window[view], fol, icon);
				try {
					TREELIST.scrollTop = TREELIST.scrollHeight;
				} catch(e) {};
			}
		});
	}
	newlist_item(RSRC$('images/stock_mail-compose.png'), 'Mail Message', function() {
		composer_op(0);
	}).setAttribute('ACCESSKEY', 'N');
	_proto_folder('mailview', 'Mail Folder', 'folder', 'New Folder', 'stock_folder');

	newlist_sep();
	newlist_item(RSRC$('images/stock_contact.png'), 'Contact', function() {
		contacteditor();
	});
	newlist_item(RSRC$('images/stock_contact-list.png'), 'Address Group', function() {
		var obj = {};
		obj._container = {};
		obj._container.role = 'MAILING-LIST';
		if (window._current_provider == 'contactsview') {
			obj._folder = window._current_folder;
		} else {
			obj._folder = 'Contacts';
		}
		contacteditor(obj);
	});
	_proto_folder('contactsview', 'Address Book', 'address book', 'New Folder', 'stock_addressbook');

	newlist_sep();
	newlist_item(RSRC$('images/stock_notes.png'), 'Note', function() {
		var obj = {};
		obj.title = '';
		obj.FORM = 'notesview';
		composer(obj);
	});
	if (UNSTABLE('planner')) {
		newlist_item(RSRC$('images/stock_new-appointment.png'), 'Appointment', function() {
			eventform();
		});
		newlist_item(RSRC$('images/stock_new-meeting.png'), 'Meeting', function() {
			meetform();
		});
	}

	NEWLIST.className = 'noprint';
	LAYOUT.appendChild(NEWLIST);

	function inittool() {
		while (TOOLBAR.firstChild) TOOLBAR.removeChild(TOOLBAR.firstChild);
		while (EXTOOL.firstChild) EXTOOL.removeChild(EXTOOL.firstChild);

		TOOLBAR._lastsep=undefined;
		firstaction$.active = undefined;

		EXTOOL_BUTTON.style.display = 'none';
		EXTOOL.style.display = 'none';
		EXTOOL._active=false;

		if (subwindow) return;

		NEWACTOR = tool(RSRC$('images/tools/stock_new.png'), 'New', false$);
		ungrey$(tool(RSRC$('images/arrow.png'), '', function() {
			if (NEWLIST._active && NEWLIST._active==true) return _hide_popups();
			NEWLIST._active=true;
			NEWLIST.style.display = 'block';
			window.setTimeout(function() {
				NEWLIST._active=true;
				NEWLIST.style.display = 'block';
				document.onclick = function() {
					window.setTimeout(function() {
						NEWLIST._active=false;
						document.onclick = true$;
						NEWLIST.style.display = 'none';
					},13);
					return false;
				};
			}, 20);
			return false;
		},11,24));
		toolsep();
	}
	function finishtool() {
		if (subwindow) return;

		toolsep();
		ungrey$(tool(RSRC$('images/tools/stock_print.png'), 'Print', function() {
			window.print();
		}));

		ungrey$(tool(RSRC$('images/tools/gnome-control-center.png'), 'Settings', function() {
			setupview();
		}));

		var logouttext = 'Logout';
		var logoutconfirm = 'Are you sure you want to log out of netMail?';
		if (document.domain.toLowerCase() == 'demo.internetconnection.net') {
			logouttext = 'Reset Demo';
			logoutconfirm = 'This will reset all folders and settings, continue?';
		}
		ungrey$(tool(RSRC$('images/tools/stock_exit.png'), logouttext, function() {
			if (confirm(logoutconfirm)) {
				document.cookie = 'AUTHORIZATION=; EXPIRES=Thu, 01-Jan-1970 00:00:00 GMT';
				if (document.domain.toLowerCase() == 'demo.internetconnection.net') {
					document.cookie = 'DEMO=; EXPIRES=Thu, 01-Jan-1970 00:00:00 GMT; PATH=/';
				}
				location.reload(false);
			}
		}));
		window.setTimeout(_resize_toolbar, 1);
		toolsep();
	}

	var did = {};
	function add_container(view,n,imgsrc,exact) {
		if (subwindow) return;
		if (did[n]) return;

		var j;
		var linein = 0;
		var lastdot;
		for (j = 0; j < n.length; j++) {
			if (n.substr(j,1) == '.') {
				linein++;
				lastdot = j;
			}
		}

		var mb = document.createElement('A');
		mb.tabIndex = -1;
		mb.href=nullhref();
		mb.style.cursor = 'default';
		mb._ident = n;
		mb._viewer = view;

		var zf = function(what) {
			if (!what) return false;
			what(n, this);
			return false;
		};
		if (view.accept) zf.can = view.accept;
		if (view.noMoveTo) zf.suppress_move=true;
		dragtarget$(mb,zf);

		var cg = document.createElement('SPAN');
		cg.style.fontSize = '90%';

		mb._status = cg;
		mb.setInfo = function(xq) {
			if (typeof xq != 'undefined' && xq != '') {
				if (typeof this._status_data != 'undefined'
				&& this._status_data == xq) return;

				this._status_data = xq;
				var azy = document.createTextNode('\xa0(' + xq + ')');
				if (this._status.firstChild) {
					while (this._status.firstChild.nextSibling)
						this._status.removeChild(this._status.firstChild);
					this._status.replaceChild(azy, this._status.firstChild);
				} else {
					this._status.appendChild(azy);
				}
				this._status.style.fontWeight = 'bold';
				this.style.fontWeight = 'bold';
			} else {
				if (!this._status_data) return;
				this._status_data = undefined;
				while (this._status.firstChild)
					this._status.removeChild(this._status.firstChild)
				this._status.style.fontWeight = '';
				this.style.fontWeight = '';
			}
		};

		mb.onmouseover = _fix_status;
		mb.onmousedown = false$;
		mb.onclick=function(e) {
			e = E$(e);
			if (e.clientX || e.clientY) {
				noticex = e.clientX;
				noticey = e.clientY;
			}

			icon_alert_cancel$();

			var j;
			var me = this._ident;
			for (j = 0; j < window._html_mailboxes.length; j++) {
				var nb = window._html_mailboxes[j];
				if (nb._ident != me) {
					FGCOLOR(nb,COLOR.innerWindowText);
					BGCOLOR(nb,COLOR.innerWindow);
				}
			}
			BGCOLOR(this,COLOR.hilight);
			FGCOLOR(this,COLOR.hilightText);

			// empty toolbar
			inittool();
			_searchbox_vis('');
			this._viewer(me);
			finishtool();

			blur$();
			return false;
		};
		FGCOLOR(mb,COLOR.innerWindowText);
		BGCOLOR(mb,COLOR.innerWindow);
		mb.style.paddingLeft = '1px';
		mb.style.paddingRight = '4px';
		mb.style.paddingTop = '1px';
		mb.style.paddingBottom = '2px';
		mb.style.margin = '2px';
		mb.style.textDecoration = 'none';
		mb.style.borderTop = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderLeft = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderRight = '1px solid ' + FIRST$(COLOR.innerWindow);
		mb.style.borderBottom = '1px dotted ' + FIRST$(COLOR.window);
		mb.style.whiteSpace = 'nowrap';
		mb.style.display='block';
		mb.setAttribute('unselectable','on');
		if (!exact && linein > 0) {
			var jy = document.createElement('SPAN');
			jy.appendChild(document.createTextNode('\xa0'));
			jy.style.display = INLINE_BLOCK;
			jy.style.width = (linein*16) + 'px';
			mb.appendChild(jy);
		}
		if (did['SPAM']) {
			if (!config.prefs || !config.prefs['hidefol:SPAM']) {
				// put it before the last child
				TREELIST.insertBefore(mb, did['SPAM']);
			}
		} else if (did['Trash']) {
			// put it before the last child
			TREELIST.insertBefore(mb, did['Trash']);
		} else {
			TREELIST.appendChild(mb);
		}
		did[n]=mb;

		if (imgsrc) imgsrc = RSRC$('images/'+imgsrc+'.png');
		else imgsrc = RSRC$('blank.gif');
		mb.appendChild(imgsrc$(imgtag$(), imgsrc, 16, 16));

		var span = document.createElement('SPAN');
		span.style.paddingLeft='2px';
		if (lastdot && !exact) {
			span.appendChild(document.createTextNode('...' + n.substr(lastdot+1, n.length-(lastdot+1))));
		} else if (config['FEED$title.' + n]) {
			span.appendChild(document.createTextNode(config['FEED$title.' + n]));
		} else {
			span.appendChild(document.createTextNode(n));
		}

		mb.appendChild(span);
		mb.appendChild(cg);
		window._html_mailboxes[ window._html_mailboxes.length ] = mb;
	}
	function add_mimeview(type, fnu) {
		// fnu is function pobj.fnu(drawtarget, summarytext)
		if (!window.mimeview) window.mimeview = {};
		var ka=(type?type+'':'').split('/');
		if (ka.length == 0 || ka.length > 2) throw "INTERNAL ERR";
		if (!window.mimeview[ ka[0] ]) window.mimeview[ka[0]] = {};
		var za = window.mimeview[ka[0]];
		if ((ka.length == 2 && (ka[1] == '*' || ka[1] == ''))  || ka.length==1) {
			za['*'] = fnu;
		} else {
			za[ka[1]] = fnu;
		}
	}

	// add_mimeview functions...
	add_mimeview('text/vcard', function(div,title) {
		_vcard_viewedit(div, this);
	});
	var plain_helper = _xh_bodypart_chunkhelper(function(body, data) {
		body.style.whiteSpace = 'pre';
		var g = data.split("\n");
		var i;
		for (i = 0; i < g.length; i++) {
			body.appendChild(urlexpand(g[i]));
			body.appendChild(document.createElement('BR'));
		}
	});
	add_mimeview('message/delivery-status', plain_helper);

	add_mimeview('message/external-body', function(div, title) {
		var obj = this;
		var ct;
		if (obj._message && !obj.multipart) {
			obj = obj._message;
			ct = obj.contenttype;
		} else {
			ct = obj.partContentType
		}

		if (!ct) return apply$(this, plain_helper, div,title);
		if (!ct.match(/access-type=URL/i)) {
			var za = ct.match(/access-type=([^;]*)/i);
			if (!za) {
				return apply$(this, plain_helper, div,title);
			}
			// fall through
		}
		var na = ct.match(/URL="(.[^"]*)"/i);
		if (!na) {
			return apply$(this, plain_helper, div,title);
		}

		var ha = document.createElement('DIV');
		BGCOLOR(ha,COLOR.info);
		FGCOLOR(ha,COLOR.infoText);
		ha.style.border = '1px solid ' + COLOR.infoText;
		ha.style.padding = '1px';
		ha.style.margin = '2px';

		if (UNSTABLE('planner') && na[1].match(/^webcal:/)) {
			var aa = document.createElement('A');
			aa.href = nullhref();
			aa._feedurl = na[1];
			FGCOLOR(aa,COLOR.infoText);
			aa.style.textDecoration = 'none';
			aa.style.display = 'block';
			var img = imgsrc$(imgtag$(), RSRC$('images/stock_web-calendar.png'), 16,16);
			img.setAttribute('VALIGN', 'bottom');
			aa.onclick = function(e) {
				apply$(_calfeed_popf, _drop_may_popup, e,
						this,
						_attachment_tailf);
				blur$();
			};
			linkstatus$(aa, na[1]);
			aa.appendChild(img);
			if (_cal_issub(na[1])) {
				aa.appendChild(document.createTextNode('\xa0This is a calendar that you are already subscribed to'));
			} else {
				aa.appendChild(document.createTextNode('\xa0This is a calendar that you can have netMail subscribe to'));
			}
			ha.appendChild(aa);
			div.appendChild(ha);
		} else {
			var aa = document.createElement('A');
			aa.href = na[1];
			aa.target = '_new';
			aa.style.textDecoration = 'none';
			aa.style.display = 'block';
			FGCOLOR(aa,COLOR.infoText);
			aa.appendChild(document.createTextNode('This is an external URL: ' + na[1]));
			linkstatus$(aa, na[1]);
			ha.appendChild(aa);
			div.appendChild(ha);
		}
		return apply$(this, plain_helper, div,title);
	});


	if (!subwindow) {
		add_container(mailview, 'INBOX', 'stock_inbox');
		if (UNSTABLE('planner')) {
			add_container(planview, 'Planner', 'stock_calendar');
		}
		add_container(contactsview, 'Contacts', 'stock_addressbook');
		add_container(sentmailview, 'Drafts', 'stock_folder');
		add_container(notesview, 'Notes', 'stock_notes');
		add_container(sentmailview, 'Sent Items', 'stock_outbox');
		add_container(mailview, 'Trash', 'stock_delete');
		if (!config.prefs || !config.prefs['hidefol:SPAM'])
			add_container(mailview, 'SPAM', 'stock_spam');
		var qxre = /^\/*((feed|rss|rdf|atom):)?https?:\/\//i;
		var exts = [];
		var rest = [];
		for (i = 0; i < window.mailboxes.length; i++) {
			var nm = window.mailboxes[i];
			if (nm.className) {
				if (nm.className != 'mailview') {
					exts[exts.length] = nm;
					continue;
				}
				nm = nm.name;
			}
			if (config.prefs && config.prefs['hidefol:'+nm])
				continue;
			if (qxre.exec(nm)) {
				add_container(rssview, nm, 'stock_news', true);
			} else {
				rest[rest.length] = nm;
			}
		}
		for (i = 0; i < exts.length; i++) {
			var nh = exts[i];
			var vv = window[ nh.className ];
			if (!vv) {
				rest[rest.length] = nh.name;
				continue;
			}
			add_container(vv, nh.name, vv.containerIcon);
		}
		for (i = 0; i < rest.length; i++) {
			add_container(mailview, rest[i], 'stock_folder');
		}
	}

	layoutbuilder$._fixme = function() {
		hideLIST$();
		inittool();
		_searchbox_vis('');
		finishtool();

		recolorsite$();
	};
	layoutbuilder$._fixme();

	LAYOUT.style.visibility='visible';
	opacity$(LAYOUT,1.0);

	resizeHelper(_resize_toolbar);
	if (window.LICENSE && status$ && status$.current && status$.current == '') status$(window.LICENSE);
}
function viewwindow$(ng,gf) {
	if (!RUNNING) return false; // mur?
	var p = window;
	while (p._parentWindow && p._parentWindow != p) p = p._parentWindow;
	var rfs='';
	if (p.VWIDTH && p.VHEIGHT) {
		rfs = ',width='+p.VWIDTH+',height='+p.VHEIGHT;
	}

	var cn = arguments.callee._callnumber;
	if (!cn) cn=0;
	arguments.callee._callnumber = cn+1;
	var nd = new Date();
	var name = '_view_window'+cn+'_'+nd.getMilliseconds();
	var o = window.open('', name, 'menubar=no,toolbar=no,status=yes,location=no,resizable=yes'+rfs);
	o.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	o.document.writeln('<?xml version="1.0" encoding="UTF-8"?>');
	o.document.writeln('<html><head><title></title>');
	o.document.writeln('<span id="favicon"><link rel="SHORTCUT ICON" href="favicon.ico" /></span><style type="text/css">');
	o.document.writeln('html,body{margin:0;padding:0;overflow:hidden;}');
	o.document.writeln('body.busy,body.busy a,body.busy div,body.busy input,body.busy img,body.busy span {cursor:wait !important;}');
	o.document.writeln('@media print {');
	o.document.writeln('body.ready #layout .noprint,body.busy #layout .noprint { display: none !important; }');
	o.document.writeln('body.ready #layout #printme,body.busy #layout #printme {');
	o.document.writeln('border: none !important;');
	o.document.writeln('position: static !important;');
	o.document.writeln('width: 100% !important; height: auto !important;');
	o.document.writeln('overflow: visible !important;');
	o.document.writeln('}');
	o.document.writeln('html.ready,body.ready,html.busy,html.busy{ overflow:visible !important;height: auto !important; }');
	o.document.writeln('body.ready,body.ready #layout,body.busy,body.busy #layout { position: static !important; background: inherit !important;height: auto !important; overflow:visible !important; }');
	o.document.writeln('body.ready .unbox,body.busy .unbox { position: static !important; overflow: visible !important; height: auto !important; }');
	o.document.writeln('}');
	o.document.writeln('</style>');
	if (window.NME && window.NME != false) {
		o.document.writeln('<script>');
		o.document.writeln(window.NME);
		o.document.writeln('</'+'script>');
	} else {
		o.document.writeln('<script src="nme.js"></'+'script>');
	}
	o.document.writeln('</head><body onload="window.setTimeout(function() { window._finish_load(); },10);"><i>\xa0<b>\xa0</b></i><div style="height:100%;">\xa0</div><script>');
	o.document.writeln('window._finish_load_spring1 = function() { window.focus(); layoutbuilder$(true); };');
	o.document.writeln('window._finish_load_spring2 = function() { document.body.className="ready";if(document.documentElement)document.documentElement.className="ready";var ez = window[window._current_provider]; ez.view(); _ungrey_tools(); _add_printbutton()};');
	o.document.writeln('</'+'script><script>');
	o.document.writeln(window.VI);
	o.document.writeln('</'+'script></body></html>');
	o._finish_load = function() {
		// copy over everything done by main$()
		this.FAVICON = false;
		this._parentWindow = window;

		this.NME = window.NME;
		this.VI = window.VI;
		this.COLOR = window.COLOR;
		this.LIMIT = window.LIMIT;
		this.BASE_HREF = window.BASE_HREF;
		this.INLINE_BLOCK = window.INLINE_BLOCK;
		this._can_canvas=window._can_canvas;

		this.httpmail = window.httpmail;

		this.sbwidth = window.sbwidth;
		this.tbheight = window.tbheight;
		this.framewidth = window.framewidth;

		this.logged_in = window.logged_in;
		this.config = window.config;

		this.mailboxes = window.mailboxes;

		this._name = name;
		this.default_pref['my_email'] = window.default_pref['my_email'];
		this.default_pref['my_name'] = window.default_pref['my_name'];

		this._labelcolors = window._labelcolors;
		this._labelhide = window._labelhide; // eh?

		if (ng) {
			this._current_provider = ng;
		} else {
			this._current_provider = window._current_provider;
		}
		this._current_folder = window._current_folder;
		this.folunseen = window.folunseen;
		this.folview = window.folview;
		this.__selected_object = window.__selected_object;
		this.folcache = window.folcache;
		this.folsize = window.folsize;

		// start$()
		(function(spring) {
			window.setTimeout(function() {
				if (spring && spring._finish_load_spring1) {
					spring._finish_load_spring1();
					window.setTimeout(function() {
						spring._finish_load_spring2();
					}, 10);
				}
			}, 10);
		})(this);
	};
	if (gf) gf(o);
	var c_nf;
	if (window._current_provider) c_nf = window._current_provider;
	(function(nf) {
		onclose$(o, function() {
			if (nf == 'contactsview' || WANT('auto_contacts')) {
				reload_contacts();
			}

			if (!window._current_folder) return;
			_zapcache(window._current_folder, true);
		});
	})(c_nf);
	window.setTimeout(function() {
		o.document.close();
	}, 10);
	return o;
}
function start$splash() {
	setup_colors$();
	window.status = '\xa0 ';

	while (VIEWLIST.firstChild) VIEWLIST.removeChild(VIEWLIST.firstChild);
	ATTPICK.style.display = 'none';
	_searchbox_vis('');

	var xtc = dom_autocomplete;
	if (xtc && xtc._boundto) {
		xtc.style.display='none';
		xtc._eatme=-1;
	}

	hideLIST$();
	window._current_view = '';
	window._current_provider = '';
	window.__lv2 = undefined;
	window.__pv2 = undefined;
	if (!window._name) {
		window._current_folder = '';
	}

	document.title = 'netMail';

	if (window.INTROTEXT) {
		update_view3m(window.INTROTEXT);
	} else {
		update_view3m('<div style="padding-left:4px;font-family:sans-serif;">If you are reading this then <tt>intro.html</tt> is missing from your netMail distribution.</div>');
	}
	if (window.LICENSE && status$ && status$.current && status$.current == '') status$(window.LICENSE);
	if (layoutbuilder$ && layoutbuilder$._fixme)
		layoutbuilder$._fixme();
	window.setTimeout(function() {
		recolorsite$();
	}, 10);
}
function start$() {
	var wasr=RUNNING;
	RUNNING=true;
	layoutbuilder$(false);
	start$splash();

	var ng;
	for (ng = document.body.firstChild.nextSibling; ng; ng = ng.nextSibling) {
		if (ng.tagName && !ng._important) {
			ng.style.backgroundColor='#fff';
			ng.style.visibility='hidden';
/*@cc_on @*/
/*@if (1) {
			ng.runtimeStyle.visibility='hidden';
}
@end @*/
		}
	}

	BGCOLOR(document.body,COLOR.window);//xxx
	document.body.className = 'ready';

	if (document.documentElement) document.documentElement.className = 'ready';

	_update_mail_containers();
	icon_alert_cancel$();
	if (wasr != true) {
		ping_monitor$();
	}
}
function _favstrobe_fn() {
	var nf = _favstrobe_fn;
	if (!nf._glowpos) nf._glowpos = 0;
	var s = 'glow0' + nf._glowpos + '.ico';
	nf._glowpos++;
	if (nf._glowpos > 5) nf._glowpos = 0;
	FAVICON.innerHTML = '<link rel="SHORTCUT ICON" href="' + RSRC$('strobe/'+s) + '" /><link rel="icon" href="' + RSRC$('strobe/'+s) + '" />';
			
}
function icon_alert_cancel$() {
	if (!FAVICON || FAVICON == false) return;
	if (icon_alert$.strobee) window.clearInterval(icon_alert$.strobee);

	FAVICON.innerHTML = '<link rel="SHORTCUT ICON" href="' + RSRC$('strobe/glow00.ico') + '" /><link rel="icon" href="' + RSRC$('strobe/glow00.ico') + '" />';
}
function icon_alert$() {
	if (icon_alert$.strobee) window.clearInterval(icon_alert$.strobee);
	if (FAVICON && FAVICON != false) icon_alert$.strobee = window.setInterval(_favstrobe_fn, 100);
}
function can_java$() {
	return false; /* todo */
}
function sound_alert$() {
//	try { document.applets['services'].alert(); } catch(e) {};
}

function ping_monitor$() {
	if (window._name) return;
	if (!ping_monitor$._ov) ping_monitor$._ov = {};

	var tl = 15000;

	window.setTimeout(function() {
		if (!ping_monitor$) return;
		if (!window || window.closed || !window.folview) return;

		var i;
		if (typeof window._viewoptions != 'undefined') {
			for (i in window._viewoptions) {
				try { ping_monitor$(); } catch(e) {};
				// try again later...
				return;
			}
		}

		var tp = [];
		for (i in window.folview) {
			tp[tp.length] = i;
		}
		var tq;
		httpmail.mailbox.onerror = false$;
		try {
			tq = httpmail.mailbox.ping(tp);
		} catch(e) {};

		var tx = [];
		if (tq && tq.length) {
			var ca=false;
			var za=false;

			for (i=0; i < tp.length; i++) {
				var xy = tp[i];
				var zed = tq[i];
				var v = ping_monitor$._ov[xy]||0;
				if (zed && v && v > 1 && v != zed) {
					ca=true;
					tx[tx.length]=xy;
				}
				if (zed) {
					ping_monitor$._ov[xy] = zed;
				}
			}
			for (i=0; i < tx.length; i++) {
				_zapcache(tx[i], true);
			}
			if (ca == true) {
				if (WANT('alert_icon')) {
					icon_alert$();
				}
				if (WANT('alert_sound')) {
					sound_alert$();
				}
				_update_mail_containers();
			}
		}
		try { ping_monitor$(); } catch(e) {};
	}, tl);
}
function busy$() {
	if (!busy$.level) busy$.level=0;
	if (THROBBER && busy$.level == 0) {
		if (busy$._timeout) window.clearTimeout(busy$._timeout);
		busy$._timeout = window.setTimeout(function() {
			THROBBER.src = RSRC$('images/throbber-anim.gif');
			if (RUNNING) {
				document.body.className = 'busy';
				if (document.documentElement)
					document.documentElement.className = 'ready';
			}
		}, 2000);
	}
	busy$.level++;
}
function unbusy$() {
	busy$.level--;
	if (THROBBER && busy$.level == 0) {
		if (busy$._timeout) {
			window.clearTimeout(busy$._timeout);
			busy$._timeout = undefined;
		}
		THROBBER.src = RSRC$('images/throbber-idle.png');
		if (RUNNING) {
			document.body.className = 'ready';
			if (document.documentElement)
				document.documentElement.className = 'ready';
		}
	}
}
function linkstatus$(o, s) {
	if (typeof s == 'undefined') s = '';
	o.onmouseover = function(e) {
		window.status = s;
		return true;
	};
	o.onmouseout = _fix_status;
}
function _fix_status(e) {
	if (typeof status$ != 'undefined') {
		if (typeof status$.current != 'undefined') {
			window.status = status$.current;
		} else {
			window.status = '';
		}
	} else {
		window.status = '';
	}
	return true;
}
function status$(s) {
	if (!s) s = '';
	if (s == '' && !RUNNING) return;
	if (s == '') s = ' \xa0 ';

	if (!RUNNING) {
		var z = document.getElementById('z');
		if (z) {
			while (z.firstChild) z.removeChild(z.firstChild);
			z.appendChild(document.createTextNode(s));
			return;
		}
	}

	status$.current = s;
	window.defaultStatus = s;
//	try { if (document.applets && document.applets.services)
//		document.applets['services'].defaultStatus(s); } catch(e) {};
	window.status = s;

	if (THROBBER) {
		THROBBER.title = s;
		THROBBER.alt = s;
	}
}
function _preload_helper() {
	preload$.qq.append(function() {
		var f = preload$._fini;
		if (!preload$._fini) return;
		if (preload$.imgcount > 0) return;
		if (f._fini_complete) return;

		f();
		f._fini_complete=true;
	});
}
function preloadFinish$(f) {
	preload$._fini = f;
	_preload_helper();
}
function preloadSetup$() {
	preload$.qq = new Queue();
	preload$.imgcount = 0;
}
function preload$(s, zz) {
	if (!s) return;

	var ext = s.substr(s.length-4, 4);
	if (!zz && (ext == '.png' || ext == '.jpg' || ext == '.ico' || ext == '.gif')) {
		preload$.imgcount++;
		var j = document.createElement('IMG');
		j.style.width = '1px';
		j.style.height = '1px';
		j.style.position = 'absolute';
		j.style.top = '0px';
		j.style.left = '-5px';
		j._want=true;
		document.body.appendChild(j);

		j.onload = j.onerror = j.onabort = function() {
			if (!this._serv) {
				this._serv=true;
				preload$.imgcount--;
			}
			if (preload$.imgcount < 5) {
				var aa = document.getElementsByTagName('IMG');
				var i;
				for (i = 0; i < aa.length; i++) {
					if (!aa[i]._want) continue;
					if (aa[i]._serv) continue;
				}
			}

			if (preload$.imgcount == 0) window.setTimeout(_preload_helper,10);
		};
		j.src = s;
	} else if (!zz && (ext == '.htm' || ext == '.html')) {
		// can't _reliably_ get notification
	} else if (!zz && (ext == '.css')) {
		// can't _reliably_ get notification
	} else {
		preload$.qq.insert(function() {
			preload$.qq.lock();
	
			try {
				var xh = XH();
				xh.open('GET', s, true);
				xh.onreadystatechange = function() {
					try {
						if (xh.readyState != 4) return;
						if (xh.status == 200 && zz) zz(xh.responseText);
					} catch(e) {};
					preload$.qq.unlock();
				};
				xh.send(undefined);
			} catch(ne) {
				preload$.qq.unlock();
			};
		});
	}
}
function opacity$(o,v){
/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
 	if (v >= 1.0) {
		o.runtimeStyle.filter = '';
		o.style.filter = '';
		return;
	}
  	v = parseInt(v*100);
	o.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+v+",Style=0)";
	return;
}
@end @*/
	try {
		if (v >= 1.0) v = '';
		o.style.opacity=v;
	} catch(e){};
}
function setup_colors$(ras) {
	window.COLOR = {};

	var ua = navigator.userAgent;
	var as = ras||WANT('colorscheme')||'';
	if (ua.indexOf('Wii') > -1) {
		// disable color schemes on the wii
		as = '';
	}

	if (as != '' && window.color_schemes && window.color_schemes[as]) {
		var f = window.color_schemes[as];
		if (typeof f == 'string') {
			// xxx not implemented
		}
		f();
		return;
	}
	// "browser default"
	if (ua.indexOf('Safari') > -1) {
		COLOR.info='#f7f3bd';
		COLOR.infoText='#000';

		COLOR.menu = '#f7f7f7';
		COLOR.menuText='#000';

		COLOR.window = '#efefef';
		COLOR.windowText='#000';

		COLOR.innerWindow = '#ffffff';
		COLOR.innerWindowText='#000';

		COLOR.grayText='#666';

		COLOR.hilight='#316dce';
		COLOR.hilightText='#ffffff';
		return;
	}
	COLOR.info='InfoBackground';
	COLOR.infoText='InfoText';
	COLOR.menu='Menu';
	COLOR.menuText='MenuText';
	COLOR.hilightText='HighlightText';
	COLOR.hilight='Highlight';
	COLOR.button = 'ButtonFace';
	COLOR.buttonText = 'ButtonText';
	if (ua.indexOf('Gecko') > -1 && ua.indexOf('Windows') == -1) {
		COLOR.innerWindow='white';
		COLOR.innerWindowText='black';
		COLOR.window='Window';
		COLOR.windowText='WindowText';
	} else {
		COLOR.innerWindow='Window';
		COLOR.innerWindowText='WindowText';
		COLOR.window='ButtonFace';
		COLOR.windowText='ButtonText';
	}
	COLOR.grayText='GrayText';
}
function main$() {

	const_httpmail();

	window.LICENSE='';
	if (window.top && window.top != window) {
		window.top.location.href = location.href;
		return;
	}
	if (window.parent && window.parent != window) {
		window.parent.location.href = location.href;
		return;
	}

	if (document.body && document.body.runtimeStyle) {
		/*
		window.onbeforeprint = function() {
			if (!window._name) {
				window._oldhgrab_pos = HGRAB._position;
				HGRAB._position = -(4*parseInt(framewidth));
				HGRAB.style.display = 'none';
			}
			_resizehandler();
			window._printing = true;
			VIEWLIST.position = 'static';
		};
		window.onafterprint = function() {
			if (!window._name) {
				HGRAB._position = window._oldhgrab_pos;
				HGRAB.style.display = 'block';
			}
			VIEWLIST.style.position = 'absolute';
			VIEWLIST.style.width = '';
			window._printing = undefined;
			_resizehandler();
		};
		*/
	}

	window.__selected_object=-1;

	FAVICON = document.getElementById('favicon');

	window._can_canvas=false;
	try {
		var cv = document.getElementById('x1');
		if (cv && cv.getContext && cv.getContext('2d')) {
			window._can_canvas=true;
		}
	} catch(e) {};

	var x=document.getElementById('x');
	opacity$(x,0.2);
	var cssextra='';
/*@cc_on @*/
/*@if (1) {
	x.runtimeStyle.visibility='visible';
   }
@end @*/
	x.style.visibility='visible';
	preloadSetup$();
	// load all the images we will need
	status$('Copyright ' + String.fromCharCode(0xa9) + ' 1998-2007, Internet Connection, Inc.');

	preload$('blank.gif');
	preload$(RSRC$('images/stock_inbox.png'));
	preload$(RSRC$('images/stock_mail-open.png'));
	preload$(RSRC$('images/stock_mail-flag-for-followup.png'));
	preload$(RSRC$('images/stock_mail-unread.png'));
	preload$(RSRC$('images/stock_mail-replied.png'));
	preload$(RSRC$('images/stock_mail-forwarded.png'));
	preload$(RSRC$('images/stock_addressbook.png'));
	preload$(RSRC$('images/stock_contact.png'));
	preload$(RSRC$('images/stock_contact-list.png'));
	preload$(RSRC$('images/stock_outbox.png'));
	preload$(RSRC$('images/stock_delete.png'));
	preload$(RSRC$('images/stock_calendar.png'));
	preload$(RSRC$('images/stock_folder.png'));
	preload$(RSRC$('images/stock_notes.png'));
	preload$(RSRC$('images/stock_attach.png'));
	preload$(RSRC$('images/stock_properties.png'));
	preload$(RSRC$('images/stock_news.png'));
	preload$(RSRC$('images/stock_web-calendar.png'));
	preload$(RSRC$('images/stock_macro-stop-watching.png'));
	preload$(RSRC$('images/stock_macro-watch-variable.png'));
	preload$(RSRC$('images/tools/stock_new.png'));
	preload$(RSRC$('images/stock_spam.png'));
	preload$(RSRC$('images/stock_mail-compose.png'));
	preload$(RSRC$('images/stock_new-appointment.png'));
	preload$(RSRC$('images/stock_new-meeting.png'));
	preload$(RSRC$('images/tools/stock_mail-reply.png'));
	preload$(RSRC$('images/tools/stock_mail-reply-to-all.png'));
	preload$(RSRC$('images/tools/stock_mail-forward.png'));
	preload$(RSRC$('images/tools/stock_contact.png'));
	preload$(RSRC$('images/tools/stock_trash_full.png'));
	preload$(RSRC$('images/tools/stock_mail-compose.png'));
	preload$(RSRC$('images/tools/stock_mail-send.png'));
	preload$(RSRC$('images/tools/stock_save.png'));
	preload$(RSRC$('images/tools/stock_not-spam.png'));
	preload$(RSRC$('images/tools/gnome-control-center.png'));
	preload$(RSRC$('images/tools/stock_undo-history.png'));
	preload$(RSRC$('images/tools/stock_attach.png'));
	preload$(RSRC$('images/tools/stock_spellcheck.png'));
	preload$(RSRC$('images/tools/stock_print.png'));
	preload$(RSRC$('images/tools/stock_folder.png'));
	preload$(RSRC$('images/tools/stock_spam.png'));
	preload$(RSRC$('images/tools/stock_exit.png'));
	preload$(RSRC$('images/tools/stock_calendar-view-day.png'));
	preload$(RSRC$('images/tools/stock_calendar-view-month.png'));
	preload$(RSRC$('images/tools/stock_calendar-view-work-week.png'));
	preload$(RSRC$('images/tools/stock_calendar-view-year.png'));
	preload$(RSRC$('images/tools/stock_view-html-source.png'));
	preload$(RSRC$('images/tools/stock_new-appointment.png'));
	preload$(RSRC$('images/arrow.png'));
	preload$(RSRC$('images/gtk-dnd-multiple.png'));preload$(RSRC$('images/gtk-dnd.png'));
	preload$(RSRC$('images/throbber-anim.gif'));
	preload$(RSRC$('images/throbber-idle.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-msword.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-pdf.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-rtf.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-vnd.ms-excel.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-vnd.ms-powerpoint.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-x-compress.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-x-shellscript.png'));
	preload$(RSRC$('images/mime/gnome-mime-audio-ac3.png'));
	preload$(RSRC$('images/mime/gnome-mime-application-x-sql.png'));
	preload$(RSRC$('images/mime/gnome-mime-text-html.png'));
	preload$(RSRC$('images/mime/gnome-mime-text-x-txt.png'));
	preload$(RSRC$('images/mime/gnome-mime-text-x-vcalendar.png'));
	preload$(RSRC$('images/mime/gnome-mime-text-x-vcard.png'));
	preload$(RSRC$('images/gnome-fs-directory.png'));
	preload$(RSRC$('images/stock_callout.png'));
	preload$(RSRC$('images/stock_copy.png'));preload$(RSRC$('images/stock_move.png'));preload$(RSRC$('images/stock_undo.png'));
	preload$(RSRC$('strobe/glow00.ico'));preload$(RSRC$('strobe/glow01.ico'));preload$(RSRC$('strobe/glow02.ico'));
	preload$(RSRC$('strobe/glow03.ico'));preload$(RSRC$('strobe/glow04.ico'));preload$(RSRC$('strobe/glow05.ico'));

	preload$('nme.css');preload$('vi.css');preload$('edit.htm');
	preload$('intro.html', function(q) { window.INTROTEXT=q; });
	preload$('vi.js', function(q) { window.VI=q; });

/*@cc_on @*/
/*@if (@_jscript_version >= 5) {
	preload$('nme.js', function(q) { window.NME=q; });
   }
@end @*/
	preloadFinish$(function() { document.title = 'netMail'; });

	if (document.domain.toLowerCase() == 'demo.internetconnection.net') {
		login$('demo-' + parseInt(1|(Math.random() * 65535)), 'demo');
	} else if (location.search && location.search.length > 3 && location.search.indexOf('&') == -1) {
		login$(LTRIM$(location.search, "?"));
	} else {
		document.getElementById('username').disabled=false;
		document.getElementById('password').disabled=false;
		document.getElementById('login').disabled=false;
		window.setTimeout(function() {
			try {
				document.getElementById('username').focus();
				document.getElementById('username').select();
			} catch(e) {};
		}, 10);
	}
}
function _pf_finish() {
/*@cc_on @*/
/*@if (@_jscript_version >= 5 && @_jscript_version < 7) {
	document.documentElement.style.backgroundImage = 'url(http://)';
	document.documentElement.style.backgroundAttachment = 'fixed';
  }
@end @*/
	var x=document.getElementById('x');
	// detect -moz-inline-box
	var gx = document.createElement('SPAN');
	gx.style.display='inline-block';
	gx.style.width = '42px';
	gx.style.height = '4px';
	document.body.appendChild(gx);

	var gy = document.createElement('DIV');
	gy.appendChild(document.createTextNode('foo'));
	gy.style.position = 'absolute';
	gy.style.top = '44px';
	gy.style.left = '-154px';
	gy.style.overflow = 'scroll';
	gy.style.width = '48px';
	gy.style.height = '48px';
	document.body.appendChild(gy);

	window.mailboxes = undefined;
	window._html_mailboxes = undefined;

	opacity$(x,0.4);
	status$('Connecting to message store');
	window.setTimeout(function() {
		if (gx) {
			if (gx.offsetWidth != 42) INLINE_BLOCK = '-moz-inline-box';
			gx.parentNode.removeChild(gx);
		}
		if (gy) {
			// size of a scroll bar
			window.sbwidth = gy.offsetWidth - gy.clientWidth;
			gy.parentNode.removeChild(gy);
		}

		httpmail.config.get.onreply = function(cf) {
			var cx = [];
			if (cf.wordlist) {
				var cj;
				for (cj in cf.wordlist) {
					cx[cx.length] = cf.wordlist[cj];
				}
			}
			cf.wordlist = cx;
			config = cf;
			if (!config.prefs || typeof config.prefs != 'object') config.prefs = {};
			default_pref['my_email'] = config['$user'] + '@' + config['$domain'];
			default_pref['my_name'] = config['$user'];

			opacity$(x,0.6);
			status$('Downloading folder list');

			window.folcache={};
			window.folsize={};
			window.folunseen={};
			window.folview={};

			httpmail.mailbox.list.onreply = function(ml) {
				window.mailboxes=ml;
				opacity$(x,0.8);
				status$('Connecting to address book provider');
				(function(baq) {
				 	_planmonth_initial(true$);
					(function(clo) {
					 	opacity$(x,1.0);
						baq.append(function() { baq.lock(); reload_contacts(clo); });
						baq.append(function() { baq.lock(); fetchview('Contacts', {}, clo); });
						baq.append(function() { baq.lock(); fetchview('Notes', {}, clo); });
						baq.append(function() { baq.lock(); fetchview('Drafts', {}, clo); });
						baq.append(function() { baq.lock(); fetchview('INBOX', {}, clo); });
						baq.append(function() {
							unbusy$();
							start$();
							update_news();
						});
					})(function() { baq.unlock(); });
				})(new Queue());
			};
			httpmail.mailbox.list();
		};
		httpmail.config.get();
	}, 10);
}
function _login_animate() {
	var h = document.getElementById('loginbox');
	if (!h._h) {
		h._h = h.offsetHeight;
	}

	h._pos = (h._pos||0) - (h._h / 10);
	h.style.top = parseInt(h._pos) + 'px';
	if (h._pos >= -h._h) {
		window.setTimeout(_login_animate, 50);
	}
}
function login$(u,p) {
	u=sed(u,/[@#&][^@#&]*$/,"");
	httpmail.license.onreply = function(sv) {
		if (!sv) {
			httpmail.license.onerror();
			return;
		}
		window.LICENSE=sv;

		preloadFinish$(_pf_finish);
		_login_animate();
	};

	status$('Attempting to log in...');
	document.getElementById('username').disabled=true;
	document.getElementById('password').disabled=true;
	document.getElementById('login').disabled=true;
	busy$();
	if (typeof p == 'undefined') {
		document.cookie = 'AUTHORIZATION=' + u;
		document.getElementById('username').value = u;
	} else {
		document.cookie = 'AUTHORIZATION=' + BASE64(u+':'+p);
		u = BASE64(u+':'+p);
		p = undefined;
	}
	httpmail.license();
}
function const_httpmail() {
	httpmail.mailbox.summary.onerror = function(e) {
		try {
			status$('');
			unbusy$();
			if (!fetchmail.qq.sizeof()) {
				if (RUNNING) {
					_update_mail_containers();
					update_listview();
				}
			}
		} catch(e) {};
		fetchmail.qq.unlock();
	};
	httpmail.message.structure.onerror = function(e) {
		status$('');
		unbusy$();
	};
	httpmail.config.get.onerror = function(e) {
		status$('Could not obtain configuration: '+e);
	};
	httpmail.license.onerror = function(s) {
		status$('Invalid username or password');
		document.getElementById('username').disabled=false;
		document.getElementById('password').disabled=false;
		try {
			document.getElementById('login').disabled=false;
			document.getElementById('password').value='';
		} catch(e) {};
		try {
			document.getElementById('username').focus();
			document.getElementById('username').select();
		} catch(e) {};
		unbusy$();
	};
	httpmail.mailbox.list.onerror = function(e) {
		status$('Could not obtain folder list: '+e);
	};
	httpmail.message.setFlags.onerror = function(e) {
		msg_flag_setto._busy--;
		if (msg_flag_setto._busy<0)
			msg_flag_setto._busy=0;
		status$('');
	};
	httpmail.calendar.fetch.onerror = function(e) {
		unbusy$();
		status$('');
		try { _planmonth.qq.unlock(); } catch(e2) {};
	};
	httpmail.mailbox.copyto.onerror = function(e) {
		unbusy$();
	};
	httpmail.mailbox.moveto.onerror = function(e) {
		unbusy$();
	};
}
