function addLabelItems(req, container) {
    if (req.readyState != 4) return;
    if (req.status != 200 && req.status != 304) {
	// On error, don't do anything.
	alert('HTTP error ' + req.status);
	return;
    }

    var label_list_page = req.responseText;

    var start_key = "<!--START_LABEL_OUTPUT-->"
    var stop_key = "<!--STOP_LABEL_OUTPUT-->"

    var start_idx = label_list_page.indexOf(start_key, 0);
    if (start_idx > 0) start_idx += start_key.length;

    var end_idx = label_list_page.indexOf(stop_key, -1);

    var label_list = label_list_page.substring(start_idx, end_idx);

    container.innerHTML = label_list;
}

function getLabelItems(container) {
    var req = null;
    var url = "http://notes.komarix.org/cgi/label_lister"

    if (window.XMLHttpRequest) req = new XMLHttpRequest();
    else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");

    if (req != null) {
        req.open("GET", url, true);
	req.onreadystatechange = function () {
	    addLabelItems(req, container);
	}
	if (req.readyState == 4) return;
        req.send(null);
    }
}
