
//  MENU ITEMS //
// DUPLICATE THIS ENTIRE SECTION FOR MULTIPLE MENUS.  PLEASE SEE THE INSTRUCTIONS FILE FOR DETAILS ///   
var Menu1 = new Array ()
var subMenu1 = new Array ()

Menu1[0] = new Array("About Us&nbsp;&nbsp;|", "about.htm","_top", "left")
subMenu1[0] = new Array()

Menu1[1] = new Array("Our Team&nbsp;&nbsp;|", "team.htm","_top", "left")
subMenu1[1] = new Array()
     
   	 Menu1[2] = new Array("Find a Home&nbsp;&nbsp;|", "#","_top", "left")
     subMenu1[2] = new Array()
	 subMenu1[2][0] = new Array ("Search Our Property Listings", "listings.php","_top")
	 subMenu1[2][1] = new Array ("Why Purchase With Us?", "whyPurchase.htm","_top")
	 subMenu1[2][2] = new Array ("Tips for Buying a Home", "buyingTips.htm","_top")

   Menu1[3] = new Array("Sell Your Home&nbsp;&nbsp;|", "#","_top", "left")
     subMenu1[3] = new Array()
	 subMenu1[3][0] = new Array ("List My Property", "listProperty.htm","_top")
	 subMenu1[3][1] = new Array ("Tips for Selling a Home", "sellingTips.htm","_top")

   Menu1[4] = new Array("Links & Information&nbsp;&nbsp;|", "links.htm","_top", "right")
     subMenu1[4] = new Array()

	Menu1[5] = new Array("Privacy Policy", "privacy.htm","_top", "left")
     subMenu1[5] = new Array()



/// FORMAT MENU  ///
menuStyle = "flat"                                  // Menu Style (flat, 3d)
cellPadding = "2"                                   // Cell Padding
cellBorder = 1                                      // Border width (for no border, enter 0)  THIS VALUE APPLIES TO ALL MENUS
verticalOffset = "8"                                // Vertical offset of Sub Menu. 
horizontalOffset = "-1"                              // Horizontal offset of Sub Menu. 
subMenuDelay = 1                                    // Time sub menu stays visible for (in seconds). THIS VALUE APPLIES TO ALL MENUS
subIndicate = 1                                     // Show if a sub menu is present (use 0 for "no")  THIS VALUE APPLIES TO ALL MENUS
indicator = "" // Symbol to show if a sub menu is present (subIndicate must be to set to 1)
                                                    // Use standard HTML <img> tag. You can use a character instead of an image. 
                                                    // e.g.      indicator = ">"
// Main Menu Items
menuWidth = "0"                  // Width of menu item.  Use 0 for default
borderColor = "#356ea4"            // Border Colour (flat mode only)
borderHighlight = "#97BBD3"      // Border Highlight Colour (3d mode only)
borderShadow = "#31556D"         // Border Shadow Colour (3d mode only)
menuBackground = "#356ea4"       // Cell Background Colour
menuHoverBackground = "356ea4"    // Cell Background Colour on mouse rollover
fontFace = "verdana"               // Font Face
fontColour = "#ffffff"           // Font Colour
fontHoverColour = "#0E3793"      // Font Colour on mouse rollover
fontSize = "10 px"                 // Font Size
fontDecoration = "none"          // Style of the link text (none, underline, overline, line-through)
fontWeight = "normal"            // Font Weight (normal, bold)

// Sub Menu Items
smenuWidth = "150"                 // Width of sub menu item.  Use 0 for default
sborderColor = "#ffffff"           // Border Colour (flat mode only)
sborderHighlight = "#E9E9E2"     // Border Highlight Colour (3d mode only)
sborderShadow = "#83837C"        // Border Shadow Colour (3d mode only)
smenuBackground = "356ea4"        // Cell Background Colour
smenuHoverBackground = "#BECDD7" // Cell Background Colour on mouse rolloverr
sfontFace = "verdana"              // Font Face
sfontColour = "#ffffff"          // Font Colour
sfontHoverColour = "#0E3793"     // Font Colour on mouse rollover
sfontSize = "10 px"                // Font Size
sfontDecoration = "none"         // Style of the link text (none, underline, overline, line-through)
sfontWeight = "normal"           // Font Weight (normal, bold)

quantity = 1
/// END FORMAT MENU  ////

