function showHelp(title)
{
    var text = "";
    switch(title)
    {
    case "IRR Calculator":
            text = "Hover over any of the (?) on the page to get more help information.";
            break;
    case "Project Name":
            text = "";
            break;
    case "Square Footage":
            text = "The square foot is an imperial unit / U.S. customary unit (non-SI non-metric) of area, used mainly in the United States, the United Kingdom, Hong Kong, Japan, Afganistan and Canada. It is defined as the area of a square with sides of 1 foot (0.333... yards, 12 inches, or 0.3048 metres) in length.<br /><br />A symbol for square foot, square feet, and per square foot commonly used in architecture, real estate and interior space plans is a simple square with a vertical line bisecting it. It is also occasionally written as a square with a slash through it.";
            text += "<br /><br />e.g 1200";
            break;
    case "Property Type":
            text = "";
            break;
    case "GSI":
            text = "Gross Scheduled Income is the theoretical maximum achievable annualized income assuming full rental occupancy.";
            break;		
    case "Vacancy Factor":
            text = "<p>Vacancy factor is a measurement of gross rental income loss due to vacancy and non-collection of rent. The rate is expressed as a percentage, and is calculated by dividing lost rental income (from vacancy and non-collection) into total potential gross rental income (including income from other rental units and the lost income).</p>";
            text += "<br /><br />This is entered as a percentage. e.g 10";
            break;		
    case "EGI":
            text = "Effective gross income (EGI) estimates the total income of the project while taking vacancy loss and other (non-rent) revenues into account. Finding suitable tenants takes time and lost revenue from unoccupied units is an important consideration after a project opens its doors. On the other hand, other revenue from a project can help increase the EGI of a project.";
            break;		
    case "Property CAP Rate":
            text = "A Capitalization Rate or Cap Rate rate is determined by evaluating the financial data of similar properties which have recently sold in a specific market.  It provides a more reliable estimate of value than a market Gross Rent Multiplier since the cap rate calculation utilizes more of a property's financial detail. The GRM calculation only considers a property's selling price and gross rents.  The Cap Rate calculation incorporates a property's selling price, gross rents, non rental income, vacancy amount and operating expenses thus providing a more reliable estimate of value.";
            break;		
    case "Expenses":
            text = "Any cost of doing business resulting from revenue-generating activities.";
            break;		
    case "Reserves":
            text = "Lorem Ipsum doloreum malastras feyodor ranka.";
            break;	
    case "Reserves - note":
            text = "Lorem Ipsum doloreum malastras feyodor ranka.";
            break;		
    case "NOI":
            text = "Net Operating Income or NOI is equal to a property's yearly gross income less operating expenses.  Gross income includes both rental income and other income such as parking fees, laundry and vending receipts, etc.  All income associated with a property.  Operating expenses are costs incurred during the operation and  maintenance of a property.  They include repairs and maintenance, insurance, management fees, utilities, supplies, property taxes, etc.";
            break;		
    case "Valuation Information":
            text = "Lorem Ipsum doloreum malastras feyodor ranka.";
            break;
    case "Property CAP rate":
            text = "The Capitalization Rate or Cap Rate is a ratio used to estimate the value of income producing properties.  Put simply, the cap rate is the net operating income divided by the sales price or value of a property expressed as a percentage.  Investors, lenders and appraisers use the cap rate to estimate the purchase price for different types of  income producing properties.";
            break;			
    case "Bank Information":
            text = "";
            break;
    case "Down Payment":
            text = "Down payment (or downpayment) is a term used in the context of the purchase of expensive items such as a car and a house, whereby the payment is the initial upfront portion of the total amount due and it is usually given in cash at the time of finalizing the transaction.[1] A loan is then required to make the full payment.";
            break;
    case "APR":
            text = "The terms annual percentage of rate (APR), nominal APR, and effective APR (EAR)[1] describe the interest rate for a whole year (annualized), rather than just a monthly fee/rate, as applied on a loan, mortgage, credit card, etc. It is a finance charge expressed as an annual rate.";
            break;
    case "Amortization Period":
            text = "The amortization period is the period of time after which, if all the monthly payments are made, the loan will be paid out.";
            break;
    case "ADS":
            text = "The amount of money on a total yearly basis required for the payment of interest and principal on a long-term debt.";
            break;				
    case "DCR":
            text = "The debt service coverage ratio (DSCR), is the ratio of cash available for debt servicing to interest, principal and lease payments. It is a popular benchmark used in the measurement of an entity's (person or corporation) ability to produce enough cash to cover its debt (including lease) payments. The higher this ratio is, the easier it is to obtain a loan. The phrase is also used in commercial banking and may be expressed as a minimum ratio that is acceptable to a lender; it may be a loan condition or covenant. Breaching a DSCR covenant can, in some circumstances, be an act of default.";
            break;		
    case "Cash Flow Assumptions":
            text = "Lorem Ipsum doloreum malastras feyodor ranka.";
            break;			
    case "Loan Amount Warning":
            text = "Please check with your bank on the loan amount.  Typical loan amounts today range between 25% to 40% down.";
            break;
     case "DCR Warning":
            text = "Your DCR is below 1.20, which is a typical minimum DCR amount.  You may need to increase the down payment in order to increase the DCR.";
            break;
    default:
            // do nothing
    }
    document.getElementById("helptitle").innerHTML = title;	
    document.getElementById("helptext").innerHTML = text;
}

  function openScheduler() {
              // price	name="loan_amount" id='B30'
              // interest	name="apr" id='B32'
              // time	name="amortization_period" id='B33'
              var price = document.getElementById('B30');
              var interest = document.getElementById('B32');
              var time = document.getElementById('B33');
              // these are for the 10 YEAR CF
              var egi = document.getElementById('D14');
              var expenses = document.getElementById('D16');
              var reserves = document.getElementById('D17');
              var sf = document.getElementById('square_footage');
              var B24 = document.getElementById('B24'); //$
              var B34 = document.getElementById('B34'); //$
              var B33 = document.getElementById('B33'); //$
              var B30 = document.getElementById('B30'); //$
              var dollaramountdown = parseInt(B24.value.replace(/,/g,"")) - parseInt(B30.value.replace(/,/g,""));
              var aig = document.getElementById('annual_income_growth_rate'); //%
              var aeg = document.getElementById('annual_expense_growth_rate'); //%
              var d = new Date();
    
                var housePrice = parseInt(price.value.replace(/,/g,"")) - dollaramountdown;
                var years = parseFloat(B33.value);//
                var month = years * 12;
                var negmonth =- 1 * month;
                var interestRate = ((interest.value / 100) / 12);
                var bottom = 1 - (Math.pow(interestRate+1,negmonth));
                var top = interestRate;
                var mid = top / bottom;
                //alert(housePrice * mid);
                //return false;
                /*url_with_query_string += "?price=" + parseInt(price.value.replace(/,/g,"")) 
                      + "&interest=" + (interest.value / 100)
                      + "&time=" + time.value 
                      + "&egi=" + parseInt(egi.value.replace(/,/g,"")) 
                      + "&expenses=" + parseInt(expenses.value.replace(/,/g,"")) 
                      + "&reserves=" + parseInt(reserves.value.replace(/,/g,""))
                      + "&sf=" + parseInt(sf.value.replace(/,/g,""))
                      + "&dollaramountdown=" + dollaramountdown
                      + "&aig=" + aig.value
                      + "&aeg=" + aeg.value
                      + "&startm=" + (d.getMonth()+1)
                      + "&startyear=" + d.getFullYear()
                      + "&monthPay=" + (housePrice * mid) 
                      + "&month=" + (B33.value*12)
                      + "&addpayment=0.00";*/
                pre_url_with_query_string = "project_name=" + document.getElementById('project_name').value; 
                pre_url_with_query_string += "&property_type=" + document.getElementById('property_type').value; 
                pre_url_with_query_string += "&gsi_month=" + (!isNaN(parseInt(document.getElementById('C10').value.replace(/,/g,"")))?parseInt(document.getElementById('C10').value.replace(/,/g,"")):0); 
                pre_url_with_query_string += "&gsi_annual=" + (!isNaN(parseInt(document.getElementById('D10').value.replace(/,/g,"")))?parseInt(document.getElementById('D10').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&vacancy_factor=" + (!isNaN(parseInt(document.getElementById('B12').value.replace(/,/g,"")))?parseInt(document.getElementById('B12').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&expenses_percent=" + (!isNaN(parseInt(document.getElementById('B16').value.replace(/,/g,"")))?parseInt(document.getElementById('B16').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&reserves_percent=" + (!isNaN(parseInt(document.getElementById('B17').value.replace(/,/g,"")))?parseInt(document.getElementById('B17').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&property_cap_rate=" + (!isNaN(parseInt(document.getElementById('B25').value.replace(/,/g,"")))?parseInt(document.getElementById('B25').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&loan_amount_percent=" + (!isNaN(parseInt(document.getElementById('B29').value.replace(/,/g,"")))?parseInt(document.getElementById('B29').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&apr=" + (!isNaN(parseInt(document.getElementById('B32').value.replace(/,/g,"")))?parseInt(document.getElementById('B32').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&amortization_period=" + (!isNaN(parseInt(document.getElementById('B33').value.replace(/,/g,"")))?parseInt(document.getElementById('B33').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&annual_income_growth_rate=" + (!isNaN(parseInt(document.getElementById('annual_income_growth_rate').value.replace(/,/g,"")))?parseInt(document.getElementById('annual_income_growth_rate').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&annual_expense_growth_rate=" + (!isNaN(parseInt(document.getElementById('annual_expense_growth_rate').value.replace(/,/g,"")))?parseInt(document.getElementById('annual_expense_growth_rate').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&square_footage=" + (!isNaN(parseInt(document.getElementById('square_footage').value.replace(/,/g,"")))?parseInt(document.getElementById('square_footage').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&equity_percent=" + (!isNaN(parseInt(document.getElementById('B31').value.replace(/,/g,"")))?parseInt(document.getElementById('B31').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&amortization_period=" + (!isNaN(parseInt(document.getElementById('B33').value.replace(/,/g,"")))?parseInt(document.getElementById('B33').value.replace(/,/g,"")):0);
                pre_url_with_query_string += "&price=" + parseInt(price.value.replace(/,/g,""));
                pre_url_with_query_string += "&interest=" + (interest.value / 100);
                pre_url_with_query_string += "&time=" + time.value;
                pre_url_with_query_string += "&egi=" + parseInt(egi.value.replace(/,/g,""));
                pre_url_with_query_string += "&expenses=" + parseInt(expenses.value.replace(/,/g,""));
                pre_url_with_query_string += "&reserves=" + parseInt(reserves.value.replace(/,/g,""));
                pre_url_with_query_string += "&sf=" + parseInt(sf.value.replace(/,/g,""));
                pre_url_with_query_string += "&dollaramountdown=" + dollaramountdown;
                pre_url_with_query_string += "&dpayment=" + dollaramountdown;
                pre_url_with_query_string += "&aig=" + aig.value;
                pre_url_with_query_string += "&aeg=" + aeg.value;
                pre_url_with_query_string += "&startm=" + (d.getMonth()+1);
                pre_url_with_query_string += "&startyear=" + d.getFullYear();
                pre_url_with_query_string += "&monthPay=" + (housePrice * mid);
                pre_url_with_query_string += "&month=" + (B33.value*12);
                pre_url_with_query_string += "&addpayment=0.00";
                $.ajax({
                    type: "POST",
                    url: ajax_session_init_dir + "calculator_session.php",
                    data: pre_url_with_query_string,
                    success: function(msg){
                        //alert( "Data Saved: " + msg );
                        window.location.href = url_with_query_string;
                    },
                    error: function(msg){
                        alert( "Data Failed: " + msg );
                    }
                });
                //
              //window.open(url_with_query_string);
      }
    function resetform() {
        document.getElementById('resetme').value = 1;
        $.ajax({
            url: ajax_session_init_dir + "resetcalc.php",
            success: function(msg){
                //alert( "Data Saved: " + msg );
                //window.location.href = thisurl;
                document.form1.submit();
            },
            error: function(msg){
                alert( "Data Failed: " + msg );
            }
        });
    }
//  http://dev-answers.blogspot.com/2007/08/firefox-does-not-reflect-input-form.html
//	function updateDOM(inputField) 
//	function updateAllDOMFields(theForm)
//	function getAllFormFields(theForm)
//
// Will be called by input fields when in 'update DOM' mode. This will
// make sure that changes to input fields in the form will be captured
// in the DOM - not necessary in IE but is required in Moz, etc as the DOM
// will otherwise reflect the page as it was initially.
//
// inputField : the input field that has just been tabbed out of (onBlur) OR the ID of the input field
      function updateDOM(inputField) {
              // if the inputField ID string has been passed in, get the inputField object
              if (typeof inputField == "string") {
                      inputField = document.getElementById(inputField);
              }
              if (inputField.type == "select-one") {
                      for (var i=0; i<inputField.options.length; i++) {
                              if (i == inputField.selectedIndex) {
                                      inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
                              }
                      }
              } else if (inputField.type == "text") {
                      inputField.setAttribute("value",inputField.value);
              } else if (inputField.type == "textarea") {
                      inputField.setAttribute("value",inputField.value);
              } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
                      if (inputField.checked) {
                              inputField.setAttribute("checked","checked");
                      } else {
                      inputField.removeAttribute("checked");
                      }
              }
      }

      function updateAllDOMFields(theForm) {
              var inputNodes = getAllFormFields(theForm);
              for(x=0; x < inputNodes.length; x++){
                      var theNode = inputNodes[x];
                      updateDOM(theNode)
                      } 
              }

      function getAllFormFields(theForm){
              try{
                      var inputFields = theForm.getElementsByTagName("input");
                      var selectFields = theForm.getElementsByTagName("select");
                      var textFields = theForm.getElementsByTagName("textarea");
                      var array = new Array(inputFields + selectFields + textFields);
                      for(i=0; i < array.length; i++){
                              for(x=0; x < inputFields.length; x++){
                                      array[i] = inputFields[x];
                                      i++
                              }
                              for(a=0; a < selectFields.length; a++){
                                      array[i] = selectFields[a];
                                      i++
                              }
                              for(t=0; t < textFields.length; t++){
                                      debug("Text box Found"+textFields.name);
                                      array[i] = textFields[t];
                                      i++
                                      }
                              }
                      }
                      catch(e){alert("Error when evoking getAllFormFields(): \nSomething is probably wrong with the form you passed in\n\n"+e.message)}
              return array;
      }

    function iterator1(oForm) {
      var O = document.getElementById('form_innerHTML');
      var e = oForm;
      for(var i in e)
      {
        if(i == "innerHTML" )
        {
          O.value = e[i];
            }
      }
    }

    function round_number(rnum, rlength) { // Arguments: number to round, number of decimal places
    return Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
    }
  
    function CurrencyFormatted(amount) {
    var i = parseFloat(amount);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
        i = Math.abs(i);
        i = parseInt((i + .005) * 100);
        i = i / 100;
        s = new String(i);
        if(s.indexOf('.') < 0) { s += '.00'; }
        if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
        s = minus + s;
        return s;
    } // end of function CurrencyFormatted()
  
    function CommaFormatted(amount) {
        var delimiter = ","; // replace comma if desired
        var a = amount.split('.',2)
        var d = a[1];
        var i = parseInt(a[0]);
        if(isNaN(i)) { return ''; }
        var minus = '';
        if(i < 0) { minus = '-'; }
        i = Math.abs(i);
        var n = new String(i);
        var a = [];
        while(n.length > 3)
        {
            var nn = n.substr(n.length-3);
            a.unshift(nn);
            n = n.substr(0,n.length-3);
        }
        if(n.length > 0) { a.unshift(n); }
        n = a.join(delimiter);
        if(d.length < 1) { amount = n; }
        else { amount = n + '.' + d; }
        amount = minus + amount;
        return amount;
    } // end of function CommaFormatted()
  
    function update_table(either_or) {
        calc_gross(either_or);
        calc_vacancy();
        calc_egi();
        calc_egi_expenses();
        calc_egi_reserves();
        calc_noi();
        calc_property_value(either_or);
        calc_loan_amount(either_or);
        calc_payment();
        calc_dcr();
        mark_negative_values();
        mark_exceeded_amts();
    }
    
    function mark_exceeded_amts() {
        var B29 = document.getElementById('B29'); // %
        var B29IMG = document.getElementById('B29IMG');
                var B17 = document.getElementById('B17'); // $
        var B17IMG = document.getElementById('B17IMG');		
        if (B29.value > 75)
        {
            B29IMG.style.visibility = "visible";
        }
        else if (B29.value <= 75)
        {
            B29IMG.style.visibility = "hidden";
        }
        if (B17.value > 15)
        {
            B17IMG.style.visibility = "visible";
        }
        else if (B29.value <= 15)
        {
            B17IMG.style.visibility = "hidden";
        }
    }
  
    function unmark_exceeded_amts() {
        var B29IMG = document.getElementById('B29IMG');
                var B17IMG = document.getElementById('B17IMG');
        B29IMG.style.visibility = "hidden";
                B17IMG.style.visibility = "hidden";
    }
    
    function mark_negative_values() {
        for(i=0; i<document.forms[0].elements.length; i++)
        {
            if(document.forms[0].elements[i].type == "text")
            {
                var text_field_id = document.forms[0].elements[i].id;
                if (document.forms[0].elements[i].value.indexOf('-') >= 0)
                {
                                        document.getElementById(text_field_id).style.color = "#ff0000";
                }
                else
                {
                                        document.getElementById(text_field_id).style.color = "#616161";
                }
            }
        }
    }
    
    function unmark_negative_values() {
        for(i=0; i<document.forms[0].elements.length; i++)
        {
            if(document.forms[0].elements[i].type == "text")
            {
                var text_field_id = document.forms[0].elements[i].id;
                                document.getElementById(text_field_id).style.color = "#616161";
            }
        }
    }    
    
    function calc_gross(monthly_annual) {
  
      var C10 = document.getElementById('C10'); // $
      var D10 = document.getElementById('D10'); // $
      var number = 0;
      var result = 0;      
  
        if (monthly_annual == "C10")
        {
            number = round_number(parseInt(C10.value.replace(/,/g,""))*12,2); 
            result = CurrencyFormatted(number);
            D10.value = CommaFormatted(result);
  
            number = 0;
            result = 0;
  
            number =  round_number(parseInt(C10.value.replace(/,/g,"")),2); 
            result = CurrencyFormatted(number);
            C10.value = CommaFormatted(result);
        }
        else if (monthly_annual == "D10")
        { 
            number = round_number(parseInt(D10.value.replace(/,/g,""))/12,2);
            result = CurrencyFormatted(number);
            C10.value = CommaFormatted(result);
  
            number = 0;
            result = 0;
  
            number =  round_number(parseInt(D10.value.replace(/,/g,"")),2); 
            result = CurrencyFormatted(number);
            D10.value = CommaFormatted(result);
        } else {
            number = round_number(parseInt(C10.value.replace(/,/g,""))*12,2); 
            result = CurrencyFormatted(number);
            D10.value = CommaFormatted(result);
  
            number = 0;
            result = 0;
  
            number =  round_number(parseInt(C10.value.replace(/,/g,"")),2); 
            result = CurrencyFormatted(number);
            C10.value = CommaFormatted(result);
        }
    }
  
    function calc_vacancy() {
        var B12 = document.getElementById('B12'); // %
        var C12 = document.getElementById('C12'); // $
        var D12 = document.getElementById('D12'); // $
        var C10 = document.getElementById('C10'); // $
        var D10 = document.getElementById('D10'); // $
        var number = 0;
        var result = 0;     
  
        number = round_number(-1 * (parseInt(B12.value)/100) * parseInt(C10.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        C12.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number = round_number(-1 * (parseInt(B12.value)/100) * parseInt(D10.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        D12.value = CommaFormatted(result);
    }
  
    function calc_egi() {
        var C10 = document.getElementById('C10'); // $
        var C12 = document.getElementById('C12'); // $
        var C14 = document.getElementById('C14'); // $
        var D10 = document.getElementById('D10'); // $
        var D12 = document.getElementById('D12'); // $
        var D14 = document.getElementById('D14'); // $
        var number = 0;
        var result = 0;     
  
        number = round_number(parseInt(C10.value.replace(/,/g,"")) + parseInt(C12.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        C14.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number = round_number(parseInt(D10.value.replace(/,/g,"")) + parseInt(D12.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        D14.value = CommaFormatted(result);
    }
  
    function calc_egi_expenses() {
        var B16 = document.getElementById('B16'); // %
        var C16 = document.getElementById('C16'); // $
        var D16 = document.getElementById('D16'); // $
        var C14 = document.getElementById('C14'); // $
        var D14 = document.getElementById('D14'); // $
        var number = 0;
        var result = 0;     
  
        number = round_number(parseInt('-1') * (parseInt(B16.value)/100) * parseInt(C14.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        C16.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number = round_number(parseInt('-1') * (parseInt(B16.value)/100) * parseInt(D14.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        D16.value = CommaFormatted(result);
    }
  
    function calc_egi_reserves() {
        var B17 = document.getElementById('B17'); // %
        var C17 = document.getElementById('C17'); // $
        var D17 = document.getElementById('D17'); // $
        var C14 = document.getElementById('C14'); // $
        var D14 = document.getElementById('D14'); // $
        var number = 0;
        var result = 0;     
  
        number = round_number(parseInt('-1') * (parseInt(B17.value)/100) * parseInt(C14.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        C17.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number = round_number(parseInt('-1') * (parseInt(B17.value)/100) * parseInt(D14.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        D17.value = CommaFormatted(result);
    }
  
    function calc_noi() {
        var C14 = document.getElementById('C14'); // $
        var C16 = document.getElementById('C16'); // $
        var C17 = document.getElementById('C17'); // $
        var D14 = document.getElementById('D14'); // $
        var D16 = document.getElementById('D16'); // $
        var D17 = document.getElementById('D17'); // $
        var C19 = document.getElementById('C19'); // $
        var D19 = document.getElementById('D19'); // $
        var number = 0;
        var result = 0;    
  
        number =  round_number(parseInt(C14.value.replace(/,/g,"")) + parseInt(C16.value.replace(/,/g,"")) + parseInt(C17.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        C19.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number =  round_number(parseInt(D14.value.replace(/,/g,"")) + parseInt(D16.value.replace(/,/g,"")) + parseInt(D17.value.replace(/,/g,"")),2);
        result = CurrencyFormatted(number);
        D19.value = CommaFormatted(result);
    }
  
    function calc_property_value(either_or) {
        var B24 = document.getElementById('B24'); // $
        var D19 = document.getElementById('D19'); //$
        var B25 = document.getElementById('B25'); // %
        var number = 0;
        var result = 0;
        if (either_or=='B24') {
            number =  round_number((parseInt(D19.value.replace(/,/g,""))/parseInt(B24.value.replace(/,/g,"")))*100, 2);
            B25.value = number;
        } else {
            number =  round_number(parseInt(D19.value.replace(/,/g,"")) / (parseInt(B25.value)/parseInt('100')),2);
            result = CurrencyFormatted(number);
            B24.value = CommaFormatted(result);
        }
        //alert(parseInt(D19.value.replace(/,/g,"")));
        //alert(parseInt(B24.value.replace(/,/g,"")));
        //alert((parseInt(D19.value.replace(/,/g,""))/parseInt(B24.value.replace(/,/g,"")))*100);
    }
   
    function calc_loan_amount(loan_down) {
                // if loan_down is not B29 or B31
                // then proceed with default calculation
                // else if B29, set B31
                // else if B31, set B29
        var B29 = document.getElementById('B29'); // %	// Loan Amount %
        var B24 = document.getElementById('B24'); // $	// Property Value 
        var B30 = document.getElementById('B30'); // $	// Loan Amount $
        var B31 = document.getElementById('B31'); // %	// Down Payment %
        var number = 0;
        var result = 0;    
  
                switch (loan_down) {
                        case "B29": 
                                //alert("B29");
                                number =round_number(parseInt(B29.value)/parseInt('100') * parseInt(B24.value.replace(/,/g,"")),2);
                                result = CurrencyFormatted(number);
                                B30.value = CommaFormatted(result);
                                B31.value = !isNaN(round_number((parseInt('1') - parseInt(B29.value)/100)*100,2))?round_number((parseInt('1') - parseInt(B29.value)/100)*100,2):'';
                                break;
                        case "B31":
                                //alert("B31");
                                // TO DO!
                                number =round_number(parseInt( (parseInt('100') - B31.value) )/parseInt('100') * parseInt(B24.value.replace(/,/g,"")),2);
                                result = CurrencyFormatted(number);
                                B30.value = CommaFormatted(result);
                                B29.value = round_number((parseInt('1') - parseInt(B31.value)/100)*100,2);
                                break;
                        default: 
                                //alert("default");
                                number =round_number(parseInt(B29.value)/parseInt('100') * parseInt(B24.value.replace(/,/g,"")),2);
                                result = CurrencyFormatted(number);
                                B30.value = CommaFormatted(result);
                                B31.value = !isNaN(round_number((parseInt('1') - parseInt(B29.value)/100)*100,2))?round_number((parseInt('1') - parseInt(B29.value)/100)*100,2):'';				
                }
    }
  
    function pmt(i, n, p) {
            return i * p * Math.pow((1 + i), n) / ((Math.pow((1 + i), n) - 1));
    }
  
    function calc_payment() {
        //B32, B33, B29, B24, => B34
        var B32 = document.getElementById('B32'); // %
        var B33 = document.getElementById('B33'); // #
        var B29 = document.getElementById('B29'); // %
        var B24 = document.getElementById('B24'); // $
        var B34 = document.getElementById('B34'); // $
        var B35 = document.getElementById('B35'); // $
  
        // monthly_payment = (rate + (rate / ( ( 1 + rate) ^ months) -1)) * principal
        // rate == APR / 1200    => B32 / 12 / 100
        // months == years * 12  => B33 *12
        // loan amt == % * value => (B29/100) * B24
        var rate = parseInt(B32.value)/parseInt('1200');
        var months = parseInt(B33.value) * 12;
        var principal = (parseInt(B29.value) / parseInt('100')) * B24.value.replace(/,/g,"");
        // var monthly_payment = (rate + (rate / (Math.pow((parseInt('1') + rate),months) - parseInt('1')))) * principal;
        var monthly_payment = pmt(rate,months,principal);
  
        var number = 0;
        var result = 0;    
  
        number =round_number(monthly_payment,2);
        result = CurrencyFormatted(number);
        B34.value = CommaFormatted(result);
  
        number = 0;
        result = 0;
  
        number =round_number(parseInt(B34.value.replace(/,/g,"")) * parseInt('12'),2);
        result = CurrencyFormatted(number);
        B35.value = CommaFormatted(result);
    }
  
    function calc_dcr() {
        var D19 = document.getElementById('D19'); // $
        var B35 = document.getElementById('B35'); // $
        var B37 = document.getElementById('B37'); // #
        var B37IMG2 = document.getElementById('B37IMG2');
        var number = 0;
        number =round_number((parseInt('1') * parseInt(D19.value.replace(/,/g,""))) / parseInt(B35.value.replace(/,/g,"")),3);
        if (number < 1.2)
        {
            B37IMG2.style.visibility = "visible";
        }
        else
        {
            B37IMG2.style.visibility = "hidden";
        }
        B37.value = number;
    }
    //  End -->