﻿function getQueryVariable() {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == "principal") {
            document.aspnetForm.principal.value = pair[1];
            document.aspnetForm.interest.value = 4.99;
            document.aspnetForm.years.value = 5;
        }
        else {
            document.aspnetForm.principal.value = 0;
            document.aspnetForm.interest.value = 4.99;
            document.aspnetForm.years.value = 5;
        }
    }
    calculate();
}

function calculate() {
    // Get the user's input from the form. Assume it is all valid.
    // Convert interest from a percentage to a decimal, and convert from
    // an annual rate to a monthly rate. Convert payment period in years
    // to the number of monthly payments.  

    var principal = document.aspnetForm.principal.value;
    var interest = document.aspnetForm.interest.value / 100 / 12;
    var payments = document.aspnetForm.years.value * 12;

    // Now compute the monthly payment figure, using esoteric math.
    var x = Math.pow(1 + interest, payments);
    var monthly = (principal * x * interest) / (x - 1);

    // Check that the result is a finite number. If so, display the results
    if (!isNaN(monthly) &&
                (monthly != Number.POSITIVE_INFINITY) &&
                (monthly != Number.NEGATIVE_INFINITY)) {

        document.aspnetForm.payment.value = round(monthly);
    }
    // Otherwise, the user's input was probably invalid, so don't
    // display anything.
    else {
        document.aspnetForm.payment.value = "";
    }
}

function round(x) {
    return Math.round(x * 100) / 100;
}

function goToApply() {
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height);
    window.location = "../secure/apply.aspx"
}

function goToApplyPage2() {
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height);
    window.location = "../secure/apply2.aspx"
}





// used to open small email customer windows
function openScript(url, width, height) {
    var Win = window.open(url, 'openScript', 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no,status=yes');
}








// part of the page auto refresh timing
function startTimer(refreshCount) {
    setInterval(onTick, refreshCount);
}


// part of the page auto refresh timing
function onTick() {
    document.location.reload();
}


// used to reposition the quik desk tool, found in bottom left of a desking page
function reposition() {
    var el = document.getElementById('bottomLeft');
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    if (ScrollTop < 200)
        el.style.bottom = 25 - ScrollTop + "px";
    else
        el.style.bottom = "0px";
}


// used in the "DMSmaster"
function clearText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    target.style.color = "#000000";
    target.value = '';
    return;
}


// used in the "DMSmaster"
function validateSearch(e) {
    if (e.value == null || e.value == "" || e.value == "Search" || e.value == "NOTCHANGED") {
        return false;
    }
    else {
        return true;
    }
}


// the following javascript is used in compiled server controls


// used in the "Application_FullSize"
function checkTimeValues(years_ClientID, months_clientID, additionalSection_ClientID) {
    var tempYears = parseInt(document.getElementById(years_ClientID).value);
    var tempMonths = parseInt(document.getElementById(months_clientID).value);
    if (!tempYears) {
        tempYears = 0;
    }
    if (!tempMonths) {
        tempMonths = 0;
    }
    while (tempMonths > 11) {
        tempYears = tempYears + 1; tempMonths = tempMonths - 12;
    }
    document.getElementById(years_ClientID).value = tempYears;
    document.getElementById(months_clientID).value = tempMonths;
    if (tempYears > 1) {
        document.getElementById(additionalSection_ClientID).style.display = 'none';
    }
    else {
        document.getElementById(additionalSection_ClientID).style.display = 'block';
    }
}


// used in the "CustomTextBox_currancy"
function validateCurrency(currentNode) {
    var intValidationString = /^\d+$/;
    var TargetValue = currentNode.value.replace('.', '');
    TargetValue = TargetValue.replace(',', '');
    TargetValue = TargetValue.replace('$', '');
    var isValidInt = intValidationString.test(TargetValue);
    if (isValidInt == false) {
        currentNode.value = '';
    }
}


// used in the "CustomTextBox_double"
function validateDouble(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value.replace('.', '').replace('-', ''));
    if (isValidInt == false) {
        currentNode.value = '';
    }
}


// used in the "CustomTextBox_email"
function validateEmail(currentNode) {
    if (currentNode.value.length < 6) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.indexOf('@', 2) == -1) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.indexOf('.', 4) == -1) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.lastIndexOf('.') == (currentNode.value.length - 1)) {
        currentNode.value = ''; return;
    }
}


// used in the "CustomTextBox_email"
function compareTwoBoxes(currentNode, ClientID) {
    if (currentNode.value != document.getElementById(ClientID).value) {
        document.getElementById(ClientID).value = ''; currentNode.value = ''; return;
    }
}


