onload=function(){ //al caricamento di pagina..
nw=getCookie("nw"); //reperisce il cookie
if(nw!=null){
if(nw=="yes"){
document.getElementById("newin").checked=true; //e setta il checkbox
addNW();
}
}
}
function check(){ //viene invocata all' onclick del checkbox
if(document.getElementById("newin").checked){ //se Ë settato..
setCookie("nw","yes",30);
addNW();
}
else{
setCookie("nw","no",30);
removeNW();
}
}
//aggiunge il title e fa aprire le nuove finestre sull' onclick dei link con classe ext
function addNW(){
l=document.getElementsByTagName("a");
for(i=0;i<l.length;i++){
c=l[i].className;
if(c.indexOf("ext")!=-1){
l[i].title="link esterno, si apre in una nuova finestra";
l[i].onclick=function(){window.open(this.href);return(false);};
}
}
}
function removeNW(){ //ripristina il comportamento normale
l=document.getElementsByTagName("a");
for(i=0;i<l.length;i++){
if(l[i].className.indexOf("ext")!=-1){
l[i].title="link esterno";
l[i].onclick=function(){};
}
}
}
//funzioni di manipolazione dei cookie
function setCookie(name, value, expdays) { //memorizza il cookie
var now = new Date();
var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
document.cookie = name + "=" + escape(value) + ";" + "expires=" + exp.toGMTString() + ";" + "path=/";
}
function getCookie(name) { //restituisce il cookie
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
var start = dc.indexOf(cname);
if (start != -1) {
start += cname.length;
var stop = dc.indexOf(";", start);
if (stop == -1) stop = dc.length;
return unescape(dc.substring(start,stop));
}
}
return null;
}