/**
 * PlusRater
 * Javascript object to handle ratings for Plus anime/manga.
 *
 * @author Jared Armstrong
 *
 */
var PlusRater = {
	animeId: "",
	type: "anime",
	ratingInfo: {},
	
	construct: function(animeId, type, ratingButton, ratingText, f1, f2, f3, f4) {
		this.animeId = animeId;
		this.type = type;
    this.ratingButton = ratingButton; 
    this.ratingText = ratingText;
    this.f1 = f1;
    this.f2 = f2;
    this.f3 = f3;
    this.f4 = f4;
	},
	
	postRating: function() { 
		this.disablePostRating();
		$('#' + this.ratingText).html("Please wait, submitting rating...").removeClass('warningnotice').addClass('infonotice');
		$.post("/cgi/Procedures.PlusRate", {
  		  "animeid": this.animeId,
  			"type": this.type, 
  			"rate_f1": $("#" + this.f1).val(),
  			"rate_f2": $("#" + this.f2).val(),
  			"rate_f3": $("#" + this.f3).val(),
  			"rate_f4": $("#" + this.f4).val()
			}, function(response) {
					eval(response);
			});
	},
	
	showRatingDone: function() {
		$('#' + this.ratingText).html("Your rating was added to our records! Thank you for your input.").removeClass('warningnotice').addClass('infonotice');
	},
	
	disablePostRating: function() {
	  $('#' + this.ratingButton).attr('disabled', true);
	},
	
	enablePostRating: function() { 
		$('#' + this.ratingText).html("");
    $('#' + this.ratingButton).attr('disabled', false).mouseup().mouseout();
	},
	
	
	/**
	 * Run when invalid info is passed to post rating.
	 */
	returnInvalid: function() {
		this.enablePostRating();
		$('#' + this.ratingText).html("Please select a rating for all categories.").removeClass('infonotice').addClass('warningnotice');
	},
	
	returnError: function() {
		this.enablePostRating();
		$('#' + this.ratingText).html("A system error occurred while recording your rating. Please try again.").removeClass('infonotice').addClass('warningnotice');
	},
	
	returnNotLogged: function() {
		$('#' + this.ratingText).html("You must <a href=\"/login/\">login</a> before you can submit ratings.").removeClass('infonotice').addClass('warningnotice');
	},
	
	returnAlreadyRated: function() {
		$('#' + this.ratingText).html("You can't rate this series because you have already submitted a rating.").removeClass('infonotice').addClass('warningnotice');
	},
	
	returnDone: function() {
		this.showRatingDone();	
	}
}
