var schoolDetailJSON = null;
var communtiyInfoJSON = null
var listingDetailJSON = null;
var listingDetailurl = "/include/ajax/mapsearch/listingDetail.aspx";
var photoHTML = "";	
var bubbleHeight=130;
var bubbleWidth=300;
var favorites = new Array();
var bClientPortal = false;
var bClientListng = false;
var bFavorite = false;
var clientId = 0;
var userId = 0;
var scope = '';
var isWebtop = false;
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function getElementTop(elemID)
{ 
 var offsetTrail = document.getElementById(elemID); 
 var offsetLeft = 0; 
 var offsetTop = 0; 
 while (offsetTrail){ 
  offsetLeft += offsetTrail.offsetLeft; 
  offsetTop += offsetTrail.offsetTop; 
  offsetTrail = offsetTrail.offsetParent; 
 } 
 if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){ 
  offsetLeft += document.body.leftMargin; 
  offsetTop += document.body.topMargin; 
 } 
 return offsetTop; 

} 

	
//function ShowListingBubble(x, y, listing){
function ShowListingBubble(glatlng, listing){
	var gPt = map.fromLatLngToContainerPixel(glatlng)
	x = gPt.x;
	y = gPt.y;
	
	var horizontalAdjust = x+5;
	var verticalAdjust = y;
	var mapWidth = document.getElementById('Map1').offsetWidth; 	
	var mapHeight = document.getElementById('Map1').offsetHeight;	
	var adjustheight = 0;
	var adjustwidth = 0;
	var bubble = $('ListingBubble');
		
	bubble.innerHTML = buildBubbleHtml(listing);
	bubble.style.display='block';
	var strHref = window.location.href.toLowerCase();
	//alert("mapW: " + mapWidth + " mapH: " + mapHeight + " x: " + x + "Y: " + y + " bubbleWidth: " + bubbleWidth + " bubbleHeight: " + bubbleHeight);
	if(x < 0){x=0;}
	if(y < 0){y=0;}
	
	if (isWebtop == 'True') 
	{	
		if (strHref.indexOf("cmc") > 0) adjustheight = 30;//-120;
		else if (strHref.indexOf("savedsearchid") > 0) adjustheight = 54 ;
		else 
		{
			adjustheight = 47 ;
			adjustwidth = 20;
			if (is.ie6) {adjustheight += 20;}
		}
	}
	if(x+bubbleWidth >= mapWidth)
	{ 
		horizontalAdjust = x-bubbleWidth-1;
	}
	
/*	if(y < bubbleHeight)
	{ 
		verticalAdjust = y+bubbleHeight;
		if (isWebtop == 'True') 
		{
			if (strHref.indexOf("cmc") > 0) adjustheight = 44;//-120;
			else if (strHref.indexOf("savedsearchid") > 0) adjustheight = 78 ;
			else 
			{
				adjustheight = 45 ;
				adjustwidth = 20;
				if (is.ie6) {adjustheight += 20;}
			}
		}
	}
*/
	if (scope == 'domain') adjustheight = 47;
	else if (scope == 'office') adjustheight = 50;
	else if (scope == 'agent' || scope == 'agent_finehomes' ||scope == 'team')
	{
		if (websitecateg == "AGENT/DESIGNER") 
		{
			if (theme == 'DEFAULT') adjustheight = 60;
			else adjustheight = 55 ;
		}
		else 
		{	
			if (theme == 'DEFAULT') adjustheight = 60;
			else adjustheight = 60 ;
			
			if (is.ie6) {adjustheight += 15;}
		}
	}
	
	else if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller') 
	{
		 adjustheight = 60;
		 if (is.ie6) {adjustheight += 15;}
	}
	
	if (is.gecko && (isWebtop != 'True')) {adjustheight += -20;}
	
	
	verticalAdjust = verticalAdjust + adjustheight;
	horizontalAdjust = horizontalAdjust + adjustwidth;
	bubble.className = 'listingBubble';
	bubble.style.left = horizontalAdjust + 'px';
	bubble.style.top = verticalAdjust + 'px';
	
}

		
	function toggle(s, listingID)
	{
		if (s == 'details')
		{
			$('ListingBubbleMoreInfo').style.display='none'; 
			$('ListingBubbleDetails').style.display='block'; 
			$('aDetails').className = 'selected' ;
			if ($('aMoreInfo') != null) $('aMoreInfo').className = '' ;
		}
		else if (s == 'more-info')
		{
			$('ListingBubbleDetails').style.display='none'; 
			$('ListingBubbleMoreInfo').style.display='block'; 
			if ($('aMoreInfo') != null) $('aMoreInfo').className = 'selected' ;
			$('aDetails').className = '' ;
			
			var params = "listingId=" + listingID;
			var myAjax = new Ajax.Request(
			listingDetailurl, 
			{
				method: 'get', 
				parameters: params, 
				onComplete: showResponseDetail
			});
		}
	}
	
	function showResponseDetail(originalRequest)
	{
		listingDetailJSON = null;
		response = originalRequest.responseText;
		if (response != null) 
		{
			listingDetailJSON = eval('(' + response + ')');
		}
	}
	function buildBubbleHtml(listing)
	{
		var strHref = window.location.href.toLowerCase();
		var htmlFragArray = new Array();
		var htmlFrag = "";
		
		htmlFragArray.push("<div id=bubble class=mapbubble>");
				htmlFragArray.push("<div class=bubbleTitlebar>");
				htmlFragArray.push("<ul>");
				htmlFragArray.push("<li><a id='aDetails' class='selected' href=javascript:toggle('details','" + listing.listingid + "')>Details</a></li>");
				if (document.getElementById('cat') !=  null)
				{
					if ($('cat').value == 'res' || $('cat').value == 'mob') htmlFragArray.push("<li><a id='aMoreInfo' class='more-info' href=javascript:toggle('more-info','" + listing.listingid + "')>More Info</a></li>");
				}
				else 
				{
					if (listing.type == 'SFR' || listing.type == 'MOBILE') htmlFragArray.push("<li><a id='aMoreInfo' class='more-info' href=javascript:toggle('more-info','" + listing.listingid + "')>More Info</a></li>");
				}
				htmlFragArray.push("</ul>");
			htmlFragArray.push("<a href='javascript:HideListingBubble()'><img class='remove' src=/images/removeButton.gif border=0></a></div>");
			
			htmlFragArray.push("<div class=bubbleData id='ListingBubbleDetails'><div class=bubbleInfo>");
				if (listing.ListPriceFlag == '1') htmlFragArray.push("<span class='price-reduce'>Price Reduction On Property<br /></span>");
				if (isWebtop == 'True') htmlFragArray.push("<a href=javascript:webtopPropertyDetail('" + listing.mlslistingid + "','" + listing.mlsid + "')>" + listing.address + " " + listing.unitnumber + "</a><br />" + listing.city + "<br />");
				else 
				{
					if (strHref.indexOf("popup.aspx") > 0) htmlFragArray.push(listing.address + " " + listing.unitnumber + "<br />" + listing.city + "<br />");
					else htmlFragArray.push("<a href=javascript:redirect('" + listing.listingid + "')>" + listing.address + " " + listing.unitnumber + "</a><br />" + listing.city + "<br />");
				}
				htmlFragArray.push("$" + fmtMoney(listing.ListPrice,0,'.',',') + "<br />" );
			if (document.getElementById('cat') !=  null)
			{
				if ($('cat').value == 'lnd' || listing.type == 'LAND')
				{
					htmlFragArray.push("" + listing.lotsizeacre + " acres<br />");
				}
				else if ($('cat').value == 'inc' || listing.type == "RESINC" || listing.type == "RESINC5")
				{
					htmlFragArray.push("" + listing.multitotalunits + " units<br />");
				}
				else if ($('cat').value == 'res' || $('cat').value == 'mob')
				{
					htmlFragArray.push("" + listing.Bedrooms + " BD<br />");
					if (listing.bathspartial == "0" || listing.bathspartial == "") htmlFragArray.push(listing.bathsfull + " BA " + "<br />");
					else htmlFragArray.push(listing.bathsfull + " BA, " + listing.bathspartial + " PAR BA" + "<br />");
					htmlFragArray.push("" + listing.LivingArea + " Sq Ft.<br />");
				}
			}
			else 
			{
				//for cleint portal and other listing modules
					if (listing.type == "LAND")
					{
						htmlFragArray.push("" + listing.lotsizeacre + " acres<br />");
					}
					else if (listing.type == "RESINC" || listing.type == "RESINC5")
					{
						htmlFragArray.push("" + listing.multitotalunits + " units<br />");
					}
					else
					{
						htmlFragArray.push("" + listing.Bedrooms + " BD");
						if (listing.bathspartial == "0" || listing.bathspartial == "") 
						htmlFragArray.push(" , " + listing.bathsfull + " BA " + "<br />");
						else htmlFragArray.push(" / " + listing.bathsfull + " BA, " + listing.bathspartial + " PAR BA" + "<br />");
						htmlFragArray.push("" + listing.LivingArea + " Sq Ft.<br />");
					}
			}
			
			if (bClientPortal == 'True') 
			{
				htmlFragArray.push("<div class=\"save-button\" id=\"sv_" + listing.listingid + "\">"); 
				var inFavoriteArray = FindInFavorites(listing.listingid);
				if (listing.clientId > 0 || inFavoriteArray || bFavorite == 'True') 
				{
					htmlFragArray.push("<span class=\"text\">SAVED FAVORITE</span>");
				}
				else if(bClientListng != 'True')
				{
					htmlFragArray.push("<a href=javascript:save_property('" + listing.listingid + "','" + userId + "','" + clientId + "','" + listing.listingid + "','sv_" + listing.listingid + "') class=text> SAVE AS FAVORITE </a>");
				}
				
				htmlFragArray.push("</div>");
			}
			else if(isWebtop != 'True')
			{
				htmlFragArray.push("<div class=\"save-button\" id=\"sv_" + listing.listingid + "\">"); 
				var inFavoriteArray = FindInFavorites(listing.listingid);
				if (listing.clientId > 0 || inFavoriteArray) 
				{
					htmlFragArray.push("<span class=\"text\">SAVED FAVORITE</span>");
				}
				else
				{
					htmlFragArray.push("<a href=javascript:save_property_agent_domain_site('" + listing.listingid + "','" + userId + "','" + clientId + "','" + listing.listingid + "','sv_" + listing.listingid + "') class=text> SAVE AS FAVORITE </a>");
				}
				htmlFragArray.push("</div>");
			}
			if ((getDomainId() == 1 || getDomainId() == 4) && scope == 'domain' && isWebtop != 'True') htmlFragArray.push("<a class=showing-time id=lnkShowingTime href='" + getShowingTimeUrl(listing.listOfficeName,listing.listingid,listing.address, listing.city, listing.StateOrProvince, listing.postalcode,listing.ListPrice, listing.isprulist, listing.userId, listing.officeID,getDomainId()) + "' target=_blank>Schedule a Showing</a>");
			htmlFragArray.push("</div>");
			if (isWebtop == 'True') htmlFragArray.push("<div class='listing-photo'><a href=javascript:webtopPropertyDetail('" + listing.mlslistingid + "','" + listing.mlsid + "')><img  id='imgOfficePhoto' src='" + imageServerURL + "/include/imageserver.aspx?listingID=" + listing.listingid + "' &height=75&width=-1' height=75 border='0' /></a></div>");
			else 
			{
				if (strHref.indexOf("popup.aspx") > 0) htmlFragArray.push("<div class='listing-photo'><img  id='imgOfficePhoto' src='" + imageServerURL + "/include/imageserver.aspx?listingID=" + listing.listingid + "' &height=75&width=-1' height=75 border='0' /></div>");
				else htmlFragArray.push("<div class='listing-photo'><a href=javascript:redirect('" + listing.listingid + "')><img  id='imgOfficePhoto' src='" + imageServerURL + "/include/imageserver.aspx?listingID=" + listing.listingid + "' &height=75&width=-1' height=75 border='0' /></a></div>");
			}
			htmlFragArray.push("</div>");
			
			htmlFragArray.push("<div id='ListingBubbleMoreInfo' style='display:none' class='more-info'>");
				htmlFragArray.push("<div><a href=javascript:showThis('Photos','" + listing.listingid + "')>More Photos</a></div>");
				htmlFragArray.push("<div id=Photos style=display:none>");
				htmlFragArray.push("</div>");
				htmlFragArray.push("<div><a href=javascript:showSchools('" + listing.postalcode + "')>School Info</a></div>");
				htmlFragArray.push("<div id=School style=display:none>");
				htmlFragArray.push("</div>");
				htmlFragArray.push("<div><a href=javascript:showCommunityInfo('" + listing.postalcode + "')>Community Info</a></div>");
				htmlFragArray.push("<div id=Community style=display:none>");
				htmlFragArray.push("</div>");
				htmlFragArray.push("<div><a href=javascript:showThis('Property','" + listing.listingid + "')>Property Features</a></div>");
				htmlFragArray.push("<div id=Property style=display:none>");
				htmlFragArray.push("</div>");
				htmlFragArray.push("<div><a href=javascript:showThis('Amenities','" + listing.listingid + "')>Amenities</a></div>");
				htmlFragArray.push("<div id=Amenities style=display:none>");
				htmlFragArray.push("</div>");
			htmlFragArray.push("</div>");
	
		htmlFragArray.push("</div>");
			
		htmlFrag = htmlFragArray.join('');	
		return htmlFrag;
	}
	function FindInFavorites(l)
	{
		if (favorites != null && favorites.length > 0)
		{
			for (i=0; i<favorites.length; i++)
			{
				if (l == favorites[i]) return true;
			}
		}
		return false;
	}
	function redirect(listingId)
	{
		var strUrl = "";
		var strhref = window.location.href;
		if (strhref != null)
		{
			if (strhref.toLowerCase().indexOf("mapsearch.aspx") > 0)
			{
				strUrl = "propertydetail.aspx?src=mapsearch&listingID=" + listingId ;
				
			}
			else if (strhref.toLowerCase().indexOf("fhsearchresults.aspx") > 0)
			{
				strUrl = "fineHomesDetail.aspx?src=searchresults&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("searchresults.aspx") > 0)
			{
				strUrl = "propertydetail.aspx?src=searchresults&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("officelistings.aspx") > 0) 
			{
				strUrl = "propertydetail.aspx?src=officeListing&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("mylistings.aspx") > 0)
			{
				strUrl = "propertydetail.aspx?src=myListing&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("executiveestatesresults.aspx") > 0)
			{
				strUrl = "executiveEstatesDetail.aspx?src=propSearch&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("openhomesresults.aspx") > 0)
			{
				strUrl = "propertydetail.aspx?src=openhome&listingID=" + listingId ;
			}
			else if (strhref.toLowerCase().indexOf("newpropertymatches.aspx") > 0 || strhref.toLowerCase().indexOf("propertiesofinterest.aspx") > 0)
			{
				strUrl = "propertydetail.aspx?listingID=" + listingId ;
			}
			else strUrl = "propertydetail.aspx?src=propSearch&listingID=" + listingId ;
		}
		document.cookie = "cords=" + redirectparams + "; path=/; ";
		document.cookie = "redirect=true" + "; path=/; ";
		//document.cookie = "sort=" + sortcolumnname + "," + sortdirection + "; path=/; ";
		var s = 0;
		var o = 0;
		if ($('chkSchools') != null) 
		{
			if ($('chkSchools').checked) s = 1;
			else s = 0;
		}
		if ($('chkOffices') != null)
		{
			if ($('chkOffices').checked) o = 1;
			else o = 0;
		}
		if (s==1 && o==1) document.cookie = "so=1,1" + "; path=/; ";
		else if (s==0 && o==1) document.cookie = "so=0,1" + "; path=/; ";
		else if (s==1 && o==0) document.cookie = "so=1,0" + "; path=/; ";

		window.location.href = strUrl;
	}
	function buildPhotoHTML(listingid)
	{
		var htmlFragArray = new Array();
		var htmlFrag = "";
		var strHref = window.location.href.toLowerCase();
		if (listingDetailJSON != null && listingDetailJSON.Photos != null && listingDetailJSON.Photos.length != null)
		{
			htmlFragArray.push("<div class='photos'>");
			for (var i=0; i<listingDetailJSON.Photos.length; i++)
			{
				if (isWebtop == 'True') htmlFragArray.push("<img src='" + imageServerURL + "/include/ImageServer.aspx?mlsPhotoID=" + listingDetailJSON.Photos[i].mlsphotoid + "&amp;propdetail=thumb'>");
				else 
				{
					if (strHref.indexOf("popup.aspx") > 0) htmlFragArray.push("<img src='" + imageServerURL + "/include/ImageServer.aspx?mlsPhotoID=" + listingDetailJSON.Photos[i].mlsphotoid + "&amp;propdetail=thumb'>");
					else htmlFragArray.push("<a href=javascript:redirect('" + listingid + "')><img src='" + imageServerURL + "/include/ImageServer.aspx?mlsPhotoID=" + listingDetailJSON.Photos[i].mlsphotoid + "&amp;propdetail=thumb'></a>");
				}
			}
			htmlFragArray.push("</div><div class='clearleft'></div>");
			htmlFrag = htmlFragArray.join('');	
			return htmlFrag;
		}
	}
	function buildAmenitiesHTML(listingid)
	{
		var htmlFragArray = new Array();
		var htmlFrag = "";
		var strHref = window.location.href.toLowerCase();
		if (listingDetailJSON != null && listingDetailJSON.Detail != null && listingDetailJSON.Detail.length != null)
		{
			htmlFragArray.push("<div class='amenities'>");
			htmlFragArray.push("<ul>");
			htmlFragArray.push("<li>Pool:" + listingDetailJSON.Detail[0].bPool + "</li>");
			//htmlFragArray.push("<li>Horses:" + listingDetailJSON.Detail[0].bHorses + "</li>");
			htmlFragArray.push("<li>Laundry:" + listingDetailJSON.Detail[0].bLaundry + "</li>");
			//htmlFragArray.push("<li>Loft:" + listingDetailJSON.Detail[0].bLoft + "</li>");
			htmlFragArray.push("<li>Parking:" + listingDetailJSON.Detail[0].bParking + "</li>");
			//htmlFragArray.push("<li>View Description:" + listingDetailJSON.Detail[0].bViewDescription + "</li>");
			htmlFragArray.push("<li>Lot Features:" + listingDetailJSON.Detail[0].bLotFeatures + "</li>");
			if (isWebtop == 'True') htmlFragArray.push("<li><a href=javascript:webtopPropertyDetail('" + listingDetailJSON.Detail[0].MLSListingID + "','" + listingDetailJSON.Detail[0].MLSID + "')>more..</a></li>");
			else 
			{
				if (strHref.indexOf("popup.aspx") <= 0) htmlFragArray.push("<li><a href=javascript:redirect('" + listingid + "')>more..</a></li>");
			}
			htmlFragArray.push("</ul></div>");
					
			htmlFrag = htmlFragArray.join('');	
			return htmlFrag;
		}
	}
	function buildPropertyFeaturesHTML(listingid)
	{
		var htmlFragArray = new Array();
		var htmlFrag = "";
		var strCat = "";
		var strHref = window.location.href.toLowerCase();
		if ($("cat") != null) strCat = $("cat").value;
		
		if (listingDetailJSON != null && listingDetailJSON.Detail != null && listingDetailJSON.Detail.length != null)
		{
			htmlFragArray.push("<div class='property-features'>");
			htmlFragArray.push("<ul>");
			
			if (strCat == "lnd")
			{
				htmlFragArray.push("<li>Type:" + listingDetailJSON.Detail[0].Type + "</li>");
				htmlFragArray.push("<li>Status:" + listingDetailJSON.Detail[0].StatusName + "</li>");
				htmlFragArray.push("<li>Lot Size:" + listingDetailJSON.Detail[0].lotSizeInAcres + "</li>");
				htmlFragArray.push("<li>Zoning:" + listingDetailJSON.Detail[0].zoning + "</li>");
			}
			else if (strCat == "inc")
			{
				htmlFragArray.push("<li>Type:" + listingDetailJSON.Detail[0].Type + "</li>");
				htmlFragArray.push("<li>Year Built:" + listingDetailJSON.Detail[0].YearBuilt + "</li>");
				htmlFragArray.push("<li>Total Units:" + listingDetailJSON.Detail[0].multiTotalUnits + "</li>");
			}
			else if (strCat == "mob")
			{
				htmlFragArray.push("<li>Bedrooms:" + listingDetailJSON.Detail[0].Bedrooms + "</li>");
				htmlFragArray.push("<li>Baths Full:" + listingDetailJSON.Detail[0].BathsFull + "</li>");
				htmlFragArray.push("<li>Baths Partial:" + listingDetailJSON.Detail[0].BathsPartial + "</li>");
				htmlFragArray.push("<li>Type:" + listingDetailJSON.Detail[0].Type + "</li>");
				htmlFragArray.push("<li>Year Built:" + listingDetailJSON.Detail[0].YearBuilt + "</li>");
				htmlFragArray.push("<li>Living Area:" + listingDetailJSON.Detail[0].LivingArea + "</li>");
			}
			else // "res"
			{
				htmlFragArray.push("<li>Style:" + listingDetailJSON.Detail[0].bStyle + "</li>");
				htmlFragArray.push("<li>Stories:" + listingDetailJSON.Detail[0].bStories + "</li>");
				htmlFragArray.push("<li>Fireplaces:" + listingDetailJSON.Detail[0].bFireplaces + "</li>");
				htmlFragArray.push("<li>Cooling:" + listingDetailJSON.Detail[0].bCooling + "</li>");
				htmlFragArray.push("<li>Heating:" + listingDetailJSON.Detail[0].bHeating + "</li>");
				//htmlFragArray.push("<li>Garage:" + listingDetailJSON.Detail[0].bGarage + "</li>");
				htmlFragArray.push("<li>Type:" + listingDetailJSON.Detail[0].Type + "</li>");
			}
			if (isWebtop == 'True') htmlFragArray.push("<li><a href=javascript:webtopPropertyDetail('" + listingDetailJSON.Detail[0].MLSListingID + "','" + listingDetailJSON.Detail[0].MLSID + "')>more..</a></li>");
			else 
			{
				if (strHref.indexOf("popup.aspx") <= 0) htmlFragArray.push("<li><a href=javascript:redirect('" + listingid + "')>more..</a></li>");
			}
			htmlFragArray.push("</ul></div>");
					
			htmlFrag = htmlFragArray.join('');	
			return htmlFrag;
		}
	}
	function showSchools(zipcode)
	{
		var schoolDetailURL = "/include/ajax/mapsearch/schoolList.aspx";
		$('Community').style.display='none';
		$('Property').style.display='none';
		$('Amenities').style.display='none';
		$('Photos').style.display='none';
		
		var params = "zipcode=" + zipcode;
		var myAjax = new Ajax.Request(
		schoolDetailURL, 
		{
			method: 'get', 
			parameters: params, 
			onComplete: showResponseSchoolDetail
		});
		if ($('School').style.display == 'none') $('School').style.display='block';
		else if ($('School').style.display == 'block') $('School').style.display = 'none';
	}
	function showResponseSchoolDetail(originalRequest)
	{
		schoolDetailJSON = null;
		response = originalRequest.responseText;
		if (response != null) 
		{
			schoolDetailJSON = eval('(' + response + ')');
		}
		$('School').innerHTML = buildSchoolsHTML();
	}
	function buildSchoolsHTML()
	{
		var htmlFragArray = new Array();
		var htmlFrag = "";

		if (schoolDetailJSON != null && schoolDetailJSON.Schools != null && schoolDetailJSON.Schools.length != null)
		{
			htmlFragArray.push("<div class='schools'><table id=tbSchools><tr>");
			htmlFragArray.push("<th>School</th>");
			htmlFragArray.push("<th>Address</th>");
			//htmlFragArray.push("<th>County</th>");
			htmlFragArray.push("<th>Grades</th>");
			//htmlFragArray.push("<th>District</th>");
			htmlFragArray.push("</tr>");
			for (var i=0; i<schoolDetailJSON.Schools.length; i++)
			{
				htmlFragArray.push("<tr>");
				htmlFragArray.push("<td>" + schoolDetailJSON.Schools[i].SchoolName + "</td>");
				htmlFragArray.push("<td>" + schoolDetailJSON.Schools[i].Street + "," + schoolDetailJSON.Schools[i].City + "," + schoolDetailJSON.Schools[i].State + "</td>");
				//htmlFragArray.push("<td>" + schoolDetailJSON.Schools[i].County + "</td>");
				htmlFragArray.push("<td>" + schoolDetailJSON.Schools[i].Level + "</td>");
				//htmlFragArray.push("<td>" + schoolDetailJSON.Schools[i].DistrictName + "</td>");
				htmlFragArray.push("</tr>");
				if (i == 4) break;
			}
			htmlFragArray.push("</table></div>");
			if (isWebtop == 'False') htmlFragArray.push("<p><a href=javascript:schoolredirect('" + schoolDetailJSON.Schools[0].Zip + "')>more..</a></p>");
			htmlFrag = htmlFragArray.join('');	
			return htmlFrag;
		}
	}
	function schoolredirect(zip)
	{
		var strUrl = "SchoolsSearchResults.aspx?from=ms&SchoolsSearchZipcode=" + zip ;
		//document.cookie = "searchparams=" + searchparams + "; path=/; ";
		document.cookie = "cords=" + redirectparams + "; path=/; ";
		document.cookie = "redirect=" + "true" + "; path=/; ";
		//document.cookie = "sort=" + sortcolumnname + "," + sortdirection + "; path=/; ";
		var s = 0;
		var o = 0;
		if ($('chkSchools') != null) 
		{
			if ($('chkSchools').checked) s = 1;
			else s = 0;
		}
		if ($('chkOffices') != null)
		{
			if ($('chkOffices').checked) o = 1;
			else o = 0;
		}
		if (s==1 && o==1) document.cookie = "so=1,1" + "; path=/; ";
		else if (s==0 && o==1) document.cookie = "so=0,1" + "; path=/; ";
		else if (s==1 && o==0) document.cookie = "so=1,0" + "; path=/; ";
		window.location.href = strUrl;
	}
	function showCommunityInfo(zipcode)
	{
		//communtiyInfoJSON
		var communtiyInfoURL = "/include/ajax/mapsearch/communityInfo.aspx";
		$('School').style.display='none';
		$('Property').style.display='none';
		$('Amenities').style.display='none';
		$('Photos').style.display='none';
		//$('Community').style.display = 'block';
		
		var params = "zipcode=" + zipcode;
		var myAjax = new Ajax.Request(
		communtiyInfoURL, 
		{
			method: 'get', 
			parameters: params, 
			onComplete: showResponseCommunityDetail
		});
		if ($('Community').style.display == 'none') $('Community').style.display='block';
		else if ($('Community').style.display == 'block') $('Community').style.display = 'none';
	}
	function showResponseCommunityDetail(originalRequest)
	{
		communtiyInfoJSON = null;
		response = originalRequest.responseText;
		if (response != null) 
		{
			communtiyInfoJSON = eval('(' + response + ')');
		}
		$('Community').innerHTML = buildCommunityInfoHTML();
	}
	function buildCommunityInfoHTML()
	{
		var htmlFragArray = new Array();
		var htmlFrag = "";
		var varLink = "<a href=#>more..</a>";

		if (communtiyInfoJSON != null && communtiyInfoJSON.Area != null)
		{
			htmlFragArray.push("<div class='community-info'>");
			htmlFragArray.push("<ul>");
			htmlFragArray.push("<li>Population:" + communtiyInfoJSON.Area[0].Population + "</li>");
			htmlFragArray.push("<li>County:" + communtiyInfoJSON.Area[0].CountyName + "</li>");
			htmlFragArray.push("<li>Metro Area:" + communtiyInfoJSON.Area[0].MetroName + "</li>");
			if (isWebtop == 'False') htmlFragArray.push("<li><a href=javascript:communityredirect('" + communtiyInfoJSON.Area[0].Place_Code + "')>more..</a></li>");
			htmlFragArray.push("</ul></div>");
		}
		htmlFrag = htmlFragArray.join('');	
	//	alert(htmlFrag);	
		return htmlFrag;
	}
	function communityredirect(zip)
	{
		var strUrl = "AreaNeighborhoodDetails.aspx?from=ms&AreaSearchStateChanged=False&AreaSearchNeighborhoodZipcode=" + zip ;
		//document.cookie = "searchparams=" + searchparams + "; path=/; ";
		document.cookie = "cords=" + redirectparams + "; path=/; ";
		document.cookie = "redirect=true" + "; path=/; ";
		//document.cookie = "sort=" + sortcolumnname + "," + sortdirection + "; path=/; ";
		window.location.href = strUrl;
	}
	
	function HideListingBubble(e)
	{
	  if (document.getElementById('ListingBubble') != null)	$('ListingBubble').style.display='none'; 
	}
	function showThis(strLink, listingid)
	{
				
		if (strLink == 'Photos')
		{
			photoHTML = buildPhotoHTML(listingid);
			if (photoHTML == "" || photoHTML == null) photoHTML = "No Photos available";
			$(strLink).innerHTML = photoHTML;
			$('School').style.display='none';
			$('Community').style.display='none';
			$('Property').style.display='none';
			$('Amenities').style.display='none';
		}
		else if (strLink == 'Amenities')
		{
			var amenHTML = buildAmenitiesHTML(listingid);
			if (amenHTML == "" || amenHTML == null) amenHTML = "No Data available";
			$(strLink).innerHTML = amenHTML;
			$('Photos').style.display='none';
			$('School').style.display='none';
			$('Community').style.display='none';
			$('Property').style.display='none';
		}
		else if (strLink == 'Property')
		{
			var propHTML = buildPropertyFeaturesHTML(listingid);
			if (propHTML == "" || propHTML == null) propHTML = "No Data available";
			$(strLink).innerHTML = propHTML;
			$('Photos').style.display='none';
			$('School').style.display='none';
			$('Community').style.display='none';
			$('Amenities').style.display='none';
		}
		if ($(strLink).style.display == 'none') $(strLink).style.display='block';
		else if ($(strLink).style.display == 'block') $(strLink).style.display = 'none';
	}
function SaveMapSearchParm()
{
	//set cookies that are needed for the "back" button
	document.cookie = "cords=" + redirectparams + "; path=/; ";
	document.cookie = "redirect=true" + "; path=/; ";
	//document.cookie = "sort=" + sortcolumnname + "," + sortdirection + "; path=/; ";
	var s = 0;
	var o = 0;
	if ($('chkSchools') != null) 
	{
		if ($('chkSchools').checked) s = 1;
		else s = 0;
	}
	if ($('chkOffices') != null)
	{
		if ($('chkOffices').checked) o = 1;
		else o = 0;
	}
	if (s==1 && o==1) document.cookie = "so=1,1" + "; path=/; ";
	else if (s==0 && o==1) document.cookie = "so=0,1" + "; path=/; ";
	else if (s==1 && o==0) document.cookie = "so=1,0" + "; path=/; ";
}
function save_property(db_listing_id, db_agent_id, db_client_id, html_listing_id, html_button_id)
{
	// save the property to the db (action = save | remove)
	window.location.href = '/include/config/updatepoi.aspx?listingid='+db_listing_id+'&agentID='+db_agent_id+'&clientID='+db_client_id+'&action=update'
	// update the property on the page
	favorites.push(db_listing_id);
	var listing_el = document.getElementById(html_listing_id);
	var button_el = document.getElementById(html_button_id);
	//listing_el.className = listing_el.className + ' saved';
	button_el.innerHTML = '<span class="text">SAVED FAVORITE</span>';
	SaveMapSearchParm();
}
function save_property_agent_domain_site(db_listing_id, db_agent_id, db_client_id, html_listing_id, html_button_id)
{
	var strHref = window.location.href;
	if(db_client_id == 0)
	{
		SaveMapSearchParm();
		if(strHref.indexOf("mapsearch.aspx") >= 0)
		{
			window.location.href = "login.aspx?function=favorite&listingid="+ db_listing_id + "&src=mapsearch";
		}
		else
		{
			window.location.href = "login.aspx?function=favorite&listingid="+ db_listing_id;
		}
		
	}else
	{
		save_property(db_listing_id, db_agent_id, db_client_id, html_listing_id, html_button_id)
	}
}
function save_property_from_detail(db_listing_id, db_agent_id, db_client_id, html_listing_id, html_button_id,team_id)
{
	if(db_client_id == 0)
	{
		window.location.href = "login.aspx?function=favorite&listingid="+ db_listing_id + "&src=detail";
	}else
	{
		// save the property to the db (action = save | remove)
		window.location.href = '/include/config/updatepoi.aspx?listingid='+db_listing_id+'&agentID='+db_agent_id+'&clientID='+db_client_id+'&teamID='+team_id+'&action=update'
		// update the property on the page
		favorites.push(db_listing_id);
		var listing_el = document.getElementById(html_listing_id);
		var button_el = document.getElementById(html_button_id);
		alert("Saved To Favorite");
		button_el.className = 'saved';
		var hrefStr = "javascript:remove_favorite('" + db_listing_id + "','" + db_agent_id + "','" + db_client_id + "','"+html_listing_id+ "','sv_" + db_listing_id + "','"+ team_id + "')";
		listing_el.href = hrefStr;
		listing_el.innerHTML = "<span class=\"text\">Delete From Favorite</span>";
	}
}
function remove_favorite(db_listing_id, db_agent_id, db_client_id, html_listing_id, html_button_id,team_id)
{
	if(db_client_id == 0)
	{
		window.location.href = "login.aspx?function=favorite&listingid="+ db_listing_id + "&src=mapsearch";
	}else
	{
		window.location.href = '/include/config/updatepoi.aspx?listingid='+db_listing_id+'&agentID='+db_agent_id+'&clientID='+db_client_id+'&teamID='+team_id+'&action=remove'
		// update the property on the page
		favorites.push(db_listing_id);
		var listing_el = document.getElementById(html_listing_id);
		var button_el = document.getElementById(html_button_id);
		alert("Removed From Favorite");
		button_el.className = 'save-button';
		var hrefStr = "javascript:save_property_from_detail('" + db_listing_id + "','" + db_agent_id + "','" + db_client_id + "','"+html_listing_id+ "','sv_" + db_listing_id + "','"+ team_id + "')";
		listing_el.href = hrefStr;
		listing_el.innerHTML = "<span class=\"text\">Save As Favorite</span>";
		
	}
}
function webtopPropertyDetail(mlslistingid, mlsId)
{
	var strURl = "/tools/wtmls/print_a1_photo.asp?mlsid=" + mlsId + "&mlslistingid=" + mlslistingid;
	//alert(strURl);
	window.open(strURl);
}

//showing time routines
function getDomainId()
{
	var strHref = window.location.href;
	if (isWebtop != 'True')
	{
		if(strHref.indexOf("prurealty") >= 0) return 1;
		else if(strHref.indexOf("gotucson") >= 0) return 2;
		else if(strHref.indexOf("prunevada") >= 0) return 3;
		else if(strHref.indexOf("prudentialtexasrealty") >= 0) return 5;
		else if(strHref.indexOf("prudentialtexas") >= 0) return 4;
		else return 1;
	}
}
function getShowingTimeUrl(listOfficeName, listingId, address, city, state, zip, price, isPruList, listAgentUserId, officeId, domID)
{
	var url = "http://links.showingtime.com/external/?";
	
	if(domID==4){
		url += "siteid=PRUDENTIALTEXAS.COM";
	}else{
		url += "siteid=PRUREALTY.COM";
	}
	url += "&broker=";
	url += encodeParams(listOfficeName);
	if(domID==4){
		url += "&mlsid=PRUTX";
	}else{
		url += "&mlsid=PRUCAL";
	}
	url += "&listingid=" + listingId;
	url += "&paddr=" + encodeParams(address);
	url += "&pcity=" + encodeParams(city);
	url += "&pstate=" + state;
	url += "&pzip=" + zip;
	url += "&price=" + price;
	url += "&laid=";
	if (isPruList == 1)
	{
		url += listAgentUserId;
		url += "&listingoffice=";
		url += officeId ;
	}
	else
	{
		url += "IDX&listingoffice=";
		url += encodeParams(listOfficeName);
	}
	return url;
}
function encodeParams(par)
{
	var param;
	if (window.encodeURIComponent) 
		param = encodeURIComponent(par); 
	else if (window.escape) 
		param = escape(par); 
	return param;
		
}