function largePreview(anchorId) {
	var pxTop = $("#"+anchorId).offset().top - 130;
	$("#popup_largePreview").css("top",pxTop+"px");
	$("#popup_largePreview").css("display","block");
	$("#popup_largePreview").attr("src",$("#"+anchorId).attr("src"));
  $("#popup_largePreviewX").css("top", ($("#popup_largePreview").offset().top - 23) + "px");
	$("#popup_largePreviewX").css("left", ($("#popup_largePreview").offset().left + 630) + "px");
	$("#popup_largePreviewX").css("display", "");
	$("#popup_largePreviewX").css("z-index", "999");
}
function showBidHistory(listingId) {
var bh=AJAX("get","/"+listingId+"/getBidHistory.htm","","text/html");
var popHTML = "<div id=\"bidHistoryPopup\" style=\"position:absolute;top:110px;width:395px;left:550px;background-color:white;\"><div class=\"popHeader2\" style=\"width:380px;\"><input type=\"button\" class=\"popClose\" onclick=\"javascript:closeBidHistory();\" value=\"\" /></div>";
popHTML += "<div class=\"popArea\"><div class=\"popTitle\">Bid History</div><table cellspacing=\"0\"><tr><th>Date</th><th>Screen Name</th><th>Amount</th></tr>"+bh+"</table></div>";
$("#showBidHistory").append(popHTML);
}
function closeBidHistory() {$("#bidHistoryPopup").remove();}
function autoPopup() {
pageAutoPopup = true;
var sURL = document.location.href;sURL = sURL.toLowerCase();
if (sURL.indexOf("autopopup=bid") > 0) {placeOfferFrame(listingId);}
if (sURL.indexOf("autopopup=buyitnow") > 0) {buyItNow(listingId);}
if (sURL.indexOf("autopopup=openhouse") > 0) {showOpenHouse();}
if (sURL.indexOf("autopopup=askq") > 0) {detailsAskQuestion('askQuestion',propertyId,listingId);}
if (sURL.indexOf("autopopup=watchlisting") > 0) {detailsWatchListing('watchListing',propertyId,listingId);}
pageAutoPopup = false;
}
function resultsView(layout) {
var sURL = document.location.href;
if (sURL.indexOf("search-results.htm") > 0) {document.location.href=sURL.replace("search-results.htm",layout+"-results.htm");}
if (sURL.indexOf("photo-results.htm") > 0) {document.location.href=sURL.replace("photo-results.htm",layout+"-results.htm");}
if (sURL.indexOf("map-results.htm") > 0) {document.location.href=sURL.replace("map-results.htm",layout+"-results.htm");}
	trackEvent("Page Layout", layout.toProperCase().replace("Search", "List"));
}
function sendAgentEmail() {
	var agentEmail = $("#agentEmail").val();
	var agentName = $("#agentName").val();
	var listingId = $("#listingId").val();
	var leadFirstName = $("#leadFirstName").val();
	var leadLastName = $("#leadLastName").val();
	var leadName = $("#leadFirstName").val() + " " + $("#leadLastName").val();
	var leadEmail = $("#leadEmail").val();
	var leadPhone = $("#leadPhone").val();
	var leadSubject = $("#leadSubject").val();
	var leadMessage = $("#leadMessage").val();
	var leadType = $("#leadType").val();
	var leadPaymentType = $("#leadPaymentType").val();
	var message = "The following lead was submitted on GoHoming.com (or an Affiliate Web Site) related to one of your properties:||";
	message += "Listing Id: "+listingId+"|Name: "+leadName+"|Email: "+leadEmail+"|Phone: "+leadPhone+"|Message: "+leadMessage;
	message += "||Our Best,|GoHoming.com|http://www.gohoming.com||";
	var uriParam = "agentEmail="+agentEmail+"&agentName="+agentName+"&leadName="+leadName+"&leadEmail="+leadEmail+"&leadSubject="+leadSubject+"&leadMessage="+message;
	if (leadFirstName == "" || leadLastName == "" || leadEmail == "" || leadPhone == "" || leadMessage == "" || leadType == "0" || leadPaymentType == "0") {
		alert("All Fields Required");
	} else {
		var tmpAJAX = AJAX("GET", "/"+listingId+"/emailLead.htm?"+uriParam, "", "");
		if (tmpAJAX == "true") {
			$("#emailAgentArea").html("<br/>Your message was sent directly to the property listing agent and a copy has also been sent to you at "+leadEmail+".<br/><br/>You should hear back shortly.<br/><br/>Feel free to search for more properties.");
			var tmpLEAD = AJAX("GET", "/"+listingId+"/saveLead.htm?"+uriParam, "", "");
		} else {
			alert(tmpAJAX);
		}
	}
	return false;
}
function setSearchResultsFields() {
  $("#currentRefinements").html("");addCityCurrentRefinement();addZipCurrentRefinement();
  $.each($.query.get(), function(key, val) { if (key != "sortOrder") {setCurrentRefinements(key, val); }});
  if ($("#currentRefinements").html() == "") { $("#currentRefinementBox").css("display", "none"); }
  if ($("#availableRefinement").html() == "") { $("#availableRefinementBox").css("display", "none"); }
  var tmpStr = freeTextVal();
  if (!isNaN(tmpStr) || tmpStr.indexOf(",") > 0) { $("#zipCityStateInput").val(tmpStr.replace(/%20/g, " ")); }
	currentSort = $.query.get("sortfield");
	currentSortDirection = $.query.get("orderbydirection");
	if (currentSort.toUpperCase() == "SORTPRICE") {
		if (currentSortDirection.toUpperCase() == "ASC") {$("#currentBidSort").css("background","url('/images/sr-sort-ASC.png') bottom right no-repeat");}
		if (currentSortDirection.toUpperCase() == "DESC") {$("#currentBidSort").css("background","url('/images/sr-sort-DESC.png') bottom right no-repeat");}
	}
	if (currentSort.toUpperCase() == "TIMEREMAINING") {
		if (currentSortDirection.toUpperCase() == "ASC") {$("#timeRemainingSort").css("background","url('/images/sr-sort-ASC.png') bottom right no-repeat");}
		if (currentSortDirection.toUpperCase() == "DESC") {$("#timeRemainingSort").css("background","url('/images/sr-sort-DESC.png') bottom right no-repeat");}
	}
}
function refinementsAddMoreLink() {
	$("#availableRefinement").children().each(function(i) {
	  if ($(this).html() == "City") {
	    var itemCount = 1;
	    $(this).next("div").children().each(function(i) {
	      if (itemCount > 6) {
	          $(this).css("display", "none");
	      }
	      itemCount++;
	    });
	    if (itemCount > 6) {
	      $(this).next("div").append("<a id=\"showMoreCities\" href=\"javascript:refinementsShowMoreCities();\">Show More Cities...</a>");
	    }
	  }
	  if ($(this).html() == "County") {
	    var itemCount = 1;
	    $(this).next("div").children().each(function(i) {
	      if (itemCount > 6) {
	          $(this).css("display", "none");
	      }
	      itemCount++;
	    });
	    if (itemCount > 6) {
	      $(this).next("div").append("<a id=\"showMoreCounties\" href=\"javascript:refinementsShowMoreCounties();\">Show More Counties...</a>");
	    }
			$(this).css("display", "none");
			$(this).next("div").css("display", "none");
	  }
	  if ($(this).html() == "Agent") {
	    var itemCount = 1;
	    $(this).next("div").children().each(function(i) {
	      if (itemCount > 6) {
	          $(this).css("display", "none");
	      }
	      itemCount++;
	    });
	    if (itemCount > 6) {
	      $(this).next("div").append("<a id=\"showMoreAgents\" href=\"javascript:refinementsShowMoreAgents();\">Show More Agents...</a>");
	    }
			$(this).css("display", "none");
			$(this).next("div").css("display", "none");
	  }
	});
}
function formatRange(sRange) {var range = sRange.split("-");return formatNumber(range[0])+"-"+formatNumber(range[1]);}
function refinementsShowMoreCities() { $("#A1").next("div").children().each(function(i) { $(this).css("display", "block"); }); $("#showMoreCities").remove(); }
function refinementsShowMoreCounties() { $("#A2").next("div").children().each(function(i) { $(this).css("display", "block"); }); $("#showMoreCounties").remove(); }
function refinementsShowMoreAgents() { $("#A3").next("div").children().each(function(i) { $(this).css("display", "block"); }); $("#showMoreAgents").remove(); }
function setCurrentRefinements(key, value) {try {var keyDisplay = refinementLabel(key);var valDisplay = value; if (key=="squareFeetRange") {valDisplay=formatRange(value);} if (valDisplay=="AUCN") {valDisplay="Time Limit Offer";} if (valDisplay=="TRNL") {valDisplay="No Limit-Best Offer";} if (keyDisplay != "") {if (key == "agent") {var tmpAJAX = AJAX("GET", "/" + value + "/" + "/getAgent.htm?statecode=", "", "");valDisplay = tmpAJAX;}if (key == "maxPrice") {valDisplay="$"+addCommas(valDisplay);}if (key == "minPrice") {valDisplay="$"+addCommas(valDisplay);}$("#currentRefinements").html($("#currentRefinements").html() + "<a href=\"javascript:removeRefinement('" + key + "');\"><strong>" + keyDisplay + ":</strong> " + valDisplay.toString().replace(/\+/g," ") + "</a>");}} catch (e) { }}
function addCityCurrentRefinement() {var sURL = document.location.href.replace("http://", "");if (sURL.indexOf("?") > 0) { sURL = sURL.split("?"); sURL = sURL[0].split("/"); } else { sURL = sURL.split("/"); }var cityVal = "";if (sURL[2].indexOf(".htm") == -1) { cityVal = sURL[2].replace(/%20/g, " "); }if (cityVal != "") {$("#currentRefinements").html($("#currentRefinements").html() + "<a href=\"javascript:removeCityRefinement();\"><strong>City:</strong> " + cityVal + "</a>");}}
function addZipCurrentRefinement() {var sURL = document.location.href.replace("http://", "");if (sURL.indexOf("?") > 0) { sURL = sURL.split("?"); sURL = sURL[0].split("/"); } else { sURL = sURL.split("/"); }var zipVal = "";if (sURL.length > 3) {if (sURL[3].indexOf(".htm") == -1) { zipVal = sURL[3].replace(/%20/g, " "); }if (zipVal != "") {$("#currentRefinements").html($("#currentRefinements").html() + "<a href=\"javascript:removeZipRefinement();\"><strong>Zip Code:</strong> " + zipVal + "</a>");}}}
function getCityCurrentRefinement() {var sURL = document.location.href.replace("http://", "");if (sURL.indexOf("?") > 0) { sURL = sURL.split("?"); sURL = sURL[0].split("/"); } else { sURL = sURL.split("/"); }var cityVal = "";if (sURL[2].indexOf(".htm") == -1) { cityVal = sURL[2].replace(/%20/g, " "); }return cityVal;}
function getZipCurrentRefinement() {var sURL = document.location.href.replace("http://", "");if (sURL.indexOf("?") > 0) { sURL = sURL.split("?"); sURL = sURL[0].split("/"); } else { sURL = sURL.split("/"); }var zipVal = "";if (sURL.length > 3) {if (sURL[3].indexOf(".htm") == -1) { zipVal = sURL[3].replace(/%20/g, " "); }}return zipVal;}
function removeCityRefinement() {var sURL=document.location.href.replace("http://", "");sURL = sURL.split("/");if (sURL[3].indexOf(".htm") > 0) {newURL = "http://" + sURL[0] + "/" + sURL[1] + "/" +sURL[3];} else {newURL = "http://" + sURL[0] + "/" + sURL[1] + "/" +sURL[4];}document.location.href = newURL;}
function removeZipRefinement() {var sURL=document.location.href.replace("http://","");sURL=sURL.split("/");newURL="http://"+sURL[0]+ "/"+sURL[1]+"/"+sURL[2]+"/"+sURL[4];document.location.href=newURL;}
function removeRefinement(key) {var sURL=document.location.href;sURL=sURL.split("/");
  if (key == "city") {
      var tmpURL = "";
      if (sURL[4].indexOf(".htm?") > 0) {
          tmpURL = sURL[0] + "/" + sURL[1] + "/" + sURL[2] + "/" + sURL[3] + "/" + sURL[4];
      } else {
          tmpURL = sURL[0] + "/" + sURL[1] + "/" + sURL[2] + "/" + sURL[3] + "/" + sURL[5];
      }
      document.location.href = tmpURL;
  } else {document.location.href=$.query.remove(key).set("pagenumber", "1");}
}
function changeSort() {
	trackEvent("Sort Properties", $("#sortBy").val());
	document.location.href=$.query.set("sortOrder",$("#sortBy").val()).set("pagenumber", "1");
}
function toggleSort(newSort) {
	currentSort = $.query.get("sortfield");
	currentSortDirection = $.query.get("orderbydirection");
	if (currentSortDirection.toUpperCase() == "DESC" || currentSortDirection == "") {currentSortDirection = "ASC";} else {currentSortDirection = "DESC";}
	if (newSort.toUpperCase() == "CURRENTBID") {currentSort = "sortPrice";}
	if (newSort.toUpperCase() == "TIMEREMAINING") {currentSort = "timeRemaining";}
	trackEvent("Sort Properties", currentSort);
	document.location.href=$.query.set("sortfield",currentSort).set("orderbydirection",currentSortDirection).set("pagenumber", "1");
}
function addRefinement(sKey, sValue) {
  if (sKey == "city") {
    var sQUERY = $.query.set("pagenumber", "1");
    var sURL = document.location.href;
    sURL = sURL.split("/");
	  if (sURL[4].indexOf(".htm?") > 0) {
	      sQUERY = sURL[4].substring(0,sURL[4].indexOf("?")) + sQUERY;
    } else if (sURL[4].indexOf(".htm") > 0) {
        sQUERY = sURL[4].substring(0,sURL[4].indexOf(".htm")+4) + sQUERY;
	  } else if (sURL[5].indexOf(".htm?") > 0) {
	      sQUERY = sURL[5].substring(0,sURL[5].indexOf("?")) + sQUERY;
	  } else if (sURL[5].indexOf(".htm") > 0) {
        sQUERY = sURL[5].substring(0,sURL[5].indexOf(".htm")+4) + sQUERY;
		}
    document.location.href = sURL[0] + "/" + sURL[1] + "/" + sURL[2] + "/" + sURL[3] + "/" + sValue + "/" + sQUERY;
  } else {
			var isOk = true;var errorTxt = "";
			if (sKey == "squareFeetRange") {sValue = sValue.replace(/,/g,"");}
			if (sKey == "minPrice") {
				var tmpVal = $.query.get("maxPrice");
				if (tmpVal != "") {if (tmpVal < sValue) {isOk = false;errorTxt = "Minimum Price must be less than Maximum Price.";}				}
			}
			if (sKey == "maxPrice") {
				var tmpVal = $.query.get("minPrice");
				if (tmpVal != "") {if (tmpVal > sValue) {isOk = false;errorTxt = "Minimum Price must be less than Maximum Price.";}				}
			}
			if (isOk) {document.location.href = $.query.set(sKey, sValue).set("pagenumber", "1");} else {alert(errorTxt);}
  }
}
function srTypeInfoPopup(anchorId, contentId) {
	var top = $("#"+anchorId).offset().top + 20;
	$("#"+contentId).css("top",top+"px");
	$("#"+contentId).css("display","block");
}
function srTypeInfoHide(contentId) {$("#"+contentId).css("display", "none");}
function sellerInfoCall() { $("#sellerInfoCall").css("display", "block");trackEvent("Call"); }
function sellerInfoEmail() { $("#sellerInfoEmail").css("display", "block");trackEvent("Email"); }
function sellerInfoFax() { $("#sellerInfoFax").css("display", "block");trackEvent("Fax"); }
function placeOfferFrame(listingId) {showPopupFrame(590,900,30,30);autoRefresh=true;$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"placeBid.action?domain="+baseDomain+"&listingId="+listingId+"&bidType=PlaceBid&refUrl="+escape(document.location.href)+"?autopopup=bid"));trackEvent("Bid");}
function buyItNow(listingId) {showPopupFrame(590, 900, 30, 30);autoRefresh=true;$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"placeBid.action?domain="+baseDomain+"&listingId="+listingId+"&bidType=BuyNow&refUrl="+escape(document.location.href)+"?autopopup=buynow"));trackEvent("Buy It Now");}
function detailsAskQuestion(oTag,propertyId,listingId) {showPopupFrame(320,500,$("#"+oTag).offset().top-300,$("#"+oTag).offset().left+10);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"askAQuestion.action?domain="+baseDomain+"&propertyId="+propertyId+"&listingId=" + listingId + "&refUrl="+escape(document.location.href)+"?autopopup=askQ"));trackEvent("Ask Question");}
function detailsWatchListing(oTag,propertyId,listingId) {showPopupFrame(320,500,$("#"+oTag).offset().top-300,$("#"+oTag).offset().left+10);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"createWatch.action?domain="+baseDomain+"&propertyId="+propertyId+"&listingId=" + listingId + "&refUrl="+escape(document.location.href)+"?autopopup=watchListing"));trackEvent("Watch Listing");}
function detailsScheduleVisit(oTag,propertyId,listingId) {showPopupFrame(320,500,$("#"+oTag).offset().top-200,$("#"+oTag).offset().left+10);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"openScheduleVisitForm.action?domain="+baseDomain+"&propertyId=" + propertyId + "&listingId=" + listingId));trackEvent("Schedule Visit");}
function detailsSendListing(oTag, propertyId, listingId) {showPopupFrame(400,510,$("#"+oTag).offset().top-350,$("#"+oTag).offset().left+10);$("#iframePopup").attr("src", "http://addthis.com/bookmark.php?v=250&amp;pub=xa-4aa7b20d54ca2f48");trackEvent("Send Listing");}
function askQuestion(oTag,propertyId,listingId) {showPopupFrame(320,500,$(oTag).offset().top-140,$(oTag).offset().left-320);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"askAQuestion.action?domain="+baseDomain+"&propertyId="+propertyId+"&listingId="+listingId + "&refUrl="+escape(document.location.href)));trackEvent("Ask Question");}
function scheduleVisit(oTag,propertyId,listingId) {showPopupFrame(320,500,$(oTag).offset().top-140,$(oTag).offset().left-320);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"openScheduleVisitForm.action?domain="+baseDomain+"&propertyId="+propertyId+"&listingId="+listingId));trackEvent("Schedule Visit");}
function watchListing(oTag,propertyId,listingId) {showPopupFrame(320,500,$(oTag).offset().top-140,$(oTag).offset().left-320);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"createWatch.action?domain="+baseDomain+"&propertyId="+propertyId+"&listingId="+listingId + "&refUrl="+escape(document.location.href)));trackEvent("Watch Listing");}
function closeOpenHouse() {$("#openHousePopup").css("display","none");}
function showOpenHouse() {$("#openHousePopup").css("display","block");}
function closePropertyFees(sDiv) {$("#"+sDiv).css("display","none");}
function showPropertyFees(sDiv) {$("#"+sDiv).css("display","block");
	switch (sDiv) {
		case "webTransactionFeesPopup": trackEvent("Property Fees", "Web Transaction Fee"); break;
		case "depositEarnestFeesPopup": trackEvent("Property Fees", "Deposit/Earnest Money"); break;
		case "withdrawFeesPopup": trackEvent("Property Fees", "Withdraw Penalty"); break;
		case "termsPopup": trackEvent("Property Fees", "Terms/Contingencies"); break;
	}
}
function closeNetOfferPercent(sDiv) {$("#"+sDiv).css("display","none");}
function showNetOfferPercent(sDiv) {$("#"+sDiv).css("display","block");}
function mortageCal() {showPopupFrame(380,380,50,340);$("#iframePopup").attr("src",pageTracker._getLinkerUrl(baseURL+"mortgageCalculator.action?domain="+baseDomain));trackEvent("Calculate Monthly Payment");}
function pagerGOTO(pageNumber) { trackEvent("Pagination");document.location.href = $.query.set("pagenumber", pageNumber); }
function toggleRefinement(sPlace,sDiv,sTitle) {if ($("#"+sPlace).attr("class")=="refinementClosed") {$("#"+sPlace).attr("class","refinementOpen");trackEvent("Refinement", "Maximize " + sTitle);} else {$("#"+sPlace).attr("class","refinementClosed");trackEvent("Refinement", "Minimize " + sTitle);} $("#"+ sDiv).toggle("slow");}
function loadPropertyBuyItNow(url) {trackEvent('Buy It Now');document.location.href=url;}
function showPopupFrame(pxHeight, pxWidth, pxTop, pxLeft, fitWidth, fitHeight) {
  /* $("body").css("overflow", "hidden"); */
  $("#WebSiteGrad").css("visibility", "visible");$("#WebSiteGrad").css("z-index", "998");$("#WebSiteGrad").css("height", "2000px");
  var currentScroll = getTopScroll();var maxHeight;var maxWidth;
  if (window.innerHeight == null) {
      maxHeight = document.documentElement.clientHeight;maxWidth = document.documentElement.clientWidth;
  } else {
      maxHeight = window.innerHeight;maxWidth = window.innerWidth;
  }
  /* apply rules */
  if (fitWidth == true) { 
    pxLeft = 20;maxWidth = maxWidth - 90;
  } else {
    if (pxWidth > 0) { maxWidth = pxWidth; }
  }
  if (fitHeight == true) { 
    pxTop = 30;maxHeight = maxHeight - 70;
  } else {
    if (pxHeight > 0) { maxHeight = pxHeight; }
  }
  /* make it so */
  $("#iframePopup").css("top", pxTop + "px");$("#iframePopup").css("left", pxLeft + "px");$("#iframePopup").css("width", maxWidth + "px");$("#iframePopup").css("height", maxHeight + "px");$("#iframePopup").css("visibility", "visible");
  $("#iframePopupX").css("top", (pxTop - 28) + "px");$("#iframePopupX").css("left", (pxLeft + maxWidth - 5) + "px");$("#iframePopupX").css("visibility", "visible");$("#iframePopupX").css("z-index", "999");
  $("#iframePopup").css("z-index", "999");
}
function closeFrame() {
  if (autoRefresh == true) {
    var sURL = document.location.href;
    autoRefresh = false;
    if (sURL.indexOf("autopopup=bid") > 0) {sURL = sURL.replace("autopopup=bid","");}
    if (sURL.indexOf("autopopup=openhouse") > 0) {sURL = sURL.replace("autopopup=openhouse","");}
    if (sURL.indexOf("autopopup=buyitnow") > 0) {sURL = sURL.replace("autopopup=buyitnow","");}
    document.location.href = sURL;
  } else {
		setUserDisplay();
  	$("body").css("overflow","auto");$("#WebSiteGrad").css("height","1px");$("#WebSiteGrad").css("visibility","hidden");$("#iframePopup").attr("src","");$("#iframePopup").css("visibility","hidden");$("#iframePopupX").css("visibility","hidden");
	}
}
function refinementLabel(key) {
  var returnVal = "";
  switch (key) {
    case "sortOrder": returnVal = "Sort"; break;
    case "beds": returnVal = "Beds"; break;
    case "baths": returnVal = "Baths"; break;
    case "listingType": returnVal = "Listing Type"; break;
    case "squareFeetRange": returnVal = "Square Feet"; break;
    case "yearBuiltRange": returnVal = "Year Built"; break;
    case "minPrice": returnVal = "Minimum Price"; break;
    case "maxPrice": returnVal = "Maximum Price"; break;
    case "propertySubType": returnVal = "Property Type"; break;
    case "agent": returnVal = "Agent"; break;
    case "county": returnVal = "County"; break;
    case "propertyStatus": returnVal = "Property Status"; break;
  }
  return returnVal;
}
function loadComparePage() {var compare=getCookie("compare");if (compare=="null") {compare="";}var compareCheck=compare.split("||");if (compareCheck.length<2) {alert("Select 2 or more properties to compare");} else {document.location.href="/compare.htm";}}
function listingCompareHTML(listing) {
    var sHTM = "<td style=\"vertical-align:top;\">";
    var qs = listing.split("&");
    var qsKEY = []; var qsVAL = [];
    for (var r = 0; r < qs.length; r++) { var tmpPair = qs[r].split("="); qsKEY[r] = tmpPair[0]; qsVAL[r] = tmpPair[1]; }
    sHTM += "<a href=\"javascript:removeCompare('" + qsVAL[$.inArray("listingid", qsKEY)] + "');\">remove</a><br />";
    sHTM += "<img src=\"" + qsVAL[$.inArray("photo", qsKEY)] + "\" alt=\"\" onerror=\"javascript:this.src='/images/no-photo.jpg';\" />";
    sHTM += qsVAL[$.inArray("address", qsKEY)] + "<br />";
    sHTM += qsVAL[$.inArray("city", qsKEY)] + ", " + qsVAL[$.inArray("state", qsKEY)] + " " + qsVAL[$.inArray("zip", qsKEY)] + "<br />";
    sHTM += "<strong>Beds:</strong>" + qsVAL[$.inArray("beds", qsKEY)] + "<br />";
    sHTM += "<strong>Baths:</strong>" + qsVAL[$.inArray("baths", qsKEY)] + "<br />";
    sHTM += "<strong>Type:</strong>" + qsVAL[$.inArray("propertytype", qsKEY)] + "<br />";
    sHTM += "<strong>Year Built:</strong>" + qsVAL[$.inArray("yearbuilt", qsKEY)] + "<br />";
    sHTM += "<strong>Sq.Ft.:</strong>" + qsVAL[$.inArray("sqft", qsKEY)] + "<br />";
    sHTM += "<strong>Listing Price:</strong>" + qsVAL[$.inArray("listingprice", qsKEY)] + "<br />";
    sHTM += "<strong>Fireplace:</strong>" + qsVAL[$.inArray("fireplace", qsKEY)] + "<br />";
    sHTM += "<strong>Deck/Patio:</strong>" + qsVAL[$.inArray("deckpatio", qsKEY)] + "<br />";
    sHTM += "<strong>HOA Dues:</strong>" + qsVAL[$.inArray("hoadues", qsKEY)] + "<br />";
    sHTM += "<strong>County:</strong>" + qsVAL[$.inArray("county", qsKEY)] + "<br />";
    sHTM += "<strong>Highest Bid:</strong>" + qsVAL[$.inArray("highestbid", qsKEY)] + "<br />";
    sHTM += "<strong>Auction End Date:</strong>" + qsVAL[$.inArray("auctionenddate", qsKEY)] + "<br />";
    sHTM += "<strong>MLS#:</strong>" + qsVAL[$.inArray("mls", qsKEY)] + "<br />";
    sHTM += "<strong>Description:</strong>" + qsVAL[$.inArray("description", qsKEY)] + "<br />";
    sHTM += "<a href=\"" + qsVAL[$.inArray("url", qsKEY)] + "\">View Details</a><br />";
    sHTM += "</td>";
    return sHTM;
}
function addCompare(compareId) {
  var autoLoadCompare = false;
  var compare = getCookie("compare");
  if (compare == "null") { compare = ""; }
  var checkIt = $("#" + compareId);
  var listingId = compareId.substring(8);
  var compareCheck = compare.split("||");
  var compareCount = compareCheck.length;
  if (checkIt.attr("checked") == true) {
  if (compareCount <= 3) {
  if (compare.indexOf("|" + listingId + "|") == -1) { compare += "|" + listingId + "|"; }
  } else {
  $("#" + compareId).attr("checked", false);
  autoLoadCompare = true;
  }
  } else {
  if (compare.indexOf("|" + listingId + "|") > -1) { compare = compare.replace("|" + listingId + "|", ""); }
  }
  setCookie("compare", compare, 1);
  if (autoLoadCompare == true) { document.location.href = "/compare.htm"; }
}
function removeCompare(listingId) {var compare=getCookie("compare");if (compare=="null") {compare="";}compare=compare.replace("|"+listingId+"|","");setCookie("compare",compare,1);document.location.href="/compare.htm";}
function loadCompareFromCookie() {
  var sHTML = "<h1>No Properties to compare</h1>";
  var compare = getCookie("compare");
  if (compare == "null") { compare = ""; }
  if (compare != "") {
    var compareCheck = [];
    if (compare.indexOf("||") > 0) {
      compareCheck = compare.split("||");
    } else {
      compareCheck[0] = compare;
    }
    sHTML = "<table><tr>";
    for (var x = 0; x < compareCheck.length; x++) {
        var listing = AJAX("get", "/" + compareCheck[x].replace(/\|/g, "") + "/getListing.htm", "", "text/html");
        listing = listing.replace(/~/g, "&").replace(/\n/g, "");
        sHTML += listingCompareHTML(listing);
    }
    sHTML += "</tr></table>";
  }
  $("#compareListings").html(sHTML);
}
function saveSearch() {
	trackEvent("Save");
  var offsetTop = $(".saveSearch").offset().top - 340;
  if (offsetTop < 40) {offsetTop = 40;}
  showPopupFrame(350, 380, offsetTop, $(".saveSearch").offset().left + 40);
  saveSearchQuery = "";
	var sURL = document.location.href;
	sURL = sURL.split("/");
	saveSearchQuery += "&statecode="+sURL[3];
  var currentCity = getCityCurrentRefinement();
  if (currentCity != "") {saveSearchQuery += "&city=" + currentCity;}
  var currentZip = getZipCurrentRefinement();
  if (currentZip != "") {saveSearchQuery += "&zip=" + currentZip;}
  $.each($.query.get(), function(key, val) { saveSearchQuery += "&" + key + "=" + val; });
  $("#iframePopup").attr("src", pageTracker._getLinkerUrl(baseURL + "createSaveSearchAction.action?domain="+baseDomain+saveSearchQuery+"&refUrl=" + escape(document.location.href+"&statecode="+sURL[3])));
}
function closePopup(popupKey) {$(popupKey).css('display','none');$(popupKey+"X").css("display", "none");$("#WebSiteGrad").css("height","1px");$("#WebSiteGrad").css("visibility","hidden");}
function addCommas(nStr) {nStr += '';x = nStr.split('.');x1 = x[0];x2 = x.length > 1 ? '.' + x[1] : '';var rgx = /(\d+)(\d{3})/;while (rgx.test(x1)) {x1 = x1.replace(rgx, '$1' + ',' + '$2');}return x1 + x2;}
function loadStandardMessagePopup() {
  $("#WebSiteGrad").css("visibility", "visible");$("#WebSiteGrad").css("z-index", "998");$("#WebSiteGrad").css("height", "2000px");
	$("#standardMessage").css("width","800px");
	$("#standardMessage").css("height","283px");
	$("#standardMessage").css("position","absolute");
	$("#standardMessage").css("top","70px");
	$("#standardMessage").css("left","100px");
	$("#standardMessage").css("display","");
	$("#standardMessage").css("z-index","999");
}
function popup_zillowSingleHomeValueWidget(aPoint) {
$("#popup_zillowSingleHomeValueWidget").css("width","302px");
$("#popup_zillowSingleHomeValueWidget").css("height","406px");
$("#popup_zillowSingleHomeValueWidget").css("position","absolute");
$("#popup_zillowSingleHomeValueWidget").css("top",($(aPoint).offset().top - 380) + "px");
$("#popup_zillowSingleHomeValueWidget").css("left",($(aPoint).offset().left - 30) + "px");
$("#popup_zillowSingleHomeValueWidget").css("display","");
$("#popup_zillowSingleHomeValueWidgetX").css("top", ($("#popup_zillowSingleHomeValueWidget").offset().top - 26) + "px");
$("#popup_zillowSingleHomeValueWidgetX").css("left", ($("#popup_zillowSingleHomeValueWidget").offset().left + 297) + "px");
$("#popup_zillowSingleHomeValueWidgetX").css("display", "");
$("#popup_zillowSingleHomeValueWidgetX").css("z-index", "999");
}
function popup_zillowRecentlySoldHomesWidget(aPoint) {
$("#popup_zillowRecentlySoldHomesWidget").css("width","160px");
$("#popup_zillowRecentlySoldHomesWidget").css("height","378px");
$("#popup_zillowRecentlySoldHomesWidget").css("position","absolute");
$("#popup_zillowRecentlySoldHomesWidget").css("top",($(aPoint).offset().top - 350) + "px");
$("#popup_zillowRecentlySoldHomesWidget").css("left",($(aPoint).offset().left - 0) + "px");
$("#popup_zillowRecentlySoldHomesWidget").css("display","");
$("#popup_zillowRecentlySoldHomesWidgetX").css("top", ($("#popup_zillowRecentlySoldHomesWidget").offset().top - 26) + "px");
$("#popup_zillowRecentlySoldHomesWidgetX").css("left", ($("#popup_zillowRecentlySoldHomesWidget").offset().left + 157) + "px");
$("#popup_zillowRecentlySoldHomesWidgetX").css("display", "");
$("#popup_zillowRecentlySoldHomesWidgetX").css("z-index", "999");
}
/* Google Maping code */
var geocoder;
var map;
var myPano;
var markerBounds = null;
var infowindowLevel = 0;
function stateBrowsePathMap() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP };
    map = new google.maps.Map(document.getElementById("statePageMap"), myOptions);
    for (var x = 0; x < browsePathCityState.length; x++) {
        var newMarker = codeAddress(browsePathCityState[x], true);
    }
}
function searchResultsMap() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP };
    map = new google.maps.Map(document.getElementById("searchResultsPageMap"), myOptions);
    for (var x = 0; x < searchResultsAddress.length; x++) {
        var newMarker = codeAddress(searchResultsAddress[x], true);
    }
}
function propertyDetailsMapV2() {
    if (propertyDetailsLAT != null && propertyDetailsLONG != null) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("detailsPageMap"));
        map.setCenter(new GLatLng(propertyDetailsLAT, propertyDetailsLONG), 11);
        map.setUIToDefault();
      }
    } else if (propertyADDRESS != null) {
			if (GBrowserIsCompatible()) {
	      map = new GMap2(document.getElementById("detailsPageMap"));
	      map.setCenter(new GLatLng(-34.397, 150.644), 11);
	      map.setUIToDefault();
	      geocoder = new GClientGeocoder();
				codeAddressV2(propertyADDRESS);
			}
    } else {
        document.getElementById("detailsPageMap").innerHTML = "<b>Address or Lat/Long required to map property</b>";
    }
}
function codeAddressV2(address) {
	if (geocoder) {
		// Create our "tiny" marker icon
		var houseIcon = new GIcon(G_DEFAULT_ICON);
		houseIcon.image = "/images/map-marker.gif";
		houseIcon.iconSize = new GSize(15,16);
		houseIcon.iconAnchor = new GPoint(-1,-1);
		houseIcon.shadow = '';
		houseIcon.shadowSize = new GSize(0,0);
		
		// Set up our GMarkerOptions object
		markerOptions = { icon:houseIcon };

	  geocoder.getLatLng(
	    address,
	    function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
	        map.setCenter(point, 11);
	        var marker = new GMarker(point, markerOptions);
	        map.addOverlay(marker);
					
				  var panoramaOptions = { latlng:point };
				  myPano = new GStreetviewPanorama(document.getElementById("detailsPageStreetView"), panoramaOptions);
				  GEvent.addListener(myPano, "error", handleNoFlash);
	      }
	    }
	  );
	}
}
function handleNoFlash(errorCode) {
	if (errorCode == 600) {
		document.getElementById("detailsPageStreetView").innerHTML = "<br /><br /><b><h2 style='padding-left:15px;'>Street View data does not exist for this address.</h2></b>";
		return;
	}
  if (errorCode == FLASH_UNAVAILABLE) {
    alert("Error: Flash doesn't appear to be supported by your browser");
    return;
  }
}
function propertyDetailsMap() {
    if (propertyDetailsLAT != null && propertyDetailsLONG != null) {
        var latlng = new google.maps.LatLng(propertyDetailsLAT, propertyDetailsLONG);
        var myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
        map = new google.maps.Map(document.getElementById("detailsPageMap"), myOptions);
    } else if (propertyADDRESS != null) {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
        map = new google.maps.Map(document.getElementById("detailsPageMap"), myOptions);
        var x = codeAddress(propertyADDRESS, false);
    } else {
        alert("Address or Lat/Long required to map property");
    }
}
function codeAddress(data, autoZoom) {
    var returnLatLng;
    dataItems = data.split("|");
    address = dataItems[0];
    if (geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location,
                        title: address,
                        icon: (dataItems.length == 2) ? "" : "/images/map-marker.gif"
                    });
                    if (autoZoom == true) {
                      /* Create the markerBounds object starting with the first marker */
                      if (markerBounds == null)
                      {
                        markerBounds = new google.maps.LatLngBounds(marker.getPosition(), marker.getPosition()); 
                      }  
                      markerBounds.extend(marker.getPosition());
                      map.fitBounds(markerBounds); 
                      attachInfowindow(marker, data);
                      returnLatLng = marker.getPosition().toString();
                    }
                } else {
                    /* alert("No results found"); */
                }
            } else {
                /* alert("Geocode was not successful for the following reason: " + status); */
            }
        });
    } else {
        /* alert("Missing geocoder object."); */
    }
    //return returnLatLng;
}
function attachInfowindow(marker, data) {
	var infowindow;
  dataItems = data.split("|");
	if (dataItems.length == 2) {
	  infowindow = new google.maps.InfoWindow(
	    { content: 
	        dataItems[0] +
					"<br /><a href=\"" + dataItems[1] + "\">View " + dataItems[0] + " search results</a>"
	    });
	} else {
	  infowindow = new google.maps.InfoWindow(
	    { content: 
	        "<a class=\"srViewListing\" href=\"" + dataItems[7] + "\"><!-- --></a>" +
	        "<br/><b>#</b> " + dataItems[8] +
	        "<br/><b>Address:</b> " + dataItems[0] +
	        "<br/><b>Property ID:</b> " + dataItems[1] +
	        "<br/><b>MLS #:</b> " + dataItems[2] + 
	        "<br/>" + dataItems[3] +
	        "<br/>" + dataItems[4] + " Beds, " + dataItems[5] + " Baths" +
	        "<br/><b>Listing Date:</b> " + dataItems[6]
	    });
	}
  google.maps.event.addListener(marker, 'click', function() { infowindow.zIndex = infowindowLevel++; infowindow.open(map, marker); });
}