/// DO NOT EDIT BELOW THIS LINE  ///
// Browser Sniffer
var isIE = (document.getElementById && document.all)?true:false;
var isNS4 = (document.layers)?true:false;
var isNS6 = (document.getElementById && !document.all)?true:false;
var timer;
var obj = (isIE)?"document.all":"document.getElementById"
// Menu Styles
function createStyles(quant){
styleBorder=(menuStyle.split(",")[quant-1].toLowerCase() == "flat")?cellBorder:0 
  document.writeln ('<style>');
  document.writeln ('.rcMenuStatic'+quant+' {font-family:'+fontFace.split(",")[quant-1]+';font-size:'+fontSize.split(",")[quant-1]+';color:'+fontColour.split(",")[quant-1]+';font-weight:'+fontWeight.split(",")[quant-1]+';background-color:'+menuBackground.split(",")[quant-1]+'; cursor:hand; text-decoration:'+fontDecoration.split(",")[quant-1]+'}');
  document.writeln ('.rcMenuHover'+quant+'  {font-family:'+fontFace.split(",")[quant-1]+';font-size:'+fontSize.split(",")[quant-1]+';color:'+fontHoverColour.split(",")[quant-1]+';font-weight:'+fontWeight.split(",")[quant-1]+';background-color:'+menuHoverBackground.split(",")[quant-1]+'; cursor:hand; text-decoration:'+fontDecoration.split(",")[quant-1]+'}');
  document.writeln ('.rcSubMenuStatic'+quant+' {font-family:'+sfontFace.split(",")[quant-1]+';font-size:'+sfontSize.split(",")[quant-1]+';color:'+sfontColour.split(",")[quant-1]+';font-weight:'+sfontWeight.split(",")[quant-1]+';text-decoration:'+sfontDecoration.split(",")[quant-1]+';background-color:'+smenuBackground.split(",")[quant-1]+'; cursor:hand}');
  document.writeln ('.rcSubMenuHover'+quant+'  {font-family:'+sfontFace.split(",")[quant-1]+';font-size:'+sfontSize.split(",")[quant-1]+';color:'+sfontHoverColour.split(",")[quant-1]+';font-weight:'+sfontWeight.split(",")[quant-1]+';text-decoration:'+sfontDecoration.split(",")[quant-1]+';background-color:'+smenuHoverBackground.split(",")[quant-1]+'; cursor:hand}');
  document.writeln ('</style>');
}
// Build and show the main menu items
function showMenus(quant,definedOrientation)
{
  createStyles(quant);
  if(definedOrientation!=""){orientation=definedOrientation}
  if (orientation.toLowerCase() == "vertical"){document.writeln ('<table border="0" cellpadding="0" cellspacing="'+styleBorder+'" bgColor="'+borderColor.split(",")[quant-1]+'">')}
  else{document.writeln ('<table border="0" cellpadding="0" cellspacing="'+styleBorder+'" bgColor="'+borderColor.split(",")[quant-1]+'"><tr>')}  
  for (x=0; x<eval("Menu"+quant).length; x++)
  {
    if (orientation.toLowerCase()=="vertical") document.writeln('<tr>')
    document.writeln ('<td width="'+menuWidth+'" onclick="tdMouseClick(\''+quant+'mainLink'+x+'\')" onMouseOver="hoverMenu(); popDown(\''+quant+'\','+x+', \''+quant+'button'+x+'\',\''+orientation+'\'); " onMouseOut="clearMenu('+quant+','+x+')" ')
    if (menuStyle.split(",")[quant-1].toLowerCase() == "3d"){document.writeln ('style="border-left:'+cellBorder+'px solid '+borderHighlight.split(",")[quant-1]+';border-top:'+cellBorder+'px solid '+borderHighlight.split(",")[quant-1]+';border-right:'+cellBorder+'px solid '+borderShadow.split(",")[quant-1]+';border-bottom:'+cellBorder+'px solid '+borderShadow.split(",")[quant-1]+';"');}        
    document.writeln ('><div id="'+quant+'button'+x+'"><table border="0" cellpadding="'+cellPadding.split(",")[quant-1]+'" cellspacing="0" width="100%"><tr><td class="rcMenuStatic'+quant+'" id="'+quant+'cell'+x+'" nowrap>');
    document.writeln ('<a id="'+quant+'mainLink'+x+'" href="'+eval("Menu"+quant)[x][1]+'" target="'+eval("Menu"+quant)[x][2]+'" class="rcMenuStatic'+quant+'">'+eval("Menu"+quant)[x][0]+'</a></td>');
    if (subIndicate == 1&&eval("subMenu"+quant)[x].length>=1){
      document.writeln('<td class="rcMenuStatic'+quant+'" id="'+quant+'cell'+x+'a" align="right">');
      document.writeln ('<a id="'+quant+'mainLink'+x+'a" href="'+eval("Menu"+quant)[x][1]+'" target="'+eval("Menu"+quant)[x][2]+'" class="rcMenuStatic'+quant+'">'+indicator+'</a></td>');}
    document.writeln ('</tr></table></div></td>');    
    if (orientation.toLowerCase()=="vertical") document.writeln('</tr>')
  }
  if (orientation.toLowerCase() == "vertical"){document.writeln ('</table>');}
  else{document.writeln ('</tr></table>');}   
// Build the sub menu items
  for (x=0; x<eval("Menu"+quant).length; x++)
  { 
    if (eval("subMenu"+quant)[x].length > 0)
    {     
      document.writeln ('<div id="'+quant+'MENU'+x+'" style="visibility:hidden; position:absolute; z-index:2" >');
      document.writeln ('<table width="'+smenuWidth.split(",")[quant-1]+'" border="0" cellpadding="'+cellPadding.split(",")[quant-1]+'" cellspacing="'+styleBorder+'" bgColor="'+sborderColor.split(",")[quant-1]+'">');
      for (y=0; y<eval("subMenu"+quant)[x].length; y++)
      {
        document.writeln ('<tr>');
        if (eval("subMenu"+quant)[x][y][1].indexOf("#") != -1)
        {
          document.writeln ('<td bgColor="'+eval("subMenu"+quant)[x][y][2]+'" id="'+quant+'subMenu'+x+y+'" onMouseOver="hoverMenu(); highlightMenu(\'sub\','+x+','+y+',\'\','+quant+')" nowrap')
          if (menuStyle.split(",")[quant-1].toLowerCase() == "3d"){document.writeln ('style="border-left:'+cellBorder+'px solid '+sborderHighlight.split(",")[quant-1]+';border-top:'+cellBorder+'px solid '+sborderHighlight.split(",")[quant-1]+';border-right:'+cellBorder+'px solid '+sborderShadow.split(",")[quant-1]+';border-bottom:'+cellBorder+'px solid '+sborderShadow.split(",")[quant-1]+';"');}
          document.writeln ('><p style="font-family:'+sfontFace.split(",")[quant-1]+'; font-size:'+sfontSize.split(",")[quant-1]+'; color:'+eval("subMenu"+quant)[x][y][1]+'"id="'+quant+'subLink'+x+y+'">'+eval("subMenu"+quant)[x][y][0]+'</p></td></tr>');
        }
        else
        {
          document.writeln ('<td id="'+quant+'subMenu'+x+y+'" class="rcSubMenuStatic'+quant+'" onMouseOver="hoverMenu(); highlightMenu(\'sub\','+x+','+y+',\'\','+quant+')" onMouseOut="clearMenu('+quant+','+x+');" onclick="tdMouseClick(\''+quant+'subLink'+x+y+'\')" nowrap')
          if (menuStyle.split(",")[quant-1].toLowerCase() == "3d"){document.writeln ('style="border-left:'+cellBorder+'px solid '+sborderHighlight.split(",")[quant-1]+';border-top:'+cellBorder+'px solid '+sborderHighlight.split(",")[quant-1]+';border-right:'+cellBorder+'px solid '+sborderShadow.split(",")[quant-1]+';border-bottom:'+cellBorder+'px solid '+sborderShadow.split(",")[quant-1]+';"');}
          document.writeln ('><a id="'+quant+'subLink'+x+y+'" href="'+eval("subMenu"+quant)[x][y][1]+'" target="'+eval("subMenu"+quant)[x][y][2]+'" class="rcSubMenuStatic'+quant+'">'+eval("subMenu"+quant)[x][y][0]+'</a></td></tr>');
        }
      }
      document.writeln ('</table></div>');
    }
  }
} 
// Change colour or menu and submenu items when the mouse hovers over.  
function highlightMenu(element,mainMenu,dropMenu,state,quant)
{
  hoverMenu();
  state=(state == "hover")?"rcMenuHover"+quant:"rcMenuStatic"+quant
  if (element == "sub")
  {
    for (x=0; x < eval("subMenu"+quant)[mainMenu].length; x++)
    {
      if (eval("subMenu"+quant)[mainMenu][x][1].indexOf("#") == -1){
        eval(obj+'("'+quant+'subMenu'+mainMenu+x+'").className = "rcSubMenuStatic'+quant+'"')
        eval(obj+'("'+quant+'subLink'+mainMenu+x+'").className = "rcSubMenuStatic'+quant+'"')
      }
    } 
    if (eval("subMenu"+quant)[mainMenu][dropMenu][1].indexOf("#") == -1)  {
      eval(obj+'("'+quant+'subMenu'+mainMenu+dropMenu+'").className="rcSubMenuHover'+quant+'"')
      eval(obj+'("'+quant+'subLink'+mainMenu+dropMenu+'").className="rcSubMenuHover'+quant+'"')
    }
  }
  else
  {
    eval(obj+'("'+quant+'cell'+mainMenu+'").className = "'+state+'"')
    eval(obj+'("'+quant+'mainLink'+mainMenu+'").className = "'+state+'"')
    if (subIndicate == 1&&eval("subMenu"+quant)[mainMenu].length>=1)
    {
      eval(obj+'("'+quant+'cell'+mainMenu+'a").className = "'+state+'"')
      eval(obj+'("'+quant+'mainLink'+mainMenu+'a").className = "'+state+'"')
    }
  }
}
// Find positioning for sub menus
function getOffset(obj, dim) 
{
  if(dim=="left") 
  {     
    oLeft = obj.offsetLeft;    
    while(obj.offsetParent!=null) 
    {    
      oParent = obj.offsetParent     
      oLeft += oParent.offsetLeft 
      obj = oParent 	
    }
    return oLeft
  }
  else if(dim=="top")
  {
    oTop = obj.offsetTop;
    while(obj.offsetParent!=null) 
    {
      oParent = obj.offsetParent
      oTop += oParent.offsetTop
      obj = oParent 	
    }
    return oTop
  }
  else if(dim=="width")
  {
    oWidth = obj.offsetWidth
    return oWidth
  }  
  else if(dim=="height")
  {
    oHeight = obj.offsetHeight
    return oHeight
  }    
  else
  {
    alert("Error: invalid offset dimension '" + dim + "' in getOffset()")
    return false;
  }
}
// Show sub menus
function popDown(quant, param, id, orientation)
{
  var cellBorderOffset = (isNS6)?cellBorder:eval(cellBorder*2)
  var browserAdjustment = (isNS6)?cellBorder:0
  var menu;
  var button;

  if (id)
  {    
    getOffset(eval(obj+'(id)'),'left');
    getOffset(eval(obj+'(id)'),'top');    
    getOffset(eval(obj+'(id)'),'width');  
    getOffset(eval(obj+'(id)'),'height');
    
    if (eval("Menu"+quant+"["+param+"][3]")=="right" && eval("subMenu"+quant+"["+param+"].length")>0) 
    { 
      oLeft=oLeft  
      oLeft=oLeft+oWidth; 
      getOffset(eval(obj+'("'+quant+'MENU'+param+'")'),'width');
      oLeft=oLeft-oWidth ;
      alignAdjustment = cellBorder*2 + 1
    }
    else 
    {
      alignAdjustment = 0
      oLeft=oLeft
    }    
  }  

  
  n = 0;    
  while (n < eval("Menu"+quant).length)
  {          
    menu = quant+"MENU"+n
    if (param == n)
    {

      theObj = eval(obj+'(menu)');
      if (theObj)
      {
         theObj.style.visibility = "visible"
          if (orientation.toLowerCase()=="vertical"){
            theObj.style.left=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oLeft+oWidth+cellBorder+parseInt(horizontalOffset.split(",")[quant-1]):oLeft+oWidth+cellBorderOffset+parseInt(horizontalOffset.split(",")[quant-1]);
            theObj.style.top=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oTop-cellBorder+parseInt(verticalOffset.split(",")[quant-1]):oTop+parseInt(verticalOffset.split(",")[quant-1])-browserAdjustment}
          else{
            theObj.style.left=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oLeft-cellBorder+parseInt(horizontalOffset.split(",")[quant-1])+alignAdjustment:oLeft+parseInt(horizontalOffset.split(",")[quant-1])-browserAdjustment+alignAdjustment;
            theObj.style.top=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oTop+oHeight+cellBorder+parseInt(verticalOffset.split(",")[quant-1]):oTop+oHeight+cellBorderOffset+parseInt(verticalOffset.split(",")[quant-1]);}
        }
      
       highlightMenu('main',n,'','hover',quant)
       if (eval("subMenu"+quant)[param].length > 0)
       {
         for (x=0; x<eval("subMenu"+quant)[param].length; x++)
         {
           if(eval("subMenu"+quant)[param][x][1].indexOf("#") == -1){
             eval (obj+'("'+quant+'subMenu'+param+x+'").className = "rcSubMenuStatic'+quant+'"')
             eval (obj+'("'+quant+'subLink'+param+x+'").className = "rcSubMenuStatic'+quant+'"')  
           }       
         }
       }
    }
    else 
    {  
      for (x=1; x<quantity+1; x++)
      {       
        menu = x+"MENU"+n   
        //alert(menu)     
        if (eval(obj+'(menu)'))
        {
          eval(obj+'(menu).style.visibility = "hidden"')            
        }
        highlightMenu ('main',n,'','static',quant)
      }
    }

    n++
  }  
}
// Re-set timer for sub menus
function hoverMenu()
{
  if(timer)
  clearTimeout(timer)
}
// Set timer for sub menus
function clearMenu(quant,menu)
{
  setDelay = subMenuDelay*1000
  delay = (eval("subMenu"+quant)[menu].length > 0)?setDelay:1
  
  timer = setTimeout("popDown("+quant+","+(eval("Menu"+quant).length + 1)+")",delay)
}
// when you click the box, perform the same function as if the user had clicked the hyperlink
function tdMouseClick(theElement)
{
  eval(obj+'(theElement).click()')
}
//-->

