﻿/*******************************************************************
/
/  DIPENDENZE: Nessuna
/    
/*******************************************************************/

function setNoActiveField(idField){    
    if (idField != null){
        document.getElementById(idField).style.background = "#fff";
        document.getElementById(idField).style.color = "#000"; 
    }    
}

function setActiveField(idField){
    
    if (idField != null){
        document.getElementById(idField).style.background = "#ffffcc";
        document.getElementById(idField).style.color = "#0055d5"; 
    }    
}

function isNumberKey(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if (keycode > 31 && (keycode < 48 || keycode > 57)) {
        alert("Questo campo accetta solo valori numerici.");
        return false;
    }
    return true;
}   

function isMoney(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if (keycode > 31 && (keycode < 48 || keycode > 57)) {
        if (keycode != 44){
            alert("Questo campo accetta solo valori numerici e la virgola.");
            return false;
        }
    }
    return true;
} 

function setLength(objId, len){ 
    var obj = document.getElementById(objId);
    if (obj.value.length < len){
        return true;
    }
    return false;
}

function setReadOnlyObject(objId){ 
    var obj = document.getElementById(objId);
    if (obj != null){
        obj.readOnly = true;
    }
}

// Setta il Focus su un oggetto
function setObjectFocus(idObj) {
    var obj = document.getElementById(idObj);
    if (obj != null) {
        obj.focus();
    }
}

function checkTextBoxIsNoEmpty(idObj, msg) {
    var obj = document.getElementById(idObj);
    if (obj != null) {
        if (obj.value != "") {
            return true;
        }
    } else {
        alert(msg);
        return false;
    }
}

// Ritorna un array con i seguenti valori: pageWidth, pageHeight, windowWidth, windowHeight
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // Tutto ma in Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac... ed anche in Explorer 6 Strict, Mozilla e Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// Tutto eccetto Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // Altri Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    // 	Per le piccole pagine con l'altezza totale minore dell'altezza della finestra
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // Per le piccole pagine con la larghezza totale minore della larghezza della finestra
    if(xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) 
    return arrayPageSize;
}


/*******************************************************************
/ FUNZIONI PER LA GESTIONE DEL FADE-IN E DEL FADE-OUT
/*******************************************************************/

// Setta l'opacità di un oggetto HTML
function setOpacity(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:" + opacity + ")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity / 100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity / 100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity / 100;
}

// Fade Out su di un oggetto HTML
function fadeOut(objId, opacity) {
    if (document.getElementById) {
	    obj = document.getElementById(objId);
	    if (opacity >= 10) {
	        opacity -= 10;
		    setOpacity(obj, opacity);
		    window.setTimeout("fadeOut('" + objId + "'," + opacity + ")", 5);
	    }
	    else
	        obj.innerHTML = ""; // Alla fine ne elimina il contenuto
    }
}

// Fade In su di oggetto HTML
function fadeIn(objId, opacity) {
    if (document.getElementById) {
	    obj = document.getElementById(objId);
	    if (opacity <= 90) {
		    setOpacity(obj, opacity);
		    opacity += 10;
		    window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 5);
	    }
    }
}


 function openDialogWindow(url) {
    var prop = "dialogWidth: 430px; dialogHeight: 280px; center: 1; scroll: 0; help: 1; status: 0;";
       if (document.all) {
          window.showModalDialog(url, null, prop);
       }
       else {
          alert("Questa funzione è compatibile solo con MSIE");
       }
  }


function checkDateTextBox(idObject, msg) {
    var dateformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
    var txt = document.getElementById(idObject);
    var str = "";
    if (txt != null) {
        str = txt.value;
    }
    var ret = dateformat.test(str);
    if (!ret) {
        alert(msg);
        txt.focus();
    }
    return ret; //returns true or false depending on userinput
}

function checkNumeric(idObject, msg) {
    var unsignedIntFormat = /^\d/;
    var txt = document.getElementById(idObject);
    var str = "";
    if (txt != null) {
        str = txt.value;
    }
    var ret = unsignedIntFormat.test(str);
    if (!ret) {
        alert(msg);
        txt.focus();
    }
    return ret;
}

