﻿/** 	KUTILS Version 1.1, codifica UTF-8
 *  v1.0 Giovanni O'Connor, Firenze, Giungno 2002
 *  v1.0.1 Giovanni O'Connor, Firenze, Dicembre 2002
 *  v1.1 Giovanni O'Connor, Firenze, Marzo 2005
 *  v1.2 Giovanni O'Connor, Firenze, Febbraio 2007 (aggiunta localizzazione in Bulgaro)
 *  v1.3 Giovanni O'Connor, Firenze, Settembre 2007 (aggiunta localizzazione in Francese)
 *  Copyright 2002 Prometeo
 *  Copyright 2005 OS
 *  Copyright 2007 Giunti Multimedia
*/

/* *******************************************************
 *       HASH MAP
 * anche se non è realmente assolutamente necessario si consiglia di usare stringhe come chiavi!
 * HashMap.Size(); torna int
 * HashMap.GetKeys(); torna array
 * HashMap.GetValues(); torna array
 * HashMap.Remove(kStr); torna l'oggetto
 * HashMap.Get(kStr); torna l'oggetto
 * HashMap.Put(kStr,val); torna void;
 *
 ******************************************************* */
function KUHMGetKeys(){
	var dummy=new Array();
	for(var i=0;i<this.keys.length;i++){
		dummy[i]=this.keys[i];
	}
	return dummy;
}
function KUHMGetValues(){
	var dummy=new Array();
	for(var i=0;i<this.values.length;i++){
		dummy[i]=this.values[i];
	}
	return dummy;
}
function KUHMRemove(kStr){
	for(var i=0;i<this.keys.length;i++){
		if(this.keys[i]==kStr){
			this.keys.splice(i);
			return this.values.splice(i);
		}
	}
	return null;
}
function KUHMGet(kStr){
	for(var i=0;i<this.keys.length;i++){
		if(this.keys[i]==kStr) return this.values[i];
	}
	return null;
}
function KUHMPut(kStr,val){
	for(var i=0;i<this.keys.length;i++){
		if(this.keys[i]==kStr){
			this.values[i]=val;
			return;
		}
	}
	var n=this.keys.length;
	this.keys[n]=kStr;
	this.values[n]=val;
}
function KUHMSize(){
	return this.keys.length;
}
function KUHashMap(){
	// private!
	this.keys=new Array();
	this.values=new Array();
	// pubblici
	this.Size=KUHMSize;
	this.GetKeys=KUHMGetKeys;
	this.GetValues=KUHMGetValues;
	this.Remove=KUHMRemove;
	this.Get=KUHMGet;
	this.Put=KUHMPut;
}
self.kutils.HashMap=KUHashMap;
/* ************************************************************ */
			// LINGUA E FRASI LOCALIZZATE
/* ************************************************************ */
// oggetto kutils.i18n (per ora solo frasi)
function KI18nInit(){ // aggiunti italiano, inglese, tedesco, spagnolo e ungherese. Aggiunto Bulgaro.
	this.supportedLanguage=new self.kutils.HashMap();
	var it="it";
	var en="en";
	var hu="hu";
	var es="es";
	var de="de";
	var bg="bg";
	var fr="fr";
	this.AddNewLanguage(it);
	this.AddNewLanguage(en);
	this.AddNewLanguage(hu);
	this.AddNewLanguage(es);
	this.AddNewLanguage(de);
	this.AddNewLanguage(bg);
	this.AddNewLanguage(fr);
	var curPhs=null;
	var id="none";
	// aggiungo le frasi nelle varie lingue una ad una...
// error manager
	id="ErrorManager.ph1";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Errore in ");
	curPhs.Put(en,"Error in ");
	curPhs.Put(hu,"Hiba ");
	curPhs.Put(es,"Error en ");
	curPhs.Put(de,"Fehler in ");
	curPhs.Put(bg,"грешка в ");
	curPhs.Put(fr,"Erreur concernant ");
	this.AddPhrase(id,curPhs);

	id="ErrorManager.ph2";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"messaggio");
	curPhs.Put(en,"message");
	curPhs.Put(hu,"üzenet");
	curPhs.Put(es,"Mensaje");
	curPhs.Put(de,"Nachricht");
	curPhs.Put(bg,"съобщение");
	curPhs.Put(fr,"message");
	this.AddPhrase(id,curPhs);

	id="ErrorManager.ph3";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Livello di errore");
	curPhs.Put(en,"Error level");
	curPhs.Put(hu,"Hibaszint");
	curPhs.Put(es,"Nivel de error");
	curPhs.Put(de,"Fehlerebene");
	curPhs.Put(bg,"грешно ниво");
	curPhs.Put(fr,"Niveau de l'erreur");
	this.AddPhrase(id,curPhs);

// alert
	id="Alert.title";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Attenzione!");
	curPhs.Put(en,"Attention!");
	curPhs.Put(hu,"Figyelem!");
	curPhs.Put(es,"¡Atención!");
	curPhs.Put(de,"Achtung!");
	curPhs.Put(bg,"Внимание!");
	curPhs.Put(fr,"Attention!");
	this.AddPhrase(id,curPhs);

// recorder
	id="Recorder.SaveAll";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Attenzione esistono dati salvati precedentemente, continuando verranno persi. È sicuro di volerli sovrascrivere?");
	curPhs.Put(en,"CAUTION: Data have already been saved once before. If you continue, the data previously saved will be lost. Are you sure you wish to overwrite it?");
	curPhs.Put(hu,"Figyelem: Az adatok már korábban el lettek mentve. Ha most is menti az adatokat, akkor a korábbiak elvesznek. Valóban menteni kívánja?");
	curPhs.Put(es,"¡Atención! Hay datos archivados anteriormente, si continúa se perderán. ¿Está seguro de que quiere sobreescribirlos?");
	curPhs.Put(de,"ACHTUNG - es liegen bereits gespeicherte Daten vor, die verloren gehen, wenn Sie fortfahren.Sind Sie sicher, daß Sie überschreiben wollen?");
	curPhs.Put(bg,"ПРЕДУПРЕЖДЕНИЕ: Данните вече бяха запазени. Ако продължите, запазените данни ще бъдат загубени. Наистина ли искате да пишете върху тях?");
	curPhs.Put(fr,"Attention: Les données ont déjà été energistrées précédemment. Si vous continuez, les données précédemment sauvegardées, seront perdues. Souhaitez-vous les écraser?");
	this.AddPhrase(id,curPhs);

// validator
	id="Validator.errTit";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Errore");
	curPhs.Put(en,"Error");
	curPhs.Put(hu,"Hiba");
	curPhs.Put(es,"Error");
	curPhs.Put(de,"Fehler");
	curPhs.Put(bg,"Грешка");
	curPhs.Put(fr,"erreur");
	this.AddPhrase(id,curPhs);

	id="Validator.campo";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"Il campo ");
	curPhs.Put(en,"The field ");
	curPhs.Put(hu,"Mező ");
	curPhs.Put(es,"El campo ");
	curPhs.Put(de,"Das Feld ");
	curPhs.Put(bg,"В полето ");
	curPhs.Put(fr,"Le champ ");
	this.AddPhrase(id,curPhs);

	id="Validator.radio";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve essere selezionato");
	curPhs.Put(en,"must be selected");
	curPhs.Put(hu,"ki kell választani");
	curPhs.Put(es,"seleccione");
	curPhs.Put(de,"muss ausgewählt werden");
	curPhs.Put(bg,"трябва да бъде избрано");
	curPhs.Put(fr,"doit être sélectionné");
	this.AddPhrase(id,curPhs);

	id="Validator.chk1";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve riportare ");
	curPhs.Put(en,"needs ");
	curPhs.Put(hu,"tartalmaznia kell ");
	curPhs.Put(es,"prepare un informe ");
	curPhs.Put(de,"muss enthalten ");
	curPhs.Put(bg,"трябва да съдържа ");
	curPhs.Put(fr,"doit contenir ");
	this.AddPhrase(id,curPhs);

	id="Validator.chk2";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it," opzioni");
	curPhs.Put(en," options");
	curPhs.Put(hu," opciók");
	curPhs.Put(es," opciones");
	curPhs.Put(de," Optionen");
	curPhs.Put(bg," опции");
	curPhs.Put(fr," options");
	this.AddPhrase(id,curPhs);

	id="Validator.txt";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve essere riempito");
	curPhs.Put(en,"must be filled in");
	curPhs.Put(hu,"ki kell tölteni");
	curPhs.Put(es,"rellene");
	curPhs.Put(de,"muss ausgefüllt werden");
	curPhs.Put(bg,"трябва да бъде попълнено");
	curPhs.Put(fr,"doit être rempli");
	this.AddPhrase(id,curPhs);

