function openMonth(id)
{
	//expand_collapse_standard("scdmntmenu" + id);
  	expand_collapse_standard("mnt" + id);
	/*SetCookie('currentMonth',id); commenta l'istruzione che scrive il cookie*/
	collapse_all('scd');
}

function openCurrentMonth()
{
	
	id =getCookie('currentMonth')
	if (id == ''){
		id=2;
	}
	openMonth(id);
}

function getCookie(NameOfCookie){
/*funzione atta a leggere un cookie per intero, non la chiave singola...*/
   if (document.cookie.length > 0)
{
      begin = document.cookie.indexOf(NameOfCookie+"=");
      if (begin != -1)
      {
         begin += NameOfCookie.length+1;
         end = document.cookie.indexOf(";", begin);
         if (end == -1) end = document.cookie.length;
         return unescape(document.cookie.substring(begin, end));
      }
   }
   return '';
}

function SetCookie (name, value) {
/*funzione atta a scrivere un cookie per intero, non la chiave singola...*/
    var todayDate = largeExpDate = new Date ();
    largeExpDate.setTime(todayDate.getTime() + 365 * 24 * 3600 * 1000);
    document.cookie = name+'='+escape(value)+'; expires=' + largeExpDate.toGMTString();
}

function expand_collapse_Day(ident)
{
	expand_collapse_standard(ident);
	window.scroll(0,150);
}

/*funzione apri/chiudi sezioni standard id-cizzate*/
function expand_collapse_standard(ident)
{
	var idpart=ident.substr(0,3);
	collapse_all(idpart);

	obj = document.getElementById(ident);
	if (obj.style.display == "none")
	{
		obj.style.display = "";
	}
	else
	{
		obj.style.display = "none"; 
	}
}

/*chiude tutti gli elementi con id che cominciano per "idpart" (3 caratteri)*/
function collapse_all(idpart)
{
	var divs = document.getElementsByTagName("div");
	for (i=0;i<divs.length;i++) {
		if(divs[i].getAttribute("id") && divs[i].getAttribute("id").search(idpart)!= -1) divs[i].style.display = "none";
	}
}

/*apre/chiude gli elementi con id "ident"*/
function change_status (ident)
{
	obj = document.getElementById(ident);
	header_img = document.getElementById(ident + "_h");

	if (obj.style.display == "none")
	{
		obj.style.display = "";
		header_img.src = "http://www.ipsoa.it/images/collapse.gif";
	}
	else
	{
		obj.style.display = "none"; 
		header_img.src = "http://www.ipsoa.it/images/expand.gif"; 
	}
}


/*
funzione per la visualizzazione delle pagine pop up

*/
function popup(url, w, h) {
	window.open(url,"_newPopUp","scrollbars=yes,resizable=yes,width="+ w +",height="+ h +",status=no,location=no,toolbar=no");
	return void(0);
}

function openPopup(url, w, h) {
	window.open(url,"_newPopUp","scrollbars=yes,resizable=yes,width="+ w +",height="+ h +",status=no,location=no,toolbar=no");
	return void(0);
}

function openNewsletter(url) {
	window.open(url,"_newNewsletter","scrollbars=yes,resizable=yes,width=710,height=500,status=no,location=no,toolbar=no");
	return void(0); 
}

function openRivAnteprima(url) {
	window.open(url,"_newAnteprimaRivista","scrollbars=yes,resizable=yes,width=500,height=700,status=no,location=no,toolbar=no");
	return void(0); 
}

function openAttach(url) {
	window.open(url,"_newAttach","scrollbars=yes,resizable=yes,width=500,height=700,status=no,location=no,toolbar=no");
	return void(0); 
}

function openDocument(url) {
	return popup(url, 500, 400)
}

function popUpLink(percorso,w,h) {
	window.open(percorso,"_newPopUpLink","scrollbars=yes,resizable=yes,width="+w+",height="+h+",status=no,location=no,toolbar=no");
return false;
}

/* vecchia versione mantenuta per compatibilità*/
function PopUp(percorso,w,h,scroll,dir) {
	window.open(percorso+"&dir="+dir,"_newPopUp","scrollbars=" + scroll + ",resizable=yes,width="+w+",height="+h+",status=no,location=no,toolbar=no");
return false;
}


/*
funzioni per evidenziare le ricerche nei documenti
data: 2005 05 19
author: FC
*/
function highlightWord(node, word) {
	if (node.hasChildNodes) {
		for (var i = 0; i < node.childNodes.length; i++) {
			highlightWord(node.childNodes[i], word);
		}
	}
	
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "highlight") { // word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal); // Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "highlight";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function highlightUrl(url, param, check) {
	if (url.indexOf('?') == -1) return;
	url = url.toLowerCase()
	if (check && url.indexOf(check) == -1) return; // check string not found
	qs = url.substr(url.indexOf('?') + 1);
	qsa = qs.split('&');
	for (var i = 0; i < qsa.length; i++) {
		qsip = qsa[i].split('=');
	    if (qsip.length == 1) continue;
        if (qsip[0] == param) { 
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	        for (var w = 0; w < words.length; w++) {
				if (words[w].length > 1) 
					highlightWord(document.getElementsByTagName("body")[0], words[w]);
            }
	    }
	}
}

document.write("<style>.highlight {background-color: #AAC8D6;}</style>");

function highlightSearch() {
	if (!document.createElement) return;
	highlightUrl(document.referrer, "q", ".google.")
	highlightUrl(document.referrer, "q", ".msn.")
	highlightUrl(document.referrer, "p", ".yahoo.")
	highlightUrl(document.referrer, "qs", ".virgilio.")
	highlightUrl(document.referrer, "highlight", "highlight")
	highlightUrl(document.location.href, "highlight", "highlight")
}

window.onload = highlightSearch

