// CLASSE ListFormActionHandler
    function ListFormActionHandler(formName){
      	this.actions = new Array();
		this.formName = formName;
    }
    // aggiunge una nuova azione (nome azione, messaggio conferma azione)
    ListFormActionHandler.prototype.addAction = function(name, message){
      	var idx = this.actions.length;
        this.actions[idx] = new Object();
      	this.actions[idx].name = name;
        this.actions[idx].message = message;
    }
    // azione di gruppo su checkbox 'selItemsId'
    ListFormActionHandler.prototype.selActionChanged = function(){
      	var objForm = document.forms[this.formName];
    	if(!FormUtil.existsSelected(objForm, "selItemsId")) {
			objForm.selAction.selectedIndex = 0;
			return;
		}
        var name = objForm.selAction.options[objForm.selAction.selectedIndex].value;
        var item;
      	for(var n=0;n<this.actions.length;n++){
        	item = this.actions[n];
            if(item.name==name){
            	if(!confirm(item.message)) {
					objForm.selAction.selectedIndex = 0;
				}
                else{
                	objForm.cmd.value = item.name;
					objForm.submit();
                }
                return;
            }
        }
    }
	// azione singolo elemento / senza elemento
    ListFormActionHandler.prototype.doAction = function(actionName, fieldName, fieldValue){
		var objForm = document.forms[this.formName];
        var item;
      	for(var n=0;n<this.actions.length;n++){
        	item = this.actions[n];
            if(item.name==actionName){
            	if(item.message){
					if(!confirm(item.message)) return;
            	}
				if(fieldName) objForm.elements[fieldName].value = fieldValue;
				objForm.cmd.value = item.name;
				objForm.submit();
				return;
      		}
        }
    }
    // seleziona tutti i checkbox 'selItemsId' della form 'listForm'
    ListFormActionHandler.prototype.selectAll = function(){
		FormUtil.selectAll(document.forms[this.formName], "selItemsId");
    }
    // deseleziona tutti i checkbox 'selItemsId' della form 'listForm'
   	ListFormActionHandler.prototype.selectNone = function(){
		FormUtil.selectNone(document.forms[this.formName], "selItemsId");
    }
// FINE classe ListFormActionHandler

// CLASSE FormUtil
    function FormUtil(){}
	//seleziona tutti i checkBox di una form
	FormUtil.selectAll = function(objForm, checkBoxName){
		var obj=objForm.elements[checkBoxName];
		if(obj){
			if(obj.length>1){
				for(var n=0;n<obj.length;n++){
					obj[n].checked=true;
				}
			}
			else{
				obj.checked=true;
			}
		}
	}
	//controlla per almeno un chbox selezionato, ritorna true|false
	FormUtil.existsSelected = function(objForm, checkBoxName){
		var obj=objForm.elements[checkBoxName];
		if(obj){
			if(obj.length>1){
				for(var n=0;n<obj.length;n++){
					if(obj[n].checked) return true;
				}
			}
			else{
				if(obj.checked) return true;
			}
		}
		return false;
	}
	FormUtil.selectNone = function(objForm, checkBoxName){
		var obj=objForm.elements[checkBoxName];
		if(obj){
			if(obj.length>1){
				for(var n=0;n<obj.length;n++){
					obj[n].checked=false;
				}
			}
			else{
				obj.checked=false;
			}
		}
	}
// FINE classe FormUtil

	
/*
	SelectOrder: ordinatore di select
	costruttori:
		SelectOrder(refOggettoSelectdaOrdinare)
	metodi:
		moveUp()
			sposta in alto l'elemento selezionato
		moveDown()
			sposta in basso l'elemento selezionato
		selectAllItems()
			seleziona tutti gli item
*/
SelectOrder = function(selectObj) {
	this.selectObj = selectObj;
};
SelectOrder.prototype.moveUp = function(){
	// esco se non è selezionato alcun elemento o se è selezionato il primo (selectedIndex==0)
	if (this.selectObj.selectedIndex < 1) return;

	var indexSource = this.selectObj.selectedIndex;
	var indexTarget = indexSource - 1;
	var savedText  = this.selectObj.options[indexTarget].text
	var savedValue = this.selectObj.options[indexTarget].value
	this.selectObj.options[indexTarget].text	=  this.selectObj.options[indexSource].text
	this.selectObj.options[indexTarget].value	=  this.selectObj.options[indexSource].value
	this.selectObj.options[indexSource].text  = savedText;
	this.selectObj.options[indexSource].value = savedValue;
	this.selectObj.selectedIndex = indexTarget;
};
SelectOrder.prototype.moveDown = function(){
	// esco se non è selezionato alcun elemento o se è selezionato l'ultimo (selectedIndex==selectObj.length)
	if (this.selectObj.selectedIndex < 0 || this.selectObj.selectedIndex==this.selectObj.length-1) return;

	var indexSource = this.selectObj.selectedIndex;
	var indexTarget = indexSource + 1;
	var savedText  = this.selectObj.options[indexTarget].text
	var savedValue = this.selectObj.options[indexTarget].value
	this.selectObj.options[indexTarget].text	=  this.selectObj.options[indexSource].text
	this.selectObj.options[indexTarget].value	=  this.selectObj.options[indexSource].value
	this.selectObj.options[indexSource].text  = savedText;
	this.selectObj.options[indexSource].value = savedValue;
	this.selectObj.selectedIndex = indexTarget;
};
SelectOrder.prototype.selectAllItems = function(){
	var n;
	for(n=0;n<this.selectObj.length;n++){
		this.selectObj.options[n].selected=true;
	}
};
//FINE classe SelectOrder

