/**
 * Rating rendering functionality for rating temaplte 3.ascx
 */

// GLOBAL VARIABLES & CONSTANTS
var _AltImagePath = "/img/slideshow/global/stars_on.gif,/img/slideshow/global/stars_off.gif,/img/slideshow/global/stars_on.gif";
var _IntroText = "Rate this pic";
var _ExistingRatingText = "You rated this pic ";
var _CurrentRatingText = "Current rating by";
var _AverageRatingText = "Overall average rating by ";
var _EnforceSecurity = true;
var _CookieExpiry = 1;

function showRatingsForSlideshow(objectId,onclickcode)
{
	var _maxRating = eval("_maxRating_" + objectId);
	var _rated = eval("_rated_" + objectId);
	var _arrImages = eval("_arrImages_" + objectId);
	var _ratedValue = null;
	var _aspect = eval("_aspect_" + objectId);
	if(_arrImages  && _arrImages == "")
	{
		_arrImages = _AltImagePath.split(",");
	}
	var _currentRating = eval("_currentRating_" + objectId);
	var _ratingTotal = eval("_ratingTotal_" + objectId);
	var _averageRating = Math.floor(parseInt(_currentRating) / parseInt(_ratingTotal));
	
	var _lDivObject;
	if(objectId != "m")
	{
		_lDivObject = document.getElementById("RatingContainer_" + objectId);
	}
	else
	{
		_lDivObject = document.getElementById("RatingContainer_multi");
	}	
	var _lCode = "";
	var _uCode = "";
	if(_blnNoPost == false)
	{
		_uCode = "<div class='UserRating'><span id='UserRateMsg_" + objectId + "' class='UserRating_text'>" + (isNullOrEmpty(_aspect) ? (isNullOrEmpty(JS_RATING_RATETHISITEM) ? _IntroText : JS_RATING_RATETHISITEM) : _aspect) + " </span><span class='UserRating_img'>" + " ";
	}
	else
	{
		_uCode = "<div class='UserRating'><span id='UserRateMsg_" + objectId + "' class='UserRating_text'></span>";
	}
	try
	{
		if(_EnforceSecurity == true)
		{
			_ratedValue = checkRatingCookie(objectId);
		}
		
		for(var cnt=0;cnt<_maxRating;cnt++)
		{
			if(objectId != "m" && _blnNoPost == false)  
			{
				_uCode = _uCode + "<img class=ratingImages id=img_" + objectId + "_" + cnt + " src='" + _arrImages[1] + "' " + onclickcode + " alt='Click to rate: " + (cnt+1) + " out of " + _maxRating + "' >";
			}
			if(cnt < _averageRating)
			{
				_lCode = _lCode + "<img class=avgImages  src='" + _arrImages[0] + "' alt='Rating value: " + (cnt+1) + " out of " + _maxRating + "' >";
			}
			else
			{
				_lCode = _lCode + "<img class=avgImages  src='" + _arrImages[1] + "' alt='Rating value: " + (cnt+1) + " out of " + _maxRating + "' >";
			}
		}
		if(_ratedValue != null)
		{	
			var _uCode = "<div class='UserRating'><span id='UserRateMsg_" + objectId + "' class='UserRating_text'>" + (isNullOrEmpty(JS_RATING_YOURATEDTHISITEM) ? _ExistingRatingText : JS_RATING_YOURATEDTHISITEM) + "</span><span class='UserRating_img'>" + " ";

			for(var cnt=0;cnt<_maxRating;cnt++)
			{
				if(cnt<parseInt(_ratedValue))
				{
					_uCode = _uCode + "<img class=avgImages  src='" + _arrImages[0] + "' alt='Rating value: " + (cnt+1) + " out of " + _maxRating + "' >";
				}
				else
				{
					_uCode = _uCode + "<img class=avgImages  src='" + _arrImages[1] + "' alt='Rating value: " + (cnt+1) + " out of " + _maxRating + "' >";
				}			
			}
		}
		if(objectId != "m" && _blnNoPost == false)
		{
			_lCode = "<div class='RatingContainer'>" +  _uCode + " " + "</span></div><div id=ratingAvg_" + objectId + " class=ratingAvg><span class='ratingAvg_text'>" + (isNullOrEmpty(JS_RATING_CURUSERRATEBY) ? _CurrentRatingText : JS_RATING_CURUSERRATEBY) + " " + _ratingTotal +" users: </span><span class='ratingAvg_img'>" + _lCode + "</span></div>";					

		}
		else if(objectId != "m" && _blnNoPost == true)
		{
			_lCode = "<div class='RatingContainer'>" +  _uCode + "</div><div id=ratingAvg_" + objectId + " class=ratingAvg><span class='ratingAvg_text'>" + (isNullOrEmpty(JS_RATING_CURUSERRATEBY) ? _CurrentRatingText : JS_RATING_CURUSERRATEBY) +" "+ _ratingTotal +" users: </span><span class='ratingAvg_img'>" + _lCode + "</span></div>";					
		}
		else
		{
			//get the total number of aspects for this multi-rating
			var _NoOfMultiRatingAspects = window["_NoOfMultiRatingAspects_" + objectId];
			var _totalNoOfUsers = 0; //default value is zero total no. of users on error
			if (!_NoOfMultiRatingAspects || _NoOfMultiRatingAspects <= 0)
			{
				alert("Multi Rating Exception: variable '_NoOfMultiRatingAspects' is missing or has an invalid value.");
			}
			else
			{
				_totalNoOfUsers = Math.ceil(_ratingTotal / _NoOfMultiRatingAspects);
			}
			_lCode = "<div class='RatingContainer'><div id=ratingAvg_" + objectId + " class=ratingAvg>"+ _AverageRatingText + _totalNoOfUsers +" users: " + _lCode + "</span></div>";
		}
		_lDivObject.innerHTML = _lCode + "</div>";
	}
	catch(e)
	{
	}
}