
    function initializeMLCalcWidget() {
    var iframeHeight = 0;
        $("#MLCalcFormMortgageForm #dp INPUT").bind("keyup", function () {return calcDPValue();});
        $("#MLCalcFormMortgageForm #ma INPUT").bind("keyup", function () {return calcDPValue();});
        $("#MLCalcFormMortgageForm #dp INPUT").trigger("keyup");
        $("#MLCalcFormMortgageForm").attr("autocomplete", "off");
        $("#MLCalcFormMortgageForm").bind("submit", function () {if (typeof mlcalc_amortization == "undefined") {mlcalc_amortization = "none";}
		if (validateForm($(this)) == false) {return false;}iframeHeight = (mlcalc_amortization == "none") ? 319 : 570;initFloatLayer(iframeHeight);$(this).attr("target", "MLCalcFrame");});
		
		
		
    }


    function initFloatLayer(iframeHeight) {
        var viewportWidth = $(window).width();
        var viewportHeight = $(window).height();
        var documentWidth = 0;
        var documentHeight = 0;
        var viewportLeft = 0;
        var viewportTop = 0;
        if (document.body) {
            documentWidth = document.body.scrollWidth;
            documentHeight = document.body.scrollHeight;
            viewportLeft = document.body.scrollLeft;
            viewportTop = document.body.scrollTop;
        }
        if (document.documentElement) {
            documentWidth = Math.min(documentWidth, document.documentElement.scrollWidth);
            documentHeight = Math.max(documentHeight, document.documentElement.scrollHeight);
            viewportLeft = Math.max(viewportLeft, document.documentElement.scrollLeft);
            viewportTop = Math.max(viewportTop, document.documentElement.scrollTop);
        }
        var shaderWidth = Math.max(documentWidth, viewportWidth);
        var shaderHeight = Math.max(documentHeight, viewportHeight);
        $("#MLCalcShader").css({width: shaderWidth, height: shaderHeight, top: 0, left: 0, opacity: "0.5"}).show().click(function () {$("#MLCalcShader").fadeOut(300);$("#MLCalcHolder, #MLCalcClose, #MLCalcFrame").hide();showObjects();});
        var holderLeft = parseInt((viewportWidth - 680) / 2) + viewportLeft;
        var holderTop = parseInt((viewportHeight - iframeHeight) / 2) + viewportTop;
        if (holderLeft < 0) {
            holderLeft = 0;
        }
        if (holderTop < 0) {
            holderTop = 0;
        }
        hideObjects(holderLeft, holderTop, holderLeft + 680, holderTop + iframeHeight);
        $("#MLCalcHolder").css({width: 680, height: iframeHeight, top: holderTop, left: holderLeft}).show();
        if ($("#MLCalcHolder #MLCalcFrame").size() < 1) {
            $("#MLCalcHolder").html("<iframe src=\"#\" scrolling=\"no\" id=\"MLCalcFrame\" name=\"MLCalcFrame\" width=\"0\" height=\"0\" frameborder=\"0\" allowtransparency=\"true\" style=\"background-color: transparent; display: none\"></iframe><iframe id=\"garbageFrame\" style=\"display:none\"></iframe>");
        }
        $("#MLCalcHolder").find("#MLCalcFrame").css({width: 680, height: iframeHeight}).load(function () {$(this).show();$("#MLCalcHolder #garbageFrame").attr("src", "");$("#MLCalcClose").show().css({height: 25, width: 25}).css({top: holderTop, left: holderLeft + $("#MLCalcHolder").width() - 2 - $("#MLCalcClose").width()}).click(function () {$("#MLCalcShader").fadeOut(300);$("#MLCalcHolder, #MLCalcClose, #MLCalcFrame").hide();showObjects();}).hover(function () {$(this).css({background: "#F5F5F5", color: "#808080"});}, function () {$(this).css({background: "#D5D5D5", color: "#F5F5F5"});});});
    }


    function hideObjects(X1, Y1, X2, Y2) {
        $("OBJECT").each(function () {var offset = $(this).offset();oX1 = offset.left;oY1 = offset.top;oX2 = oX1 + $(this).width();oY2 = oY1 + $(this).height();if ((X1 > oX1 && X1 < oX2 || X2 > oX1 && X2 < oX2) && (Y1 > oY1 && Y1 < oY2 || Y2 > oY1 && Y2 < oY2) || (oX1 > X1 && oX1 < X2 || oX2 > X1 && oX2 < X2) && (oY1 > Y1 && oY1 < Y2 || oY2 > Y1 && oY2 < Y2)) {$(this).attr("originalVisibility", $(this).css("visibility")).css("visibility", "hidden").attr("hiddenBy", "MLCalc");}});
        if (jQuery.browser == "msie" && jQuery.browser.version < 7) {
            $("SELECT").each(function () {$(this).attr("originalVisibility", $(this).css("visibility")).css("visibility", "hidden").attr("hiddenBy", "MLCalc");});
        }
    }


    function showObjects() {
        $("OBJECT[hiddenBy=MLCalc]").each(function () {$(this).css("visibility", $(this).attr("originalVisibility")).removeAttr("originalVisibility").removeAttr("hiddenBy");});
        if (jQuery.browser == "msie" && jQuery.browser.version < 7) {
            $("SELECT[hiddenBy=MLCalc]").each(function () {$(this).css("visibility", $(this).attr("originalVisibility")).removeAttr("originalVisibility").removeAttr("hiddenBy");});
        }
    }


    function validateForm(form) {
        var validations = {ma: {minval: 1, maxval: 999999999, required: true, errmsg: "Le prix de l'immobilier doit \xEAtre dans la fourchette de 1 \xE0 999,999,999"}, dp: {minval: 0, maxval: 99, required: false, errmsg: "Acompte doit \xEAtre dans la fourchette de 0 \xE0 99"}, mt: {minval: 1, maxval: 100, required: true, errmsg: "Terme de l'hypoth\xE8que doit \xEAtre dans la fourchette de 1 \xE0 100"}, pt: {minval: 0, maxval: 999999, required: false, errmsg: "Imp\xF4t foncier doit \xEAtre dans la fourchette de 0 \xE0 999,999"}, pi: {minval: 0, maxval: 999999, required: false, errmsg: "Assurance de la propri\xE9t\xE9 doit \xEAtre dans la fourchette de 0 \xE0 999,999"}, mi: {minval: 0, maxval: 99.99, required: false, errmsg: "PMI doit \xEAtre dans la fourchette de 0 \xE0 99.99"}, la: {minval: 1, maxval: 999999999, required: true, errmsg: "Montant du cr\xE9dit doit \xEAtre dans la fourchette de 1 \xE0 999,999,999"}, lt: {minval: 1, maxval: 100, required: true, errmsg: "Terme du cr\xE9dit doit \xEAtre dans la fourchette de 1 \xE0 100"}, ir: {minval: 0.01, maxval: 99.99, required: true, errmsg: "Taux d'int\xE9r\xEAt doit \xEAtre dans la fourchette de 0.01 \xE0 99.99"}};
        var toSubmit = true;
        form.find(".valid").each(function () {var val = parseFloat($(this).val().replace(/[^0-9\.]/g));var name = $(this).attr("name");if ((val == "null" || isNaN(val)) && (validations[name].required === false)) {return true;}if (val < validations[name].minval || val > validations[name].maxval || (val == "null" || isNaN(val))) {alert(validations[name].errmsg);$(this).select();toSubmit = false;return false;}});
        return toSubmit;
    }


    function formatNum(num) {
        return num.toString().replace(/(\d+)(\d{3})/, function (num, num1, num2) {return ((num1.length < 3) ? num1 : formatNum(num1)) + "," + num2;});
    }


    function calcDPValue() {
        var ma = parseFloat($("#MLCalcFormMortgageForm #ma INPUT").val().replace(/[^0-9\.]/g, ""));
        var dp = parseFloat($("#MLCalcFormMortgageForm #dp INPUT").val());
        if (dp < 100) {
            $("#MLCalcFormMortgageForm #downPaymentValue").html("(" + mlcalc_currency_symbol + "" + formatNum(Math.round(ma * dp / 100)) + ")");
        }
        if (dp >= 20) {
            $("#MLCalcFormMortgageForm #mi *").attr("disabled", "disabled").addClass("disabled");
        } else {
            $("#MLCalcFormMortgageForm #mi *").removeAttr("disabled").removeClass("disabled");
        }
    }

    mlcalc_language = "fr";
    if (typeof mlcalc_currency_code == "undefined") {
        mlcalc_currency_code = "usd";
    }
    if (mlcalc_currency_code.toLowerCase() == "eur") {
        mlcalc_currency_symbol = "&euro;";
    }
    if (mlcalc_currency_code.toLowerCase() == "gbp") {
        mlcalc_currency_symbol = "&pound;";
    }
    if (mlcalc_currency_code.toLowerCase() == "usd") {
        mlcalc_currency_symbol = "$";
    }
    if (typeof mlcalc_currency_symbol == "undefined") {
        mlcalc_currency_symbol = mlcalc_currency_code.substr(0, 3);
    }
    if (typeof mlcalc_default_calculator == "undefined") {
        mlcalc_default_calculator = "loan";
    }
    if (typeof mlcalc_form_size == "undefined") {
        mlcalc_form_size = "small";
    }
    if (typeof mlcalc_purchase_price == "undefined") {
        mlcalc_purchase_price = "250,000";
    }
    if (typeof mlcalc_down_payment == "undefined") {
        mlcalc_down_payment = "10";
    }
    if (typeof mlcalc_mortgage_term == "undefined") {
        mlcalc_mortgage_term = "30";
    }
    if (typeof mlcalc_interest_rate == "undefined") {
        mlcalc_interest_rate = "5.5";
    }
    if (typeof mlcalc_property_tax == "undefined") {
        mlcalc_property_tax = "3,000";
    }
    if (typeof mlcalc_property_insurance == "undefined") {
        mlcalc_property_insurance = "1,500";
    }
    if (typeof mlcalc_pmi == "undefined") {
        mlcalc_pmi = "0.52";
    }
    if (typeof mlcalc_loan_amount == "undefined") {
        mlcalc_loan_amount = "150,000";
    }
    if (typeof mlcalc_loan_term == "undefined") {
        mlcalc_loan_term = "15";
    }
    if (typeof mlcalc_amortization == "undefined") {
        mlcalc_amortization = "year_nc";
    }

    mlcalc_display_mortgage_only = mlcalc_display_mortgage_form = "";

    var mlcalc_hidden = "";
    var mlcalc_display_amortization = "";
    if (mlcalc_amortization.search(/_nc$/i) != -1 ||
        mlcalc_amortization == "none") {
        mlcalc_display_amortization = "style=\"display:none\"";
        mlcalc_hidden += "<input type=\"hidden\" name=\"as\" value=\"" + mlcalc_amortization.replace(/_nc/i, "") + "\">";
    }
    var mlcalc_as_year = (mlcalc_amortization.search(/year/i) != -1) ? "checked=\"checked\"" : "";
    var mlcalc_as_month = (mlcalc_amortization.search(/month/i) != -1) ? "checked=\"checked\"" : "";
	

    $(document).ready(function () {$("body").prepend("<div id=\"MLCalcHolder\"></div><div id=\"MLCalcShader\"></div><div id=\"MLCalcClose\">X</div>");initializeMLCalcWidget();});
    var img3 = new Image(312, 44);
    img3.src = "/images/ajax-loader.gif";

