//Script per il testo scorrevo per un link

function ShowTip(current,e,text)
{
	if (document.all&&document.readyState=="complete")
	{
		document.all.tooltip.innerHTML='<marquee style="border:1px solid black">'+text+'</marquee>'
		document.all.tooltip.style.pixelLeft=event.clientX+document.body.scrollLeft+10
		document.all.tooltip.style.pixelTop=event.clientY+document.body.scrollTop+10
		document.all.tooltip.style.visibility="visible"
	}
	else if (document.layers)
	{
		document.tooltip.document.nstip.document.write('<b>'+text+'</b>')
		document.tooltip.document.nstip.document.close()
		document.tooltip.document.nstip.left=0
		currentscroll=setInterval("scrolltip()",100)
		document.tooltip.left=e.pageX+10
		document.tooltip.top=e.pageY+10
		document.tooltip.visibility="show"
	}
}

function HideTip()
{
	if (document.all) document.all.tooltip.style.visibility="hidden"
	else if (document.layers)
	{
		clearInterval(currentscroll)
		document.tooltip.visibility="hidden"
	}
}

function ScrollTip()
{
	if (document.tooltip.document.nstip.left>=-document.tooltip.document.nstip.document.width)
		document.tooltip.document.nstip.left-=5
	else document.tooltip.document.nstip.left=150
}

//Fine

/* Menu */
// ---------------------------------------------------------------------------
//Script per la costruzione dei menu
// ---------------------------------------------------------------------------

var timerID = 0;
var menuToDestroy = null;

// ---------------------------------------------------------------------------
//Carica lo stile dei menu da CSS
// ---------------------------------------------------------------------------
function load_menu() 
{
  //preCacheImages();
  createMenu('navigation');
  divMenu = document.getElementById('navigation');
  divMenu.style.display = 'block';
}

// ---------------------------------------------------------------------------
//Cattura le coordinate di un elemento di menu
// ---------------------------------------------------------------------------
function getCoordinate(element)
{
  var punto = { x: 0, y: 0 };
  while (element)
  {
    punto.x += element.offsetLeft;
    punto.y += element.offsetTop;
    element = element.offsetParent;
  }
  return punto;
}

// ---------------------------------------------------------------------------
//Imposta le coordinate di un elemento di menu
// ---------------------------------------------------------------------------
function setCoordinate(elemento, x, y)
{
  var parentXY = {x: 0, y: 0 };

  if (elemento.offsetParent)
  {
    parentXY = getCoordinate(elemento.offsetParent);
  }
	
	//Costruisce gli elementi left e top
  elemento.style.left = (x - parentXY.x) + 'px';
  elemento.style.top  = (y - parentXY.y) + 'px';
}

// ---------------------------------------------------------------------------
//Costruisce il menu sulla barra di navigazione
// ---------------------------------------------------------------------------
function createMenu(menuid)
{
  var i;
  var j;
  var nodo;
	var versione;
  var offset;
  var nodoFiglio;
  var nodoGenitore;
	
	//Array di elementi del tipo HTML ul
	var ulArray = new Array();
	//Array di elementi contenente gli elementi HTML ul > li
	var ul_gt_li_Array = new Array();
	var ul_gt_li_gt_ul_Array = new Array();

  // Se il browser non supporta il metodo getElementById esce
  if (!document.getElementById)
  {
    return true;
  }

	//Lettura elemento di menu
  var divElement = document.getElementById(menuid);

  // Vettore di elementi ul
  for (i = 0; i < divElement.childNodes.length; i++)
  {
    nodo = divElement.childNodes[i];
    if (nodo.nodeName.toUpperCase() == 'UL')
    {
      ulArray[ulArray.length] = nodo;
    }
  }
	
  // Se ul > li
  for (i = 0; i < ulArray.length; i++)
  {
    nodo = ulArray[i];
    for (j = 0; j < nodo.childNodes.length; j++)
    {
      nodoFiglio = nodo.childNodes[j];
      if (nodoFiglio.nodeName.toUpperCase() == 'LI')
      {
        ul_gt_li_Array[ul_gt_li_Array.length] = nodoFiglio;
        nodoFiglio.style.display = 'inline';
        nodoFiglio.style.listStyle = 'none';
        nodoFiglio.style.position = 'static';
      }
    }
  }
	
	// ul > li > ul
  
  for (i = 0; i < ul_gt_li_Array.length; i++)
  {
    nodo = ul_gt_li_Array[i];
    for (j = 0; j < nodo.childNodes.length; j++)
    {
      nodoFiglio = nodo.childNodes[j];
      if (nodoFiglio.nodeName.toUpperCase() == 'UL')
      {
        ul_gt_li_gt_ul_Array[ul_gt_li_gt_ul_Array.length] = nodoFiglio;
        nodoFiglio.style.position = 'absolute';

        // Concatena hover al genitore li
        nodoGenitore = nodoFiglio.parentNode;
				
				//Effetto onMouseOver
        nodoGenitore.onmouseover = function (e)
        {
          var i;
          var nodoFiglio;
          var punto;

          stopDelay();
          // Termina l'effetto CSS hover
          this.style.paddingBottom = '0px';

          for (i = 0; i < this.childNodes.length; i++)
          {
            nodoFiglio = this.childNodes[i];
            if (nodoFiglio.nodeName.toUpperCase() == 'UL')
            {
              punto = getCoordinate(this);
              setCoordinate(nodoFiglio, punto.x, punto.y + this.offsetHeight);
              nodoFiglio.style.visibility = 'visible';
            }
          }
          return false;
        };
        
				//Effetto onMouseOut
        nodoGenitore.onmouseout = function (e)
				{
          startDelay(this);        			 
          return false;
        };
      }
    }
  }
  return true;
}

