// This file contains the definition of a Search Result object
// It also contains the logic to write the results out on the LocationSearchAlt.asp page

function SearchResult(id, c, l, a1, a2, city, st, zip, ctry, phone, fax, lat, lon, comingsoon )
{
	this.ID = id;
	this.Code = c;
	this.Location = l;
	this.Address1 = a1;
	this.Address2 = a2;
	this.City = city;
	this.State = st;
	this.Zip = zip;
	this.Country = ctry;
	this.Phone = phone;
	this.Fax = fax;
	this.Lat = lat;
	this.Lon = lon;
	this.comingsoon = comingsoon;
}

function DisplaySearchResults()
{
	if ( ResultsArray.length == 1 )
	{
		BuildResultsTable( false );
		return;
	}
	
	var resultsLayer = new VEShapeLayer();
	map.AddShapeLayer( resultsLayer );
	//Add each result to the map
	for ( var i = 0; i < ResultsArray.length; i++ )
	{
        if ( ResultsArray[i] != null )
		{
			// Exception for newly closed restaurant #122 - 900 Mansel Road, Roswell, GA 30076
			if (ResultsArray[i].ID != '122')
			{
				var shape = new VEShape( VEShapeType.Pushpin, new VELatLong( parseFloat(ResultsArray[i].Lat), 
																			 parseFloat(ResultsArray[i].Lon ) ));
				shape.SetCustomIcon( "<div style='border:1px solid black'><img src='../images/LongHorn_25x25.gif' height='25' width='25' alt='' /></div>" );
				resultsLayer.AddShape( shape );
			}
		}
	}
	
	map.SetMapView( resultsLayer.GetBoundingRectangle() );
	BuildResultsTable( true );
}

function BuildResultsTable( foundResults )
{
    if ( foundResults )
	{
		var table = document.createElement("table");
		table.setAttribute("class", "ResultsTable");
		table.setAttribute("width", "650");
		var tbody = document.createElement("tbody");
		for ( var i = 0; i < ResultsArray.length; i += 2 )
		{
			if ( (i + 1) == ResultsArray.length )
				tbody.appendChild( BuildResultsTableRow( ResultsArray[i], null ));
			else
				tbody.appendChild( BuildResultsTableRow( ResultsArray[i], ResultsArray[i+1] ));
		}
		table.appendChild( tbody );
		document.getElementById("searchResults").appendChild( table );
	}
	else
	{
		var resultsDiv = document.getElementById("searchResults");
		resultsDiv.innerHTML = "We're Sorry. No results were found near your location";
	}
}

// Creates a row in the results table
function BuildResultsTableRow(r1, r2)
{
	var row = document.createElement("tr");
	//row.setAttribute("class", "ResultsTable");
	row.appendChild( BuildResultsTableCell( r1) );
	row.appendChild( BuildResultsTableCell( r2) );
	
	return row;
}

// Creates a Cell in the results table
function BuildResultsTableCell( r1 )
{
	var cell = document.createElement("td");
	cell.setAttribute("valign", "top");
	if ( r1 != null )
	{
if ( document.location.pathname.indexOf("/about/FeedBackPopUpResult.asp") != -1 )

 

{

 

  cell.innerHTML = "<a href='/process.asp?recordid=" + r1.ID + "&address=" + r1.Address1 +"&city=" + r1.city + "&state=" + r1.state + "&zip=" + r1.zip + "'>" + r1.Address1 +"</a><br/>";
  cell.innerHTML += r1.City + ", " + r1.State + " " + r1.Zip + "<br/>";
	

}

		
	
		else
		{
			cell.innerHTML = "<a href='map.asp?RestaurantID=" + r1.ID + "'>" + r1.Location +"</a><br/>";
	if ( String(r1.comingsoon) == "1" )
	{
		cell.innerHTML += "<span style='color:red;font-weight: bold;'>Coming Soon</span><br/>";//coming soon
	}
			cell.innerHTML += r1.Address1 + " " + r1.Address2 + "<br/>";
			cell.innerHTML += r1.City + ", " + r1.State + " " + r1.Zip + "<br/>";
			cell.innerHTML += "Phone: " + r1.Phone + "<br/>";
			cell.innerHTML += "Fax: " + r1.Fax + "<br/>";	
		}
	}
	return cell;
}


