// è un file UTF-8 - © www.broken-arts.com

var div_info = null;
function print_info( st ) {
	if (!div_info)
		create_div_info();
	div_info.st_info += st+'<br />';
	div_info.innerHTML = div_info.st_info;
}
function print_err( st ) {
	if (!div_info)
		create_div_info();
	div_info.st_info += st+'<br />';
	div_info.innerHTML = div_info.st_info;
	div_info.style.background = "#F00";
}
function create_div_info() {
	if (div_info)
		return;
	newdiv = document.createElement('div');
	newdiv.setAttribute( 'id', 'div_info' );
	newdiv.style.width = '400px';
	newdiv.style.height = '200px';
	newdiv.style.position = "absolute";
	newdiv.style.left = '600px';
	newdiv.style.top = '30px';
	newdiv.style.background = "#C0C0C0";
	newdiv.style.border = "1px solid black";
	newdiv.innerHTML = "ok";
	document.body.appendChild(newdiv);
	div_info = newdiv;
	div_info.st_info = '';
}
//debug_int=setInterval("debug_interval();", 5000);
function debug_interval() {
	win = window_get_scroll();
	doc = document_wh_get();
	print_info( 'doc.w='+doc.w+' doc.h='+doc.h+' win.x='+win.x+' win.y='+win.y+' win.w='+win.w+' win.h='+win.h );
}

var mouse_x = 0;
var mouse_y = 0;
var mouse_is_IE = document.all?true:false;
function handlerMM(e) {
	if (mouse_is_IE) { // grab the x-y pos.s if browser is IE
		mouse_x = event.clientX;
		mouse_y = event.clientY;
		c = window_get_scroll_xy();
		mouse_x += c.x;
		mouse_y += c.y;
	} else {  // grab the x-y pos.s if browser is NS
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}  
	if (mouse_x < 0){mouse_x = 0;}
	if (mouse_y < 0){mouse_y = 0;}  
}
document.onmousemove = null;
// document.onmousemove = handlerMM; inserito alla fine di htmlpag2_end.inc.php per evitare errori javascript in explorer
// fine funzioni pop-up
function mouse_get_doc_xy() {
	// restiruisce le coordinate del maouse RELATIVE AL DOCUMENTO
	var x = mouse_x;
	var y = mouse_y;
	return {x:x, y:y}; 
}

function window_get_scroll_xy() {
	var ofs_x = 0;
	var ofs_y = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		// Netscape compliant
		ofs_x = window.pageXOffset;
		ofs_y = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		// DOM compliant
		ofs_x = document.body.scrollLeft;
		ofs_y = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { 
		// IE6 standards compliant mode
		ofs_x = document.documentElement.scrollLeft;
		ofs_y = document.documentElement.scrollTop;
	}
	return {x:ofs_x, y:ofs_y}; 
}

function window_get_scroll() {
	var xy = window_get_scroll_xy();
	var w=0;
	var h=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		// Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		// IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return {x:xy.x, y:xy.y, w:w, h:h}; 
}

function document_wh_get() { // attenzione può essere più piccolo della finestra
	if (typeof(document.body.scrollWidth)=="number") {
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	} else { // da verificare
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	} 
	return {w:w, h:h}; 
}

function obj_get_from_id( id ) {
	var obj_var = 'obj_var_'+id; 
	if (eval('typeof('+obj_var+')=="undefined"')) {
		return null;
	}
	eval('var obj='+obj_var+';');
	return obj;
}

