function loadData() {

	var box = map.getBounds();		

	var searchUrl = "retrieveSales.php?sw=" + box.getSouthWest() + "&ne=" + box.getNorthEast();			
		  
	GDownloadUrl(searchUrl, function(data) {
		var xml = GXml.parse(data);
		var markers = xml.documentElement.getElementsByTagName('marker');
		
		var sidebar = document.getElementById('sidebar');
		sidebar.innerHTML = '';
		if (markers.length == 0) {
			sidebar.innerHTML = '<p class="body">Sorry, there are no sales in this area.  Try zooming out to find more sales.</p>';
		}
		else
		{
			//Clear the sidebar
			sidebar.innerHTML = '';
		}
		
		tempMarkers = [];
		
		//Clear the newMarkers Array
		while (newMarkers.length > 0)
		{
			junk = newMarkers.pop();
		}
		
		var bounds = new GLatLngBounds();
		for (var i = 0; i < markers.length; i++)
		{
			
			var id = markers[i].getAttribute('id');
			var title = markers[i].getAttribute('title');
			var address = markers[i].getAttribute('address');
			var city = markers[i].getAttribute('city');
			var state = markers[i].getAttribute('state');
			var zipcode = markers[i].getAttribute('zipcode');
			var day1 = markers[i].getAttribute('day1');
			var day1start = markers[i].getAttribute('day1start');
			var day1end = markers[i].getAttribute('day1end');
			var day2 = markers[i].getAttribute('day2');
			var day2start = markers[i].getAttribute('day2start');
			var day2end = markers[i].getAttribute('day2end');
			var day3 = markers[i].getAttribute('day3');
			var day3start = markers[i].getAttribute('day3start');
			var day3end = markers[i].getAttribute('day3end');
			var description = markers[i].getAttribute('description');
			var email = markers[i].getAttribute('email');
			var contact = markers[i].getAttribute('contact');
			var created = markers[i].getAttribute('created');
			var modified = markers[i].getAttribute('modified');
			var status_id = markers[i].getAttribute('status_id');
			var point = new GLatLng(parseFloat(markers[i].getAttribute('latitude')),parseFloat(markers[i].getAttribute('longitude')));

			var htmlContent = generateHTML(id, title, address, city, state, zipcode,day1,day1start,day1end,day2,day2start,day2end,day3,day3start,day3end,description,email,contact,created,modified,status_id);

			//Check to see if the marker exists already
			exists = false;
			existingMarkerID = "";
			
			for (n=0;n<existingMarkers.length;n=n+1) 
			{
    			if (String(existingMarkers[n].getLatLng()) == String(point))
    			{
    				existingMarkerID = n;
    				exists = true;
    			}
			}
			
			
			var marker = createMarker(point, id, title, address, city, state, zipcode,day1,day1start,day1end,day2,day2start,day2end,day3,day3start,day3end,description,email,contact,created,modified,status_id,htmlContent);

			if (exists == false)
			{
				map.addOverlay(marker);
				tempMarkers.push(marker);
			}

			newMarkers.push(marker);

			var sidebarEntry = createSidebarEntry(existingMarkers[existingMarkerID], id,title, description,htmlContent);
			sidebar.appendChild(sidebarEntry);

		}
		
		//Loop through the old markers to see if any of them need to be removed
		if (existingMarkers.length > 0)
		{
			if (newMarkers.length == 0)
			{
				map.clearOverlays();
				
				//Clear existing markers
				while (existingMarkers.length > 0)
				{
					junk = existingMarkers.pop();
				}				
			}
			else
			{
				
				for (x=0;x<existingMarkers.length;x=x+1) 
				{			
					remove = true;
					
					for (v=0;v<newMarkers.length;v=v+1) 
					{
						if (String(newMarkers[v].getLatLng()) == String(existingMarkers[x].getLatLng()))
						{
							remove = false;
						}
					}
					
					if (remove == true)
					{
						map.removeOverlay(existingMarkers[x]);
					}
					else
					{
						tempMarkers.push(existingMarkers[x]);
					}
				}
				
				//Clear the existing Markers and replace with tempMarkers
				//Clear the existing Array
				while (existingMarkers.length > 0)
				{
					junk = existingMarkers.pop();
				}
				
				//Add the tempMarkers to existingMarkers
				for (d=0;d<tempMarkers.length;d=d+1) 
				{
					existingMarkers.push(tempMarkers[d]);
				}				
				
			}
		}
		else
		{
			//Add all the new markers to existing
			for (d=0;d<newMarkers.length;d=d+1) 
			{
				existingMarkers.push(newMarkers[d]);
			}
		}
						
	});
	
}

function createMarker(point, id, title, address, city, state, zipcode,day1,day1start,day1end,day2,day2start,day2end,day3,day3start,day3end,description,email,contact,created,modified,status_id,htmlContent) {

	var marker = new GMarker(point);
	
	var htmlTab1 = "<p class='body'><strong>"+title+"</strong><br />"+htmlContent;
  
	var htmlTab2 = "<p class='body'>"+description+"</p>";
  
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml([new GInfoWindowTab("Sale",htmlTab1), new GInfoWindowTab("Items",htmlTab2)],{maxWidth:200});
	});
	
	return marker;
}


