function ResultGroup(sObjName, sSpanID, sCaption, aHeaders, iPerPage, iProductPageID)
{
	this.Handle = sObjName;
	this.Caption = sCaption;
	this.Headers = aHeaders;
	this.Results = new Array();
	this.PerPage = iPerPage;
	this.HTMLID = sSpanID;
	this.PageLBound = 0;
	this.SortDir = new Object();
	this.ProductPageID = iProductPageID;
	
	//add to global array of result sets
	ResultGroup.SETS.push(this);
	
	//Initialize sort columns
	for(var i=0; i<aHeaders.length; i++)
		if(aHeaders[i].Sortable)
			this.SortDir[aHeaders[i].ID] = 'DESC';
}	

ResultGroup.prototype.Draw = function()
{
	var PageUBound = (this.PageLBound + this.PerPage >= this.Results.length)? this.Results.length : this.PageLBound + this.PerPage;
	var curPage = Math.ceil((this.PageLBound + 1) / this.PerPage);
	var PageCount = Math.ceil(this.Results.length / this.PerPage);
	var str = '', aHTML = new Array();
	var FixedWidth = true;
	var instruct = txtWidth = "";
	
	if(this.Caption.indexOf("PROPERTIES") != -1)
		instruct = ' - <span style="color:#000;">please click on property name or picture to open complete package.</span>';
	
	//alert('curPage:' + curPage + ' <> PageCount:' + PageCount + ' <> PageUBound:' + PageUBound + ' <> ResultsLen:' + this.Results.length + ' <> PerPage:' + this.PerPage);
	
	aHTML.push('<div class="SortInstruct">Click on <img src="/DSN/wwwtheshoppingcentergroupcom/Content/Images/default/sort-arrow.gif" style="margin:0 1px 2px;"> to Sort.</div>');
	
	for(var i=0; i<this.Headers.length; i++)
		if(this.Headers[i].Width) {
			FixedWidth = false;
			break;
		}
	
	if(FixedWidth)
		txtWidth = ' style="table-layout:fixed;"';
	else
		txtWidth = ' style="table-layout:auto;"';
	
	if(typeof(rgInvestment) != 'undefined')
		aHTML.push('<table class="SearchResultsINV"' + txtWidth + '>');
	else
		aHTML.push('<table class="SearchResults"' + txtWidth + '>');
	
	if(curPage > 1)
		aHTML.push('<caption>' + this.Caption + '&nbsp;<span style="color:#000;">(PAGE ' + curPage + ' OF ' + PageCount + ')' + instruct + '</span></caption>');
	else
		aHTML.push('<caption>' + this.Caption + instruct +'</caption>');
		
	aHTML.push('<tr>');
	
	for(var i=0; i<this.Headers.length; i++)
		if((typeof(rgInvestment) != 'undefined' && this.Headers[i].Name != 'Description') ||
			typeof(rgInvestment) == 'undefined')
			if(this.Headers[i].Sortable)
				aHTML.push('<th style="width:' + ((this.Headers[i].Width)? this.Headers[i].Width + 'px' : 'auto') + '"><a href="javascript:void(' + this.Handle + '.Sort(\'' + this.Headers[i].Sort + '\'));" class="Sortable">' + this.Headers[i].Name + '</a></th>');
			else
				aHTML.push('<th style="width:' + ((this.Headers[i].Width)? this.Headers[i].Width + 'px' : 'auto') + '">' + this.Headers[i].Name + '</th>');
	
	aHTML.push('</tr>');
	
	for(var i=this.PageLBound; i<PageUBound; i++)
		aHTML.push(this.Results[i].getHTML());

	
	aHTML.push('</table>');
	
	for(var i=1; i<=PageCount; i++)
	{
		if(i != curPage)
			str += ' &nbsp;&nbsp;<a href="javascript:void(' + this.Handle + '.PageJump(' + i + '));">' + i + '</a>';
		else
			str += ' &nbsp;&nbsp;<strong>' + i + '</strong>';
	}
	
	aHTML.push('<div style="margin-top:4px;">[PAGE ' + curPage + ' OF ' + PageCount + ']' + str + '</div>');
	
	GetTag(this.HTMLID).innerHTML = aHTML.join('\n');
}

ResultGroup.prototype.PageJump = function(num)
{
	this.PageLBound = this.PerPage * (parseInt(num) - 1);
	window.location.href = '#' + this.HTMLID;
	this.Draw();
}