var obj_arr = new Array();
var obj_arr_tot = 0;
function obj_arr_add( obj ) {
	// restituisce la posizione dell'obj nell'array
	var idx = obj_arr_idx( obj );
	if (idx >= 0) // esiste già nell'array
		return idx;
	for (var i=0; i<obj_arr_tot; i++) {
		if (obj_arr[i] == null) {
			obj_arr[i] = obj;
			return i;
		}
	}
	var pos = obj_arr_tot;
	obj_arr[pos] = obj;
	obj_arr_tot++;
	return pos;
}
function obj_arr_idx( obj ) {
	for (var i=0; i<obj_arr.length; i++) {
		if (obj_arr[i]) {
			if (obj_arr[i].id == obj.id)
				return i;
		}
	}
	return -1;
}
function obj_arr_get_from_id( id ) {
	for (var i=0; i<obj_arr.length; i++) {
		if (obj_arr[i]) {
			if (obj_arr[i].id == id)
				return obj_arr[i];
		}
	}
	return null;
}
function obj_arr_delete( obj ) {
	for (var i=0; i<obj_arr.length; i++) {
		if (obj_arr[i]) {
			if (obj_arr[i].id == obj.id) {
				obj_arr[i].distruttore();
				delete obj_arr[i];
				obj_arr[i] = null;
				return true;
			}
		}
	}
	return false;
}
function obj_arr_message_to_all( msg ) {
	// broadcasting di messaggi ai miei oggetti
	for (var i=0; i<obj_arr.length; i++) {
		if (obj_arr[i]) {
			if (obj_arr[i].message( msg ))
				return true;
		}
	}
	return false;
}

window.onresize = function() {
	// faccio un broadcast a tutti gli oggetti avvisandoli che c'è un evento di resize
	obj_arr_message_to_all( 'window_resize' );
}
// questo è un metodo alternativo per aggirare l'incompatibilità cross-browser del position:fixed;
// con un setInterval chiamo ogni tanto la funzione glb_interval_func() per riposizionare
// se necessario gli elementi spostati con un eventuale scroll
var ws_xywh_prec = null;
function glb_interval_func() {
	var xywh = window_get_scroll();
	if (!ws_xywh_prec)
		ws_xywh_prec = xywh;
	// controllo solo gli spostamenti x e y, per la larghezza ed altezza ci pensa window.onresize
	if ((ws_xywh_prec.x != xywh.x) || (ws_xywh_prec.y != xywh.y))
		obj_arr_message_to_all( 'window_resize' );
	ws_xywh_prec = xywh;
}
glb_interval = 0;
function glb_interval_start() {
	if (!glb_interval)
		glb_interval = window.setInterval("glb_interval_func()",500);
}

function elm_xy_get( elm ) {
	var left = 0; 
	var top  = 0; 
	while (elm.offsetParent){ 
		left += parseInt(elm.offsetLeft); 
		top  += parseInt(elm.offsetTop); 
		elm = elm.offsetParent; 
	} 
	left += parseInt(elm.offsetLeft); 
	top  += parseInt(elm.offsetTop); 
	return {x:left, y:top}; 
}

function elm_wh_get( elm ) {
	// i valori potrebbe essere seguiti da 'px', ad esempio: '20px'
	// devo quindi forzare la tipizzazione a numero con parseInt()
	var w = parseInt(elm.offsetWidth);
	var h = parseInt(elm.offsetHeight);
	return {w:w, h:h}; 
}

function elm_xy_set( elm, x, y ) {
	elm.style.position = 'absolute'; 
	elm.style.left = x+"px"; 
	elm.style.top = y+"px"; 
}

function elm_wh_set( elm, w, h ) {
	if (w) {
		if (typeof(w)=="number")
			elm.style.width = w+"px";
		else
			elm.style.width = w;
	}
	if (h) {
		if (typeof(h)=="number")
			elm.style.height = h+"px";
		else
			elm.style.height = h;
	}
}


