﻿function f_Submit(id) {
    document.getElementById(id).submit();
}
function alterNate(e) {
    if (!e.base) e.base = e.value
    if (e.value == e.base) e.value = "";
    else if (e.value == "") e.value = e.base;
}
function f_ValidateNewUser(l) {
    var v1 = document.getElementById('fidnu_email').value.replace(' ', ''),
        v2 = document.getElementById('fidnu_un').value.replace(' ', ''),
        v3 = document.getElementById('fidnu_password').value.replace(' ', ''),
        v4 = document.getElementById('fidnu_passwordc').value.replace(' ', ''),
        v5 = document.getElementById('fidnu_name').value.replace(' ', ''),
        v6 = document.getElementById('fidnu_lastname').value.replace(' ', ''),
        v7 = document.getElementById('fidnu_soc').value.replace(' ', ''),
        v8 = document.getElementById('fidnu_phone').value.replace(' ', ''),
        m;
    
    if (v1 == '')
        m = l == 'en' ? 'The field Email is mandatory' : 'Il campo Email è obbligatorio';
    else if (!f_CheckEmail(v1))
        m = l == 'en' ? 'The selected Email is invalid' : 'La Mail selezionata non è valida';
    else if (v2 == '')
        m = l == 'en' ? 'The field User Name is mandatory' : 'Il campo User Name è obbligatorio';
    else if (v3 == '')
        m = l == 'en' ? 'The field Password is mandatory' : 'Il campo Password è obbligatorio';
    else if (v3.length < 6)
        m = l == 'en' ? 'The Password must be at leas 6 characters' : 'Il campo Password deve contenere almeno 6 caratteri';
    else if (v4 == '')
        m = l == 'en' ? 'The field Confirm Password is mandatory' : 'Il campo Conferma Password è obbligatorio';
    else if (v3!=v4)
        m = l == 'en' ? 'Password and Confirm Password don\'t match' : 'I campi Password e Conferma Password non corrispondono';
    else if (v5 == '')
        m = l == 'en' ? 'The field First Name is mandatory' : 'Il campo Nome è obbligatorio';
    else if (v6 == '')
        m = l == 'en' ? 'The field Last Name is mandatory' : 'Il campo Cognome è obbligatorio';
    else if (v7 == '')
        m = l == 'en' ? 'The field Company is mandatory' : 'Il campo Azienda è obbligatorio';
    else if (v8 == '')
        m = l == 'en' ? 'The field Phone is mandatory' : 'Il campo Telefono è obbligatorio';
        
    if (!m) return true;
    alert(m);
    return false;
}
function f_ProtectedLink(t) {
    if(confirm(t)) alert('Andiamo');
}
function f_CheckEmail(email) {
    var valid = "y";
    if (email != "") {
        if (email.length < 7 || email.indexOf("@.") != -1 || email.indexOf("-.") != -1 || email.indexOf("_.") != -1 ||
                email.indexOf("..") != -1 || email.indexOf("._") != -1 || email.indexOf(".-") != -1 ||
                email.indexOf(".@") != -1 || email.indexOf("@-") != -1 || email.indexOf("@_") != -1 ||
                email.indexOf("@") != email.lastIndexOf("@") || email.indexOf("@") == -1 || email.indexOf(".") == -1 ||
                (email.length - (email.lastIndexOf(".") + 1)) < 2)
            return false;
        else {
            a = "abcdefghijklmnopqrstuvwxyz0123456789@-_.";
            b = 0;
            while (b < email.length) {
                if (a.indexOf(email.charAt(b)) == -1) return false;
                b = b + 1;
            }
        }
    }
    rx = /^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z][a-z]$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.aero$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.biz$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.coop$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.com$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.edu$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.gov$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.info$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.int$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.mil$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.museum$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.name$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.net$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.org$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.pro$/i;
    if (rx.test(email)) {
        rx = /^[a-z0-9_]/i;
        if ((rx.test(email))) return true;
    }
    return false;
}



