// JavaScript Document
//-------- addLoadEvent() 
function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window.onload!='function')
    window.onload = func;
else
    window.onload=function(){
      if(oldonload)
        oldonload();
      func();
      }
}

addLoadEvent(function(){	//al caricamento di pagina..
nw=getCookie("nw");			//reperisce il cookie
if(nw!=null){
	if(nw=="yes"){
		if(document.body.id=='home') document.getElementById("newin").checked=true; //e setta il checkbox
		addNW();
		}
	}
}
)

function modificaLinks() {
var sezione = document.getElementById('content');
var links = sezione.getElementsByTagName('a');
var sito = /\.asp/i;
for (i = 0; i < links.length; i++) {
var link = links[i];
url = links[i].getAttribute('href');
if (url.match(sito)) {
//link.className='css';
//link.setAttribute('class', 'css'); 
					}
else {
link.className='web';
link.setAttribute('class', 'web'); 
		}
	}
}

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+=" [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=l[i].title.replace(' [si apre in una nuova finestra]', '');
	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;
}