// validator, formato
	id="Validator.format.n1";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve contenere almeno ");
	curPhs.Put(en,"must contain at least ");
	curPhs.Put(hu,"tartalmaznia kell legalább ");
	curPhs.Put(es,"contenido mínimo ");
	curPhs.Put(de,"muss mindestens enthalten ");
	curPhs.Put(bg,"трябва да съдържа поне ");
	curPhs.Put(fr,"doit contenir au moins ");
	this.AddPhrase(id,curPhs);

	id="Validator.format.n2";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it," caratteri");
	curPhs.Put(en," characters");
	curPhs.Put(hu," karakter");
	curPhs.Put(es," caracteres");
	curPhs.Put(de," Buchstaben");
	curPhs.Put(bg," букви");
	curPhs.Put(fr," caractères");
	this.AddPhrase(id,curPhs);

	id="Validator.format.soloN";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve contenere solo numeri");
	curPhs.Put(en,"must contain figures only");
	curPhs.Put(hu,"csak számokat tartalmazhat");
	curPhs.Put(es,"debe contener solo cifras");
	curPhs.Put(de,"darf nur Zahlen enthalten");
	curPhs.Put(bg,"трябва да съдържа само цифри");
	curPhs.Put(fr,"doit être numérique");
	this.AddPhrase(id,curPhs);

	id="Validator.format.nMaggiore";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve essere un numero non inferiore a ");
	curPhs.Put(en,"must be a number not below ");
	curPhs.Put(hu,"nem lehet alacsonyabb szám, mint ");
	curPhs.Put(es,"debe ser un número no inferior a ");
	curPhs.Put(de,"muss eine Zahl sein, die nicht kleiner ist als ");
	curPhs.Put(bg,"цифрата не трябва да е по-малка от ");
	curPhs.Put(fr,"doit être un nombre supérieur ou égal à ");
	this.AddPhrase(id,curPhs);

	id="Validator.format.nMinore";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"deve essere un numero non superiore a ");
	curPhs.Put(en,"amust be a number not above ");
	curPhs.Put(hu,"nem lehet magasabb szám, mint ");
	curPhs.Put(es,"debe ser un número no superior a ");
	curPhs.Put(de,"muss eine Zahl sein, die nicht höher ist als ");
	curPhs.Put(bg,"цифрата не трябва да е повече от ");
	curPhs.Put(fr,"doit être un nombre inférieur ou égal à ");
	this.AddPhrase(id,curPhs);

	id="Validator.format.forbiddenChar";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non deve contenere i caratteri: ");
	curPhs.Put(en,"must not contain the characters: ");
	curPhs.Put(hu,"nem tartalmazhat betűt: ");
	curPhs.Put(es,"no debe contener las letras: ");
	curPhs.Put(de,"darf keine Buchstaben enthalten: ");
	curPhs.Put(bg,"не трябва да съдържа букви ");
	curPhs.Put(fr,"ne doit pas contenir les caractères: ");
	this.AddPhrase(id,curPhs);

	id="Validator.format.notValidChar";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"contiene caratteri non validi");
	curPhs.Put(en,"contains invalid characters");
	curPhs.Put(hu,"érvénytelen betűket tartalmaz");
	curPhs.Put(es,"contiene letras no válidas");
	curPhs.Put(de,"enthält ungültige Buchstaben");
	curPhs.Put(bg,"съдържа невалидни букви");
	curPhs.Put(fr,"contient des caractères invalides");
	this.AddPhrase(id,curPhs);

	id="Validator.format.email";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non contiene un'indirizzo e-mail valido");
	curPhs.Put(en,"does not contain a valid email address");
	curPhs.Put(hu,"érvénytelen e-mail cím");
	curPhs.Put(es,"no contiene una dirección de e-mail válida");
	curPhs.Put(de,"enthält keine gültige E-mail-Adresse");
	curPhs.Put(bg,"невалиден е-mail");
	curPhs.Put(fr,"contient une adresse email invalide");
	this.AddPhrase(id,curPhs);

	id="Validator.format.formatoData";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non contiene un formato data valido");
	curPhs.Put(en,"does not contain a valid date format");
	curPhs.Put(hu,"érvénytelen adatformátum");
	curPhs.Put(es,"no contiene un formato de fecha válido");
	curPhs.Put(de,"enthält kein gültiges Datenformat");
	curPhs.Put(bg,"невалиден формат на датата");
	curPhs.Put(fr,"contient un format date invalide");
	this.AddPhrase(id,curPhs);

	id="Validator.format.dataCambiata";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non rispettava il formato specificato ed &egrave stato cambiato, verificare la data e ripetere l'invio");
	curPhs.Put(en,"did not respect the specified format and has been modified: please check the date and send again");
	curPhs.Put(hu,"nem a megadott formátumban készült, módosítva lett: kérem ellenőrizze a dátumot és küldje el újra");
	curPhs.Put(es,"no respeta el formato especificado y ha sido cambiado; verificar los datos y repetir el envío");
	curPhs.Put(de,"entspricht nicht dem erforderlichen Format und wurde verändert, bitte überprüfen Sie das Datum und wiederholen Sie die Eingabe");
	curPhs.Put(bg,"не се отнася до специфичния формат и е променен. Проверете датата и изпратете пак");
	curPhs.Put(fr,"ne respecte pas le format spécifié: veuillez vérifier la date et envoyer à nouveau");
	this.AddPhrase(id,curPhs);

	id="Validator.format.dataInventata";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non contiene una data valida");
	curPhs.Put(en,"does not contain a valid date");
	curPhs.Put(hu,"érvénytelen dátum");
	curPhs.Put(es,"no contiene una fecha válida");
	curPhs.Put(de,"enthält kein gültiges Datum");
	curPhs.Put(bg,"съдържа невалидна дата");
	curPhs.Put(fr,"ne contient pas une date correcte");
	this.AddPhrase(id,curPhs);

	id="Validator.format.CF";
	curPhs=new self.kutils.HashMap();
	curPhs.Put(it,"non contiene una codice fiscale valido");
	curPhs.Put(en,"does not contain a valid italian tax code");
	curPhs.Put(hu,"érvénytelen adókód");
	curPhs.Put(es,"no contiene un código fiscal válido");
	curPhs.Put(de,"enthält keine gültige Steuernummer");
	curPhs.Put(bg,"невалиден БУЛСТАТ");
	curPhs.Put(fr,"ne contient pas un code taxe valide");
	this.AddPhrase(id,curPhs);
}
function KI18nAddNewLanguage(l){
	if( this.SupportLanguage(l) && top.debug ) alert("Attenzione, si sta cercando di aggiungere una lingua già presente!");
	else{
		var frasi = new self.kutils.HashMap();
		this.supportedLanguage.Put(l,frasi);
	}
}
function KI18nAddPhrase(id,phrases){ // phrases deve essere una hash map con chiave la lingua e valore la frase
	if(top.debug&&(this.supportedLanguage.Size()!=phrases.Size())) alert("Il numero delle lingue e quello delle frasi localizzate non torna. Id="+id);
	var lang=phrases.GetKeys();
	var lMap=null;
	for(var i=0;i<lang.length;i++){
		lMap=this.supportedLanguage.Get(lang[i]);
		if( (lMap==null) && top.debug ) alert("Attenzione frase in una lingua non prevista");
		else{
			lMap.Put(id,phrases.Get(lang[i]));
			this.supportedLanguage.Put(lang[i],lMap);
		}
	}
}
function KI18nGetPhrase(phId){
	if(this.curPh==null) this.curPh=this.supportedLanguage.Get(this.curLang);
	return ((this.curPh.Get(phId)==null)?"":this.curPh.Get(phId));
}
function KI18nSetCurrentLanguage(l){
	if(!this.SupportLanguage(l)){
		if(top.debug) alert("i18n.SetCurrentLanguage fallito, lingua "+l+" sconosciuta!");
		return false;
	}
	else{
		this.curLang=l;
		this.curPh=this.supportedLanguage.Get(l);
		return true;
	}
}
function KI18nGetCurrentLanguage(){
	return this.curLang;
}
function KI18nSupportLanguage(l){
 return( this.supportedLanguage.Get(l)!=null );
}
function KI18nSupportLanguages(){
	var langs=KI18nSupportLanguages.arguments;
	for(var i=0;i<langs.length;i++){
		if(!this.SupportLanguage(langs[i])) return false;
	}
	return true;
}
function KI18n(){
	this.defLang=self.kutils.defaultLanguage;
	this.curLang=this.defLang;
	this.curPh=null;
	this.supportedLanguage=null //new self.kutils.HashMap();
	// private
	this.AddNewLanguage=KI18nAddNewLanguage;
	this.AddPhrase=KI18nAddPhrase;
	// public
	this.Init=KI18nInit;
	this.GetPhrase=KI18nGetPhrase;
	this.GetCurrentLanguage=KI18nGetCurrentLanguage;
	this.SetCurrentLanguage=KI18nSetCurrentLanguage;
	this.SupportLanguages=KI18nSupportLanguages;
	this.SupportLanguage=KI18nSupportLanguage;
}
self.kutils.i18n=new KI18n();
// attenzione, per aggiungere le frasi deve essere inizializzato!
/* ************************************************************ */
			// BROWSER CHECK - part 2
