function pageLoad() {
    for (var x = 0; x < WiFiEncryption.encryptionID.length; x++) {
        if (WiFiEncryption.encryptionSelected[x] === 1) {
            $('#encryptionTypes').val(WiFiEncryption.encryptionID[x]);
        }
    }
    for (var y = 0; y < WiFiAuthentication.authenticationID.length; y++) {
        if (WiFiAuthentication.authenticationSelected[y] === 1) {
            $('#authenticationTypes').val(WiFiAuthentication.authenticationID[y]);
        }
    }
};

function setLanguage() {
    var headID = document.getElementsByTagName("head")[0];
    var newScript10 = document.createElement('script');
    newScript10.type = 'text/javascript';
    newScript10.async = false;

    for (var i = 0; i < RegionAll.regionSelected.length; i++) {
        if (RegionAll.regionSelected[i] == 1) {
            switch (i + 1) {
                case 1:
                case 12:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_portuguese();
                    }, false)
                    newScript10.src = "/includes/js/wifi_portuguese.min.js";
                    headID.appendChild(newScript10);
                    break;

                //English 
                case 2:
                case 9:
                case 10:
                    $('#license_key').text("License Key: " + InsightCoreInfo.Value[0]);
                    break;

                case 3:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_dutch();
                    }, false)
                    newScript10.src = "/includes/js/wifi_dutch.min.js";
                    headID.appendChild(newScript10);
                    break;

                case 4:
                case 11:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_french();
                    }, false)
                    newScript10.src = "/includes/js/wifi_french.min.js";
                    headID.appendChild(newScript10);
                    break;

                case 5:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_german();
                    }, false)
                    newScript10.src = "/includes/js/wifi_german.min.js";
                    headID.appendChild(newScript10);
                    break;

                case 6:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_italian();
                    }, false)
                    newScript10.src = "/includes/js/wifi_italian.min.js";
                    headID.appendChild(newScript10);
                    break;

                case 7:
                case 8:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_spanish();
                    }, false)
                    newScript10.src = "/includes/js/wifi_spanish.min.js";
                    headID.appendChild(newScript10);
                    break;

                case 13:
                    newScript10.addEventListener('load', function(evt) {
                        convert_for_chinese();
                    }, false)
                    newScript10.src = "/includes/js/wifi_chinese.min.js";
                    headID.appendChild(newScript10);
                    break;

                default:
                    break;
            }
        }
    }
};

function checkSecurity() {
    $('#authenticationSelection').val($('#authenticationTypes').val());
    $('#encryptionSelection').val($('#encryptionTypes').val());
    $('#user_ssid').val($('#ssid').val());
    $('#user_pw').val($('#wifi_password').val());
    $('#securitysubmit').val(1);
    $('#ipsubmit').val(0);

    var numCheck = $('#spinEdit37').val();

    $("#iptype1").val($("#static_dynamic_b").val());

    $("#ipaddressfirst1").val($('#spinEdit17').val());
    $("#ipaddresssecond1").val($('#spinEdit18').val());
    $("#ipaddressthird1").val($('#spinEdit19').val());
    $("#ipaddressfourth1").val($('#spinEdit20').val());

    $("#subnetmaskfirst1").val($('#spinEdit21').val());
    $("#subnetmasksecond1").val($('#spinEdit22').val());
    $("#subnetmaskthird1").val($('#spinEdit23').val());
    $("#subnetmaskfourth1").val($('#spinEdit24').val());

    $("#gatewayfirst1").val($('#spinEdit25').val());
    $("#gatewaysecond1").val($('#spinEdit26').val());
    $("#gatewaythird1").val($('#spinEdit27').val());
    $("#gatewayfourth1").val($('#spinEdit28').val());

    if (numCheck != 'NaN') {
        $("#dnsfirst1").val($('#spinEdit37').val());
        $("#dnssecond1").val($('#spinEdit38').val());
        $("#dnsthird1").val($('#spinEdit39').val());
        $("#dnsfourth1").val($('#spinEdit40').val());
    }
    else {
        $("#dnsfirst1").val(127);
        $("#dnssecond1").val(0);
        $("#dnsthird1").val(0);
        $("#dnsfourth1").val(1);
    }
    document.cont_wifi_security.submit();
};

