/**************************************************************\
*                   TheOtherVoice Ajax v. 2.0                  *
*      Copyright (C) 2008 Tozzini Alessio TheOtherVoce.it      *
*  rilasciato secondo i termini di GNU GENERAL PUBLIC LICENSE  *
*--------------------------------------------------------------*
* ajax.js: oggetto x ajax con i vari div                       *
\**************************************************************/


/**********************************************************\
* oggetto calcolo dimensioni pagina                        *
\**********************************************************/
var tovDimPage = Class.create();
tovDimPage.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( options ) {},
	//
	// RESTITUISCE MISURE PAGINA CON SCROLL
	//
	getPageSize : function()
	{
		var	dim_win = this.getVisiblePageSize(),
			dim_scroll = this.getScrollPageSize(),
			dim = {};
		// return
		dim.width = (dim_scroll.width < dim_win.width) ? dim_win.width : dim_scroll.width;
		dim.height = (dim_scroll.height < dim_win.height) ? dim_win.height : dim_scroll.height;
		return dim;
	},
	//
	// RESTITUISCE MISURE SENZA SCROLL
	//
	getVisiblePageSize : function()
	{
		var dim = {};
		// finestra
		if( self.innerHeight )
		{
			// non Explorer
			dim.height = self.innerHeight;
			dim.width = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : self.innerWidth;
		} else {
			// Explorer
			dim.height = document.documentElement.clientHeight;
			dim.width = document.documentElement.clientWidth;
		}
		// return
		return dim;
	},
	//
	// RESTITUISCE MISURE PAGINA SCROLL
	//
	getScrollPageSize : function()
	{
		var dim = {};
		// scroll
		if( window.innerHeight && window.scrollMaxY )
		{
			dim.width = window.scrollMaxX + window.innerWidth;
			dim.height = window.scrollMaxY +  window.innerHeight;
		} else if( document.body.scrollHeight > document.body.offsetHeight )
		{
			// Mac Explorer
			dim.width = document.body.scrollWidth;
			dim.height = document.body.scrollHeight;
		} else {
			// altri
			dim.width = document.body.offsetWidth;
			dim.height = document.body.offsetHeight;
		}
		// return
		return dim;
	},
	//
	// RESTITUISCE SCROLLING PAGINA
	//
	getOffsetPage : function ()
	{
		var offset = {};
		if( window.pageXOffset && window.pageYOffset )
		{
			offset.x = window.pageXOffset;
			offset.y = window.pageYOffset;
		} else if( document.documentElement )
		{
			offset.x = document.documentElement.scrollLeft;
			offset.y = document.documentElement.scrollTop;
		} else if( document.body )
		{
			offset.x = document.body.scrollLeft;
			offset.y = document.body.scrollTop;
		}
		return offset;
	}
};


/**********************************************************\
* oggetto gestione fumetti                                 *
\**********************************************************/
var tovBalloon = Class.create();
tovBalloon.prototype = {
	dim : new tovDimPage(), // restituisce dim. finestra
	desc : [], // lista descrizioni
	//
	// INIZIALIZZO
	//
	initialize : function( div_lista, div_desc, direzione )
	{
		this.div = {
				list: div_lista,
				description: div_desc
			};
		if( typeof( direzione ) == "undefined" )
		{
			this.direction = "right";
		} else {
			this.direction = direzione;
		}
	},
	//
	// VISUALIZZA FUMETTO
	//
	appear : function( elemento )
	{
		var s = this.getPosition( elemento );
		this.changeText( elemento );
		this.move( elemento, s );
		Element.show( this.div.description );
	},
	changeText : function( id )
	{
		$( this.div.description ).innerHTML = this.desc[ id ];
	},
	//
	// RESTITUISCE COORDINATE LINK
	//
	getPosition : function( elemento )
	{
		var	e = $( elemento ),
			position = { x:0, y:0 };
		while (e)
		{
    			position.x += e.offsetLeft;
    			position.y += e.offsetTop;
    			e = e.offsetParent;
		}
		return position;
	},
	//
	// NASCONDE FUMETTO
	//
	hide : function() { Element.hide( this.div.description ); },
	//
	// SPOSTA FUMETTO
	//
	move : function( elemento, pos )
	{
		var d = $( this.div.description );
		var scrolling = this.dim.getOffsetPage();
		var h_img = $( elemento ).getHeight() / 2;
		var t = ( pos.y < scrolling.y ) ?  scrolling.y : pos.y + h_img;
		if( this.direction == "right" )
		{
		} else {
			var l = pos.x - d.getWidth();
		}
		d.setStyle( { top: t + "px", left: l + "px" } );
	},
	//
	// STAMPA FUMETTO
	//
	print : function( originalResponse )
	{
		var	obj = obj_data_page.returnJSON( originalResponse ),
			lista = obj;
		var titolo, immagine, testo, chiave = "", stringa = "";
		for( var k in lista )
		{
			titolo = obj_data_page.htmlEntityDecode( lista[k].title );
			immagine = obj_data_page.htmlEntityDecode( lista[k].image );
			testo = obj_data_page.htmlEntityDecode( lista[k].text );
			chiave = 'promo' + k;
			stringa += "<img id=\"" + chiave +
					"\" src=\"" + immagine +
					"\" alt=\"" + titolo +
					"\" title=\"\" onmouseover=\"obj_promozioni.appear('" + chiave +
					"');\" onmouseout=\"obj_promozioni.hide();\" /><br />";
			this.desc[ chiave ] = testo;
		}
		$( this.div.list ).innerHTML = stringa;
	}
};