function floor(number)
	{
	  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
	}
	
	function dosum()
	{
	  var mi = document.temps.ir.value / 1200;
	  var base = 1;
	  var mbase = 1 + mi;
	  for (i=0; i<document.temps.yr.value * 12; i++)
	  {
	    base = base * mbase
	  }
	  document.temps.pi.value = floor(document.temps.la.value * mi / ( 1 - (1/base)))
	  document.temps.mt.value = floor(document.temps.at.value / 12)
	  document.temps.mi.value = floor(document.temps.ai.value / 12)
	  var dasum = document.temps.la.value * mi / ( 1 - (1/base)) +
		document.temps.at.value / 12 + 
		document.temps.ai.value / 12;
	  document.temps.mp.value = floor(dasum);
	}
	
	var bDebug = 0 ;        // change to 1 for extra output
var bZeroOk = 0 ;       // zero tax/insurance is ok
var bSuppressChecking = 0 ;     // suppress some error checking
var sNl = "\r";
var sOut = "", sDump = "" ;         // html output string
var nErrorNumber = -1.2345e-12 ;

var sSub = "%s" ;

var shStart = "<html>" + sNl
      + "<head><title>%s</title>" + sNl
      + "<style type='text/css'>" + sNl
      + "<!--" + sNl
      + "/* make all text the same font */" + sNl
      + "TD {FONT-FAMILY: Arial, Helvetica, sans-serif} " + sNl
      + "TH {FONT-FAMILY: Arial, Helvetica, sans-serif} " + sNl
      + "-->" + sNl
      + "</style>" + sNl
      + "</head>" + sNl
      + "<body>" + sNl
      + "<BASEFONT FACE='Arial, Helvetica, sans-serif'>" ;


