function t() {
    var itype = null;
    var ihTypes = document.getElementsByName('ihType');
    for (var i = 0; i < ihTypes.length; i++) {
        if (ihTypes[i].checked) { itype = ihTypes[i].value; break; }
    }
    var a = parseInt(itype);
    var b = (a == 1) ? 'none' : 'block'; var c = (a == 1) ? 'block' : 'none';
    document.getElementById('accn').style.display = b;
    document.getElementById('hn').style.display = c;
    if (a == 1)
        document.getElementsByName('account')[0].value = "";

    if (a == 2)
        document.getElementsByName('hostname')[0].value = "";
}
function secTypeChange(e) {
    var v = parseInt(document.getElementsByName('secType')[0].options[document.getElementsByName('secType')[0].selectedIndex].value);
    if (v == 0) {
        document.getElementsByName('secKey')[0].value = "";
        document.getElementById('password-field').style.display = "none";
    } else {
        document.getElementById('password-field').style.display = "block";
    }
}
function ip() {
    var iptype = null;
    var ipTypes = document.getElementsByName('ipAddrMode');
    for (var i = 0; i < ipTypes.length; i++) {
        if (ipTypes[i].checked) { iptype = ipTypes[i].value; break; }
    }

    a = parseInt(iptype);
    var e = document.getElementById('ip-static-settings');
    var b = (a == 1) ? 'none' : 'block';

    e.style.display = b;
}
function e(a) {
    return (a.replace(/^\s+|\s+$/gm, '')).length;
}
function h(a) {
    try {
        return (new RegExp(/[A-Fa-f0-9]*/)).exec(a)[0].toString().length == a.toString().length
    } catch (e) { return false; }
}
function v() {
    var r = false;
    try {
        if (e(document.getElementsByName('ssid')[0].value) < 1) {
            alert('SSID cannot be empty');
            return false;
        }
        var ss = document.getElementsByName('secType')[0];
        var st = parseInt(ss.options[ss.selectedIndex].value, 10);
        var p = document.getElementsByName('secKey')[0].value;
        var l = p.length;
        var m = "";
        switch (st) {
            case 0:
                r = l == 0;
                break;
            case 1:
            case 2:
                r = (h(p) && l == 64) || (l > 7 && l < 64);
                m = st == 1 ? ' WPA' : ' WPA2';
                break;
            case 3:
                r = (h(p) && (l == 10 || l == 26 || l == 32 || l == 58)) || (l == 5 || l == 13 || l == 16 || l == 29)
                m = ' WEP';
                break;
        }
        if (!r) { alert('Invalid' + m + ' password.'); return r; };
        r = false;
        if (document.querySelector('input[name="ihType"]:checked').value == 1) {
            if (!(r = (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(:([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$)?$/).test(document.getElementsByName('hostname')[0].value))) {
                alert('Hostname must be a valid IP Address.');
            }
        } else {
            if (e(document.getElementsByName('account')[0].value) > 0)
                r = true;
            else alert('Account cannot be empty.');
        }
    } catch (er) {
        r = false;
        alert('Error, try again.');
    }
    return r;
}