function optInit() { sels = document.getElementsByTagName('select'); }
function pop(xml,obj) {
	var els = xml.getElementsByTagName('optgroup');
	for (var i=els.length-1; i>=0; i--) {
		if (els[i]) {
			var t = new Option('-','');
			var ops = document.getElementById(els[i].attributes[0].value);
			var init = ops.value;
			for (var j=ops.options.length; j>=0; j--) {
				ops.options[j] = null;
			}
			ops.options.length=0;
			var news = els[i].childNodes;
			ops.options[0]=t;
			for (var j=1; news[j-1]; j++) {
				var c = news[j-1].innerText || news[j-1].textContent || news[j-1].innerHTML || news[j-1].text;
				ops.options[j] = new Option(c,news[j-1].attributes[0].value);
				if (ops.options[j].value == init) { ops.options[j].selected = 'selected'; ops.options[j].defaultSelected='selected'; }
			}
		}
	}
}
function opts(obj) {
	if (sels.length) {
		var q = '?';
		for (var i=sels.length-1; i>=0; i--) {
			if (sels[i].value.length) { q+=sels[i].id+'='+sels[i].value+'&'; }
		}
		var xhr = new XMLHttpRequest;
		xhr.onreadystatechange = function() {
			switch(xhr.readyState) {
				case 4:
					if (xhr.status/100 == 2) { pop(xhr.responseXML,obj); } else { alert('XML HTTP request failed.\n\nStatus: '+xhr.status+' '+xhr.statusText); }
				break;
			}
		}
		xhr.open('GET','options.php'+q,true);
		xhr.send(null);
	}
}
function formRefresh(obj) {
	if (document.getElementById('autoRefresh').checked) {
		document.getElementById('louverForm').submit();
	} else { opts(obj); }
}