/**********************************************************\
* oggetto che gestisce le icone                            *
\**********************************************************/
var tovIcons = Class.create();
tovIcons.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( options )
	{
		this.image = options.image;
		this.dir = options.dir;
		this.max = options.max;
		this.min = options.min;
	},
	//
	// RESTITUISCE STRINGA INTERA
	//
	get : function( n ) { return this.getDir() + '/' + this.getImage(); },
	//
	// RESTITUISCE DIRECTORY
	//
	getDir : function() { return this.dir; },
	//
	// RESTITUISCE IMMAGINE
	//
	getImage : function() { return this.image; },
	//
	// RESTITUISCE DIMENSIONI MASSIME
	//
	getMax : function() { return this.max; },
	//
	// RESTITUISCE DIMENSIONI MASSIME
	//
	getMin : function() { return this.min; },
	//
	// MODICA DIMENSIONI
	//
	setDimensions : function( min, max )
	{
		this.max = max;
		this.min = min;
	}
};


/**********************************************************\
* oggetto che si occupa dell'immagine di loading           *
\**********************************************************/
var tovLoadingPage = Class.create();
tovLoadingPage.prototype = {
	div : "loading", // div dove scrivere messaggi
	image : "image/loading.gif", // immagine loading
	message : "Loading...", // messaggio loading
	string_clear : "", // stringa x clear
	//
	// INIZIALIZZO
	//
	initialize : function(  ) {},
	//
	// CANCELLA LOADING CON STRINGA
	//
	clear : function() { $( this.div ).innerHTML = this.string_clear; },
	//
	// VISUALIZZO LOADING
	//
	print : function( )
	{
		$( this.div ).innerHTML = "<img class=\"loading\" src=\"" + this.image +
						"\" alt=\"loading\" /> " + this.message;
	},
	//
	// IMPOSTO STRINGA CLEAR
	//
	setClearString : function( s ) { this.string_clear = s; },
	//
	// IMPOSTO DIV
	//
	setDiv : function( div ) { this.div = div; },
	//
	// IMPOSTO IMMAGINE LOADING
	//
	setImage : function( img ) { this.image = img; },
	//
	// IMPOSTO TESTO MESSAGGIO
	//
	setMessage : function( s ) { this.message = s; }
};

/**********************************************************\
* oggetto pagine da opzioni Minimale                       *
\**********************************************************/
var tovTitlePage = Class.create();
tovTitlePage.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( div, titolo, image )
	{
		this.div = div; // dove scrivere
		this.title = titolo; // titolo
		if( typeof( image ) != "undefined" )
		{
			this.image = image;
		} else {
			this.image = "";
		}
	},
	//
	// STAMPO TITOLO
	//
	print : function() {
		if( this.image == "" )
		{
			var stringa = this.title;
		} else {
			var stringa = "<img src=\"" + this.image +
					"\" alt=\"" + this.title +
					"\" />";
		}
		$( this.div ).innerHTML = stringa;
	 },
	//
	// IMPOSTA NUOVI VALORI
	set : function( div, titolo, image )
	{
		this.div = div; // dove scrivere
		this.title = titolo; // titolo
		if( typeof( image ) != "undefined" )
		{
			this.image = image;
		} else {
			this.image = "";
		}
	},
};

/**********************************************************\
* oggetto gestione linguaggio                              *
\**********************************************************/
var tovChangeLanguage = Class.create();
tovChangeLanguage.prototype = {
	lang : [],
	//
	// INIZIALIZZO
	//
	initialize : function( div, funct, dir )
	{
		this.div = div;
		this.funct = funct;
		this.dir = dir;
	},
	//
	// IMPOSTA LINGUA ATTUALE
	//
	actualLanguage : function( l ) { this.actual_language = l; },
	//
	// AGGIUNGE LINGUA
	//
	addLanguage : function( opt, s, icon_v, icon_h  )
	{
		this.lang[opt] = {
				'icon' : {
					'visible' : icon_v,
					'hide' : icon_h
					},
				'language' : s,
				'option' : opt
				};
	},
	//
	// RESTITUISCE LINGUA ATTUALE
	//
	getActualLanguage : function() { return this.actual_language; },
	//
	// STAMPO ICONE
	//
	print : function()
	{
		var lang = this.getActualLanguage();
		var s = "";
		for( var i in this.lang )
		{
			if( typeof( this.lang[i].option ) != "undefined" )
			{
				if( this.lang[i].option == lang )
				{
					s += "<img src=\"" + this.dir +
						"/" + this.lang[i].icon.hide +
						"\" alt=\"" + this.lang[i].language + "\" />";
				} else {
					s += "<a href=\"javascript:" + this.funct +
						"('" + this.lang[i].option + "');\">"  +
						"<img src=\"" + this.dir +
						"/" + this.lang[i].icon.visible +
						"\" alt=\"" + this.lang[i].language + "\" /></a>";
				}
			}
		}
		$( this.div ).innerHTML = s;
	},
};