/* ************************************************************ */
// check di comodo
self.kutils.IE4=false;
self.kutils.NS4=false;
self.kutils.NS6=false;
if(self.kutils.VERS>3){
	if(self.kutils.VERS<5){
		if(self.kutils.IE) self.kutils.IE4=true;
		else if(self.kutils.NS) self.kutils.NS4=true;
        } else{
          if(self.kutils.NS) self.kutils.NS6=true;
          self.kutils.COMPL=true;
	}
}
if(!self.kutils.NS&&!self.kutils.IE) self.kutils.COMPL=true; // e sperare
/* ******************************************* */
	// DISABILITA TASTO DESTRO DEL MOUSE (Per explorer funziona solo da 5+)
/* ******************************************* */
function RCDisabled(e){
	if( self.kutils.IE ) return false;
	else if( self.kutils.NS6 || self.kutils.COMPL ){
		if(e.button>1){ e.preventDefault(); e.stopPropagation(); }
	}
	else if( self.kutils.NS4 ){
		if(e.which>1) return false;
		else return true;
	}
}
function DisableRightClick(wObj){
	try{
		if(top.debug) return;
	} catch(er){
		// do nothing
	}
	if( self.kutils.IE ){ wObj.RCDisabled=RCDisabled; wObj.document.oncontextmenu=wObj.RCDisabled; }
	else if( self.kutils.NS4 ){ wObj.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP); wObj.onclick=RCDisabled; wObj.onmousedown=RCDisabled; wObj.onmouseup=RCDisabled; wObj.ondblclick=RCDisabled; } // da testare
	else if( self.kutils.NS6 || self.kutils.COMPL ){ wObj.addEventListener("mousedown",RCDisabled,true); wObj.addEventListener("mouseup",RCDisabled,true); wObj.addEventListener("click",RCDisabled,true); wObj.addEventListener("dblclick",RCDisabled,true); }
}
self.kutils.DisableRightClick=DisableRightClick;
/* ******************************************* */
	// RETRIVA POSIZIONE DI OGGETTO
/* ******************************************* */
function GetPosX(Obj){
	var a=Obj;
	var pos=0;
	if(self.kutils.NS4){ // funziona solo con tag (e layer?), nei layer rende la posizione rispetto al layer
		pos=a.x;
	} else {
		genitore=a;
		while(genitore){
			pos+=genitore.offsetLeft;
			if( (genitore.tagName=="BODY")||(genitore.tagName=="HTML")||(genitore==genitore.offsetParent) ) genitore=null;
			else genitore=genitore.offsetParent;
		}
	}
	return(pos);
}
function GetPosY(Obj){
	var a=Obj;
	var pos=0;
	if(self.kutils.NS4){ // funziona solo con tag (e layer?), nei layer rende la posizione rispetto al layer
		pos=a.y;
	} else {
		genitore=a;
		while(genitore){
			pos+=genitore.offsetTop;
			if( (genitore.tagName=="BODY")||(genitore.tagName=="HTML")||(genitore==genitore.offsetParent) ) genitore=null;
			else genitore=genitore.offsetParent;
		}
	}
	return(pos);
}
self.kutils.GetPosX=GetPosX;
self.kutils.GetPosY=GetPosY;
/* ******************************************* 
	*      GESTORE COOKIES
	*  richiede l'accesso a "top", e i cookie devono avere la medesima url di riferimento di questo file
  ******************************************* */
function KUSetCookie(n,v,d){
	var cS=n+"="+v;
	if(d){ // d = numero di giorni
		d=parseInt(d,10); td=new Date(); ldm=td.getTime()+d*86400000;
		ld=new Date(ldm);
		cS=cS+"; expires="+ld.toGMTString();
	}
	top.document.cookie=cS;
}
function KUGetCookie(name){
	ck=top.document.cookie;
	ckstart=ck.indexOf( name + "=" );
	if( (ckstart < 0) && (window.opener!=null)&&(typeof(window.opener)!="undefined")){
		try{
			ck=window.opener.top.document.cookie;
			ckstart=ck.indexOf( name + "=" );
		} catch(e){ ckstart=-1; }
	}
	if( ckstart < 0 )	return("");
	ckend=ck.indexOf( ";", ckstart );
	if( ckend<0 ) ckend=ck.length;
	if( ckstart+name.length+1>=ckend ) return("");
	return( ck.substring( ckstart+name.length+1, ckend ) );
}
self.kutils.SetCookie=KUSetCookie;
self.kutils.GetCookie=KUGetCookie;
/* ******************************************************* */
/*   			  					DATI SU COOKIE				 		 			     */
/* ******************************************************* */
function KUDCSet(n,v){
	if( !v ){ this.Drop(n); return; }
	var val=escape(v);
	var cStr=self.kutils.GetCookie(this.id);
	cStr=unescape(cStr);
	var cStrAr=cStr.split(this.pv);
	var cNV=new Array(false,false);
	var toMatch=n+this.eq;
	for(var i=0;i<cStrAr.length;i++){
		cNV=cStrAr[i].split(this.eq);
		if( (cNV.length!=2) || (cNV[1]=="") ){
			cNV[0]=false;	cStrAr[i]="";	continue;
		}
		if(cStrAr[i].indexOf(toMatch)>-1){
			if(cNV[0]!=n){
				cNV[0]=false; continue;
			}
			cStrAr[i]=n+this.eq+val;
			break;
		}
		cNV[0]=false;
	}
	if(!cNV[0]) cStrAr[cStrAr.length]=n+this.eq+val;
	cStr=cStrAr[0];
	for(j=1;j<cStrAr.length;j++) if(cStrAr[j]!="") cStr+=(this.pv+cStrAr[j]);
	escape(cStr);
	self.kutils.SetCookie(this.id,cStr,this.daysOfPerm);
}
function KUDCGet(name){
	var cStr=self.kutils.GetCookie(this.id);
	cStr=unescape(cStr);
	var cStrAr=cStr.split(this.pv);
	var toMatch=name+this.eq;
	var cNV=new Array("","");
	for(var i=0;i<cStrAr.length;i++){
		if(cStrAr[i].indexOf(toMatch)>-1){
			cNV=cStrAr[i].split(this.eq);
			if(cNV.length>2||cNV[0]!=name){
				cNV[0]="";	cNV[1]=""; continue; // cambiata, prima metteva false ai due cNV. Da notare che questo poteva voler dire un ritorno a false invece che "".
			}
			break;
		}
	}
	return(cNV[1]);
}
function KUDCDrop(name){
	var cStr=self.kutils.GetCookie(this.id);
	cStr=unescape(cStr);
	var cStrAr=cStr.split(this.pv);
	cStr="";
	var toMatch=name+this.eq;
	var cNV=new Array("","");
	for(var i=0;i<cStrAr.length;i++){
		if(cStrAr[i].indexOf(toMatch)>-1){
			cNV=cStrAr[i].split(this.eq);
			if(cNV.length>2||cNV[0]!=name){
				cNV[0]="";	cNV[1]="";	continue;
			}
			else cStrAr[i]="";
		}
		if(cStrAr[i]!="") cStr+=(this.pv+cStrAr[i]);
	}
	escape(cStr);
	self.kutils.SetCookie(this.id,cStr,this.daysOfPerm);
}
function KUDCReset(){
	self.kutils.SetCookie(this.id,"",0);
}
function KUDCGetAll(){
 return self.kutils.GetCookie(this.id);
}
function KUDCOverrideAll(dataString){
	self.kutils.SetCookie(this.id,dataString,this.daysOfPerm);
}
function KUDataCookie(cN,cS,cE){ // introdotta la permanenza dei cookies
	this.id=(!cN||(cN==""))?"_KUDC-":cN;
	this.pv=(!cS||(cS==""))?"_PV-":cS;
	this.eq=(!cE||(cE==""))?"_EQ-":cE;
	this.daysOfPerm=0;
	this.Set=KUDCSet;
	this.Get=KUDCGet;
	this.Drop=KUDCDrop;
	this.Reset=KUDCReset;
	this.GetAll=KUDCGetAll;
	this.OverrideAll=KUDCOverrideAll;
}
self.kutils.DataCookie=KUDataCookie;
/* ******************************************************* */
/*       KRONO 		 */
/* ******************************************************* */
function KUKGSeconds(){
	var sec=Math.round((this.stopTime-this.startTime)/1000)+this.passedSeconds;
	return(Math.max(sec,0));
}
function KUKStart(){
	if(this.stopped){ this.startTime =(new Date()).getTime(); this.stopped=false; }
}
function KUKStop(){
	if(!this.stopped){ this.stopTime =(new Date()).getTime(); this.stopped=true; this.passedSeconds=this.GetSeconds(); }
	return(this.passedSeconds);
}
function KUKReset(val){
	var sec;
	if(!this.stopped) sec=this.Stop();
	else sec=this.GetSeconds();
	this.startTime=null;
	this.stopTime=null;
	this.stopped=true;
	this.passedSeconds=val?val:0;
	return(sec);
}
function KUKRead(){
	var sec;
	if(this.stopped) sec=this.passedSeconds;
	else{
		readTime=(new Date()).getTime();
		sec=Math.round((readTime-this.startTime)/1000)+this.passedSeconds;
	}
	return(Math.max(sec,0));
}
function KUKrono(){
	this._className="KUKrono";
	this.startTime=0;
	this.stopTime=0;
	this.passedSeconds=0;
	this.stopped=true;
	this.Start=KUKStart;
	this.Stop=KUKStop;
	this.Reset=KUKReset;
	this.Read=KUKRead;
	this.GetSeconds=KUKGSeconds;
}
self.kutils.Krono=KUKrono;
/* ******************************************************* */
/*       MAPPE CARATTERI (default 64 caratteri 6 bit) 		 */
/* ******************************************************* */
function KUCMGetChar(n){
	return(this.charsStr.charAt(n));
}
function KUCMGetValue(c){
	return(this.charsStr.indexOf(c));
}
function KUCharMap(chars){
	if(chars!="") this.charsStr=chars;
	else this.charsStr="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM@&"; // 64 webSafe
	this.length=this.charsStr.length;
	this.GetChar=KUCMGetChar;
	this.GetValue=KUCMGetValue;
}
self.kutils.CharsMap=KUCharMap;
/* **************************************************** */
/*          				  		Compressor				   					*/
/* **************************************************** */
function KUGetBitValue(num,ind){
	var cUN=num;
	var u=(1<<ind);
	var v=(u&cUN)?1:0;
	return(v);
}
function KUSetBitValue(num,ind,v){
	var cUN=num;
	var u=(1<<ind); var nu=~u;
	if(v) cUN=(cUN|u);
	else cUN=(cUN&nu);
	return(cUN);
}
function KUCGetBitAt(str,pos){
	var cIdx=Math.floor(pos/this.byteLength); var ind=(pos%this.byteLength);
	var num=this.charsMap.GetValue(str.charAt(cIdx));
	return(KUGetBitValue(num,ind));
}
function KUCSetBitAt(str,pos,val){
	var cIdx=Math.floor(pos/this.byteLength); var ind=pos%this.byteLength;
	var num=this.charsMap.GetValue(str.charAt(cIdx));
	var nNum=KUSetBitValue(num,ind,val);
	if(num==nNum) return(str);
	var nC=this.charsMap.GetChar(nNum);
	str=(str.slice(0,cIdx)+nC+str.slice(cIdx+1,str.length));
	return(str);
}
function KUCGetNullString(bitsNum){
	var nC=Math.ceil(bitsNum/this.byteLength); var c=this.charsMap.GetValue(0);
	var str=""
	while(i<(nC+1)){ i++;	str+=c;	}
	return(str)
}
function KUCompressor(cmObj){
	this.charsMap=cmObj;
	this.byteLength=parseInt((Math.log(this.charsMap.length)/Math.LN2),10);
	this.GetNullString=KUCGetNullString;
	this.GetBitAt=KUCGetBitAt;
	this.SetBitAt=KUCSetBitAt;
}
self.kutils.CompressData=KUCompressor;
/* ****************************************************** */
			// CHARSBINARYTRANSLATOR 1 e 2