function class_obj( id ) {
	if (id) { // necessario altrimenti fa casino quando viene ereditata
		if (obj_arr_get_from_id( id )) {
			print_err('errore class_obj, oggetto '+id+' esistente');
			return;
		}
		this.id = id;
		this.obj_arr_idx = obj_arr_add( this );
		this.elm = document.getElementById( this.id );
		if (!this.elm)
			print_err('errore div '+this.id+' non trovato');
		this.window_centra_auto = false; // se true, autocentra l'elemento al resize della window, 
		this.window_resize_auto = false; // se true, ridimensione l'elemento alla dimensione della window
		// variabili per funzione slide()
		this.slide_interval = 0;
	}
	this.distruttore = function() {
	}
	this.xy_get = function() {
		return elm_xy_get( this.elm );
	}
	this.wh_get = function() {
		return elm_wh_get( this.elm );
	}
	this.wh_get = function() {
		// i valori potrebbe essere seguiti da 'px', ad esempio: '20px'
		// devo quindi forzare la tipizzazione a numero con parseInt()
		var w = parseInt(this.elm.offsetWidth);
		var h = parseInt(this.elm.offsetHeight);
		return {w:w, h:h}; 
	}
	this.xy_set = function( x, y ) {
		this.elm.style.position = 'absolute'; 
		this.elm.style.left = x+"px"; 
		this.elm.style.top = y+"px"; 
	}
	this.x_set = function( x ) {
		this.elm.style.position = 'absolute'; 
		this.elm.style.left = x+"px"; 
	}
	this.wh_set = function( w, h ) {
		if (w) {
			if (typeof(w)=="number")
				this.elm.style.width = w+"px";
			else
				this.elm.style.width = w;
		}
		if (h) {
			if (typeof(h)=="number")
				this.elm.style.height = h+"px";
			else
				this.elm.style.height = h;
		}
	}
	this.padding_set = function ( val ) {
		// qui bisogna controllare le differenze tra firefox e explorer
		// uno fa il padding fuori e uno dentro.
		this.elm.style.padding = val+'px';
	}
	this.html_set = function( st ) {
		this.elm.innerHTML=st;
	}
	this.html_get = function() {
		return this.elm.innerHTML;
	}
	this.hide = function() {
		this.elm.style.visibility="hidden";
	}
	this.show = function() {
		this.elm.style.visibility="visible";
	}
	this.display = function ( st ) { // me lo metto qui per meditarci nelle future estensioni
		// display è diverso da show & hide, in quanto influenza il layout della pagina
		this.elm.style.display=st;
	}
	this.window_centra = function( mode ) {
		// quando il valore width è stato impostato ad 'auto', ogni volta che sposto
		// la posizione x del div, la larghezza viene reimpostata al bordo destro della finestra
		// se mode == 'w' centra solo in larghezza
		var wh = this.wh_get();
		var xywh = window_get_scroll();
		// soluzione compatibile con explorer 6
		var xofs = Math.round((xywh.w - wh.w) / 2);
		var yofs = Math.round((xywh.h - wh.h) / 2);
		var x = xywh.x+xofs;
		var y = xywh.y+yofs;
		if (x < 0)
			x = 0;
		if (y < 0)
			y = 0;
		if (mode == 'w')
			this.x_set( x );
		else
			this.xy_set( x, y );
		this.window_centra_auto = true;
		glb_interval_start();
		/* non compatibile con explorer 6
		if (mode == 'w') {
			this.elm.style.left = xofs+'px'; 
		} else {
			this.elm.style.top = yofs+'px'; 
			this.elm.style.left = xofs+'px'; 
		}
		this.elm.style.position = 'fixed';
		this.window_centra_auto = true;
		*/
	}
	this.window_resize = function() {
		// metodo compatibile cn explorer 6
		this.wh_set( 1, 1 );
		wh = document_wh_get();
		this.xy_set( 0, 0 );
		this.wh_set( wh.w, wh.h );
		glb_interval_start();
		/* non compatibile col 6
		c = window_get_scroll();
		this.elm.style.position = 'fixed';
		this.elm.style.top = '0px'; 
		this.elm.style.left = '0px'; 
		this.elm.style.width = c.w+'px';
		this.elm.style.height = c.h+'px';
		*/	
		this.window_resize_auto = true;
	}
	this.centra = function( px, py, pw, ph ) { // centra rispetto alle coordinate specificate
		// quando il valore width è stato impostato ad 'auto', ogni volta che sposto
		// la posizione x del div, la larghezza viene reimpostata al bordo destro della finestra
		var wh = this.wh_get();
		var xofs = Math.round((pw - wh.w) / 2);
		var yofs = Math.round((ph - wh.h) / 2);
		var x = px+xofs;
		var y = py+yofs;
		if (x < 0)
			x = 0;
		if (y < 0)
			y = 0;
		this.xy_set( x, y );
	}
	this.slide_to = function ( to_x, to_y ) {
		var xy = this.xy_get();
		this.slide_x1 = xy.x;
		this.slide_y1 = xy.y;
		this.slide_x2 = to_x;
		this.slide_y2 = to_y;
		this.slide_xofs = 0;
		this.slide_yofs = 0;
		this.slide_pix = 10; // numero di pixel per ogni spostamento
		if (Math.abs(this.slide_x2-this.slide_x1) > Math.abs(this.slide_y2-this.slide_y1))
			this.slide_length = Math.abs(this.slide_x2-this.slide_x1);
		else
			this.slide_length = Math.abs(this.slide_y2-this.slide_y1);
		this.slide_dx = (this.slide_x2-this.slide_x1) / (this.slide_length / this.slide_pix);
		this.slide_dy = (this.slide_y2-this.slide_y1) / (this.slide_length / this.slide_pix);
		if (!this.slide_interval)
			this.slide_interval = setInterval("class_obj_slide_interval("+this.obj_arr_idx+")",40);
	}
	this.slide_interval_func = function() {
		this.slide_xofs += this.slide_dx;
		this.slide_yofs += this.slide_dy;
//		print_info('test');
		var end = false;
		if (Math.abs(this.slide_yofs) >= this.slide_length)
			end = true;
		if (Math.abs(this.slide_xofs) >= this.slide_length)
			end = true;
		if (end) {
			this.xy_set( this.slide_x2, this.slide_y2 );
			clearInterval(this.slide_interval);
			this.slide_interval = 0;
			return;
		}
		this.xy_set( this.slide_x1+this.slide_xofs, this.slide_y1+this.slide_yofs );
	}
	this.message = function( msg ) {
		// funzione che mi permette un semplice broadcasting di messaggi
		if (msg=='window_resize') {
			if (this.window_centra_auto)
				this.window_centra();
			if (this.window_resize_auto)
				this.window_resize();
		}
	}
}
function class_obj_slide_interval( idx ) {
	obj_arr[idx].slide_interval_func();
}


