// home_tour.js

// findDOM
// DOM <===> Document Object Model
// Find out which DOM, if any, that the browser supports

var isDHTML  = 0; // 1 - supports some kind of DOM - isDHTML || isID || isLayers
var isID     = 0; // 1 - supports W3C ID DOM (MSIE5.0, MacMSIE5, MSIE6.0, NN6.2)
var isAll    = 0; // 1 - supports Internet Explorer All DOM (MSIE4)
var isLayers = 0; // 1 - browser supports Netscape Layer DOM (nn4.8)

// Detect IE_All and W3C_ID using feature sensing to include compatible browsers
// Detect NN_Layers using browser sensing to work-around NN4 bug that causes 
//   feature sensing to fail in external scripts
if( document.getElementById ) 
 { isID = 1; isDHTML = 1; }
else if( document.all )
 { isAll = 1; isDHTML = 1; }
else
 {
 browserVersion = parseInt(navigator.appVersion);
 if( (navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4) )
  { isLayers = 1; isDHTML = 1; }
 }

// Return a pointer to the DOM for an object, or an objects style
function findDOM( objectID, withStyle )
 {
 if( withStyle == 1 )
  {
  if( isID )
   { return (document.getElementById(objectID).style) ; }
  else if( isAll ) 
   { return (document.all[objectID].style); }
  else if( isLayers )
   { return( document.layers[objectID] ); }
  }
 else
  {
  if( isID )
   { return (document.getElementById(objectID)) ; }
  else if( isAll )
   { return (document.all[objectID]); }
  else if( isLayers )
   { return (document.layers[objectID]); }
  }
 }
 
//----- display selected title, picture and text
var bgPos = 0;
var scrollDelay = 1;
//var dX = 5;
var dX = 2;
var go = 0;
var width = 0;
var bgX = 0;

function getObj( name ) 
 {
 var o = 'this.obj = document.';
 var s = 'this.style = document.';
 if( document.getElementById ) 
  {
  eval( o + 'getElementById( name );' );
  eval( s + 'getElementById( name ).style;' );
  }
 else if( document.all ) 
  {
  eval( o + 'all[name];' );
  eval( s + 'all[name].style;' );
  }
 else if( document.layers ) 
  {
  eval( o + 'layers[name];' );
  eval( s + 'layers[name];' );
  }
 }

function show_pic( pic_name, pic_title, panorama, pic_width )
 {
 bgPos = 0;
 bgX = 0;
 width = pic_width;
 document.getElementById('main_pic').style.backgroundImage = "url(images/"+pic_name+".jpg)";
 var bgr = new getObj( 'main_pic' );
 eval( 'bgr.style.backgroundPosition="0px 0px";' );
 document.getElementById('pic_title').innerHTML = pic_title;
 document.getElementById('main_text').innerHTML = $texts[pic_name];
 if( panorama==2 )
  {
  document.getElementById('go_left_box').innerHTML = '<a name="go_left" href="javascript:void()" onMouseOver="go=1; scroll2(1);" onMouseOut="go=0;"><img src="../images/go_left.gif" alt="scroll image left" width="20" height="20" border="0" /></a>';
  document.getElementById('go_right_box').innerHTML = '<a name="go_right" href="javascript:void()" onMouseOver="go=1; scroll2(0);" onMouseOut="go=0;"><img src="../images/go_right.gif" alt="scroll image right" width="20" height="20" border="0" /></a>';
  }
 else if( panorama==1 )
  {
  document.getElementById('go_left_box').innerHTML = '<a name="go_left" href="javascript:void()" onMouseOver="go=1; scroll(1);" onMouseOut="go=0;"><img src="../images/go_left.gif" alt="scroll image left" width="20" height="20" border="0" /></a>';
  document.getElementById('go_right_box').innerHTML = '<a name="go_right" href="javascript:void()" onMouseOver="go=1; scroll(0);" onMouseOut="go=0;"><img src="../images/go_right.gif" alt="scroll image right" width="20" height="20" border="0" /></a>';
  }
 else if( panorama==0 )
  {
  document.getElementById('go_left_box').innerHTML = '';
  document.getElementById('go_right_box').innerHTML = '';
  }
 }

function scroll2( left )
 {
 if( go == 1 )
  {
  var bgr = new getObj( 'main_pic' );
  //if( left == 1 )
  if( (left == 1) && (bgX > 0) )
   { bgPos = bgPos +dX; bgX = bgX -dX; }
  else if( left==0 && (bgX < width-400) )
   { bgPos = bgPos -dX; bgX = bgX +dX; }
  eval( 'bgr.style.backgroundPosition="'+bgPos+'px 0px";' );
  setTimeout( "scroll2( "+left+" )", scrollDelay );
  }
 }
 
function scroll( left )
 {
 if( go == 1 )
  {
  var bgr = new getObj( 'main_pic' );
  //if( left == 1 )
  if( left == 1 )
   { bgPos = bgPos +dX; }
  else
   { bgPos = bgPos -dX; }
  eval( 'bgr.style.backgroundPosition="'+bgPos+'px 0px";' );
  setTimeout( "scroll( "+left+" )", scrollDelay );
  }
 }
 
