/*  
    dw_fontsizer.js  version date: Jan 2004
    requires dw_cookies.js
    
    This code manipulates document.body.style.fontSize.
    Other elements sized using relative measures (em's or %)
    in style sheets will adjust accordingly. 
    Exclude elements (i.e., selectors) by using pixels, points or 
    constants (small, medium, etc.) to set their font-size in style sheets.
*/

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2004 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

var dw_fontSizer = {
  // sizeUnit and defaultSize for body.style.fontSize
  sizeUnit: "%",
  defaultSize: 76,
	hiContrastDefaultSize: 76,
  // numbers (same unit as sizeUnit)
  maxSize:     120,
  minSize:     60,

  init: function() {
    if ( !document.body || !document.getElementById ) return;
// sulle pagine asp cerca di interpretare i parametri asp come dimensioni fisse del font 
// e non riuscendoci reimposta il valori standard
//    var size = window.location.search? window.location.search.slice(1): getCookie("fontSize");
    var size =  getCookie("fontSize");
    size = !isNaN( parseFloat(size) )? parseFloat(size): this.defaultSize;
    // in case default unit changed or size passed in url out of range
    if ( size > this.maxSize || size < this.minSize ) size = this.defaultSize;
    var sizerEl = document.getElementById('sizer');
    if (sizerEl) sizerEl.style.display = "block";
    document.body.style.fontSize = size + this.sizeUnit;
  },
  
  adjust: function(inc) {
    var size = parseFloat( document.body.style.fontSize );
    size += inc;
    // Test against max and min sizes 
    if (inc > 0) size = Math.min(size, this.maxSize);
    else size = Math.max(size, this.minSize);
    setCookie( "fontSize", size, 180, "/" );
    document.body.style.fontSize = size + this.sizeUnit;
  },

  reset: function() {
    document.body.style.fontSize = this.defaultSize + this.sizeUnit;
    deleteCookie("fontSize", "/");
  },
	
  set: function() {
   document.body.style.fontSize = this.hiContrastDefaultSize + this.sizeUnit;
   deleteCookie("fontSize", "/");
  }
  
}

/*********************************************************************************
  dw_cookies.js - cookie functions for www.dyn-web.com
  Recycled from various sources 
**********************************************************************************/

// Modified from Bill Dortch's Cookie Functions (hidaho.com) 
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

// from Bill Dortch's Cookie Functions (hidaho.com) 
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



