function UserListControl( options )
{
	var controlDiv = $( "#" + options.controlDivId );
	var userCombo = controlDiv.find( "select:eq(0)" );
	var listCombo = controlDiv.find( "select:eq(1)" );
	
	// Save state of form in these hidden inputs (to restore state after a postback)
	var hidUser = controlDiv.find( "input:hidden:eq(0)" );
	var hidList = controlDiv.find( "input:hidden:eq(1)" );
	var hidListType = controlDiv.find( "input:hidden:eq(2)" );
	var hidAllowEmptyList = controlDiv.find( "input:hidden:eq(3)" );
	
	// State variables
	var listId = hidList.val();
	var userId = hidUser.val();	

	this.fillListCombo = function( json )
	{
		if ( json )
		{
			listCombo.empty();
			if ( hidAllowEmptyList.val() == "1")
			{
				var option = $( "<option></option>" );
				option.val( "0" );
				option.text( "(none selected)" );
				option.appendTo( listCombo );
			}
			
			$( json ).each( function( i, obj )
			{
				var option = $( "<option></option>" );
				option.val( obj.id );
				option.text( obj.text );
				option.appendTo( listCombo );
			} );
		}
		else
		{
			listCombo.find( 'option' ).remove().end().append( '<option value="0">(none available)</option>' ).val( '0' );
		}
		
		touchIEControl(listCombo);
		
		// Restore state
		if ( listId )
		{
			listCombo.val( listId );		
			listId = "";
		}
		
		hidList.val( listCombo.val() );
	}

	this.updateListCombo = function()
	{
		var id = userCombo.val();
		var listType = hidListType.val();
		$.ajax(
		{
			type: "GET", url: "/Ajax/ListLookupPage.aspx", dataType: "json", data:
			{
				listkindid: listType, userid: id
			},
			timeout: 2000, success: function( opts )
			{
				this.fillListCombo( opts );
			}.bind(this),
			error: function( xhr, status )
			{
				listCombo.find( 'option' ).remove().end().append( '<option value="0">(none selected)</option>' ).val( '0' );
			}
		} );
	};

	userCombo.change( function()
	{
		hidUser.val( userCombo.val() );
		this.updateListCombo();
	}.bind(this) );

	listCombo.change( function()
	{
		hidList.val( listCombo.val() );
	} );                                                                                     

	this.updateListCombo();
}

UserListControl.create = function( id, options )
{
	if ( !this._instances )
	{
		this._instances =
		{
		};
	}

	this._instances[ id ] = new UserListControl( options );
};

UserListControl.getInstance = function( id )
{
	return this._instances[ id ];
};