<!--

//DEFAULT POPUP
var common = null;
function popUpCommon(url,parameters) {
  common = window.open(url,'definePopUp',parameters);
}
//DEFAULT POPUP
var commonstay = null;
function popUpCommonStay(url,parameters) {
  commonstay = window.open(url,'fullPopUp',parameters);
}
function obliterate() {
  if (common != null && common.open) common.close();
}
window.onfocus=obliterate;

// HOMES LISTING IMAGE POPUP
function PopupPic(sPicURL) { 
   window.open("/homes/img_popup.aspx?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200,location=0");
}
function fitPic() {
   iWidth = (NS)?window.innerWidth:document.body.clientWidth;
   iHeight = (NS)?window.innerHeight:document.body.clientHeight;
   iWidth = document.images[0].width - iWidth;
   iHeight = document.images[0].height - iHeight;
   window.resizeBy(iWidth, iHeight-1);
   self.focus();
};
//AUTOS ENLARGE IMAGE POPUP
var autosEnlange = null;
function popUpAutosEnlange(url) {
  autosEnlange = window.open(url,'imageWindow','width=425,height=293,scrollbars=no,resizable=yes,toolbar=no,left=50,top=50');
}


//AUTOS MORE POPUP
var More = null;
function openWindow(url) {
  More = window.open(url,'imageWindow','width=365,height=170,scrollbars=yes,resizable=yes,toolbar=no,left=50,top=50');
}


//RESOURCES CALCULATOR POPUPS
var Calculator = null;
function popUpCalculator(url) {
  Calculator = window.open(url,'imageWindow','width=620,height=399,scrollbars=no,resizable=yes,toolbar=no,left=50,top=50');
}


//MYBARGAINS SAVED ITEMS POPUP
var savedItems = null;
function popUpSavedItems(url) {
  savedItems = window.open(url,'detailsWindow','width=750,height=400,scrollbars=yes,resizable=yes,toolbar=no,left=50,top=50');
}


//HOMES DETAILS IMAGE POPUP
var detailsImage = null;
function popUpSDetailsImage(url) {
  detailsImage = window.open(url,'imageWindow','width=475,height=330,scrollbars=yes,resizable=yes,toolbar=no,left=50,top=50');
}

function openZipWindow(strField) {
   popupWin = window.open('/fe/zipPopup.aspx?ZipFieldName='+strField, 'remote', 'status,scrollbars=0,width=435,height=185,left=30,top=30')
}

//TAB SWITCHING
function switchtabs(activateThisTab, color){
   var nameArray = new Array();
   doSwitch(activateThisTab, color);
   //IE Fix, as IE still looks for IDs when using getElementsByName
   function getElementsByName_iefix(tag, name) {    
      var elem = document.getElementsByTagName(tag);
      for(i = 0,iarr = 0; i < elem.length; i++) {
         att = elem[i].getAttribute("name");
         attID = elem[i].getAttribute("id");
         if(att == name) {       
            nameArray[iarr] = attID;
            iarr++;//REMOVE
         }          
      }   
   }     
   function doSwitch(activateThisTab, color){
      //set all tabs to inactiveTab class
       var alltabs = document.getElementsByName("tab");
       for(var i=0; i<alltabs.length; i++){
         alltabs[i].className = "inactiveTab";       
      }  
      //IE Way to deactivate contents  
      getElementsByName_iefix("li", "tab");  
      for(i = 0; i < nameArray.length; i++){ 
      //pull out using substr into new array
         var tabId = document.getElementById(nameArray[i]);
         tabId.className = "inactiveTab";
      }
      //find the tab to activate and assign it the class for its color specified in the onclick event
      document.getElementById(activateThisTab).className = "activeTab " + color + "Tab";
      //set all content panels to inactive class
      var alltabbedContentPanels = document.getElementsByName("tabbedContentPanel");
      for (var i=0; i < alltabbedContentPanels.length; i++){
         alltabbedContentPanels[i].className = "inactiveTabbedContentPanel";
      }  
      //IE way to set all content panels to inactive class
      getElementsByName_iefix("div", "tabbedContentPanel"); 
      for(i = 0; i < nameArray.length; i++){ 
         var tabbedContentId = document.getElementById(nameArray[i]);
         tabbedContentId.className = "inactiveTabbedContentPanel";
      }  
      //find the number of the contentpanel and show it
      whichContentPanel = activateThisTab.charAt(3);
      document.getElementById("tabbedContentPanel" + whichContentPanel).className = "activeTabbedContentPanel";   
   }
}
   