/* ****************************************************** */
// 1 trasla l'array di bit in nel numero decimale
function KUCBGBin(ch){
	n=this.charsMap.GetValue(ch);
	ind=this.bitDimension; bArray=new Array(ind);
	while(ind>0){	bArray[--ind]=( (n%2)>0 )?true:false; n=Math.floor(n/2);	}
	return bArray;
}
function KUCBGChar(bArray){
	bStr="";
	for(var i=0;i<this.bitDimension;i++) bStr+=bArray[i]?"1":"0";
	return this.charsMap.GetChar(parseInt(bStr,2));
}
function KUCBTranslator(mObj){
	this._className="KUCBTranslator";
	this.charsMap=mObj;
	this.bitDimension=parseInt((Math.log(this.charsMap.length)/Math.LN2),10);
	this.GetBinary=KUCBGBin;
	this.GetChar=KUCBGChar;
}
self.kutils.CharBinaryTranslator=KUCBTranslator;
// 2 rende il numero della posizione del primo true dell'array di boolean e rende array di boolean con un solo valore a true.
function KUCPGBin(ch){
	n=this.charsMap.GetValue(ch)-1;
	bArray=new Array();
	for(var i=0;i<this.bitDimension;i++){
		bArray[i]=(n==i);
	}
	return bArray;
}
function KUCPGChar(bArray){
	if(bArray.length>this.bitDimension){
		if(top.debug) alert("kutils.CharPositionTranslator.GetChar(byteArray): la lunghezza dell'array eccede il massimo!");
		return "?";
	}
	var pos=0;
	for(var i=0;i<bArray.length;i++) if(bArray[i]) return this.charsMap.GetChar(i+1);
	return this.charsMap.GetChar(0); // il primo carattere (nel charMap di default "0") diventa il jolly per dire "tutto false"
}
function KUCPTranslator(mObj){
	this._className="KUCPTranslator";
	this.charsMap=mObj;
	// N.B. Shifta di uno per trattare il primo carattere come un carattere jolly da usare quando sono tutti false! Insomma proprio brutto ma non saprei come fare altrimenti!
	this.bitDimension=this.charsMap.length-1;
	this.GetBinary=KUCPGBin;
	this.GetChar=KUCPGChar;
}
self.kutils.CharPositionTranslator=KUCPTranslator;
/* ****************************************************** */
			// FINDER
/* ****************************************************** */
function FGetAnchorByName(wObj,aName){
	var a=0;
	if(!wObj || wObj=="undefined"){
		if(top.debug) alert("errore in kutils.finder.GetAnchorByName( "+wObj+" , "+aName+" ): wObj non esiste!");
		return(0);
	}
	if(self.kutils.IE) a=wObj.document.all(aName);
	else if(self.kutils.NS4) a=wObj.document.anchors[aName];
	else{
		var dummy=wObj.document.getElementsByTagName("a");
		for(var i=0;i<dummy.length;i++){
			if(dummy[i].name==aName){
				a=dummy[i];
				break;
			}
			a=0;
		}
	}
	if(!a){ if(top.debug) alert("finder.GetAnchorByName: oggetto non trovato!");	return null; }
	return(a);
}
function FGetImageByName(wObj,iName){
	var i=0;
	if(self.kutils.IE) i=wObj.document.all(iName);
	else if(self.kutils.NS4){
		i=wObj.document.images[iName];
		for(j=0;(!i && j>wObj.document.layers.length);j++) i=wObj.document.layers[j].document.images[iName];
	}
	else{
		var dummy=wObj.document.getElementsByTagName("img");
		for(j=0;j<dummy.length;j++){
			if(dummy[j].name==iName){	i=dummy[j];	break; }
		}
	}
	if(!i){	if(top.debug) alert("finder.GetAnchorByName: oggetto non trovato!"); return null; }
	return(i);
}
function FGetLayerById(wObj,dId){
	var a=0;
	if(self.kutils.IE) a=wObj.document.all(dId);
	else if(self.kutils.NS4) a=wObj.document.layers[dId];
	else a=wObj.document.getElementById(dId);
	if(!a){
		if(top.debug) alert("finder.GetLayerById: oggetto non trovato!");
		return(0);
	}
	return(a);
}
// privata per quella dopo!
function FFindJSObj(wObj,cStr,cStr2){
	var w=wObj;
	if( eval(cStr) && eval(cStr2) ) return eval(cStr);
	else return null;
}
function FGetJSObj(wObj,opnr,oId,cId){
	var o=null;
	var cStr="w."+oId;
	var cStr2=(cId=="")?"true":("w."+oId+"._className=="+cId);
	var t=0,tMax=10; w=wObj;
	while( (FFindJSObj(w,cStr,cStr2)==null) && (w.parent!=null) && (w.parent!=w) && (t<tMax) ){t++; w=w.parent}
	o=FFindJSObj(w,cStr,cStr2);
	if( (o==null) && opnr && (w.opener!=null) && (typeof(w.opener)!="undefined") ) o=FGetJSObj(w.opener,opnr,oId,cId);
	return o;
}
function FindObject(){
	this.GetAnchorByName=FGetAnchorByName;
	this.GetImageByName=FGetImageByName;
	this.GetLayerById=FGetLayerById;
	this.GetJSObject=FGetJSObj;
}
self.kutils.finder = new FindObject();
/* ****************************************************** */
			// WIN Manager
