/**
 * @author john
 */
function getDateString(saleObj) {
	var dateObj = new Date();
	var thisMonth = (dateObj.getMonth()+1);
	if(thisMonth < 10)
		thisMonth = "0" + thisMonth;
	var todaysDate = dateObj.getFullYear() + '-' + thisMonth + '-' + dateObj.getDate();
	var dateString = "";
	if(todaysDate >= saleObj.properties.saleStartDate) {
		dateString = dateToString(saleObj.properties.saleEndDate + " " + saleObj.properties.saleStartTime);
	} else {
		dateString = dateToString(saleObj.properties.saleStartDate + " " + saleObj.properties.saleStartTime);
	}
	return dateString;
}
 
var sfrListCons = function(iObj) {
	var color = bgcolors[iObj.idx % 2];
	var dateString = getDateString(iObj);
	var output = '<div id="' + color + '" class="leftBox clickableRow" onmouseover="HL.hl(this)" onmouseout="HL.uhl(this)" onclick="RM.listItemClick(\'' + iObj.parent.id + '\', ' + iObj.idx + ')">';
	output += '<p class="boxTxt"><span class="numBox">' + (Number(iObj.idx) + 1) + '</span><span class="listTitle">' + iObj.properties.title + '</span><strong>' + dateString + '</strong><br />';
	output += 'Source: ' + siteTitle + '<br class="spacer" />';
	output += "</p></div>";
	
	return output;
}

var sfrMapClick = function(iObj) {
	lastItemClicked = iObj;
	tabView.set('activeIndex', 0);
	map.checkResize();
	var href = 'RM.openTab(\'' + iObj.parent.id + '\', ' + iObj.idx + ');';
	var IThref = 'RM.addToItinerary(\'' + iObj.parent.id + '\', ' + iObj.properties.id + ');';
	var dateString = getDateString(iObj);
	
	var output = "<div id='maplisting'>";
	output += "<table cellspacing='0' cellpadding='0' width='280' id='mapTable'>";
	output += "<tr><td colspan='2' class='mapTitle' align='center'><a href=\"javascript: " + href + "\">" + iObj.properties.title + "</a></td>";
	output += "<tr><td colspan='2' class='mapDate'>" + dateString + "</td>";
	output += "<tr><td colspan='2' class='mapDescription'>" + iObj.properties.description + "</td>";
	output += "<tr><td id='viewDetails' class='greenBtn' align='center' valign='middle'><a href=\"javascript: " + href + "\" alt='View Sale Details'>View Sale Details</a></td>";
	output += "<td id='addIt' align='center' class='greenBtn' valign='middle'><a href=\"javascript: " + IThref + "\" alt='Add to Itinerary'>Add to Itinerary</a></td></tr>";
	output += "</table></div>";
	iObj.marker.openInfoWindowHtml(output);
}

var sfrAddItinerary = function(iObj) {
	lastItemAdded = iObj;
	map.checkResize();
	requestUrl = "mygarage/itinerary/add.php?name=" + iObj.properties.title + "&lat=" + iObj.properties.location.lat + "&lon=" + iObj.properties.location.lon + "&id=" + iObj.properties.id;
	var request = YAHOO.util.Connect.asyncRequest('GET', requestUrl, {success: evaluator, failure: this.logError});
}

var getSfrTab = function(iObj) {
	var tab = new YAHOO.widget.Tab({
		label: TM.getTabLabel(trunc(iObj.properties.tabTitle, 23)),
		content: TM.getIframeCode(iObj.properties.url),
		active: true
	});
	tab.url = iObj.properties.url;
	tab.parent = cloneObjectForTab(iObj);
	TM.addTab(iObj.properties.url, tab);
	prepareActions(tab);
}