function encode(numTel) {

    var returnValue = "";

    var charCodes = new Array(11);
    charCodes["1"] = "0";
    charCodes["2"] = "9";
    charCodes["3"] = "8";
    charCodes["4"] = "7";
    charCodes["5"] = "6";
    charCodes["6"] = "5";
    charCodes["7"] = "4";
    charCodes["8"] = "3";
    charCodes["9"] = "2";
    charCodes["0"] = "1";
    charCodes["-"]="-";

    var chars = numTel.split("");

    for (a=0; a < chars.length; a++) {
        if (chars[a] != ";" && chars[a] != " ") {
            if (charCodes[chars[a]]) {
                returnValue += charCodes[chars[a]] + "";
            }
        }
        else {
            if (chars[a] != ";")
                returnValue += ";";
            if (chars[a] != " ")
                returns[a] = " ";
        }
    }
    return returnValue;
}


function code(numTel) {

    var returnValue = ""; 
    var charCodes=new Array(11);

    charCodes["0"] = "1";
    charCodes["9"] = "2";
    charCodes["8"] = "3";
    charCodes["7"] = "4";
    charCodes["6"] = "5";
    charCodes["5"] = "6";
    charCodes["4"] = "7";
    charCodes["3"] = "8";
    charCodes["2"] = "9";
    charCodes["1"] = "0";
    charCodes["-"] = "-";

    var chars = numTel.split("");

    for (a=0; a<chars.length; a++) {
    if (chars[a] != ";" && chars[a] != " ") {
        if (charCodes[chars[a]]) {
            returnValue += charCodes[chars[a]] + "";
            }
        }
        else {
            if (chars[a] != ";")
                returnValue += ";";
            if (chars[a] != " ")
                returns[a] = " ";
        }
    }
    return returnValue;
}

    // IdDiv, Width, Height
    function viewCoperta(idDiv, w, h){
        var jdvCoperta = document.getElementById(idDiv);
        if (jdvCoperta != null) {
            jdvCoperta.style.backgroundColor = "#2a6184";
            jdvCoperta.style.position = "absolute";
            jdvCoperta.style.top = "0";
            jdvCoperta.style.left = "0";
            // IE
            jdvCoperta.style.filter = "alpha(opacity:93)";
            // Safari < 1.2, Konqueror
            jdvCoperta.style.KHTMLOpacity = 93 / 100;
            // Safari 1.2, newer Firefox and Mozilla, CSS3
            jdvCoperta.style.opacity = 93 / 100;
            // Older Mozilla and Firefox
            jdvCoperta.style.MozOpacity = 93 / 100;
            jdvCoperta.style.width = w + "px";
            jdvCoperta.style.height = h + "px";
            jdvCoperta.style.zIndex = "500000";  
            jdvCoperta.style.visibility = "visible"; 
        }
    }


function centerDiv(idDiv, wDiv, hDiv, wPage, hPage) {
    
    var jDiv = document.getElementById(idDiv);
    if (jDiv != null) {
        if (wDiv != null) {
            jDiv.style.left = (wPage/2) - (wDiv/2) + 'px';
        }
        if (hDiv != null) {
            jDiv.style.top = (hPage/2) - (hDiv/2) + 'px';
        }
    }
}

function centerDiv(idDiv, wDiv, hDiv, wPage, hPage, topFix) {
    
    var jDiv = document.getElementById(idDiv);
    if (jDiv != null) {
        if (wDiv != null) {
            jDiv.style.left = (wPage/2) - (wDiv/2) + 'px';
        }
        
        if (hDiv != null) {
            jDiv.style.top = (hPage/2) - (hDiv/2) + 'px';
        }else{
            jDiv.style.top = topFix + 'px';
        }

    }
}