/**********************************************************\
* oggetto pagine da opzioni                                *
\**********************************************************/
var tovPageOption = Class.create();
tovPageOption.prototype = {
	dim : new tovDimPage(), // restituisce dim. finestra
	//
	// INIZIALIZZO
	//
	initialize : function( div_win, div_bg, div_close, div_txt, w )
	{
		this.div = {
			win : div_win, // sfondo semitrasparente
			background : div_bg, // sfondo pagina
			close : div_close, // pulsante di chiusura
			page : [ div_txt ] // dove scrivere
		};
		this.actual_page = 0; // pagina attuale
		this.width = w; // larghezza div pagina
	},
	//
	// AGGIUNGE UN DIV PAGINA
	//
	addPage : function( div )
	{
		var l = this.lengthPages();
		this.div.page[ l ] = div;
	},
	//
	// CENTRA DIV PAGINA
	//
	centerDiv : function()
	{
		var d = this.dim.getVisiblePageSize();
		var x = ( d.width - this.width ) /2;
		$( this.div.background ).style.left = x + "px";
	},
	//
	// CAMBIA ID DIV PAGINA
	//
	changeIdPage : function( num, div ) { this.div.page[ num ] = div; },
	//
	// PULISCO PAGINE
	//
	clear : function( n_page )
	{
/*		if( n_page == "" )
		{
			var num_voice = this.div.page.length;
			for( i=0; i<num_voice; i++ )
			{
				$( this.div.page[ i ] ).innerHTML = "";
			}
		} else {
			$( this.div.page[ n_page ] ).innerHTML = "";
		}
*/	},
	//
	// ALLARGA SFONDO
	//
	extendBackground : function()
	{
		var d = this.dim.getPageSize();
		$( this.div.win ).style.width = d.width + "px";
		$( this.div.win ).style.height = d.height + "px";
	},
	//
	// RESTITUISCE INDICE PAGINA ATTUALE
	//
	getActualPage : function() { return this.actual_page; },
	//
	// RESTITUISCE ID PAGINA ATTUALE
	//
	getIdActualPage : function() { return this.getIdPage( this.getActualPage() ); },
	//
	// RESTITUISCE ID PAGINA
	//
	getIdPage : function( n ) { return this.div.page[ n ]; },
	//
	// RESTITUISCE NUMERO DIV PAGINA
	//
	lengthPages : function() { return this.div.page.length; },
	//
	// NASCONDI TUTTO
	//
	hide : function()
	{
		new Effect.Fade( this.div.win );
		new Effect.Fade( this.div.background );
		for( var i=0; i<this.lengthPages(); i++ )
		{
			new Effect.Fade( this.div.page[ i ] );
		}
	},
	//
	// STAMPO PULSANTE DI CHIUSURA
	//
	printClose : function( menu, opzione )
	{
		var s = "<a href=\"javascript:obj_data_page.closePageOption('" +
				menu + "','" + opzione +
				"');\"><img src=\"image/dialog-error.png\" alt=\"close\" /></a>";
		$( this.div.close ).innerHTML = s;
	},
	//
	// STAMPO STRINGA HTML IN PAGINA
	//
	printHTML : function( stringa )
	{

		$( this.getIdActualPage() ).innerHTML = stringa;
		this.show();
	},
	//
	// IMPOSTA PAGINA ATTUALE
	//
	setActualPage : function( n ) { this.actual_page = n; },
	//
	// VISUALIZZA TUTTO
	//
	show : function()
	{
		this.extendBackground();
		this.centerDiv();
		new Effect.Appear( this.div.win );
		new Effect.Appear( this.div.background );
		for( var i=0; i<this.lengthPages(); i++ )
		{
			new Effect.Appear( this.getIdPage( i ) );
		}
	}
};

