// JavaScript Document
/*
########################################
########################################
##									  ##
## F5 - Content Management System 	  ##
##									  ##
## Copyright © 2007					  ##
## 	Reload - Laboratorio Multimediale ##
## 	(http://www.reloadlab.it -		  ##
## 	info@reloadlab.it)				  ##
##									  ## 
## author:							  ##
## 	Domenico Gigante				  ##
## 	(domenico@reloadlab.it)			  ##
## 	Alessio Attanasio				  ##
##  (aatt@reloadlab.it)				  ##
##									  ##
########################################
########################################
*/

/* Gestione menu a comparsa */
function manageMenuList(obj){
	obj.className += " over";
	obj.onmouseout = function() {
		this.className = this.className.replace(" over", "");
	}
}

/* gestione del menu cartelle */
function mmenu(elem) {
	var menuDir = $(elem);
	var displayDir = menuDir.style.display;
	menuDir.style.display = (displayDir == "block") ? "none" : "block";
	menuDir.parentNode.style.listStyleImage = (displayDir == "block") ? "url(ico/folder_closed.gif)" : "url(ico/folder_open.gif)";
}

/* inizializzazione del menu */
function initDirList() {
	var uls = document.getElementsByTagName("ul");
	for (i = 0; i < uls.length; i++) {
		if(uls[i].className == "dirlist") uls[i].style.display = "none";
		if(uls[i].className == "dirlistBlock") uls[i].style.display = "block";
	}
}

/* AGGIUNGI / ELIMINA RISPOSTA A SONDAGGIO */
function addRow(){
	var r = document.getElementById('mytab').getElementsByTagName('span');
	var len = r.length;
	var clone = r[0].cloneNode(true);
	for(var i = 0; i < clone.getElementsByTagName('td').length; i++){
		var kids = clone.getElementsByTagName('td')[i].childNodes;
		for(var j = 0; j < kids.length; j++){
			(kids[j].name)?kids[j].name+=len:null
		}
	}
	r[0].parentNode.appendChild(clone)
}
function deleteElement() {
	var r = document.getElementById('mytab');
	if(r.hasChildNodes()) {
		var children = r.childNodes
		var n = children.length - 1
		if(n > 0){
			var lastChild = children.item(n)
			r.removeChild(lastChild)
		}
	}
}

/* Apertura pop-up */
function openPopup(url, name, w, h, s){
	var prop = "width=" + w + ", height=" + h + ", scrollbars=" + s + ", top=100, left=100";
	window.open(url, name, prop);
}

function mostraTesto(id) {
	var elem = $(id);
	var dspl = elem.style.display;
	elem.style.display = (dspl == "inline") ? "none" : "inline";
}

function VisibleElement(obj, elem){
	if($(elem).style.display == 'block'){
		$(elem).style.display = 'none';
		obj.src = 'ico/maximize.gif';
	}
	else{
		$(elem).style.display = 'block';
		obj.src = 'ico/minimize.gif';
	}
}
function changeLeftMenu(obj, elem){
	if($(elem).style.display == 'block'){
		$(elem).style.display = 'none';
		$('spalla').style.width = '18px';
		obj.src = 'ico/maximize.gif';
	}
	else{
		$(elem).style.display = 'block';
		$('spalla').style.width = '400px';
		obj.src = 'ico/minimize.gif';
	}
}

function googleLoad(){
	return;	
}

/* Prototype Ajax */
function setAjaxProto(method, fload, ferror, formId){
	bindArgs = new Object();
	method = (method != null)?method:"post";
	bindArgs.method = method;
	if(fload != null) bindArgs.onSuccess = fload;
	if(ferror != null) bindArgs.onFailure = ferror;
	if(formId != null) bindArgs.parameters = Form.serialize($(formId));
	return bindArgs;
}

function setRespProto(fcreate, fcomplete){
	bindArgs = new Object();
	if(fcreate != null) bindArgs.onCreate = fcreate;
	if(fcomplete != null) bindArgs.onComplete = fcomplete;
	return bindArgs;
}

/* mia funzione */
function myAjaxFunc(url){
	if(url == null) return;
	params = setAjaxProto('get', fload, ferror, null);
	var req = new Ajax.Request(url, params);
	
	// opzionale
	other = setRespProto(fcreate, fcomplete);
	Ajax.Responders.register(other);
}

/* Tipo fload */
function floadExemple(resp){
	// qualcosa	succede
}

/* Tipo ferror */
function ferrorExemple(error){
	// qualcosa	succede
}

/* Tipo fcreate */
function fcreateExemple(){
	// qualcosa	succede
}

/* Tipo fcomplete */
function fcompleteExemple(){
	if(Ajax.activeRequestCount == 0){
		// qualcosa	succede
	}
}

