﻿function DisplaySolds(textObject)
{
    var maxElementDisplayCount = 100;
    // Populate listing object from text object results
	var soldCount = textObject.substring(0,6);
	
    if (soldCount > 100)
    {
        ShowSoldSearchWarning("<span style=\"font-size:1.2em;font-weight:bold;color:red;margin-left:3px;\">"+parseFloat(soldCount)+"</span><span style=\"color:red;\"> sold properties.<br />&nbsp;Please <a href=\"javascript:zoomIn(\'GetSolds()\');\">zoom in</a></span>&nbsp;<a href=\"javascript:zoomIn(\'GetSolds()\');\"><img src=\"../App_Themes/Default/Images/Map/circle_plus.png\" border=\"0\"></a>");
        return;
    }

    if (soldCount == 0)
    {
        ShowSoldSearchWarning("<span style=\"color:red;margin-left:3px;\">No sold properties.<br />&nbsp;Please expand your search.</span>");
        return;
    }
    	
     // Check to see if listing layer exists
    if (typeof(_soldLayer)!="undefined")
    {
        _map.DeleteShapeLayer(_soldLayer);
        // Delete all existing listing icons
        _soldLayer = new VEShapeLayer();
        _map.AddShapeLayer(_soldLayer);        
    }
    else
    {
        // Create listing layer
        _soldLayer = new VEShapeLayer();
        _map.AddShapeLayer(_soldLayer);
    }
		
    var solds = textObject.substring(6,textObject.length).split("@^");   //make an array of listings
    var elementCount = parseFloat(soldCount);
    
    //show data: for debugging
    for (var n = 0, len = solds.length, soldItems; n < len; n++) {
        document.getElementById('divResult').innerHTML += solds[n]+"<br><br>";
    }
       
   	// Display number of found listings
	displayMatchingSolds("<span style=\"font-size:1.0em;font-weight:bold;color:green;margin-left:3px;\">" + elementCount+ "</span> sold properties<br />");
	//"<span style=\"color:red;\">Maximum of 20 Sold Properties can be displayed. Please <a href=\"javascript:zoomIn(\'GetSolds()\');\">zoom in</a>&nbsp;<a href=\"javascript:zoomIn(\'GetSolds()\');\"><img src=\"../App_Themes/Default/Images/Map/circle_plus.png\" border=\"0\" align=\"middle\"></a>&nbsp;to refine your search</span>");

	var shapeArray = [];
	for (var n = 0, len = solds.length, soldItems; n < len; n++) {
		if(solds[n]) {								//take a single listing: listingElements[n]
			soldItems = solds[n].split("@~"); 	//make an array of its properties
			
			var soldListing = new SoldListing();                //Populate a ve_listing_object
   		    soldListing.Populate(soldItems);
			shapeArray.push(soldListing.GetShape());
		}
	}
	
	soldListing.DisplayShapeArray(shapeArray);                     //Display listing on map
}