
var tempControllerVersion = 2;

function startupWizard() {  // 
    console.log('startupWizard &&&&&&&&&&&&&&&&&&&&&&&&&&');

    $('.ds18b20Popup-body').empty();
    ds18b20Popup.style.display = "block";
    document.querySelector("body").style.overflow = 'hidden';

    $('.ds18b20PopupHeader').empty();
    $(".ds18b20PopupHeader").append("Robo-Tank Startup Wizard");
    
    $(".ds18b20Popup-body").append(
        `<p>&nbsp;</p>
        <p class="h1">Welcome to Robo-Tank!</p>
        <p></p>
        <p style="text-align: center;">
            This is the offical beta app for the Robo-Tank aquarium controller, if you don't own Robo-Tank you are required to pay
            a license fee, otherwise feel free to use it.
        <p>
        <p style="text-align: center;">
            Sorry, currently I'm unable to give the software away, this involves a lot of time, if I don't generate income this can't
            happen. If you do need a license you can use the donation links at the end of the setup wizard, there is no set fee
            right now.
        </p>
        <p style="text-align: center;">
            At this time the Robo-Tank app is in beta testing as more features come online, you should take extra precautions and fully test
            the features you use before running on a live tank. Overall the app is running well but you should procede with caution.
        </p>
        <div class='widgetButtonBox' style="margin-top:-30px;">
            <button class='button _wide' style='margin-top:40px;' type='button' onclick='emailsForm()'>I Agree</button>
        </div>`);
}

