// JavaScript Document
   function init()  
 { 
 	if (tag!=""){
		tags =  new Array (["prodotti"],["agricoli"],["mov_terra"],["generatori"],["industriali"]);
		if (tags.join().indexOf(tag)>=0) tag = "prodotti";
		selezionato=document.getElementById(tag);
		//alert(tag);
 		if(selezionato)	
		{
			selezionato.getElementsByTagName("a")[0].className = "active";			
			if (tag=="prodotti") document.getElementById("abs").style.display = "block";
		}
	}
	elNascondi=document.getElementById("nascondi");
	elElenco=document.getElementById("elenco");
	if (elNascondi && elElenco) {
		tutti = true;
		objLink = elNascondi.getElementsByTagName("a");	
		for(i=0;i<objLink.length;i++)  
		  {  
			objLink[i].onclick=function()
				{
					objLi = elElenco.getElementsByTagName("li");
					for (j=0;j<objLi.length;j++) {
						if(/disbl/.test(objLi[j].className))  
	   					{	
							if (tutti)
								mn(objLi[j],this,"none",false,"Nascondi","Mostra");
							else
								mn(objLi[j],this,"block",true,"Mostra","Nascondi");
						}
					}				
				};
		  }  	
	}
//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');};
		  }	
 
	var box = {};
	box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: false});
	
 /*
 //assegna le funzioni di rollover ai menu con id "navx" dove x è da 1 a nNav
 	var tag = "";
  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
			   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);};  
		   }
	   }  
	  }  
	  }
	}
	//se c'è il box delle news scorrevole assegna i comportamenti di cambio variabile
	var mc = document.getElementById("marqueecontainer");
	if (mc){
		initializemarquee();
		mc.onmouseover=function(){copyspeed=pausespeed;};
		mc.onmouseout=function(){copyspeed=marqueespeed;};	
	}
	
   //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 attivita = new Array();
	 var nt = "";
	 for(i=0;i<links.length;i++)  
	  {  
	   if(/blind/.test(links[i].className))  
	   {		
	   			j=links[i].getAttribute('id').replace("toggle","");
				attivita[j] = new Fx.Slide('attivita_'+j);$('toggle'+j).addEvent('click', function(e){
				e = new Event(e);				
				h = this.getAttribute('id').replace("toggle","");
				attivita[h].toggle();
				if (nt!="") attivita[nt].toggle();
				if (h!=nt){
					nt = h;
				}else{
					nt="";
				}
				e.stop();
				});
				if (c == "") attivita[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;};
		   }
	  }
 */}  
 
 //funzioni richiamate dalla init
 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','');  
   disp = "none";
  }else{  
   newsrc = src.replace(ftype, '_on'+ftype);  
   disp = "block";
  }  
  o.childNodes[isnode].src=newsrc;  
  ulin = o.getElementsByTagName("ul");
  if(ulin[0])  ulin[0].style.display = disp;
 }  
   
   function verificaTotale(inputss,nmax, sel,aa)
   {
	   var totale = 0;
		for(n=0;n<inputss.length;n++)  
	  	{
			if(/qta/.test(inputss[n].className))
			  {
				  totale+=(inputss[n].value*1);
			  }
		}
		if (totale > nmax || !totale)
		{
			showtrail(200,1,"<b>Attenzione! </b><br />prodotti consentiti: "+nmax+"<br />prodotti inseriti: "+totale+" <br />&Egrave; stato sostituito l'ultimo valore inserito con il massimo consentito dalla confezione scelta");
			sel.value = nmax-(totale-sel.value);
			setTimeout(function(){sel.focus();sel.select();},10)
		} else {
			hidetrail();	
		}
   }
/* window.onload=function(){  
  init();  
 }  
 */
 /***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
cross_marquee=document.getElementById("vmarquee")
cross_marquee.style.top=0
marqueeheight=document.getElementById("marqueecontainer").offsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}
function formCallback(result, form) {
	window.status = "convalida del modulo '" + form.id + "': responso = " + result;
}
function codiceFISCALE(cfins)
   {
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
   }
   function CtrPartIVA(PIVA) {
    if (PIVA.length!=11) { 
        return false;
    } else {
        for (i=0;i<PIVA.length;i++) {
            if ((PIVA.charAt(i)<"0")||(PIVA.charAt(i)>"9"))
                return false;
        } 
    }
    return true; 
}
//showtrail
function gettrailobj(idt)
{
	if (document.getElementById) return document.getElementById(idt).style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('tcont').innerHTML=""
	gettrailobj("trailimageid").visibility="hidden"
	gettrailobj("trailimageid").left=-1000
	gettrailobj("trailimageid").top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{
		w=width
		h=height
		followmouse()	
		gettrailobj("trailimageid").visibility="visible"
		gettrailobj("trailimageid").width=w+"px"//gettrailobj("tcont").width//
		gettrailobj("trailimageid").height=gettrailobj("tcont").height//h+"px"
		document.getElementById('tcont').innerHTML=file
		document.onmousemove=followmouse
	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{

		var xcoord=20
		var ycoord=20

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj("trailimageid").left=xcoord+"px"
		gettrailobj("trailimageid").top=ycoord+"px"

	}

}

//end showtrail
   function mn(obj1,obj2,displ,tt,txt1,txt2)
   {
	   obj1.style.display=displ;
	   tutti=tt;
	   newTxt=obj2.innerHTML.replace(txt1,txt2);
	   obj2.innerHTML=newTxt;
   }
// 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

