function OpenTimePicker()
{
		var picker = new TimePicker( 'timeForm' );
		tb_show('','#TB_inline?height=45&width=330&inlineId=undefined','');
		picker.RenderOutput( 'TB_ajaxContent' );	
		
		picker.ButtonOK.onclick = function()
		{
			picker.ChangeValue();
			tb_remove();
		}
		return false;
}
function TimePicker( target )
{
	this.ID	= 'TimePicker';
	this.TargetID	= target;
	this.ButtonOK = null;
	
	TimePicker.Cache = this;
	
	this.RenderOutput = function( element )
	{
		var root = document.createElement( "div");
		root.setAttribute( 'id', this.ID );
		
		root.appendChild( this.GetElement_Label( 'od ' ) );
		root.appendChild( this.getElement_ComboBoxHours( 'FromHour' ) );
		root.appendChild( this.GetElement_Label( ' : ' ) );
		root.appendChild( this.getElement_ComboBoxMinutes( 'FromMinutes' ) );
		root.appendChild( this.GetElement_Label( ' do ' ) );
		root.appendChild( this.getElement_ComboBoxHours( 'ToHour' ) );
		root.appendChild( this.GetElement_Label( ' : ' ) );
		root.appendChild( this.getElement_ComboBoxMinutes( 'ToMinutes' ) );
		root.appendChild( this.GetElement_Label( ' ' ) );
		root.appendChild( this.GetElement_Button( 'OK' ) );
		
		document.getElementById( element ).innerHTML = '';
		document.getElementById( element ).appendChild( root );
	
		this.SetDefaultValues();
		
		return;
	}
	
	this.ComboBoxByName = function( str )
	{
		return document.getElementById( this.ID + '_' + str  );
	}
	
	this.SetDefaultValues = function()
	{
		var value = document.getElementById( this.TargetID ).value.toString();
		var tmp = [];
		if ( value.length > 0 && value.indexOf( ':') > -1 && value.indexOf( '-' ) > -1  )
		{
			var d = [];
			tmp[0] = value.substring( 0, value.indexOf( ':' ) );
			tmp[1] = value.substring( value.indexOf( ':' ) + 1, value.indexOf( '-' ) );
			tmp[2] = value.substring( value.indexOf( '-' ) + 1, value.lastIndexOf( ':' ) );
			tmp[3] = value.substring( value.lastIndexOf( ':' ) + 1, value.length );
			
			for ( var i =  0; i < tmp.length; i++ )
				tmp[i] = tmp[i].length == 1 ? '0' + tmp[i] : tmp[i];
			
			this.SetValueToComboBox( 'FromHour',  tmp[0] );
			this.SetValueToComboBox( 'FromMinutes',  tmp[1] );
			this.SetValueToComboBox( 'ToHour',  tmp[2] );
			this.SetValueToComboBox( 'ToMinutes',  tmp[3] );
		}
		else
		{
			this.ComboBoxByName( 'ToHour' ).options[this.ComboBoxByName( 'ToHour' ).options.length-1].selected = true;
			this.ComboBoxByName( 'ToMinutes' ).options[this.ComboBoxByName( 'ToMinutes' ).options.length-1].selected = true;
			
		}
	}
	
	this.SetValueToComboBox = function( comboboxName, value )
	{
		var combo = this.ComboBoxByName( comboboxName );
		for ( var i = 0; i < combo.options.length; i++ )
		{
			if ( combo.options[i].value == value )
			{
				combo.options[i].selected = true;
				combo.SelectedValue = value;
			}
		}
	}
	
	this.SelectedValueAsString = function()
	{
		var fhour = this.ComboBoxByName(  'FromHour' ).SelectedValue;
		fhour = fhour == undefined ? this.ComboBoxByName( 'FromHour' ).options[0].value : fhour; 
		var fmin = this.ComboBoxByName( 'FromMinutes' ).SelectedValue;
		fmin = fmin == undefined ? this.ComboBoxByName( 'FromMinutes' ).options[0].value : fhour; 
		
		var thour = this.ComboBoxByName( 'ToHour' ).SelectedValue;
		thour = thour == undefined ? this.ComboBoxByName( 'ToHour' ).options[this.ComboBoxByName( 'ToHour' ).options.length-1].value : thour;
		var tmin = this.ComboBoxByName( 'ToMinutes' ).SelectedValue;
		tmin = tmin == undefined ? this.ComboBoxByName( 'ToMinutes' ).options[this.ComboBoxByName( 'ToMinutes' ).options.length-1].value : tmin;
		
		return fhour + ':' + fmin + '-' + thour + ':' + tmin;
	}
	
	/**
	 * Return DOM Element span with some text 
	 */
	this.GetElement_Label = function( text )
	{
		var fromLabel = document.createElement( 'span' );
		fromLabel.innerHTML = text;
		
		return fromLabel;
	}
	
	this.ChangeValue = function()
	{
		document.getElementById( TimePicker.Cache.TargetID ).value = TimePicker.Cache.SelectedValueAsString();
	}
	
	this.GetElement_Button = function( text )
	{
		var tmp = document.createElement( 'button' );
		tmp.innerHTML = text;
		this.ButtonOK = tmp;
		return tmp;
	}
	
	/**
	 * Get DOM element select with hours
	 */
	this.getElement_ComboBoxHours = function( elementName )
	{
		var select = document.createElement( 'select' );
		select.setAttribute( 'name', elementName );
		select.setAttribute( 'id', this.ID + '_' + elementName );
		for ( var i = 8; i<=19; i++ )
		{
			var tmp = document.createElement( 'option' );
			var text = i < 10 ? '0' + i : i;
			tmp.setAttribute( 'value',  text );
			tmp.innerHTML = text;
			
			select.appendChild( tmp );
		}

		select.onchange = function()
		{
			this.SelectedValue = this.options[this.selectedIndex].value;
		}

		return select;
	}
	
	this.getElement_ComboBoxMinutes = function( elementName )
	{
		var select = document.createElement( 'select' );
		select.setAttribute( 'name', elementName  );
		select.setAttribute( 'id', this.ID + '_' + elementName );
		
		for ( var i = 0; i<=59; i++ )
		{
			var tmp = document.createElement( 'option' );
			var text = i < 10 ? '0' + i : i;
			tmp.setAttribute( 'id', elementName + '_option_' + text );
			tmp.setAttribute( 'value',  text );
			tmp.innerHTML = text;
			
			select.appendChild( tmp );
		}

		select.onchange = function()
		{
			this.SelectedValue = this.options[this.selectedIndex].value;
		}

		
		return select;
	}


	
	
	/**
	 * Return DOM Element span with text "do"
	 */
	this.GetElement_ToLabel = function()
	{
		var tmp = document.createElement( 'span' );
		tmp.innerHTML = "do ";
		
		return tmp;
	}
	
		
}