/* ****************************************************** */
function WMGetWidth(wObj){
	var val=parseInt(this.GetInfo(wObj,"width"),10);
	return(val);
}
function WMGetHeight(wObj){
	var val=parseInt(this.GetInfo(wObj,"height"),10);
	return(val);
}
function WMGetScrollX(wObj){
	var val=parseInt(this.GetInfo(wObj,"scrollX"),10);
	return(val);
}
function WMGetScrollY(wObj){
	var val=parseInt(this.GetInfo(wObj,"scrollY"),10);
	return(val);
}
function WMScrollX(wObj,val){
	this.Scroll(wObj,val,-1);
}
function WMScrollY(wObj,val){
	this.Scroll(wObj,-1,val);
}
// private
function WMGetInfo(wObj,info){
	if( wObj=="undefined" || !wObj ){
		if(top.debug) alert("errore in kutils.win.GetInfo( "+wObj+" , "+info+" ): wObj.document non esiste!");
		return(0);
	}
	switch(info){
		case "scrollX":
			var posX = (self.kutils.NS ? wObj.pageXOffset : wObj.document.body.scrollLeft);
			return(posX);
		case "scrollY":
			var posY = (self.kutils.NS ? wObj.pageYOffset : wObj.document.body.scrollTop);
			return(posY);
		case "width":
			var larghezza = (self.kutils.NS ? wObj.innerWidth : wObj.document.body.clientWidth);
			return(larghezza);
		case "height":
			var altezza = (self.kutils.NS ? wObj.innerHeight : wObj.document.body.clientHeight);
			return(altezza);
		default:
			if(top.debug) window.alert("errore in kutils.win.GetInfo( "+wObj+" , "+info+" ): info non prevista");
			return(0);
	}
}
function WMScroll(wObj,Xpos,Ypos){
	if(Xpos>0) Xpos=this.GetScrollX(wObj);
	if(Ypos<0) Ypos=this.GetScrollY(wObj);
	wObj.scrollTo(Xpos,Ypos);
}
function WMOpenWin(url,name,features){
	var winName=name;
	var winUrl=url;
	var winFeatures=features;
	eval("this."+winName+" = window.open('',winName,winFeatures);");
	eval("this."+winName+".location.href = winUrl;");
	eval("window.setTimeout('self.kutils.win."+winName+".focus();',500);");
}
function WMGetHrefPart(wObj,which){
	var hrefStr=wObj.document.location.href;
	if( (!hrefStr) || (!which) ) return "";
	var searchStr="";
	var anchorStr="";
	if(hrefStr.indexOf("?")>-1){
		var searchIndex=hrefStr.lastIndexOf( "?" );
		searchStr=hrefStr.substring(searchIndex+1, hrefStr.length);
		hrefStr=hrefStr.substring(0, searchIndex);
	}
	if(hrefStr.indexOf("#")>-1){
		var anchorIndex=hrefStr.lastIndexOf( "#" );
		anchorStr=hrefStr.substring(anchorIndex+1, hrefStr.length);
		hrefStr=hrefStr.substring(0, anchorIndex);
	}
	eval("hStr="+which+"Str");
	return( hStr )
}
function WMGetRootUrl(wObj,idStr){
	var str=this.GetHrefPart(wObj,"href");
	var rIn=str.indexOf(idStr);
	if(rIn<0) return 0;
	rIn+=idStr.length;
	str=str.substring(0,rIn);
	return(str);
}
function WinManager(){
	this.GetWidth=WMGetWidth;
	this.GetHeight=WMGetHeight;
	this.GetScrollX=WMGetScrollX;
	this.GetScrollY=WMGetScrollY;
	this.ScrollX=WMScrollX;
	this.ScrollY=WMScrollY;
	this.OpenNew=WMOpenWin;
	this.GetHrefPart=WMGetHrefPart;
	this.GetRootUrl=WMGetRootUrl;
	// private
	this.GetInfo=WMGetInfo;
	this.Scroll=WMScroll;
}
self.kutils.win = new WinManager();
/* *********************************************************** */
					// BOX
/* *********************************************************** */
function BoxSetPos(which,howMuch){
	var dX=0;
	var dY=0;
	var val=0;
	switch( which ){
		case "left":
			val=howMuch;
			if(self.kutils.COMPL) val+="px";
			this.lRef.left=val;
			break;
		case "sx":
			var wSX=self.kutils.win.GetScrollX(this.win);
			val=howMuch+wSX;
			if(self.kutils.COMPL) val+="px";
			this.lRef.left=val;
			break;
		case "right":
			var wW=self.kutils.win.GetWidth(this.win);
			var wSX=self.kutils.win.GetScrollX(this.win);
			var wSY=self.kutils.win.GetScrollY(this.win);
			if(self.kutils.NS&&(wSY!=0)) wSX-=15;
			var bW=this.GetWidth();
			val=wW+wSX-bW-parseInt(howMuch,10);
			if(self.kutils.COMPL) val+="px";
			this.lRef.left=val;
			break;
		case "top":
			val=howMuch;
			if(self.kutils.COMPL) val+="px";
			this.lRef.top=val;
			break;
		case "up":
			var wSY=self.kutils.win.GetScrollY(this.win);
			val=howMuch+wSY;
			if(self.kutils.COMPL) val+="px";
			this.lRef.top=val;
			break;
		case "bottom":
			var wH=self.kutils.win.GetHeight(this.win);
			var wSY=self.kutils.win.GetScrollY(this.win);
			var wSX=self.kutils.win.GetScrollX(this.win);
			if(self.kutils.NS&&(wSX!=0)) wSY-=15;
			var bH=this.GetHeight();
			val=wH+wSY-bH-parseInt(howMuch,10);
			if(self.kutils.COMPL) val+="px";
			this.lRef.top=val;
			break;
		default:
			if(top.debug) alert("BoxSetPos, parametro non corretto");
			break;
	}
}
function BoxSetDim(which,howMuch){
	switch( which ){
		case "height":
			if(self.kutils.NS4) this.l.clip.height=howMuch;
			this.lRef.height=howMuch;
			break;
		case "width":
			if(self.kutils.NS4) this.l.clip.width=howMuch;
			this.lRef.width=howMuch;
			break;
		default:
			if(top.debug) alert("BoxSetDim, parametro non corretto");
			break;
	}
}
function BoxSetBGColor(color){
	if(self.kutils.NS4)	this.lRef.bgColor=color;
	else this.lRef.background=color;
}
function BoxHide(){
	if(self.kutils.NS4) this.lRef.visibility="hide";
	else this.lRef.visibility="hidden";
}
function BoxShow(){
	if(self.kutils.NS4) this.lRef.visibility="show";
	else this.lRef.visibility="visible";
}
function BoxReset(pos,dim,vis,col){
	if(pos=="all"){
		pos=true;
		dim=true;
		vis=true;
		col=true;
	}
	if(pos){
		this.SetPos("left",this.posX);
		this.SetPos("top",this.posY);
	}
	if(dim){
		this.SetDim("width",this.width);
		this.SetDim("height",this.height);
	}
	if(col) this.SetBGColor(this.BGColor);
	if(vis){
		if(this.visibility) this.Show();
		else this.Hide();
	}
}
// GET INFO
	// private
function BoxGetPosX(){
	return(parseInt(this.lRef.left,10));
}
function BoxGetPosY(){
	return(parseInt(this.lRef.top,10));
}
function BoxGetHeight(){
	if(self.kutils.NS4) return(parseInt(this.l.clip.height));
	else return(parseInt(this.l.offsetHeight));
}
function BoxGetWidth(){
	if(self.kutils.NS4) return(parseInt(this.l.clip.width));
	else return(parseInt(this.l.offsetWidth));
}
	// public
