// fs.js - JavaScript unit to set font size in Web pages
// Copyright J. A. Wrotniak, 2008-2009; free for anyone to use or modify
// 1.00 08/03/12 Original as fs.js
// 1.01 08/03/13 Added font face setting
// 1.02 08/03/14 Added cookie removal
// 1.03 08/03/19 Added larger fonts for w>1280
// 1.04 09/02/25 Extracted from fs.js as fs-fs.js
// 1.05 09/03/01 Added fs_window(), in_set
//----------------------------------------------------------------------
// NOTE: the fs.js has to be included before this file!
// For details how this works, see the source of
// http://www.wrotniak.net/fs.html
//----------------------------------------------------------------------

// Function fs_reset() will be executed automatically upon loading of
// any page which refers to this file (fs.js).

var _ss = "";      // last custom font name used
var _fs = "";      // last font size used
var _ff = "";      // last font face used
_in_set = 1;

//----------------------------------------------------------------------

// Helper function; modified after Peter-Paul Koch; original at
// http://www.quirksmode.org/js/cookies.html

function write_cookie(nam,val,days) {
   var d = new Date();
   d.setTime(d.getTime()+(86400000*days));
   document.cookie = nam+"="+val+"; expires="+d.toGMTString()+"; path=/";
   }

//----------------------------------------------------------------------

// Checks if browser accepts cookies
// Note: does not work in Opera 9.50B !!!

function check_cookies() {
   if (navigator.cookieEnabled) {
      return 1;
      }
   else {
      alert("This will not work: your browser refuses cookies from thie site.\nEnable cookie support and try again.");
      return 0;
      }
   }
   
//----------------------------------------------------------------------

// Callback to button click: set font size to 'val'

function fs_size(val) {
   // if (!check_cookies()) return;
   if (_ff!=null) {
      write_cookie("ff",_ff,366);
      fs_set_face(_ff);
      }
   write_cookie("fs",val,366);
   _fs = val;
   fs_set_size(val);
   window.status="Cookies set:   ff="+_ff+"   fs="+_fs;
   fs_show();
   }

//----------------------------------------------------------------------

// Callback to button click, or called from fs_custom(): set font face

function fs_face(val) {
   // if (!check_cookies()) return;
   write_cookie("ff",val,366);
   _ff = val;
   fs_set_face(val);
   if (_fs!=null) {
      write_cookie("fs",_fs,366);
      fs_set_size(_fs);
      }
   window.status="Cookies set:   ff="+_ff+"   fs="+_fs;
   fs_show();
   }

//----------------------------------------------------------------------

// Callback to button click

function fs_custom() {
   // if (!check_cookies()) return;
   var os = _ss;
   _ss = window.prompt("Enter the font name:",_ss);
   if (_ss) {
      fs_face(_ss);
      }
   else {
      _ss = os;
      }
   }
      
//----------------------------------------------------------------------

// Removes size/face cookies, callback to button click

function fs_remove() {
   // if (!check_cookies()) return;
   write_cookie("fs","",-1);
   write_cookie("ff","",-1);
   fs_reset();
   window.status = "Cookies removed";
   fs_show();
   }

//----------------------------------------------------------------------

// Displays font info in box:

function fs_show() {
   var sty = document.body.style;
   var s = sty.fontFamily.split(",");
   _fs = sty.fontSize;
   _ff = s[0];
   var txt = "Current font: "+_fs+" "+_ff;
   document.getElementById('f_stat').innerHTML = txt;
   }
   
//----------------------------------------------------------------------

// Displays window size in status line

function fs_window() {
   window.status = "Window width: "+document.body.clientWidth;
   }
   
//--- END --------------------------------------------------------------


