/**
 *Resize the fonts in the middle of the page. This is the onLoad event handler.
 *The font size is loaded from a cookie if it exists.
 *@author J Francis
 */
 
function resizeFontsAsEvent( evnt ){
 
  //The cookie exists and there is no input parameter.
  //Resize content based on the cookie value.
  if( document.cookie && (document.cookie.indexOf('otlms_preferences') > -1) ){
    
    var cookies = document.cookie.split(';');
    
    for( var k = 0; k < cookies.length; k++ ){
      
      if( cookies[k].indexOf('otlms_preferences') > -1){
        
        var pair = cookies[k].split('=');
        
        var name  = pair[0];
        var value = pair[1];
        
        var regEx = /^([0-9])+pt$/
         
        if( !value.match( regEx ) ){ //Make sure there is no garbage stored.
          value = '8pt';
        }
        
        resizeFonts(value);
      }
    }
  }
  
  return true;
}

/**
 *Resize the fonts in the middle of the page. Parameter is stored in a cookie.
 *@author J Francis
 */
 
function resizeFonts( param ){
  
  if( param ){
    
    var element = document.getElementById( 'PageCenter' );
    
    elementWiseFontResize( element, param );
    
    //Make a note of the paramater in a cookie.
    if( document.cookie ){
      //Kill any cookie with the same name.
      document.cookie = 'otlms_preferences=foobar;path=/;expires=' + (new Date('January 1, 1970')).toGMTString();
      
      //Reset the cookie.
      document.cookie = 'otlms_preferences=' + escape( param ) + ";path=/";
    }
  }
  
  return false;
}

/**
 *Handle all child elements.
 */
function elementWiseFontResize( element, param ){
  
  if(element.style)
    element.style.fontSize = param;
  
  for( var k = 0; k < element.childNodes.length; k++ ){
    
    elementWiseFontResize( element.childNodes.item(k), param );
  }
}