var shHeading1 = "<TABLE border=0 cellpadding=0 cellspacing=0 "
         + "width=525>" + sNl
         + "<TR><TD><font size=+2><B>%s</B><BR><BR></TD></TR></TABLE>" ;

var shHeadGif = "<TABLE width=500 cellpadding=0 cellspacing=0>" + sNl
      + "<TR><TD><img src='%s' " + sNl
      + "width=471 height=24></TD></TR></TABLE>" ;

var shHeading2 =  "<TABLE border=0 cellpadding=0 "
                + "cellspacing=0 width=500>" + sNl
      + "<TR><TD>"
      + "<font size=+2><b>%s</b></font></TD></TR></TABLE>" ;

var shBeginTable1 =
      "<TABLE border=1 cellpadding=3 cellspacing=0 width=500>" ;
var shBeginTable2 =
      "<TABLE border=0 cellpadding=0 cellspacing=0 width=500><BR>" ;

var shEndTable = "</table>" ;

var shBeginRow1 = "<tr>" ;
var shBeginRow2 = "<tr align=center>" ;
var shEndRow = "</tr>" ;

var shCell1 = "<TD align=right><font size=-1><B>%s</B></font></TD>" ;
var shCell2 = "<TD><font size=-1><B>%s</B></font></TD>" ;
var shCell3 = "<TD align=right><font size=-1>%s</font></TD>" ;

