WWW_URL = "http://www.upsidevaluation.com"; var investTab = null; var resultsTab = null; var detailedTab = null; //var myTabs = new YAHOO.widget.TabView('tabMenu', { activeIndex:1}); function init() { YAHOO.namespace("main"); investTab = document.getElementById('container'); resultsTab = document.getElementById('chart'); detailedTab = document.getElementById('comment'); } // Yes, I know this seems really redundant. This will be cleaned up later. // This generates the information from the calculations and puts them into the HTML of the page. var handleSuccessResults = function(o){ // alert ('here'); inputsDivRef = returnObjById("inputsDiv"); resultsDivRef = returnObjById("resultsDiv"); strategy_titleRef = returnObjById("strategy_title"); strategy_help_linkRef = returnObjById("strategy_help_link"); errorMessageDivRef = returnObjById("errorMessages"); if (errorMessageDivRef != null) { if (o.responseText.substr(0, 9) == "{*ERROR*}") { errorMessageDivRef.innerHTML = o.responseText.substr(9, o.responseText.length-9) return; } else { errorMessageDivRef.innerHTML = ""; } } curTitle = strategy_titleRef.innerHTML; titleSuffix = ""; if (curTitle != null && curTitle.length >= 7) { titleSuffix = curTitle.substr(curTitle.length-7, 7); } if (titleSuffix != "Results") { newTitle = curTitle + " Results"; strategy_titleRef.innerHTML = newTitle; } switch (curTitle) { case 'Buy and Hold (Rental)' : strategy_help_linkRef.href = WWW_URL + '/strategy/help_results_buyhold.php'; break; case 'Buy, Renovate and Hold (Rental)' : strategy_help_linkRef.href = WWW_URL + '/strategy/help_results_buyrenohold.php'; break; case 'Buy, Renovate, Refinance and Hold (Rental)' : strategy_help_linkRef.href = WWW_URL + '/strategy/help_results_buyrenorefihold.php'; break; case 'Buy, Renovate and Sell' : strategy_help_linkRef.href = WWW_URL + '/strategy/help_results_buyrenosell.php'; break; case 'Buy and Sell' : strategy_help_linkRef.href = WWW_URL + '/strategy/help_results_buysell.php'; break; } resultsDivRef.innerHTML = o.responseText; hideDiv(inputsDivRef); showDiv(resultsDivRef); topInstructionsDivRef = returnObjById("topInstructions"); if (topInstructionsDivRef != null) { hideDiv(topInstructionsDivRef); } //investTab.innerHTML = o.responseText; }; var handleSuccessDetailed = function(o){ resultsTab.innerHTML = o.responseText; }; var handleSuccessComment = function(o){ // If the comment was put into the database successfully then it will return 0. Errors will give a 1. if (o.responseText == 0) { detailedTab.innerHTML = "Your comments were successfully submitted. Thank you for your time."; document.getElementById('commentName').value = ""; document.getElementById('commentEmail').value = ""; document.getElementById('commentTextArea').value = ""; } else if (o.responseText == 2) { detailedTab.innerHTML = "You have not entered any comments. Please enter in a comment before submitting."; } else { detailedTab.innerHTML = "There was an error in the submittion. Please submit your comments again."; } } // If at anytime there is a problem with the connection when using Ajax then this will be called. var handleFailure = function(o){ YAHOO.log("The failure handler was called. tId: " + o.tId + ".", "info", "example"); if(o.responseText !== undefined){ investTab.innerHTML = "
  • Transaction id: " + o.tId + "
  • "; investTab.innerHTML += "
  • HTTP status: " + o.status + "
  • "; investTab.innerHTML += "
  • Status code message: " + o.statusText + "
  • "; } }; // Once again, this is probably redundant. Will clean this up in future releases. var callbackResults = { success:handleSuccessResults, failure:handleFailure }; var callbackDetailed = { success:handleSuccessDetailed, failure:handleFailure }; var callbackComment = { success:handleSuccessComment, failure:handleFailure }; function onSiteLoad(){ sUrl = WWW_URL + "application/View/view_rpc.php"; var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackResults, ''); } var backToInputs = function() { inputsDivRef = returnObjById("inputsDiv"); resultsDivRef = returnObjById("resultsDiv"); resultsButtonRef = returnObjById("resultsButton"); resultsButtonImgRef = returnObjById("resultsButtonImg"); strategy_titleRef = returnObjById("strategy_title"); strategy_help_linkRef = returnObjById("strategy_help_link"); curTitle = strategy_titleRef.innerHTML; titleSuffix = ""; if (curTitle != null && curTitle.length >= 7) { titleSuffix = curTitle.substr(curTitle.length-7, 7); } if (titleSuffix == "Results") { curTitle = curTitle.substr(0, curTitle.length-8); strategy_titleRef.innerHTML = curTitle; } strategy_help_linkRef.href = WWW_URL + '/strategy/help_strategy.php'; showDiv(inputsDivRef); hideDiv(resultsDivRef); topInstructionsDivRef = returnObjById("topInstructions"); if (topInstructionsDivRef != null) { showDiv(topInstructionsDivRef); } } /**************************************************** This is where the meat of the program starts. ****************************************************/ //var strategy_ref = document.getElementById('investmentStrategy'); // Saving input values and posting the data. var makeStrategyRequest = function() { var sUrl = ""; strategyRef = returnObjById("strategyName"); switch (strategyRef.value) { case "primary": case "HOLD_RENTAL": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_RESULTS_HOLD_RENTAL']); //pageTracker._trackPageview("/VIEW_RESULTS_HOLD_RENTAL"); } // Section to grab variables for primary and rental strategies sUrl = WWW_URL + "/application/Results/resultBasic.php"; //createInvestmentGraph(); postData = setMortgageData() + setPurchaseData() + setExpenseData() + setOptionalData(); break; case "buyRenoHold": case "RENO_HOLD_RENTAL": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_RESULTS_RENO_HOLD_RENTAL']); //pageTracker._trackPageview("/VIEW_RESULTS_RENO_HOLD_RENTAL"); } // Section to grab variables for the buy/reno/hold strategy. sUrl = WWW_URL + "/application/Results/resultMedium.php"; //createInvestmentGraph(); postData = setMortgageData() + setPurchaseData() + setExpenseRenoData() + setRenoData() + setOptionalData(); break; case "buyRenoRefiHold": case "RENO_FINANCE_HOLD_RENTAL": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_RENO_FINANCE_HOLD_RENTAL']); //pageTracker._trackPageview("/VIEW_RENO_FINANCE_HOLD_RENTAL"); } // Section to grab variables for the buy/reno/refi/hold strategy. sUrl = WWW_URL + "/application/Results/resultHigh.php"; createInvestmentGraph(); postData = setMortgageRefiData() + setPurchaseData() + setExpenseRenoData() + setRenoRefiData() + setInvestorData() + setOptionalData(); break; case "buySell": case "SELL": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_SELL']); //pageTracker._trackPageview("/VIEW_SELL"); } // Section to grab variables for the buy and sell strategy. sUrl = WWW_URL + "/application/Results/resultSale.php"; // Used for clearing the bar graph. Will have a profit bar graph in future releases. //sUrl2 = WWW_URL + "application/Clear/clear.php"; //var request2 = YAHOO.util.Connect.asyncRequest('POST', sUrl2, callbackDetailed, ""); postData = setMortgageData() + setPurchaseData() + setExpenseData() + setSaleData() + setInvestorData() + setOptionalData(); break; case "buyRenoSell": case "RENO_SELL": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_RENO_SELL']); //pageTracker._trackPageview("/VIEW_RENO_SELL"); } sUrl = WWW_URL + "/application/Results/resultSaleReno.php"; // Used for clearing the bar graph. Will have a profit bar graph in future releases. //sUrl2 = WWW_URL + "/application/Clear/clear.php"; //var request2 = YAHOO.util.Connect.asyncRequest('POST', sUrl2, callbackDetailed, ""); postData = setMortgageData() + setPurchaseData() + setExpenseRenoSaleData() + setSaleData() + setRenoSellData() + setInvestorData() + setOptionalData(); break; case "BASIC_MORTGAGE": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_BASIC_MORTGAGE']); //pageTracker._trackPageview("/VIEW_BASIC_MORTGAGE"); } sUrl = WWW_URL + "/application/BasicMortgage/basicMortgage.php"; postData = setBasicMortgageData(); break; case "BASIC_THINKMORTGAGE": if (_gaq != null) { _gaq.push(['_trackPageview','/VIEW_BASIC_THINKMORTGAGE']); //pageTracker._trackPageview("/VIEW_BASIC_THINKMORTGAGE"); } sUrl = WWW_URL + "/application/BasicMortgage/basicThinkMortgage.php"; postData = setBasicMortgageData(); break; } //alert('sending request'); var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackResults, postData); //myTabs.selectTab(4); // This makes it so that after the user clicks on "Calculate" it will bring them to the results tab. /* else if (currentTab == 2) { //sUrl2 = WWW_URL + "application/Clear/clear.php"; // Used for clearing the bar graph. Will have a profit bar graph in future releases. //var request2 = YAHOO.util.Connect.asyncRequest('POST', sUrl2, callbackDetailed, ""); myTabs.selectTab(4); } else if (currentTab == 3) { sUrl = WWW_URL + "application/RateCompare/rateCompare.php"; postData = setRateCompareData(); var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackResults, postData); sUrl2 = WWW_URL + "application/Clear/clear.php"; // Used for clearing the bar graph. Will have a profit bar graph in future releases. var request2 = YAHOO.util.Connect.asyncRequest('POST', sUrl2, callbackDetailed, ""); myTabs.selectTab(4); } */ }; // Clear page of calculations. function clearPage() { // Need to clear inputs as well. Will worry about this in future releases if users want this. var sUrl = WWW_URL + "application/Clear/clear.php"; var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackResults, ""); var request2 = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackDetailed, ""); }; // This function just brings the user back to the inputs tab. Nothing is cleared. function startOver() { // myTabs.selectTab(1); }; // Function to initialize the tabs on the page. (function() { // var tabView = new YAHOO.widget.TabView('tabMenu'); })(); // Function to handle the comments that users may enter. function commentSubmit() { sUrl = WWW_URL + "/application/Comment/comment_rpc.php"; var commentName_ref = document.getElementById('commentName'); var commentEmail_ref = document.getElementById('commentEmail'); var commentTextArea_ref = document.getElementById('commentTextArea'); postData = "commentName="+commentName_ref.value+ "&commentEmail="+commentEmail_ref.value+ "&commentTextArea="+commentTextArea_ref.value; var request3 = YAHOO.util.Connect.asyncRequest('POST', sUrl, callbackComment, postData); } //****************************************************************************** // // Section to get variables from page. // //****************************************************************************** // Section to set the mortgage variables into the post data string. function setMortgageData() { var buy_ref = document.getElementById('buyPrice'); var actualPrice_ref = document.getElementById('actualPrice'); var percent_ref = document.getElementById('percentDown'); var mortgageRate_ref = document.getElementById('mortgageRate'); var amortization_ref = document.getElementById('amortization'); var insurancePremium_ref = document.getElementById('insurancePremium'); var paymentType_ref = document.getElementById('paymentType'); var postData = "buyPrice="+buy_ref.value+ "&actualPrice="+actualPrice_ref.value+ "&percentDown="+percent_ref.value+ "&mortgageRate="+mortgageRate_ref.value+ "&amortization="+amortization_ref.value+ "&insurancePremium="+insurancePremium_ref.value+ "&paymentType="+paymentType_ref.value; return (postData); }; // Section to set the mortgage refinance variables into the post data string. function setMortgageRefiData() { var buyBefore_ref = document.getElementById('buyPriceBefore'); var actualPriceBefore_ref = document.getElementById('actualPriceBefore'); var percentBefore_ref = document.getElementById('percentDownBefore'); var mortgageRateBefore_ref = document.getElementById('mortgageRateBefore'); var amortizationBefore_ref = document.getElementById('amortizationBefore'); var insurancePremiumBefore_ref = document.getElementById('insurancePremiumBefore'); var paymentTypeBefore_ref = document.getElementById('paymentTypeBefore'); //var buyAfter_ref = document.getElementById('buyPriceAfter'); //var actualPriceAfter_ref = document.getElementById('actualPriceAfter'); var percentAfter_ref = document.getElementById('percentDownAfter'); var mortgageRateAfter_ref = document.getElementById('mortgageRateAfter'); var amortizationAfter_ref = document.getElementById('amortizationAfter'); var insurancePremiumAfter_ref = document.getElementById('insurancePremiumAfter'); var paymentTypeAfter_ref = document.getElementById('paymentTypeAfter'); var postData = "buyPriceBefore="+buyBefore_ref.value+ "&actualPriceBefore="+actualPriceBefore_ref.value+ "&percentDownBefore="+percentBefore_ref.value+ "&mortgageRateBefore="+mortgageRateBefore_ref.value+ "&amortizationBefore="+amortizationBefore_ref.value+ "&insurancePremiumBefore="+insurancePremiumBefore_ref.value+ "&paymentTypeBefore="+paymentTypeBefore_ref.value+ //"&buyPriceAfter="+buyAfter_ref.value+ //"&actualPriceAfter="+actualPriceAfter_ref.value+ "&percentDownAfter="+percentAfter_ref.value+ "&mortgageRateAfter="+mortgageRateAfter_ref.value+ "&amortizationAfter="+amortizationAfter_ref.value+ "&insurancePremiumAfter="+insurancePremiumAfter_ref.value+ "&paymentTypeAfter="+paymentTypeAfter_ref.value; return (postData); } // Section to set the purchase variables into the post data string. function setPurchaseData() { var lawyerPurchase_ref = document.getElementById('lawyerPurchase'); var appraisalPurchase_ref = document.getElementById('appraisalPurchase'); var inspectionPurchase_ref = document.getElementById('inspectionPurchase'); var otherPurchase_ref = document.getElementById('otherPurchase'); var postData = "&lawyerPurchase="+lawyerPurchase_ref.value+ "&appraisalPurchase="+appraisalPurchase_ref.value+ "&inspectionPurchase="+inspectionPurchase_ref.value+ "&otherPurchase="+otherPurchase_ref.value; return (postData); } // Section to set the expense variables into the post data string. function setExpenseData() { var rent_ref = document.getElementById('rent'); var vacancyRate_ref = document.getElementById('vacancyRate'); var condoFees_ref = document.getElementById('condoFees'); var utilities_ref = document.getElementById('utilities'); var extraIncome_ref = document.getElementById('extraIncome'); var maintenanceCost_ref = document.getElementById('maintenanceCost'); var management_ref = document.getElementById('management'); var advertise_ref = document.getElementById('advertising'); var insurance_ref = document.getElementById('insurance'); var propertyTax_ref = document.getElementById('propertyTax'); var postData = "&rent="+rent_ref.value+ "&vacancyRate="+vacancyRate_ref.value+ "&condoFees="+condoFees_ref.value+ "&utilities="+utilities_ref.value+ "&extraIncome="+extraIncome_ref.value+ "&maintenanceCost="+maintenanceCost_ref.value+ "&management="+management_ref.value+ "&advertising="+advertise_ref.value+ "&insurance="+insurance_ref.value+ "&propertyTax="+propertyTax_ref.value; return (postData); }; // Section to set the renovation expense variables into the post data string. function setExpenseRenoData() { var rentBefore_ref = document.getElementById('rentBefore'); var vacancyRateBefore_ref = document.getElementById('vacancyRateBefore'); var condoFeesBefore_ref = document.getElementById('condoFeesBefore'); var utilitiesBefore_ref = document.getElementById('utilitiesBefore'); var extraIncomeBefore_ref = document.getElementById('extraIncomeBefore'); var maintenanceCostBefore_ref = document.getElementById('maintenanceCostBefore'); var advertisingBefore_ref = document.getElementById('advertisingBefore'); var managementBefore_ref = document.getElementById('managementBefore'); var insuranceBefore_ref = document.getElementById('insuranceBefore'); var propertyTaxBefore_ref = document.getElementById('propertyTaxBefore'); var rentDuring_ref = document.getElementById('rentDuring'); var vacancyRateDuring_ref = document.getElementById('vacancyRateDuring'); var condoFeesDuring_ref = document.getElementById('condoFeesDuring'); var utilitiesDuring_ref = document.getElementById('utilitiesDuring'); var extraIncomeDuring_ref = document.getElementById('extraIncomeDuring'); var maintenanceCostDuring_ref = document.getElementById('maintenanceCostDuring'); var advertisingDuring_ref = document.getElementById('advertisingDuring'); var managementDuring_ref = document.getElementById('managementDuring'); var insuranceDuring_ref = document.getElementById('insuranceDuring'); var propertyTaxDuring_ref = document.getElementById('propertyTaxDuring'); var rentAfter_ref = document.getElementById('rentAfter'); var vacancyRateAfter_ref = document.getElementById('vacancyRateAfter'); var condoFeesAfter_ref = document.getElementById('condoFeesAfter'); var utilitiesAfter_ref = document.getElementById('utilitiesAfter'); var extraIncomeAfter_ref = document.getElementById('extraIncomeAfter'); var maintenanceCostAfter_ref = document.getElementById('maintenanceCostAfter'); var advertisingAfter_ref = document.getElementById('advertisingAfter'); var managementAfter_ref = document.getElementById('managementAfter'); var insuranceAfter_ref = document.getElementById('insuranceAfter'); var propertyTaxAfter_ref = document.getElementById('propertyTaxAfter'); postData = "&rentBefore="+rentBefore_ref.value+ "&vacancyRateBefore="+vacancyRateBefore_ref.value+ "&condoFeesBefore="+condoFeesBefore_ref.value+ "&utilitiesBefore="+utilitiesBefore_ref.value+ "&extraIncomeBefore="+extraIncomeBefore_ref.value+ "&maintenanceCostBefore="+maintenanceCostBefore_ref.value+ "&managementBefore="+managementBefore_ref.value+ "&advertisingBefore="+advertisingBefore_ref.value+ "&insuranceBefore="+insuranceBefore_ref.value+ "&propertyTaxBefore="+propertyTaxBefore_ref.value+ "&rentDuring="+rentDuring_ref.value+ "&vacancyRateDuring="+vacancyRateDuring_ref.value+ "&condoFeesDuring="+condoFeesDuring_ref.value+ "&utilitiesDuring="+utilitiesDuring_ref.value+ "&extraIncomeDuring="+extraIncomeDuring_ref.value+ "&maintenanceCostDuring="+maintenanceCostDuring_ref.value+ "&managementDuring="+managementDuring_ref.value+ "&advertisingDuring="+advertisingDuring_ref.value+ "&insuranceDuring="+insuranceDuring_ref.value+ "&propertyTaxDuring="+propertyTaxDuring_ref.value+ "&rentAfter="+rentAfter_ref.value+ "&vacancyRateAfter="+vacancyRateAfter_ref.value+ "&condoFeesAfter="+condoFeesAfter_ref.value+ "&utilitiesAfter="+utilitiesAfter_ref.value+ "&extraIncomeAfter="+extraIncomeAfter_ref.value+ "&maintenanceCostAfter="+maintenanceCostAfter_ref.value+ "&managementAfter="+managementAfter_ref.value+ "&advertisingAfter="+advertisingAfter_ref.value+ "&insuranceAfter="+insuranceAfter_ref.value+ "&propertyTaxAfter="+propertyTaxAfter_ref.value; return (postData); }; // Section to set the renovation expense for the sale variables into the post data string. function setExpenseRenoSaleData() { // This section is not posting the values properly from the input table. var rentDuring_ref = document.getElementById('rentRenoDuring'); var vacancyRateDuring_ref = document.getElementById('vacancyRateRenoDuring'); var condoFeesDuring_ref = document.getElementById('condoFeesRenoDuring'); var utilitiesDuring_ref = document.getElementById('utilitiesRenoDuring'); var extraIncomeDuring_ref = document.getElementById('extraIncomeRenoDuring'); var maintenanceCostDuring_ref = document.getElementById('maintenanceCostRenoDuring'); var managementDuring_ref = document.getElementById('managementRenoDuring'); var advertisingDuring_ref = document.getElementById('advertisingRenoDuring'); var insuranceDuring_ref = document.getElementById('insuranceRenoDuring'); var propertyTaxDuring_ref = document.getElementById('propertyTaxRenoDuring'); var rentAfter_ref = document.getElementById('rentRenoAfter'); var vacancyRateAfter_ref = document.getElementById('vacancyRateRenoAfter'); var condoFeesAfter_ref = document.getElementById('condoFeesRenoAfter'); var utilitiesAfter_ref = document.getElementById('utilitiesRenoAfter'); var extraIncomeAfter_ref = document.getElementById('extraIncomeRenoAfter'); var maintenanceCostAfter_ref = document.getElementById('maintenanceCostRenoAfter'); var managementAfter_ref = document.getElementById('managementRenoAfter'); var advertisingAfter_ref = document.getElementById('advertisingRenoAfter'); var insuranceAfter_ref = document.getElementById('insuranceRenoAfter'); var propertyTaxAfter_ref = document.getElementById('propertyTaxRenoAfter'); postData = "&rentDuring="+rentDuring_ref.value+ "&vacancyRateDuring="+vacancyRateDuring_ref.value+ "&condoFeesDuring="+condoFeesDuring_ref.value+ "&utilitiesDuring="+utilitiesDuring_ref.value+ "&extraIncomeDuring="+extraIncomeDuring_ref.value+ "&maintenanceCostDuring="+maintenanceCostDuring_ref.value+ "&managementDuring="+managementDuring_ref.value+ "&advertisingDuring="+advertisingDuring_ref.value+ "&insuranceDuring="+insuranceDuring_ref.value+ "&propertyTaxDuring="+propertyTaxDuring_ref.value+ "&rentAfter="+rentAfter_ref.value+ "&vacancyRateAfter="+vacancyRateAfter_ref.value+ "&condoFeesAfter="+condoFeesAfter_ref.value+ "&utilitiesAfter="+utilitiesAfter_ref.value+ "&extraIncomeAfter="+extraIncomeAfter_ref.value+ "&maintenanceCostAfter="+maintenanceCostAfter_ref.value+ "&managementAfter="+managementAfter_ref.value+ "&advertisingAfter="+advertisingAfter_ref.value+ "&insuranceAfter="+insuranceAfter_ref.value+ "&propertyTaxAfter="+propertyTaxAfter_ref.value; return (postData); }; // Section to set the renovation variables into the post data string. function setRenoData() { var renoCost_ref = document.getElementById('renoCost'); var renoDuration_ref = document.getElementById('renoDuration'); var newActualPrice_ref = document.getElementById('newActualPrice'); postData = "&renoCost="+renoCost_ref.value+ "&renoDuration="+renoDuration_ref.value+ "&newActualPrice="+newActualPrice_ref.value; return (postData); }; // Section to set the renovation variables into the post data string. function setRenoSellData() { var renoCost_ref = document.getElementById('renoCost'); var renoDuration_ref = document.getElementById('renoDuration'); postData = "&renoCost="+renoCost_ref.value+ "&renoDuration="+renoDuration_ref.value; return (postData); }; // Section to set the renovation variables without the new market price for refinance into the post data string. function setRenoRefiData() { var renoRefiCost_ref = document.getElementById('renoCost'); var renoRefiDuration_ref = document.getElementById('renoDuration'); var newActualPrice_ref = document.getElementById('newActualPrice'); postData = "&renoRefiCost="+renoRefiCost_ref.value+ "&renoRefiDuration="+renoRefiDuration_ref.value+ "&newActualPrice="+newActualPrice_ref.value; return (postData); }; // Section to set the investor variables into the post data string. function setInvestorData() { //var useInvestor_ref = document.getElementById('useInvestor'); var amountBorrowed_ref = document.getElementById('amountBorrowed'); //postData = "&useInvestor="+useInvestor_ref.value; //if (useInvestor_ref.value == "True") { if (amountBorrowed_ref.value != "") { //var amountBorrowed_ref = document.getElementById('amountBorrowed'); var repayMethod_ref = document.getElementById('repayMethod'); if(repayMethod_ref.value == "interestMethod") { var loanDuration_ref = document.getElementById('loanDuration'); var interestInput_ref = document.getElementById('interestInput'); postData = postData + "&repayMethod="+repayMethod_ref.value+ "&amountBorrowed="+amountBorrowed_ref.value+ "&interestInput="+interestInput_ref.value+ "&loanDuration="+loanDuration_ref.value; } else if (repayMethod_ref.value == "flatMethod") { var flatInput_ref = document.getElementById('flatInput'); postData = postData + "&repayMethod="+repayMethod_ref.value+ "&amountBorrowed="+amountBorrowed_ref.value+ "&flatInput="+flatInput_ref.value; } } return (postData); }; // Section to set the Sale variables into the post data string. function setSaleData() { var salePrice_ref = document.getElementById('salePrice'); var saleCost_ref = document.getElementById('saleCost'); var lawyerSale_ref = document.getElementById('lawyerSale'); var appraisalSale_ref = document.getElementById('appraisalSale'); var inspectionSale_ref = document.getElementById('inspectionSale'); var realProperty_ref = document.getElementById('realProperty'); postData = "&salePrice="+salePrice_ref.value + "&saleCost="+saleCost_ref.value + "&lawyerSale="+lawyerSale_ref.value + "&appraisalSale="+appraisalSale_ref.value + "&inspectionSale="+inspectionSale_ref.value + "&realProperty="+realProperty_ref.value; return (postData); }; // Section to set the optional variables into the post data string. function setOptionalData() { var appreciation_ref = document.getElementById('appreciation'); var inflation_ref = document.getElementById('inflation'); /*if (appreciation_ref.value <= 0) { appreciation_ref.value = "3"; } if (inflation_ref.value <= 0) { inflation_ref.value = "3"; }*/ postData = "&appreciation="+appreciation_ref.value+ "&inflation="+inflation_ref.value; return (postData); }; //****************************************************************************** // // Section for the basic mortgage variables to be grabbed. // //****************************************************************************** function setBasicMortgageData() { var mortgageAmount_ref = document.getElementById('mortgageAmount'); var mortgageRateInterest_ref = document.getElementById('mortgageRateInterest'); var mortgageRateTerm_ref = document.getElementById('mortgageRateTerm'); var mortgageAmortization_ref = document.getElementById('mortgageAmortization'); var postData = "mortgageAmount="+mortgageAmount_ref.value+ "&mortgageRateInterest="+mortgageRateInterest_ref.value+ "&mortgageRateTerm="+mortgageRateTerm_ref.value+ "&mortgageAmortization="+mortgageAmortization_ref.value; return (postData); }; //****************************************************************************** // // Section for the Rate Compare variables to be grabbed. // //****************************************************************************** function setRateCompareData() { var originalLoanAmount_ref = document.getElementById('originalLoanAmount'); var whatIfPenalty_ref = document.getElementById('whatIfPenalty'); var originalRate_ref = document.getElementById('originalRate'); var whatIfRate_ref = document.getElementById('whatIfRate'); var originalRateTerm_ref = document.getElementById('originalRateTerm'); var originalAmortization_ref = document.getElementById('originalAmortization'); var originalPaymentType_ref = document.getElementById('originalPaymentType'); var postData = "originalLoanAmount="+originalLoanAmount_ref.value+ "&whatIfPenalty="+whatIfPenalty_ref.value+ "&originalRate="+originalRate_ref.value+ "&whatIfRate="+whatIfRate_ref.value+ "&originalRateTerm="+originalRateTerm_ref.value+ "&originalAmortization="+originalAmortization_ref.value+ "&originalPaymentType="+originalPaymentType_ref.value; return (postData); }; //****************************************************************************** // // Section to try and create the graphs // //****************************************************************************** // Section to create a graph for the investment strategies. function createInvestmentGraph() { /* //var strategy_ref = document.getElementById('investmentStrategy'); // This switch statement is to help us figure out which values to grab depending on the investment strategy. switch (strategy_ref.value) { case "primary": case "rental": case "buyRenoHold": var buy_ref = document.getElementById('buyPrice'); var amortization_ref = document.getElementById('amortization'); break; case "buyRenoRefiHold": // Section to grab variables for the buy/reno/refi/hold strategy. var buy_ref = document.getElementById('actualPriceAfter'); var amortization_ref = document.getElementById('amortizationAfter'); break; case "buySell": break; case "buyRenoSell": break; } YAHOO.widget.Chart.SWFURL = "http://www.upsidevaluation.comassets/lib/yui/build/charts/assets/charts.swf"; var jsonData = new YAHOO.util.DataSource( dataGraph() ); // When using JSON use double quotes, single quotes will give an error. jsonData.connMethodPost = true; jsonData.responseType = YAHOO.util.DataSource.TYPE_JSON; jsonData.responseSchema = { resultsList: "Results", fields: ["Year","Value"] }; //Style object for chart var styleDef = { yAxis: { titleRotation:-90 } } YAHOO.formatCurrencyAxisLabel = function( value ) { return YAHOO.util.Number.format( value, { prefix: "$", thousandsSeparator: ",", decimalPlaces: 2 }); } var yAxis = new YAHOO.widget.NumericAxis(); yAxis.minimum = 0; yAxis.maximum = buy_ref.value; yAxis.labelFunction = YAHOO.formatCurrencyAxisLabel; yAxis.title = "Mortgage Balance"; var xAxis = new YAHOO.widget.NumericAxis(); xAxis.maximum = amortization_ref.value; xAxis.title = "Years"; var mychart = new YAHOO.widget.ColumnChart( "chart", jsonData, { xField: "Year", yField: "Value", xAxis: xAxis, yAxis: yAxis, style: styleDef, //only needed for flash player express install expressInstall: "assets/expressinstall.swf" }); */ }; // Section to create the data for the investment graph. function dataGraph() { /* // var strategy_ref = document.getElementById('investmentStrategy'); // Set up section so that it can handle both regular mortgage or refinance mortgage. // Create new function which holds arrays? switch (strategy_ref.value) { case "primary": case "rental": case "buyRenoHold": var buy_ref = document.getElementById('buyPrice'); var percent_ref = document.getElementById('percentDown'); var mortgageRate_ref = document.getElementById('mortgageRate'); var amortization_ref = document.getElementById('amortization'); var insurancePremium_ref = document.getElementById('insurancePremium'); var paymentType_ref = document.getElementById('paymentType'); break; case "buyRenoRefiHold": // Section to grab variables for the buy/reno/refi/hold strategy. var buy_ref = document.getElementById('actualPriceAfter'); var percent_ref = document.getElementById('percentDownAfter'); var mortgageRate_ref = document.getElementById('mortgageRateAfter'); var amortization_ref = document.getElementById('amortizationAfter'); var insurancePremium_ref = document.getElementById('insurancePremiumAfter'); var paymentType_ref = document.getElementById('paymentTypeAfter'); break; case "buySell": break; case "buyRenoSell": break; } // Calculating mortgage payment on the purchase price including insurance premiums. var percentDownPayment = (percent_ref.value / 100) * buy_ref.value; var mortgageRatePercent = mortgageRate_ref.value / 100; var insurancePremiumPercent = insurancePremium_ref.value / 100; // Math.round only works for whole numbers. You must multiply by 100 then divide by 100 after the calculations. Make function for this later to clean up code. var mortgagePaymentBuyPrice = Math.round(((((buy_ref.value - percentDownPayment) + ((buy_ref.value - percentDownPayment) * insurancePremiumPercent)) * (Math.pow((Math.pow((1 + (mortgageRatePercent / 2)), 2)),(1 / 12)) - 1)) / (1 - Math.pow(((Math.pow((Math.pow((1 + (mortgageRatePercent / 2)),2)),(1 / 12)))),(0 - (amortization_ref.value * 12))))) * 100) / 100; var payDuration = 0; var mort_month_ref = 0; if (paymentType_ref.value == "Monthly") { // monthly payments payDuration = 12; mort_month_ref = mortgagePaymentBuyPrice; } else if (paymentType_ref.value == "SemiMonthly") { // payments on the 1st and 15th of each month payDuration = 24; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 2 * 100) / 100; } else if (paymentType_ref.value == "Biweekly") { payDuration = 26; mort_month_ref = Math.round(mortgagePaymentBuyPrice * 12 / 26 * 100) / 100; } else if (paymentType_ref.value == "Accelerated Biweekly") { // Payment on every second week. This makes it so that from time to time you pay for // 13 months instead of 12 months in a year. payDuration = 26; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 2 * 100) / 100; } else if (paymentType_ref.value == "Weekly") { // Pay every week payDuration = 52; mort_month_ref = Math.round(mortgagePaymentBuyPrice * 12 / 52 * 100) / 100; } else if (paymentType_ref.value == "Accelerated Weekly") { // Pay every week but at a higher price payDuration = 52; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 4 * 100) / 100; } // Calculating the Canadian mortgage interest rates // Should the mortgage rate be based on the payment type or just based around a 12 month period? monthly_mortgageRate = ((Math.pow(Math.pow(1 + (mortgageRatePercent / 2), 2), (1 / payDuration)) - 1) * 100).toFixed(6); //calculates mortgage rate for a year. var newBalance = buy_ref.value - percentDownPayment; var balanceTotal = new Array(); var interest = 0; var principle = 0; for (var yearCounter = 0; yearCounter <= amortization_ref.value; yearCounter++) { balanceTotal[yearCounter] = newBalance; for (var monthCounter = 0; monthCounter < payDuration; monthCounter++) { interest = Math.round(newBalance * monthly_mortgageRate) / 100; principle = Math.round((mort_month_ref - interest) * 100) / 100; newBalance = newBalance - principle; } } var max = amortization_ref.value; var stringJSON = '{"Results": ['; for (var i = 0; i <= max; i++) { stringJSON = stringJSON + '{"Year":"' + i + '","Value":"' + balanceTotal[i] + '"}'; if (i < max) { stringJSON = stringJSON + ','; } } stringJSON = stringJSON + '] }'; var objectJSON = YAHOO.lang.JSON.parse(stringJSON); return(objectJSON); */ }; // Section to create a graph for a basic mortgage calculator. function createBasicGraph() { var mortgageAmount_ref = document.getElementById('mortgageAmount'); var mortgageAmortization_ref = document.getElementById('mortgageAmortization'); YAHOO.widget.Chart.SWFURL = "http://www.upsidevaluation.comassets/lib/yui/build/charts/assets/charts.swf"; var jsonData = new YAHOO.util.DataSource( dataBasicGraph() ); // When using JSON use double quotes, single quotes will give an error. jsonData.connMethodPost = true; jsonData.responseType = YAHOO.util.DataSource.TYPE_JSON; jsonData.responseSchema = { resultsList: "Results", fields: ["Year","Value"] }; //Style object for chart var styleDef = { yAxis: { titleRotation:-90 } } YAHOO.formatCurrencyAxisLabel = function( value ) { return YAHOO.util.Number.format( value, { prefix: "$", thousandsSeparator: ",", decimalPlaces: 2 }); } var yAxis = new YAHOO.widget.NumericAxis(); yAxis.minimum = 0; yAxis.maximum = mortgageAmount_ref.value; yAxis.labelFunction = YAHOO.formatCurrencyAxisLabel; yAxis.title = "Mortgage Balance"; var xAxis = new YAHOO.widget.NumericAxis(); xAxis.maximum = mortgageAmortization_ref.value; xAxis.title = "Years"; var mychart = new YAHOO.widget.ColumnChart( "chart", jsonData, { xField: "Year", yField: "Value", xAxis: xAxis, yAxis: yAxis, style: styleDef, //only needed for flash player express install expressInstall: "assets/expressinstall.swf" }); }; // Section that contains the graph data. function dataBasicGraph() { var mortgageAmount_ref = document.getElementById('mortgageAmount'); var mortgageRateInterest_ref = document.getElementById('mortgageRateInterest'); var mortgageAmortization_ref = document.getElementById('mortgageAmortization'); var mortgagePaymentType_ref = document.getElementById('mortgagePaymentType'); // Calculating mortgage payment on the purchase price.. var mortgageRateInterest = mortgageRateInterest_ref.value / 100; // Math.round only works for whole numbers. You must multiply by 100 then divide by 100 after the calculations. Make function for this later to clean up code. var mortgagePaymentBuyPrice = Math.round(((mortgageAmount_ref.value * (Math.pow((Math.pow((1 + (mortgageRateInterest / 2)), 2)),(1 / 12)) - 1)) / (1 - Math.pow(((Math.pow((Math.pow((1 + (mortgageRateInterest / 2)),2)),(1 / 12)))),(0 - (mortgageAmortization_ref.value * 12))))) * 100) / 100; var payDuration = 0; var mort_month_ref = 0; if (mortgagePaymentType_ref.value == "Monthly") { // monthly payments payDuration = 12; mort_month_ref = mortgagePaymentBuyPrice; } else if (mortgagePaymentType_ref.value == "SemiMonthly") { // payments on the 1st and 15th of each month payDuration = 24; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 2 * 100) / 100; } else if (mortgagePaymentType_ref.value == "Biweekly") { payDuration = 26; mort_month_ref = Math.round(mortgagePaymentBuyPrice * 12 / 26 * 100) / 100; } else if (mortgagePaymentType_ref.value == "Accelerated Biweekly") { // Payment on every second week. This makes it so that from time to time you pay for // 13 months instead of 12 months in a year. payDuration = 26; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 2 * 100) / 100; } else if (mortgagePaymentType_ref.value == "Weekly") { // Pay every week payDuration = 52; mort_month_ref = Math.round(mortgagePaymentBuyPrice * 12 / 52 * 100) / 100; } else if (mortgagePaymentType_ref.value == "Accelerated Weekly") { // Pay every week but at a higher price payDuration = 52; mort_month_ref = Math.round(mortgagePaymentBuyPrice / 4 * 100) / 100; } // Calculating the Canadian mortgage interest rates // Should the mortgage rate be based on the payment type or just based around a 12 month period? monthly_mortgageRate = ((Math.pow(Math.pow(1 + (mortgageRateInterest / 2), 2), (1 / payDuration)) - 1) * 100).toFixed(6); //calculates mortgage rate for a year. var newBalance = mortgageAmount_ref.value; var balanceTotal = new Array(); var interest = 0; var principle = 0; for (var yearCounter = 0; yearCounter <= mortgageAmortization_ref.value; yearCounter++) { balanceTotal[yearCounter] = newBalance; for (var monthCounter = 0; monthCounter < payDuration; monthCounter++) { interest = Math.round(newBalance * monthly_mortgageRate) / 100; principle = Math.round((mort_month_ref - interest) * 100) / 100; newBalance = newBalance - principle; } } var max = mortgageAmortization_ref.value; var stringJSON = '{"Results": ['; for (var i = 0; i <= max; i++) { stringJSON = stringJSON + '{"Year":"' + i + '","Value":"' + balanceTotal[i] + '"}'; if (i < max) { stringJSON = stringJSON + ','; } } stringJSON = stringJSON + '] }'; var objectJSON = YAHOO.lang.JSON.parse(stringJSON); return(objectJSON); }; YAHOO.util.Event.onDOMReady(init);