/**********************************************************\
* oggetto pagine da opzioni Minimale                       *
\**********************************************************/
var tovPageOptionMinimal = Class.create();
tovPageOptionMinimal.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( div_txt )
	{
		this.page = [ div_txt ]; // dove scrivere
		this.actual_page = 0; // pagina attuale
	},
	//
	// AGGIUNGE UN DIV PAGINA
	//
	addPage : function( div )
	{
		var l = this.lengthPages();
		this.page[ l ] = div;
		return l;
	},
	//
	// CAMBIA ID DEL DIV PAGINA
	//
	changeIdPage : function( num, div ) { this.page[ num ] = div; },
	//
	// PULISCO PAGINE
	//
	clear : function( n_page )
	{
		var div;
		if( n_page == "" )
		{
			var num_voice = this.lengthPages();
			for( i=0; i<num_voice; i++ )
			{
				div = this.getIdPage( i );
				if( $( div ) != null )
				{
					$( div ).innerHTML = "";
				}
			}
		} else {
			div = this.getIdPage( n_page );
			if( $( div ) != null )
			{
				$( div ).innerHTML = "";
			}
		}
	},
	//
	// CANCELLA DIVS DALL'ARRY ECCETTO IL PRIMO
	//
	clearDivs : function()
	{
		var div = this.getIdPage( 0 );
		this.page.clear();
		this.addPage( div );
	},
	//
	// RESTITUISCE INDICE PAGINA ATTUALE
	//
	getActualPage : function() { return this.actual_page; },
	//
	// RESTITUISCE ID PAGINA ATTUALE
	//
	getIdActualPage : function() { return this.getIdPage( this.getActualPage() ); },
	//
	// RESTITUISCE ID PAGINA
	//
	getIdPage : function( n ) { return this.page[ n ]; },
	//
	// RESTITUISCE NUMERO PAGINA CON ID
	//
	getNumDiv : function( id )
	{
		var c = null;
		for( var i in this.page )
		{
			if( this.page[i] == id ) { c = i; }
		}
		return c;
	 },
	//
	// RESTITUISCE NUMERO DIV PAGINA
	//
	lengthPages : function() { return this.page.length; },
	//
	// NASCONDI TUTTO
	//
	hide : function() {},
	//
	// STAMPO STRINGA HTML IN PAGINA
	//
	printHTML : function( stringa ) { $( this.getIdActualPage() ).innerHTML = stringa; },
	//
	// IMPOSTA PAGINA ATTUALE
	//
	setActualPage : function( n ) { this.actual_page = n; },
	//
	// VISUALIZZA TUTTO
	//
	show : function() {}
};

/**********************************************************\
* oggetto gestisce chiamate ajax                           *
\**********************************************************/
var tovAjax = Class.create();
tovAjax.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( file_ajax, mysql, language, param_ajax )
	{
		// percorso + file ajax
		if( typeof( file_ajax ) != "undefined" )
		{
			this.file = file_ajax;
		} else {
			this.file = "";
		}
		// tabella mysql
		if( typeof( mysql ) != "undefined" )
		{
			this.mysql = mysql;
		} else {
			this.mysql = "";
		}
		// lingua
		if( typeof( language ) != "undefined" )
		{
			this.language = language;
		} else {
			this.language = "";
		}
		// parametri ajax standard
		if( typeof( param_ajax ) != "undefined" )
		{
			this.param = param_ajax;
		} else {
			this.param = "";
		}
	},
	//
	// ESEGUE CHIAMATA AJAX
	//
	exec : function( tipo, div, str, funct )
	{
		var stringa = this.getInit( str );
		switch( tipo )
		{
		case 'updater':
			var mAjax = new Ajax.Updater(
				div,
				this.getFile(),
				{
					method: 'post',
					parameters: stringa
				}
			);
			break;
		case 'request':
			var myAjax = new Ajax.Request(
				this.getFile(),
				{
					method: 'post',
					parameters: stringa,
					onComplete: funct
				}
			);
			break;
		default:
		}
		return mAjax;
	},
	//
	// RESTITUISCE NOME FILE AJAX CON PERCORSO
	//
	getFile : function()
	{
		return this.file;
	},
	//
	// RESTITUISCE STRINGA PARAMETRI INIZIALI
	// PER AJAX
	//
	getInit : function( s )
	{
		var stringa = "";
		if( this.param != "" )
		{
			stringa += "&" + this.param;
		}
		if( this.language != "" )
		{
			stringa += "&language=" + this.language;
		}
		if( this.mysql != "" )
		{
			stringa += "&mysql_table=" + this.mysql;
		}
		if( ( s != null ) && ( s != "" ) )
		{
			stringa += "&" + s;
		}
		return stringa;
	},
	//
	// RESTITUISCE DATI JSON DA CHIAMATA AJAX
	//
	returnJSON : function ( originalResponse )
	{
		var r = "";
		if( originalResponse.responseText != "" )
		{
			r = originalResponse.responseText.evalJSON();
		}
		return r;
	},
	//
	// IMPOSTO FILE AJAX
	//
	setFile : function( file )
	{
		this.file = file;
	},
	//
	// IMPOSTA LINGUA
	//
	setLanguage : function( l )
	{
		this.language = l;
	},
	//
	// IMPOSTO PARAMETRI AJAX
	//
	setParam : function( param )
	{
		this.param = param;
	},
	//
	// IMPOSTO TABELLA MYSQL
	//
	setMysql : function( tabella )
	{
		this.mysql = tabella;
	}
};

/**********************************************************\
* oggetto contatore accessi web                            *
\**********************************************************/
var tovCounterWeb = Class.create();
tovCounterWeb.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( ajax, t_web, t_services )
	{
		if( typeof( ajax ) == "undefined" )
		{
			this.file_ajax = "ajax_php/counter_web.php";
		} else {
			this.file_ajax = ajax;
		}
		if( typeof( mysql_web ) == "undefined" )
		{
			this.mysql_web = "counter_web";
		} else {
			this.mysql_web = t_web;
		}
		if( typeof( mysql_services ) == "undefined" )
		{
			this.mysql_services = "counter_services";
		} else {
			this.mysql_services = t_services;
		}
		mysql_web = this.mysql_web + "&mysql_services=" + this.mysql_services;
		this.ajax = new tovAjax( this.file_ajax, mysql_web );
	},
	//
	// AGGIUNGO ACCESSO WEB O SERVIZIO
	//
	addCount: function( tipo, chiamata )
	{
		var stringa =	"type=" + tipo +
				"&page=" + encodeURIComponent( self.location.href );
		if( tipo == 'services' )
		{
			stringa += "&ajax_funct=" + encodeURIComponent( chiamata );
		}
		this.ajax.exec( "request", "", stringa, null );
	}
};


