// *********************************************************
// This java script library is included at the top of all
// pages within the HomesUnique site system. It contains
// all the java functions and some of array definitions.
//
// Data is passed between the individual pages using the
// document cookie. The cookie is parsed by each page at
// loadtime by code in this file.
//
// Author: Ross McDowell
//         3rdOrigin Productions www.3rdorigin.com
//**********************************************************

// *********************************************************
function getCookieVar( forString )
// This function gets the value associated with "forString"
// from the cookie. Return value is numeric
// *********************************************************
{
  return getCookieStr(forString).valueOf();
}

// *********************************************************
function getCookieStr( forString )
// This function gets the value associated with "forString"
// from the cookie. Return value is alpa string.
// *********************************************************
{
  var index;
  var namestart;
  var nameend;
  // if this function fails to get a valid string retString
  // will be returned with NULL value.
  var retString = "";

  if(document.cookie)  // is there a cookie?
  {
    // if the cookie exists, get the character position of
    // the first occurance of "forString" in the cookie and
    // assign it to the index variable. -1 is the result
    // when the string is not found within the cookie.
    index = document.cookie.indexOf(forString);
    if (index != -1)
    {
      namestart = (document.cookie.indexOf("=", index) + 1);
      if( namestart == -1 )
        retString = "";
      else
      {
        nameend = document.cookie.indexOf(";", index);
        if (nameend == -1)
        {
          nameend = document.cookie.length;
          retString = document.cookie.substring(namestart, nameend);
        }
        else if ( nameend > namestart )
        {
          retString = document.cookie.substring(namestart, nameend);
        }
      }
    }
  }
  return retString;
}

// **************************************************************
// Parse the cookie for data passed from previously loaded pages
// **************************************************************
//alert(document.cookie);
// numMatches would be the number of plans in the database that
// match the user's search criteria. Put in the cookie by
// HU-SearchForm.htm
var numMatches = getCookieVar("SEARCH_MATCHES");

// thumbsRequested, used primarily by HU-SearchResults.htm, indicates
// whether or not the user wants to view thumbnails in the list of
// search results.
var thumbsRequested = getCookieVar("THMB_REQ");

// masterSearchString, set by HU-SearchForm.htm is passed to
// HU-PlanPage.htm when the user inputs the name or number of
// a specific HomesUnique stock plan.
var masterSearchString = getCookieStr("MSRCHSTR");

// numWishes is the number of plans that have been added to the
// cookie wishlist.
var numWishes = getWishList();

var planNum = getCookieVar("PLANVIEW");

var HU_url="http://www.homesuniqueinc.com";
var HU_title="Homes Unique, Inc. - Residential Design";

// ******************************************************
// Thus ends the cookie parsing done by each page onload.
// ******************************************************

// Now for some general purpose functions.

// **************************************
function putCookieVar( forString, sVal )
// **************************************
{
  document.cookie = forString +"="+ sVal;
}

