// JavaScript Document
   function init()  
 { 
 tag="";
 	if (tag!=""){
		selezionato=document.getElementById(tag);
 		if(selezionato)		selezionato.getElementsByTagName("a")[0].className = "active";
	}

//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 = "";
	 var 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 == "") 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});
		//		}
		
}  
 
 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 nuovalingua(id) {
  var url = String(window.location) ;
  set_cookie('lang', id);
  var index2 = url.indexOf('#');
	
  a=url.split('#');
  url=a[0];
  
  var index = url.indexOf('?');
  
  
  conc=(index == -1)?"?":"&";
  //conc2=(a[1] <>'')?"#"+a[1]:"";  
  
  
  url = url + conc+"lang="+id;
  //alert (url);
  window.location=url;
}

function set_cookie(name, value)
{
	document.cookie= name + "=" + escape(value);
}

// 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