dark_div = null;
function dark_div_create() {
	if (dark_div)
		return;
	var id = 'dark_div';
	var elm  = document.createElement('div');
	elm.style.position='absolute';   
	elm.style.top='0px';   
	elm.style.left='0px';
	var opacity = 30;   
	var opaque = (opacity / 100);    
	elm.style.opacity=opaque;
	elm.style.MozOpacity=opaque;
	elm.style.filter='alpha(opacity='+opacity+')';
	elm.style.backgroundColor="#000000";
	elm.setAttribute( 'id', id );
	document.body.appendChild( elm );
	// document.body.insertBefore(elm,document.body.firstChild);
	// elm.style.zIndex = 100;
	dark_div = new class_obj( id );
}
function dark_div_show() {
	if (!dark_div)
		dark_div_create();
	dark_div.window_resize();
	dark_div.show();
}
function dark_div_hide() {
	if (!dark_div)
		dark_div_create();
	dark_div.hide();
}

loading_obj = null;
function loading_obj_create() {
	if (loading_obj)
		return;
	var id = 'loading_div';
	var elm  = document.createElement('div');
	elm.setAttribute( 'id', id );
	elm.style.position='absolute';   
	elm.style.top='0px';   
	elm.style.left='0px';
	// glb_loading_obj_img_url viene definito nell'head della pagina html (da htmlpag1_start)
	elm.innerHTML = '<img src="'+glb_loading_obj_img_url+'" alt="Loading" />';
	document.body.appendChild( elm );
	loading_obj = new class_obj( id );
}
function loading_obj_show( parent_obj ) {
	if (!loading_obj)
		loading_obj_create();
	var xy = parent_obj.xy_get();
	var wh = parent_obj.wh_get();
	loading_obj.centra( xy.x, xy.y, wh.w, wh.h );
	loading_obj.show();
}
function loading_obj_hide() {
	if (!loading_obj)
		loading_obj_create();
	loading_obj.hide();
}