// *********************
function changeImages()
// *********************
{
  var i;
	if (document.images)
	{
		for (i=0; i<changeImages.arguments.length; i+=2)
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// *********************************************
function NewWindow(mypage, myname, w, h, scroll)
// *********************************************
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
  win = window.open(mypage, myname, winprops);
  if (parseInt(navigator.appVersion) >= 4)
  {
    win.window.focus();
  }
}

// *************************
function resetMatchFlags()
// *************************
{
  var i;
  //initialize the matchFlag array
  for( i=1; i<=parent.databaserecords; i++ )
    parent.matchFlag[i] = 1;
}

// ************************
function runQuery()
// ************************
{
  var i;
  var flMin = 0;
  var flMax = 0;
  var slMin = 0;
  var slMax = 0;
  var fDimCheck = 0;
  var sDimCheck = 0;
  var hLen = 0;
  var hDep = 0;

  if(document.ExtDimForm.FLmin.value != "" )
    flMin = parseInt(document.ExtDimForm.FLmin.value);
  if(document.ExtDimForm.FLmax.value != "" )
    flMax = parseInt(document.ExtDimForm.FLmax.value);
  if(document.ExtDimForm.SLmin.value != "" )
    slMin = parseInt(document.ExtDimForm.SLmin.value);
  if(document.ExtDimForm.SLmax.value != "" )
    slMax = parseInt(document.ExtDimForm.SLmax.value);

  if( (flMin > 0 ) && (flMax > 0) )
    fDimCheck = 1;
  if( (slMin > 0) && (slMax > 0) )
    sDimCheck = 1;

  numMatches = 0;

  for( i=1; i<=parent.databaserecords; i++ )
  {
    // match on number of floors ?
    if( parent.numFloors[0] != -1 )
      if( parent.numFloors[i] != document.PlanTypeForm.rad[parent.numFloors[0]].value )
      parent.matchFlag[i] = 0;

    // match on number of bedrooms ?
    if( parent.numBed[0] != -1 && parent.numBed[i] != document.numBedsForm.rad[parent.numBed[0]].value )
      parent.matchFlag[i] = 0;

    // match on location of master ?
    if( parent.masterUp[0] != -1 && parent.masterUp[i] != document.masterUpForm.rad[parent.masterUp[0]].value )
      parent.matchFlag[i] = 0;

    // match on bonus room ?
    //if( parent.bonusRoom[0] != -1 && parent.bonusRoom[i] != document.bonusRoomForm.rad[parent.bonusRoom[0]].value )
    if( parent.bonusRoom[0] == 0 && parent.bonusRoom[i] == 0)
      parent.matchFlag[i] = 0;

    // match on square footage ?
    if( parent.sqFootage[i].valueOf() < document.sfForm.sfMin.value.valueOf() ||
        parent.sqFootage[i].valueOf() > document.sfForm.sfMax.value.valueOf()    )
      parent.matchFlag[i] = 0;

    // match on plan style ?
    if( document.styleForm.planStyle.value != "undefined" && parent.styleCode[i] != document.styleForm.planStyle.value )
      parent.matchFlag[i] = 0;

    // match on exterior dimensions?
    hLen = parent.hLength[i].valueOf();
    hDep = parent.hDepth[i].valueOf();

    if( sDimCheck > 0 )
    {
        if( hDep < slMin )
        {
          parent.matchFlag[i] = 0;
        }
        if( slMax < hDep )
        {
          parent.matchFlag[i] = 0;
        }
    }
    if( fDimCheck > 0 )
    {
      if( hLen > flMax )
      {
          parent.matchFlag[i] = 0;
      }
      if( hLen < flMin )
      {
          parent.matchFlag[i] = 0;
      }
    }

    // match on garage ?
    if( parent.garage[0] == 0 && parent.garage[i] == 0)
      parent.matchFlag[i] = 0;
//    if( parent.garage[0] != -1 && parent.garage[i] != document.garageForm.rad[parent.garage[0]].value )
//      parent.matchFlag[i] = 0;

    // match on split plan ?
    if( parent.splitPlan[0] != -1 && parent.splitPlan[i] != document.splitForm.rad[parent.splitPlan[0]].value )
      parent.matchFlag[i] = 0;

    // Set number of matches found
    if( parent.matchFlag[i] )
    {
        numMatches++;
        putCookieVar( "SEARCH_MATCHES", numMatches );
    }
  }
}

// ******************************************
function getRadioCheckedValue( buttonGroup )
// ******************************************
{
  var i;
  var retValue = -1;
  for( i=0; i<buttonGroup.length; i++ )
  {
		if (buttonGroup[i].checked)
		{
			retValue=i;
		}
	}
  return retValue;
}

// *********************
function psearch()
// *********************
{
  var treq = 1;

//  if( document.PlanSearch.thumbs.checked != true)
//    treq = 0;

  putCookieVar( "THMB_REQ", treq );
  resetMatchFlags();

  // load plan specified
  if( document.PlanSearch.plan_name.value != "" )
  {
    masterSearchString = document.PlanSearch.plan_name.value;
    getMatchesByPlanName(masterSearchString);
  }
  else if( document.PlanSearch.plan_num.value != "" )
  {
    masterSearchString = document.PlanSearch.plan_num.value;
    getMatchesByPlanNum(masterSearchString);
  }
  else
  {
    masterSearchString = "";

    parent.numFloors[0] = getRadioCheckedValue( document.PlanTypeForm.rad );
    parent.numBed[0] = getRadioCheckedValue( document.numBedsForm.rad );
    parent.masterUp[0] = getRadioCheckedValue( document.masterUpForm.rad );
    parent.bonusRoom[0] = getRadioCheckedValue( document.bonusRoomForm.rad );
    parent.garage[0] = getRadioCheckedValue( document.garageForm.rad );
    parent.splitPlan[0] = getRadioCheckedValue( document.splitForm.rad );

    // query the database for form matches
    runQuery();
  }
  if( masterSearchString.length > 0 )
      putCookieVar( "MSRCHSTR", masterSearchString );
}

// ************************
function commaformat(sval)
// ************************
{
  var decpoint;
  var begin;
  var middle="";
  var end;
	var temp_char;


  // find the possible decimal point in the number string
  decpoint = sval.indexOf(".")
  // separate the whole number from the fraction
  if (decpoint != -1)
  {
    begin = sval.substring(0, decpoint);
    end = sval.substring(decpoint+1, sval.length);
  }
  else
  {
    begin = sval;
    end = "";
  }

  // break the whole number string where the comma should go
  while( begin.length > 3 )
  {
    middle = "," + begin.substring( begin.length - 3, begin.length ) + middle;
    begin = begin.substring( 0, begin.length-3 );
  }

  temp_char = begin + middle;
  if( end != "" )
    return( temp_char + "." + end );
  else
    return temp_char;
  return ( begin + middle + "." + end )
}

// *****************************************
function getMatchesByPlanName( planName )
// *****************************************
{
  var i;
  var recMatch;
  var dbName = "";

  for( i=1; i<=parent.databaserecords; i++ )
  {
    dbName = parent.modelName[i].toLowerCase();
    recMatch = dbName.indexOf(planName.toLowerCase());
    if( recMatch == -1 )
    {
      parent.matchFlag[i] = 0;
    }
    else
    {
      numMatches++;
      putCookieVar( "SEARCH_MATCHES", numMatches );
    }
  }
}

// *****************************************
function getMatchesByPlanNum( planNum )
// *****************************************
{
  var i;
  var recMatch;
  var dbNum = "";

  for( i=1; i<=parent.databaserecords; i++ )
  {
    dbNum = parent.baseFileName[i].toLowerCase();
    recMatch = dbNum.indexOf(planNum.toLowerCase());
    if( recMatch == -1 )
    {
      parent.matchFlag[i] = 0;
    }
    else
    {
      numMatches++;
      putCookieVar( "SEARCH_MATCHES", numMatches );
    }
  }
}

// *********************************
function loadPlanPage( planIndex )
// *********************************
{
  //masterSearchString = parent.baseFileName[planIndex];
  putCookieVar( "MSRCHSTR", parent.baseFileName[planIndex] );
  // Load the plan page
  parent.HU_Frame.location.href = "HU-PlanPage.htm";
}

// *****************************
function addToWishList(planNum)
// *****************************
{
  var wishedItAlready = findPlanInWishList(planNum);

  if( wishedItAlready == -1 )
  {
    parent.wishList[numWishes] = planNum;
    numWishes++;
    putWishList();
    alert('The ' +parent.modelName[planNum]+ ', plan code: ' +getModelNumber(planNum)+ ' has been added to your personal wish list.  This is one of ' +numWishes+ ' plans currently on your wishlist. Click on the "Wishlist" link at the top of the page to view and edit your wishlist.');
  }
  else
  {
    alert('The ' +parent.modelName[planNum]+ ', plan code: ' +getModelNumber(planNum)+ ' is already in your personal wish list.  This is one of ' +numWishes+ ' plans currently on your wishlist. Click on the "Wishlist" link at the top of the page to view and edit your wishlist.');
  }
}

// **********************************
function findPlanInWishList(planNum)
// **********************************
{
  var i;
  for( i=0; i<numWishes; i++ )
  {
    if( parent.wishList[i] == planNum )
      return i;
  }
  return -1;
}

// *********************
function putWishList()
// *********************
{
  var ckString = "";
  var i;
  for( i=0; i<numWishes; i++ )
  {
    if( parent.wishList[i] > 0 )
    {
      if( ckString.length )
        ckString = ckString + ",";
      ckString = ckString + parent.wishList[i];
    }
  }
  if( ckString.length )
  {
    var expdate = new Date();
    expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 365));
    ckString = "WISHES=" + ckString + "; expires=" + expdate.toGMTString();
  }
  else
    ckString = "WISHES=0; expires=Thu, 01-Jan-70 00:00:01 GMT"

    document.cookie = ckString;
}