function runUpdates() {
    var decimal_location = WIN_IP_wifi_info[1].indexOf(".", 0);
    var next = WIN_IP_wifi_info[1].indexOf(".", (decimal_location + 1));
    var last = WIN_IP_wifi_info[1].indexOf(".", (next + 1));

    var subnet_decimal_location = WIN_IP_wifi_info[2].indexOf(".", 0);
    var subnet_next = WIN_IP_wifi_info[2].indexOf(".", (subnet_decimal_location + 1));
    var subnet_last = WIN_IP_wifi_info[2].indexOf(".", (subnet_next + 1));

    var gateway_decimal_location = WIN_IP_wifi_info[3].indexOf(".", 0);
    var gateway_next = WIN_IP_wifi_info[3].indexOf(".", (gateway_decimal_location + 1));
    var gateway_last = WIN_IP_wifi_info[3].indexOf(".", (gateway_next + 1));

    var dns_decimal_location = WIN_IP_wifi_info[4].indexOf(".", 0);
    var dns_next = WIN_IP_wifi_info[4].indexOf(".", (dns_decimal_location + 1));
    var dns_last = WIN_IP_wifi_info[4].indexOf(".", (dns_next + 1));

    var dhcp_decimal_location = WIN_IP_wifi_info[5].indexOf(".", 0);
    var dhcp_next = WIN_IP_wifi_info[5].indexOf(".", (dhcp_decimal_location + 1));
    var dhcp_last = WIN_IP_wifi_info[5].indexOf(".", (dhcp_next + 1));

    $('#spinEdit17').spinedit();
    $('#spinEdit18').spinedit();
    $('#spinEdit19').spinedit();
    $('#spinEdit20').spinedit();
    $('#spinEdit21').spinedit();
    $('#spinEdit22').spinedit();
    $('#spinEdit23').spinedit();
    $('#spinEdit24').spinedit();
    $('#spinEdit25').spinedit();
    $('#spinEdit26').spinedit();
    $('#spinEdit27').spinedit();
    $('#spinEdit28').spinedit();
    $('#spinEdit29').spinedit();
    $('#spinEdit30').spinedit();
    $('#spinEdit31').spinedit();
    $('#spinEdit32').spinedit();

    $('#spinEdit37').spinedit();
    $('#spinEdit38').spinedit();
    $('#spinEdit39').spinedit();
    $('#spinEdit40').spinedit();

    $('#spinEdit17').spinedit('setValue', WIN_IP_wifi_info[1].slice(0, decimal_location));
    $('#spinEdit17').spinedit('setMinimum', 0);
    $('#spinEdit17').spinedit('setMaximum', 255);
    $('#spinEdit17').spinedit('setStep', 1);

    $('#spinEdit18').spinedit('setValue', WIN_IP_wifi_info[1].slice((decimal_location + 1), next));
    $('#spinEdit18').spinedit('setMinimum', 0);
    $('#spinEdit18').spinedit('setMaximum', 255);
    $('#spinEdit18').spinedit('setStep', 1);

    $('#spinEdit19').spinedit('setValue', WIN_IP_wifi_info[1].slice((next + 1), last));
    $('#spinEdit19').spinedit('setMinimum', 0);
    $('#spinEdit19').spinedit('setMaximum', 255);
    $('#spinEdit19').spinedit('setStep', 1);

    $('#spinEdit20').spinedit('setValue', WIN_IP_wifi_info[1].slice(last + 1));
    $('#spinEdit20').spinedit('setMinimum', 0);
    $('#spinEdit20').spinedit('setMaximum', 255);
    $('#spinEdit20').spinedit('setStep', 1);

    $('#spinEdit21').spinedit('setValue', WIN_IP_wifi_info[2].slice(0, subnet_decimal_location));
    $('#spinEdit21').spinedit('setMinimum', 0);
    $('#spinEdit21').spinedit('setMaximum', 255);
    $('#spinEdit21').spinedit('setStep', 1);

    $('#spinEdit22').spinedit('setValue', WIN_IP_wifi_info[2].slice((subnet_decimal_location + 1), subnet_next));
    $('#spinEdit22').spinedit('setMinimum', 0);
    $('#spinEdit22').spinedit('setMaximum', 255);
    $('#spinEdit22').spinedit('setStep', 1);

    $('#spinEdit23').spinedit('setValue', WIN_IP_wifi_info[2].slice((subnet_next + 1), subnet_last));
    $('#spinEdit23').spinedit('setMinimum', 0);
    $('#spinEdit23').spinedit('setMaximum', 255);
    $('#spinEdit23').spinedit('setStep', 1);

    $('#spinEdit24').spinedit('setValue', WIN_IP_wifi_info[2].slice(subnet_last + 1));
    $('#spinEdit24').spinedit('setMinimum', 0);
    $('#spinEdit24').spinedit('setMaximum', 255);
    $('#spinEdit24').spinedit('setStep', 1);

    $('#spinEdit25').spinedit('setValue', WIN_IP_wifi_info[3].slice(0, gateway_decimal_location));
    $('#spinEdit25').spinedit('setMinimum', 0);
    $('#spinEdit25').spinedit('setMaximum', 255);
    $('#spinEdit25').spinedit('setStep', 1);

    $('#spinEdit26').spinedit('setValue', WIN_IP_wifi_info[3].slice((gateway_decimal_location + 1), gateway_next));
    $('#spinEdit26').spinedit('setMinimum', 0);
    $('#spinEdit26').spinedit('setMaximum', 255);
    $('#spinEdit26').spinedit('setStep', 1);

    $('#spinEdit27').spinedit('setValue', WIN_IP_wifi_info[3].slice((gateway_next + 1), gateway_last));
    $('#spinEdit27').spinedit('setMinimum', 0);
    $('#spinEdit27').spinedit('setMaximum', 255);
    $('#spinEdit27').spinedit('setStep', 1);

    $('#spinEdit28').spinedit('setValue', WIN_IP_wifi_info[3].slice(gateway_last + 1));
    $('#spinEdit28').spinedit('setMinimum', 0);
    $('#spinEdit28').spinedit('setMaximum', 255);
    $('#spinEdit28').spinedit('setStep', 1);

    if (WIN_IP_wifi_info[5] == '') {
        $('#spinEdit29').spinedit('setValue', 0);
        $('#spinEdit29').spinedit('setMinimum', 0);
        $('#spinEdit29').spinedit('setMaximum', 255);
        $('#spinEdit29').spinedit('setStep', 1);

        $('#spinEdit30').spinedit('setValue', 0);
        $('#spinEdit30').spinedit('setMinimum', 0);
        $('#spinEdit30').spinedit('setMaximum', 255);
        $('#spinEdit30').spinedit('setStep', 1);

        $('#spinEdit31').spinedit('setValue', 0);
        $('#spinEdit31').spinedit('setMinimum', 0);
        $('#spinEdit31').spinedit('setMaximum', 255);
        $('#spinEdit31').spinedit('setStep', 1);

        $('#spinEdit32').spinedit('setValue', 0);
        $('#spinEdit32').spinedit('setMinimum', 0);
        $('#spinEdit32').spinedit('setMaximum', 255);
        $('#spinEdit32').spinedit('setStep', 1);
    }
    else {
        $('#spinEdit29').spinedit('setValue', WIN_IP_wifi_info[5].slice(0, dhcp_decimal_location));
        $('#spinEdit29').spinedit('setMinimum', 0);
        $('#spinEdit29').spinedit('setMaximum', 255);
        $('#spinEdit29').spinedit('setStep', 1);

        $('#spinEdit30').spinedit('setValue', WIN_IP_wifi_info[5].slice((dhcp_decimal_location + 1), dhcp_next));
        $('#spinEdit30').spinedit('setMinimum', 0);
        $('#spinEdit30').spinedit('setMaximum', 255);
        $('#spinEdit30').spinedit('setStep', 1);

        $('#spinEdit31').spinedit('setValue', WIN_IP_wifi_info[5].slice((dhcp_next + 1), dhcp_last));
        $('#spinEdit31').spinedit('setMinimum', 0);
        $('#spinEdit31').spinedit('setMaximum', 255);
        $('#spinEdit31').spinedit('setStep', 1);

        $('#spinEdit32').spinedit('setValue', WIN_IP_wifi_info[5].slice(dhcp_last + 1));
        $('#spinEdit32').spinedit('setMinimum', 0);
        $('#spinEdit32').spinedit('setMaximum', 255);
        $('#spinEdit32').spinedit('setStep', 1);
    }

    $('#spinEdit37').spinedit('setValue', WIN_IP_wifi_info[4].slice(0, dns_decimal_location));
    $('#spinEdit37').spinedit('setMinimum', 0);
    $('#spinEdit37').spinedit('setMaximum', 255);
    $('#spinEdit37').spinedit('setStep', 1);

    var numCheck = $('#spinEdit37').val();

    if (numCheck != 'NaN') {
        $('#spinEdit38').spinedit('setValue', WIN_IP_wifi_info[4].slice((dns_decimal_location + 1), dns_next));
        $('#spinEdit39').spinedit('setValue', WIN_IP_wifi_info[4].slice((dns_next + 1), dns_last));
        $('#spinEdit40').spinedit('setValue', WIN_IP_wifi_info[4].slice(dns_last + 1));
    }
    else {
        $("#spinEdit37").val(127);
        $("#spinEdit38").val(0);
        $("#spinEdit39").val(0);
        $("#spinEdit40").val(1);
    }

    $('#spinEdit38').spinedit('setMinimum', 0);
    $('#spinEdit38').spinedit('setMaximum', 255);
    $('#spinEdit38').spinedit('setStep', 1);

    $('#spinEdit39').spinedit('setMinimum', 0);
    $('#spinEdit39').spinedit('setMaximum', 255);
    $('#spinEdit39').spinedit('setStep', 1);

    $('#spinEdit40').spinedit('setMinimum', 0);
    $('#spinEdit40').spinedit('setMaximum', 255);
    $('#spinEdit40').spinedit('setStep', 1);

    if (WIN_IP_wifi_info[0] == 1) {
        $("#dhcp_server1").show();
        $("#dns1").hide();
        $('#static_b').removeClass("btn btn-warning").addClass("btn btn-default");
        $('#dynamic_b').removeClass("btn btn-default").addClass("btn btn-warning");
        $('#static_dynamic_b').val(1);
        $('#specific_server_b').removeClass("btn btn-warning").addClass("btn btn-default");
        $('#dhcp_auto_b').removeClass("btn btn-default").addClass("btn btn-warning");
        $('#dhcp_server_b').val(1);
    }
    else {
        $("#dhcp_server1").hide();
        $("#dns1").show();
        $('#static_b').removeClass("btn btn-default").addClass("btn btn-warning");
        $('#dynamic_b').removeClass("btn btn-warning").addClass("btn btn-default");
        $('#static_dynamic_b').val(0);
        $('#specific_server_b').removeClass("btn btn-default").addClass("btn btn-warning");
        $('#dhcp_auto_b').removeClass("btn btn-warning").addClass("btn btn-default");
        $('#dhcp_server_b').val(0);
    }

    $('#mac_b').text("MAC: " + WIN_IP_wifi_info[6]);

    if ($('#static_dynamic_b').val() == 1) {
        $("INPUT[type=text]").attr("disabled", "disabled");
        $("INPUT[type=text]").css("background-color", "#999999");
        $('#spinEdit17').spinedit('setStep', 0);
        $('#spinEdit18').spinedit('setStep', 0);
        $('#spinEdit19').spinedit('setStep', 0);
        $('#spinEdit20').spinedit('setStep', 0);
        $('#spinEdit21').spinedit('setStep', 0);
        $('#spinEdit22').spinedit('setStep', 0);
        $('#spinEdit23').spinedit('setStep', 0);
        $('#spinEdit24').spinedit('setStep', 0);
        $('#spinEdit25').spinedit('setStep', 0);
        $('#spinEdit26').spinedit('setStep', 0);
        $('#spinEdit27').spinedit('setStep', 0);
        $('#spinEdit28').spinedit('setStep', 0);
        $('#spinEdit29').spinedit('setStep', 0);
        $('#spinEdit30').spinedit('setStep', 0);
        $('#spinEdit31').spinedit('setStep', 0);
        $('#spinEdit32').spinedit('setStep', 0);
    }
    $("#dns1 :input").attr("disabled", false);
    $("#dns1 :input").css("background-color", "#FFFFFF");
};

