/* Uses Mootools to provide AJAX powered dependant drop downs for country/region selection */

function clearSelect(selectelement) {
	var select = $E('#' + selectelement);
	while (select.options.length > 0) {
    	select.options[0] = null;
	}
    var optionObject = new Option('- All -', '');
    select.options[0] = optionObject;
}

function updateSelect(selectelement, functionname, id) {
	// alert(selectelement + ' ' + functionname + ' ' + id);
	var select = $E('#' + selectelement);
	var url = '/ajax-functions.php?mode=' + functionname;
	new Ajax(url, {
		method:'post',
		data: 'id=' + id,
		onComplete: function(responseText, responseXML) {
			var options = responseXML.getElementsByTagName('option');
			var status = responseXML.getElementsByTagName('status');
			clearSelect(selectelement);
			if (status[0].firstChild.nodeValue == '1') {
				for (i = 0; i < options.length; i++) {
					var optionObject = new Option(options[i].firstChild.firstChild.nodeValue, options[i].attributes.getNamedItem('optionid').nodeValue);
				    select.options[select.options.length] = optionObject;
				}
			}
		}
	}).request();
}