//ROLLOVERS FOR NAVIGATION
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//TRAP ENTER FUNCTIONS
function TrapEnterButtonLookup(btnName)
{
   var button = null;

   //-Which browser are we using?-
   if (document.all)                 //IE
   {
      button = document.all[btnName];
   }
   else if (document.getElementById) //Mozilla
   {
      button = document.getElementById(btnName);
   }

   //-Do the trap?-
   if (button != null)
   {
      TrapEnter(button);
   }
   else
   {
      return !(window.event && window.event.keyCode == 13);
   }
}

//TRAP ENTER FUNCTIONS -- Firefox
function TrapEnterButtonLookupFF(btnName, evt)
{
   var button = null;

   //-Which browser are we using?-
   if (document.all)                 //IE
   {
      button = document.all[btnName];
   }
   else if (document.getElementById) //Mozilla
   {
      button = document.getElementById(btnName);
   }

   //-Do the trap?-
   if (button != null)
   {
      TrapEnterFF(button, evt);
   }
   else
   {
      return !(window.event && window.event.keyCode == 13);
   }
}

function TrapEnterFF(btn, e) {
if(window.event) // IE
  {
  if (window.event.keyCode == 13) 
  {
    window.event.returnValue= false;
   window.event.cancel = true;
   btn.click();
}
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  if (e.which == 13)
   {
   e.returnValue=false;
   e.cancel = true;
   btn.click();
   }
  }
 }
 


function TrapEnter(btn) {
  if (event.keyCode == 13) {
    event.returnValue=false;
    event.cancel = true;      
    btn.click();
  }
}

