/*=================================================================
--------- INIZIO FUNZIONI USATE DAL MENU --------------------------
==================================================================*/

var eOpenMenu = null;
var stopTimer = true;

/*=================================================================
	visualizza l'elemento passato con fArg nelle coordinate x, y
	maxX rappresenta la coordinata massima X di delimitazione a destra
	se il menu non ci sta dentro, viene forzato
==================================================================*/
function mnuShow(fArg, x, y, maxX)
{	
	stopTimer = true;

	//obj=document.getElementById('imgmenu');
	//x=x+obj.style.left;
	
	// se era già aperto un altro menu precedente, lo chiude!	
	if (eOpenMenu) eOpenMenu.style.visibility = "hidden";
		
	eOpenMenu=document.getElementById(fArg);
	
	// se non rientra nel bordo destro, viene forzato a sinistra
	if (x + eOpenMenu.clientWidth > maxX) x = maxX- eOpenMenu.clientWidth;
	if (x < 1) x=1;

	eOpenMenu.style.left = x;
	eOpenMenu.style.top = y;
	
	eOpenMenu.style.position = "absolute";
	
	eOpenMenu.style.visibility = "visible";
}

/*=================================================================
	entra nel menu e ferma il timer
==================================================================*/
function mnuInside()
{
	stopTimer = true;
}

/*=================================================================
	chiude il menu, se timer non è stato fermato
==================================================================*/
function mnuClose()
{
	// se il timer non è stato stoppato e se il menu è aperto, lo chiude!
	
	if (!stopTimer && eOpenMenu) {
		eOpenMenu.style.visibility = "hidden";
		eOpenMenu = null;
	}
}

/*=================================================================
	esce dal menu ed avvia il timer per la chiusura
==================================================================*/
function mnuLeave(fArg)
{
	stopTimer = false;
	setTimeout('mnuClose()',100);
}


/*=================================================================
	Mostra l'evidenziatore sotto al link nell'immagine
==================================================================*/
function LinkRepos(fArg, x, y, lar)
{
	obj=document.getElementById(fArg);

	obj.style.left = x;
	obj.style.top = y;	
	obj.style.width = lar;	
	obj.style.visibility = "visible";
}


function LinkNascondi(fArg)
{
	var obj=document.getElementById(fArg);	
	obj.style.visibility = "hidden";
}

/*=================================================================
--------- FINE FUNZIONI USATE DAL MENU ----------------------------
==================================================================*/





/*=================================================================
  Avvia una finestra secondaria
==================================================================*/
function apriWin(quale, x, y, mleft, mtop){
  // mleft e mtop=-1, posiziona la finestra centrata nello schermo
  // questo sistema non funziona con finestre aperte su link esterni al sito e genera un errore
  // perciò, passando come parametro -2, viene evitato il posizionamento

  if(x > screen.availWidth) x = screen.availWidth;
  if(y > screen.availHeight) y = screen.availHeight;

  finestra = window.open(quale, "PopupWindow", "titlebar=no,toolbar=no,status=no,location=no,menubar=no,resizable=yes,scrollbars=yes,width=" + x + ",height=" + y);

  if(mleft==-1 || mtop ==-1){
    mleft = screen.availWidth/2 - x/2;
    mtop = screen.availHeight/2 - y/2;
  }
  if(mleft!=-2){
    finestra.moveTo(mleft, mtop);
    finestra.focus();
  }
}


/*=================================================================
  Avvia una finestra secondaria a dimensioni max dello schermo
==================================================================*/
function apriWinMax(quale){

  var w = screen.availWidth||screen.width;
  var h = screen.availHeight||screen.height;


  finestra = window.open(quale, "PopupWindow", "titlebar=no,toolbar=no,status=no,location=no,menubar=no,resizable=yes,scrollbars=yes,width=200,height=200");
  finestra.moveTo(0, 0);
  finestra.resizeTo(w,h);
}


/*=================================================================
  Avvia la finestra di download
==================================================================*/
function Download(iddownload){
  apriWin("http://www.danea.it/service/download/download.asp?ID=" + iddownload, 500, 430, -2, -2)
}


/*=================================================================
  Verifica validità email
==================================================================*/
function ValidaEmail(field) {
		
	if (field.value.indexOf("@") == -1) return(false);
	if (field.value.indexOf("@") != field.value.lastIndexOf("@")) return(false);
	if (field.value.indexOf("@") > field.value.lastIndexOf(".")) return(false);
	if (field.value.indexOf(",") != -1 ||
		field.value.indexOf(":") != -1 ||
		field.value.indexOf(";") != -1 ||
		field.value.indexOf(" ") != -1 ||
		field.value.indexOf("\"") != -1 ||		
		field.value.indexOf("\'") != -1 ||				
		field.value.indexOf("<") != -1 ||	
		field.value.indexOf(">") != -1) return(false);
		
	return(true);
}

/*=================================================================
Function: ShowTT (posiziona sopra al link di origine)
==================================================================*/
function ShowTT(fArg, myevent)
{
	var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
	var ns6=document.getElementById&&!document.all;

	obj = document.getElementById(fArg);

	x = ie4? event.clientX : ns6? myevent.clientX : myevent.x;
	y = ie4? event.clientY : ns6? myevent.clientY : myevent.y;
	
	x = x - obj.scrollWidth / 2 + document.body.scrollTop;
	y = y - obj.scrollHeight + document.body.scrollLeft - 40;		

	obj.style.left = x;
	obj.style.top = y;	
	obj.style.visibility = "visible";
}		


/*=================================================================
Function: HideTooltip
==================================================================*/
function HideTT(fArg)
{
	tooltipOBJ = document.getElementById(fArg);
	tooltipOBJ.style.visibility = "hidden";
}

/*=================================================================
Function: ShowTTDn (posiziona sotto il link di origine)
==================================================================*/
function ShowTTDn(fArg, myevent)
{
	var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
	var ns6=document.getElementById&&!document.all;

	obj = document.getElementById(fArg);

	x = ie4? event.clientX : ns6? myevent.clientX : myevent.x;
	y = ie4? event.clientY : ns6? myevent.clientY : myevent.y;
	
	x = x + document.body.scrollLeft;	
	if (x < 0) x = 0;
	
	obj.style.left = x + 20;
	obj.style.top = y + 20 + document.body.scrollTop;
	obj.style.visibility = "visible";
}

/*=================================================================
Function: ReposTT
riposiziona sull'angolo 10,10 in modo che non si attivino inutilmente
le scroll bar
==================================================================*/
function ReposTT(fArg)
{
	tooltipOBJ = document.getElementById(fArg);
	tooltipOBJ.style.left = 10;
	tooltipOBJ.style.top = 10;
}