<!--

// onLoad event
window.onload = function(){
    set_scroll();
}

/**
 * Restituisce il valore di un cookie
 *
 * @example
 *  var res = getCookie( 'variabile' );
 *
 */
function getCookie( name ) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return(null); 
   if (start == -1) return(null); 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return(unescape(document.cookie.substring(len,end)) ); 
}

/**
 * Imposta un cookie
 *
 * @example
 *
 * setCookie( 'variabile', 'valore', 10 );
 *
 */
function setCookie(name, value, expiredays, path, domain, secure) {
    var expires = new Date();
    expires.setDate( expires.getDate() + expiredays );
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") +        
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
}

/**
 * Elimina un cookie
 *
 * @example
 *  deleteCookie( 'variabile' );
 *
 */
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"; 
}

function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        var subSection = name.substring(6,0);
        if(subSection == " slide")
          document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}

// if query string in URL contains scroll=nnn, then scroll position will be restored
function set_scroll(){
    // get query string parameter with "?"
    //var search = window.location.search;
    var search = getCookie( 'scroll' );
    // if query string exists
    //if (search){
        // find scroll parameter in query string
        //var matches = /scroll=(\d+)/.exec(search);
        // jump to the scroll position if scroll parameter exists
        if (search) window.scrollTo(0, search);
    //}
}
 
// onBeforeUnload Event
window.onbeforeunload = function() {
  var scroll;
    // Netscape compliant
  if (typeof(window.pageYOffset) == 'number')
    scroll = window.pageYOffset;
  // DOM compliant
  else if (document.body && document.body.scrollTop)
    scroll = document.body.scrollTop;
  // IE6 standards compliant mode
  else if (document.documentElement && document.documentElement.scrollTop)
    scroll = document.documentElement.scrollTop;
  // needed for IE6 (when vertical scroll bar is on the top)
  else scroll = 0;
   // set cookie
  deleteCookie( 'scroll' );
  setCookie( 'scroll', scroll, 1 );
}


// -->

