/* default javascript for extension "gov_synergie" */
/*********************************************************************************
  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";
  }
}

/*  
    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: 100,
	hiContrastDefaultSize: 100,
	// numbers (same unit as sizeUnit)
	maxSize:     140,
	minSize:     80,

init: function() {
    if ( !document.body || !document.getElementById ) return;
    var size = window.location.search? window.location.search.slice(1): 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;
    var colzoom=document.getElementById('colzoom');
    var HtmlZOOM='';

    HtmlZOOM+='            <h2 class="lightblu1"><b>Zoom Pagina</b></h2>';
    HtmlZOOM+='                <ul>';
    HtmlZOOM+='                        <li><a href="#" onclick="dw_fontSizer.adjust(10); return false;" onkeypress="dw_fontSizer.adjust(10); return false;" title="aumenta le dimensioni della pagina e dei caratteri"><span>ingrandimento [+]</span></a></li>';
    HtmlZOOM+='                        <li><a href="#" onclick="dw_fontSizer.adjust(-10); return false;" onkeypress="dw_fontSizer.adjust(-10); return false;" title="riduci le dimensioni della pagina e dei caratteri"><span>riduzione [-]</span></a></li>';
    HtmlZOOM+='                        <li><a href="#" onclick="dw_fontSizer.reset(); return false;" onkeypress="dw_fontSizer.reset(); return false;" title="riporta la pagina alle dimensioni di default"><span>dimensione iniziale [=]</span></a></li>';
    HtmlZOOM+='                </ul>';
    colzoom.innerHTML=HtmlZOOM;
    
  },
  
  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", "/");
  }
  
}


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function autoClear(obj,def){
 if (obj.value==def) obj.value=""
}

function inizializza() {
a = document.getElementsByTagName('A');
for(i=0;a[i];i++) if(a[i].className.indexOf('blank') != -1) {
a[i].title += " [il collegamento apre una nuova finestra]";
a[i].onclick = function () {window.open(this.href, '_blank');return false;};
a[i].onkeypress = function (e) {
k = (e) ? e.keyCode : window.event.keyCode;
if(k==13) {
window.open(this.href, '_blank');
return false;
}
}
}
}


