
var Ratings = {};
var rating = 0;

Ratings = {
  initRatingWindow: function() {
	var el = document.getElementById("ratingcomment_rating");
	Ratings.setRating(el.getAttribute("value"));
  },

  setRating: function(r) {
    rating = r;
    
	// find element and set it to this value
	var el = document.getElementById("ratingcomment_rating");
	el.setAttribute("value",rating);
	
	var shownRating = rating;
	if (-1 == rating) {
		shownRating = 0;
	}
	
	// now set number of stars with star / stargrey .png
	for (var i = 1;i<=5;i++) {
		el = document.getElementById("rating-" + i);
		if (i <= shownRating) {
			el.setAttribute("src","/images/theme/star.png");
		} else {
			el.setAttribute("src","/images/theme/star-grey.png");
		}
	}
  },

  openRatingWindow: function(ableclass,ableid) {
	if (window.showModalDialog("/application/ratingnew?ableclass=" + ableclass + "&ableid=" + ableid,
	  null,"dialogHeight:370px;dialogWidth:640px;") == true) {
		// success
		setTimeout("window.location.reload()",1);
	} else {
		// failure
	}
  },

  sendSuccess: function() {
  	window.returnValue=true;
  	window.close();
  },

  sendCancel: function() {
  	window.returnValue=false;
  	window.close();
  }
}