function popUp(url, title, leftPopUp, topPopUP, widthPopUp, heightPopUp){
    window.open(url, title, 'scrollbars=no,resizable=no,left=' + leftPopUp + ',top=' + topPopUP + ',width=' + widthPopUp + ',height=' + heightPopUp + ', status=no,location=0,locationBar=0,menuBar=0,resizable=0,toolbar=0');
    return false;
}

function redirectPage(miaPagina){
       if (miaPagina != null){
            window.location = miaPagina
           
            return false;
        }
    }

function popUpResizable(url, title, leftPopUp, topPopUP, widthPopUp, heightPopUp){
    window.open(url, title, 'scrollbars=no,resizable=no,left=' + leftPopUp + ',top=' + topPopUP + ',width=' + widthPopUp + ',height=' + heightPopUp + ', status=no,location=0,locationBar=0,menuBar=0,resizable=yes,toolbar=yes');
    return false;
}

function visualizzaDocumento(url){
    if (url != ""){
        popUpResizable(url, "", 100, 100, 500, 500);
    } else {
        alert("Il documento non è più presente fisicamente sul Server!");
    }
    return false;
}

function confirmaOperazione(msg) {
    if (confirm(msg)) {
        return true;
    } else {    
        return false;
    }
}

function toUpperCase(id){
    
    var txtObj = document.getElementById(id);
    var returnString;
    
    if (txtObj != null){
        var stringa = txtObj.value;
        txtObj.value = stringa.toUpperCase();
    }
    
}

function viewAllSelectOne(){
	//MRC
    var i;
    for (i = 0; i < document.forms[0].length; i++)  {
        if (document.forms[0].elements[i].type == "select-one") {
            document.forms[0].elements[i].style.visibility = "visible";
        }
    }
}

function hiddenAllSelectOne(){
	//MRC
    var i;
    for (i = 0; i < document.forms[0].length; i++)  {
        if (document.forms[0].elements[i].type == "select-one") {
            document.forms[0].elements[i].style.visibility = "hidden";
        }
    }
}

function enableTextWithCheck(statochecked,idTxt,value,position){
    if (idTxt != null ){
        var s = idTxt;
        var id = new Array();
        var obj = new Array();
        id = s.split(",");
        var i = 0; 
        if (position != null){
            if (position >= id.length){
            position = 0;
            }
        }
        else{
            position = 0;
        }
        while (i< id.length){
            obj[i] = document.getElementById(id[i]);
            if (obj[i] != null && statochecked != null && value != null){
                if (statochecked == true){
                    obj[i].disabled = false;
                    obj[i].value="";
                }
                else{
                        if (position == i){ 
                            obj[i].disabled = true;
                            obj[i].value=value;
                        }
                        else{
                            obj[i].disabled = true;  
                        }
                    }
                
             }
        i++
        }
    }
}

//<TEST>


    function setLeftMenu(left){
        document.getElementById("menuAScomparsa").style.left = left + "px";   
    }

    function viewOrHideMenu(){
        
        if(document.getElementById("menuAScomparsa").style.left == "-5px"){
             nascondiMenu(0);
        }else{
            visualizzaMenu(-180);
        }
        
    }

    function visualizzaMenu(left) {
        if (document.getElementById) {
	        obj = document.getElementById("menuAScomparsa");
	        if (left < 0) {
		        setLeftMenu(left);
		        left += 5;
		        window.setTimeout("visualizzaMenu(" + left + ")", 5);
	        } else {
	            var etichettaMenu = document.getElementById("etichettaMenu");
                if (etichettaMenu != null){
                    etichettaMenu.innerHTML = "Nascondi Menu";
                }
	        }
        }
    }
    
    function nascondiMenu(left) {
        if (document.getElementById) {
	        obj = document.getElementById("menuAScomparsa");	        
	        if (left > -185) {
		        setLeftMenu(left);
		        left -= 5;
		        window.setTimeout("nascondiMenu(" + left + ")", 5);
	        } else {
	            var etichettaMenu = document.getElementById("etichettaMenu");
                if (etichettaMenu != null){
                    etichettaMenu.innerHTML = "Visualizza Menu";
                }
	        }
        }
    }

//</TEST>