function BoxGetPos(which){
	var val=0;
	switch( which ){
		case "left":
			val=this.GetPosX();
			break;
		case "right":
			var sx=this.GetPosX()+this.GetWidth();
			val=self.kutils.win.GetWidth(this.win)-sx;
			break;
		case "top":
			val=this.GetPosY();
			break;
		case "bottom":
			var su=this.GetPosY()+this.GetHeight();
			val=self.kutils.win.GetHeight(this.win)-su;
			break;
		default:
			if(top.debug) alert("BoxGetPos, parametro non corretto");
			break;
	}
	if(isNaN(val)) val=0;
	return(val);
}
function BoxGetDim(which){
	var val=0;
	switch( which ){
		case "height":
			val=this.GetHeight();
			break;
		case "width":
			val=this.GetWidth();
			break;
		default:
			if(top.debug) alert("BoxGetDim, parametro non corretto");
			break;
	}
	if(isNaN(val)) val=0;
	return(val);
}
function BoxGetBGColor(){
		if(self.kutils.NS4)	return(this.lRef.bgColor);
		else return(this.lRef.background);
}
function BoxIsVisible(){
	vis=true;
	if( this.lRef.visibility=="hidden" || this.lRef.visibility=="hide") vis=false;
	return(vis);
}
function BoxSwitchVisibility(){
	if(this.IsVisible()) this.Hide();
	else this.Show();
}
// BOX Object
function Box_cnstr(obj,wObj,lObj){ // AGGIUNTO lo Switch della visibilit� per il testing
// arg error
	if(!lObj){
		if(top.debug) alert("Oggetto BOX non creato: layer non trovato");
		return;
	}
	if(!wObj){
		if(top.debug) alert("Oggetto BOX non creato: finestra non trovata");
		return;
	}
// properties
	obj.l=lObj;
	obj.win=wObj;
	obj.lRef = self.kutils.NS4 ? obj.l : obj.l.style;
	// initial state
	obj.posX=0;
	obj.posY=0;
	obj.height=0;
	obj.width=0;
	obj.BGColor="";
	obj.visibility=false;
// methods
	obj.SetPos = BoxSetPos;
	obj.GetPos = BoxGetPos;
	obj.SetDim = BoxSetDim;
	obj.GetDim = BoxGetDim;
	obj.IsVisible = BoxIsVisible;
	obj.Hide = BoxHide;
	obj.Show = BoxShow;
	obj.SwitchVisibility=BoxSwitchVisibility;
	obj.GetBGColor = BoxGetBGColor;
	obj.SetBGColor = BoxSetBGColor;
	obj.Reset = BoxReset;
	// private
	obj.GetWidth=BoxGetWidth;
	obj.GetHeight=BoxGetHeight;
	obj.GetPosX=BoxGetPosX;
	obj.GetPosY=BoxGetPosY;
	// initialize
	obj.posX = obj.GetPosX();
	obj.posY = obj.GetPosY();
	obj.height = obj.GetHeight();
	obj.width = obj.GetWidth();
	obj.BGColor = obj.GetBGColor();
	obj.visibility = obj.IsVisible();
}

function Box(wObj,lObj){
	Box_cnstr(this,wObj,lObj);
}
/* *********************************************************** */
					// TEXTBOX
/* *********************************************************** */
function TBWriteHTML(htmlStr){
	if( self.kutils.NS4 ) {
		this.l.document.open();
		this.l.document.write(htmlStr);
		this.l.document.close();
	}
	else this.l.innerHTML=htmlStr;
}
function TBReset(pos,dim,vis,col,txt){
	this.SuperReset(pos,dim,vis,col);
	if(txt || (pos=="all")) this.WriteHTML("");
}
function TextBox(wObj,lObj){
	Box_cnstr(this,wObj,lObj);
// methods
	this.WriteHTML=TBWriteHTML;
	this.SuperReset=this.Reset;
	this.Reset = TBReset; // sovrascrive il metodo Reset di BOX aggiungendogli il reset del testo
}
/* *********************************************************** */
					// BUTTONBOX
/* *********************************************************** */
function BBTurnOn(){
	if(this.lighted) return;
	if( this.iBE && (!this.selected) ) this.iRef.src=this.iBE.src;
	else if(this.iSE&&this.selected) this.iRef.src=this.iSE.src;
	this.lighted=true;
}
function BBTurnOff(){
	if(!this.lighted) return;
	if(!this.selected) this.iRef.src=this.iB.src;
	else this.iRef.src=this.iS.src;
	this.lighted=false;
}
function BBSelect(){
	if(this.selected) return;
	if(!this.iS) return;
	if(this.lighted&&this.iSE) this.iRef.src=this.iSE.src;
	else this.iRef.src=this.iS.src;
	this.selected=true;
}
function BBDeSelect(){
	if(!this.selected) return;
	if(!this.iS) return;
	if(this.lighted&&this.iBE) this.iRef.src=this.iBE.src;
	else this.iRef.src=this.iB.src;
	this.selected=false;
}
function BBReset(pos,dim,vis,col,img){
	this.superReset(pos,dim,vis,col);
	if( img || (pos=="all") ){
		this.selected=false;
		this.lighted=false;
		this.iRef.src=this.iB.src;
	}
}
function BBIsSelected(){
	return( this.selected );
}
function BBSwitchLight(){ // aggiunta per testing
	if(	this.lighted ) this.TurnOff();
	else this.TurnOn();
}
function ButtonBox(wObj,lObj,iName,r,s,rs){ // aggiunto _className e .SwitchLight in testing
	this._className="ButtonBox";
	Box_cnstr(this,wObj,lObj);
	this.iRef=self.kutils.finder.GetImageByName(this.win,iName);
// controllo arg
	if(!this.iRef){
		if(top.debug) alert("Oggetto BUTTONBOX non creato: manca l\'immagine");
		return;
	}
	if(rs&&!s){
		if(top.debug) alert("Oggetto BUTTONBOX non creato: impossibile assegnare un rollover ad un\'immagine selezionata inesistente");
		return;
	}
// fine controllo
	this.name=iName;
	this.selected=false;
	this.lighted=false;
	// ricavo path e l'estensione da quella iniziale
	this.ext=(this.iRef.src.indexOf(".gif")>-1)?".gif":".jpg";
	this.path=this.iRef.src.substring(0,this.iRef.src.lastIndexOf("/"+this.name)+1);
	//inizializzo le immagini, anche per preload
	this.iB=new Image();
	this.iB.src=this.path+this.name+this.ext;
	if(r){ // rollover
		this.iBE=new Image();
		this.iBE.src=this.path+this.name+"_e"+this.ext;
	}
	if(s){ // selezione
		this.toSelect=true;
		this.iS=new Image();
		this.iS.src=this.path+this.name+"_s"+this.ext;
	}
	if(rs){ //rollover su selezione
		this.iSE=new Image();
		this.iSE.src=this.path+this.name+"_se"+this.ext;
	}
	//methods
	this.TurnOn=BBTurnOn;
	this.TurnOff=BBTurnOff;
	this.SwitchLight=BBSwitchLight;
	this.Select=BBSelect;
	this.DeSelect=BBDeSelect;
	this.IsSelected=BBIsSelected;
	this.superReset=this.Reset;
	this.Reset=BBReset;
}
self.kutils.Box = Box;
self.kutils.BoxText = TextBox;
self.kutils.BoxButton = ButtonBox;
/* ****************************************************** */
			// WIN ALERT e WIN MESSAGE
/* ****************************************************** */
function WAWrite(htmlStr){
		self.kutils.win.kAlert.document.open("text/html", "replace");
		self.kutils.win.kAlert.document.write(htmlStr);
		self.kutils.win.kAlert.document.close();
		if(self.kutils.NS6) self.kutils.win.kAlert.location.reload(); // per un baco che non mi fa lo show...
}
function WinAlert(hStr){
	var myUrl=self.kutils.GetFile("alert");
	var features="scrollbars=no,resizable=yes,menubar=no,status=no,width=300,height=200,top="+((screen.height-200)/2)+",left="+((screen.width-300)/2);
	self.kutils.win.OpenNew(myUrl,"kAlert",features);
	var htmlStr="<HTML><HEAD><TITLE>"+self.kutils.i18n.GetPhrase("Alert.title")+"</TITLE>";
	htmlStr+="<LINK REL='stylesheet' HREF='"+self.kutils.GetStileFile("alert")+"'>";
	htmlStr+="</HEAD><BODY onBlur='self.focus();'><P>";
	htmlStr+=hStr;
	htmlStr+="</P><CENTER><DIV ALIGN='center'><form name='alertForm'><INPUT TYPE='button' VALUE='OK' onClick='window.top.close();' ALIGN='center'></form></DIV></CENTER></BODY></HTML>";
	WAWrite(htmlStr);
}
function KMessageWin(tit,message){
	var myUrl=self.kutils.GetFile("message")+"?tit="+escape(tit)+"&msg="+escape(message);
	var features="scrollbars=no,resizable=no,menubar=no,status=no,width=300,height=120,top="+((screen.height-120)/2)+",left="+((screen.width-300)/2);
	self.kutils.win.OpenNew(myUrl,"kAlert",features);
}
self.kutils.Alert=WinAlert;
self.kutils.SendMessageWin=KMessageWin;
/* ****************************************************** */
			// ERROR MANAGER