function class_div( id, nuovo ) {
	if (id) {
		// se nuovo=false si attacca ad un div già esistente nella pagina, altrimenti ne crea uno nuovo
		if (!dark_div)
			dark_div_create(); // faccio in modo che il dark_div venga creato prima di questo div, in modo che sia posizionato sotto di questo
		//
		this.created_dyn = false; // true se creato dinamicamente
		if (nuovo) {
			this.created_dyn = true; // true se creato dinamicamente
			var newdiv = document.createElement('div');
			newdiv.setAttribute( 'id', id );
			newdiv.style.background = "#FFFFFF";
			newdiv.style.border = "1px solid black";
			newdiv.style.visibility="hidden";
			newdiv.style.border = "1px solid black";
			newdiv.innerHTML = "";
			document.body.appendChild(newdiv);
		}
		this.base = class_obj;
		this.base( id );
		this.xhr = null;			// meccanismo di scambio dati
		this.xhr_xml = true; 		// se false, uso Microsoft.XMLHTTP (Explorer vecchio)
		this.xhr_url = '';			// url della pagina incaricamento
		this.xhr_params = false;	// params dell'url da caricare, es: 'test=3&prova=2'
		this.xhr_loop = false; 		// se true, quando ha finito di ricaricare xhr_url la ricarica daccapo fino a quando non riceve '--stop--' invece dell'html
		this.xhr_loading = false; 	// true se la connessione è aperta e non ancora conclusa
		this.xhr_err = 0;			// > 0 se si è verificato un errore
		this.xhr_sts = 0;
		this.xhr_onreadystatechange_func = new Function('xhr_onreadystatechange("'+this.id+'");'); // questa è la funzione che verrà chiamata per interrogare lo stato dell'xhr
		this.loading_obj_show = true;	// se true mostra l'icona di caricamento
	}
	this.distruttore = function() {
		if (this.created_dyn)
			document.body.removeChild(this.elm);
		if (this.xhr) {
			delete this.xhr;
			this.xhr = null;
		}
	}
	this.hide = function() {
		this.elm.style.visibility="hidden";
	}
	this.show = function() {
		this.elm.style.visibility="visible"
	}
	this.load_page_form = function( url, form_id ) {
		var form = document.getElementById( form_id );
		var first = true;
		var st_params = '';
		for (var i=0; i<form.length; i++)  {
			if (form.elements[i].name) {
				if (first)
					first = false;
				else
					st_params+='&';
				st_params+=form.elements[i].name+'='+encodeURI(form.elements[i].value);
			}
			switch (form.elements[i].type) {
				case 'button':
				case 'submit':
					form.elements[i].disabled=true; // per evitare che l'utente prema daccapo un bottone
//					form.elements[i].style.visibility="hidden"; // per evitare che l'utente prema daccapo un bottone
					break;
			}
		}
		this.load_page( url, st_params );
	}
	this.load_page = function( url, params, loop, loading_obj_hide ) {
		// url = "get_data.php";
		// params = "lorem=ipsum&name=binny";
		//
		if ( this.xhr ) {
			if (this.xhr.readyState != 4)
				return; // sto ancora attendendo il caricamento
//				this.xhr.abort();
			// con Explorer 8 e mozilla posso riutilizzare xhr per un altro caricamento, ma con explorer 7 no
			// per cui cancello xhr vecchio e ne creo uno nuovo
			delete this.xhr;
			this.xhr = null;
		}
		//
		this.xhr_url = url;
		this.xhr_params = params;
		this.xhr_loop = loop;
		if (loading_obj_hide)
			this.loading_obj_show = false;		
		//
		try {
			this.xhr = new XMLHttpRequest();
			this.xhr_xml = true;
		} catch (e) {
			try {
				this.xhr = new ActiveXObject('Microsoft.XMLHTTP');
				this.xhr_xml = false;
			} catch (e2) {
				try {
					this.xhr = new ActiveXObject('Msxml2.XMLHTTP');
					this.xhr_xml = false;
				} catch (e3) {
					this.xhr = false;
				}
			}
		}
		if (!this.xhr) {
			alert('impossibile creare XMLHttpRequest');
			return false;
		}
		this.xhr.onreadystatechange = this.xhr_onreadystatechange_func;
		this.xhr_loading = true;
		this.xhr_err = 0;
		if (params) {
			this.xhr.open('POST', url,  true); 
			this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xhr.setRequestHeader("Content-length", params.length);
			this.xhr.setRequestHeader("Connection", "close");
			this.xhr.send(params);
		} else {
			this.xhr.open('GET', url,  true);
			this.xhr.send(null);
		}
		if (this.loading_obj_show)
			loading_obj_show( this );
	}
	this.load_page_completed_function = function( err ) {
		if ( err ) {
			if (this.xhr_sts) // stampo l'errore solo se lo status è != 0 (altrimenti cliccando su un link nella pagina mi stampa l'errore)
				this.elm.innerHTML='<div style="text-align:center; padding:10px;">Errore nel caricamento di<br />'+this.xhr_url+'<br>Status: '+this.xhr_sts+'</div>';
			return;
		}
		if (this.xhr_loop) { // devo ricaricare la pagina
			// controllo se all'inizio dell'html c'è la stringa di stop
			var st = '--stop--';
			var lst = st.length;
			if (this.elm.innerHTML.substr(0,lst)==st) { // all'inizio dell'html ho ricevuto il messaggio di chiudere il loop
				this.elm.innerHTML = this.elm.innerHTML.substr(lst);
				return; // fine del loop
			}
			var st = '--reload--';
			var lst = st.length;
			if (this.elm.innerHTML.substr(0,lst)==st) { // segnale di location.reload pagina
				this.elm.innerHTML = this.elm.innerHTML.substr(lst);
				location.reload(true);
				return;
			}
			var st = '--loop--';
			var lst = st.length;
			if (this.elm.innerHTML.substr(0,lst)==st) { // all'inizio dell'html ho ricevuto il messaggio di continuare il loop
				this.elm.innerHTML = this.elm.innerHTML.substr(lst);
				this.load_page( this.xhr_url, this.xhr_params, this.xhr_loop );
				return; // fine del loop
			}
			// in tutti gli altri casi il loop si interrompe (così se si verificaun errore PHP il loop non continua)
		}
	}
	this.load_page_interval = function() {
		// fine caricamento
		if (!this.xhr)
			return;
		if (!this.xhr_loading)
			return;
		if (this.xhr.readyState == 4) {
			if (this.loading_obj_show)
				loading_obj_hide();
			this.xhr_err = 0;
			this.xhr_sts = this.xhr.status;
			if (this.xhr_sts == 200)
				this.elm.innerHTML= this.xhr.responseText;
			else
				this.xhr_err = 1; // si è verificato un errore di connessione
			this.xhr_loading = false;
			// 
			delete this.xhr;
			this.xhr = null;
			//
			this.load_page_completed_function( this.xhr_err );
		}
	}
}
class_div.prototype = new class_obj;