// ******************************
function getModelNumber(planNum)
// ******************************
{
  return parent.baseFileName[planNum].substring( 2, 9 );
}

// ********************
function getWishList()
// ********************
{
  var wishcount = 0;
  var commaLoc=0;
  var ckString = "";
  var newString = "";
  var nsVal = 0;

  if(document.cookie)
  {
    ckString = getCookieStr("WISHES");

    if( ckString.substring(0, 1) == ';' )
      return 0;

    while( ckString.length )
    {
      commaLoc = ckString.indexOf(",", 0 );
      if( commaLoc != -1 )
      {
        newString = ckString.substring( 0, commaLoc );
        nsVal = newString.valueOf();
        if( nsVal > 0 )
        {
          parent.wishList[wishcount] = nsVal;
          wishcount++;
          newString = ckString.substring(commaLoc+1);
        }
      }
      else
      {
        nsVal = ckString.valueOf();
        if( nsVal > 0 )
        {
          parent.wishList[wishcount] = ckString.valueOf();
          wishcount++;
        }
        newString = "";
      }
      ckString = newString;
    }
  }
  return wishcount;
}


// **********************************
function delFromWishList( wishIndex )
// **********************************
{
  // To delete a member of the wishlist, simply set it's
  // value to 0. Then call putWishList and getWishList to
  // re-align the array.
  parent.wishList[wishIndex] = 0;
  putWishList();
  numWishes = getWishList();
}

