	//--------------------------------------------------

	var img = new Image(); 
	loadPic('combo_btn_default.gif');
	loadPic('combo_btn_hover.gif');
	loadPic('combo_btn_active.gif');

	var dd_active = null; //contains pointer to open box at all time
	var dd_block = null; //avoid double opening
	var dd_focus = 0; //we keep track separately of focus because stupid IE loses it when using scrollbars
	var dd_ctrl = false; //we also keep track of CTRL key, because of the extended mousewheel functionality it provides

	//-------------------------------------------------------------------------------------------------
	function dd_select(ddid,index)
	{
		var sysbox = document.getElementById(ddid+'_sysbox');

		if (index < 2) index = 2;
		if (index > sysbox.options.length - 1) index = sysbox.options.length - 1;
		
		var txt = sysbox.options[index].innerHTML;
		if ((txt == '&nbsp;') || (txt == '') || (txt == ' ')) index = 0;

		sysbox.selectedIndex = index;
		eval(document.getElementById(ddid+'_onchange').value);

		dd_markOpt(ddid,index);
		document.getElementById(ddid+'_caption').innerHTML = sysbox.options[index].innerHTML;

		dd_forcePullUp();
	}

	//-------------------------------------------------------------------------------------------------
	function dd_set(ddid,value,txt) //only for custom
	{
		document.getElementById(ddid+'_sysbox').value = value;
		if (!txt) txt = value;
		document.getElementById(ddid+'_caption').innerHTML = txt;

		eval(document.getElementById(ddid+'_onchange').value);
		
		dd_forcePullUp();
	}

	//-------------------------------------------------------------------------------------------------
	function dd_keyDown(e)
	{
		var key = e.keyCode;

		// SAFARI?
		//e.returnValue = false;

		var ddid = dd_active.id;
		var sysbox = document.getElementById(ddid+'_sysbox');
		var markedOpt = dd_getMarkedOpt(ddid);
		var curOpt = markedOpt?markedOpt:sysbox.selectedIndex;
		if (curOpt < 2) curOpt = 1;

		if ((key == 37) || (key == 38)) dd_select(ddid,curOpt - 1); // up or left
		if ((key == 39) || (key == 40)) dd_select(ddid,curOpt + 1); // down or right
		if (key == 33) dd_select(ddid,curOpt - 10); // pgup
		if (key == 34) dd_select(ddid,curOpt + 10); // pgdn
		if (key == 36) dd_select(ddid,2); // start
		if (key == 35) dd_select(ddid,sysbox.options.length - 1); // end

		if ((key >= 65) && (key <= 90)) // A-Z
		{
			var walk = curOpt;
			for (var cnt = 2; cnt < sysbox.options.length; cnt++)
			{
				walk++;
				if (walk > sysbox.options.length - 1) walk = 2;

				if (sysbox.options[walk].innerHTML.substr(0,1).toUpperCase() == String.fromCharCode(key))
				{
					dd_select(ddid,walk);
					break;
				}
			}
		}

		if (key == 13) //enter
		{
			var markedOpt = dd_getMarkedOpt(ddid);
			if (markedOpt) dd_select(ddid,markedOpt);
			dd_pullUp(dd_active);
		}

		if (key == 27) dd_pullUp(dd_active);

		if (key == 17) dd_ctrl = true;
	}

	//-------------------------------------------------------------------------------------------------
	function dd_keyUp(e)
	{
		var key = e.keyCode;

		if (key == 17) dd_ctrl = false;
	}

	//-------------------------------------------------------------------------------------------------
	// Custom mousewheel handling for IE required, since focus is kept on sysbox and IE bases wheel 
	// operations on focus instead of hover. This also forces us to keep track of the CTRL key.
	//
	// NOTE: Must test wheel in Safari !
	//-------------------------------------------------------------------------------------------------
	function dd_wheelIE(ddid)
	{
		if ((_ie) && (!dd_ctrl))
		{	
			ee = window.event;
			ee.returnValue = false;
			var pop = document.getElementById(ddid+'_pop');
			var optHeight = document.getElementById(ddid+'_opt_2').offsetHeight;

			if (ee.wheelDelta > 0)
			{
				pop.scrollTop -= optHeight * 3;
			}
			else
			{
				pop.scrollTop += optHeight * 3;
			}
		}
	}

	//-------------------------------------------------------------------------------------------------
	function dd_prePull(ddid)
	{
		if (dd_active != null) ddaid = dd_active.id; else ddaid = 'null';
		trace('prePull: '+ddid+' active: '+ddaid);

		var dd = document.getElementById(ddid);
		if (dd_active == dd) dd_block = dd;
	}

	//-------------------------------------------------------------------------------------------------
	function dd_adaptSize(ddid)
	{
		var pop = document.getElementById(ddid+'_pop');
		var optHeight = document.getElementById(ddid+'_opt_2').offsetHeight;
		var listHeight = 11;
		var sysbox = document.getElementById(ddid+'_sysbox');
		if (sysbox.options.length - 2 < listHeight) listHeight = sysbox.options.length - 2;
		pop.style.height = optHeight * listHeight + (_ie?2:0);

		if (navigator.appName=="Netscape") var winH = window.innerHeight-16 + document.body.scrollTop;
		if (navigator.appName.indexOf("Microsoft")!=-1) var winH = document.body.offsetHeight-20 + document.body.scrollTop;
		if (pop.parentNode.offsetTop+pop.offsetHeight > winH) pop.style.top = -pop.offsetHeight-optHeight-4; else pop.style.top = 0;

		pop.style.width = document.getElementById(ddid+'_env').offsetWidth + (_ie?0:4);
	}

	//-------------------------------------------------------------------------------------------------
	function dd_pullDown(ddid)
	{
		trace('pullDown: '+ddid+' (blocked: '+(dd_block!=null?dd_block.id:'none')+')');

		var src = document.getElementById(ddid);

		if (dd_block == src) 
		{
			src.blur();
			dd_block = null;
		}
		else
		{
			var pop = document.getElementById(ddid+'_pop');
			pop.style.display = 'block';

			if (document.getElementById(ddid+'_custom').value == 0)	dd_adaptSize(ddid); else pop.style.left =  - (pop.offsetWidth - src.offsetWidth)
			
			document.getElementById(ddid+'_sysbox').focus();
			dd_active = src;
			src.className = 'dd_active dropdown';
		}
	}

	//-------------------------------------------------------------------------------------------------
	function dd_pullUp()
	{

		if (dd_active != null)
		{
			trace('pullUp: '+dd_active.id+' (focus='+dd_focus+')');

			if (dd_focus == 0)
			{
				var pop = document.getElementById(dd_active.id+'_pop');
				pop.style.display = 'none';

				dd_active.className = 'dd_default dropdown';
				document.getElementById(dd_active.id+'_sysbox').blur();
				dd_active = null;
			}
			else
			{
				dd_focus = 0;
				//dd_block = dd_active;
				document.getElementById(dd_active.id+'_sysbox').focus();
			}
		}
	}

	//-------------------------------------------------------------------------------------------------
	function dd_forcePullUp()
	{
		dd_block = null;
		dd_focus = 0;
		dd_pullUp();
	}

	//-------------------------------------------------------------------------------------------------
	function dd_markOpt(ddid,index)
	{
		var mark = document.getElementById(ddid+'_mark');
		if (mark.value > 0) dd_unmarkOpt(ddid,mark.value);
		mark.value = index;

		if (index > 1)
		{
			var opt = document.getElementById(ddid+'_opt_'+index);
			opt.className = 'dd_option dd_option_hover';
			dd_adjustScroll(ddid,opt);
		}
	}

	//-------------------------------------------------------------------------------------------------
	function dd_unmarkOpt(ddid,index)
	{
		document.getElementById(ddid+'_opt_'+index).className = 'dd_option';
	}

	//-------------------------------------------------------------------------------------------------
	function dd_getMarkedOpt(ddid)
	{
		return document.getElementById(ddid+'_mark').value * 1;
	}

	//-------------------------------------------------------------------------------------------------
	function dd_adjustScroll(ddid,opt)
	{
		var pop = document.getElementById(ddid+'_pop');
		var optpos = opt.offsetTop + opt.offsetHeight;
		var pophs = pop.offsetHeight + pop.scrollTop;
		if (optpos > pophs) pop.scrollTop = pop.scrollTop + optpos - pophs + (_ie?2:3);
		if (opt.offsetTop < pop.scrollTop) pop.scrollTop = opt.offsetTop + (_ie?0:1);
	}

	//-------------------------------------------------------------------------------------------------
	function dd_init(ddid,custom)
	{
		document.getElementById(ddid+'_env').style.display = 'block';

		var sysbox = document.getElementById(ddid+'_sysbox');
		sysbox.style.marginLeft = '-9999px';
		if ((document.getElementById(ddid+'_custom').value == 0) && (sysbox.selectedIndex))
		{
			document.getElementById(ddid+'_caption').innerHTML = sysbox.options[sysbox.selectedIndex].innerHTML;
			dd_markOpt(ddid,sysbox.selectedIndex);
		}
	}

