/*
===========================================================
SCRIPT FOR CHANGE FONTSIZE (TYPE C)

Last Updated:08/21/2004
 - change URI from last version : 09/21/2001

 - translation to funny English by
	Satoshi Sakanoshita (Fukuoka Central Church)

insomnia!
http://insomnia.jp/
http://insomnia.jp/workshop/
===========================================================
*/


/*
========== ::: Initialization ::: ==========
*/
// Set the unit (Enclose by quote or w-quote)
var fontSizeUnit = "%";

// Set size per order (Don't enclose by quote or w-quote)
var perOrder = 20;

// Set initialize value (Don't enclose by quote or w-quote)
var defaultSize = 100;

// cookie name (Enclose by quote or w-quote)
var ckName = "FSCc";

// cookie expiration[DAY] (Don't enclose by quote or w-quote)
var ckDays = 2;

// cookie path (Enclose by quote or w-quote. If you don't need, set "/")
var ckPath = "/"


/*
========== ::: Set value of page loading ::: ==========
*/

// read cookie
var fsCK = GetCookie( ckName );

if ( fsCK == null ){
// If there is no cookie,
// Set the current value to an initial value of the cookie
  var currentSize = defaultSize;
}
else{
// If there is cookie,
// Set the current value to the cookie.
  var currentSize = eval( fsCK );
}


/*
========== ::: The Element of STYLE is output to HEAD.  ::: ==========
*/
document.writeln( '<style type="text/css">' );
document.write( 'body{font-size:' + currentSize + fontSizeUnit+ '}' );
document.writeln( '</style>' );


/*===================================
  [Function fsc]
  The value after it changes is calculated according to
  the value of argument CMD, and it writes in the cookie. 
====================================*/

function fsc( CMD ){

  // Expansion: It substitutes it for the value "NewSize" after
  // it operates it adding the value changed to a present value by the operation once.

  if ( CMD == "larger" ){
    var newSize = Number( currentSize + perOrder );
    SetCookie( ckName , newSize );          // write cookie
  }

  // The reduction: It substitutes it for the value after
  // the value changed from a present value by the operation once is pulling operated. 

  if ( CMD == "smaller" ){
    if ( currentSize != perOrder ){
      var newSize = Number( currentSize - perOrder );
      SetCookie( ckName , newSize );          // write cookie
    }
    else{
      var newSize = Number( currentSize );
    }
  }

  // Return value¡§It returns it: The value after
  // it operates it is adjusted to an initial value.
  if ( CMD == "default" ){
    DeleteCookie( ckName );          // delete cookie
  }

  // Page reload
  // The style element that reflects the value after
  // it changes by doing the rereading seeing is output. 
  location.reload();
}

// _______________________________________ end of function fsc() ___ 


/*===================================
  [Function SetCookie]
  write value to cookie
====================================*/
function SetCookie( name , value ){
  var dobj = new Date();
  dobj.setTime(dobj.getTime() + 24 * 60 * 60 * ckDays * 1000);
  var expiryDate = dobj.toGMTString();
  document.cookie = name + '=' + escape(value) + ';expires=' + expiryDate + ';path=' + ckPath;
}

/*===================================
  [Function GetCookie]
  get cookie
====================================*/
function GetCookie (name){
  var arg  = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen){
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

/*===================================
  [function getCookieVal]
  get cookie value
====================================*/
function getCookieVal (offset){
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}

/*===================================
  [function DeleteCookie]
  delete cookie
====================================*/
function DeleteCookie(name){
  if (GetCookie(name)){
    document.cookie = name + '=' +
    '; expires=Thu, 01-Jan-70 00:00:01 GMT;path='+ckPath;
  }
}

//EOF