function NewsCategoryItem( name, urlFormat, basePath )
{ // Represents a category in the quick search form.
	this.name = name;
	this.urlFormat = urlFormat;
	this.basePath = (typeof(basePath) == "undefined")? "" : basePath;
	
	this.toString = function( date )
	{
		var s = new jsDocument();
		
		if( "undefined" == typeof( date ) )
			date = new Date();
			
		//s.write( date.toString( "ddd MM/dd/yyyy" ) );
		//s.write( " - " );
		s.write( this.name );

		return s.toString();
	}
	
	this.formatUrl = function( date )
	{
		// Replace place holder for article's date with CEE-style date
		return basePath.concat( this.urlFormat.replace( /\{0\}/g, date.toString( "MMddyy" ) ) );
	}
	
	this.toDdlOption = function( date, cssClass )
	{
		var ddlOption = new Option( this.toString( date ), this.formatUrl( date ) );
		if( cssClass )
			ddlOption.setAttribute( "class", cssClass );
		return ddlOption;
	}
	
	this.toDdlOptionHtml = function( date, cssClass )
	{
		var s = new jsDocument();
		
		s.write( "<option" );
		s.write( " value='" ).write( this.formatUrl( date ) ).write( "'" );
		if( cssClass )
			s.write( " class='" ).write( cssClass ).write( "'" );
		s.write( ">" );
		s.write( this.toString( date ) );
		s.write( "</option>" );
		return s.toString();
	}
}

function PopulateQuickSearchForm( selectElm, catItems )
{
	if( selectElm.options.length <= 1 )
	{
		var currDate = new Date();
		for( var day = 0; day < 7; day++ )
		{
			for( var itemIdx = 0; itemIdx < catItems.length; itemIdx++ )
			{
				var cssClass = (day % 2 == 0)? "" : "odd";
				selectElm.options.add( catItems[ itemIdx ].toDdlOption( currDate, cssClass ) );
			}
			
			// Subtract one day from current date
			currDate.addDays( -1 );
		}
	}
}

function PopulateQuickSearchFormWithHtml( selectElm, catItems )
{
	if( selectElm.options.length <= 1 )
	{
		var sb = new jsDocument();
		var currDate = new Date();

		if( typeof(window.opera) == "undefined" )
		{
			sb.write( "<option value=''>- Last 7 Days -</option>" );

			for( var day = 0; day < 7; day++ )
			{
				sb.write( "<optgroup" )
					.write( " label='" ).write( currDate.toString( "ddd, MMM/dd/yyyy" ) ).write( "'" )
					.write( ">" );
				for( var itemIdx = 0; itemIdx < catItems.length; itemIdx++ )
				{
					var cssClass = (day % 2 == 0)? "" : "odd";
					sb.write( catItems[ itemIdx ].toDdlOptionHtml( currDate, cssClass ).toString() );
				}
				sb.write( "</optgroup>" );
				
				// Subtract one day from current date
				currDate.addDays( -1 );
			}
		}
		else
		{
			// Special processing for opera because the stupid thing (Opera 9.6x) doesn't
			// render the optgroups and options correctly: only the first level "optgroups"
			// are displayed by the browser. 
			sb.write( "<option value=''>- Last 7 Days -</option>" );

			for( var day = 0; day < 7; day++ )
			{
				sb.write( "<option value='' style='background:#000;color:white;'>" )
					.write( currDate.toString( "ddd, MMM/dd/yyyy" ) )
					.write( "</option>" );
				for( var itemIdx = 0; itemIdx < catItems.length; itemIdx++ )
				{
					var cssClass = (day % 2 == 0)? "" : "odd";
					sb.write( catItems[ itemIdx ].toDdlOptionHtml( currDate, cssClass ).toString() );
				}
				
				// Subtract one day from current date
				currDate.addDays( -1 );
			}			
		}
		
		jQuery(selectElm).html( sb.toString() );
	}
}

function RedirectToSelectedItem( selectElm )
{
	if( selectElm.selectedIndex != 0 ) 
	{ 
		location.href = selectElm.options[ selectElm.selectedIndex ].value;
	}
}