// **************************
function docwriteCheckOut()
// **************************
{
  var i = 0;
  var iTemp = 0.0;
  var checks = 0;
  var planNum = 0;
  var planCodeNum = "";
  var planName = ""
  var bsPrice = 0;
  var vlPrice = 0;
  var totalString = "";
  var subtotal = 0.0;
  var grandTotal = 0.0;
  var j;
  var orderString = "";

  // Make sure the client actually checked some purchase options
  // on the wishlist page
  for( i = 0; i < numWishes; i++ )
    if( parent.orderOptions[i][11] > 0 )
      if( (parent.orderOptions[i][1] + parent.orderOptions[i][2] + parent.orderOptions[i][3]) > 0 )
      { checks++; }

  if( checks <= 0 )
  {
    document.write('<P><CENTER><TABLE Border=0 CELLPADDING=4 CELLSPACING=0 WIDTH=90%>');
    document.write('<TR><TD bgcolor=#E1D9CA><center><TABLE Border=0 width=98% CELLPADDING=0 CELLSPACING=0><TR><TD>');
    document.write("<Font face=verdana size=2 color=#000000><CENTER><B>You have requested a WishList Purchase Order. However, you forgot to check any of the purchase options within the Wishlist form.<P>Use your browser BACK button, or click on the WishList icon at the top of this page to return. </B></CENTER>");
    document.write('</TD></TR></TABLE></TD></TR></TABLE>');
  }
  else
  {
    document.write('<TR><TD colspan=2><CENTER><Font face=verdana size=2 color=#000000><B>Summary of WishList Purchase Order</B></FONT><HR></CENTER></TD></TR> ');
    document.write('<TR><TD colspan=2>&nbsp;</TD></TR>');
    // NOTE: This code assumes that list content has been verified before linking to the checkout page.
    // Therefore, the numWishes variable value should be greater than 0
    for( i = 0; i < numWishes; i++ )
    {
      if( parent.orderOptions[i][11] > 0 )
      {
        subtotal = 0;
        planNum = parent.wishList[i];  // database index of this plan
        planCodeNum = getModelNumber(planNum);
        planName  = parent.modelName[planNum];
        orderString = "\nHU #: " +planCodeNum+ "  HU Name: " +planName;

        document.write('<TR><TD><Font face=verdana size=1 color=#0000FF><B>' +planCodeNum+ '</B></TD><TD><Font face=verdana size=1 color=#0000FF><B>' +planName+ '</B></TD></TR>');
        if( parent.orderOptions[i][1] > 0 )
        {
          iTemp = getPlanPrice( planNum, 1 );
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Builder Set:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Builder Set&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][2] > 0 )
        {
          iTemp = getPlanPrice( planNum, 2 );
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Vellum Set:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Vellum Set&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][3] > 0 )
        {
          iTemp = 50.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Study Set:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Study Set&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][4] > 0 )
        {
          iTemp = 150.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Reverse Plan:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Reverse Plan&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][5] > 0 )
        {
          iTemp = 150.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " 2X6 Exterior Walls:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>2X6 Exterior Walls&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][6] > 0 )
        {
          iTemp = 200.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Brick Veneer:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Brick Veneer&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][7] > 0 )
        {
          iTemp = 100.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Garage Alteration:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Garage Alteration&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][8] > 0 )
        {
          iTemp = 200.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Basement Plan:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Basement Plan&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][9] > 0 )
        {
          iTemp = 150.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Slab Foundation Plan:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Slab Foundation Plan&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        if( parent.orderOptions[i][10] > 0 )
        {
          iTemp = 125.0;
          subtotal += iTemp;
          priceString = String(iTemp);
          priceString = "$"+commaformat(priceString);
          orderString = orderString+ " Ceiling Height Changes:" +priceString;
          document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#0000FF>Ceiling Height Changes&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        }
        priceString = String(subtotal);
        priceString = "$"+commaformat(priceString);
        document.write('<TR><TD></TD><TD><Font face=verdana size=1 color=#FF0000>Total this plan:&nbsp;&nbsp;' +priceString+ '</TD></TR>');
        document.write('<TR><TD colspan=3><HR></TD></TR>');
        document.write('<input type=hidden name="OrderedPlans" value="' +orderString+ '">');
        grandTotal += subtotal;
      }
    } //end of forloop
    totalString = ""+grandTotal;
    totalString = "$"+commaformat(totalString);
    document.write('<TR><TD colspan=2><Font face=verdana size=1 color=#000000><B>Total Price = </B>&nbsp;<Font face=verdana size=1 color=#0000FF><B>' +totalString+ '</B></TD></TR>');
    docwriteCheckoutForm();
  }
}

// ****************************************************************
function getPlanPrice( planIndex, getType )
// ****************************************************************
{
  var i;
  var retValue = -1;
  var priceLetter = "";

  priceLetter = parent.priceCode[planIndex];
  if( priceLetter.length )
  {
    for( i = 0; i<parent.priceCodeRecords; i++ )
    {
      if( parent.codeLetter[i] == priceLetter )
      {
        if( getType == 1 )
          return  Number(parent.buildingSetPrice[i]);
        else if( getType == 2 )
          return Number(parent.vellumPrice[i]);
      }
    }
  }
  return -1;
}

// ********************
function saveSetType()
// ********************
{
  setType = document.SetType.settype.value;
  putCookieVar("SET_TYPE", setType );
}

