/* Inizio Storeddocs
Credit
Nick Sumner 
http://www.tele-pro.co.uk/scripts/storeddocs/ 
*/		
var expDays= 365;
  var CookieInfoStr='';
  var maxrows=30;

  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 + '\');">Salva in bacheca</a>');
}		
function ClearStoredDocumentsLink(){
    document.write ('<a href="javascript:del();" class=\"link-dart\">Svuota la bacheca</a>');
}			
function ShowStoredDocumentsLink(){
  var rows = 0;
  //document.write ('<ul>');
  //while (getCookie('names' + i) != null) {
   for (var i = 0; i < maxrows; i++) {
   if (getCookie('names' + i) != null) {
  document.write ('<table cellspacing=\"0\" cellpadding=\"0\"><tr>');  
   document.write ('<td style=\"width:12px; vertical-align:top\"><a href="javascript:delad(\'' + i + '\')"><img src=\"img/cancella.gif\" border=\"0\" alt=\"Elimina\" title=\"Elimina\" style=\"margin-top:5px\"></a></td>');
   document.write ('<td style=\"padding-bottom:3px\"><a href="' + getCookie('urls' + i) + ' ">' + getCookie('names' + i) + '</a></td>'); 
   document.write ('</tr></table>');
   rows++; 
  }

  } 
  if (rows==0){
   //document.write ('');  
   document.write ('La bacheca è vuota.' );
   //document.write ('');
  }
  //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++;	
  } 

if (i > (maxrows-1)) {alert('Hai raggiunto il limite massimo di ' + maxrows +' annunci in  bacheca.');} else {

  for (var irows = i; irows < maxrows; irows++) { 
  if (getCookie('names' + irows) == name) found=true;
  }

    
  if (!found) {
  setCookie ('names' + i, name, expdate);
  setCookie ('urls' + i, val, expdate);
  alert('L\'annuncio è stato inserito nella bacheca personale.');
  location.reload();
  }
  else {
  alert('Questo annuncio è già in bacheca.');
  }
 }
  
}

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('Sei sicuro di voler 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 è stata svuotata.');
  location.reload();
}
}

function delad(i) {
if (window.confirm('Sei sicuro di voler eliminare l\'annuncio dalla bacheca?')) {

  setCookie ('names' + i, '', olddate);
  setCookie ('urls' + i, '', olddate);
  alert('L\'annuncio è stato eliminato dalla bacheca.');
  location.reload();
}
}
/* FINE Storeddocs */

