 var expDays= 365;
  var CookieInfoStr='';

  var expdate = new Date();
  var olddate = new Date();
  expdate.setTime (expdate.getTime() + (expDays*24*60*60*1000));
  olddate.setTime (expdate.getTime() - (expDays*24*60*60*1000));
		
function StoreDocumentLink(){

    var string1=document.title;
    cleanstring1=string1.replace(/["']/g, "");
    document.write ('<a href="javascript:addCookieArray(\'' + cleanstring1 + '\',\'' + location.href + '\');"><img src="dettagli/add.png"  border="0" align="absmiddle"></a>');
}		
function ClearStoredDocumentsLink(){
    document.write ('<a href="javascript:del();"><img src="dettagli/remall.png" align="absmiddle"  border="0"></a>');
}			
function ShowStoredDocumentsLink(){
  var presence = 0;
  //document.write ('<ul>');
  //while (getCookie('names' + i) != null) {
   for (var i = 0; i < 100; i++) {
   if (getCookie('names' + i) != null) {
   document.write ('<img src="images/note.png" width="15" border="0" align="absmiddle" hspace="2">');  
   document.write ('<a href="' + getCookie('urls' + i) + ' " target="_self">' + getCookie('names' + i) + '</a>' + ' | <a href="javascript:delselect(\'' + i + '\')"><img src="dettagli/delete.png"  border="0" align="absmiddle"></a>');
   document.write ('<br><hr style="height:1px" color="#e3e464">');
   presence++; 
  }

  } //Close  
  if (presence==0){
   document.write ('<img src="images/note.png" width="15" border="0" align="absmiddle" hspace="2">');  
   document.write ('Nessun annuncio in bacheca' );
   document.write ('<br>');
  }
  //document.write ('</ul>');

}
function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
  while (cbegin < clen) {
  var vbegin = cbegin + cname.length;
  if (dcookie.substring(cbegin, vbegin) == cname) { 
    var vend = dcookie.indexOf (";", vbegin);
    if (vend == -1) vend = clen;
    return unescape(dcookie.substring(vbegin, vend));
  }
  cbegin = dcookie.indexOf(" ", cbegin) + 1;
  if (cbegin == 0) break;
  }
return null;
}
function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie=name+"="+escape (value)+"; expires="+expires.toGMTString()+"; path=/";
}
function setCookieArray(name){
this.length = setCookieArray.arguments.length - 1;
  for (var i = 0; i < this.length; i++) {
  this[i + 1] = setCookieArray.arguments[i + 1];
  setCookie (name + i, this[i + 1], expdate);
  }  
}
function addCookieArray(name, val){
  var i = 0;
  var found=false;
    
  while (getCookie('names' + i) != null) { 
    if (getCookie('names' + i) == name) found=true;
    i++;	
  } 

//Limit
if (i > 99) {alert('Hai raggiunto il limite di 100 annunci in questa bacheca. ');} else {

  //complete check presence on entire array
  for (var ipresence = i; ipresence < 100; ipresence++) { 
  if (getCookie('names' + ipresence) == name) found=true;
  }
    
  if (!found) {
  setCookie ('names' + i, name, expdate);
  setCookie ('urls' + i, val, expdate);
  alert('L\'annuncio e stato inserito nella bacheca personale. ');
  location.reload();
  }
  else {
  alert('Questo annuncio e gia presente in bacheca. ');
  }
  
}//close
  
}

function getCookieArray(name){
var i = 0;
  while (getCookie(name + i) != null) {
  this[i + 1] = getCookie(name + i);
  i++; this.length = i;
  }		
}
function del() {
var i = 0;
if (window.confirm('Vuoi veramente svuotare la bacheca?  ')) {

  while (getCookie('names' + i) != null) {
  setCookie ('names' + i, '', olddate);
  setCookie ('urls' + i, '', olddate);
  i++; 
  }  
  i++; 
  setCookie ('names' + i, '', olddate);
  setCookie ('urls' + i, '', olddate);   
  alert('La bacheca e stata svuotata. ');
  location.reload();
}
}

function delselect(i) {
if (window.confirm('Vuoi eliminare l\'annuncio dalla bacheca?  ')) {

  setCookie ('names' + i, '', olddate);
  setCookie ('urls' + i, '', olddate);
  alert('L\'annuncio e stato eliminato dalla bacheca. ');
  location.reload();
}
}
