//FUNZIONE PER MENU TENDINA
//parametri: il contenitore del menu
//associa le classi "hafigli" agli elementi di una lista che contengono una sottolista
//associa la classe "active" agli elementi attivati dal mouseover e mostra la lista sottostante
function rollmenu(container) {
    var arr = document.getElementById(container).getElementsByTagName("li");
    var i;
    for (i=0; i<arr.length; i++) {

         if (arr[i].getElementsByTagName("ul")[0]) {
            arr[i].getElementsByTagName("a")[0].className += " hafigli ";        
        }

        arr[i].onmouseover = function() {
            this.getElementsByTagName("a")[0].className += " active ";
            if (this.getElementsByTagName("ul")[0]) this.getElementsByTagName("ul")[0].style.display="block";
        }
        arr[i].onmouseout = function() {
            this.getElementsByTagName("a")[0].className=this.getElementsByTagName("a")[0].className.replace("active","");            
            if (this.getElementsByTagName("ul")[0]) this.getElementsByTagName("ul")[0].style.display="none";
        }
    }
}

//SIMULA LA PSEUDO-CLASSE "FOCUS" - v.1.1 (ora può avere la propria classe, ne viene aggiunta un'altra)
function setFocus(elemento) {
    elemento.className+=" focus";
}

function unsetFocus(elemento) {
    elemento.className=elemento.className.replace('focus', '');
}

//FUNZIONE PER MOSTRARE I LINK ATTIVI
// richiamare la funzione nel tag body con onLoad e passare come parametro l'id del contenitore del menu
// non serve assegnare nessun valore particolare all'html.
// non funziona coi link indicizzabili ma tanto nel menu di navigazione non ci sono le categorie ;)

function currentlink(contenitore) {

    var stringa_get = document.location.href;        
    var menu = new Array();        
    menu = document.getElementById(contenitore).getElementsByTagName("a");
    if (stringa_get.match("php")) { //cioè se sono nel caso www.nomedominio.com/qualcosa.PHP <--
        var i;
        for (i=0; i<menu.length; i++) {            
            if (stringa_get.match(menu[i].href)) menu[i].className = "active";
        }
    } else menu[0].className = "active";
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


var wiN;

function openWin(nomeFile,nomeFinestra,parametri,larghezza,altezza,barre,ridimensione,centrato) {

    option="toolbar=no,width=" + larghezza + ",height=" + altezza +",resizable=" + ridimensione + ",scrollbars=" + barre
    if (centrato=='yes') {
        LeftPosition = (screen.width) ? (screen.width-larghezza)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-altezza)/2 : 0;
        option=option + ",top="+TopPosition+",left="+LeftPosition
    }
    wiN = window.open(nomeFile + "?titolo=" + nomeFinestra + parametri,nomeFinestra,option);
}

 

 // Spam-proof email by deanq.com
function vmemail(who,subject,domain,body) {
  if (!who) var who = "info";
  if (!domain) var domain = "sito.com";
  if (!subject) var subject = "Richiesta Informazioni";
  if (!body) var body = " ";
  eval("location.href='mailto:" + who + "@" + domain + "?subject=" + subject + "&body=" + body + "'");
}


function cambiaInfoUtente() {

    error = false;
    msgError="";

    nomeCognome = document.new_customer.txtNomeCognome.value;
    indirizzo = document.new_customer.txtIndirizzo.value;
    citta = document.new_customer.txtCitta.value;
    cap = document.new_customer.txtCap.value;
    provincia = document.new_customer.selProvincia.value;
    nazione = document.new_customer.txtNazione.value;
    telefono = document.new_customer.txtTelefono.value;
    email = document.new_customer.txtEmail.value;
    
    if (nomeCognome == "") {
        error = true;
        msgError = "Compilare il campo 'Nome Cognome'\n"+msgError;
    }
    if (indirizzo == "") {
        error = true;
        msgError = "Compilare il campo 'Indirizzo'\n"+msgError;
    }
    if (citta == "") {
        error = true;
        msgError = "Compilare il campo 'Città'\n"+msgError;
    }
    if (cap == "") {
        error = true;
        msgError = "Compilare il campo 'Cap'\n"+msgError;
    }
    if (provincia == "") {
        error = true;
        msgError = "Compilare il campo 'Provincia'\n"+msgError;
    }
    if (nazione == "") {
        error = true;
        msgError = "Compilare il campo 'Nazione'\n"+msgError;
    }
    if (telefono == "") {
        error = true;
        msgError = "Compilare il campo 'Telefono'\n"+msgError;
    }
    if (email == "") {
        error = true;
        msgError = "Compilare il campo 'Email'\n"+msgError;
    }
    
    if (!error) {
        // nn ci sn errori
        if (confirm("Confermi i dati inseriti?")) {
            document.new_customer.azione.value = "salva";
            document.new_customer.submit();
        }
    } else {
        alert(msgError);
    }

    return false;
}


function controllaPermessi() {
    if ((window.opener!==null) && (window.opener!==undefined) ) {
    } else {
        window.location.href = "http://www.blicomm.net";
    }
}

function paginateSize(pagina) {
        
    var paginaNumber = 1;
    var paginaSize = 10;
    
    if($("#selPageSize").val() != "") {
        paginaSize = $("#selPageSize").val();
    }
    
    if($("#selPageSize").val() != "") {
        document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
        //$("#frmPaginate").submit(function() {alert('ok')});
    }
    return true;
}

function paginate(pagina) {
        
        var paginaNumber = 1;
        var paginaSize = 10;
        
        if($("#page").val() != "") {
            paginaNumber = $("#page").val();
        }
        
        if($("#selPageSize").val() != "") {
            paginaSize = $("#selPageSize").val();
        }
        
        if($("#page").val() != "") {
            document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
            //$("#frmPaginate").submit(function() {alert('ok')});
        }
        return true;
    }