function destroyMenu() {

  if (timerID) {
    clearTimeout(timerID);
    timerID = 0;
  }

  var i;
  var nodoFiglio;
  for (i = 0; i < menuToDestroy.childNodes.length; i++)
  {
    nodoFiglio = menuToDestroy.childNodes[i];
    if (nodoFiglio.nodeName.toUpperCase() == 'UL')
    {
        nodoFiglio.style.visibility = 'hidden';
    }
  }
  return true;
}

function startDelay(objTopMenu) {
  menuToDestroy = objTopMenu;
  
  timerID = setTimeout("destroyMenu()", 200);

  return true;
}

function stopDelay() {
  if (timerID) {
    clearTimeout(timerID);
    timerID  = 0;
    
    if (menuToDestroy != null) {
      destroyMenu();
      menuToDestroy = null;
    }
  }
  return true;
}

/***************/

/* Contatti */
 function ResetCampi()
 {
	document.frmInvioRichiesta.Mittente.value="";
	document.frmInvioRichiesta.Azienda.value="";
	document.frmInvioRichiesta.Telefono.value="";
	document.frmInvioRichiesta.Cellulare.value="";
	document.frmInvioRichiesta.Email.value="";
	document.frmInvioRichiesta.Richiesta.value="Inserire qui la propria richiesta";
 }

 function ControllaRichiesta()
 {
	var Mittente=new String(document.frmInvioRichiesta.Mittente.value)
	var Azienda=new String(document.frmInvioRichiesta.Azienda.value)
	var Telefono=new String(document.frmInvioRichiesta.Telefono.value)
	var Cellulare=new String(document.frmInvioRichiesta.Cellulare.value)
	var Email=new String(document.frmInvioRichiesta.Email.value)	
	
	var Richiesta=new String(document.frmInvioRichiesta.Richiesta.value)	
	var lunghezza
		
	lunghezza=Mittente.length;
	Mittente=Spazi(Mittente,lunghezza);
	lunghezza=Azienda.length
	Azienda=Spazi(Azienda,lunghezza);
	lunghezza=Telefono.length
	Telefono=Spazi(Telefono,lunghezza);
	lunghezza=Cellulare.length
	Cellulare=Spazi(Cellulare,lunghezza);
	lunghezza=Email.length
	Email=Spazi(Email,lunghezza);	
	lunghezza=Richiesta.length
	Richiesta=Spazi(Richiesta,lunghezza);
   
	if (Mittente=="")
	{
		window.alert("Mittente non inserito!");
		document.frmInvioRichiesta.Mittente.focus(); 
		return false;
	}
      
	if (Azienda=="")
	{
		window.alert("Azienda non inserita!");
		document.frmInvioRichiesta.Azienda.focus(); 
		return false;
	}
  
	if (Telefono=="")
    {
		window.alert("Telefono non inserito!")
		document.frmInvioRichiesta.Telefono.focus(); 
		return false;   
    }
	else if (isNaN(Telefono))
	{
		window.alert("Telefono deve essere in formato numerico!")
		document.frmInvioRichiesta.Telefono.focus(); 
		return false;
	}
	
	if (Email=="")
	{
		window.alert("Email non inserita!");
		document.frmInvioRichiesta.Email.focus();
		return false;
	}	
	else if (!CheckEmail(Email)) 
	{	
		window.alert("Email non corretta!");
		document.frmInvioRichiesta.Email.focus();
		return false;
	}

	if (Richiesta=="")
    {
		window.alert("Contenuto e-mail non inserito!")
		document.frmInvioRichiesta.Richiesta.focus(); 
		return false;   
	}	

	if (Cellulare!="" && isNaN(Cellulare))
	{
		window.alert("Cellulare deve essere in formato numerico!")
		document.frmInvioRichiesta.Cellulare.focus(); 
		return false;
	}
}