//URL FOR BUTTONS
function MM_goToURL() {
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//BOOKMARK THIS PAGE
function addBookmark(title,url) {
   if (window.sidebar) { 
      window.sidebar.addPanel(title, url,""); 
   } else if( document.all ) {
      window.external.AddFavorite( url, title);
   } else if( window.opera && window.print ) {
      return true;
   }
}

//FROM RANDOMURL.JS
   // Set up the variables we need for the random URL selection using 4 arrays.

   var uc = 2;             // Number of URLs
   var u = new Array(uc);           // Array to hold URLs

   var uc1 = 2;               // Number of URLs
   var u1 = new Array(uc1);         // Array to hold URLs
   
   var uc2 = 2;               // Number of URLs
   var u2 = new Array(uc2);         // Array to hold URLs
   
   var uc3 = 2;               // Number of URLs
   var u3 = new Array(uc3);         // Array to hold URLs
   // point to URL
   
   
   // Pre-Qualify
   u[0] = "/fe/redirect.aspx?http%3A//service.bfast.com/bfast/click%3Fbfmid%3D115759%26sourceid%3D40662145%26categoryid%3Dmortgage_loans%26brand%3D40662145";
   u[1] = "/fe/redirect.aspx?http%3A//clk.atdmt.com/HLC/go/brgnchlc00300005hlc/direct/01/";
   
   // Get A Mortgage 
   u1[0] = "/fe/redirect.aspx?http%3A//service.bfast.com/bfast/click%3Fbfmid%3D115759%26sourceid%3D40662145%26categoryid%3Dmortgage_loans%26brand%3D40662145";
   u1[1] = "/fe/redirect.aspx?http%3A//clk.atdmt.com/HLC/go/brgnchlc00300006hlc/direct/01/";
   
   // Refinance
   u2[0] = "/fe/redirect.aspx?http%3A//service.bfast.com/bfast/click%3Fbfmid%3D115759%26sourceid%3D40662145%26categoryid%3Drefinance_loans%26brand%3D40662145";
   u2[1] = "/fe/redirect.aspx?http%3A//clk.atdmt.com/HLC/go/brgnchlc00300002hlc/direct/01/";
   
   // Home Equity Loan 
   u3[0] = "/fe/redirect.aspx?http%3A//service.bfast.com/bfast/click%3Fbfmid%3D115759%26sourceid%3D40662145%26categoryid%3Dhome_equity_loans%26brand%3D40662145";
   u3[1] = "/fe/redirect.aspx?http%3A//clk.atdmt.com/HLC/go/brgnchlc00300003hlc/direct/01/";


   // pickRandom - Return a random number in a given range. This
   // function is 'browser-proofed' to run correctly on older
   // browsers that don't implement 'Math.random'.
   
   function pickRandom(range) {
      if (Math.random)
         return Math.round(Math.random() * (range-1));
      else {
         var   now = new Date();
         return (now.getTime() / 1000) % range;
      }
   }

   // Function: pickRandomURL
   //
   // A very simple function that selects one of the URLs in the
   // 'u' array at random, and returns it as a string.

   function pickPreURL() {
      var choice = pickRandom(uc);
      return u[choice];
   }
   
   function pickMortgageURL() {
      var choice = pickRandom(uc1);
      return u1[choice];
   }
   
    function pickRefinanceURL() {
      var choice = pickRandom(uc2);
      return u2[choice];
   }
   
    function pickEquityURL() {
      var choice = pickRandom(uc3);
      return u3[choice];
   }

//ENHANCED STRING FUNCTIONS
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

//TODAYS DATE AND OTHER DATE RELATED FUNCTIONS

function Now() { // Global Now() function
   return new Date();
}

var JANUARY   = 0; // Global Constants
var FEBRUARY  = 1;
var MARCH     = 2;
var APRIL     = 3;
var MAY       = 4;
var JUNE      = 5;
var JULY      = 6;
var AUGUST    = 7;
var SEPTEMBER = 8;
var OCTOBER   = 9;
var NOVEMBER  = 10;
var DECEMBER  = 11;

// Conversion factors as varants to eliminate all the multiplication
var SECONDS_CF     = 1000;
var MINUTES_CF     = 60000;          // 60 * 1000
var HOURS_CF       = 3600000;        // 60 * 60 * 1000
var DAYS_CF        = 86400000;       // 24 * 60 * 60 * 1000
var WEEKS_CF       = 604800000;      // 7 * 24 * 60 * 60 * 1000
var FORTNIGHTS_CF  = 1209600000;     // 14 * 24 * 60 * 60 * 1000
var MONTHS_CF      = 2592000000;     // 30 * 24 * 60 * 60 * 1000  (approx = 1 month)
var QUARTERS_CF    = 7776000000;     // 90 * 24 * 60 * 60 * 1000  (approx = 3 months)
var YEARS_CF       = 31557600000;    // 365 * 24 * 60 * 60 * 1000 (approx = 1 year)
var DECADES_CF     = 315576000000;   // 10 * 365 * 24 * 60 * 60 * 1000 (approx = 1 decade)
var CENTURIES_CF   = 3155760000000;  // 100 * 365 * 24 * 60 * 60 * 1000 (approx = 1 century)


Date.prototype.addMilliseconds = function(ms) {  // Non-destructive instance methods
  return new Date(new Date().setTime(this.getTime() + (ms)));  
}
Date.prototype.addSeconds = function(s) {
  return this.addMilliseconds(s * SECONDS_CF);
}
Date.prototype.addMinutes = function(m) {
  return this.addMilliseconds(m * MINUTES_CF);
}
Date.prototype.addHours = function(h) {
  return this.addMilliseconds(h * HOURS_CF);
}
Date.prototype.addDays = function(d) {
  return this.addMilliseconds(d * DAYS_CF);  
}
Date.prototype.addWeeks = function(w) {
  return this.addMilliseconds(w * WEEKS_CF);  
}
Date.prototype.getMonthName = function() {
  var index = (0 == arguments.length) ? this.getMonth() : arguments[0];
  switch(index) {
    case JANUARY: 
      return "January";
    case FEBRUARY: 
      return "February";
    case MARCH: 
      return "March";
    case APRIL: 
      return "April";
    case MAY: 
      return "May";
    case JUNE: 
      return "June";
    case JULY: 
      return "July";
    case AUGUST: 
      return "August";
    case SEPTEMBER: 
      return "September";
    case OCTOBER: 
      return "October";
    case NOVEMBER: 
      return "November";
    case DECEMBER: 
      return "December";
    default:
      throw "Invalid month index: " + index.toString();
  }
}
Date.prototype.noon = function() {
  var dt = this.clone();
  dt.setHours(12);
  dt.setMinutes(0);
  dt.setSeconds(0);
  dt.setMilliseconds(0);
  return dt;
}
Date.prototype.clone = function() {
  var dt = new Date();
  dt.setTime(this.getTime());  
  return dt;
}
Date.nextWeek = function() {  
  return new Date().noon().addWeeks(1);
}

//FOR SUBMIT FEEDBACK TO BARGAIN ABOUT PROPERTY DETAIL LISTINGS (USED IN PROPERTY-DETAILS.APX
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)    //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)     //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)  // IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
function scrollToId(divId){
  window.scrollTo(0,320);
}
function activateError(szDivID) // 1 visible, 0 hidden
{
    if(document.layers)    //NN4+
    {
       document.layers[szDivID].className = "errorMessage";
    }
    else if(document.getElementById)     //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.className = "errorMessage";
    }
    else if(document.all)  // IE 4
    {
        document.all[szDivID].className = "errorMessage";
    }
}

