
// variabili globali
var smiliestrans = null;

// variabili per le funzioni dell'archivio
var archivio_anno_corrente = 0;
var object_type_selected = null;
var anno_object_selected = null;
var mese_object_selected = null;

/**************************************************************************
 * Funzioni per l'archivio												  *
 **************************************************************************/
function loadDefaultsArchivio(){
	
	var archivioAnni = document.getElementById("archivio-anni"); 
	archivioAnni.style.background = "url(/images/indicator.gif) no-repeat center center";
	
	var myEffect = new fx.Opacity(archivioAnni.getElementsByTagName("ul")[0] , {duration: 500} );
	myEffect.hide();

	var bindArgs = {
		url: "archivio-ajax.asp?tipo=anni",
		//url: "/public/ajax.xml",
		
		mimetype: "text/xml",
		error: function(type, errObj){
			archivioAnni.style.background = "url(/images/indicator.gif) no-repeat center center";
		},
		load: function(type, data, evt){
			var content = new dojo.string.Builder("");
			var anni = data.getElementsByTagName("anno");
			for (var i=0; i<anni.length; i++) {
				node 		= anni.item(i);
				anno 		= node.childNodes.item(0).data;
				totElementi = node.getAttribute("tot");
				content.append("<li onmouseover=\"this.className = 'selected'\" onmouseout=\"removeSelected(this)\" onclick=\"cambiaAnno(this, "+ totElementi +")\"><strong>"+ anno +"</strong>&nbsp;&nbsp;<img src=/images/frecciaVerde.jpg></li>");
			}
			
			archivioAnni.childNodes[0].innerHTML = content.toString();
			archivioAnni.style.background = "none";
			
			object_type_selected = "anni";
			content = null;
			
			myEffect.toggle();
		}
	};//

	dojo.io.bind(bindArgs);
}

function removeSelected(obj){
	for (var i=0; i<obj.parentNode.childNodes.length; i++) {
		node = obj.parentNode.childNodes[i];
		node.className = "";
		if( node == anno_object_selected || node == mese_object_selected ) {
			node.className = "selected";		
		}
	}
}

function cambiaAnno(obj, anno){
	
	object_type_selected = "anni";
	anno_object_selected = obj;
	archivio_anno_corrente = anno;

	removeSelected(obj);
	obj.className = "selected";
	
	var archivioMesi = document.getElementById("archivio-mesi");
	
	archivioMesi.innerHTML = "<ul><li></li></ul>";
	archivioMesi.style.background = "url(/images/indicator.gif) no-repeat center center";
	document.getElementById("archivio-posts").innerHTML = "";
			
	var myEffect = new fx.Opacity(archivioMesi.getElementsByTagName("ul")[0] , {duration: 500} );
	myEffect.hide();
	
	var bindArgs = {
		url: "archivio-ajax.asp?tipo=mesi&anno="+ anno,
		mimetype: "text/xml",
		error: function(type, errObj){
			document.getElementById("archivio-mesi").style.background = "none";
		},
		load: function(type, data, evt){
			var content = new dojo.string.Builder("");
			var mesi = data.getElementsByTagName("mese");
			for (var i=0; i<mesi.length; i++) {
				node 		= mesi.item(i);
				mese 		= node.childNodes.item(0).data;
				numeroMese  = node.getAttribute("n");
				totElementi = node.getAttribute("tot");
				content.append("<li onmouseover=\"this.className = 'selected'\" onmouseout=\"removeSelected(this)\" onclick=\"cambiaMese(this, "+ numeroMese +")\"><strong>"+ mese +"</strong>&nbsp;&nbsp;<img src=/images/frecciaVerde.jpg></li>");
			}
			archivioMesi.childNodes[0].innerHTML = content.toString();
			archivioMesi.style.background = "none";
			content = null;
			
			myEffect.toggle();
		}
	};
	dojo.io.bind(bindArgs);
}

function cambiaMese(obj, mese){

	object_type_selected = "mesi";
	mese_object_selected = obj;
	
	removeSelected(obj);
	obj.className = "selected";
	
	var archivioPosts = document.getElementById("archivio-posts"); 
	archivioPosts.innerHTML = "<ul><li><em></em></li></ul>";
	archivioPosts.style.background = "url(/images/indicator.gif) no-repeat center center";
	
	var myEffect = new fx.Opacity(archivioPosts.getElementsByTagName("ul")[0] , {duration: 1000} );
	myEffect.hide();
	
	var bindArgs = {
		url: "archivio-ajaxNS.asp?tipo=posts&anno="+ archivio_anno_corrente +"&mese="+ mese,
		mimetype: "text/xml",
		error: function(type, errObj){
			document.getElementById("archivio-posts").style.background = "none";
		},
		load: function(type, data, evt){
			var content = new dojo.string.Builder("");
			var posts = data.getElementsByTagName("post");
			for (var i=0; i<posts.length; i++) {
				node 	= posts.item(i);
				title 	= node.childNodes.item(0).data;
				path  	= node.getAttribute("path");
			
				content.append("<li onmouseover=\"this.className = 'selected'\" onmouseout=\"removeSelected(this)\"  onClick=\"Richiesta('"+ path +"')\"><strong>"+ title +"</strong></li>");
			}
			archivioPosts.childNodes[0].innerHTML = content.toString();
			archivioPosts.style.background = "none";
			content = null;
			
			myEffect.toggle();
		}
	}
	dojo.io.bind(bindArgs);
}

/**************************************************************************
 * associa a tutte le ancore l'attributo target="_blank"				  *
 **************************************************************************/
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if ( anchor.getAttribute("href") &&	anchor.getAttribute("rel") == "external" ){
			anchor.target = "_blank";
		}
	}
}