// *********************
function sideMenuHome()
// *********************
{
  document.write('<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="135">');
  document.write('<TR>');
  document.write('<TD BACKGROUND="images/side_menu_back.jpg" CLASS="menutext" VALIGN="middle" WIDTH="135" NOWRAP ALIGN="CENTER"><BR>');
  document.write('<A HREF="HU-About.htm" CLASS="menutext" onfocus="if(this.blur)this.blur()" title="About Us">About Us</A><BR>');
  document.write('<BR><A HREF="HU-Services.htm" CLASS="menutext" onFocus="if(this.blur)this.blur()" title="Additional Services">Additional <br>Services</A><BR>');
  document.write('<BR><A HREF="HU-Links.htm" CLASS="menutext" onFocus="if(this.blur)this.blur()" title="Links">Links</A><BR>');
  document.write('<BR><A HREF="feedback.html" CLASS="menutext" onFocus="if(this.blur)this.blur()" title="Give us your feedback">Feedback Form</A><BR>');
  document.write('<BR><A HREF="HU-FAQ.htm" CLASS="menutext" onFocus="if(this.blur)this.blur()" title="Frequently Asked Questions">FAQ?</A><BR>');
  document.write('<BR>');

  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
  {
    document.write('<A HREF="javascript:window.external.AddFavorite(');
    document.write("'" +HU_url+ "','" +HU_title+ "')");
    document.write('" onMouseOver=" window.status=');
    document.write("'Add Us To Your Favorites'; return true;");
    document.write('" onMouseOut=" window.status=');
    document.write("' '; return true;");
    document.write('" class="orangetext">Bookmark Us</a>');

  }
  else
  {
    var msg = "Don't forget to bookmark us!";
    if(navigator.appName == "Netscape") msg += "  (CTRL-D)";
    document.write(msg);
  }

  document.write('<br><br></td></tr><tr>');
  document.write('<td width="135" valign="top" nowrap><img src="images/search.jpg" width="135" height="74" border="0"  USEMAP="#search_Map"></td>');
  document.write('</tr></table>');
}

// ***********************
function sideMenuSearch()
// ***********************
{
  document.write('<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="135">');
  document.write('<TR><TD BACKGROUND="images/side_menu_back.jpg" CLASS="menutext" VALIGN="middle" WIDTH="135" NOWRAP ALIGN="CENTER"><BR><BR>');
  document.write('<A HREF="HU-OneStory.htm" CLASS="menutext">&nbsp;&nbsp;&nbsp;&nbsp; One Story</A><BR><BR><BR>');
  document.write('<A HREF="HU-OneHalfStory.htm" class="menutext">&nbsp;&nbsp;&nbsp;&nbsp; One and a <br>&nbsp;&nbsp;&nbsp;&nbsp; Half Story</a><BR><BR><BR>');
  document.write('<a href="HU-TwoStory.htm" class="menutext">&nbsp;&nbsp;&nbsp;&nbsp; Two Story</a><BR><BR><BR>');
  document.write('<a href="HU-StockPricing.htm" class="orangetext"><ul>Pricing</a><BR><BR><BR>');
  document.write('<a href="HU-Copyright.htm" class="orangetext">Copyright</ul></a>');
  document.write('</TD></TR><TR>');
  document.write('<TD WIDTH="135" VALIGN="top" NOWRAP><IMG SRC="images/search.jpg" WIDTH="135" HEIGHT="74" BORDER="0"  USEMAP="#search_Map"></TD>');
  document.write('</TR></TABLE>');
}

// *****************************
function docwritePriceTable()
// *****************************
{
  var i = 0;

  document.write('<CENTER><table border=0>');
  document.write('<tr height="50">');
  document.write('<td colspan=4 width=400 height=50 class="bluetext" align=center><b>2005 Pricing Sheet for Homes Unique Stock Plans</b></td>');
  document.write('</tr><tr>');
  document.write('<td colspan=2 height=30 class="bodytext" align=center><b>Stock Plan Package</b></td>');
  document.write('<td width=100 height=30 class="bodytext" align=center><b>Building Sets</b></td>');
  document.write('<td width=100 height=30 class="bodytext" align=center><b>Reproducible Vellums</b></td>');
  document.write('</tr>');

  for( i = 1; i<=parent.priceCodeRecords; i++ )
  {
    document.write('<TR>');
    document.write('<td width=50 height=20 class="bodytext" align=center><B>');
    document.write(parent.codeLetter[i]+ '</B></td>');

    document.write('<td width=100 height=20 class="bodytext">');
    document.write(parent.sqRange[i]+ '</td>');

    document.write('<td width=125 height=20 class="bodytext" align=center>$');
    document.write(parent.buildingSetPrice[i]+ '</td>');

    document.write('<td width=125 height=20 class="bodytext" align=center>$');
    document.write(parent.vellumPrice[i]+ '</td>');

    document.write('</tr>');
  }
  document.write('</table></CENTER>');
}

// **********************************************************************
function docwriteTopImageMap()
// This function is used by every dang file in the HomesUnigue web site.
// It dynamically writes the image map for the wishlist
// icon at the top of each page. This is usefull for ease in updating
// the top image, you will need to change the COORDS only once, below.
// **********************************************************************
{
  document.write('<MAP NAME="top_image_Map">');
  document.write('<AREA SHAPE="rect" ALT="View My Wishlist" COORDS="209,8,259,43" HREF="HU-WishList.htm">');
  document.write('</MAP>');
}