function EmitRow1(s1)
{
   Emit(shBeginRow1) ;
   Emit1(shCell1, "&nbsp;") ;
   Emit1(shCell1, s1) ;
// Emit1(shCell1, s2) ;
   Emit(shEndRow) ;
}

function EmitRow2D(s1, s2)
{
   Emit(shBeginRow1) ;
   Emit1(shCell2, s1) ;
   Emit1(shCell3, DollarFormat(s2, 0, 2)) ;
// Emit1(shCell3, DollarFormat(s3, 0, 2)) ;
   Emit(shEndRow) ;
}

function EmitRow2P(s1, s2)
{
   Emit(shBeginRow1) ;
   Emit1(shCell2, s1) ;
   Emit1(shCell3, s2 + " %") ;
// Emit1(shCell3, s3 + " %") ;
   Emit(shEndRow) ;
}

var shLongText = ""


   + "<TR><TD><font size=-1>The <B>maximum home price" + sNl
   + "</B> is the amount that you can afford based on" + sNl
   + "the following housing expense, long term debt, and cash-available" + sNl 
   + "guidelines that are used by lenders to determine the mortgage amount" + sNl
   + "they will lend to a home buyer:  <ul><li>Housing expenses" + sNl
   + "(monthly mortgage principal and interest, plus monthly property tax" + sNl
   + "and home insurance costs (also known as \"PITI\"), plus the monthly PMI" + sNl
   + "payment (if applicable)) should not exceed 28 percent of the homeowner's" + sNl
   + "gross monthly income.<br><br><li>Housing expenses (monthly mortgage principal" + sNl
   + "and interest, plus monthly property tax and home insurance costs (also" + sNl
   + "known as \"PITI\"), plus the monthly PMI payment (if applicable)) PLUS all" + sNl
   + "other monthly debt payments should not exceed 36 percent of the homeowner's" + sNl
   + "gross monthly income.<br><br><li>An estimate" + sNl
   + "of your maximum loan amount can be determined by dividing" + sNl 
   + "your available cash by the minimum total percentage of the" + sNl 
   + "home price that will need to go toward the down payment" + sNl 
   + "and all closing costs.</ul></font></TD></TR>" + sNl + sNl

   + "<TR><TD><font size=-1><br>A <B>monthly PMI payment</B>" + sNl
   + "appears above if your down payment is less than 20% of" + sNl
   + "your home value. That means you must pay an extra .7%" + sNl
   + "of your beginning loan balance per year for private" + sNl
   + "mortgage insurance (\"PMI\").  In many cases, the lender" + sNl
   + "will allow cancellation of PMI when the loan is paid" + sNl
   + "down to 80% of the original property" + sNl
   + "value.</font></TD></TR>" + sNl + sNl

   + "<TR><TD><font size=-1><BR>Note: For this calculation," + sNl
   + "we assume a minimum down payment of 5% and use estimated closing costs" + sNl
   + "of 2% of the loan amount.</font></TD></TR>" + sNl + sNl ;
 

function Initialize(oForm)
{
    if (0 && bDebug)
    {
        oForm.appm0001.value = 65714 ;
        oForm.appm0002.value = 1000 ;
        oForm.appm0003.value = 20000 ;
        oForm.appm0004.value = 2 ;
        oForm.appm0005.value = 1.5 ;
        oForm.appm0006.value = 8.5 ;
//      oForm.appm0007.value =  ;
//      oForm.appm0008.value =  ;
    }
}

