var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var dom=(document.getElementById && !document.all)? true:false
var isMac = (navigator.appVersion.indexOf("Mac") != -1); // 
var isOver='si' //   variabile  per  vedere se  sono su un layer oppure no

//  funzioni show/hide
function nascondo(quale) {
  if (ie4) {document.all[quale].style.visibility="hidden"}
  if (ns4) {document.layers[quale].visibility="hide"}
  if (dom) {document.getElementById(quale).style.visibility="hidden"}
}

function vedo(quale) { 
  clearTimeout(timerID);
  timerId=null;
  if (ns4) {document.layers[quale].visibility="show" }
  if (ie4) {document.all[quale].style.visibility="visible"}
  if(dom) {document.getElementById(quale).style.visibility="visible"}
}  
      
// funzione  scrivi in un layer    
function scrivi(quale,stringa) {

  if (ie4) {document.all[quale].innerHTML=stringa}
  else if (ns4) {
     with (document.layers[quale].document) {
      open();
      write(stringa);
      close();
    }  
	}
	else {document.getElementById(quale).innerHTML=stringa}
}

// per muovere un layer
function moveTo(quale,x,y) {
  if(ie4) {
    document.all[quale].style.left = x+1;
    document.all[quale].style.top = y;
  }
  else if(ns4) {
    document.layers[quale].left = x+1;
    document.layers[quale].top = y;
  }
  else {
    document.getElementById(quale).style.left = x+1;
    document.getElementById(quale).style.top = y;
  }
}

function layerWidth(quale,what) {
  if (dim==1) {dim="auto"}
  if (ie4) {document.all[quale].style.width=dim}
  else if (ns4) {document.layers[quale].document.width=dim}
  else {document.getElementById(quale).style.width=dim}
}
  
// becco una  posizione
function getPos(voce) {
  if (ie4) {  
    xPos= holdspace.offsetLeft;
    yPos= holdspace.offsetTop;
  }
  else if (ns4) { 
    xPos=document.images[holdspace].x;
    yPos=document.images[holdspace].y;
  }
  else if (dom) { 
    el=document.getElementById(holdspace);
    xPos=el.offsetLeft;
    yPos=el.offsetTop;
  }
  what=parseInt(navMenu[voce].w )
  // setto la  posizione dell'ultima immagine
  if (what==9) {
    what=8; 
    deltaLast=document.images[navMenu[what].sez].width+1;
  }
  else {deltaLast=0}
  delta=navMenu[what].sez;
  getPosPlus(delta,deltaLast);
}

// becco  piu posozioni
function getPosPlus(voce) {
  curHold=voce
  if (ie4) {curHold=voce}
  if (ie4) { 
    xPos2=document.images[curHold].offsetLeft+xPos;
    yPos2=document.images[curHold].offsetTop;
  }
  else if (ns4) { 
    xPos2=document.images[curHold].x;
    yPos2=document.images[curHold].y;
  }
  else if (dom) { 
    el = document.getElementById(curHold);
    xPos2=el.offsetLeft;
    yPos2=el.offsetTop;
  }
  dim=eval(deltaLast+(xPos2-xPos))-2;
  if (dim<0) {dim=1}
  return(dim);
}

// funzione  per  mostrare  le  immagini
function showImma(imma,nomeImma) {
  if (document.images) {
    document.images[imma].src = "/images/"+nomeImma+".gif"; 
    return true;
	}
}

// funzione  per  mostrare  le  immagini
function showImmaPlus(imma,nomeImma) {
  if (document.images) {
    document.images[imma].src = nomeImma; 
    return true;
	}
}

// becco il path o comunque var del percorso
function getPath() {
  myLoc=location.href;
  var curPath=window.location.href;
  myFile=curPath.substr(curPath.lastIndexOf("/")+1);
  return myLoc,myFile;
}

// funzione per immagine casuale del top Hp
var imageArray = new makeimageArray('/images/top_img_0.jpg','/images/top_img_1.jpg', '/images/top_img_2.jpg', '/images/top_img_3.jpg','/images/top_img_4.jpg','/images/top_img_5.jpg','/images/top_img_6.jpg','/images/top_img_7.jpg','/images/top_img_8.jpg','/images/top_img_9.jpg','/images/top_img_10.jpg','/images/top_img_11.jpg');
//var imageArray = new makeimageArray('/images/top_italia.jpg','/images/top_germania.jpg', '/images/top_francia.jpg', '/images/top_inghilterra.jpg','/images/top_spagna.jpg');


function makeimageArray() {
  this.length = makeimageArray.arguments.length;
  for (var i = 0; i < this.length; i++) {
    this[i + 1] = makeimageArray.arguments[i];
  }
}

function randNum (num) {
  var now = new Date();
  var rand = Math.round(num * Math.cos(now.getTime()));
  if (rand < 0) {rand = - rand}
  if (rand == 0) {rand++}
  return rand;
}

// funzione per aprire una finestra di popup
function OpenWindow(URL,name,w,h) {
 	var main_opts = "location=0,scrollbars=0,status=1,resizable=0,directories=0,menubar=0"; 
  var this_opts = main_opts + ',width=' + w + ',height=' + h ;
  var this_win = open(URL,name,this_opts) ;
  if (window.focus ) {
   this_win.focus();
  }
}

function OpenWindowS(URL,name,w,h) {
 	var main_opts = "location=0,scrollbars=1,status=1,resizable=0,directories=0,menubar=0"; 
  var this_opts = main_opts + ',width=' + w + ',height=' + h ;
  var this_win = open(URL,name,this_opts) ;
  if (window.focus ) {
   this_win.focus();
  }
}


// funzione che serve per scrivere un immagine in un pop-up
function scriviWin(tit,imma,w,h) {
  var win_opts = "location=0,scrollbars=0,status=0,resizable=0,directories=0,menubar=0"; 
  var all_opts = win_opts + ',width=' + w + ',height=' + h ;
  var win = open("","immaWin",all_opts) ;
  with (win.document) {
    open("text/html", "replace");
    write("<HTML><HEAD><TITLE>"+tit+"</TITLE><SCRIPT>self.focus();</SCRIPT></HEAD><BODY marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" topmargin=\"0\" bottommargin=\"0\" rightmargin=\"0\"><img src='"+imma+"' border='0'></BODY></HTML>");
    close();
  }
}


// funzione per aprire il pop up della sezione standars
function apri(desktopURL) {
  var i=desktopURL.selectedIndex;
  var nomefile='popStandard.jsp?lang='+curLang+'&nFile='
  if (desktopURL.options[i].value!= '') {
    nomefile+=desktopURL.options[i].value
    desktop = window.open(nomefile, "Normativa","width=317,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0" );
    desktopURL.selectedIndex=0
  }
}


// funzione per aprire il pop up della sezione standars
function apri2(desktopURL) {
  var i=desktopURL.selectedIndex;
  var nomefile='popStandard.php?lang='+curLang+'&nFile='
  if (desktopURL.options[i].value!= '') {
    nomefile+=desktopURL.options[i].value
    desktop = window.open(nomefile, "Normativa","width=317,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0" );
    desktopURL.selectedIndex=0
  }
}



// stampa pagina
function printArticle() {
  var agt=navigator.userAgent.toLowerCase();
  if (window.print) {
    setTimeout('window.print();',200);
	}
	else if (agt.indexOf("mac") != -1) {
    alert("Press 'Cmd+p' on your keyboard to print article.");
	}
	else {
    alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}


function showImg(nameImg, srcImg) {
   if (document.images) {
    document.images[nameImg].src ="/images/"+srcImg;
   }
}

