var openHouses = new Array();
var showDate = new Date();
showDate.setDate(showDate.getDate()-1);	
function openHouse(id, start, end){
	this.id = id;
	this.start = start;
	this.end = end;
}
function addOpenHouse(id, start, end){
	o = new openHouse(id, start, end);
	openHouses.push(o);
}
function showOpenHouseDetails(){
	var valid = false;
	var str = "Open House:<ul>";
	for (var i=0; i<=openHouses.length; i++){
		if (i < openHouses.length){
			if (openHouses[i].start > showDate){
				valid = true;
				str += "<li class=\"OpenHouseTime\">";
				str += openHouses[i].start.format('DDDD, MMMM D, YYYY h:mm tt');
				str += " to ";
				if (openHouses[i].start.getDate() != openHouses[i].end.getDate())
				 str += openHouses[i].end.format('DDDD, MMMM D, YYYY h:mm tt');
				else
				str += openHouses[i].end.format('h:mm tt');
				str += "</li>";
			}
		}			
	}
	if (valid){
		var node = document.getElementById('openHouses'+openHouses[0].id);		
		str += "</li>";	
		node.innerHTML = str;
		node.style.display = "block";
	}
}
function showOpenHouseLinks(){
	var firstInGroup = true;
	var valid = false;
	var curID = 0;
	var str = "";
	for (var i=0; i<=openHouses.length; i++){
		if ((i == openHouses.length  || (curID != 0 && curID != openHouses[i].id)) && valid){
			var node = document.getElementById('openHouses'+curID);			
			node.title = str;
			node.style.display = "block";
			str = ""; 
			firstInGroup = true;
			valid = false;
		}
		if (i < openHouses.length && !(valid)){
			curID = openHouses[i].id;
			if (openHouses[i].start > showDate){
				valid = true;
				str += "Open House: "
				str += openHouses[i].start.format('DDDD, MMMM D, YYYY h:mm tt');
				str += " to ";
				if (openHouses[i].start.getDate() != openHouses[i].end.getDate())
				 str += openHouses[i].end.format('DDDD, MMMM D, YYYY h:mm tt');
				else
				 str += openHouses[i].end.format('h:mm tt');
			}
		}			
	}	
}