function Execute(oForm)
{
   var iError = 0 ;

   var nAnnualIncome, nMonthlyDebt, nCash, nDownPc ;
   var nPropertyTaxPc, nInsurancePc, nInputInterest, iYears ;

   if ( (nAnnualIncome = Validate(oForm.appm0001.value, 0)) == nErrorNumber)
      iError = 100 ;

   else if ( (nMonthlyDebt = Validate(oForm.appm0002.value, 0)) == nErrorNumber)
      iError = 110 ;

   else if ( (nCash = Validate(oForm.appm0003.value, 0)) == nErrorNumber)
      iError = 120 ;

// else if ( (nDownPc = Validate(oForm.appm0004.value, 0)) == nErrorNumber)
//    iError = 130 ;

   else if ( (nPropertyTaxPc = Validate(oForm.appm0004.value, 0)) == nErrorNumber)
      iError = 140 ;

   else if ( (nInsurancePc = Validate(oForm.appm0005.value, 0)) == nErrorNumber)
      iError = 150 ;

   else if ( (nInputInterest = Validate(oForm.appm0006.value, 0)) == nErrorNumber)
      iError = 160 ;

   else if ( (iYears = Validate(oForm.appm0007.value, 1)) == nErrorNumber)
      iError = 170 ;

   if (!iError)
   {
      var sMessage = "" ;
      if (nAnnualIncome == 0)
         sMessage = "Please enter Gross Annual Income" ;
      else if (nAnnualIncome < 0)
         sMessage = "Gross Annual Income must be positive" ;
//    else if (nMonthlyDebt == 0)
//       sMessage = "Please enter Monthly Debt Payments" ;
      else if (nMonthlyDebt < 0)
         sMessage = "Monthly Debt Payments must be zero or positive" ;
      else if (nCash == 0)
         sMessage = "Please enter Cash Available" ;
      else if (nCash < 0)
         sMessage = "Cash Available must be positive" ;
//    else if (nDownPc == 0)
//       sMessage = "Please enter Desired Down Payment Percentage" ;
//    else if (nDownPc < 3)
//       sMessage = "Desired Down Payment Percentage must be at least 3%" ;
      else if (!bZeroOk && nPropertyTaxPc == 0)
         sMessage = "Please enter Property Tax Rate" ;
      else if (nPropertyTaxPc < 0)
         sMessage = "Property Tax Rate must be positive" ;
      else if (!bZeroOk && nInsurancePc == 0)
         sMessage = "Please enter Home Insurance Rate" ;
      else if (nInsurancePc < 0)
         sMessage = "Home Insurance Rate must be positive" ;
      else if (nInputInterest == 0)
         sMessage = "Please enter Interest Rate" ;
      else if (nInputInterest < 0)
         sMessage = "Interest Rate must be positive" ;
      else if (iYears == 0)
         sMessage = "Please enter Length of Loan (in years)" ;
      else if (iYears < 0)
         sMessage = "Length of Loan (in years) must be positive" ;

      if (sMessage != "")
      {
         iError = 190 ;
         alert(sMessage) ;
      }
   }

   if (!iError)
   {
      var iK, nLoanMp, nPmiMp, nFactor ;
      var bC36, bReject ;
      var nClosePc = .02, nMaxLoanPc = .97 ;
      var nNumer, nDenom ;
      var nPayment, nLenderPayment, nDebtPayment, nPmiPayment ;
      var iMonths = 12 * iYears ;
      var nPaymentMp = 1 / PresentValue(1, nInputInterest/1200,
                                iMonths) ;
      var bV28 = false, bV36 = false ;

      var nQPrice = nErrorNumber, nQLoan = 0, nQDown = 0, nQDownPc = 0 ;
      var nQClose = 0, nQPayment = 0, nQTin = 0, nQPmi = 0 ;

      for (iK = 0 ; iK < 4 ; ++iK)
      {
         nPmiMp = (iK % 2) ? 0 : .7/1200 ;
         bC36 = (iK < 2) ;
         nFactor = (bC36 ? 36 : 28) / 1200 ;
         nNumer = nAnnualIncome * nFactor
                         - (bC36 ? nMonthlyDebt : 0)
                                + (nPaymentMp + nPmiMp) * nCash ;
         nDenom = (nPaymentMp + nPmiMp) * (1 + nClosePc)
                        + (nPropertyTaxPc + nInsurancePc) / 1200 ;
         nQMax = (nDenom == 0) ? nCash / (1 + nClosePc)
                                        : nNumer / nDenom ;
         nLoanPc = 1 + nClosePc - nCash / nQMax ;
         if (!bSuppressChecking && nLoanPc < 0)
         {
            nNumer = nAnnualIncome * nFactor
                         - (bC36 ? nMonthlyDebt : 0) ;
            nDenom = (nPropertyTaxPc + nInsurancePc) / 1200 ;
            nQMax = (nDenom == 0) ? nCash / (1 + nClosePc)
                                        : nNumer / nDenom ;
            nLoanPc = 0 ;
         }
         if (!bSuppressChecking && nLoanPc > nMaxLoanPc && nPmiMp > 0)
         {
            nQMax = nCash / (1 - nMaxLoanPc + nClosePc) ;
            nLoanPc = nMaxLoanPc ;
         }
         bReject = (nLoanPc >= .80) != (nPmiMp > 0)
                        || (!bSuppressChecking && nLoanPc > nMaxLoanPc) ;

         if (!bReject && ((nQPrice == nErrorNumber) || nQMax < nQPrice))
         {
            nQPrice = Round(nQMax, 2) ;
            nQLoan = Round(nQPrice * nLoanPc, 2) ;
            nQDown = nQPrice - nQLoan ;
            nQDownPc = Round(nQDown / nQPrice * 100, 2) ;
            nQClose = Round(nQPrice * nClosePc, 2) ;
            nQPayment = nQLoan / PresentValue(1,
                                nInputInterest/1200, iMonths) ;
            nQTin = (nPropertyTaxPc + nInsurancePc) / 1200
                                        * nQPrice ;
            nQPmi = Round(nQLoan * nPmiMp, 2) ;
         }
         if (!bReject)
            if (bC36) bV36 = true ; else bV28 = true ;
                                
         nPrincipal = nQMax * nLoanPc ;
         nPayment = nPrincipal / PresentValue(1,
                                nInputInterest/1200, iMonths) ;
         nLenderPayment = nPayment + nQMax * (nPropertyTaxPc
                                + nInsurancePc) / 1200 ;
         nDebtPayment = nLenderPayment + nMonthlyDebt ;

         nPmiPayment = nPmiMp * nPrincipal ;

         nForwardIncome = (nLenderPayment + nPmiPayment
                        + (bC36 ? nMonthlyDebt : 0)) / nFactor ;

         bCheckError = Math.abs((nAnnualIncome - nForwardIncome)
                                / nAnnualIncome) > .01 ;

         if (bDebug)
         {
            Dump(iK + (bC36 ? ": Q36" : ": Q28")) ;
            Dump("nAnnualIncome = " + nAnnualIncome) ;
            Dump("nPmiMp = " + nPmiMp) ;
            Dump("nPaymentMp = " + nPaymentMp) ;
            Dump("nInputInterest = " + nInputInterest) ;
            Dump("nCash = " + nCash) ;
            Dump("nPropertyTaxPc = " + nPropertyTaxPc) ;
            Dump("nInsurancePc = " + nInsurancePc) ;
            Dump("nNumer = " + nNumer) ;
            Dump("nDenom = " + nDenom) ;
            Dump("nQMax = " + nQMax + " **************** "
                        + (bReject ? "Rejected" : "Accepted")) ;
            Dump("nLoanPc = " + nLoanPc) ;
            Dump("nClosePc = " + nClosePc) ;
            Dump("nPrincipal = " + nPrincipal) ;
            Dump("nPayment = " + nPayment) ;
            Dump("nMonthlyDebt = " + nMonthlyDebt) ;
            Dump("nLenderPayment = " + nLenderPayment) ;
            Dump("nDebtPayment = " + nDebtPayment) ;
            Dump("nPmiPayment = " + nPmiPayment) ;
            Dump("nForwardIncome = " + nForwardIncome) ;
            Dump("nAnnualIncome = " + nAnnualIncome) ;
            Dump(bReject ? "Value rejected" : "Value accepted") ;
            if (bCheckError)
               Dump("***************** Income Check Error "
                        + "*****************") ;
            Dump("=======================================") ;
         }
      }

      if (nQPrice == nErrorNumber || nQPrice < 0 || !bV28 || !bV36)
      {
         alert("No affordable house was found; please "
                        + "check your figures.") ;
         if (!bSuppressChecking)
            iError = 300 ;
      }
   }

   if (!iError)
   {
      Emit1(shStart, "How Much House Can You Afford Results") ;

      Emit1(shHeading1, "Here is an Estimate of What "
                                + "You Can Afford:") ;
      Emit(shBeginTable1) ;

      EmitRow2D("Maximum Home Price", nQPrice) ;
      EmitRow2D("Maximum Loan Amount", nQLoan) ;
      EmitRow2P("Interest Rate", nInputInterest) ;
      EmitRow2D("Down Payment Amount", nQDown) ;
      EmitRow2P("Down Payment (%)", nQDownPc) ;
      EmitRow2D("Estimated Closing Costs", nQClose) ;
      EmitRow2D("Monthly Principal and Interest", nQPayment) ;
      EmitRow2D("Monthly Taxes and Insurance", nQTin) ;
      EmitRow2D("Monthly PMI Payment", nQPmi) ;
      EmitRow2D("Other Monthly Debt", nMonthlyDebt) ;
      Emit(shEndTable) ;

      Emit(shBeginTable2) ;
      Emit(shLongText) ;
      Emit(shEndTable) ;

   }

   if (!iError)
   {
      if (bDebug && sDump != "")
         sOut += sNl + "<pre>" + sDump + "</pre>" ;
//    document.open() ;
      document.write(sOut) ;
      document.close() ;

   }

}

