
/////////////////////////////////////////////////////////////////////////////
// newsdisp.js - Javascript file to handle writing the news headlines from
//               a JSMsg object
//
//
// (c) 2004 - Bruce Hellstrom
/////////////////////////////////////////////////////////////////////////////


function newsdisp( msgobj, dispcount, hlstyle, descstyle, datestyle )
{
    this.msgdispcount = dispcount;
    this.headlinestyle = hlstyle;
    this.descriptionstyle = descstyle;
    this.datestyle = datestyle;
    this.jsmsgobj = msgobj;
    
    this.months = new Array( '', 'January', 'Februrary', 'March', 'April', 'May', 'June',
                             'July', 'August', 'September', 'October', 'November', 'December' );
    
    
    
    this.setMsgCount = function( newcount ) {
        var maxmsgs = this.jsmsgobj.MetaMsg( "MetaCount" );
        
        if ( newcount > 0 && newcount <= maxmsgs )
            this.msgdispcount = newcount;
        else
            this.msgdispcount = maxmsgs;
    }
    
    this.setHeadlineStyle = function( newstyle ) {
        this.headlinestyle = newstyle;
    }
    
    this.setDescriptionStyle = function( newstyle ) {
        this.descriptionstyle = newstyle;
    }
    
    this.setDateStyle = function( newstyle ) {
        this.datestyle = newstyle;
    }
    
    this.setMessageObject = function( msgobj ) {
        this.jsmsgobj = msgobj;
    }
    
    
    this.drawNews = function()
    {
        if ( this.msgdispcount > 0 )
        {
            document.writeln( "<UL>" );
            
            for ( var nctr = 0; nctr < this.msgdispcount; nctr++ ) {
                var hdline = this.jsmsgobj.GetN( "Title", nctr );
                var link = this.jsmsgobj.GetN( "Link", nctr );
                var desc = this.jsmsgobj.GetN( "Desc", nctr );
                var datemon = this.jsmsgobj.GetN( "MonthN", nctr );
                var dateday = this.jsmsgobj.GetN( "DayN", nctr );
                var dateyear = this.jsmsgobj.GetN( "Year4N", nctr );
                var datestr = "";
                
                if ( datemon != "" && dateday != "" && dateyear != "" ) {
                    datestr = this.months[ datemon ] + " " + dateday + ", " + dateyear;
                }
                
                var hasdesc = ( desc != "" ? 1 : 0 );
                var hasdate = ( datestr != "" ? 1 : 0 );
                
                document.writeln( "<LI class=\"" + this.headlinestyle + "\">" );
                document.writeln( "<A HREF=\"" + link + "\" target=\"_blank\">" + hdline + "</A>" );
                
                if ( hasdesc ) {
                    document.writeln( "<BR>" );
                    document.writeln( "<SPAN class=\"" + this.descriptionstyle + "\">" );
                    document.writeln( desc );
                    document.writeln( "</SPAN>" );
                }
                
                if ( hasdate ) {
                    document.writeln( "<BR>" );
                    document.writeln( "<SPAN class=\"" + this.datestyle + "\">" );
                    document.writeln( datestr );
                    document.writeln( "</SPAN>" );
                }
                document.writeln( "</LI>" );
            }
            document.writeln( "</UL>" );
        }
    }
}