function createSidebarEntry(marker, id,title, description,htmlContent) {
  var div = document.createElement('div');
  
  var html = '<p class="body"><a class="title" href="#">' + title + '</a><br />' + htmlContent + '</p>';  div.innerHTML = html;
  
  div.style.cursor = 'pointer';
  div.style.marginBottom = '5px';
  GEvent.addDomListener(div, 'click', function() {
    GEvent.trigger(marker, 'click');
  });
  GEvent.addDomListener(div, 'mouseover', function() {
    div.style.backgroundColor = '#eee';
  });
  GEvent.addDomListener(div, 'mouseout', function() {
    div.style.backgroundColor = '#fff';
  });
  return div;
}


function generateHTML(id, title, address, city, state, zipcode,day1,day1start,day1end,day2,day2start,day2end,day3,day3start,day3end,description,email,contact,created,modified,status_id) {

	//Set up the weekday conversions  
	var weekday=new Array(7);
	weekday[0]="SUN";
	weekday[1]="MON";
	weekday[2]="TUE";
	weekday[3]="WED";
	weekday[4]="THU";
	weekday[5]="FRI";
	weekday[6]="SAT";
	
	var monthtext=new Array(13);
	monthtext['00']="";
	monthtext['01']="Jan";
	monthtext['02']="Feb";
	monthtext['03']="Mar";
	monthtext['04']="Apr";
	monthtext['05']="May";
	monthtext['06']="Jun";   
	monthtext['07']="Jul"; 
	monthtext['08']="Aug"; 
	monthtext['09']="Sep"; 
	monthtext['10']="Oct"; 
	monthtext['11']="Nov"; 
	monthtext['12']="Dec"; 
	
	var timetext=new Array(24);
	timetext['00']="12AM";
	timetext['01']="1AM";
	timetext['02']="2AM";
	timetext['03']="3AM";
	timetext['04']="4AM";
	timetext['05']="5AM";
	timetext['06']="6AM";   
	timetext['07']="7AM"; 
	timetext['08']="8AM"; 
	timetext['09']="9AM"; 
	timetext['10']="10AM"; 
	timetext['11']="11AM"; 
	timetext['12']="12PM";
	timetext['13']="1PM"; 
	timetext['14']="2PM"; 
	timetext['15']="3PM"; 
	timetext['16']="4PM"; 
	timetext['17']="5PM"; 
	timetext['18']="6PM"; 
	timetext['19']="7PM"; 
	timetext['20']="8PM"; 
	timetext['21']="9PM"; 
	timetext['22']="10PM"; 
	timetext['23']="11PM"; 
	
	//Set the date variables
	var day1Temp = new Date();
	var day2Temp = new Date();
	var day3Temp = new Date();
	
	day1Temp.setFullYear(day1.slice(0,4),day1.slice(5,7)-1,day1.slice(8,10));
	day2Temp.setFullYear(day2.slice(0,4),day2.slice(5,7)-1,day2.slice(8,10));
	day3Temp.setFullYear(day3.slice(0,4),day3.slice(5,7)-1,day3.slice(8,10));
  
	var htmlTab1 = "<strong>"+weekday[day1Temp.getDay()]+". "+monthtext[day1.slice(5,7)]+". "+day1.slice(8,10)+"</strong> : "+timetext[day1start.slice(0,2)]+" to "+timetext[day1end.slice(0,2)]+"<br />";

	if (day2Temp.getFullYear() != -1)
	{
		htmlTab1 = htmlTab1 + "<strong>"+weekday[day2Temp.getDay()]+". "+monthtext[day2.slice(5,7)]+". "+day2.slice(8,10)+"</strong> : "+timetext[day2start.slice(0,2)]+" to "+timetext[day2end.slice(0,2)]+"<br />";
	}

	if (day3Temp.getFullYear() != -1)
	{
		htmlTab1 = htmlTab1 + "<strong>"+weekday[day3Temp.getDay()]+". "+monthtext[day3.slice(5,7)]+". "+day3.slice(8,10)+"</strong> : "+timetext[day3start.slice(0,2)]+" to "+timetext[day3end.slice(0,2)]+"<br />";
	}  
  
  	htmlTab1 = htmlTab1 + address+"<br />"+city+", "+state+" "+zipcode;
  	
  	if (contact == 1)
  	{
//  		htmlTab1 = htmlTab1 + "<br /><a href='#' onClick='return (email("+id+")'><img src='images/searchEmailDetails.gif' alt='Contact Seller' width='85' height='10' border='0' /></a>";
  	}
  
	htmlTab1 = htmlTab1 + "<br /><a target='blank' href='printerfriendly.php?id="+id+"'>Print Sale</a></p>";
  
	return (htmlTab1);
}