function xhr_onreadystatechange( div_id ) {
	var obj = obj_arr_get_from_id( div_id );
	if (!obj)
		alert('error');
	obj.load_page_interval();
}


function divload_load_page( div_id, url, params, loop, loading_obj_hide ) {
	// div_id = id del div in cui caricare la paginaù
	// url = url della pagina
	// params = parametri as esempio 'prova=2&test=4'
	// loop = se true dopo aver caricato la pagina la ricarica ancora fino a quando riceve --stop--
	// loading_obj_hide = se true non mostra l'icona di caricamento
	var obj = obj_arr_get_from_id( div_id );
	if (obj == null)
		obj = new class_div(div_id, false);
	obj.load_page( url, params, loop, loading_obj_hide );
}

divpopload_obj = null;
function divpopload_open( url ) {
	if (!divpopload_obj) {
		divpopload_obj = new class_div("divpopload", true);
		divpopload_obj.arr_del_obj = new Array();
	}
	dark_div_show();
	divpopload_obj.show();
	divpopload_obj.xy_set( 0, 0 );
	divpopload_obj.wh_set( 'auto', 'auto' );
	divpopload_obj.html_set('<div style="width:100px; height:100px;"></div>');
	divpopload_obj.window_centra();
	divpopload_obj.first_load_page = true;
	divpopload_obj.load_page_completed_function = divpopload_load_page_completed;
//	loading_obj_show( divpopload_obj );
	divpopload_obj.load_page( url );
}
function divpopload_load_page_completed( err ) {
	if ( err ) {
		this.elm.innerHTML='<div style="text-align:center; padding:10px;">Errore nel caricamento<br /><br /><button onclick="divpopload_close()">Chiudi</button></div>';
		return;
	}
	if (!divpopload_obj)
		return;
	if (this.elm.innerHTML.substr(0,2)=='--') { // azione
		var arrst = this.elm.innerHTML.split('|');
		switch (arrst[0]) {
			case '--errmsg--': // messaggio di errore: --errmsg--|messaggio di errore|
				this.elm.innerHTML='<div style="text-align:center; padding:10px;">'+arrst[1]+'<br /><br /><button onclick="divpopload_close()">Chiudi</button></div>';
				return;
			case '--divload--': // chiude il divpopload e carica una pagina nel div con l'id indicato
				// --divload--|div_id|url|params
				divpopload_close();
				var div_id = arrst[1];
				var url = arrst[2];
				var params = '';
				if (arrst.length > 3) {
					params = arrst[3];
					// c'è un problema grave: javascript mi riceve &amp; al posto della &, per cui lo correggo con un replace
					// no xe so mare bona, ma insomma...
					params = params.replace(/\&amp\;/g,'&');
				}
				divload_load_page( div_id, url, params );
				return;
			case '--quit--': // chiude il divpopload
				divpopload_close();
				return;
		}
	}
	if (divpopload_obj.first_load_page) {
		divpopload_obj.window_centra();
		divpopload_obj.first_load_page = false;
		divpopload_obj.first_load_page_xy = divpopload_obj.xy_get();
	} else { // load a seguito di un evento submit
//		divpopload_obj.xy_set( divpopload_obj.first_load_page_xy.x, divpopload_obj.first_load_page_xy.y );
		divpopload_obj.window_centra();
	}
}
function divpopload_submit( url, form_id, azione_id, azione_value ) {
	var obj = document.getElementById( azione_id );
	obj.value = azione_value;
	divpopload_del_obj_delete();
	divpopload_obj.load_page_form( url, form_id );
//	loading_obj_show( divpopload_obj );
//	divpopload_obj.html_set('Attendere, caricamento in corso.');
}
function divpopload_del_obj_add( obj ) {
	// inserisco il puntatore ad un oggetto che dovrà essere distrutto al hide() di divpopload
	// e anche ogni volta che viene caricata una nuova pagina
	// mi serve in js_autocomp, in modo da distruggere il div di autocomp alla chiusura del divpopload
	if (!divpopload_obj)
		print_err('errore, divpopload_obj non definito');
	for (var i=0; i<divpopload_obj.arr_del_obj.length; i++) {
		if (divpopload_obj.arr_del_obj[i]==null) { // riciclo gli spazi vuoti nell'array
			divpopload_obj.arr_del_obj[i] = obj;
			return;
		}
	}
	divpopload_obj.arr_del_obj.push( obj );
}
function divpopload_del_obj_delete() {
	for (var i=0; i<divpopload_obj.arr_del_obj.length; i++) {
		if (divpopload_obj.arr_del_obj[i] != null) {
			obj_arr_delete( divpopload_obj.arr_del_obj[i] );
			divpopload_obj.arr_del_obj[i] = null;
		}
	}
	divpopload_obj.arr_del_obj = new Array();
}
function divpopload_close() {
	divpopload_del_obj_delete();
	divpopload_obj.hide();
	divpopload_obj.elm.innerHTML=''; // è necessario azzerare innerHTML alla chiusura, altrimenti restano pezzi in giro se in una form ho impostato lo stile di qualche elemento a visible
	dark_div_hide();
}

