function SwitchLng(lngID){nURL="/"+lngID+"/index.htm";window.document.location.href = nURL;return true;}
function SwitchLngEx(lngID){var sURL=window.document.location.href;nURL=new String(sURL);aURL=nURL.split("/");nURL=nURL.replace("/"+aURL[3]+"/","/"+lngID+"/");window.document.location.href = nURL;return true;}
function resizeDiv(a,b,h){if(a!=0) b1 = document.getElementById(a).offsetHeight; else b1 = 0; b2 = document.getElementById(b).offsetHeight; if((b1 + b2) < h) { k = h - (b1 + b2); document.getElementById(b).style.height = (b2 + k) + "px"; } }
function getColMh() {mh=0;ch=0;for(i=1;i<5;i++) {if(document.getElementById("col"+i)!=undefined) {document.getElementById("col"+i).style.height="auto"; ch = document.getElementById("col"+i).offsetHeight; if(ch>mh) mh = ch;}}return mh;}

  function emailcheck(str) {
    var at="@"
  	var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at) == -1)
      return 1
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
  	  return 1
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
  	  return 1
    if (str.indexOf(at,(lat+1))!=-1)
  	  return 1
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
  	  return 1
    if (str.indexOf(dot,(lat+2))==-1)
      return 1
    if (str.indexOf(" ")!=-1)
      return 1
    return 0
  }
  function ValidateFastLogin()
  {
    var err = "";
    if(document.fastloginform.usr_pass.value == "") { err = "Non e' stata specificata la password."; }
    if(document.fastloginform.usr_name.value == "") { err = "Manca il nome utente.";}
    if(emailcheck(document.fastloginform.usr_name.value)==1) { err = "Nome utente errato verificate di averlo digitato correttamente.";}
    if(err!="") { alert(err); return false;}
    document.fastloginform.submit();
  }
  function Logout()
  {
    document.fastloginform.submit();
  }
  function background_callback(err,data) 
  {
    if(err==0) {
      window.document.location.href = data;
    }
    if(err==1) {
      oHTML  = "<br />Benvenuto <b>" + data + "</b><br />";
      oHTML += "<input type=\"hidden\" id=\"ecm_URI\" name=\"ecm_URI\" value=\"\" />";
  		oHTML += "<input type=\"hidden\" id=\"usr_name\" name=\"usr_name\" value=\"logout\" />";
			oHTML += "<input type=\"hidden\" id=\"usr_pass\" name=\"usr_pass\" value=\"logout\" /><br />";	
	  oHTML += "<ul><li><a href=\"/it/area_riservata/profilo_utente.htm\">Verifica i tuoi dati personali</a></li>";
      oHTML += "<li><a href=\"javascript: Logout();\">Logout</a></li></ul>";
      var oE = document.getElementById("fastlogin_form");
      oE.innerHTML = "";
      var oE = document.getElementById("fastlogin_greatings");
      oE.innerHTML = oHTML;
    }
    if(err==2) {
      oHTML = data;
      var oE = document.getElementById("fastlogin_greatings");
      oE.innerHTML = oHTML;
    }
  }
  function recuperapass(){
  	oHTML  = "<h4>Recupera password</h4>";
  	oHTML += "Inserisci il tuo indirizzo e-mail.<br />";
    oHTML += "<input type=\"hidden\" id=\"ecm_URI\" name=\"ecm_URI\" value=\"\" />";
  	oHTML += "<input type=\"edit\" id=\"usr_name\" name=\"usr_name\" value=\"\" style=\"width: 200px;\"/>";
		oHTML += "<input type=\"hidden\" id=\"usr_pass\" name=\"usr_pass\" value=\"sendmypass\" /><br />";
    oHTML += "<p><input type=\"button\" value=\"Invia\" onclick=\"javascript: ValidateFastLogin();\" /></p>";
    var oE = document.getElementById("fastlogin_form");
    oE.innerHTML = "";
    var oE = document.getElementById("fastlogin_greatings");
    oE.innerHTML = oHTML;
    var oE = document.getElementById("usr_name");
    oE.focus();
  }


var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false; 
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox')>=0?true:false; 
var navigatorVersion = navigator.appVersion.replace(/.*?MSIE ([0-9]\.[0-9]).*/g,'$1')/1; 
var exceptMenus = new Array(); 

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function menuHover(oE,eV,idm) {
  isrc = new String(oE.src);
  if(eV.type=="mouseover") {
    oE.src = isrc.replace(".gif","_hover.gif");
    var x = getposOffset(oE, "left");
    var y = getposOffset(oE, "top") + oE.height;
    
    if(!MSIE) x = x - 40;
    
    ShowDiv(idm,x,y);
  }
  if(eV.type=="mouseout") { 
    oE.src = isrc.replace("_hover","");
    setTimeout("HideDiv('"+idm+"')",99);
  }
}

function ShowDiv(idm,x,y){
  var el;
  el = document.getElementById(idm);
  if(el!=undefined){ el.style.left = x+"px"; el.style.top = y+"px"; el.style.display = 'block';}
}

function HideDiv(idm){
  if(array_in(exceptMenus,idm)) return; 
  var el;
  el = document.getElementById(idm);
  if(el!=undefined) el.style.display = '';
}

function array_in(arr,idm) {
  var found = false;
  for(var no=0;no<arr.length;no++){
    if(arr[no]==idm) {
      found = true;
    }
  }
  return found;
}

function array_add(arr,idm){
 arr.push(idm);
}

function moo(idm) {
  if(!array_in(exceptMenus,idm)) array_add(exceptMenus,idm);
}
function mii(idm) {
  exceptMenus = new Array();
  setTimeout("HideDiv('"+idm+"')",300);
}
 
activateMenu = function(nav) {

/* currentStyle restricts the Javascript to IE only */
	if (document.all &&
 document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */

        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {   
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

window.onload= function(){
    activateMenu('vertnav'); 
}

