//=====================================================================||
//               CBC RealEstate General Include                        ||
//                                                                     ||
// This JS should be included on all CBC.com pages, and contains only  ||
// shared functions that may be called from most any page.             ||
//                                                                     ||
// Portions of this script are used with permission from the NOP Design||
// Free-Shopping Cart, located at http://www.nopdesign.com/freecart    ||
//                                                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
// GLOBAL VARIABLES                                                    ||
//---------------------------------------------------------------------||
var g_strRedirectLegalDisclaimer = "You have selected a link to a website that is not owned or maintained by Coldwell Banker Real Estate Corporation.  Different terms of use and privacy policies will apply.";

//g_CbcTabImages[<tab name>][<off|on>]
g_CbcTabImages = new Array();
g_CbcTabImages['off'] = new Array();
g_CbcTabImages['on']  = new Array();

g_CbcTabImages['off']['tabhome']        = 'images/tabhome.gif';
g_CbcTabImages['off']['tabprofessionals'] = 'images/tabprofessionals.gif';
g_CbcTabImages['off']['tabsearchprop']  = 'images/tabsearchprop.gif';
g_CbcTabImages['off']['tabservices']    = 'images/tabservices.gif';
g_CbcTabImages['off']['tabmarketintel'] = 'images/tabmarketintel.gif';
g_CbcTabImages['off']['tabnews']        = 'images/tabnews.gif';
g_CbcTabImages['off']['tababoutus']     = 'images/tababoutus.gif';

g_CbcTabImages['on']['tabhome']         = 'images/tabhome_on.gif';
g_CbcTabImages['on']['tabprofessionals']  = 'images/tabprofessionals_on.gif';
g_CbcTabImages['on']['tabsearchprop']   = 'images/tabsearchprop_on.gif';
g_CbcTabImages['on']['tabservices']     = 'images/tabservices_on.gif';
g_CbcTabImages['on']['tabmarketintel']  = 'images/tabmarketintel_on.gif';
g_CbcTabImages['on']['tabnews']         = 'images/tabnews_on.gif';
g_CbcTabImages['on']['tababoutus']      = 'images/tababoutus_on.gif';

//---------------------------------------------------------------------||
// FUNCTION:    CbcTab                                                 ||
// PARAMETERS:  Tab name to highlight (must have image defined with    ||
//              this name), boolean highlight = true                   ||
// RETURNS:     Does not return                                        ||
// PURPOSE:     Highlights or dulls a specific tab                     ||
//---------------------------------------------------------------------||
function CbcTab(strTab, bHighlight)
{
   if( document.images ) {
      var pThisImage = eval( 'document.images.' + strTab );         
      if( pThisImage ) {
         if( bHighlight ) {
            if( g_CbcTabImages['on'][strTab] ){
               pThisImage.src = g_CbcTabImages['on'][strTab];
            }
         } else {
            if( g_CbcTabImages['off'][strTab] ){
               pThisImage.src = g_CbcTabImages['off'][strTab];
            }
         }
      }
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    PreLoadCbcImages                                       ||
// PARAMETERS:  None                                                   ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Loads CBC header images into browser cache             ||
//---------------------------------------------------------------------||
function PreLoadCbcImages()
{
   if( document.images ) {
      var pOffArray = g_CbcTabImages['off'];
      var pOnArray = g_CbcTabImages['on'];
      var pElement = null;

      for( pElement in pOffArray ) {
         g_pImageTmp = new Image();
         g_pImageTmp.src = pOffArray[pElement];
      }
      for( pElement in pOnArray ) {
         g_pImageTmp = new Image();
         g_pImageTmp.src = pOffArray[pElement];
      }
   }
}



//---------------------------------------------------------------------||
// FUNCTION:    ImgQuickSwap                                           ||
// PARAMETERS:  N/A                                                    ||
// RETURNS:     True if photo could NOT be swapped                     ||
// PURPOSE:     Swaps out photo without forcing page load.             ||
//---------------------------------------------------------------------||
function CbcImgQuickSwap( pPhotoToSwap, strNewPhoto, strCaption, strLargeFileUrl ) 
{
   var bReturn = true;

   if( !pPhotoToSwap ) return;

   if ( pPhotoToSwap ) {
      if ( pPhotoToSwap.src ) {
         pPhotoToSwap.src = strNewPhoto;
         bReturn = false;
      }
      if ( strLargeFileUrl ) {
         pPhotoToSwap.largephotourl = strLargeFileUrl; 
      }
   }

   if( document.getElementById ) {
      var pCaption = document.getElementById('photocaption');
      if( pCaption ) {
         pCaption.innerHTML = strCaption;
      }
   }
   return bReturn;
}