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();
				}});	
			}
		});
	}
},

Menu={
	menuDown:function(id){
		x=$(id).style.display;
		if(x=='none')
			new Effect.BlindDown(id, {duration:0.5});
		else
			new Effect.BlindUp(id, {duration:0.5});
	},
	rollover:function(div_id, div_class){
		$(div_id).className=div_class;
	},
	rollout:function(div_id, div_class){
		$(div_id).className=div_class;
	},
	
	
	
	
	btns:function(div_class){
		cl=document.getElementsByClassName(div_class);
		var clickEvent = Menu.btnClick.bindAsEventListener();
		for (i=0, l=cl.length; i<l; i++){
			Event.observe (cl[i], 'click', clickEvent);
		}
	},
	
	btnClick: function(event){
		var target = event.currentTarget || event.srcElement;
		if (target.tagName == 'SPAN')
			var el = $(target).up().next();
		else
			var el = $(target).next();
		if (el){
			var d = el.style.display;
			if (d == 'none')
				new Effect.BlindDown(el, {duration:0.3});
			else
				new Effect.BlindUp(el, {duration:0.3});
		}
	}
}

Event.observe(window, 'load', function(){
	Menu.btns('btn');
	
	// faq
	Event.observe('faq', 'click', function(){Menu.menuDown('menufaq');});
	Event.observe('faq', 'mouseover', function(){Menu.rollover('faq','faq_roll');});
	Event.observe('faq', 'mouseout', function(){Menu.rollout('faq','faq');});
	
	// utilità 
	Event.observe('utilita', 'click', function(){Menu.menuDown('ut_menu');});
	Event.observe('utilita', 'mouseover', function(){Menu.rollover('utilita','utilita_roll');});
	Event.observe('utilita', 'mouseout', function(){Menu.rollout('utilita','utilita');});
});