//----- area info
function show_area_info($data_dir)
 {
 area_info_window = window.open( "../area_info.php?data_dir=" + $data_dir, "area_info", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $area_info_width + ",height=" + $area_info_height );
 area_info_window.focus();
 }
 
 //----- school information
 function show_school_info($data_dir)
 {
 school_info_window = window.open( "../school_info.php?data_dir=" + $data_dir, "school_info", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $school_info_width + ",height=" + $school_info_height );
 school_info_window.focus();
 }
 
//----- mortgage info
function show_mortgage_info()
 {
 mortgage_info_window = window.open( "../mortgage_info.php?data_dir=" + $data_dir, "mortgage_info", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $mortgage_info_width + ",height=" + $mortgage_info_height );
 mortgage_info_window.focus();
 }
 
//----- floorplans
function show_floorplans($data_dir)
 {
 // open 1 floorplan window if a ranch, or 2 floorplan windows if 2-story layout
 floorplan_ml_window = window.open( "../floorplanml_info.php?data_dir=" + $data_dir, "floorplan_ml", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $floor_plan_width + ",height=" + $floor_plan_height );
 floorplan_ml_window.focus();
 if( $floor_plan_number_floors == 2 )
  { 
  floorplan_ul_window = window.open( "../floorplanul_info.php?data_dir=" + $data_dir, "floorplan_ul", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $floor_plan_width + ",height=" + $floor_plan_height );
  floorplan_ul_window.focus();
  }
 }
 
// room dimensions
function show_room_dimensions($data_dir)
 {
 room_dimensions_window = window.open( "../roomdim_info.php?data_dir=" + $data_dir, "room_dimensions", "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=" + $room_dim_width + ",height=" + $room_dim_height );
 room_dimensions_window.focus();
 }
 
//------ real estate agent
function show_real_estate_agent()
 {
 document.write("<div align=\"left\">\n");
 document.write(" <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
 document.write("  <tr><td class=\"tool_title\">Real Estate Agents</td></tr>\n");
 document.write("  <tr><td class=\"tool_text\">" + $r_e_agent_first_name_1 + " " + $r_e_agent_last_name_1 + "</td></tr>\n");
 document.write("  <tr><td class=\"tool_text\">" + $r_e_agent_phone_1 + "</td></tr>\n");
 document.write("  <tr><td class=\"tool_link\"><div class=\"tool_link\"><div align=\"center\"><a href=\"mailto:" + $r_e_agent_link_1 + "\" class=\"tool_link\">Email " + $r_e_agent_first_name_1 + "</a></div></div></td></tr>\n");
 if( $r_e_agent_number == 2 )
  {
  document.write("  <tr><td class=\"tool_text\">" + $r_e_agent_first_name_2 + " " + $r_e_agent_last_name_2 + "</td></tr>\n");
  document.write("  <tr><td class=\"tool_text\">" + $r_e_agent_phone_2 + "</td></tr>\n");
  document.write("  <tr><td class=\"tool_link\"><div class=\"tool_link\"><div align=\"center\"><a href=\"mailto:" + $r_e_agent_link_2 + "\" class=\"tool_link\">Email " + $r_e_agent_first_name_2 + "</a></div></div></td></tr>\n");
  }
 document.write(" </table>\n");
 document.write("</div>\n");
 }
 
//----- mortgage calculations
function calculate_qualification()
 {
 // calculate maximum monthly mortgage payment
 // form name="qualification"
 // input name="income" = monthly income
 // input name="debt"   = other monthly debt
 // answer2             = maximum monthly payment
 var monthly_pmi = document.qualification.pmi.value / 12;
 var monthly_prop_taxes = document.qualification.prop_taxes.value / 12;
 var monthly_home_insurance = document.qualification.home_insurance.value / 12;
 var monthly_income = document.qualification.income.value;
 var monthly_debt   = document.qualification.debt.value;
	 
 var short_term_qual;
 var long_term_qual;
 var answer;
 
 short_term_qual = 0.28*monthly_income - monthly_pmi - monthly_prop_taxes - monthly_home_insurance;
 long_term_qual = 0.36*monthly_income - monthly_debt - monthly_pmi - monthly_prop_taxes - monthly_home_insurance;
 if( short_term_qual < long_term_qual )
  { answer = short_term_qual; }
 else
  { answer = long_term_qual; }
  
 document.qualification.answer2.value = Math.round( answer * 100 )/100;
 }

function calculate_payment() 
 {
 // calculate monthly mortgage payment
 // form  name="payment"
 // input name="total"      = total loan amount
 // input name="num_months" = number of months in loan
 // input name="rate"       = annual interest rate in percent
 // input name="answer"     = monthly payment
 var total_loan;
 var num_months;
 var annual_rate_x100;
 var mon_rate; 
 var answer;

 total_loan       = document.payment.total.value;
 num_months       = document.payment.num_years.value * 12;
 annual_rate_x100 = document.payment.rate.value;
 mon_rate         = annual_rate_x100 / 1200;
 // calculate monthly payment
 answer = total_loan * mon_rate / ( 1 - ( Math.pow( 1 / ( 1 + mon_rate ), num_months ) ) );
 document.payment.answer.value = Math.round( answer * 100 )/100;
 }

 