var req;

function loadclubs() {
	var city = document.forms[0].city;
	var cityid = city.options[city.selectedIndex].value;
	if (cityid >= 0) {
		req = GetXmlHttp();
		req.onreadystatechange = cb_loadclubs;
		if (req!=null){
			req.open("GET", 'rpc_clubs.php?city='+cityid, true);
			req.send(null);
		}
	}
}

function cb_loadclubs() {
	if (req.readyState == 4 && req.status == 200) {
		var club = document.forms[0].club;
		var all = req.responseText.split(',');
		var ids = new Array();
		var names = new Array();
		for (i=0; i<all.length; i++) {
			idx = Math.floor(i/2);
			if (0 == i%2) {
				ids[idx] = all[i];
			} else {
				names[idx] = all[i];
			}
		}
		substitute_options(club, ids, names, true);
	}
}

function substitute_options(select, values, labels, leave_first) {
	/* remove previous options */
	var len = Math.min(values.length, labels.length);
	var start = 0;
	var tmp_option;
	if (leave_first) {
		tmp_option = select.options[0];
	}
	select.options.length = 0;
	if (leave_first) {
		select.options[0] = tmp_option;
		start = 1;
	}
	for (i = start; i<len+start; i++)
		select.options[i] = new Option(labels[i-start], values[i-start]);
}