function checkEthernetChange() {
    var staticDynamicBSide = $('#static_dynamic_b').val();
    var dhcpDNSBSide = $('#dhcp_server_b').val();

    staticDynamicBSide = parseInt(staticDynamicBSide);
    dhcpDNSBSide = parseInt(dhcpDNSBSide);

    if (staticDynamicBSide) {
        $("INPUT[type=text]").attr("disabled", "disabled");
        $("INPUT[type=text]").css("background-color", "#999999");
        $('#spinEdit17').spinedit('setStep', 0);
        $('#spinEdit18').spinedit('setStep', 0);
        $('#spinEdit19').spinedit('setStep', 0);
        $('#spinEdit20').spinedit('setStep', 0);
        $('#spinEdit21').spinedit('setStep', 0);
        $('#spinEdit22').spinedit('setStep', 0);
        $('#spinEdit23').spinedit('setStep', 0);
        $('#spinEdit24').spinedit('setStep', 0);
        $('#spinEdit25').spinedit('setStep', 0);
        $('#spinEdit26').spinedit('setStep', 0);
        $('#spinEdit27').spinedit('setStep', 0);
        $('#spinEdit28').spinedit('setStep', 0);
        $('#spinEdit29').spinedit('setStep', 0);
        $('#spinEdit30').spinedit('setStep', 0);
        $('#spinEdit31').spinedit('setStep', 0);
        $('#spinEdit32').spinedit('setStep', 0);
        $("#dns1 :input").attr("disabled", false);
        $("#dns1 :input").css("background-color", "#FFFFFF");
    }
    else {
        $("INPUT[type=text]").attr("disabled", false);
        $("INPUT[type=text]").css("background-color", "#FFFFFF");
        $('#spinEdit17').spinedit('setStep', 1);
        $('#spinEdit18').spinedit('setStep', 1);
        $('#spinEdit19').spinedit('setStep', 1);
        $('#spinEdit20').spinedit('setStep', 1);
        $('#spinEdit21').spinedit('setStep', 1);
        $('#spinEdit22').spinedit('setStep', 1);
        $('#spinEdit23').spinedit('setStep', 1);
        $('#spinEdit24').spinedit('setStep', 1);
        $('#spinEdit25').spinedit('setStep', 1);
        $('#spinEdit26').spinedit('setStep', 1);
        $('#spinEdit27').spinedit('setStep', 1);
        $('#spinEdit28').spinedit('setStep', 1);
        $('#spinEdit29').spinedit('setStep', 1);
        $('#spinEdit30').spinedit('setStep', 1);
        $('#spinEdit31').spinedit('setStep', 1);
        $('#spinEdit32').spinedit('setStep', 1);
    }

    if (dhcpDNSBSide) {
        $("#dns1").hide();
    }
    else {
        $("#dns1").show();
    }
};

