
var TDF_FontSizeTagNames = new Array(
    'a',
    'cp',
    'b',
    'dd',
    'div',
    'dt',
    'emphasis',
    'h1',
    'h2',
    'h3',
    'i',
    'li',
    'ol',
    'p',
    'pre',
    'span',
    'strong',
    'sub',
    'sup',
    'table',
    'td',
    'th',
    'tr',
    'ul'
    );

function TDF_FontSizeBodyOnLoad()
{
    var Index;
    
    TDF_CookieCreate( 'TDF_FontIndex', '0', 90 );   
    
    Index = TDF_FontSizeIndexCookieRead();
}

function TDF_FontSizeIndexCookieRead()
{
    var CookieCreateFlag = 1;
    var Index;
    var IndexAsString;
        
    IndexAsString = TDF_CookieRead( 'TDF_FontIndex' );

    // Set the cookie if not already set.
    if( !isNaN(IndexAsString) )
    {
        if( !(IndexAsString == null) )
        {
            if( IndexAsString.length > 0 )
            {
                Index = parseInt(IndexAsString);
                if( ( Index >= 0 ) && ( Index <= 2 ) )
                {
                    CookieCreateFlag = 0;
                }
            }
        }
    }
    
    if( CookieCreateFlag == 1 )
    {
        TDF_CookieCreate( 'TDF_FontIndex', '0', 90 );     
    }
    
    return Index;
}

function TDF_FontSizeParent( FontSizeId, Direction, SizeDefault, SizeMinimum, StepIn )
{
    var Index;
        
    Index = TDF_FontSizeIndexCookieRead();
        
    switch( Direction.toLowerCase() )
    {
        case "down":
            // Don't allow font size to drop below original size.
            if( Index <= 0 ) return;
            Index = Index - 1;
            Step = -StepIn;
            break;
            
        case "up":
            // Don't allow user to increase font size more than twice.
            if( Index >= 2 ) return;
            Index = Index + 1;
            Step = StepIn;
            break;
            
        default:
            // Direction is invalid
            return;
            break;
    }
    
    TDF_CookieCreate( 'TDF_FontIndex', '' + Index, 90 );     
    
    TDF_FontSizeChild( SizeDefault, Step );
}

function TDF_FontSizeChild( SizeDefault, StepIn )
{
    var BodyObj;
    var FontSize;   
    var LineHeight;
    var NaNCount = 0;
    var NewFontSize;
    var Tags;

    //alert( 'TDF_FontSize: Direction = ' + Direction + '; SizeDefault = ' + SizeDefault + ', StepIn = ' + StepIn )
        
    // In case the browser doesn't support this function.
    if( !document.getElementById) return;
         
   
    BodyObj = document.getElementsByTagName('body')[0];
    if( BodyObj == null ) return;
    
    for( i = 0; i < TDF_FontSizeTagNames.length; i++ )
    {
        Tags = BodyObj.getElementsByTagName( TDF_FontSizeTagNames[i] );
        NaNCount = 0;              
        
        for( t = 0; t < Tags.length; t++ )
        {
            //alert( 'Tag = ' + Tags[t].style.fontSize );
            FontSize = parseInt( Tags[t].style.fontSize );
            if( isNaN( FontSize ) )
            {
                TDF_FontSizeChild2( Tags[t], SizeDefault );             
                NaNCount += 1;
                continue;
            }
                        
            FontSize = FontSize + StepIn;
            
            //alert( 'Setting Font Size' + FontSize );
                    
            TDF_FontSizeChild2( Tags[t], FontSize);

        }
        
        //alert( TDF_FontSizeTagNames[i] + '; Tags.length = ' + Tags.length + '; NaNCount = ' + NaNCount );
    }
}

function TDF_FontSizeChild2( TagObj, FontSize )
{
    TagObj.style.fontSize = FontSize + 'px';
    LineHeight = FontSize * 1.2;
    TagObj.style.lineHeight = LineHeight + 'px';
}

function TDF_FontSizeIconSwap( Id, ImgFileName )
{
    var Obj;
    
    if( !document.getElementById) return;
    //alert( '1-IconSwap = ' + Id + '; ' + ImgFileName );
        
    Obj = document.getElementById( Id );
    if( Obj == null ) return;
    
    //alert( '2-IconSwap = ' + Id + '; ' + ImgFileName );
        
    Obj.src = ImgFileName;
}