// Aggiungi ai preferiti
function preferiti(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


/// CONTROLLO CAMPI FORM (Rispondi all'annuncio)
function rispondi(){
with(document.modulo) {
	
	if(email.value=="") {
	alert("Inserisci l'indirizzo e-mail!");
	email.focus();
	return false;
	}
	var stato=true;
	if(email.value.indexOf(" ")!=-1) {
	email.focus();
	stato=false;
	}
	var chiocciola=email.value.indexOf("@");
	if(chiocciola<2) {
	email.focus();
	stato=false;
	}
	var punto=email.value.indexOf(".", chiocciola);
	if(punto<chiocciola+3) {
	email.focus();
	stato=false;
	}
	var lung=email.value.length;
	if(lung-punto<3) {
	email.focus();
	stato=false;
	}
	
	//if(stato) {
		//alert("E-mail valida");
	//}else{	

	if(stato==false) {
		alert("Inserisci un indirizzo e-mail valido!");
	return stato;
	}
	if(mail.value==false) {
	alert("Inserisci un messaggio!");
	mail.focus();
	return false;
	}
	
	if(captcha.value=="") {
	alert("Inserisci il codice di sicurezza!");
	captcha.focus();
	return false;
	}
}
//alert("Il modulo è completo, grazie!");
return true;
}	


/// CONTROLLO CAMPI FORM (Invia l'annuncio)
function validazione(){
with(document.segnala) {
	
	
	if(receiver_name.value=="") {
	alert("Inserisci il nome del tuo amico!");
	captcha.focus();
	return false;
	}
	
	if(receiver_email.value=="") {
	alert("Inserisci l'indirizzo e-mail del tuo amico!");
	receiver_email.focus();
	return false;
	}
	var stato=true;
	if(receiver_email.value.indexOf(" ")!=-1) {
	receiver_email.focus();
	stato=false;
	}
	var chiocciola=receiver_email.value.indexOf("@");
	if(chiocciola<2) {
	receiver_email.focus();
	stato=false;
	}
	var punto=receiver_email.value.indexOf(".", chiocciola);
	if(punto<chiocciola+3) {
	receiver_email.focus();
	stato=false;
	}
	var lung=receiver_email.value.length;
	if(lung-punto<3) {
	receiver_email.focus();
	stato=false;
	}	
      if(stato==false) {
		alert("Inserisci un indirizzo e-mail valido!");
	return stato;
	}
	
	if(sender_name.value=="") {
	alert("Inserisci il tuo nome!");
	captcha.focus();
	return false;
	}
	
	if(sender_email.value=="") {
	alert("Inserisci il tuo indirizzo e-mail!");
	sender_email.focus();
	return false;
	}
	var stato=true;
	if(sender_email.value.indexOf(" ")!=-1) {
	sender_email.focus();
	stato=false;
	}
	var chiocciola=sender_email.value.indexOf("@");
	if(chiocciola<2) {
	sender_email.focus();
	stato=false;
	}
	var punto=sender_email.value.indexOf(".", chiocciola);
	if(punto<chiocciola+3) {
	sender_email.focus();
	stato=false;
	}
	var lung=sender_email.value.length;
	if(lung-punto<3) {
	sender_email.focus();
	stato=false;
	}	
      if(stato==false) {
		alert("Inserisci un indirizzo e-mail valido!");
	return stato;
	}
	
	if(captcha.value=="") {
	alert("Inserisci il codice di sicurezza!");
	captcha.focus();
	return false;
	}
}
return true;
}	


// -------------------------------------------------------------------
// Image Thumbnail Viewer II- By Dynamic Drive, available at: http://www.dynamicdrive.com
// Last updated: Feb 5th, 2007
// -------------------------------------------------------------------

var thumbnailviewer2={
enableTitle: true, //Should "title" attribute of link be used as description?
enableTransition: true, //Enable fading transition in IE?
hideimgmouseout: false, //Hide enlarged image when mouse moves out of anchor link? (if enlarged image is hyperlinked, always set to false!)

/////////////No need to edit beyond here/////////////////////////

iefilterstring: 'progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)', //IE specific multimedia filter string
iefiltercapable: document.compatMode && window.createPopup? true : false, //Detect browser support for IE filters
preloadedimages:[], //array to preload enlarged images (ones set to display "onmouseover"
targetlinks:[], //array to hold participating links (those with rel="enlargeimage:initType")
alreadyrunflag: false, //flag to indicate whether init() function has been run already come window.onload

loadimage:function(linkobj){
var imagepath=linkobj.getAttribute("href") //Get URL to enlarged image
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
var dest=linkobj.getAttribute("rev").split("::")[1] //Get URL enlarged image should be linked to, if any
var description=(thumbnailviewer2.enableTitle && linkobj.getAttribute("title"))? linkobj.getAttribute("title") : "" //Get title attr
var imageHTML='<img src="'+imagepath+'" style="border-width: 0" />' //Construct HTML for enlarged image
if (typeof dest!="undefined") //Hyperlink the enlarged image?
imageHTML='<a href="'+dest+'">'+imageHTML+'</a>'
if (description!="") //Use title attr of the link as description?
imageHTML+='<br />'+description
if (this.iefiltercapable){ //Is this an IE browser that supports filters?
showcontainer.style.filter=this.iefilterstring
showcontainer.filters[0].Apply()
}
showcontainer.innerHTML=imageHTML
this.featureImage=showcontainer.getElementsByTagName("img")[0] //Reference enlarged image itself
this.featureImage.onload=function(){ //When enlarged image has completely loaded
if (thumbnailviewer2.iefiltercapable) //Is this an IE browser that supports filters?
showcontainer.filters[0].Play()
}
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
if (thumbnailviewer2.iefiltercapable) //Is this an IE browser that supports filters?
showcontainer.filters[0].Stop()
}
},

hideimage:function(linkobj){
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
showcontainer.innerHTML=""
},


cleanup:function(){ //Clean up routine on page unload
if (this.featureImage){this.featureImage.onload=null; this.featureImage.onerror=null; this.featureImage=null}
this.showcontainer=null
for (var i=0; i<this.targetlinks.length; i++){
this.targetlinks[i].onclick=null
this.targetlinks[i].onmouseover=null
this.targetlinks[i].onmouseout=null
}
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
},

init:function(){ //Initialize thumbnail viewer script
this.iefiltercapable=(this.iefiltercapable && this.enableTransition) //True or false: IE filters supported and is enabled by user
var pagelinks=document.getElementsByTagName("a")
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && /enlargeimage:/i.test(pagelinks[i].getAttribute("rel"))){ //Begin if statement: Test for rel="enlargeimage"
var initType=pagelinks[i].getAttribute("rel").split("::")[1] //Get display type of enlarged image ("click" or "mouseover")
if (initType=="mouseover"){ //If type is "mouseover", preload the enlarged image for quicker display
this.preloadedimages[this.preloadedimages.length]=new Image()
this.preloadedimages[this.preloadedimages.length-1].src=pagelinks[i].href
pagelinks[i]["onclick"]=function(){ //Cancel default click action
return false
}
}
pagelinks[i]["on"+initType]=function(){ //Load enlarged image based on the specified display type (event)
thumbnailviewer2.loadimage(this) //Load image
return false
}
if (this.hideimgmouseout)
pagelinks[i]["onmouseout"]=function(){
thumbnailviewer2.hideimage(this)
}
this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
} //end if statement
} //END FOR LOOP


} //END init() function

}


if (document.addEventListener) //Take advantage of "DOMContentLoaded" event in select Mozilla/ Opera browsers for faster init
thumbnailviewer2.addEvent(document, function(){thumbnailviewer2.alreadyrunflag=1; thumbnailviewer2.init()}, "DOMContentLoaded") //Initialize script on page load
else if (document.all && document.getElementsByTagName("a").length>0){ //Take advantage of "defer" attr inside SCRIPT tag in IE for instant init
thumbnailviewer2.alreadyrunflag=1
thumbnailviewer2.init()
}
thumbnailviewer2.addEvent(window, function(){if (!thumbnailviewer2.alreadyrunflag) thumbnailviewer2.init()}, "load") //Default init method: window.onload
thumbnailviewer2.addEvent(window, function(){thumbnailviewer2.cleanup()}, "unload")