function checkInputs() {
    var numCheck = $('#spinEdit37').val();
    var ipAddress;
    var staticDynamicBSide = $('#static_dynamic_b').val();
    var e, i;

    staticDynamicBSide = parseInt(staticDynamicBSide);
    $("#iptype1").val($("#static_dynamic_b").val());

    $("#ipaddressfirst1").val($('#spinEdit17').val());
    $("#ipaddresssecond1").val($('#spinEdit18').val());
    $("#ipaddressthird1").val($('#spinEdit19').val());
    $("#ipaddressfourth1").val($('#spinEdit20').val());

    $("#subnetmaskfirst1").val($('#spinEdit21').val());
    $("#subnetmasksecond1").val($('#spinEdit22').val());
    $("#subnetmaskthird1").val($('#spinEdit23').val());
    $("#subnetmaskfourth1").val($('#spinEdit24').val());

    $("#gatewayfirst1").val($('#spinEdit25').val());
    $("#gatewaysecond1").val($('#spinEdit26').val());
    $("#gatewaythird1").val($('#spinEdit27').val());
    $("#gatewayfourth1").val($('#spinEdit28').val());

    if (numCheck != 'NaN') {
        $("#dnsfirst1").val($('#spinEdit37').val());
        $("#dnssecond1").val($('#spinEdit38').val());
        $("#dnsthird1").val($('#spinEdit39').val());
        $("#dnsfourth1").val($('#spinEdit40').val());
    }
    else {
        $("#dnsfirst1").val(127);
        $("#dnssecond1").val(0);
        $("#dnsthird1").val(0);
        $("#dnsfourth1").val(1);
    }
    
    $('#authenticationSelection').val($('#authenticationTypes').val());
    $('#encryptionSelection').val($('#encryptionTypes').val());
    $('#user_ssid').val($('#ssid').val());
    $('#user_pw').val($('#wifi_password').val());

    for (i = 0; e = document.forms[0].elements[i]; i++) {
        if (e.type == 'hidden') {
            if (e.value === 'NaN') {
                $('#invalidAddressModal').modal();
                return;
            }
        }
    }

    ipAddress = $("#ipaddressfirst1").val() + $("#ipaddresssecond1").val() + $("#ipaddressthird1").val() + $("#ipaddressfourth1").val();

    if ((ipAddress === "0000") && !(staticDynamicBSide)) {
        $('#invalidAddressModal').modal();
    }
    else {
        $('#ipAddressChangeModal').modal();
    }
};

function wifiSubmit() {
    $('#ipsubmit').val(1);
    $('#securitysubmit').val(0);
    document.cont_wifi_security.submit();
};

