//prototype counter var prototypeWindowID = 1; // Get validation libs Scriptaculous.require("fValidate.core.js"); Scriptaculous.require("fValidate.config.js"); Scriptaculous.require("fValidate.basic.js"); Scriptaculous.require("fValidate.extended.js"); Scriptaculous.require("fValidate.numbers.js"); Scriptaculous.require("fValidate.datetime.js"); Scriptaculous.require("fValidate.logical.js"); Scriptaculous.require("fValidate.web.js"); Scriptaculous.require("fValidate.controls.js"); Scriptaculous.require("fValidate.international.js"); Scriptaculous.require("fValidate.ecommerce.js"); Scriptaculous.require("fValidate.special.js"); Scriptaculous.require("fValidate.lang.js.asp"); // Behaviour library Scriptaculous.require("behaviour.js"); // Check co/borrower age Scriptaculous.require("checktext.js.asp"); // Reverse a string (used in Number.formatCurrency) String.prototype.reverse = function() { var r = ""; var i = 0; for (i = this.length - 1 ; i >= 0 ; i--) { r += this.substring(i, i+1); } return r; } // Round to a given decimal place (uses common rounding, not round to nearest even) Number.prototype.round = function(digits) { r = this + (0.5 / Math.pow(10, digits)); r *= Math.pow(10, digits); r = Math.floor(r); r /= Math.pow(10, digits); return r; } // Format a number as currency (e.g. $1,234,567.89) Number.prototype.formatCurrency = function() { // Round number, break up number and decimal portions var n = this.round(2); var s = "" + n + ""; var tmp = s.split("."); var d = "00"; var i = 0; // Get whole number portion as string n = "" + tmp[0] + ""; // Get decimal portion as string if (tmp.length > 1) { d = "" + tmp[1] + ""; } if (d.length < 2) { d += "0"; } // Add commas (reverse the number, add a comma every 3 places, reverse again) s = ""; n = n.reverse(); for (i = 0 ; i < n.length ; i++) { s += n.substring(i, i+1); if ((i + 1) % 3 == 0 && (i + 1) < n.length) { s += ","; } } s = s.reverse(); // Assemble the number, decimal, and currency symbol and format in // accounting notation (negative numbers are put in parentheses) if (this.round(2) < 0) { s = "($" + s.replace("-", "") + "." + d + ")"; } else { s = "$" + s + "." + d; } // Return return s; } // Email obfuscation function LQ_EM_Swap(that, first, middle, last) { that.href = "mai" + "lto:" + first + "@" + middle + "." + last; that.onmouseover=""; } // Open payment stream /*function showPaymentStream(args) { var psWin = window.open("payment_stream.asp?" + args, "psWin", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=330"); if (psWin) { psWin.focus(); } else { alert("A popup blocker has prevented this window from opening. Please disable any popup blocking software and try again."); } }*/ function showPaymentStream(args) { prototypeWindowID++; var windowID = 'PaymentStream' + prototypeWindowID; contentWin = new Window( windowID, { className: 'dialog', title: 'Show Payments', width:450, height:480, minimizable: false, maximizable: false, closable: true, resizable: true, url: 'payment_stream.asp?' + args + '&winID=' + windowID, showEffect: Element.show, hideEffect: Element.hide } ) contentWin.showCenter(false); } // Open closing cost /*function showClosingCosts(args) { var psWin = window.open("closing_costs.asp?" + args, "psWin", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=590"); if (psWin) { psWin.focus(); } else { alert("A popup blocker has prevented this window from opening. Please disable any popup blocking software and try again."); } } */ function showClosingCosts(args) { prototypeWindowID++; var windowID = 'ClosingCosts' + prototypeWindowID; contentWin = new Window( windowID, { className: 'dialog', title: 'Closing costs', width:500, height:400, minimizable: false, maximizable: false, closable: true, resizable: true, url: 'closing_costs.asp?' + args + '&winID=' + windowID, showEffect: Element.show, hideEffect: Element.hide } ) contentWin.showCenter(false); } // Validate dependent ages field function dependentAge(f) { // Get field value var dependentAges = $F(f); // How many dependents did they say they had? var numDependents = 0; if (f == "Borrower_Dependent_Age1") { numDependents = parseInt($F("Borrower_No_Dependents")); } else if (f == "CoBorrower_Dependent_Age1") { numDependents = parseInt($F("CoBorr_No_Dependents")); } else { return false; } // If they have 0 dependents, but they've listed ages, something's wrong if (parseInt(numDependents) == 0 && dependentAges.length > 0) { return false; } // Validate the ages are only numbers, commas, or spaces if (!dependentAges.match(/^\d+(,[ ]*\d+)*$/)) { return false; } // Break the ages apart var ages = dependentAges.replace(/,[\s]+/, ",").split(","); if (numDependents != ages.length) { return false; } // Make sure each age is reasonable (0 <= age <= 120?) var i = 0 for (i = 0 ; i < ages.length ; i++) { if (parseInt(ages[i]) < 0 || parseInt(ages[i]) > 120) { return false; } } // Nothing left to check return true; }