function findPos( obj )
{
	var curleft = curtop = 0;
	if( obj.offsetParent )
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		
		while( obj = obj.offsetParent )
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	
	return [curleft, curtop];
}

function createStyledSelect( oDockTo, nLinesCount, sID, sName )
{
	if( oDockTo )
	{
		oList = document.createElement( "SELECT" );
		oList.id = sID;
		oList.name = sName;
		oList.style.width = parseFloat( ( oDockTo.style.width.substr( -2, 2 ) == "px" ) ? oDockTo.style.width.substr( 0, oDockTo.style.width.length - 2 ) : oDockTo.style.width ) - 10;
		oList.size = nLinesCount;
		oList.style.position = "absolute";
		oList.style.display = "none";
		
		oSpan = document.createElement( "SPAN" );
		oSpan.id = sID + "_spn";
		oSpan.style.fontSize = "16px";
		oSpan.style.lineHeight = "38px";
		oSpan.style.marginLeft = 10;
		oSpan.style.fontFamily = "Trebuchet MS";
		oDockTo.appendChild( oSpan );
		
		oDockTo.onclick = function()
		{
			document.getElementById( sID ).style.display = "block";
			document.getElementById( sID ).focus();
		}
		oList.onclick = function()
		{
			var sID2 = this.id + "_spn";
			document.getElementById( sID2 ).innerHTML = this.options[this.selectedIndex].innerHTML;
			this.style.display = "none";
		}
		oList.onchange = function()
		{
			var sID2 = this.id + "_spn";
			document.getElementById( sID2 ).innerHTML = this.options[this.selectedIndex].innerHTML;
		}
		oList.onkeypress = function( event )
		{
			event = event ? event : window.event;
			
			if( event.keyCode == 13 )
			{
				var sID2 = this.id + "_spn";
				document.getElementById( sID2 ).innerHTML = this.options[this.selectedIndex].innerHTML;
				this.style.display = "none";
			}
		}
		oList.onblur = function()
		{
			this.style.display = "none";
		}
		
		var aPos = findPos( oDockTo );
		oList.style.top = aPos[1] + parseFloat( ( oDockTo.style.height.substr( -2, 2 ) == "px" ) ? oDockTo.style.height.substr( 0, oDockTo.style.height.length - 2 ) : oDockTo.style.height ) - 10;
		oList.style.left = parseInt( aPos[0] ) + 5;
		
		//document.getElementsByTagName( "body" )[0].appendChild( oList );
		document.getElementById( "my_form" ).appendChild( oList );
		
		return oList;
	}
	
	return false;
}

function setStyledSelect( oList, sValue )
{
	if( oList )
	{
		oSpan = document.getElementById( oList.id + "_spn" );
		
		if( oSpan )
		{
			if( sValue == "" )
			{
				oSpan.innerHTML = oList.options[0].innerHTML;
				oList.options[0].selected = true;
			}
			else
			{
				for( var i = 0; i < oList.options.length; i++ )
				{
					if( oList.options[i].value == sValue )
					{
						oSpan.innerHTML = oList.options[i].innerHTML;
						oList.options[i].selected = true;
					}
				}
			}
		}
	}
}

function createStyledSelectItem( oList, sValue, sText )
{
	if( oList )
	{
		oOption = document.createElement( "OPTION" );
		oOption.value = sValue;
		oOption.appendChild( document.createTextNode( sText ) );
		oList.appendChild( oOption );
	}
}
