function LOAD(FN){var O=window.onload;(typeof window.onload!='function')?window.onload=FN:window.onload=function(){O();FN()}}
function ID(el,obj){if(!obj)obj=document;return(typeof(el)=='string')?obj.getElementById(el):el}
function TAG(tag,obj){if(!obj)obj=document;return obj.getElementsByTagName(tag)}
function CLASS(obj,tag,cls){var E=(tag=="*"&&document.all)?document.all:TAG(tag,obj);var A=[];cls=cls.replace(/\-/g, "\\-");var R=new RegExp("(^|\\s)"+cls+"(\\s|$)");var O;for(var i=0;i<E.length;i++){O=E[i];if(R.test(O.className))A.push(O)}return(A)}
function TAGS(list,obj){var T=list.split(',');var A=[];for(var i=0;i<T.length;i++){var t=TAG(T[i],obj);for(var j=0;j<t.length;j++)A.push(t[j])}var N=A[0];if(N.sourceIndex){A.sort(function(a,b){return a.sourceIndex-b.sourceIndex})}else if(N.compareDocumentPosition){A.sort(function(a,b){return 3-(a.compareDocumentPosition(b)&6)})}return A}

// FUNZIONE che verifica se un valore è settato o meno (quindi diverso da 'undefined', null, o da lunghezza 0)
function isSet(Var){return(typeof(Var)=='undefined'||isNull(Var)||Var.length==0)?false:true}

// FUNZIONE che verifica se una vaiabile è impostata a null o meno
function isNull(v){return v===null}

// FUNZIONE che verifica se il tipo di dato è "stringa"
function isString(obj){return typeof(obj)=='string'}

// FUNZIONE che verifica se il tipo di dato è "array"
function isArray(obj){return obj&&!isString(obj)&&isSet(obj.length)}

// FUNZIONE che forza una variabile ad array (se questa non lo è già)
// N.B. se arg è un array associativo (object) questo viene trasformato in array con conseguente perdita delle chiavi
function toArr(arg){return isArray(arg)?arg:[arg]}

// FUNZIONE che spunta o meno l'insieme degli oggetti o l'oggetto form 'radio' o 'checkbox' passati come argomento
// INPUT: 1) (var ) el --> può essere:
//				A) (str) riferimento ad un'unico oggetto
//				B) (arr) riferimenti a più oggetti
//		2) (bool) TF --> se true aggiunge il segno di spunta, altrimenti toglie il segno di spunta
//
// OUTPUT: nessuno
function setChecked(el,TF){
	el=toArr(el);
	for(var i=0;i<el.length;i++){
		ID(el[i]).checked=TF
	}
}

// FUNZIONE che dato un'insieme di checkbox con lo stesso nome (tipo array PHP, es: "sel[]") consente di determinarne la selezione di gruppo
// INPUT: 1) (var) frm --> identificativo o nome del form contenente l'insieme di checkbox
//		2) (str) FldNm --> nome comune delle checkbox da selezionare
//		3) (str) dir [all|none|inverse/""] (default "") --> indica la direttiva in base alla quale selezionare le checkbox
//
// OUTPUT: nessuno
function checkAll(frm,FldNm,dir){
	var i,B=formId(frm).elements[FldNm];
	switch(dir){
		case'all':
			setChecked(B,true);
			break;
		case'none':
			setChecked(B,false);
			break;
		default:
			for(i=0;i<B.length;i++)B[i].checked=(B[i].checked)?false:true
	}
}

	
// FUNZIONE che dato un nome o id (str) di un form, ne restituisce l'identificativo
// INPUT: 1) (str) nm --> nome o id del form
//
// OUTPUT: (el) riferimento all'elemento form
function formId(nm){
	return document.forms[nm]||ID(nm)
}

function inArray(arr,src){
	for(var i=0;i<arr.length;i++){
		if(src==arr[i])return true
	} 
	return false
}
