function SelectBox(name,id,tabindex)
{
	this.id = id;
	this.name = name;
	this.addOption = selectBoxAddOption;
	this.optionTexts = new Array();
	this.optionValues = new Array();
	this.toggleMenu = selectBoxToggleMenu;
	this.display = selectBoxBuild;
	this.selectedIndex = 0;
	this.IsMenuOpen = false;
	this.closeMenu = selectBoxCloseMenu;
	this.openMenu = selectBoxOpenMenu;
	this.optionClick = selectBoxOptionClick;
	this.updateValue = selectBoxUpdateValue;
	this.closeMenuOnTimer = selectBoxCloseMenuOnTimer;
	this.closeTimer = null;
	this.openTimer = null;
	this.clearCloseMenuTimer = selectBoxClearCloseMenuTimer;
	this.tabIndex = tabindex;
	this.width = 140;
}
function selectBoxClearCloseMenuTimer()
{
	clearTimeout(this.closeTimer);
	return false;
}
function selectBoxCloseMenuOnTimer(val)
{
	if (!val) val=100;
	if (this.openTimer==null)
	{
		this.closeTimer = setTimeout(''+this.name+'.closeMenu();',val);
	}
	return false;
}
function selectBoxUpdateValue()
{
	elInput = document.getElementById(''+this.id+'');
	elText = document.getElementById(''+ this.id +'SelectedOption');
	if (this.selectedIndex>=0)
	{
		elInput.value = this.optionValues[this.selectedIndex];
		elText.innerHTML = this.optionTexts[this.selectedIndex];
	}
	else
	{
		elInput.value = '';
		elText.innerHTML = '';
	}
}
function selectBoxOptionClick (key)
{
	this.selectedIndex = key;
	this.updateValue();
	this.closeMenu();
	return false;
}
function selectBoxOpenMenu()
{
	elMenu = document.getElementById(''+this.id+'List');
	elMenu.className = 'jsSelectBoxListOpen';
	elMain = document.getElementById(''+this.id+'Main');
	elMain.style.zIndex = 9999;
	this.IsMenuOpen = true;
	this.openTimer = null;
}
function selectBoxCloseMenu()
{
	elMenu = document.getElementById(''+this.id+'List');
	elMenu.className = 'jsSelectBoxList';
	elMain = document.getElementById(''+this.id+'Main');
	elMain.style.zIndex = 0;
	this.IsMenuOpen = false;
}
function selectBoxAddOption(value,text,selected)
{
	var newCount = this.optionTexts.push(text);
	this.optionValues.push(value);
	if (selected)
	{
		this.selectedIndex = (newCount - 1);
	}
}
function selectBoxToggleMenu()
{
	if (this.IsMenuOpen)
	{
	   if (this.openTimer==null) this.closeMenuOnTimer();
	}
	else
	{
	   this.openTimer = setTimeout(''+this.name+'.openMenu()',100);
	}
	return false;
}
function selectBoxBuild()
{
	var varName = this.name;
   var sTabIndex = "";
	if (this.tabIndex) sTabIndex = ' tabindex="'+ this.tabIndex +'" ';
	document.write('<input type="hidden" name="'+ this.id +'" id="'+ this.id +'">');
	document.write('<ul class="jsSelectBox" id="'+ this.id +'Main" style="width:'+this.width+'px"><div onmouseover="'+varName+'.clearCloseMenuTimer();" onmouseout="return '+varName+'.closeMenuOnTimer(1000);"><div>');
	var optionsCount = this.optionValues.length;
	if (optionsCount > 0)
	{
	   var selectedText = '';
	   if (this.selectedIndex>=0)
		{
			selectedText = this.optionTexts[this.selectedIndex]
		}
		document.write('<li><a id="'+ this.id +'Link" href="#" '+sTabIndex+' onfocus="'+varName+'.clearCloseMenuTimer();" onblur="return '+varName+'.closeMenuOnTimer();" onclick="return '+varName+'.toggleMenu();"><div onclick="return '+varName+'.toggleMenu();" onfocus="return '+varName+'.clearCloseMenuTimer();" onblur="return '+varName+'.closeMenuOnTimer();" id="'+ this.id +'SelectedOption">'+ selectedText +'</div></a>');
		document.write('<ul id="'+this.id+'List" class="jsSelectBoxList" onfocus="return '+varName+'.clearCloseMenuTimer();" onblur="return '+varName+'.closeMenuOnTimer();">');
		var i = 0;
		var text = '';
		var sel = '';
		while (i < optionsCount)
		{
		   text = '';
		   if (this.optionTexts[i]) text = this.optionTexts[i];
			document.write('<li style="width:100%;"><a href="?"" id="" onfocus="return '+varName+'.clearCloseMenuTimer();" onblur="return '+varName+'.closeMenuOnTimer();" onclick="document.getElementById(\''+ this.id +'Link\').focus();return '+varName+'.optionClick('+i+');">'+ text +'</a></li>');
			i++;
		}
		document.write('</ul></li>');
	}
	document.write('</div></div></ul>');
	this.updateValue();
}
