function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Non è stato possibile impostare un gestore di eventi");
  }
}
addEvent(window,'load',init,false);
//addEvent(window,'load',mngBoxHeight,false);
clicked=null;

function init(){
el=$('socialnet');	
var mostra = new fx.Scroll({duration: 500});
var nascondi = new fx.Scroll({duration: 500, onComplete: function()
  {el.style.display="none";}
});
if ($('socialnet')){
		addRSS.init();	
		$('btn-sn').onclick=function(){
			if (clicked) return false;
			mngSN(el,mostra,null);
			$('btn-godomino-sn').style.display="block";
			mngBoxHeight();
			mngBoxH_SN();
			};
	if ($('btn-gotosn')){
	$('btn-gotosn').onclick=function(){
			if (clicked) return false;
			mngSN(el,mostra,null);
			$('btn-godomino-sn').style.display="block";
			mngBoxHeight();
			mngBoxH_SN();
			};
		}
	}
		
if ($('socialnet')){
		$('btn-godomino-sn').onclick=function(){
			if (!clicked) return false;
			mngSN(el,null,nascondi);
			$('btn-godomino-sn').style.display="none";
			};
		}		
if ($('btn-readnewshp')){
	$('btn-readnewshp').onclick=function(){
		mnsFirstFooter();
		return false;
		}
	}
}	
	

function initializeDomanda(){
	box = document.getElementsByClassName("domanda")
	for (var i = 0; i<box.length; i++){
		href = box[i].getElementsByTagName("A")
		for (var j = 0; j<href.length; j++){
			if (href[j].getAttribute("rel") == "dom"){
				href[j].onclick = function(){
					dom = (this.parentNode.id)
					ris = (this.parentNode.parentNode.childNodes[1].id)
					$(ris).style.display = "block"
					$(dom).style.display = "none"
					return false;
				}
			}
		}
	}
}
function initializeRisposta(){
	box = document.getElementsByClassName("risposta")
	for (var i = 0; i<box.length; i++){
		href = box[i].getElementsByTagName("A")
		for (var j = 0; j<href.length; j++){
			if (href[j].getAttribute("rel") == "ris"){
				href[j].onclick = function(){
					ris = (this.parentNode.id)
					dom = (this.parentNode.parentNode.childNodes[0].id)
					$(ris).style.display = "none"
					$(dom).style.display = "block"
					return false;
				}
			}
		}
	}
}


function mngSN(el,mostra,nascondi){
	sn=$('socialnet');
	topHp=$('hp');
	if ((sn.style.display==''||sn.style.display=='none')&&!clicked){
	sn.style.display="block";
	mostra.scrollTo(el);
	clicked=true;
		}
	else{
		nascondi.scrollTo(topHp);
		clicked=false;
		}
	return false;
	}

function mnsFirstFooter(){
var f1mostra = new fx.Scroll({duration: 500});
var f1nascondi = new fx.Scroll({duration: 500});
var vn=$('vetrina-news');
	f1mostra.scrollTo(vn);
	
	}	
	
function mngBoxHeight(){
	var hebsx=$('box-cosarss').offsetHeight;
	var hebdx=$('box-linkroll').offsetHeight;
	var highest=Math.max(hebsx,hebdx);
	$('box-cosarss').style.height=highest+"px";
	$('box-linkroll').style.height=highest+"px";
	}
function mngBoxH_SN(){
	var hwebSN=$('sn-web').offsetHeight;
	var humSN=$('sn-um').offsetHeight;
	var hitSN=$('sn-it').offsetHeight;
	var highest=Math.max(hwebSN,humSN,hitSN);
	$('sn-web').style.height=highest+"px";
	$('sn-um').style.height=highest+"px";
	$('sn-it').style.height=highest+"px";
	}	


var addRSS = {
	status : 'hidden',
	init : function(){
		svela = new fx.Opacity  ($('addsubscription') , {duration: 400});
		this.box = document.getElementById('addsubscription');
		var sn=document.getElementById('socialnet');
		var btns_webrss=getElementsByClass('webrss',sn,'a')
		for(i=0;i<btns_webrss.length;i++){
			btns_webrss[i].onmouseover=addRSS.display;
			}
		},	
	display : function(e){
		svela = new fx.Opacity  ($('addsubscription') , {duration: 400});
		addRSS.box.style.display="block";
		svela.setOpacity(0);
		addRSS.addUrl(this);
		var btnAddRss=this;
		if(addRSS.status=='hidden'){
			var posleft=findPosX(btnAddRss);
			var postop=findPosY(btnAddRss);
			var offset=35;
			svela.toggle();
			addRSS.box.style.left=(posleft-addRSS.box.offsetWidth+offset)+"px";
			addRSS.box.style.top=(postop-6)+"px";
			addRSS.status='visible';
			addEvent(addRSS.box,'mouseout',addRSS.hide,true);
			}
		else{
			addRSS.hide();
			}
		},
	hide : function(e){
		nascondi = new fx.Opacity  ($('addsubscription') , {duration: 400});
		if (e&&e.target){
				var posMouse=checkWhere(e)
					}
				if (window.event&&window.event.srcElement){
					var posMouse=checkWhere(window.event)
					}
				if (posMouse){
					nascondi.toggle();	
					addRSS.status='hidden';
					}
		},
	addUrl : function(el){
		var rssLinks=addRSS.box.getElementsByTagName('a');
		for(i=0;i<rssLinks.length;i++){
			rssLinks[i].id="rsslink-"+i;
			rssLinks[i].onclick=function(){
				oldHref=this.href;
				newHref=this.href+el.href;
				this.href=newHref;
				this.target="_blank";
				window.setTimeout("addRSS.restoreUrl('"+this.id+"','"+oldHref+"')",2000);
				}
			}
		},
	restoreUrl : function(theLink,oldHref){
		var linkRss=document.getElementById(theLink);
		linkRss.href=oldHref;
		}	
	};




