Common={
	// lingua
	lang: function(){
		var href = location.pathname;
		var cut = href.split('/');
		switch(location.host){
			default: var lingua = cut[1]; break; // online
			case 'xxx': var lingua = cut[3]; break; // locale
			case 'lavorazioni.addviser.net': var lingua = cut[2]; break; // lavorazioni
		}
		return lingua;
	},

	
	// nome dominio
	myhost: function(){
		var href = location.pathname;
		var cut = href.split('/');
		switch(location.host){
			default: var path = location.protocol+'//'+location.host+'/'; break; // online
			case 'xxx': var path = location.protocol+'//'+location.host+'/'+cut[1]+'/sito/'; break; // locale
			case 'lavorazioni.addviser.net': var path = location.protocol+'//'+location.host+'/'+cut[1]+'/'; break; // lavorazioni
		}
		return path;
	},

	
	// tutti gli elementi del form
	els:null,
	nomeForm:null,
	fields:new Object,
	fieldsID:new Object,
	elements:function(nomeForm){
		allForm = nomeForm.split('||');
		for (a=0, z=allForm.length; a<z; a++){
			if($(allForm[a])){
				Common.els=Form.getElements($(allForm[a]));
				for (i=0, l=Common.els.length; i<l; i++){
					Common.fields[Common.els[i].name] = $F(Common.els[i]); // valore campo
					Common.fieldsID[Common.els[i].name] = Common.els[i].id; // solo il nome del id
				}
			}
		}
	},


	// popup errore - apertura
	error:function(messaggio,elemento){
		
		/* nascondo i select */
		var selects = document.getElementsByTagName("select"); 
		for (var i = 0; i < selects.length; i++) { 
			selects[i].style.visibility='hidden';
		}

		/* scrivo i div contenitori */
		var objBody = $$('body')[0];
		objBody.appendChild(Builder.node('div',{id:'error'}));
        objBody.appendChild(Builder.node('div',{id:'err_msg'}));
		err = $('error');
		msg = $('err_msg');
		err.style.display='none';
		msg.style.display='none';

		/* calcolo altezza complessiva della finestra */
		bodyWidth = $$('body')[0].getWidth();
		viewWidth = self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
		bodyHeight = $$('body')[0].getHeight();
		viewHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
		
		/* assegno altezza e larghezza */
		err.style.width =  bodyWidth > viewWidth  ?  bodyWidth+'px' : viewWidth+'px';
		err.style.height = bodyHeight > viewHeight  ?  bodyHeight+'px' : viewHeight+'px';
		msg.style.marginTop = ((bodyHeight > viewHeight  ?  bodyHeight : viewHeight)/2)-75+'px';

		/* scrivo l'errore */
		msg.innerHTML = '<div id="close_btn" onclick="Common.close(\''+elemento+'\');"></div><div class="cleaner"></div>'+messaggio+'<br/><br/><br/>';
		new Effect.Appear(err, {to:0.8, from:0.0, duration:0.3, afterFinish:function(){
				new Effect.Appear(msg, {to:1.0, from:0.0, duration:0.3});
			}
		});
	},

	

	// popup errore - chiusura
	close:function(elemento){
		err = $('error');
		msg = $('err_msg');
		new Effect.Opacity(msg, {to:0.0, from:1.0, duration:0.3, afterFinish:function(){
				new Effect.Appear(err, {to:0.0, from:1.0, duration:0.3, afterFinish:function(){
					err.remove();
					msg.remove();
					/* riappaiono i select */
					var selects = document.getElementsByTagName("select"); 
					for (var i = 0; i < selects.length; i++) { 
						selects[i].style.visibility='visible';
					}
					$(elemento).focus();
				}});	
			}
		});
	},
	
	change_lang: function()
	{
		if ($('select_change_lang'))
		{
			Event.observe(
				$('select_change_lang'), 
				'change', 
				function() 
				{
					var lang = $F('select_change_lang');
					var page = $F('page-menu-'+lang);
					location.href = Common.myhost()+lang+'/'+page+'/';
				}
			);
		}
	}


}

// function to initialize a function on page loading
var page_loading = 
{
	initialize: function()
	{
		Common.change_lang();
	}
}

if (window.addEventListener) window.addEventListener('load', page_loading.initialize, false);
else window.attachEvent('onload', page_loading.initialize);