function makeOption(text, value) {
	if (typeof(window.Option) == 'function') {
		// netscape
		var opt = new Option(text, value);
	} else {
		// ie
		var opt = document.createElement('option');
			opt.value = value;
			opt.innerHTML = text;
	}
	return opt;
}

function ds_activate(ds, index, url) {
	if (index == '')
		return;

	if (typeof(ds) == 'string') {
		var lookup = document.getElementById(ds);
		if (lookup)
			ds = lookup;
		else
			return;
	}

	if (typeof(ds.dIndex) == 'undefined')
		ds.dIndex = '';

	if (ds.dIndex == index) {
		//alert('already active OR still activating');
		return;
	} else {
		//alert('activating ...' + this.dIndex + ' ' + index);

		if (typeof(ds.dStorage) == 'undefined') {
			// raw select
			ds.dStorage = new Object();

			var x = ds.firstChild;
			while(x) {
				var y = x.nextSibling;

				if ( typeof(x.value) != 'undefined' )
					if (x.value != '')
						ds.removeChild(x);

				x = y;
			};
		}

		if (ds.dIndex.length > 0) {
			// HIDE
			if (typeof(ds.dStorage[ds.dIndex]) != 'undefined')
				for(var i=0; i< ds.dStorage[ds.dIndex].length; i++)
					ds.removeChild(ds.dStorage[ds.dIndex][i]);

			ds.selectedIndex = 0;
		}

		ds.dIndex = index;

		if (typeof(ds.dStorage[ds.dIndex]) == 'undefined') {
			// ajax request
			if (typeof(ds.dAjax) == 'undefined')
				ds.dAjax = new Object();

			if (ds.dAjax[ds.dIndex] == true)
				return;

			var optionSet = new Array();
			var ds_dIndex = ds.dIndex;

			if (ds.style.border)
				var ds_oldStyle = ds.style.border;
			else
				var ds_oldStyle = '1px solid green';


			function local_handler(html) {
				var optiuni = html.split('&');

				for(var i=0; i< optiuni.length; i++) {
					var data = optiuni[i].split('*');
					if (data.length != 2) {
						if (ds.dIndex == ds_dIndex) {
							ds.dAjax[ds_dIndex] = false;
							ds.style.border = ds_oldStyle;
							ds.selectedIndex = 0;
							ds.dIndex = '';
						}
						return;
					}
					var opt = makeOption(data[0], data[1]);
					optionSet.push(opt);
				}

				ds.dStorage[ds_dIndex] = optionSet;

				for(var i=0; i< optionSet.length; i++) {
					if (ds.dIndex != ds_dIndex)
						optionSet[i].style.display = 'none';
					ds.appendChild( optionSet[i] );
				}

				ds.dAjax[ds_dIndex] = false;
				ds.style.border = ds_oldStyle;
				ds.selectedIndex = 0;
			}

			ds.dAjax[ds.dIndex] = true;
			ds.style.border = '1px solid red';

			//alert('ajax request');
			if (typeof(window.ajax_get) == 'function')
				window.ajax_get(url, local_handler);
			else if (typeof(jQuery) == 'function')
				jQuery.get(url, local_handler);
			else
				alert('Fatal error: AJAX component missing.' + window.jQuery);

		} else {
			// show options
			for(var i=0; i< ds.dStorage[ds.dIndex].length; i++)
				ds.appendChild(ds.dStorage[ds.dIndex][i]);
		}
	}
}