/*
	MoveOptions: sposta options tra due select (sorgente e destinazione)
	costruttori:
		MoveOptions(sourceSelect, destSelect)
	metodi:
		moveSourceToDest()
			sposta gli elementi selezionati dalla sourceSelect alla destSelect
		moveDestToSource()
			sposta gli elementi selezionati dalla destSelect alla sourceSelect
		selectAllSourceItems()
			seleziona tutti gli elementi della sourceSelect
		selectAllDestItems()
			seleziona tutti gli elementi della destSelect
*/
MoveOptions = function(sourceSelectObj, destSelectObj) {
	this.sourceSelectObj = sourceSelectObj;
	this.destSelectObj = destSelectObj;
};
MoveOptions.prototype.moveSourceToDest = function(){
	var n=0, nn=0;
	var moved = new Array();
	for(n=0;n<this.sourceSelectObj.length;n++){
		if(this.sourceSelectObj.options[n].selected){
			moved[nn++] = this.sourceSelectObj.options[n];
			this.destSelectObj.options[this.destSelectObj.length] = new Option(this.sourceSelectObj.options[n].text, this.sourceSelectObj.options[n].value);
		}
	}
	for(n=0;n<moved.length;n++){
		for(nn=0;nn<this.sourceSelectObj.length;nn++){
			if(this.sourceSelectObj.options[nn] && this.sourceSelectObj.options[nn] == moved[n]) this.sourceSelectObj.options[nn] = null;
		}
	}
};
MoveOptions.prototype.moveDestToSource = function(){
	var n=0, nn=0;
	var moved = new Array();
	for(n=0;n<this.destSelectObj.length;n++){
		if(this.destSelectObj.options[n].selected){
			moved[nn++] = this.destSelectObj.options[n];
			this.sourceSelectObj.options[this.sourceSelectObj.length] = new Option(this.destSelectObj.options[n].text, this.destSelectObj.options[n].value);
		}
	}
	for(n=0;n<moved.length;n++){
		for(nn=0;nn<this.destSelectObj.length;nn++){
			if(this.destSelectObj.options[nn] && this.destSelectObj.options[nn] == moved[n]) this.destSelectObj.options[nn] = null;
		}
	}
};
MoveOptions.prototype.selectAllSourceItems = function(){
	var n;
	for(n=0;n<this.sourceSelectObj.length;n++){
		this.sourceSelectObj.options[n].selected=true;
	}
};
MoveOptions.prototype.selectAllDestItems = function(){
	var n;
	for(n=0;n<this.destSelectObj.length;n++){
		this.destSelectObj.options[n].selected=true;
	}
};
//FINE classe MoveOptions


// vecchie funzioni 'old style'

//controlla almeno un chbox selezionato, ritorna true|false
function existsSelected(formObj, checkBoxName){
	var obj=formObj.elements[checkBoxName];
	if(obj){
		if(obj.length>1){
			for(var n=0;n<obj.length;n++){
				if(obj[n].checked) return true;
			}
		}
		else{
			if(obj.checked) return true;
		}
	}
	return false;
}


//seleziona tutti i chbox
function selectAll(formObj, checkBoxName){
	var obj=formObj.elements[checkBoxName];
	if(obj){
		if(obj.length>1){
			for(var n=0;n<obj.length;n++){
				obj[n].checked=true;
			}
		}
		else{
			obj.checked=true;
		}
	}
	return;
}


//deseleziona tutti i chbox
function selectNone(formObj, checkBoxName){
	var obj=formObj.elements[checkBoxName];
	if(obj){
		if(obj.length>1){
			for(var n=0;n<obj.length;n++){
				obj[n].checked=false;
			}
		}
		else{
			obj.checked=false;
		}
	}
	return;
}



// funzione di controllo di validità della data
// compatibilità con Netscape 4.5, 4.7 , 6.0 ed Explorer 4, 5, 5.5
//IN 	: stringa di data nel formato giorno/mese/anno
//OUT	: true = data valida / false = data non valida
function isDateS(data)
{
	if (data.indexOf("/") == data.lastIndexOf("/") || data.indexOf("/") == -1 || data.lastIndexOf("/")==-1)
		return false

	gg		= data.split("/")[0]
	mm		= data.split("/")[1]
	aaaa	= data.split("/")[2]

	return (isDate(gg,mm,aaaa))
}

// funzione di controllo per data inserita in un campo triplice nel formato gg/mm/aaaa
// compatibilità con Netscape 4.5, 4.7 , 6.0 ed Explorer 4, 5, 5.5
//IN 	: variant giorno, variant mese, variant anno 4 cifre
//OUT	: true = data valida / false = data non valida
function isDate(gg,mm,aaaa)
{

		gg = Number(gg)
		mm = Number(mm)

	if(aaaa.length<4) return false;
	else
	{
		data = new Date(aaaa,mm-1,gg)
		gg1 = data.getDate()
		mm1 = data.getMonth()+1
		aaaa1 = data.getFullYear()

		datainput = gg+"/"+mm+"/"+aaaa
		dataresult = gg1+"/"+mm1+"/"+aaaa1
		if (dataresult!=datainput)
			return false
		else
			return true
	}
}

function redimPopup(windowObj, width, height){
	var posX =(Math.round(screen.width/2))-(Math.round(width/2));
	var posY =(Math.round(screen.height/2))-(Math.round(height/2));
	windowObj.resizeTo(width, height);
	windowObj.moveTo(posX, posY);
}


//toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0
function openPopup(url, windowId, width, heigth, options){
	var posX =(Math.round(screen.width/2))-(Math.round(width/2));
	var posY =(Math.round(screen.height/2))-(Math.round(heigth/2));
	var windowObj=window.open(url, windowId, options+",width="+width+",height="+heigth+",top="+posY+",left="+posX);
	windowObj.focus();
	return windowObj
}
