//*********************************************************************
//
// Featured Homes
//
// Copyright (c) 2009, MFM Communication Software, Inc.
//
//*********************************************************************
//
// feturedhomes.js
// $Id: featuredhomes.js,v 1.7 2009/05/20 12:16:04 lbettag Exp $
//
// Main functions for displying featured homes
//
//*********************************************************************
//
// Tell jsjam.pl to not change these identifier and function names
//
// jsjam-keep:addFeaturedHome
// jsjam-keep:initFeaturedHome
// jsjam-keep:feathomes
// jsjam-keep:makeFHHtml
// jsjam-keep:fhDisplayNum
//
//*********************************************************************

function initFeaturedHome()
{
  var numHomes = feathomes.length;
  var found = 0;
  var temp = new Array();
  
  // ah....what if we don't have enough qualifying listings?
  var cnt = 0;
  var id = "";

  var myHtml = "<table>";

  while (found < fhDisplayNum && cnt < 100)
  {
    cnt++;

    // Get number between 0.0 and 1.0 from random() method.
    // Multiply it with the difference of upper value and one less than the lower 
    // value of the range.
    // Use floor() to convert it into an integer
    // Add the lower value of the range

    //var rand_no = Math.floor((numHomes-0)*Math.random()) + 1;

    var randomnumber=Math.floor(Math.random()*(numHomes));
    //alert(rand_no + " - " + randomnumber);
    
    if (randomnumber == 0)
      continue;
    
    // see if we have that number in any of temp's elements
    var foundtemp = false;
    for (var i = 0; i < temp.length; i++)
    {
      if (temp[i] == randomnumber)
        foundtemp = true;
    }
    if (foundtemp)
      continue;
    
    // check for valid data
    if (feathomes[randomnumber]['status'] != "A" && feathomes[randomnumber]['status'] != "P")
      continue;
    
    temp[found] = randomnumber;  
    myHtml += makeFHHtml(temp[found]);

    found++;
  }

  myHtml += "</table>";
  var fhContainer = document.getElementById('fhContainer');
  fhContainer.innerHTML = myHtml; 
}

function addFeaturedHome(num)
{
  // main container div
  var fhContainer = document.getElementById('fhContainer');
  
  var newLink=document.createElement('A');
  newLink.setAttribute('href','/displaylist.asw?listnum=' + feathomes[num]['listnum'] + '&mls=' + feathomes[num]['mls']);
  newLink.setAttribute('target','_top');

  var img = document.createElement('IMG');
  img.setAttribute('src',feathomes[num]['photo']);
  img.setAttribute('alt','');
  img.setAttribute((document.all ? 'className' : 'class'), 'fhImage');

  newLink.appendChild(img);

  // fhImageDiv - containing the image/link
  var fhImageDiv = document.createElement('DIV');
  fhImageDiv.setAttribute((document.all ? 'className' : 'class'), 'fhImageDiv');
  fhImageDiv.setAttribute('id',"fhImageDiv_" + num);
  
  fhImageDiv.appendChild(newLink);

  // fhDiv - containing div for one listing
  var fhDiv = document.createElement('Div');
  fhDiv.setAttribute((document.all ? 'className' : 'class'), 'fhDiv');
  fhDiv.setAttribute('id',"fhDiv_" + num);
  
  fhDiv.appendChild(fhImageDiv);

  // fhInfoDivInner - inner div for listing info
  var fhInfoDivInner  = document.createElement('DIV');
  fhInfoDivInner.setAttribute((document.all ? 'className' : 'class'), 'fhInfoDivInner');
  fhInfoDivInner.setAttribute('id', "fhInfoDivInner_" + num);

  var fhHtml = makeFHHtml(num);
  fhInfoDivInner.innerHTML = fhHtml;
  
  // fhInfoDivMiddle - middle div for listing info
  var fhInfoDivMiddle  = document.createElement('DIV');
  fhInfoDivMiddle.setAttribute((document.all ? 'className' : 'class'), 'fhInfoDivMiddle');
  fhInfoDivMiddle.setAttribute('id', "fhInfoDivMiddle_" + num);
  
  fhInfoDivMiddle.appendChild(fhInfoDivInner);

  // fhInfoDivOuter - outer div for listing info
  var fhInfoDivOuter  = document.createElement('DIV');
  fhInfoDivOuter.setAttribute((document.all ? 'className' : 'class'), 'fhInfoDivOuter');
  fhInfoDivOuter.setAttribute('id', "fhInfoDivOuter_" + num);
 
  fhInfoDivOuter.appendChild(fhInfoDivMiddle);

  fhDiv.appendChild(fhInfoDivOuter);

  fhContainer.appendChild(fhDiv);
}

//*********************************************************************
//
// CHANGE HISTORY
//
// $Log: featuredhomes.js,v $
// Revision 1.7  2009/05/20 12:16:04  lbettag
// change random number generator
//
// Revision 1.6  2009/05/19 16:45:47  lbettag
// test random num generator
//
// Revision 1.4  2009/05/19 16:21:24  lbettag
// pass 2nd random number
//
// Revision 1.3  2009/05/19 16:19:49  lbettag
// compare random number generators
//
// Revision 1.2  2009/04/23 12:09:44  lbettag
// add table tags to html output
//
// Revision 1.1  2009/04/22 17:27:56  lbettag
// override standard file
//
// Revision 1.9  2009/04/07 18:38:34  lbettag
// remove debug code
//
// Revision 1.8  2009/04/07 18:37:56  lbettag
// add debug code
//
// Revision 1.7  2009/04/07 14:08:55  lbettag
// tweak for jsjam
//
// Revision 1.6  2009/04/07 13:22:45  lbettag
// change class name fhImg to fhImage
//
// Revision 1.5  2009/04/07 12:31:24  lbettag
// clean up
//
// Revision 1.4  2009/04/07 12:30:15  lbettag
// format
//
// Revision 1.3  2009/04/06 17:05:41  lbettag
// add target to link
//
// Revision 1.2  2009/04/06 14:10:36  lbettag
// add standar head/footer for.  ad jsjam-keep lines
//
//
//*********************************************************************
