// JavaScript Document
   function init()  
 { 
	//assegna le funzioni di rollover ai menu con id "navx" dove x è da 1 a nNav
	  var nNav=1;
	  var imgs,j,i;  
	 // Loop through all images, check if they contain the class roll  
 	  for (j=1;j<=nNav;j++) {
		  uls=document.getElementById('nav'+j)
		  if (uls)
			  {
			  imgs=uls.getElementsByTagName('img');  
			  for(i=0;i<imgs.length;i++)  
			  { 
			   if(/roll/.test(imgs[i].className))  
			   {  
			 // add the function roll to the parent Element of the image  
				   if(tag!='' && imgs[i].getAttribute('name')==tag) {
					   sr = imgs[i].src
					   if(!(/_on/.test(sr)))
						 {  
						   ft = sr.substring(sr.lastIndexOf('.'), sr.length);  
						   imgs[i].src= sr.replace(ft, '_on'+ft);
						 }
				   }else{
				   imgs[i].parentNode.onmouseover=function(){roll(this);};  
				   imgs[i].parentNode.onmouseout=function(){roll(this);};  
				   imgs[i].parentNode.onfocus=function(){roll(this);};  
				   imgs[i].parentNode.onblur=function(){roll(this);};  
				   }
			   }  
			  }  
		  }
	  }
	  	 
//se c'è una form assegna inizia la validazione o per i cesti il controllo delle quantita
	var formv = document.getElementsByTagName("form");
	for(i=0;i<formv.length;i++)  
	  {
		  var nome = formv[i].getAttribute('id');
		  if(/valida/.test(formv[i].className))
		  {
			var myFormValidation = new Validate(nome,{
					errorClass: 'red'
				});
		  }
		  if (nome=="frm_contatti")
		  	formv[i].onsubmit=function(){submit_contatti('result_contattaci','phpmyformmail.php');};
	  }	
 
   //se c'è un'area per la comparsa e scomparsa dei div qui la configura
     div_effetto = document.getElementById("effetto");
	 if (div_effetto) {
	 links =  div_effetto.getElementsByTagName("a");
	 var apri = new Array();
	 var nt = c;
	 for(i=0;i<links.length;i++)  
	  {  
	   if(/blind/.test(links[i].className))  
	   {		
	   			j=links[i].getAttribute('id').replace("toggle","");
				apri[j] = new Fx.Slide('apri_'+j);$('toggle'+j).addEvent('click', function(e){
				e = new Event(e);				
				h = this.getAttribute('id').replace("toggle","");
				document.getElementById('apri_'+h).style.display="block";
				apri[h].toggle();
				if (nt!="") apri[nt].toggle();
				if (h!=nt){
					nt = h;
				}else{
					nt="";
				}
				e.stop();
				});
				if (c != j)  
					apri[j].hide();
	   }
	  }
	 }
	 
	 //cerca campi con classe "vuota" e gli assegna l'effetto che al focus il campo si vuota
	 inputs = document.getElementsByTagName("input");
	 var initVal = "";
	 for(i=0;i<inputs.length;i++)  
	  {  	 
		 if(/vuota/.test(inputs[i].className))  
		   {
				inputs[i].onfocus=function(){initVal = this.value;this.value="";};  
				inputs[i].onblur=function(){if (this.value=="") this.value=initVal;};
		   }
	  }
	  //cerca i button e gli assegna l'onclick
	   buttons = document.getElementsByTagName("button");
	   if(buttons)
	   {
			for(i=0;i<buttons.length;i++)  
			{  
				buttons[i].onclick=function(){document.location.href = this.getAttribute("title");};  
			}
			    
	   }
	   if(document.getElementById("mb0"))
				{
				var box = {};
				box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: false});
				}
	
	if (tag!="")
	MM_swapImage(tag,'','imm/menu/'+tag+'_sel.png',1);
		
}  
 
 function submit_contatti(obj) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	var edtemail=document.getElementById("edtemail").value;
	var edtmessaggio=document.getElementById("edtmessaggio").value;
	var edtrecipient=document.getElementById("edtrecipient").value;
	var edtsubject=document.getElementById("edtsubject").value;
	
	if(edtemail == ""){ 
		alert("Inserire l'email.");
		document.getElementById("edtemail").className="error";
		return false;
	}
	
	if(!emailPattern.test(edtemail)){	
		alert("L'indirizzo "+ edtemail + " non è corretto.");
		document.getElementById("edtemail").className="error";
		return false; 
		}	
		
	if(edtmessaggio == ""){ 
		alert("Inserire il messaggio.");
		document.getElementById("edtmessaggio").className="error";
		return false;
	}   
	
	var poststr = "email=" + encodeURI( edtemail ) + "&messaggio=" + encodeURI( edtmessaggio ) + "&recipient=" + encodeURI( edtrecipient ) + "&subject=" + encodeURI( edtsubject ) ;
		document.getElementById('result_contattaci').innerHTML = '<div style="width:24px;margin:50px auto"><img src="images/loadinfo.gif" /></div>'; 
		makePOSTRequest('phpmyformmail.php', poststr,'result_contattaci');
	
}

function formCallback(result, form) {
	window.status = "convalida del modulo '" + form.id + "': responso = " + result;
}

 function roll(o)  
 {  
  var i,isnode,src,ftype,newsrc,nownode;  
 // loop through all childNodes  
  for (i=0;i<o.childNodes.length;i++)  
  {  
   nownode=o.childNodes[i];  
 // if the node is an element and an IMG set the variable and exit the loop  
   if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))  
   {  
    isnode=i;  
    break;  
   }  
  }  
 // check src and do the rollover  
  src = o.childNodes[isnode].src;  
  ftype = src.substring(src.lastIndexOf('.'), src.length);  
  if(/_on/.test(src))  
  {  
   newsrc = src.replace('_on','');  
  }else{  
   newsrc = src.replace(ftype, '_on'+ftype);  
  }  
  o.childNodes[isnode].src=newsrc;  
 }  
// e qui parte tutto
if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.getElementById)
window.onload=init




