_spBodyOnLoadFunctionNames.push("setUserAnchor");
_spBodyOnLoadFunctionNames.push("selectMenuVoice");
_spBodyOnLoadFunctionNames.push("selectMasterMenuVoice");

/* Blocca l'invio della form alla pressione del tasto Enter */
function key(e) {
    var ev = e ? e : event;
    var obj = ev.target ? ev.target : ev.srcElement;
    var keyis = ev.keyCode;
    // Aggiunta esclusione dei link per cui l'enter deve funzionare
    if (keyis == 13) {
        if (!obj.href && ev.preventDefault) { // Mozilla
            ev.preventDefault();
        } else {
            if (!obj.href && "returnValue" in ev) { // IE
                ev.returnValue = false;
            }
        }
    }
}

function setUserAnchor() {
    var aLogin = document.getElementById("Login");
    var aRegistrati = document.getElementById("Registrati");

    if (typeof (_bfSPUserId) != "undefined") {
	    if (aLogin != null) {
	        aLogin.innerHTML = "Logout";
	        aLogin.href = "/it/_layouts/ATM/apps/signout.aspx";
	        aLogin.title = "Logout";
		}
		if (aRegistrati != null) {
	        aRegistrati.innerHTML = "I miei dati";
	        aRegistrati.href = "/it/_layouts/ATM/apps/MyProfile.aspx";
	        aRegistrati.title = "I miei dati";
		}
    }
}

function selectMasterMenuVoice() {
    var currUrl = document.URL;
    var arrA = document.getElementsByTagName("a");

    if (currUrl.indexOf("ImpreseEFornitori") > 0) {
        for (i = 0; i < arrA.length; i++) {
            var elA = arrA[i];
            sUrl = elA.href;
            if (elA.title == "Imprese e fornitori") {
                elA.style.textDecoration = "underline";
                break;
            }
        }
    }

    if (currUrl.indexOf("LavorareInAtm") > 0) {
        for (i = 0; i < arrA.length; i++) {
            var elA = arrA[i];
            sUrl = elA.href;
            if (elA.title == "Lavorare in ATM") {
                elA.style.textDecoration = "underline";
                break;
            }
        }
    }
}

function pressLoginclick(){	
	var i=0;
	var name;
	var arrInput = document.getElementsByTagName("input");
	for (i=0; i< arrInput.length; i++)
	{		
		name = arrInput[i].id;			
		if (name.indexOf('_ctl00_login')>0)
		{
			arrInput[i].click();
			return false;
		}
	}
}

function loginclick(){	
	var i=0;
	var name;
	var arrInput = document.getElementsByTagName("input");
	for (i=0; i< arrInput.length; i++)
	{		
		name = arrInput[i].id;			
		if (name.indexOf('_login_login')>0)
		{
			arrInput[i].click();
			return false;
		}
	}
}

function CenteredPopup(sUrl, width, height)
{
	var left= (screen.width/2) - (width/2)
	var top= (screen.height/2) - (height/2)
	var win = window.open(sUrl,"Window1","menubar=no,width=" + width + ", height=" + height + ",toolbar=no" + ",top=" + top + ",left=" + left);
	win.target='new';
}


document.onkeypress = key;
document.forms[0].onkeypress = key;