// *****************************************
function planSearchByFloors( numberFloors )
// *****************************************
{
  var i;
  var bcolor="#CFC7B9";
  var bcolorindex = 0;

  // query the database for floor matches
  resetMatchFlags();
  numMatches = 0;
  for( i=1; i<=parent.databaserecords; i++ )
  {
    if( parent.numFloors[i] != numberFloors )
      parent.matchFlag[i] = 0;
    else
        numMatches++;
  }

  document.write('<BR>&nbsp;&nbsp;&nbsp;&nbsp; <B>Total in current database: ' +numMatches+ '</B>');

  if( numMatches )
  {
    document.write('<P><CENTER>');
    document.write('<TABLE Border=0 CELLPADDING=4 CELLSPACING=0 WIDTH=90%>');
    document.write  ('<TR>');
    document.write    ('<TD bgcolor=#000000><center>');
    document.write      ('<TABLE Border=1 width=98% CELLPADDING=0 CELLSPACING=0>');

    var SQ = "'";
    for( i=1; i<=parent.databaserecords; i++ )
    {
      if( parent.matchFlag[i] > 0 )
      {
        docwritePlanListing(i, bcolor );

        if( bcolorindex )
        {
            bcolor = "#CFC7B9";
            bcolorindex = 0;
        }
        else
        {
            bcolor = "#E1D9CA";
            bcolorindex = 1;
        }
      }
    }
  }
  else
  {
    document.write('<P><CENTER><TABLE Border=0 CELLPADDING=4 CELLSPACING=0 WIDTH=90%>');
    document.write('<TR><TD bgcolor=#E1D9CA><center><TABLE Border=0 width=98% CELLPADDING=0 CELLSPACING=0>');
    document.write("<Font face=verdana size=2 color=#000000>We're sorry ... <BR>There are no plans in our database matching your selected search criteria.<P>Be ye not dismayed for ye may try the search again <BR> ... perhaps using fewer specifications.</font>");
    document.write('</TD></TR>');
  }
  document.write('</TABLE></TD></TR></TABLE>');
}

// ********************
function gotoNextPlan(dirc)
// ********************
{
  var tempNum = 0;

  tempNum = getNextMatchFlag(dirc);
  if( tempNum > 0 )
  {
    planNum = tempNum;
    putCookieVar("PLANVIEW", planNum );
    location.reload();
  }
}

// ***********************************
function getNextMatchFlag( direction )
// ***********************************
{
  var i = planNum;

  do
  {
    if( direction != -1 )
      i++;
    else
      i--;

//alert( "i = " +i+ " matchflag[i] = " +parent.matchFlag[i] );
    if( parent.matchFlag[i] == 1 )
      return i;

  } while( i > 0 && i < parent.databaserecords );

  return -1;
}

// **************************
function clean_SearchParms()
// **************************
{
  resetMatchFlags();
  numMatches = 0;
  document.cookie = "SEARCH_MATCHES=0; expires=Thu, 01-Jan-70 00:00:01 GMT"

  masterSearchString = "";
  document.cookie = "MSRCHSTR=; expires=Thu, 01-Jan-70 00:00:01 GMT"
}

