//<![CDATA[
function runStuff() {
    // open/close disclaimer
    if ($("open-disclaimer")) {
        $("open-disclaimer").onclick = function() {
            new Effect.Appear('disclaimer', { duration: 0.5 });
            this.blur();
            return false;
        }
        $("close-disclaimer").onclick = function() {
            new Effect.Fade('disclaimer', { duration: 0.5 });
            return false;
        }
    }
    // make it dragable
    if ($("disclaimer-image")) {
        new Draggable('disclaimer',{handle:'disclaimer-image',starteffect:null,endeffect:null});
    }
    // the calculator
    if ($("calcForm")) {
        var inputList = Form.getElements("calcForm");
        for (var i=0; i<inputList.length; i++) {
            if (inputList[i].id == "txtF_DebtTotal" || inputList[i].id == "txtI_FamilyIncomeTotal" || inputList[i].id == "txtL_AssetsTotal") {
                inputList[i].onblur = function() {
                    return calculateSubtotals();
                }
            }
            else if (inputList[i].id == "txt_InterestRate" || inputList[i].id == "txtH_FamilyIncomeYears") {
                inputList[i].onblur = function() {
                    return validatePositiveNumber(this);
                }
            }
            else if (inputList[i].id == "btnCalculate") {
                inputList[i].onclick = function() {
                    return calculateTotals();
                }
            }
            else {
                inputList[i].onblur = function() {
                    return validateCurrency(this);
                }
            }
        }
        Form.focusFirstElement('calcForm');
    }
}

// Dean Edwards/Matthias Miller/John Resig
function init() {
    if (arguments.callee.done) return; // quit if this function has already been called
    arguments.callee.done = true; // flag this function so we don't do the same thing twice
    if (_timer) clearInterval(_timer); // kill the timer
    // do stuff //
    runStuff();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;
//]]>