/**********************************************************\
* oggetto leggo var di configurazione generale d mysql     *
\**********************************************************/
var tovConfig = Class.create();
tovConfig.prototype = {
	//
	// INIZIALIZZO
	//
	initialize : function( ajax, table, funct )
	{
		this.ajax = new tovAjax( ajax, table ),
		this.ajax.exec( 'request', '', '', funct );
	},
	//
	// RESTITUISCE JSON AJAX
	//
	read : function( o )
	{
		return this.ajax.returnJSON( o );
	}
};

/**********************************************************\
* oggetto opzioni dei menu'                                *
\**********************************************************/
var tovOptionMenu = Class.create();
tovOptionMenu.prototype = {
	icon : "", // per gestire le icone
	id_form : "form_email", // id form
	loading : new tovLoadingPage(), // gestore immagine loading
	//
	// INIZIALIZZO
	//
	initialize : function( menu, name, title, funct, page )
	{
		this.menu = menu;
		this.name = name; // nome opzione
		this.title = title; // titolo opzione
		this.run = funct; // funzione quando si sceglie l'opzione
		this.page = new tovPageOptionMinimal( page.text );
		this.ajax = new tovAjax(); // gestisce chiamate ajax
		this.title_page = new tovTitlePage( 'titolo', title ); // imposta pagina da scrivere
	},
	//
	// AGGIUNGE DIV PAGINA
	//
	addPage : function( div )
	{
		var n = this.page.addPage( div );
		return n;
	},
	//
	// CAMBIO ID DIV PAGINA
	//
	changeIdPage : function( num, div ) { this.page.changeIdPage( num, div ); },
	//
	// CANCELLO TUTTI I DIVS ECCETTO IL PRINCIPALE
	//
	clearDivs : function() { this.page.clearDivs(); },
	//
	// PULISCO PAGINE
	//
	clearPage : function( page ) { this.page.clear( page ); },
	//
	// SCELTA OPZIONE MENU' PRINCIPALE
	//
	clickOption : function()
	{
		this.clearPage("");
		this.run( this.menu, this.name );
	},
	//
	// ESEGUE CHIAMATA AJAX
	//
	execAjax : function( tipo, str, funct )
	{
		var	div = this.page.getIdActualPage(),
			stringa = "menu=" + this.menu + "&option=" + this.name,
			r;
		if( typeof( str ) != "undefined" )
		{
			stringa += "&" + str;
		}
		this.loading.setDiv( div );
		this.loading.print();
		this.page.show();
		switch( tipo )
		{
			case 'updater': r = this.ajax.exec( tipo, div, stringa ); break;
			case 'request': r = this.ajax.exec( tipo, div, stringa, funct ); break;
			default:
		}
		return r;
	},
	//
	// RESTITUISCO DATI X CHIAMTE AJAX
	//
	getAjaxData : function()
	{
		return {
			"file" : this.ajax.getFile(),
			"mysql" : this.ajax.mysql,
			"param" : this.ajax.getInit() };
	},
	//
	// RESTITUISCE DATI OPZIONI
	//
	getDataOption : function()
	{
		return {	icon : this.getIcon(),
				menu : this.menu,
				name : this.name,
				title : this.title };
	},
	//
	// RESTITUISCO ICONA E PARAMETRI
	//
	getIcon : function()
	{
		if( typeof( this.icon.get ) == "undefined" )
		{
			var r = this.icon;
		} else {
			var r = this.icon.get();
		}
		return r;
	 },
	//
	// RESTITUISCE ID DIV PAGINA
	//
	getIdPage : function( num ) { return this.page.getIdPage( num ); },
	//
	// RESTITUISCE NUMERO PAGINA CON ID
	//
	getNumPage : function( id ) { return this.page.getNumDiv( id ); },
	//
	// RESTITUISCE TITOLO
	//
	getTitle : function() { return this.title; },
	//
	// NASCONDO PAGINA OPZIONE
	//
	hidePage : function() { this.page.hide(); },
	//
	// STAMPO PULSANTE DI CHIUSURA
	//
	printClosePage : function() { this.page.printClose( this.menu, this.name ); },
	//
	// STAMPO LOADING
	//
	printLoading : function( str )
	{
/*		if( typeof( str ) != "undefined" )
		{
			this.loading.setMessage( str );
		}
		var pagina = this.page.getIdActualPage();
		this.loading.setDiv( pagina );
		this.loading.print();
		this.page.show();
*/	},
	//
	// STAMPO STRINGA HTML IN PAGINA
	//
	printPageHTML : function( stringa ) { this.page.printHTML( stringa ); },
	//
	// STAMPA TITOLO PAGINA
	//
	printTitlePage : function () { this.title_page.print(); },
	//
	// LEGGE CONTENUTI DI UN FORM
	//
	readForm : function( )
	{
		// legge lista input
		var form = $( this.id_form );
		var lista = form.getElements();
		var stringa = "";
		var valore = "";
		lista.each( function( s, key )
			{
				if( $F(s.id) != null )
				{
					valore = $F( s.id );
				} else {
					valore = "-1";
				}
				stringa += "&" + s.id + "=" + encodeURIComponent( valore );
			}
		);
		return stringa;
	},
	//
	// IMPOSTA DIV PAGINA ATTUALE
	//
	setActualPage : function( n )
	{
		this.page.setActualPage( n );
	},
	//
	// IMPOSTO FILE AJAX E PARAMETRI
	//
	setAjax : function( file, language, param )
	{
		this.ajax.setFile( file );
		if( typeof( language ) != "undefined" )
		{
			this.ajax.setLanguage( language );
		}
		if( typeof( param ) != "undefined" )
		{
			this.ajax.setParam( param );
		}
	},
	//
	// IMPOSTA ICONA OPZIONE
	//
	setIcon : function( image, parametri )
	{
		parametri.image = image;
		this.icon = new tovIcons( parametri );
	},
	//
	// IMPOSTA ID DIV FORM
	//
	setIdForm : function( id ) { this.id_form = id; },
	//
	// IMPOSTO LINGUA
	//
	setLanguage : function( language ) { this.ajax.setLanguage( language ); },
	//
	// IMPOSTO DATI LOADING
	//
	setLoading : function( message, image )
	{
		if( ( typeof( message ) != "undefined" )  && ( message != "" ) )
		{
			this.loading.setMessage( message );
		}
		if( ( typeof( image ) != "undefined" )  && ( image != "" ) )
		{
			this.loading.setImage( image );
		}
	},
/*	//
	// VISUALIZZO PAGINA OPZIONE
	//
	showPage : function()
	{
		this.page.show();
	},
	//
	// IMPOSTO TABELLA MYSQL
	//
*/	setMysql : function( tabella )
	{
		this.ajax.setMysql( tabella );
	},
	//
	// IMPOSTO DATI TITOLO PAGINA DA SCRIVERE
	//
	setTitlePage : function( div, titolo, image ) { this.title_page.set( div, titolo, image ); }
};