ResultGroup.prototype.Sort = function(prop)
{
	ResultGroup.SortBy = prop;
	
	if(this.SortDir[prop] == 'DESC') {
		this.Results.sort(ResultGroup.SortASC);
		this.SortDir[prop] = 'ASC'
	} else {
		this.Results.sort(ResultGroup.SortDESC);
		this.SortDir[prop] = 'DESC'	
	}
	
	this.PageLBound = 0;
	this.Draw();
}

ResultGroup.SortASC = function(a, b)
{
	if(a[ResultGroup.SortBy] > b[ResultGroup.SortBy]) return 1;
	if(a[ResultGroup.SortBy] < b[ResultGroup.SortBy]) return -1;
	return 0;
}

ResultGroup.SortDESC = function(a, b)
{
	if(a[ResultGroup.SortBy] < b[ResultGroup.SortBy]) return 1;
	if(a[ResultGroup.SortBy] > b[ResultGroup.SortBy]) return -1;
	return 0;
}

ResultGroup.SortBy = '';
ResultGroup.SETS = new Array();

function Result(iID, sPropName, sAddress, sState, sCity, sAgentFName, sAgentMName, sAgentLName, sEmail, sPhone, sSize, sMisc, sComments, oRGroup)
{
	this.ID = iID;
	this.Name = sPropName;
	this.Street = sAddress;
	this.State = sState;
	this.City = sCity;
	this.AgentName = sAgentFName + ((sAgentMName.length)? ' ' + sAgentMName : '') + ' ' + sAgentLName;
	this.SortName = sAgentFName;
	this.AgentEmail = sEmail;
	this.AgentPhone = (sPhone != '--')? sPhone : '';
	this.Size = parseFloat(sSize.replace(/[\,\$]*/gi, ''));
	this.Comments = sComments;
	this.PageID = oRGroup.ProductPageID;
	this.Headers = oRGroup.Headers;
	this.Misc = sMisc;
	
	this.DisplayName = '<a href="/content/Product-' + this.PageID + '-1-' + this.ID + '.htm">' + this.Name + '</a>';
	this.DisplayAgent ='<a href="mailto:' + this.AgentEmail + '">' + this.AgentName + '</a><br>' + this.AgentPhone
	
	if(typeof rgLand != 'undefined')
		this.DisplaySize = this.Size;
	else if(typeof rgInvestment != 'undefined' || typeof rgSingleTenant != 'undefined')
		if("NaN" == String(this.Size)) {
			this.DisplaySize = sSize;
		} else {
			this.DisplaySize = formatCurrency(this.Size).substr(0, formatCurrency(this.Size).length - 3);
		}
	else
		this.DisplaySize = formatCurrency(this.Size).substr(1, formatCurrency(this.Size).indexOf('.') - 1);
	
	try {
		oRGroup.Results.push(this);
	} catch(err) {
		alert(err + '\n\n[' + this.ID + '] ' + this.Name);
	}
}

Result.prototype.getHTML = function()
{
	var aHTML = new Array();
	
	aHTML.push('<tr valign="top">');
	
	if(typeof(rgInvestment) != 'undefined')
	{
		for(var i=0; i<this.Headers.length; i++)
			if(this.Headers[i].Name != 'Description')
				if((i == this.Headers.length-1) || (i == this.Headers.length-2)) {
					aHTML.push('<td style="border-bottom:0;border-left:0;">' + this[this.Headers[i].ID] + '</td>');
				} else if(i == 0) {
					aHTML.push('<td style="border-bottom:0;border-right:0;">' + this[this.Headers[i].ID] + '</td>');
				} else {
					aHTML.push('<td style="border-bottom:0;border-right:0;border-left:0;">' + this[this.Headers[i].ID] + '</td>');
				}
			else
				if(this[this.Headers[i].ID].length > 0) {
					aHTML.push('</tr><tr><td style="border-top:0;padding-bottom:8px;" colspan="' + (this.Headers.length-1)
						+ '"><strong>' + this.Headers[i].Name + ':</strong><br>' + this[this.Headers[i].ID] + '</td>');
				}
				
	} else {
		for(var i=0; i<this.Headers.length; i++)
			aHTML.push('<td>' + this[this.Headers[i].ID] + '</td>');
	}
	
	aHTML.push('</tr>');
	
	return aHTML.join('\n');
}