/* ****************************************************** */
function KUEMAlert(cName,eMes,eLev){
	var str="",tit="",corpo="";
	if(parseInt(eLev,10)<=this.messageLevel){
			var ph1=self.kutils.i18n.GetPhrase("ErrorManager.ph1");
			var ph2=self.kutils.i18n.GetPhrase("ErrorManager.ph2");
			var ph3=self.kutils.i18n.GetPhrase("ErrorManager.ph3");
//			str=ph1+cName+"<BR>"+ph2+eMes+ph3+eLev;
//			self.kutils.Alert(str);
			tit=ph1+cName;
			corpo=ph2+eMes+ph3+eLev;
			self.kutils.SendMessageWin(tit,corpo);
	}
}
function KUEManager(mLevel){
	this._className="KUEManager";
	this.messageLevel=isNaN(parseInt(mLevel,10))?0:parseInt(mLevel,10);
	this.Alert=KUEMAlert;
}
self.kutils.ErrorManager=KUEManager;
/* ********************************* */
		// RECORDER // changed for testing v0.3
/* ********************************* */
function KUDRGetData(n){
	return(this.dataCookie.Get(n));
}
function KUDRInit(wObj,fObj){
	this.sendFrame=wObj;
	this.sendForm=fObj;
}
function KUDROnLoad(wObj,fObj){
	this.Init(wObj,fObj);
	this.SendResponse();
}
function KUDROnUnload(){
	this.sendForm=null;
}
function KUDRReadyToSend(){
	if( (this.sendForm==null)||(this.sendForm=='undefined')||(this.sendFrame==null)||(this.sendFrame=='undefined') )  return false;
	return true;
}
function KUDRSaveData(id,v){
	if(id!=escape(id)) return false;
	this.dataCookie.Set(id,v);
	return true;
}
function KUDRSendData(act,id,v,sObj,pAgg){
	if(!this.ReadyToSend()) return false;
	try{ 
		this.sendForm.action=act;
		this.sendForm.regName.value=id;
		this.sendForm.regValue.value=v;
		this.sendForm.parAggiuntivo.value=(pAgg?pAgg:"");
		this.sendForm.submit();
		this.sender=sObj;
		return true;
	}
	catch(e){
		if(top.debug) alert(e+"; e.message"+e.getMessage());
		return false;
	}
}
function KUDRSendResponse(){
	if(this.sender==null) return;
	try{ this.sender.ServerCommand(this.sendForm.cmd.value,this.sendForm.cmdValue.value); }
	catch(e){
		if(top.debug) alert(e+"; e.message"+e.getMessage());
	}
}
function KUDRSendReset(){
	fUrl=self.kutils.GetFile("recorder");
	if( (fUrl=="") || !this.sendFrame ){ if(top.debug) alert("KUDataRecorder.Reset(), recovery pathFile not found or !sendFrame"); return false; }
	this.sendFrame.location.href=fUrl; return true;
}
function KUDRCookieReset(){
	this.dataCookie.Reset();
}
function KUDRReset(){
	this.CookieReset();
	return(this.SendReset());
}
function KUDRGetAll(){
	return this.dataCookie.GetAll();	
}
function KUDRSetAll(dStr,force){
	if( !force && (this.dataCookie.GetAll()!="") ){
		if(!confirm( self.kutils.i18n.GetPhrase("Recorder.SaveAll") )) return false;
	}
	this.dataCookie.OverrideAll(dStr);
	return true;
}
function KUDRSetDaysOfCookiePermanence(d){
	this.dataCookie.daysOfPerm=d;
}
function KUDataRecorder(cN,cS,cE){
	this._className=(!cN||(cN==""))?"KUDataRecorder":cN;
	this.sender=null;
	this.sendForm=null;
	this.sendFrame=null;
	this.dataCookie=new self.kutils.DataCookie("_"+this._className+"-",cS,cE);
	this.GetAll=KUDRGetAll; // usare solo per prendere il blocco dei cookie da salvare sul server
	this.SetAll=KUDRSetAll; // si può usare solo una volta per ricreare dei dati salvati in blocco, se ci sono già dati presenti manda una confirm!
	this.Init=KUDRInit;
	this.OnLoad=KUDROnLoad;
	this.OnUnload=KUDROnUnload;
	this.ReadyToSend=KUDRReadyToSend;
	this.Reset=KUDRReset;
	this.SendReset=KUDRSendReset;
	this.CookieReset=KUDRCookieReset;
	this.GetData=KUDRGetData;
	this.SaveData=KUDRSaveData;
	this.SendData=KUDRSendData;
	this.SendResponse=KUDRSendResponse;
	this.SetDaysOfCookiePermanence=KUDRSetDaysOfCookiePermanence;
}
self.kutils.recorder=new KUDataRecorder("KUDataRecorder","_PV-","_EQ-");
/* ********************************* */
		// NOTE A POP UP