function elm_set_value( id, val ) {
	var elm = document.getElementById( id );
	elm.value = val;
}

function img_change( elm, suffisso_st ) {
	// cambia il src dell'immagine, per esempio con suffisso_st == 'out'
	// cambia il src da: .../immagine_over.gif a .../immagine_out.gif
	var ext_idx = elm.src.lastIndexOf('.');
	var ext_st = elm.src.substr( ext_idx );
	var url_idx = elm.src.lastIndexOf('_');
	var url_st = elm.src.substr( 0, (url_idx+1) );
	var src = url_st+suffisso_st+ext_st;
	if (src != elm.src)
		elm.src = url_st+suffisso_st+ext_st;
}

function div_display( id ) {
	var elm = document.getElementById( id );
	if (elm.style.display =='inline')
		elm.style.display = 'none';
	else
		elm.style.display = 'inline';
}

function is_def( v ) {
	if (typeof(v)=="undefined")
		return false;
	return true;
}


popup_obj = null;
function popup_show( id_pos, sttit, stmsg, larg, centra, bclose ) {
	// id_pos == oggetto da cui origina la chiamata
	// se l'oggetto non esiste lo creo, se esiste già lo riuso
	if (!popup_obj)
		popup_obj = new class_div( 'popup', true );

	var popup_col_bordo = "#000000";
	var popup_bgcol_tit = "#1F5BA5";
	var popup_col_tit = "#FFFFFF";
	var popup_bgcol_msg = "#FFFFCC";
	var popup_col_msg = "#000000";
	var popup_relposy = -5;
	var pad = 5;
	stlarg = '';
	if (larg)
		stlarg = ' width:'+(larg - (pad * 2))+'px;';
	var html='';
	if (sttit!="")
		html+='<div style="padding: 2px '+pad+'px 2px '+pad+'px; background-color:'+popup_bgcol_tit+'; color:'+popup_col_tit+';'+stlarg+'"><b>'+sttit+'</b></div>'+"\n";
	html+= '<div style="padding: 3px '+pad+'px 3px '+pad+'px; background-color:'+popup_bgcol_msg+'; color:'+popup_col_msg+';'+stlarg+'">'+stmsg+'</div>'+"\n";
	if (bclose)
		html+='<div style="padding: 2px '+pad+'px 3px '+pad+'px; background-color:'+popup_bgcol_msg+';'+stlarg+'"><a href="javascript:popup_hide()">Chiudi</a></div>'+"\n";
	popup_obj.elm.innerHTML = html;
	
	var x = 0;
	var y = 0;
	if (id_pos) {
		var elm = document.getElementById( id_pos );
		var xy = elm_xy_get( elm );
		var wh = elm_wh_get( elm );
		x = xy.x;
		y = xy.y+wh.h;
	} else {
		x = mouse_x;
		y = mouse_y + poprelposy;
	}
	if ( centra && (larg > 0) )
		x -= (larg / 2);
	if (x < 5)
		x = 5;
	popup_obj.xy_set( x, y );
	popup_obj.show();
}
function popup_hide() {
	if (popup_obj)
		popup_obj.hide();
}