function Dump(sStr) { if (bDebug) sDump += sStr + sNl ;}

function Emit(sStr) { sOut += sStr + sNl ; }

function Emit1(sStr, s1)
{
   var iK ;
   if ( (iK = sStr.indexOf(sSub)) >= 0)
      sStr = sStr.substring(0, iK) + s1
                + sStr.substring(iK + sSub.length) ;
   Emit(sStr) ;
}

function Emitx(sStr, sSubs)
{
   var iK, iL, iPos1 = 0, iPos2 = 0 ;
   while ( (iK = sStr.indexOf(iPos1, sSub)) >= 0)
   {
      if ( (iL = eSubs.indexOf(iPos2, sSep)) < 0)
         iL = eSubs.length() ;
      sStr = sStr.substring(0, iK)
                        + sSubs.substring(iPos1, iL)
                        + sStr.substring(iK + sSub.length()) ;
      iPos1 = iK + sSub.length() ;
      if ( (iPos2 = iL + eSep.length()) > sSubs.length())
         iPos2 = sSubs.length() ;
   }
   Emit(sStr) ;
}


var sBlanks = "                                             "
                + "                                          " ;
var sDashes = "---------------------------------------------"
                + "-----------------------------------------" ;

var nPowers = [
        0.0000000000000001,
        0.000000000000001,
        0.00000000000001,
        0.0000000000001,
        0.000000000001,
        0.00000000001,
        0.0000000001,
        0.000000001,
        0.00000001,
        0.0000001,
        0.000001,
        0.00001,
        0.0001,
        0.001,
        0.01,
        0.1,
        1.,
        10.,
        100.,
        1000.,
        10000.,
        100000.,
        1000000.,
        10000000.,
        100000000.,
        1000000000.,
        10000000000.] ;

function Power(n)
{
    return nPowers[n+16] ;
}

var sMonths = ["January", "February", "March", "April", "May",
        "June", "July", "August", "September", "October",
        "November", "December"] ;

function Mmm(iK) { if (!(iK >= 1 && iK <= 12)) return "MMM" + iK ;
            return sMonths[iK-1].substring(0, 3) ; }

function ExpN(nX, iN)   // compute x ** n, where n is integral
{
   var nResult = 1 ;
   var bSign = 0 ;
   if (iN < 0)
   {
      bSign = 1 ;
      iN = -iN ;
   }
   while (iN > 0)
   {
      if (iN & 1)
         nResult *= nX ;
      nX *= nX ;
      iN >>= 1 ;
   }
   if (bSign)
      nResult = 1 / nResult ;
   return nResult ;
}