/* ********************************* */
function APUShow(wObj,lId,aName){
	var lBox=new self.kutils.Box(wObj,self.kutils.finder.GetLayerById(wObj,lId));
	var a=self.kutils.finder.GetAnchorByName(wObj,aName);
	var aY=self.kutils.GetPosY(a);
	var aX=self.kutils.GetPosX(a);
	var wH=self.kutils.win.GetHeight(wObj);
	var wSY=self.kutils.win.GetScrollY(wObj);
	var wW=self.kutils.win.GetWidth(wObj);
	var wSX=self.kutils.win.GetScrollX(wObj);
	var lH=lBox.GetDim("height");
	var lW=lBox.GetDim("width");
	var posX=parseInt((aX-(lW/3)),10);
	var posY=parseInt((aY-(lH)),10);
	if((posX+lW-wSX)>wW) posX=wW+wSX-(lW+5);
	if(posX<0) posX=5;
	if((wSY-posY)>0) posY=aY+20;
	lBox.SetPos("top",posY);
	lBox.SetPos("left",posX);
	lBox.Show();
}
function APUHide(wObj,lId){
	var lBox=new self.kutils.Box(wObj,self.kutils.finder.GetLayerById(wObj,lId));
	lBox.Hide();
}
/* ************************ */
// POPUP FISSO RISCRIVIBILE
/* ************************ */
function BPUShow(){
	this.tBox.SetPos(this.posXY[0],this.posXY[1]);
	this.tBox.SetPos(this.posXY[2],this.posXY[3]);
	this.tBox.Show();
}
function BPUHide(){
	this.tBox.Hide();
}
function BPUWrite(HTMLStr){
	this.tBox.WriteHTML(HTMLStr);
	this.Show();
}
function BPUWriteTxt(txt){
	var HTMLStr=this.stHTML+txt+this.endHTML;
	this.tBox.WriteHTML(HTMLStr);
	this.Show();
}
function BPUReset(pos,dim,vis,col,txt){
	this.tBox.Reset(pos,dim,vis,col,txt);
}
function BPopUp(wObj,lId,x,valX,y,valY,startHTML,endHTML){
	this.tBox=new self.kutils.BoxText(wObj,self.kutils.finder.GetLayerById(wObj,lId));
	this.stHTML=startHTML;
	this.endHTML=endHTML;
	this.posXY=new Array(x,valX,y,valY);
// metodi
	this.Show=BPUShow;
	this.Hide=BPUHide;
	this.WriteTxt=BPUWriteTxt;
	this.Write=BPUWrite;
	this.Reset=BPUReset;
}
// attacco a kutils
self.kutils.APopUpShow = APUShow;
self.kutils.APopUpHide = APUHide;
self.kutils.BPopUp = BPopUp;
/* ********************************************** 
	*  FORM VALIDATOR, non compatibile con i browser 4!
	*
*/
function VIsValidCF(cf){ // verifica che è un codice fiscale italiano valido, browser 4+
	cf=cf.toUpperCase();
	if(!cf.match(/\D{6}\d{2}\D{1}\d{2}\D{1}\d{3}\D{1}/)) return false;
	allowedChar="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	valoriPari="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	valoriDispari="BAKPLCQDREVOSFTGUHMINJWZYX";
	numToChar="ABCDEFGHIJ";
	var ch,chVal,chIndex;
	var tot=0;
	for(i=0;i<15;i++){
		ch=cf.charAt(i);
		chIndex=allowedChar.indexOf(ch);
		if(chIndex<0) return false;
		if(chIndex<10) ch=numToChar.charAt(chIndex);
		if( ((i+3)%2)==0 ) chVal=valoriPari.indexOf(ch);
		else chVal=valoriDispari.indexOf(ch);
		tot+=chVal;
	}
	ch=cf.charAt(15);
	if( (tot%26) != valoriPari.indexOf(ch) ) return false;
	return true;
}
function VIsDateReal(y,m,d){ // verifica che è una data reale passandogli anno mese giorno, browser 4+
	Y=parseInt(y,10);M=parseInt(m,10);D=parseInt(d,10);
	if(Y>9999) return false; if(M>12) return false; if(D>31) return false;
	if((D>30)&&((M==4)||(M==6)||(M==9)||(M==11))) return false;
	if(M==2){nm=(((Y%400)==0)||(((Y%4)==0)&&((Y%100)!=0)))?29:28;if(D>nm) return false;}
	return true;
}
function VFInvalid(el,msg){ // richiede DOM HTML 4.0 implementato
	if(el.getAttribute("TYPE")=="hidden"){
		if(el.getAttribute("LABEL")) self.kutils.SendMessageWin(self.kutils.i18n.GetPhrase("Validator.errTit"),self.kutils.i18n.GetPhrase("Validator.campo")+el.getAttribute("LABEL")+" "+msg);
		return false;
	}
	n=( el.getAttribute("LABEL") ) ? el.getAttribute("LABEL") : el.name;
	try{
		el.focus();
	}catch(e){
		try{
		el[0].focus();
		} catch(t){}
	}
	try{
		el.select();
	} catch(t){}
	self.kutils.SendMessageWin(self.kutils.i18n.GetPhrase("Validator.errTit"),self.kutils.i18n.GetPhrase("Validator.campo")+n+" "+msg);
	return false;
}
function VFValid(fObj){  // richiede DOM HTML 4.0 implementato
	els=fObj.elements; i=0; valid=true; tF=fObj; msg="";
	for(i=0;i<els.length;i++){
		el=els[i]; ty=el.getAttribute("TYPE");
		if(ty=="radio"){
			if(el.getAttribute("MANDATORY")) valid=false;
			nm=el.getAttribute("NAME");en=nm;nel=el;j=i;
			while(nel&&(en==nm)){
				if(nel.checked) valid=true;
				j++;nel=els[j];en=nel.getAttribute("NAME");
			}
			if(!valid){ msg=self.kutils.i18n.GetPhrase("Validator.radio"); return(this.IsInvalid(el,msg)); }
			i=j;continue;
		} else if( ty=="checkbox" ){
			n=parseInt(el.getAttribute("MANDATORY"),10); gr=el.getAttribute("GROUP");
			if(!isNaN(n)&&gr){
				eg=gr;d=0;nel=el;j=i;
				while(nel&&(eg==gr)){
					if(nel.checked) d++;
					j++;nel=els[j];eg=nel.getAttribute("GROUP");
				}
				if(d!=n){ msg=self.kutils.i18n.GetPhrase("Validator.chk1")+n+self.kutils.i18n.GetPhrase("Validator.chk2"); return(this.IsInvalid(el,msg)); }
				i=j; continue;
			}
		}
		else if( el.getAttribute("MANDATORY")){
			mand=el.getAttribute("MANDATORY").replace(/this\./g,"el.");
			valid=!eval(mand);
			if( el.value.length > 0 ) valid=true;
			if(!valid){ msg=self.kutils.i18n.GetPhrase("Validator.txt"); return(this.IsInvalid(el,msg)); }
		}
		if( el.getAttribute("FORMAT") && (el.value.length>0) ){
			fmt=el.getAttribute("FORMAT");
			try{
				n=parseInt(fmt,10);
				if( !isNaN(n) && (el.value.length<n) ){ msg=self.kutils.i18n.GetPhrase("Validator.format.n1")+n+self.kutils.i18n.GetPhrase("Validator.format.n2"); return(this.IsInvalid(el,msg));}
				if(fmt.match(/\\d/)){
					if(el.value.match(/\D/)){ msg=self.kutils.i18n.GetPhrase("Validator.format.soloN"); return(this.IsInvalid(el,msg));}
				}
				if(fmt.match(/min\[(\d+)\]/)){
					minNum=parseInt(RegExp.$1,10);
					n=parseInt(el.value,10);
					if(isNaN(n)||(n<minNum)){ msg=self.kutils.i18n.GetPhrase("Validator.format.nMaggiore")+minNum; return(this.IsInvalid(el,msg));}
				}
				if(fmt.match(/max\[(\d+)\]/)){
					maxNum=parseInt(RegExp.$1,10);
					n=parseInt(el.value,10);
					if(isNaN(n)||(n>maxNum)){ msg=self.kutils.i18n.GetPhrase("Validator.format.nMinore")+maxNum; return(this.IsInvalid(el,msg)); }
				}
				if(fmt.match(/\^/)){
					forbiddenChars=fmt.substring(fmt.indexOf("^")+1,fmt.length);
					rE=new RegExp("["+forbiddenChars+"]");
					if(el.value.match(rE)){ msg=self.kutils.i18n.GetPhrase("Validator.format.forbiddenChar")+forbiddenChars; return(this.IsInvalid(el,msg));}
				}
				if(fmt.match(/allowedChrs\[/)){
					allowedChars=fmt.substring(fmt.indexOf("allowedChrs[")+10,fmt.length);
					allowedChars=allowedChars.substring(0,allowedChars.indexOf("]"));
					rE=new RegExp("[^"+allowedChars+"]");
					if(el.value.match(rE)){ msg=self.kutils.i18n.GetPhrase("Validator.format.notValidChar"); return(this.IsInvalid(el,msg));}
				}
				if(fmt.match(/mail/)){
					if(!el.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/)){ msg=self.kutils.i18n.GetPhrase("Validator.format.email"); return(this.IsInvalid(el,msg));}
				}
				else if(fmt.match(/date/)){
					f=""; f=fmt.match(/\[[dmy\-\/\s]*\]/);
					if(f.length>2) f=f.substring(1,f.length-1);
					else f="dd-mm-yyyy";
					df=f.split(/[\-\/\s]/);
					ed=el.value.split(/[\-\/\s]/);
					if(ed.length!=df.length){ msg=self.kutils.i18n.GetPhrase("Validator.format.formatoData"); return(this.IsInvalid(el,msg)); }
					mod=false; d=1;m=1;y=1900;
					for(j=0;j<df.length;j++){
						if(isNaN(ed[j])){msg=self.kutils.i18n.GetPhrase("Validator.format.formatoData"); return(this.IsInvalid(el,msg));}
						if(df[j].match(/d+/)){if(df[j].length>ed[j].length) { d="0"+ed[j]; mod=true; } else d=ed[j];}
						if(df[j].match(/m+/)){if(df[j].length>ed[j].length) { m="0"+ed[j]; mod=true; } else m=ed[j];}
						if(df[j].match(/yyyy/)){if(ed[j].length==2){ y="20"+ed[j]; mod=true; } else y=ed[j];}
					}
					nV=f.replace(/d+/,d); nV=nV.replace(/m+/,m); nV=nV.replace(/y+/,y);
					el.value=nV;
					if(mod){
						msg=self.kutils.i18n.GetPhrase("Validator.format.dataCambiata"); return(this.IsInvalid(el,msg));
					}
					if(!this.IsDateReal(y,m,d)){ msg=self.kutils.i18n.GetPhrase("Validator.format.dataInventata"); return(this.IsInvalid(el,msg)); }
				}
				else if(fmt.match(/codicefiscale/)){
					if(!this.IsValidCF(el.value)){ msg=self.kutils.i18n.GetPhrase("Validator.format.CF"); return(this.IsInvalid(el,msg)); } 
				}
			} catch( e ){
				if(top.debug) alert(e.message);
				valid=false;
			}
		}
	}
	return valid;
}
function  KUValidator(){
	this.IsFormValid=VFValid;
	this.IsDateReal=VIsDateReal;
	this.IsValidCF=VIsValidCF; // codice fiscale
	this.IsInvalid=VFInvalid; // private
}
self.kutils.validator=new KUValidator();
/* ************************ */
// FORMATTATORE base
/* ************************ */
function KUFToEuro(val){
	val=val.replace(",",".");
	var v=parseFloat(val);
	if(isNaN(v)) return val;
	var e=parseInt(val,10);
	var c=Math.round((v-e)*100);
	if(c==100){ e++; c=0;}
	var cStr="";
	if(c<10) cStr="0"+c;
	else cStr=c;
	return ("€ "+e+","+cStr);
}
function Formatter(){
	this.ToEuro=KUFToEuro;
}
self.kutils.baseFormatter=new Formatter();
// solo per servizio!
function KUShowForm(fObj){
	if(!top.debug) return true;
	var str="Dati della form:\n";
	for(var i=0; i<fObj.elements.length; i++){
		str+=(fObj.elements[i].name+"="+fObj.elements[i].value+";\n");
	}
	var doSub=confirm(str);
	return doSub;
}
self.kutils.ShowForm=KUShowForm;
// do il via alle kuitls
self.kutils.Starter("all");
