function selectSelectOption (combo, option) // only iframe
{
	selectChangeDependencies (combo, '');
	selectSetSelection (combo, Array (option.value.toString ()), option.checked, true);}

function selectCreateOption (combo, text, value)
{
	combo.options[combo.options.length] = new Option (text, value);							if (combo.inline)
		combo.iframe.write ('<TR><TD Width="10" BgColor="#7BAEBD"><INPUT OnClick="JavaScript: parent.selectSelectOption (parent.document.forms[\'' + combo.form.name + '\'].elements[\'' + combo.name + '\'], this);" Type="' + (combo.multiple ? 'CheckBox' : 'Radio') + '" Name="' + combo.name + '" Value="' + value + '"></TD><TD Width="1"></TD><TD Width="2"></TD><TD><FONT Size="1" Face="Verdana">' + text + '</FONT></TD></TR>\n');}

function selectOpen (combo)
{
	while (combo.options.length)
		combo.options[0] = null;							if (combo.inline)
	{
		combo.iframe.open ();		combo.iframe.write ('<BODY MarginHeight="0" MarginWidth="0" TopMargin="0" BottomMargin="0" RighMargin="0" LeftMargin="0" BgColor="#E7F3FF">\n');
		combo.iframe.write ('<TABLE CellPadding="0" CellSpacing="0" Border="0" Width="100%">\n');
		combo.iframe.write ('<FORM Name="' + combo.form.name + '">\n');	}
}

function selectClose (combo)
{
	if (combo.inline)
	{
		combo.iframe.write ('</FORM>\n');
		combo.iframe.write ('</TABLE>\n');
		combo.iframe.write ('</BODY>');
		combo.iframe.close ();	}
}

function selectLoad (combo, restricted, restrictions)
{
	selectOpen (combo);

	if (combo.noneText.length)
		selectCreateOption (combo, combo.noneText, '0');

	if (restrictions.length || !restricted)
	{
		for (var index = 0; index < combo.inner_data.length; index++)
		{
			if (!restricted || combo.inner_data[index][0] == '')
				selectCreateOption (combo, combo.inner_data[index][2], combo.inner_data[index][1]);
			else
			{
				if (selectInSelection (combo.inner_data[index][0], restrictions))
					selectCreateOption (combo, combo.inner_data[index][2], combo.inner_data[index][1]);
			}
		}
	}
	else
	{
		var index = 0;
	}

	selectClose (combo);

	return index;
}

function selectSetSelection (combo, options, value, user)
{
	var index, selected;

	for (index = 0; index < combo.options.length; index++)
	{		selected = selectInSelection (combo.options[index].value, options);							
		if (selected)		{
			combo.options[index].selected = value;

			if (combo.inline && !user)			{
				if (combo.iframe.forms[combo.form.name].elements[combo.name][index])					combo.iframe.forms[combo.form.name].elements[combo.name][index].checked = value;
				else
					combo.iframe.forms[combo.form.name].elements[combo.name].checked = value;			}
										if (combo.selectedIndex == -1 && combo.options[index].selected)
				combo.selectedIndex = index;
		}	}}

function selectGetSelection (combo)
{
	var index, options;

	options = new Array ();

	if (combo.inline)
	{
		for (index = 0; index < combo.iframe.forms[combo.form.name].elements[combo.name].length; index++)
		{
			if (combo.iframe.forms[combo.form.name].elements[combo.name][index].checked)
				options [options.length] = combo.iframe.forms[combo.form.name].elements[combo.name][index].value;
		}
	}
	else
	{
		for (index = 0; index < combo.options.length; index++)
		{
			if (combo.options[index].selected)
				options [options.length] = combo.options[index].value;
		}
	}

	return options;
}

function selectSetVisibility (combo, isVisible) // not with inline
{
	if (isVisible)
		combo.style.visibility='visible';
	else
		combo.style.visibility='hidden';
}

function selectInSelection (needle, haystack)
{
	for (var index = 0; index < haystack.length && haystack[index] != needle; index++);	
	return (index < haystack.length);}

function selectChangeDependencies (combo, dependencie)
{
	var index, index2, actualDependencie, value;

	if (combo.dependencies.length)
	{
		value = selectGetSelection (combo);

		for (index = 0; index < combo.dependencies.length; index++)
		{
			if (combo.dependencies[index] == dependencie || dependencie == '')
			{
				actualDependencie = combo.dependencies[index];

				index2 = selectLoad (actualDependencie, true, value);

				if (actualDependencie.invisible && !actualDependencie.inline)
					selectSetVisibility (actualDependencie, (index2 != 0));

				selectChangeDependencies (actualDependencie, '');
			}
		}
	}
}