//Expand & Collapse, as shown in Propert Reports
function expandCollapse(sId) {
   elem = document.getElementById(sId); 
   elem.style.display = (elem.style.display=='block'?'none':'block');
}

//used to show any element with an ID associated with it
function expandAll(sId) {
   elem = document.getElementById(sId); 
   if (!elem) {
        return false;
    }
    elem.style.display='block';
}

//used to hide any element with an ID associated with it
function collapseAll(sId) {
   elem = document.getElementById(sId);
   if (!elem) {
        return false;
    } 
   elem.style.display='none';
}

//ROLLOVERS FOR NAVIGATION
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//DROPDOWN MENU JUMP TO URL WITH BUTTON
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

//PROPERTY TYPE DETAILS TOOLTIPS
var theObj="";

function toolTip(text,me) {
theObj=me;
theObj.onmousemove=updatePos;
document.getElementById('toolTipBox').innerHTML=text;
document.getElementById('toolTipBox').style.visibility="visible";
window.onscroll=updatePos;
}

function updatePos() {
var ev=arguments[0]?arguments[0]:event;
var x=ev.clientX;
var y=ev.clientY;
diffX=-260;
diffY=-110;
document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop +"px";
document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
theObj.onmouseout=hideMe;
}
function hideMe() {
document.getElementById('toolTipBox').style.visibility="hidden";
}

// -->
//=============================================================================
// Function for Unica
//=============================================================================
function NormalizeURLHost(url)
{
   var hostToken = 'HOST_TOKEN';

   //---Remove port numbers after host name---
   var portPatt = /:\d{1,5}/;
   if (portPatt.test(url) == true)
      url = RegExp.leftContext + RegExp.rightContext;
   
   //---Replace with Temp Token---
   //Note: Order matters!
   url = url.replace('localhost', hostToken);
   url = url.replace('alpha.bargain.com', hostToken);
   url = url.replace('beta.bargain.com', hostToken);
   url = url.replace('www.bargain.com', hostToken); //Necessary
   url = url.replace('bargain.com', hostToken);
   
   //---Use Standard Host---
   url =  url.replace(hostToken, 'www.bargain.com');
   
   //---Special Case: Requested by Deborah---
   if (url == 'http://www.bargain.com/')
      url += 'default.aspx';

   return url;
}

//=============================================================================
// Functions for Default Page
//=============================================================================
function DefaultIsAol()
{
	document.write('<div style="position: absolute; left: 100%; top: 0px; overflow: visible; height: 92px; width: 118px; margin: 0 0 0 -118px; padding: 0; z-index: 9999; border: none; float: none;"><img src="/images/corner_free_trial-v2.gif" width="118" height="92" border="0" usemap="#rc"></div><map name="rc"><area shape="poly" alt="Free Trial Click Here" coords="1,0, 1,11, 5,27, 13,39, 25,53, 42,64, 57,68, 82,68, 82,0" href="/account/homes/registration.aspx" /></map>');
} 

function DefaultNotAol()
{
	document.write('<div style="position: absolute; left: 100%; top: 0px; overflow: visible; height: 92px; width: 118px; margin: 0 0 0 -118px; padding: 0; z-index: 9999; border: none; float: none;"><img src="/images/corner_free_trial-v2.gif" width="118" height="92" border="0" usemap="#rc"></div><map name="rc"><area shape="poly" alt="Free Trial Click Here" coords="1,0, 1,11, 5,27, 13,39, 25,53, 42,64, 57,68, 82,68, 82,0" href="/account/homes/registration.aspx?AID=pr_h963i" /></map>');
}