/*
var addRSS = {
	status : 'hidden',
	onbox :   'out',
	timer : null,
	init : function(){
		svela = new fx.Opacity  ($('addsubscription') , {duration: 400});
		this.box = document.getElementById('addsubscription');
		var sn=document.getElementById('socialnet');
		var btns_webrss=getElementsByClass('webrss',sn,'a')
		for(i=0;i<btns_webrss.length;i++){
			btns_webrss[i].onmouseover=addRSS.display;
			}
		},	
	display : function(e){
		if (addRSS.status!='hidden'){
			addRSS.setOutStatus();
			}
		svela = new fx.Opacity  ($('addsubscription') , {duration: 400});
		addRSS.box.style.display="block";
		svela.setOpacity(0);
		addRSS.addUrl(this);
		var btnAddRss=this;
		if(addRSS.status=='hidden'){
			var posleft=findPosX(btnAddRss);
			var postop=findPosY(btnAddRss);
			var offset=35;
			svela.toggle();
			addRSS.box.style.left=(posleft-addRSS.box.offsetWidth+offset)+"px";
			addRSS.box.style.top=(postop-6)+"px";
			addRSS.status='visible';
			addEvent(addRSS.box,'mouseover',addRSS.setOverStatus,false);
			addEvent(addRSS.box,'mouseout',addRSS.setOutStatus,false);		
			}
			addRSS.timer=window.setTimeout("addRSS.hide()",2000);
		},
	hide : function(){
				if (addRSS.onbox=='out'){
					addRSS.box.style.display="none";
					addRSS.status='hidden';
					clearTimeout(addRSS.timer);
					}
		},
	setOverStatus :  function(){
		addRSS.onbox='over';
		},
	setOutStatus :  function(e){
				if (e&&e.target){
				var posMouse=checkWhere(e)
					}
				if (window.event&&window.event.srcElement){
					var posMouse=checkWhere(window.event)
					}
				if (posMouse){
					if (addRSS.timer){
						clearTimeout(addRSS.timer);
						}
				addRSS.onbox='out';
				addRSS.hide();
				}
		},	
	addUrl : function(el){
		var rssLinks=addRSS.box.getElementsByTagName('a');
		for(i=0;i<rssLinks.length;i++){
			rssLinks[i].onclick=function(){
				newHref=this.href+el.href;
				//alert(newHref+' '+el.href);
				//return false;
				this.href=newHref;
				this.target="_blank";
				newHref='';
				}
			}
		}	
	};	
	
/*
newHref=this.href+el.href;
				//alert(newHref+' '+el.href);
				//return false;
				this.href=newHref;
				this.target="_blank";
				newHref='';
				
oldHref=this.href;
				newHref=this.href+el.href;
				this.href=newHref;
				this.target="_blank";
				newHref='';
				this.href=oldHref;
				addRSS.onbox='out';
				addRSS.hide();				
				
				
*/	
	
	
	
	
	
	
function fadeContent(el){
		var lay=document.getElementById(el);
		var bg=document.createElement('div');
		bg.setAttribute('id','bg-pop');
		
		lay.appendChild(bg);
		bg.style.width=lay.offsetWidth+"px";
		bg.style.height=lay.offsetHeight+"px";
		
	}	
function restoreContent(el){
	if (document.getElementById(el)){
	document.getElementById(el).removeChild(document.getElementById('bg-pop'));
	}	
}	
	
	
	
	
/**************************------------UTILITY--------------*************************/
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}
function checkWhere(e)
{
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	return true;
}
function checkform(){

	var f = document.subscribeform;
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if(f.attribute4.value=='' || f.attribute5.value=='' || f.attribute1.value=='' || f.attribute2.value=='' || f.email.value=='' || f.attribute8.value=='' || !espressione.test(f.email.value) || f.privacy.checked==false){	
		if(f.attribute4.value=='' || f.attribute5.value=='' || f.attribute1.value=='' || f.attribute2.value=='' || f.email.value=='' || f.attribute8.value==''){
			alert('Attenzione: tutti i campi sono obbligatori.')
			return false;
		}
		if(f.email.value!='' && !espressione.test(f.email.value)){
				alert("La mail inserita non \u00E8 valida");
				return false;
		}
		if(f.privacy.checked==false){
			alert("Attenzione: accettare l'informativa sulla privacy");
			return false;
		}	
					
	}
		
	
}