var iRating = 0;
var iRevert = 0;
var bSavingRating = false;
var RatingInstance;


function ratingRevertMsg(suffix) {
	$("#divRatingDone"+suffix).html("").hide();
	$("#divRatingDesc"+suffix).show();
}


function rated(objecttypeid, objectid, value) {
	
	if ((bLoggedIn) && ( !bProfileExists)) {
		r=confirm("You must create an online profile to contact this user. Click OK to create your profile, or click 'Cancel' to return to the page.");
		if (r){
			window.location="/community/profile/userProfile.cfm";
		}
	}
	else if (!(bLoggedIn) ) {
		r = confirm("You must be logged in to your online account and MY FLW profile to contact other users. Click OK to log in or create a free account, or click 'Cancel' to return to the page.");
		if (r){
			window.location="/community/profile/login.cfm";
		}
    }
	
	
	
	
	if (!bSavingRating) {
		clearTimeout(iRevert);
		$.post(ajaxpath, {
				method:				"rateObject"
				, objecttypeid:		objecttypeid
				, objectid:			objectid
				, value:			value
				, _ct:				new Date().getTime()
			}, function(response) {
				try {
					var json = eval("("+response+")");
					if (json.RESULTS_ARRAY.length) {
						alert(json.RESULTS_ARRAY.join("\n"));
					} else {
						var suffix = "_" + objecttypeid + "_" + objectid;
						$("#ratingsdiv"+suffix).stars("select", json.CURRENTRATING);
						$("#divRatingDesc"+suffix).hide();
						$("#divRatingDone"+suffix).html(json.DONEMSG).show();
						iRevert = setTimeout("ratingRevertMsg('"+suffix+"')", 2000);
						//var instance = $("#ratingsdiv"+suffix).data("stars");
						//instance.options.disabled = true;
					}
				}
				catch (e) {
					// if we can't get comments, fail
				}
				bSavingRating = false;
			});
	}
	
}

