function setCookie( name, value, days ) {
  var exp = null;
  if (days != null) {
    exp = new Date();
    exp.setTime( exp.getTime() + (1000 * 60 * 60 * 24 * days));
  }
  document.cookie=name+"="+escape(value)+"; path=/"+((exp==null)?"":"; expires="+exp.toGMTString());
}
function getCookie( name ) {
   var prefix = name + '=';
   var beg = document.cookie.indexOf(prefix);
   if (beg == -1) return '';
   var end = document.cookie.indexOf(";", beg + prefix.length);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(beg + prefix.length, end));
}
function closeInformationForm() {
  $('frm-information').remove();
  $('canvas').remove();
  return false;
}
function closeSavedInformationForm() {
  setCookie('knowUser','YES',5);
  var link = $('frm-information').getAttribute('link');
  if (link) window.location = link;
  return closeInformationForm();
}
function openInformationForm() {
  var link = this.href;
  var knowUser = getCookie('knowUser');
  if (knowUser == 'YES') return true;
  new Ajax.Request('/information/new', {
    method: 'get',
    onSuccess: function(transport) {
      var div = document.createElement('DIV');
      div.id = 'canvas';
      document.body.appendChild(div);
      new Insertion.Before($('canvas'), transport.responseText );
      var win = document.body.offsetWidth;
      $('frm-information').setStyle({left: ((win-400)/2)+'px'});
      $('frm-information').setAttribute('link',link);
      $A($$('#frm-information div.close, #frm-information input[name=cancel]')).each(
       function(elem) {
        elem.onclick = closeInformationForm;
      });
      window.scrollTo(0,0);
    }
  });
  return false;
}
function initAnhors() {
  var knowUser = getCookie('knowUser');
  if (knowUser == 'YES') return true;
  $$('a').each( function( anchor ) {
    var pdfext = new RegExp("\\.pdf$", "gi")
    if (anchor.href.match( pdfext )) {
      anchor.onclick = openInformationForm;
    }
  });
}
function initPage() {
  // initAnhors();
}
Event.observe(window, 'load', initPage );