/**********************************************************\
* oggetto gestione menu'                                   *
\**********************************************************/
var tovMenu = Class.create( {
	actual_option : "", //opzione attuale
	param_icons : "", // parametri icone
	//
	// INIZIALIZZO
	//
	initialize : function( nome, div )
	{
		this.name = nome;
		this.div = div;
	},
	//
	// RESTITUISCE DATI MENU'
	//
	getDataOptions : function( opzioni )
	{
		var dati = [], i = 0;
		for( var nome in opzioni )
		{
			if( typeof( opzioni[ nome ].getDataOption ) != "undefined" )
			{
				dati[ i ] = opzioni[ nome ].getDataOption();
				i++;
			}
		}
		return dati;
	},
	//
	// RESTITUISCO PARAMETRI ICONE
	//
	getParamIcons : function() { return this.param_icons; },
	//
	// GESTISCE MOUSE SU ICONA OPZIONE
	//
	onMouse : function ( icona, stato )
	{
		var p = this.getParamIcons();
		if( stato == 'over' )
		{
			icona.style.width = p.max.width;
			icona.style.height = p.max.height;
		} else {
			icona.style.width = p.min.width;
			icona.style.height = p.min.height;
		}
	},
	//
	// SCRIVO MENU'
	//
	print : function( opzioni )
	{
		var	dati = this.getDataOptions( opzioni ),
			stringa = "<ul>";
		for( i = 0; i < dati.length; i++ )
		{
			if( typeof( dati[ i ].menu != "undefined" ) )
			{
				stringa += "<li><a href=\"#\" onClick=\"obj_data_page.clickMouseOption('" +
						dati[ i ].menu + "','" +
						dati[ i ].name + "');\">" +
						dati[ i ].title +
						"</a></li>";
			}
		}
		stringa += "</ul>";
		$( this.div.menu ).innerHTML = stringa;
	},
	//
	// IMPOSTO PARAMETRI PER ICONE
	//
	setParamIcons : function( dir_icon, obj_max, obj_min )
	{
		this.param_icons = { dir : dir_icon, max : obj_max, min : obj_min };
	},
	//
	// IMPOSTO LINGUA
	//
	setLanguage : function( opzione, language )
	{
		if( typeof( language ) == "undefined" )
		{
			this.language = opzione;
		} else {
			this.list[ opzione ].setLanguage( language );
		}
	}
} );