function emailsForm() {  // 
    console.log('emailsForm &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    update_ds18b20();

    $('.ds18b20Popup-body').empty();    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Enter an administrative email address, if you forgot your login you can retrieve it through this address.</p>\
        <br>\
        <div class="container">\
            <form class="row">\
                <label class="col-lg-3 label" for="adminEmail">Admin Email:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="text" id="adminEmail" name="adminEmail" value=' + adminEmail[0] + '>\
            </form>\
        </div>\
        <p></p>\
        <p class="h2">Enter up to 3 email addresses for alerts.</p>\
        <br>\
        <div class="container">\
            <form class="row">\
                <label class="col-lg-3 label" for="email1">Email 1:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="text" id="email1" name="email1" value=' + email1[0] + '>\
            </form>\
            <form class="row">\
                <label class="col-lg-3 label" for="email2">Email 2:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="text" id="email2" name="email2" value=' + email2[0] + '>\
            </form>\
            <form class="row">\
                <label class="col-lg-3 label" for="email3">Email 3:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="text" id="email3" name="email3" value=' + email3[0] + '>\
            </form>\
        </div>\
        <div class="col-lg-3 label"></div>\
        <div class="col-lg-7 passwordError" id="passwordError"></div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupWizard()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="saveEmails()">Next</button>\
        </div>');

    document.getElementById("adminEmail").focus();
}
var username = "";
var password = "";
var confirmPassword = "";
function saveEmails()  // save password
{
    console.log('saveEmails PRESSED ----------- ');
    adminEmail[0] = document.getElementById("adminEmail").value;  // get custom name entered in form
    email1[0] = document.getElementById("email1").value;  // get custom name entered in form
    email2[0] = document.getElementById("email2").value;  // get custom name entered in form
    email3[0] = document.getElementById("email3").value;  // get custom name entered in form
    console.log('email1          = ' + email1[0]);

    document.getElementById('passwordError').innerHTML = "";

    if (adminEmail[0] == "") {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Admin Email is required!<br>";
        document.getElementById("adminEmail").focus();
    }
    else if ((!validateEmail(adminEmail[0])) && (adminEmail[0] != "")) {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Admin Email is not valid, try again!<br>";
        document.getElementById("adminEmail").value = "";
        document.getElementById("adminEmail").focus();
    }
    else if (email1[0] == "") {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Email 1 is required!<br>";
        document.getElementById("email1").focus();
    }
    else if ((!validateEmail(email1[0])) && (email1[0] != "")) {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Email 1 is not valid, try again!<br>";
        document.getElementById("email1").value = "";
        document.getElementById("email1").focus();
    }
    else if ((!validateEmail(email2[0])) && (email2[0] != "")) {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Email 2 is not valid, try again!<br>";
        document.getElementById("email2").value = "";
        document.getElementById("email2").focus();
    }
    else if ((!validateEmail(email3[0])) && (email3[0] != "")) {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML += "Email 3 is not valid, try again!<br>";
        document.getElementById("email3").value = "";
        document.getElementById("email3").focus();
    }
    else {
        $.ajax({  // update database with ds18b20 sensor ids
            method: "POST",
            url: "/php/startupEmailSave.php",
            dataType: "text/plain",
            data: {
                    "a": adminEmail[0],
                    "e1": email1[0],
                    "e2": email2[0],
                    "e3": email3[0]
            }
        });
        startupLogin();
    }

}

function startupLogin() {  // 
    console.log('startupLogin &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();
    // ds18b20Popup.style.display = "block";

    // $('.ds18b20PopupHeader').empty();
    // $(".ds18b20PopupHeader").append("Robo-Tank Startup Wizard");
    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Create a username and password to log into the Robo-Tank app.</p>\
        <br>\
        <div class="container">\
            <form class="row">\
                <label class="col-lg-3 label" for="username">Username:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="text" id="username" name="username" value=' + username + '>\
            </form>\
            <form class="row">\
                <label class="col-lg-3 label" for="userPassword">Password:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="password" id="userPassword" name="userPassword" value=' + password + '>\
            </form>\
            <form class="row">\
                <label class="col-lg-3 label" for="confirmPassword">Confirm Password:</label>\
                <input class="col-lg-7 field" onkeypress="clearErrorMsg()" type="password" id="confirmPassword" name="confirmPassword" value=' + confirmPassword + '>\
            </form>\
        </div>\
        <div class="col-lg-3 label"></div>\
        <div class="col-lg-7 passwordError" id="passwordError"></div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="emailsForm()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="saveLogin()">Next</button>\
        </div>');

    document.getElementById("username").focus();
}

function saveLogin()  // save password
{
    console.log('saveLogin PRESSED ----------- ');

    username = document.getElementById("username").value;  // get custom name entered in form
    password = document.getElementById("userPassword").value;  // get custom name entered in form
    confirmPassword = document.getElementById("confirmPassword").value;  // get custom name entered in form
    console.log('username        = ' + username);
    console.log('password        = ' + password);
    console.log('confirmPassword = ' + confirmPassword);

    if ((username == null) || (username == ""))  // check if password is blank.
    {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML = "Username is blank, try again!";
        document.getElementById("username").focus();
    }
    else if ((password == null) || (password == ""))  // check if password is blank.
    {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML = "Password is blank, try again!";
        document.getElementById("userPassword").value = "";
        document.getElementById("confirmPassword").value = "";
        document.getElementById("userPassword").focus();
    }
    else if (password != confirmPassword)  // check if password and confirm password match
    {
        passwordError.style.display = "inline-block";  // show error
        document.getElementById('passwordError').innerHTML = "Passwords don't match, try again!";
        document.getElementById("userPassword").value = "";
        document.getElementById("confirmPassword").value = "";
        document.getElementById("userPassword").focus();
    }
    else {  // password is valid
        $.ajax({  // update database with ds18b20 sensor ids
            method: "POST",
            url: "/php/startupLoginSave.php",
            dataType: "text/plain",
            data: {
                    "u": username,
                    "p": password
            }
        });
        startupTempFormat();
    }
}

function startupTempFormat() {  // 
    console.log('startupTempFormat &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();
    // ds18b20Popup.style.display = "block";

    // $('.ds18b20PopupHeader').empty();
    // $(".ds18b20PopupHeader").append("Robo-Tank Startup Wizard");
    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Would you like your temperatures to be Celsius or Fahrenheit?</p>\
        <br>\
        <div class="optionGroup">\
            <input type="radio" name="temperature" id="celsius" class="celsius" />\
            <label for="celsius">&nbsp; Celsius</label>\
            <br>\
            <input type="radio" name="temperature" id="fahrenheit" class="fahrenheit" />\
            <label for="fahrenheit">&nbsp; Fahrenheit</label>\
        </div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupLogin()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="saveTempFormat()">Next</button>\
        </div>');

    console.log('tempCorF = ' + tempCorF);
    if (tempCorF == 0) document.getElementById("celsius").checked = true;
    else if (tempCorF == 1) document.getElementById("fahrenheit").checked = true;
}

function saveTempFormat() {  // 
    console.log('saveTempFormat &&&&&&&&&&&&&&&&&&&&&&&&&&');
    if (document.getElementById("celsius").checked == true) {tempCorF = 0;}
    else if (document.getElementById("fahrenheit").checked == true) {tempCorF = 1;}
    console.log('tempCorF = ' + tempCorF);
    
    var command = "3," + tempCorF;
    sendToBackend(command);  // send slider value to backend

    startupTimeFormat();
}

function startupTimeFormat() {  // 
    console.log('startupTimeFormat &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();
    // ds18b20Popup.style.display = "block";

    // $('.ds18b20PopupHeader').empty();
    // $(".ds18b20PopupHeader").append("Robo-Tank Startup Wizard");
    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Would you like to use the 12 hour or 24 hour time format?</p>\
        <br>\
        <div class="optionGroup">\
            <input type="radio" name="time" id="12hr" class="12hr" />\
            <label for="12hr">&nbsp; 12 Hour Clock</label>\
            <br>\
            <input type="radio" name="time" id="24hr" class="24hr" />\
            <label for="24hr">&nbsp; 24 Hour Clock</label>\
        </div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupTempFormat()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="saveTimeFormat()">Next</button>\
        </div>');

    if (timeFormat == 0) document.getElementById("24hr").checked = true;
    else if (timeFormat == 1) document.getElementById("12hr").checked = true;
}

function saveTimeFormat() {  // 
    console.log('saveTimeFormat &&&&&&&&&&&&&&&&&&&&&&&&&&');
    if (document.getElementById("24hr").checked == true) {timeFormat = 0;}
    else if (document.getElementById("12hr").checked == true) {timeFormat = 1;}
    console.log('timeFormat = ' + timeFormat);
    
    var command = "5," + timeFormat;
    sendToBackend(command);  // send slider value to backend

    startupAutoUpdate();
}

function startupAutoUpdate() {  // 
    console.log('startupAutoUpdate &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();
    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Would you like to be notified when an update is available?</p>\
        <br>\
        <div class="optionGroup">\
            <input type="radio" name="time" id="enable" class="12hr" />\
            <label for="enable">&nbsp; Yes</label>\
            <br>\
            <input type="radio" name="time" id="disable" class="24hr" />\
            <label for="disable">&nbsp; No</label>\
        </div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupTimeFormat()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="saveAutoUpdate()">Next</button>\
        </div>');

    if (autoUpdate == 0) document.getElementById("disable").checked = true;
    else if (autoUpdate == 1) document.getElementById("enable").checked = true;
}

function saveAutoUpdate() {  // 
    console.log('saveAutoUpdate &&&&&&&&&&&&&&&&&&&&&&&&&&');
    if (document.getElementById("disable").checked == true) {autoUpdate = 0;}
    else if (document.getElementById("enable").checked == true) {autoUpdate = 1;}
    console.log('autoUpdate = ' + autoUpdate);
    
    var command = "993," + autoUpdate;
    sendToBackend(command);  // send slider value to backend

    startupControllerVersion();
}

function startupControllerVersion() {  // 
    console.log('startupControllerVersion &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();    
    $(".ds18b20Popup-body").append(
        `<p>&nbsp;</p>\
        <p class="h2">Select the Robo-Tank Controller you're using.</p>\
        <div class="systemVersionBox" >\
            <div class="systemSettingBoxLabel" style="text-align:center">Robo-Tank Controller</div>\
                <div class="settingsVersionText">\
                    <img id="" class="settingsVersionIcon" src="images/icons/v1.png" onclick="saveControllerVersion(0)" title="Robo-Tank Version 1">\
                    <label class="control control-radio" style="width:100%; text-align:center;">\
                        Version 1\
                        <input type="radio" name="version" id="version1" onclick="saveControllerVersion(0)" />\
                        <div class="control_indicator" style="left:63px;"></div>\
                    </label>\
                </div>\
                <div class="settingsVersionText">\
                    <img id="" class="settingsVersionIcon" src="images/icons/v2.png" onclick="saveControllerVersion(1)" title="Robo-Tank Version 2">\
                    <label class="control control-radio" style="width:100%; text-align:center;">\
                        Version 2\
                        <input type="radio" name="version" id="version2" onclick="saveControllerVersion(1)" />\
                        <div class="control_indicator" style="left:82px;"></div>\
                    </label>\
                </div>\
                <div class="settingsVersionText">\
                    <img id="" class="settingsVersionIcon" src="images/icons/v3.png" onclick="saveControllerVersion(2)" title="Robo-Tank Version 3">\
                    <label class="control control-radio" style="width:100%; text-align:center;">\
                        Version 3\
                        <input type="radio" name="version" id="version3" onclick="saveControllerVersion(2)" />\
                        <div class="control_indicator" style="left:42px;"></div>\
                    </label>\
                </div>\
        </div>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupAutoUpdate()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupCheckI2C()">Next</button>\
        </div>`);
    
    // mark controller version radio button active
    if (tempControllerVersion == 0) {
        document.getElementById("version1").checked = true;  // mark radio button checked
    }
    else if (tempControllerVersion == 1) {
        document.getElementById("version2").checked = true;  // mark radio button checked
    }
    else if (tempControllerVersion == 2) {
        document.getElementById("version3").checked = true;  // mark radio button checked
    }
}

function saveControllerVersion(value) {  // update Robo-Tank version - v1, v2 or v3
    console.log("saveControllerVersion &&&&&&&&&&&&&&&&&&&&&&&&&& " + value);
    tempControllerVersion = value;

    if (tempControllerVersion == 0) {
        document.getElementById("version1").checked = true;
        document.getElementById("version2").disabled = true;
        document.getElementById("version3").disabled = true;
    }
    else if (tempControllerVersion == 1) {
        document.getElementById("version1").disabled = true;
        document.getElementById("version2").checked = true;
        document.getElementById("version3").disabled = true;
    }
    else if (tempControllerVersion == 2) {
        document.getElementById("version1").disabled = true;
        document.getElementById("version2").disabled = true;
        document.getElementById("version3").checked = true;
    }
}

function startupCheckI2C() {  // 
    console.log('startupCheckI2C &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();    
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Robo-Tank will now scan for any I2C devices that might be connected.</p>\
        <br>\
        <p style="text-align: center;">Click next to continue.</p>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupControllerVersion()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="runI2Ccheck()">Next</button>\
        </div>');
}

function runI2Ccheck() {  // 
    console.log('runI2Ccheck &&&&&&&&&&&&&&&&&&&&&&&&&&');
    checkI2C();
}

function startupScanOneWire() {  // 
    console.log('startupScanOneWire &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    $('.ds18b20Popup-body').empty();
    $(".ds18b20Popup-body").append(
        '<p>&nbsp;</p>\
        <p class="h2">Robo-Tank will now scan for any DS18B20 temperature sensors that might be connected.</p>\
        <br>\
        <p style="text-align: center;">Click next to continue.</p>\
        <div class="widgetButtonBox" style="margin-top:-30px;">\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="startupCheckI2C()">Previous</button>\
            <button class="button _wide" style="margin-top:40px;" type="button" onclick="runOneWireCheck()">Next</button>\
        </div>');
}

function runOneWireCheck() {  // 
    console.log('runOneWireCheck &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    // startupWizardRunning = 0;
    // ds18b20Popup.style.display = "none";  // hide popup
    // $('.ds18b20Popup-body').empty();
    // firstTimeStartupFinished();
    checkDs18b20Name();
}

function startupSetupComplete() {  // 
    console.log('startupSetupComplete &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    // ds18b20Popup.style.display = "block";

    // $('.ds18b20PopupHeader').empty();
    // $(".ds18b20PopupHeader").append("Robo-Tank Startup Wizard");
    openSupport();

    // $('.ds18b20Popup-body').empty();
    // $(".ds18b20Popup-body").append(
    //     '<p>&nbsp;</p>\
    //     <p class="h2">Robo-Tank is ready to go!</p>\
    //     </br>\
    //     <p style="text-align: center;" class="link" onclick="openSupport()">Love Robo-Tank? Click here if you would like to support it further.</br></br></p>\
    //     <div class="widgetButtonBox">\
    //         <button class="button _wide" type="button" onclick="startupScanOneWire()">Previous</button>\
    //         <button class="button _wide" type="button" onclick="runSetupComplete()">Finished</button>\
    //     </div>\
    //     <p>&nbsp;</p>');

    
    // $('.ds18b20Popup-body').empty();
    // $(".ds18b20Popup-body").append(
    //     '<p>&nbsp;</p>\
    //     <p class="h2">Robo-Tank is ready to go!</p>\
    //     </br>\
    //     <p style="text-align: center;">This is 100% optional, you have already supported Robo-Tank through your purchase and I greatly appreciate it!</p>\
    //     <p style="text-align: center;">A little extra support here and there goes a long way and allows me to continually update and improve Robo-Tank.</p>\
    //     <p style="text-align: center;">Donate through Paypal or Bitcoin, one time or recurring and again this is not in any way necessary.</p>\
    //     <br>\
    //     <div class="container subColumnBox">\
    //         <div class="row ">\
    //             <form class="col-sm-4 subColumn" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">\
    //                 <h3>Monthly Support</h3>\
    //                 <img style="padding-bottom: 15px;" src="images/icons/paypal.png" alt="PayPal">\
    //                 <input type="hidden" name="cmd" value="_s-xclick">\
    //                 <input type="hidden" name="hosted_button_id" value="BEKHYNEGACEZJ">\
    //                 <table>\
    //                     <br><b>Select Monthly Amount</b><br>\
    //                     <select style="margin-bottom: 20px; margin-top: 3px; width: 130px;" name="os0">\
    //                         <option value="Level 1">$3.00 USD</option>\
    //                         <option value="Level 2">$5.00 USD</option>\
    //                         <option value="Level 3">$10.00 USD</option>\
    //                         <option value="Level 4">$15.00 USD</option>\
    //                         <option value="Level 5">$20.00 USD</option>\
    //                         <option value="Level 6">$25.00 USD</option>\
    //                         <option value="Level 7">$30.00 USD</option>\
    //                         <option value="Level 8">$40.00 USD</option>\
    //                         <option value="Level 9">$50.00 USD</option>\
    //                         <option value="Level 10">$75.00 USD</option>\
    //                     </select>\
    //                 </table>\
    //                 <input type="hidden" name="currency_code" value="USD">\
    //                 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">\
    //                 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">\
    //             </form>\
    //             <form class="col-sm-4 subColumn" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">\
    //                 <h3>One Time Support</h3>\
    //                 <img style="padding-bottom: 15px;" src="images/icons/paypal.png" alt="PayPal">\
    //                 <input type="hidden" name="cmd" value="_s-xclick">\
    //                 <input type="hidden" name="hosted_button_id" value="YXYWYBG3ZCTZC">\
    //                 <table>\
    //                     <br><b>Select One Time Amount</b><br>\
    //                     <select style="margin-bottom: 20px; margin-top: 3px; width: 130px;" name="os0">\
    //                         <option value="One Time1 -">$5.00 USD</option>\
    //                         <option value="One Time2 -">$15.00 USD</option>\
    //                         <option value="One Time3 -">$25.00 USD</option>\
    //                         <option value="One Time4 -">$40.00 USD</option>\
    //                         <option value="One Time5 -">$60.00 USD</option>\
    //                         <option value="One Time6 -">$80.00 USD</option>\
    //                         <option value="One Time7 -">$100.00 USD</option>\
    //                         <option value="One Time8 -">$150.00 USD</option>\
    //                         <option value="One Time9 -">$200.00 USD</option>\
    //                         <option value="One Time10 -">$250.00 USD</option>\
    //                     </select>\
    //                 </table>\
    //                 <input type="hidden" name="currency_code" value="USD">\
    //                 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">\
    //                 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">\
    //             </form>\
    //             <div class="col-sm-3 subColumn">\
    //                 <h3>One Time Support</h3>\
    //                 <img style="padding: 0px 10px 19px 10px;" src="images/icons/bitcoin_logo.jpg" alt="Bitcoin">\
    //                 <img src="images/icons/17SFZnKsd3BDaYxokS42LCyADhX7iZpq1E.png" alt="Bitcoin">\
    //             </div>\
    //         </div>\
    //         <div style="margin-top:-15px; text-align:center; width:100%;">Contact me for other cryptocurrencies.</div>\
    //     </div>\
    //     <div class="widgetButtonBox">\
    //         <button class="button _wide" type="button" onclick="startupScanOneWire()">Previous</button>\
    //         <button class="button _wide" type="button" onclick="runSetupComplete()">Finished</button>\
    //     </div>\
    //     <p>&nbsp;</p>');
}

function openSupport() {
    supportRoboTank();
    runSetupComplete();
}

function runSetupComplete() {  // 
    console.log('runSetupComplete &&&&&&&&&&&&&&&&&&&&&&&&&&');
    
    // ds18b20Popup.style.display = "none";  // hide popup
    // document.querySelector("body").style.overflow = 'visible';
    // $('.ds18b20Popup-body').empty();
    // closeDs18b20Popup();
    firstTimeStartupFinished();
}

function clearErrorMsg() { // clear error message
    document.getElementById('passwordError').innerHTML = ""
    passwordError.style.display = "none";  // hide error
}

function validateEmail(email) {
    const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}