

function complete_install()
{
	var lr = [ 'Left', 'Right', 'Top', 'Bottom' ];
	var sw = [ 'Width', 'Style', 'Color' ];
	var ai = document.getElementsByTagName('input');
	var awz = [];
	var i;
	var first = true;
	var key;
	for (i = 0; i < ai.length; i++) {
		var n = ai[i];
		if (n.type != 'text') continue;
		if (!n.getAttribute) continue;
		var ac = n.getAttribute('autocomplete');
		if (!ac) continue;

		if (ac.indexOf('?') == -1) {
			ac = ac + '?';
		} else {
			ac = ac + '&';
		}

		var exc = n.getAttribute('multi');
		if (exc == null || exc == '') exc = ',';

		var d = document.createElement('DIV');
		d.style.position = 'relative';
		d.style.padding = '0px 0px';
		d.style.margin = '0px 0px';
		d.style.overflowY = 'scroll';
		d.style.fontFamily = 'monospace';
		if (!document.all)
			d.style.overflow = '-moz-scrollbars-vertical';
		var css = document.getComputedStyle(n,null);
		var lri, swi;
		var allz = true;
		for (lri = 0; lri < lr.length; lri++) {
			for (swi = 0; swi < sw.length; swi++) {
				key = 'border' +  lr[lri]
					+ '' + sw[swi];
				if (css[key]) {
					allz = false;
					break;
				}
			}
		}

		if (allz) {
			n.style.borderLeft = '2px solid ThreeDShadow';
			n.style.borderTop = '2px solid ThreeDShadow';
			n.style.borderBottom = '2px solid ThreeDLightShadow';
			n.style.borderRight = '2px solid ThreeDLightShadow';
			css = document.getComputedStyle(n,null);
		}

		for (lri = 0; lri < lr.length; lri++) {
			for (swi = 0; swi < sw.length; swi++) {
				key = 'border' +  lr[lri]
					+ '' + sw[swi];
				if (n.style[key])
					d.style[key] = n.style[key];
				else
					d.style[key] = css[key];
			}
		}

		var bf = parseInt('0' + css.borderLeftWidth)
			+parseInt('0' + css.borderRightWidth);

		var wzf = function() {
			var nw = n.offsetWidth;
			d.style.width = (nw-bf) + 'px';
		};
		awz[awz.length] = wzf;
		wzf();

		bf = parseInt('0' + css.borderTopWidth);
		d.style.top = -bf;

		d.style.display = 'none';
		d.style.zindex = 300;
		d.style.cssFloat = 'left';
		d._lastdir = 0;

		d.cursor = 0;

		n.__searchbusy = false;
		n.__dbox = d;
		n.__lastresults = [];
		n.__lastsearch = '';
		n.__acurl = ac;

		var redraw = function(nx) {
			var d = nx.__dbox;
			var n = nx;
			var bv = n.value.toLowerCase();
			var av = '';

			var x = bv.lastIndexOf(exc);
			if (x > -1) {
				av = bv.substr(0, x+1);
				bv = bv.substr(x+1, (bv.length - x) - 1);
			}
			while (bv.substr(0, 1) == ' ') {
				av = av + ' ';
				bv = bv.substr(1, bv.length - 1);
			}

			var a = n.__lastresults;
			if (bv != '' && bv != n.__lastsearch
			&& (n.__lastsearch == '' || bv.substr(0,n.__lastsearch.length) != n.__lastsearch)) {

				var xh = XHTTP();
				if (xh) {
					a = [''];
					n.__lastsearch = bv;
					n.__searchbusy = true;

					xh.open('GET', n.__acurl
					+ 'q=' + escape(bv), true);
					xh.setRequestHeader('Accept', 'text/plain.subject');
					xh.onreadystatechange = function() {
						if (xh.readyState == 4) {
							n.__searchbusy = false;
							var t = xh.responseText;
							n.__lastresults = t.split('\n');
							redraw(n);
						}
					};
					xh.send(null);
				}
			}

			if (bv == '' || a.length == 0) {
				d.style.display = 'none';
				window.top._stopsubmit = false;
			} else if (n.__searchbusy) {
				window.top._stopsubmit = true;
				d.innerHTML = '<i>Searching...</i>';
				d.style.display = 'block';
			} else {
				while (d.childNodes.length > 0)
					d.removeChild(d.firstChild);

				var y = 0;
				var hy = 0;
				var hr = n.offsetHeight;
				for (x = 0; x < a.length; x++) {
					var str = a[x];
					var ss = str.toLowerCase().indexOf(bv)
					if (ss == -1) continue;

					hy = y;

					var r = document.createElement('DIV');
					r.style.margin = '0px 0px';
					r.style.padding = '0px 0px';
					r.style.height = hr;
					r.style.cursor = 'default';
					r.style.textOverflow = 'clip';
					r.style.fontFamily = css.fontFamily;
					r.style.fontSize = css.fontSize;
					r._text = str;

					if (d.cursor == y) {

						r.style.color = 'HighlightText';
						r.style.backgroundColor = 'Highlight';

						if (d._clicked) {
							d._clicked = false;
							n.blur();
							n.value = av + str + exc;
							n.form.elements[n.name] = n.value;
							n.focus();
							d.cursor = -1;
						}

					} else {
						r.style.backgroundColor = css.backgroundColor;
						r.style.color = css.color;
					}


					str = html_escape(str.substr(0, ss))
					+ '<u><b>' + html_escape(str.substr(ss, bv.length)) + '</b></u>'
					+ html_escape(str.substr(ss+bv.length));

					r.innerHTML = str;
					d.appendChild(r);
					y++;
				};

				if (d.cursor > hy) {
					d.cursor = hy;
					redraw(n);
				} else if (d.cursor == -1) {
					d.style.display = 'none';
					window.top._stopsubmit = false;
					d.cursor = 0;

				} else if (y) {
					if (y > 1) {
						d.style.height = (hr * 2) + 'px';
					} else {
						d.style.height = (hr) + 'px';
					}
					var nt;
					if (d.cursor > 1 && d._lastdir > 0) {
						nt = (d.cursor-1) * hr;
						if (d.scrollTop < nt) {
							d.scrollTop = nt;
						}
					} else if (d._lastdir < 0) {
						nt = (d.cursor) * hr;
						d.scrollTop = nt;
					}
					d.style.display = 'block';
					d.__nheight = hr;
					d.__nback = n;
					d.onmousedown = function(e) {
						if (!e) e = window.event;

						var t = 0;
						var o = this;
						while (o.offsetParent) {
							t += o.offsetTop;
							o = o.offsetParent;
						}
						var mt = (this.__nheight  * 2);
						if (e.clientY < t) return true;
						if (e.clientY > (t + mt)) return true;

						t = e.clientY - t;
						t /= this.__nheight;
						d.cursor = parseInt(t);
						d._lastdir = 0;
						d._clicked = true;
						if (this.__nback) {
							redraw(this.__nback);
						}
						return true;
					};
					window.top._stopsubmit = true;

				} else {
					window.top._stopsubmit = false;
					d.style.display = 'none';
					d.cursor = 0;
				}
			}
		};

		n.onkeydown = function(e) {
			if (!e) e = window.event;
			var k = (e.charCode ? e.charCode :
				((e.keyCode ? e.keyCode : e.which)));
			k = k + "";
			if (e.shiftKey || e.metaKey1Down) k = "s" + k;
			if (e.ctrlKey || e.metaKey2Down) k = "c" + k;
			if (e.altKey || e.metaKey3Down) k = "a" + k;
			if (e.metaKey4Down) k = "m" + k;

			if (k == '9' || k == '10' || k == '13') {
				var d = this.__dbox;
				d._clicked = true;
				redraw(this);
			} else if (k == '40' || k == '38') {
				if (window.top._stopsubmit) return false;
			}

			return true;
		};
		n.onkeyup = function(e) {
			if (!e) e = window.event;
			var k = (e.charCode ? e.charCode :
				((e.keyCode ? e.keyCode : e.which)));
			k = k + "";
			if (e.shiftKey || e.metaKey1Down) k = "s" + k;
			if (e.ctrlKey || e.metaKey2Down) k = "c" + k;
			if (e.altKey || e.metaKey3Down) k = "a" + k;
			if (e.metaKey4Down) k = "m" + k;

			var d = this.__dbox;
			var cancel = true;

			if (k == "40") {
				d.cursor++;
				d._lastdir = 1;
				cancel = false;
			} else if (k == "38") {
				d.cursor--;
				if (d.cursor < 0) d.cursor = 0;
				d._lastdir = -1;
				cancel = false;
			} else if (k == "9" || k == "10" || k == "13") {
				return false;
			}

			if (cancel) {
				if (e.preventDefault)
					e.preventDefault();
				if (e.stopPropagation)
					e.stopPropagation();
			}

			redraw(this);

			return cancel;
		};
		n.onchange = function(e) {
			redraw(this);
			return true;
		};

		if (n.nextSibling)
			n.parentNode.insertBefore(d, n.nextSibling);
		else
			n.parentNode.appendChild(d);

		if (first) {
			first = false;
			n.focus();
		}
		redraw(n);
	}
	var wz = window.onresize;
	window.onresize = function() {
		var i;
		for (i = 0; i < awz.length; i++) {
			var j =awz[i];
			j();
		}
		if (wz) wz();
	};

}
function strmap(s, a,b) {
	var i, j;
	for (j = 0; j < s.length; j++) {
		for (i = 0; i < a.length; i++) {
			if (s.charAt(j) == a[i]) {
				s = s.substr(0, j)
					+ b[i]
					+ s.substr(j+1);
				j += (b[i].length)-1;
				break;
			}
		}
	}
	return s;
}
function html_escape(e) {
	return strmap(e, [ "&", "<", "\"", ' ', ],
			[ "&amp;", "&lt;", "&quot;", "&nbsp;" ]);
}