/**********************************************************\
* oggetto che si occupa delle gestione delle pagine        *
\**********************************************************/
var tovDataPage = Class.create();
tovDataPage.prototype = {
	general_ajax : new tovAjax(), // ajax x chiamate generali
	language : "", // lingua pagine
	menu : [], // oggetti menu'
	options : [], // lista opzioni x menu'
	//
	// INIZIALIZZO
	//
	initialize : function( ajax_dir, std_page )
	{
		// dir ajax
		if( typeof( ajax_dir ) == "undefined" )
		{
			this.ajax_dir = "ajax_php/";
		} else {
			this.ajax_dir = ajax_dir;
		}
		// dati pagina
		if( typeof( std_page ) == "undefined" )
		{
			this.page = {
				text : "option_page" // div per scrivere
				};
		} else {
			this.page = std_page;
		}
	},
	//
	// AGGIUNGO ACCESSO WEB O SERVIZIO
	//
	addAccess : function( ajax )
	{
		if( typeof( this.counter_web ) != "undefined" )
		{
			// controlla se è chiamata ajax
			if( typeof( ajax ) == "undefined" )
			{
				this.counter_web.addCount( 'web' );
			} else {
				this.counter_web.addCount( 'services', ajax );
			}
		} else {
			alert( "Contatore non attivo !" );
		}
	},
	//
	// AGGIUNGO DIV PAGINA
	//
	addDivPage : function( menu, opzione, div )
	{
		var n = this.options[menu][opzione].addPage( div );
		return  n;
	},
	//
	// AGGIUNGI VOCE DI MENU'
	//
	addOption : function( menu, nome, titolo, funzione, ajax )
	{
		this.options[ menu ][ nome ] = new tovOptionMenu( menu, nome, titolo, funzione, this.page );
		// linguaggio
		var l = "";
		if( typeof( this.language ) != "undefined" )
		{
			l = this.language;
			this.options[ menu ][ nome ].setLanguage( l );
		}
		// file ajax e parametri
		if( typeof( ajax ) != "undefined" )
		{
			var a = this.ajax_dir + ajax.file;
			var param = "";
			// altri parametri
			if( typeof( ajax.param ) != "undefined" )
			{
				param += ajax.param;
			}
			this.options[ menu ][ nome ].setAjax( a, l, param );
			// tabella mysql
			if( typeof( ajax.mysql ) != "undefined" )
			{
				this.setMysql( menu, nome, ajax.mysql );
			}
		}
	},
	//
	// CHIAMATA AJAX JSON GENERALI
	//
	ajaxJSON : function( ajax, mysql, funct, param )
	{
		var g = new tovAjax(); // ajax x chiamate generali
		// parametri
		if( ( typeof( param ) == "undefined" ) )
		{
			var param = "";
		}
		g.setFile( this.ajax_dir + ajax );
		g.setMysql( mysql );
		g.exec( 'request', '', param, funct );
	},
	//
	// EFFETTO APPERAR A DIV
	//
	appearDiv : function( div )
	{
		var effetto = $( div );
		new Effect.Appear( effetto );
	},
	//
	// CAMBIO ID DIV PAGINA
	//
	changeIdDivPage : function( menu, opzione, num, div )
	{
		this.options[ menu ][ opzione ].changeIdPage( num, div );
	},
	//
	// PULISCE TUTTE LE PAGINE
	//
	clearAllPage : function( menu )
	{
		for( var i in this.options[ menu ] )
		{
			if( typeof( this.options[ menu ][ i ].clearPage ) != "undefined" )
			{
				this.options[ menu ][ i ].clearPage("");
			}
		}
	},
	//
	// CANCELLA TUTTI I DIV LASCIANDO SOLO QUELLO PRINCIPALE
	//
	clearDivPages : function( menu, opzione ) { this.options[ menu ][opzione].clearDivs(); },
	//
	// PULISCO PAGINA
	//
	clearPage : function( menu, opzione, page )
	{
		if( ( typeof( page ) == "undefined" ) )
		{
			var page = "";
		}
		this.options[ menu ][ opzione ].clearPage(page);
	},
	//
	// OPZIONE SCELTA
	//
	clickMouseOption : function( menu, opzione )
	{
		this.menu[ menu ].actual_option = opzione;
		this.options[ menu ][ opzione ].clickOption();
	},
	//
	// NASCONDE PAGINA IN VISTA
	//
	closePageOption : function( menu, opzione ) { this.options[menu][opzione].hidePage(); },
	//
	// EFFETTO FADE A DIV
	//
	fadeDiv :function( div )
	{
		var d = $( div );
		new Effect.Fade( d );
	},
	//
	// CONVERTE CARATTERI SPECIALI
	//
	htmlEntityDecode : function( str )
	{
		str = unescape( str);
		str = str.replace( /</g, "&lt;" );
		str = str.replace( />/g, "&gt;" );
		str = str.replace( /&lt;br\/\&gt;/g, "<br />" );
		str = str.replace( /\&lt;br \/\&gt;/g, "<br />" );
		return str;
	},
	//
	// RESTITUISCO DATI X CHIAMTE AJAX
	//
	getAjaxDataOption : function( menu, opzione )
	{
		// oggetto con file, mysql e param
		var d = this.options[ menu ][ opzione ].getAjaxData();
		var p = d.file.lastIndexOf( "/" ) + 1;
		d.file = d.file.substr( p );
		return d;
	},
	//
	// RESTITUISCO PARAMETRI ICONA
	//
	getIconOption : function( menu, opzione ) { return this.options[menu][opzione].getIcon(); },
	//
	// RESTITUISCO ID PAGINA
	//
	getIdDivPage : function (menu, opzione, n) { return this.options[menu][opzione].getIdPage(n); },
	//
	// RESTITUISCO ID PAGINA
	//
	getNumDivPage : function (menu, opzione, d) { return this.options[menu][opzione].getNumPage(d); },
	//
	// RESTITUISCE LINGUA PAGINE
	//
	getLanguage : function() { return this.language; },
	//
	// RESTITUISCE TITOTLO OPZIONE
	//
	getTitleOption : function( menu, opzione ) { return this.options[menu][opzione].getTitle(); },
	//
	// CREA NUOVO MEU'
	//
	newMenu : function( nome, div )
	{
		this.menu[ nome ] = new tovMenu( nome, div );
		this.options[ nome ] = [];
	},
	//
	// GESTISCE MOUSE SU ICONA OPZIONE
	//
	onMouse : function ( icona, stato, menu ) { this.menu[menu].onMouse( icona, stato ); },
	//
	// CARICO E SCRIVO PAGINA AJAX HTML
	//
	printAjaxHTML : function(menu, opzione, s)
	{
		return this.options[menu][opzione].execAjax('updater', s);
	},
	//
	// SCRIVO PULSANTE DI CHIUSURA
	//
	printClosePage : function( menu, opzione ) { this.options[menu][opzione].printClosePage(); },
	//
	// SCRIVO DIRETTAMENTE SU DIV OPZIONE
	//
	printDivPage : function( menu, opzione, stringa )
	{
		this.options[menu][opzione].printPageHTML( stringa );
	},
	//
	// SCRIVO MENU'
	//
	printMenu : function( nome ) { this.menu[ nome ].print( this.options[ nome ] ); },
	//
	// STAMPA TITOLO PAGINA
	//
	printTitlePage : function (menu, opzione) { this.options[menu][opzione].printTitlePage(); },
	//
	// CARICO E SCRIVO PAGINA AJAX HTML
	//
	requestAjax : function( menu, opzione, s, funct )
	{
		return this.options[menu][opzione].execAjax( 'request', s, funct );
	},
	//
	// RESTITUISCE OGGETTO DA CHIAMTA AJAX JSON
	//
	returnJSON : function( originalResponse )
	{
		return this.general_ajax.returnJSON( originalResponse );
	},
	//
	// SCEGLIE DIV SU CUI SCRIVERE
	//
	selectPage : function( menu, opzione, n ) { this.options[menu][opzione].setActualPage( n ); },
	//
	// SPEDISCO O SCRIVO EMAIL
	//
	sendMail : function( menu, opzione, tipo )
	{
		switch( tipo )
		{
			case 'form':
				this.printAjaxHTML( menu, opzione, "type_data=" + tipo );
				break;
			case 'send':
				var stringa = this.options[menu][opzione].readForm();
				this.printAjaxHTML( menu, opzione, "type_data=" + tipo + "&" + stringa );
				break;
			default:
		}
	},
	//
	// CREO OGGETTO CONFIG
	//
	setConfig : function( ajax, table_mysql, funct )
	{
		this.config = new tovConfig( this.ajax_dir + ajax, table_mysql, funct );
	},
	//
	// CREO OGGETTO CONTATORE ACCESSI
	//
	setCounterWeb : function( ajax, mysql_web, mysql_services )
	{
		this.counter_web = new tovCounterWeb( this.ajax_dir + ajax, mysql_web, mysql_services );
	},
	//
	// IMPOSTO PARAMETRI ICONE
	//
	setIcons : function( menu, dir, max, min ) { this.menu[menu].setParamIcons( dir, max, min ); },
	//
	// IMPOSTO LINGUA PAGINE
	//
	setLanguage : function( l )
	{
		this.language = l;
		this.general_ajax.setLanguage( l );
	},
	//
	// IMPOSTO DATI LOADING
	//
	setLoading : function( menu, opzione, message, image )
	{
		if( ( typeof( image ) == "undefined" ) )
		{
			var image = "";
		}
		if( ( typeof( message ) == "undefined" ) )
		{
			var message = "";
		}
		this.options[ menu ][ opzione ].setLoading( message, image );
	},
	//
	// IMPOSTO TABELLA MYSQL
	//
	setMysql : function(menu, opzione, tabella) { this.options[menu][opzione].setMysql( tabella ); },
	//
	// IMPOSTO ICONA PER OPZIONE
	//
	setIconOption : function( menu, opzione, image )
	{
		var p = this.menu[menu].getParamIcons();
		this.options[menu][opzione].setIcon( image, p );
	},
	//
	// IMPOSTO DATI TITOLO PAGINA DA SCRIVERE
	//
	setTitlePage : function( menu, option, div, titolo, image )
	{
		if( typeof( image ) == "undefined" ) { image = ""; }
		this.options[menu][option].setTitlePage( div, titolo, image );
	},
	//
	// EFFETTO SLIDE A DIV
	//
	slideDiv : function( div )
	{
		var display = $(div).style.display;
		if( display == "none" )
		{
			new Effect.SlideDown( $( div ) );
		} else {
			new Effect.SlideUp( $( div ) );
		}
	}
};

// creo oggetto
var obj_data_page = new tovDataPage();

// funzione da chiamare quando è finito caricamento pagina
var endLoadingPage = function() {};

// per eseguire altre funzioni e/o impostare altre variabili
var otherJavascript = function() {};