function ResetCampi_en()
 {
	document.frmInvioRichiesta.Mittente.value="";
	document.frmInvioRichiesta.Azienda.value="";
	document.frmInvioRichiesta.Telefono.value="";
	document.frmInvioRichiesta.Cellulare.value="";
	document.frmInvioRichiesta.Email.value="";
	document.frmInvioRichiesta.Richiesta.value="Insert here your request";
 }

 function ControllaRichiesta_en()
 {
	var Mittente=new String(document.frmInvioRichiesta.Mittente.value)
	var Azienda=new String(document.frmInvioRichiesta.Azienda.value)
	var Telefono=new String(document.frmInvioRichiesta.Telefono.value)
	var Cellulare=new String(document.frmInvioRichiesta.Cellulare.value)
	var Email=new String(document.frmInvioRichiesta.Email.value)	
	
	var Richiesta=new String(document.frmInvioRichiesta.Richiesta.value)	
	var lunghezza
		
	lunghezza=Mittente.length;
	Mittente=Spazi(Mittente,lunghezza);
	lunghezza=Azienda.length
	Azienda=Spazi(Azienda,lunghezza);
	lunghezza=Telefono.length
	Telefono=Spazi(Telefono,lunghezza);
	lunghezza=Cellulare.length
	Cellulare=Spazi(Cellulare,lunghezza);
	lunghezza=Email.length
	Email=Spazi(Email,lunghezza);	
	lunghezza=Richiesta.length
	Richiesta=Spazi(Richiesta,lunghezza);
   
	if (Mittente=="")
	{
		window.alert("Sender not written!");
		document.frmInvioRichiesta.Mittente.focus(); 
		return false;
	}
      
	if (Azienda=="")
	{
		window.alert("Company not written!");
		document.frmInvioRichiesta.Azienda.focus(); 
		return false;
	}
  
	if (Telefono=="")
    {
		window.alert("Phone not written!")
		document.frmInvioRichiesta.Telefono.focus(); 
		return false;   
    }
	else if (isNaN(Telefono))
	{
		window.alert("Phone must be in numbers!")
		document.frmInvioRichiesta.Telefono.focus(); 
		return false;
	}
	
	if (Email=="")
	{
		window.alert("Email not written!");
		document.frmInvioRichiesta.Email.focus();
		return false;
	}	
	else if (!CheckEmail(Email)) 
	{	
		window.alert("Email not correct!");
		document.frmInvioRichiesta.Email.focus();
		return false;
	}

	if (Richiesta=="")
    {
		window.alert("Email content not written!")
		document.frmInvioRichiesta.Richiesta.focus(); 
		return false;   
	}	

	if (Cellulare!="" && isNaN(Cellulare))
	{
		window.alert("Mobile must be in numbers!")
		document.frmInvioRichiesta.Cellulare.focus(); 
		return false;
	}
}


 function Spazi(str,lunghezza)
 {
  _str = new String(str);  
  var result= new String()
  var lung =lunghezza
  var i=0;
  var j=lung-1;
  while ((i<lung) && (_str.charAt(i)==" ")) i++;
  if (i==lung) result="";
  else
  {
  	while ((j>0) && (_str.charAt(j)==" ")) j--;
    result=_str.substring(i,j+1)
  }
  return result;
 }

 function CheckEmail(Email)
 {   
  email=new String(Email);
  var result   = true;
  var atPos    = email.indexOf("@");
  var stopPos  = email.indexOf(".",atPos);
  var spacePos = email.indexOf(" ");
  var car=email.substring(stopPos+1,email.length)	

  if (email=="") return result;
  if ((email == "") ||(spacePos != -1) ||
  (0 >= atPos) || (atPos+1 >= stopPos) || (car.length==0)) result = false;
   return result;
 }

 /**************/
 
function changeImage(obj, image) 
{
 	obj.src = image;
 	return true;
}

/**** Dove Siamo ****/
// Immagine fade 
function high(which2)
{
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",50)	
}

function low(which2)
{
	clearInterval(highlighting)
	which2.filters.alpha.opacity=20
}

function highlightit(cur2)
{
	if (cur2.filters.alpha.opacity<100) cur2.filters.alpha.opacity+=5
	else if (window.highlighting) clearInterval(highlighting)
}
/**************/

function changeImage(obj, image) 
{
	obj.src = image;
	return true;
}

function VisualizzaMappa(obj,image)
{
	changeImage(obj,image);
	obj.filters.alpha.opacity=0;
	high(obj);
	document.Zoom.style.visibility="Hidden";
}