function PresentValue(nPayment, nPercent, iNumPeriods)
{
   var nAmount = (Math.abs(nPercent) > 1e-20)
         ? nPayment * (1 - ExpN(1 + nPercent, -iNumPeriods))
                                        / nPercent 
         : nPayment * iNumPeriods ;
   return nAmount ;
}

function SparsePresentValue(nPayment, nPercent, iInterval, iNumPeriods)
{
   var nAmount = (Math.abs(nPercent) > 1e-20)
         ? nPayment * (1 - ExpN(1 + nPercent, -iNumPeriods))
                        / (ExpN(1 + nPercent, iInterval) - 1)
         : nPayment * iNumPeriods ;
   return nAmount ;
}

function Round(nVal, iD)
{
   var iSign = 1 ;
   if (nVal < 0)
   {
      nVal = - nVal ;
      iSign = -1 ;
   }
   var iInt = Math.round(nVal) ;
   if (iD > 0)
      iInt = Math.floor(nVal) ;
   var nFp = nVal - iInt ;
// alert ('iInt, nFp = ' + iInt + ", " + nFp) ;
   if (iD > 0)
      nFp = Math.round(nFp * Power(iD)) / Power(iD) ;
   nVal = iSign * (iInt + nFp) ;
   return nVal ;
}

function Round2(nVal, iD, iType)
// iType: -1 = floor, 0 = round, +1 = ceil
{
   var nPow = Power(iD) ;
   nVal = Math.round(nVal * nPow + iType * .5) / nPow ;
// alert(nVal + "/" + iD + "/" + iType + "/" + nPow + "/" + nVal) ;
   return nVal ;
}

function Validate(sVal, bInt)
{
   var sMessage = "" ;
   var bDot = 0, bE = 0, iState = 0 ;
   var sCh, iK ;
   var bInvalid = 0 ;
   var nValue = bInt ? parseInt(sVal) : parseFloat(sVal) ;

   for (iK = 0 ; sMessage == "" && iK < sVal.length ; ++iK)
   {
      sCh = sVal.charAt(iK) ;
      if (sCh == " ")
      {
         if (iState > 0)
            iState = 9 ;
      }
      else
      {
         if (iState == 9)
            sMessage = "Number '" + sVal + "' has an embedded blank" ;
         else if (sCh == '.' && !bInt)
         {
            if (bDot || bE)
               bInvalid = 1 ;
            else
               bDot = 1 ;
         }
         else if ((sCh == 'e' || sCh == 'E') && !bInt)
         {
            if (bE)
               bInvalid = 1 ;
            else
            {
               bE = 1 ;
               iState = 6 ;
            }
         }
         else if (sCh == '+' || sCh == '-')
         {
            if (iState == 0 || iState == 6)
               ++iState ;
            else
               sMessage = "Number '" + sVal + "' contains a sign "
                                + "in an illegal position"
         }
         else if (sCh >= '0' && sCh <= '9')
         {
            if (iState == 1 || iState == 7)
               ++iState ;
            else if (iState == 0 || iState == 6)
               iState += 2 ;
         }
         else
            bInvalid = 1 ;
      }
      if (bInvalid)
         sMessage = "Number '" + sVal + "' contains"
                        + " invalid non-numeric character(s)" ;
   }

   if (sMessage == "")
      if (iState == 1 || iState == 6 || iState == 7)
         sMessage = "Illegal number: " + sVal ;
      else if (iState == 0)
         nValue = 0 ;
   if (sMessage != "")
   {
      alert(sMessage) ;
      nValue = nErrorNumber ;
   }
   return nValue
}


// DollarFormat -- could be jazzed up to produce "CR" or "DB"
function DollarFormat(nVal, iW, iD)
{
   return GenFmt(nVal, iW, iD, 1) ;
}

function Format(nVal, iW, iD)
{
   return GenFmt(nVal, iW, iD, 0) ;
}

function GenFmt(nVal, iW, iD, bDollar) // format val into w chars,
                        // d digs after decimal point
{
   var sOut = "" ;
   var iSign = 0 ;
   nVal = Round(nVal, iD) ;
   if (nVal < 0)
   {
      nVal = - nVal ;
      iSign = 1 ;
   }
   var iInt = Math.round(nVal) ;
   if (iD > 0)
      iInt = Math.floor(nVal) ;
   var nFp = nVal - iInt ;
   var iDigs = 1 ;
   if (iInt > 9)
      iDigs = Math.floor(Math.log(iInt+.1)/Math.log(10)) + 1 ;
   var iLeft = iW - iSign - (bDollar ? 1 : 0) ;
   if (iD > 0)
      iLeft -= iD + 1 ;
   if (iLeft > iDigs)
      sOut += sBlanks.substring(0, iLeft - iDigs) ;
   if (iSign)
      sOut += '-' ;
   if (bDollar)
      sOut += '$' ;
   sOut += iInt ;
   if (iD > 0)
   {
      nFp = Math.round((1 + nFp) * Power(iD)) ;
      sOut += '.' + String(nFp).substring(1) ;
   }
   return sOut ;
}

function PrepadString(sStr, iW)
{
   if (sStr.length < iW)
      sStr = sBlanks.substring(0, iW - sStr.length) + sStr ;
   return sStr ;
}

function CenterString(sStr, iW)
{
   var iBlanks = iW - sStr.length ;
   if (iBlanks > 0)
      sStr = sBlanks.substring(0, Math.floor(iBlanks/2)) + sStr
                + sBlanks.substring(0, iBlanks - Math.floor(iBlanks/2)) ;
   return sStr ;
}
