﻿///returns whether the total mandate equals 100
function isMandateValid(growthControlId, balanceControlId, conservativeControlId) {
    var mandate = getMandate(growthControlId, balanceControlId, conservativeControlId);
    
    return (mandate == 100);
}

//returns the total mandate value
function getMandate(growthControlId, balanceControlId, conservativeControlId) {
    var growth = getMandateValue(growthControlId);
    var balance = getMandateValue(balanceControlId);
    var conservative = getMandateValue(conservativeControlId);

    return growth + balance + conservative;
}

function getFloatValue(controlId) {
    var control = document.getElementById(controlId);

    if (control.value == "" || isNaN(control.value) || control.value < 0) {
        control.value = "0";
    }

    return parseFloat(control.value);
}

//returns the float value of an input field.
//0 will be returned for any invalid values.
//100 will be returned for any number grater than or equal to 100.
function getMandateValue(controlId) {
    var control = document.getElementById(controlId);
    
    if (control.value == "" || isNaN(control.value) || control.value < 0) {
        control.value = "0";
    }
    else if (control.value > 100) {
        control.value = "100";
    }    

    return parseFloat(control.value);
}

//displays the message label passed in when the control value has been changed from its
//default value.
//if an invalid value has been entered then the control value will be reset to its
//default value.
function checkMandateRate(controlToCheck, defaultValue, messageLabelId) {
    var messageLabel = document.getElementById(messageLabelId);

    if (isNaN(controlToCheck.value) || controlToCheck.value < 0) {
        controlToCheck.value = defaultValue
    }
    else {
        if (controlToCheck.value != defaultValue) {
            messageLabel.style.display = "";
        }
        else {
            messageLabel.style.display = "none";
        }
    }
}

//toggles the visibility of the calculator notes
function toggleNotes(linkId, notesId) {    
    var notes = document.getElementById(notesId);
    var link = document.getElementById(linkId);

    //if the notes are currently hidden then 
    //show the notes and change the link text
    if (notes.style.display == "none") {
        link.innerHTML = "Hide Notes";        
        notes.style.display = "";
    }
    else {
        //hide the notes and reset the link text
        link.innerHTML = "View Notes";
        notes.style.display = "none";
    }
}
