var curMenu
var curMain
var submenu1
var submenu2
var submenu3
var submenu4
var submenu5
var nav = new Array(4)
var tripnt
var clearCurrent = true
var clearReset

function prepBrowser(){
  if(document.layers){
    submenu1 = document.dropdown1;
    submenu2 = document.dropdown2;
    submenu3 = document.dropdown3;
    submenu4 = document.dropdown4
  }
  else if(document.all){
    submenu1 = dropdown1.style;
    submenu2 = dropdown2.style;
    submenu3 = dropdown3.style;
    submenu4 = dropdown4.style
  }

  if(document.images){
    nav[1] = new mnuDropDown("main_micronet",  "menu_img/on_micronet.gif",  "menu_img/off_micronet.gif",  submenu1);
    nav[2] = new mnuDropDown("main_download", "menu_img/on_download.gif", "menu_img/off_download.gif", submenu2);
    nav[3] = new mnuDropDown("main_software", "menu_img/on_software.gif", "menu_img/off_software.gif", submenu3);
    nav[4] = new mnuDropDown("main_supp",     "menu_img/on_supp.gif",     "menu_img/off_supp.gif",     submenu4);
    tripnt = new mnuPointer()
  }
}

function mnuDropDown(loc, on, off, sub){
  if(document.images){
    this.loc = loc;         // "Name" dell'immagine di menu
    this.on = new Image();
    this.off = new Image();
    this.on.src = on;
    this.off.src = off;
    this.sub = sub
  }
}

function mnuPointer(){
  this.on = new Image();
  this.off = new Image();
  this.on.src = "menu_img/on_punt.gif";
  this.off.src = "menu_img/off_punt.gif"
}

function on_image(pos){
  if(document.images && typeof nav[pos] != 'undefined'){
    document.images[nav[pos].loc].src = nav[pos].on.src;
    if(curMenu){
      curMenu.visibility = "hidden"
    }
    if(curMain){
      if(curMain != pos){
        document.images[nav[curMain].loc].src = nav[curMain].off.src;
        clearCurrent = false
      }
    }
    if(document.layers || document.all){
      nav[pos].sub.visibility = "visible";
      curMenu = nav[pos].sub;
      clearCurrent = false
    }
    curMain = pos
  }
}

function off_image(pos){
  if(document.images){
    clearCurrent = true;
    setTimeout('clrTimer()',100)
  }
}

function onPoint(layerpos, loc){
  if(document.all){
    document.images[loc].src = tripnt.on.src
  }
  clearCurrent = false
}

function offPoint(layerpos, loc){
  if(document.all){
    document.images[loc].src = tripnt.off.src
  }
  clrDrop()
}

function clrDrop(){
  clearCurrent = true;
  setTimeout('clrTimer()',100)
}

function clrCur(){
  if(curMenu){
    curMenu.visibility = "hidden"
  }
  if(curMain){
    document.images[nav[curMain].loc].src = nav[curMain].off.src
  }
}

function clrTimer(){
  if(clearCurrent){
    clrCur()
  }
}

function noClear(){
  if(curMenu){
    clearCurrent = false
  }
}

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

  finestra = window.open(quale, "PopupWindow", "titlebar=yes,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();
  }
}

function Download(iddownload){
  apriWin("http://www.micronet-software.com/service/download/download.asp?ID=" + iddownload, 600, 400, -2, -2)
  //apriWin("http://negoziomicronet-software.com/download.asp?ID=" + iddownload, 600, 400, -2, -2)
}

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
==================================================================*/
function ShowTT(fArg)
{
	var tooltipOBJ = eval("document.all['" + fArg + "']");
	var tooltipOffsetTop = tooltipOBJ.scrollHeight - 50 ;
	var testTop = event.clientY - tooltipOBJ.scrollHeight - 45;
	var testLeft = event.clientX - tooltipOBJ.scrollWidth / 2;		

	tooltipOBJ.style.posLeft = testLeft + document.body.scrollLeft;
	tooltipOBJ.style.posTop = testTop + document.body.scrollTop;
	tooltipOBJ.style.visibility = "visible";
}

/*=================================================================
Function: HideTooltip
==================================================================*/
function HideTT(fArg)
{
	var tooltipOBJ = eval("document.all['" + fArg + "']");
	tooltipOBJ.style.visibility = "hidden";
}