// **************************
function docwriteWishListV2()
// **************************
{
      var i;
      var j;
      var bcolor="#E1D9CA";

      if( numWishes )
      {
        document.write('<CENTER><B>You have a total of <Font color=RED>' +numWishes+ '</FONT> plans in your wish list.</B></CENTER>');
        document.write('<CENTER><Font face=verdana size=1 color=#000000>To purchase plans, check the desired purchase options within your wish list <BR>and click the Prepare Purchase Order button!</CENTER>');
        document.write('<CENTER><P><A HREF="HU-CheckOut.htm" onClick="preparePurchaseOrder();"><img src="images/HU-OrderButton.gif" border=0></A></CENTER>');
        document.write('<P><CENTER>');
        document.write('<TABLE Border=1 CELLPADDING=1 CELLSPACING=1 WIDTH=90%>');
        document.write  ('<TR>');
        document.write    ('<TD bgcolor=#913C39><center>');
        document.write('<TABLE Border=1 CELLPADDING=2 CELLSPACING=0 WIDTH=99%>');
        document.write  ('<TR>');
        document.write    ('<TD bgcolor=#000000><center>');

        var SQ = "'";

        for( j=0; j<numWishes; j++ )
        {
          if( parent.wishList[j] > 0 )
          {
            i = parent.wishList[j];

            document.write('<TABLE Border=1 width=99% CELLPADDING=2 CELLSPACING=0>');
            document.write('<TR><TD bgcolor="' +bcolor+ '" class="bodytext">');
            docwritePlanListing(i, bcolor );
            document.write('</TD></TR><TR><TD colspan=3  bgcolor=#913C39 valign=center>');
            document.write('<TABLE Border=0 width=95% CELLPADDING=2 CELLSPACING=0>');
            document.write('<TR><TD valign=top><CENTER>');
            document.write('<input name=remitem type=button value="Remove from List" onClick="delFromWishList(' +j+ ');location.reload();">');
            document.write('</CENTER></TD></TR><TR><TD colspan=3>');

            document.write('<Font face=verdana size=1 color=#FFFFFF><HR align=center width=80% color=#FFFFFF><CENTER><Font size=2><B>Purchase Options</B></font><BR>');
            document.write('<INPUT TYPE=checkbox NAME="BSet' +j+ '">&nbsp;Builder&nbsp;Set&nbsp;($' +getPlanPrice( i, 1 )+ ')&nbsp;');
            document.write('<INPUT TYPE=checkbox NAME="VSet' +j+ '">&nbsp;Vellum&nbsp;Set&nbsp;($' +getPlanPrice( i, 2 )+ ')&nbsp;');
            document.write('<INPUT TYPE=checkbox NAME="SSet' +j+ '">&nbsp;Study&nbsp;Set&nbsp;($50)<BR>');
            document.write('</TD></TR><TR><TD colspan=3><Font face=verdana size=1 color=#FFFFFF>');

            document.write('<HR align=center width=80% color=#FFFFFF><CENTER><Font size=2><B>Plans Modifications</B></font><BR>');
            document.write('<INPUT TYPE=checkbox NAME="RevSet' +j+ '">&nbsp;Reverse&nbsp;Plan&nbsp;(+$150)&nbsp;&nbsp;<INPUT TYPE=checkbox NAME="t2x6' +j+ '">&nbsp;2X6&nbsp;Exterior&nbsp;Walls&nbsp;(+$150)&nbsp;');
            document.write('<INPUT TYPE=checkbox NAME="Brick' +j+ '">&nbsp;Brick&nbsp;Veneer&nbsp;(+$200)<BR>');
            document.write('<INPUT TYPE=checkbox NAME="Garage' +j+ '">&nbsp;Garage&nbsp;Alterations&nbsp;(+$100)&nbsp;');
            document.write('<INPUT TYPE=checkbox NAME="Basement' +j+ '">&nbsp;Basement&nbsp;Plan&nbsp;&nbsp;(+$200)<BR>');
            document.write('<INPUT TYPE=checkbox NAME="Slab' +j+ '">&nbsp;Slab&nbsp;Foundation&nbsp;Plan&nbsp;(+150)&nbsp;');
            document.write('<INPUT TYPE=checkbox NAME="Ceiling' +j+ '">&nbsp;Ceiling&nbsp;Heights&nbsp;changed&nbsp;(+$125)&nbsp;');
            document.write('</TD></TR>');
            document.write('</TABLE>');
            document.write('</TD></TR>');
            document.write('</TABLE><P>');
          }
        }
      }
      else
      {
        document.write('<P><CENTER><TABLE Border=0 CELLPADDING=4 CELLSPACING=0 WIDTH=90%>');
        document.write('<TR><TD bgcolor=#E1D9CA><center><TABLE Border=0 width=98% CELLPADDING=0 CELLSPACING=0><TR><TD>');
        document.write("<Font face=verdana size=2 color=#000000><CENTER><B>Your wish list is empty!</B></CENTER>");
        document.write('</TD></TR>');
      }
      document.write('</TABLE></TD></TR></TABLE>');
      if( numWishes )
        document.write('<CENTER><P><A HREF="HU-CheckOut.htm" onClick="preparePurchaseOrder();"><img src="images/HU-OrderButton.gif" border=0></A></CENTER>');

}

//*****************************
function preparePurchaseOrder()
//*****************************
{
  var i;
  var checks;
  var setType = 0;

  for( i=0; i<numWishes; i++ )
  {
    checks = 0;
    parent.orderOptions[i] = new Array(12);
    parent.orderOptions[i][0] = parent.wishList[i];

    if(eval("document.WishListForm.BSet" +i+ ".checked"))
    {
      parent.orderOptions[i][1] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][1] = 0;

    if(eval("document.WishListForm.VSet" +i+ ".checked"))
    {
      parent.orderOptions[i][2] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][2] = 0;

    if(eval("document.WishListForm.SSet" +i+ ".checked"))
    {
      parent.orderOptions[i][3] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][3] = 0;

    if(eval("document.WishListForm.RevSet" +i+ ".checked"))
    {
      parent.orderOptions[i][4] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][4] = 0;

    if(eval("document.WishListForm.t2x6" +i+ ".checked"))
    {
      parent.orderOptions[i][5] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][5] = 0;

    if(eval("document.WishListForm.Brick" +i+ ".checked"))
    {
      parent.orderOptions[i][6] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][6] = 0;

    if(eval("document.WishListForm.Garage" +i+ ".checked"))
    {
      parent.orderOptions[i][7] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][7] = 0;

    if(eval("document.WishListForm.Basement" +i+ ".checked"))
    {
      parent.orderOptions[i][8] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][8] = 0;

    if(eval("document.WishListForm.Slab" +i+ ".checked"))
    {
      parent.orderOptions[i][9] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][9] = 0;

    if(eval("document.WishListForm.Ceiling" +i+ ".checked"))
    {
      parent.orderOptions[i][10] = 1;
      checks++;
    }
    else
      parent.orderOptions[i][10] = 0;

    parent.orderOptions[i][11] = checks;
//alert(parent.orderOptions[i]);
  }
}