// used in the "CustomTextBox_int"
function validateInt(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value.replace('-', ''));
    if (isValidInt == false) {
        currentNode.value = '';
    }
}


// used in the "CustomTextBox_ZipCode"
function validateZipCode(currentNode) {
    var intValidationString = /^\d+$/;
    if (currentNode.value.length > 5) {
        currentNode.value = currentNode.value.substring(0, 5);
    }
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = '';
    }
}


// used in the "DateBoxes"
function curserNextBoxYear(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    var fieldValue = parseInt(currentNode.value);
    if (fieldValue > 2030) {
        currentNode.value = '';
    }
    if (fieldValue < 0) {
        currentNode.value = '';
    }
    if (fieldValue == 6 || fieldValue == 7 || fieldValue == 8 || fieldValue == 9) {
        currentNode.value = 2000 + fieldValue; return;
    }
    if (fieldValue > 1 && fieldValue < 50 && fieldValue != 19 && fieldValue != 20 && currentNode.value.length == 2) {
        currentNode.value = 2000 + fieldValue; return;
    }
    if (fieldValue >= 50 && fieldValue <= 99 && currentNode.value.length == 2) {
        currentNode.value = 1900 + fieldValue; return;
    }
}


// used in the "DateBoxes"
function curserNextBoxDay(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    var fieldValue = parseInt(currentNode.value);
    if (fieldValue > 31) {
        currentNode.value = ''; return;
    }
    if (fieldValue < 0) {
        currentNode.value = ''; currentNode.focus();
    }
    if (fieldValue == 4 || fieldValue == 5 || fieldValue == 6 || fieldValue == 7 || fieldValue == 8 || fieldValue == 9) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
    if (currentNode.value.length > 1) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "DateBoxes"
function curserNextBoxMonth(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    var fieldValue = parseInt(currentNode.value);
    if (fieldValue > 12) {
        currentNode.value = ''; return;
    }
    if (fieldValue < 0) {
        currentNode.value = ''; return;
    }
    if (fieldValue == 2 || fieldValue == 3 || fieldValue == 4 || fieldValue == 5 || fieldValue == 6 || fieldValue == 7 || fieldValue == 8 || fieldValue == 9) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
    if (currentNode.value.length > 1) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "DateBoxes"
function curserNextBoxHour(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    var fieldValue = parseInt(currentNode.value);
    if (fieldValue > 24) {
        currentNode.value = ''; return;
    }
    if (fieldValue < 0) {
        currentNode.value = ''; return;
    }
    if (fieldValue == 3 || fieldValue == 4 || fieldValue == 5 || fieldValue == 6 || fieldValue == 7 || fieldValue == 8 || fieldValue == 9) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
    if (currentNode.value.length > 1) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "DateBoxes"
function curserNextBoxMin(currentNode) {
    var intValidationString = /^\d+$/;
    var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    var fieldValue = parseInt(currentNode.value);
    if (fieldValue > 60) {
        currentNode.value = '';
    }
    if (fieldValue < 0) {
        currentNode.value = '';
    }
}


// used in the "DateBoxes"
function expandColapsCalander(ClientID_calcBox) {
    if (document.getElementById(ClientID_calcBox).style.display == 'none') {
        document.getElementById(ClientID_calcBox).style.display = 'block'; return;
    }
    document.getElementById(ClientID_calcBox).style.display = 'none'; return;
}


// used in the "Desk_DealStructure"
function changeVisableBox(selectedBox, box1_ClientID, box2_ClientID, box3_ClientID, box4_ClientID, box5_ClientID, box6_ClientID, img1_ClientID, img2_ClientID, img3_ClientID, img4_ClientID, img5_ClientID, img6_ClientID) {
    if (selectedBox == 1) {
        document.getElementById(box1_ClientID).style.display = 'block';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none none none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
    else if (selectedBox == 2) {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'block';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none none none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
    else if (selectedBox == 3) {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'block';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none none none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
    else if (selectedBox == 4) {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'block';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none none none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
    else if (selectedBox == 5) {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'block';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none none none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
    else if (selectedBox == 6) {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'block';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none none none';
    }
    else {
        document.getElementById(box1_ClientID).style.display = 'none';
        document.getElementById(img1_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box2_ClientID).style.display = 'none';
        document.getElementById(img2_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box3_ClientID).style.display = 'none';
        document.getElementById(img3_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box4_ClientID).style.display = 'none';
        document.getElementById(img4_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box5_ClientID).style.display = 'none';
        document.getElementById(img5_ClientID).style.borderStyle = 'none none solid none';
        document.getElementById(box6_ClientID).style.display = 'none';
        document.getElementById(img6_ClientID).style.borderStyle = 'none none solid none';
    }
}


// used in the "ExpandableNodeAndLabelBar"
function togleButtonSwitchText(btn, offLabel, onLabel) {
    if (btn.value != offLabel)
        btn.value = offLabel;
    else btn.value = onLabel;
}


// used in the "ExpandableNodeAndLabelBar"
function togleDivBlock(divBlock) {
    if (document.getElementById(divBlock).style.display != "none") {
        document.getElementById(divBlock).style.display = "none";
    } else {
        document.getElementById(divBlock).style.display = "block";
    }
}


// used in the "JavaMonthlyIncomeCalculator"
function changeIncomeCalculationType(currentNode, ClientID_target, ClientID_hourly, ClientID_salary, ClientID_other, ClientID_YTD) {
    document.getElementById(ClientID_hourly).style.display = 'none';
    document.getElementById(ClientID_salary).style.display = 'none';
    document.getElementById(ClientID_other).style.display = 'none';
    document.getElementById(ClientID_YTD).style.display = 'none';
    if (currentNode.checked) {
        document.getElementById(ClientID_target).style.display = 'block';
    }
}


// used in the "JavaMonthlyIncomeCalculator"
function togalCalcBox(ClientID_calcBox) {
    if (document.getElementById(ClientID_calcBox).style.display == 'none') {
        document.getElementById(ClientID_calcBox).style.display = 'block'; return;
    }
    document.getElementById(ClientID_calcBox).style.display = 'none'; return;
}


// used in the "JavaMonthlyIncomeCalculator"
function caclHourly(ClientID_hourlyRate, ClientID_HoursPerWeek, ClientID_answerBox, ClientID_calcBox) {
    var MonthlyPay = (document.getElementById(ClientID_HoursPerWeek).value * document.getElementById(ClientID_hourlyRate).value * 52) / 12;
    document.getElementById(ClientID_answerBox).value = '$' + Math.round(MonthlyPay * Math.pow(10, 2)) / Math.pow(10, 2);
    document.getElementById(ClientID_calcBox).style.display = 'none';
}


// used in the "JavaMonthlyIncomeCalculator"
function caclSalary(ClientID_yearlySalary, ClientID_answerBox, ClientID_calcBox) {
    var MonthlyPay = document.getElementById(ClientID_yearlySalary).value / 12;
    document.getElementById(ClientID_answerBox).value = '$' + Math.round(MonthlyPay * Math.pow(10, 2)) / Math.pow(10, 2);
    document.getElementById(ClientID_calcBox).style.display = 'none';
}


// used in the "JavaMonthlyIncomeCalculator"
function caclOther(ClientID_monthlyPay, ClientID_answerBox, ClientID_calcBox) {
    var MonthlyPay = document.getElementById(ClientID_monthlyPay).value;
    document.getElementById(ClientID_answerBox).value = '$' + Math.round(MonthlyPay * Math.pow(10, 2)) / Math.pow(10, 2);
    document.getElementById(ClientID_calcBox).style.display = 'none';
}


// used in the "JavaMonthlyIncomeCalculator"
function caclYTD(ClientID_YTDmonth, ClientID_YTDday, ClientID_YTDamount, ClientID_answerBox, ClientID_calcBox) {
    var totalDays = parseInt(document.getElementById(ClientID_YTDday).value) + (parseInt(document.getElementById(ClientID_YTDmonth).value) * 30.5);
    var MonthlyPay = (parseFloat(document.getElementById(ClientID_YTDamount).value) / totalDays) * 30.5;
    document.getElementById(ClientID_answerBox).value = '$' + Math.round(MonthlyPay * Math.pow(10, 2)) / Math.pow(10, 2);
    document.getElementById(ClientID_calcBox).style.display = 'none';
}


// used in the "Phone_Boxes"
function curserNextPreFixBox(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.length == 3) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "Phone_Boxes"
function curserNextAreaCodeBox(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.length == 3) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "Phone_Boxes"
function curserNextSuffixBox(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
}


// used in the "SSN_Boxes"
function curserNextBoxPart1(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.length == 3) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "SSN_Boxes"
function curserNextBoxPart2(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
    if (currentNode.value.length == 2) {
        currentNode.parentNode.nextSibling.nextSibling.firstChild.focus();
    }
}


// used in the "SSN_Boxes"
function curserNextBoxPart3(currentNode) {
    var intValidationString = /^\d+$/; var isValidInt = intValidationString.test(currentNode.value);
    if (isValidInt == false) {
        currentNode.value = ''; return;
    }
}