doRate = function(type, id, score, savingTxt, savedTxt, scoreCount) {

	lockRating(type, id, score, savingTxt, scoreCount);

	http(
		"post",
		"/ratings/components/ratings.cfc?method=rate", 
		function(obj) {
			ratingsStatus(type, id, savedTxt);
			var tmp = document.getElementById("ratings_count_" + type + "_" + id);
			if (tmp) {
				tmp.innerHTML = obj.total;
			}
		},
		{
			type: type,
			id: id,
			score: score
		}
	);
}

ratingsStatus = function(type, id, statusMessage, total) {
	var tmp = document.getElementById("rating_status_" + type + "_" + id);
	if (tmp) {
		tmp.innerHTML = statusMessage;
	}
}

lockRating = function(type, id, score, statusText, scoreCount) {
	for (var i = 1; i <= scoreCount; i++) {
		var tmp = document.getElementById("ratings_star_" + type + "_" + id + "_" + i);
		tmp.onmouseover = function() {};
		tmp.onmouseout = function() {};
		tmp.onclick = function() {};
	}
	tmp = document.getElementById("current_stars_" + type + "_" + id);
	tmp.onmouseover = function() {};
	tmp.className = "rated";
	tmp = document.getElementById("picking_stars_" + type + "_" + id);
	tmp.onmouseout = function() {};
	tmp.className = "rated";
	showPicker(type, id);
	scoreHover(type, id, score, statusText);
}

scoreHover = function(type, id, score, statusText) {
	clearCurrent(type, id);
	
	for (var i = 1; i <= score; i++) {
		document.getElementById("ratings_star_" + type + "_" + id + "_" + i).className = "star_pick";
	}
	ratingsStatus(type, id, statusText);
}

clearHover = function(type, id, score, scoreCount) {
	for (var i = score; i <= scoreCount; i++) {
		document.getElementById("ratings_star_" + type + "_" + id + "_" + i).className = "star_off";
	}
}

showPicker = function(type, id) {
	doHide(document.getElementById("current_stars_" + type + "_" + id));
	doShow(document.getElementById("picking_stars_" + type + "_" + id));
}

timeouts = new Object();
showCurrent = function(type, id, statusText, scoreCount) {
	timeouts[type + "_" + id] = setTimeout(
		function() {
			delayedCurrent(type, id, statusText, scoreCount);
		},
		250
	);
}

delayedCurrent = function(type, id, statusText, scoreCount) {
	doHide(document.getElementById("picking_stars_" + type + "_" + id));
	doShow(document.getElementById("current_stars_" + type + "_" + id));
	ratingsStatus(type, id, statusText);
	clearHover(type, id, 1, scoreCount);
}

clearCurrent = function(type, id) {
	if (timeouts[type + "_" + id] && timeouts[type + "_" + id] != null) {
		clearTimeout(timeouts[type + "_" + id]);
		timeouts[type + "_" + id] = null;
	}
}

doHide = function(obj) {
	obj.style.display = "none";
	obj.style.visibility = "hidden";
}
doShow = function(obj) {
	obj.style.display = "inline";
	obj.style.visibility = "visible";
}

currentADA = null;
doADA = function(type, id, enabled) {
	closeCurrentADA();
	if (enabled) {
		adaDiv = document.getElementById("rating_ada_" + type + "_" + id);
		adaDiv.style.display = "block";
		adaDiv.style.visibility = "visible";
	} else {
		adaDiv = document.getElementById("rating_ada_" + type + "_" + id + "_disabled");
		adaDiv.style.display = "block";
		adaDiv.style.visibility = "visible";
	}
	currentADA = adaDiv;
}
lockADA = function(type, id) {
	document.getElementById("ada_link_" + type + "_" + id).onclick = function() {
		doADA(type, id, false);
		return false;
	}
}
closeCurrentADA = function() {
	if (currentADA != null) {
		currentADA.style.display = "none";
		currentADA.style.visibility = "hidden";
		currentADA = null;
	}
}
cancelADA = function(type, id) {
	closeCurrentADA();
	document.getElementById("ada_link_" + type + "_" + id).focus();
	return false;
}
submitADA = function(form, type, id, savingTxt, savedTxt, scoreCount) {
	score = radioSelectedValue(form["score_" + type + "_" + id]);
	closeCurrentADA();
	lockADA(type, id);
	document.getElementById("ada_link_" + type + "_" + id).focus();
	doRate(type, id, score, savingTxt, savedTxt, scoreCount);
}


function radioSelectedValue(radioObject) {
	for (i=0; i<radioObject.length; i++) {
		if (radioObject[i].checked) {
			return radioObject[i].value;
		}
	}
	return false;
}

