function showSidebar(src, contentType)
{
	var httpreq;
	var rh_col = document.getElementById("col_right");
	var bodyHTML;
	var xml_content;
	var html_content;
	
	if (window.XMLHttpRequest)
	{
		httpreq = new XMLHttpRequest();
	}
	else
	{
		try
		{
			httpreq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (exception)
		{
			httpreq = false;
		}
	}
	
	if (httpreq == false)
	{
		alert("Your browser either does not support\n"
		+ "the functions required for this site,\n"
		+ "or your security settings are too strict\n"
		+ "for this page to run correctly.\n\n"
		+ "Please update your browser and check your settings,\n"
		+ "then try again.");
	}
	else
	{
		try
		{
			xml_content = getContent(httpreq, src, "text/xml").responseXML;
			rh_col.innerHTML = "<table id=\"listings_pane\"></table>";
			
			if (contentType == "listing")
			{
				genListingMenu(xml_content, document.getElementById("listings_pane"));
			}
			else if (contentType == "feat")
			{
				genFeaturedMenu(xml_content, document.getElementById("listings_pane"));
			}
			else if (contentType == "links")
			{
				genLinksMenu(xml_content, document.getElementById("listings_pane"));
			}
		}
		catch (exception)
		{
			rh_col.innerHTML = "<p>An error was encountered</p>";
		}
		
	}
}

function getContent(httpreq, uri, mime)
{
	httpreq.overrideMimeType(mime);
	httpreq.open("GET", uri, false);
	httpreq.send("");
	return httpreq;
}

function genLinksMenu(menuXML, menu)
{
	var links = menuXML.getElementsByTagName("LINK");
	var i;
	var cellContent;
	var curCell;
	var curRow;
	var link;
	var href;
	var title
	
	curRow = menu.insertRow(0);
	curCell = curRow.insertCell(0);
	curCell.innerHTML = "<h3></h3>";
	
	for (i = 0; i < links.length; i++)
	{
		curRow = menu.insertRow(i + 1);
		curCell = curRow.insertCell(0);
		link = links[i];
		
		href = getXMLValue(link, "HREF");
		title = getXMLValue(link, "TITLE");
		
		cellContent = "<span><a href=\"" + href + "\">" 
			+ title + "</a></span>";
		
		curCell.innerHTML = cellContent;
	}
}

function genListingMenu(menuXML, menu)
{
	var listings = menuXML.getElementsByTagName("LISTING");
	var i;
	var cellContent;
	var curCell;
	var curRow;
	var unit;
	var mls;
	var addr;
	var city;
	var state;
	var zip;
	var price;
	var link;
	
	curRow = menu.insertRow(0);
	curCell = curRow.insertCell(0);
	curCell.innerHTML = "<h3>For Sale</h3>";
	
	for (i = 0; i < listings.length; i++)
	{
		curRow = menu.insertRow(i + 1);
		curCell = curRow.insertCell(0);
		unit = listings[i];
		
		mls = getXMLValue(unit, "MLS");
		addr = getXMLValue(unit, "ADDRESS");
		city = getXMLValue(unit, "CITY");
		state = getXMLValue(unit, "STATE");
		zip = getXMLValue(unit, "ZIP");
		price = getXMLValue(unit, "PRICE");
		link = getXMLValue(unit, "LINK");
		
		cellContent = "<span><a href=\"" + link + "\">" + mls
			+ "</a><br />" + addr + "<br />" + city + ", "
			+ state + " " + zip + "<br />" + price + "</span>";
		
		curCell.innerHTML = cellContent;
	}
}

function genFeaturedMenu(menuXML, menu)
{
	//Modified genListingMenu to adjust format and allow images.
	//Can still work with multiple listings, but just one will work fine as well.
	
	var listings = menuXML.getElementsByTagName("LISTING");
	var i;
	var cellContent;
	var curCell;
	var curRow;
	var unit;
	var mls;
	var addr;
	var city;
	var state;
	var zip;
	var price;
	var link;
	var picture;
	
	curRow = menu.insertRow(0);
	curCell = curRow.insertCell(0);
	curCell.innerHTML = "<h3></h3>";
	
	for (i = 0; i < listings.length; i++)
	{
		curRow = menu.insertRow(i + 1);
		curCell = curRow.insertCell(0);
		unit = listings[i];
		
		mls = getXMLValue(unit, "MLS");
		addr = getXMLValue(unit, "ADDRESS");
		city = getXMLValue(unit, "CITY");
		state = getXMLValue(unit, "STATE");
		zip = getXMLValue(unit, "ZIP");
		price = getXMLValue(unit, "PRICE");
		link = getXMLValue(unit, "LINK");
		picture = getXMLValue(unit, "PICTURE");
		
		cellContent = "<span><a href=\"" + link + "\"><img src=\""
			+ picture + "\" alt=\"Featured Listing\"><br />" + mls
			+ "</a><br />" + addr + "<br />" + city + ", "
			+ state + " " + zip + "<br />" + price + "</span>";
		
		curCell.innerHTML = cellContent;
	}
}

function getXMLValue(item, name)
{
	return item.getElementsByTagName(name)[0].childNodes[0].nodeValue;
}

function showMenu(menuID, xmlURI, type)
{
	thisButton = document.getElementById(menuID);
	menuTableActive = document.getElementsByName("menubtn");
	var i;
	
	if (thisButton.class != "activebtn")
	{
		for (i = 0; i < menuTableActive.length; i++)
		{
			menuTableActive[i].class = "menu";
		}
		thisButton.class = "activebtn";
		showSidebar(xmlURI, type);
	}
	else
	{
		thisButton.class = "menu";
		showSidebar('feat.xml', 'feat');
	}
}
