/**
 * Init Recommendations
 * 
 * This method takes the following parameters:
 * 1) The ID of the recommendation.
 * 
 * The following HTML id components are expected to exist:
 * 1) #ID#_yes
 * 2) #ID#_no
 * 3) #ID#_yesCount
 * 4) #ID#_noCount
 * 
 * where '#ID#' is to be replaced by the recommendation ID, such as "families", "couples", etc.
**/

function initRecommendations(id)
{
	var yes = $(id + "_yes");
	var no = $(id + "_no");

	yes.onclick = function(event)
	{
		// Create and fire off AJAX request
		var params = "listingID=" + myListingID;
		params += "&type=" + id;
		params += "&vote=1";
		params += "&userID=" + client.userID;
		params += "&cfToken=" + client.cfToken;
		ajax("POST", "/cfc/listings.cfc?method=recommendListingRPC", ajaxFinished, null, params);

		// Update div
		yes.src = "/images/yesButton.gif";
		no.src = "/images/noButtonInactive.gif";
	}

	no.onclick = function(event)
	{
		// Create and fire off AJAX request
		var params = "listingID=" + myListingID;
		params += "&type=" + id;
		params += "&vote=0";
		params += "&userID=" + client.userID;
		params += "&cfToken=" + client.cfToken;
		ajax("POST", "/cfc/listings.cfc?method=recommendListingRPC", ajaxFinished, null, params);

		// Update div
		yes.src = "/images/yesButtonInactive.gif";
		no.src = "/images/noButton.gif";
	}

	function ajaxFinished(recommendationStruct)
	{
		$(id +"_yesCount").innerHTML = recommendationStruct.yes;
		$(id + "_noCount").innerHTML = recommendationStruct.total - recommendationStruct.yes;
	}
}