//*****************************
function docwriteCheckoutForm()
//*****************************
{
  document.write('<CENTER><TABLE Border=1 CELLPADDING=1 CELLSPACING=1 WIDTH=90%><TR><TD bgcolor=#913C39><center>');
  document.write('<TABLE Border=1 CELLPADDING=2 CELLSPACING=0 WIDTH=99%><TR><TD bgcolor=#E1D9CA><center>');
  document.write('<TABLE BORDER=0><TR><TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>Name: </TH>');
  document.write('<TD><INPUT TYPE=TEXT NAME="Name" SIZE=40><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>E-Mail: </TH>');
  document.write('<TD><INPUT TYPE=TEXT NAME="email" SIZE=40><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>Company: </TH>');
  document.write('<TD><INPUT TYPE=TEXT NAME="Company" SIZE=40><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>Street Address: </TH>');
  document.write('<TD><INPUT TYPE=text NAME="Street" SIZE=40><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>City, State, Zip: </TH>');
  document.write('<TD><INPUT TYPE=TEXT NAME="City" SIZE=20>, <INPUT TYPE=TEXT NAME="state" SIZE=2 MAXLENGTH=2>');
  document.write(' <INPUT TYPE=TEXT NAME="Zip" SIZE=10 MAXLENGTH=10><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>Phone: </TH>');
  document.write('<TD><INPUT TYPE=TEXT NAME="Phone" SIZE=12 MAXLENGTH=12><BR></TD></TR><TR>');
  document.write('<TH ALIGN=LEFT><Font face=verdana size=2 color=#000000>Comments: </TH>');
  document.write('<TD><textarea COLS=40 ROWS=4 NAME="Comments"></textarea><BR></TD></TR><TR>');
  document.write('<TH COLSPAN=2><INPUT TYPE=SUBMIT VALUE="Submit"> <INPUT TYPE=RESET><BR></TH></TR></TABLE>');
  document.write('</TD></TR></TABLE></TD></TR></TABLE></CENTER>');
}

//***********************************************
function docwritePlanListing( planNum, bcolor )
//***********************************************
{
    var SQ = "'";

        //plan thumbnail
        document.write('<TR><TD bgcolor="' +bcolor+ '" class="bodytext"  width=200>');
        document.write('<A HREF="HU-PlanPage.htm" target=HU_Frame onClick="putCookieVar(' +SQ+ 'PLANVIEW' +SQ+ ',' +planNum+ ' );"' );
        document.write('><img src="plans/' +parent.baseFileName[planNum]+ '.thumb.jpg" border=0></TD>');

        //plan name
        document.write('<TD bgcolor="' +bcolor+ '" class="bodytext"><CENTER>');
        document.write('<A HREF="HU-PlanPage.htm" target=HU_Frame onClick="putCookieVar(' +SQ+ 'PLANVIEW' +SQ+ ',' +planNum+ ' );"' );
        document.write('<B>Plan: ' +parent.modelName[planNum]+ '</B></A><BR><BR>');

        //plan number
        document.write('<A HREF="HU-PlanPage.htm" target=HU_Frame onClick="putCookieVar(' +SQ+ 'PLANVIEW' +SQ+ ',' +planNum+ ' );"');
        document.write( '>Plan No: ' +getModelNumber(planNum)+ '</A><BR><BR>');

        // plan price code
        //document.write('Price Code: <A HREF="HU-StockPricing.htm" target=HU_Frame>' +parent.priceCode[planNum]+ '</A>');
        document.write('Price Code: <A HREF="HU-PriceWindow.htm" onclick="NewWindow(this.href,' +SQ+SQ+ ',' +SQ+ '440' +SQ+ ','+SQ+'460'+SQ+','+SQ+'no'+SQ+');return false;">' +parent.priceCode[planNum]+ '</A>');
        document.write('</TD><TD bgcolor="' +bcolor+ '" class="bodytext"><CENTER>');

        //sq ft, story #, bedroom #, bath#
        document.write(commaformat(parent.sqFootage[planNum])+ ' heated sq.ft.<BR> Stories: ' +parent.numFloors[planNum]+ '<BR>Bedrooms: ' +parent.numBed[planNum]+ '<BR> Baths: ' +parent.numBath[planNum]+ '<BR>');

        //bonus room
        //if( parent.bonusRoom[planNum] > 0 )
          //document.write('Bonus Room: ' +parent.bonusRoom[planNum]+ 'sq.ft.<BR>');

        //garage
        //if( parent.garage[planNum] > 0 )
          //document.write( 'Garage: ' +parent.garage[planNum]+ 'sq.ft.<BR>');

        //dimensions
        document.write( parent.hLength[planNum]+ SQ+ 'W X ' +parent.hDepth[planNum] +SQ+ 'D' );
}

function NewWindow(mypage, myname, w, h, scroll)
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4)
  { win.window.focus(); }
}

function formReset()
{
  document.PlanSearch.reset();
  document.PlanTypeForm.reset();
  document.numBedsForm.reset();
  document.masterUpForm.reset();
  document.bonusRoomForm.reset();
  document.splitForm.reset();
  document.sfForm.reset();
  document.styleForm.reset();
  document.ExtDimForm.reset();
  document.garageForm.reset();
}