var onLoadFunctionList=onLoadFunctionList||[];
function performOnLoadFunctions(){
for(var i=0;i<onLoadFunctionList.length;i++){
onLoadFunctionList[i]();
}
}
function removeClass(element,_class){
var upperClass=_class.toUpperCase();
var remainingClasses=[];
if(element.className){
var classes=element.className.split(' ');
for(var i=0;i<classes.length;i++){
if(classes[i].toUpperCase()!=upperClass){
remainingClasses[remainingClasses.length]=classes[i];
}
}
element.className=remainingClasses.join(' ');
}
}

var UT_RATING_IMG='icn_star_full_19x20';
//var UT_RATING_IMG_HOVER='http://s.ytimg.com/yt/img/star_hover-vfl2056.gif';
var UT_RATING_IMG_HALF='icn_star_half_19x20';
var UT_RATING_IMG_BG='icn_star_empty_19x20';
//var UT_RATING_IMG_REMOVED='http://s.ytimg.com/yt/img/star_removed-vfl2028.gif';
function UTRating(ratingElementId,maxStars,objectName,formName,ratingMessageId,componentSuffix,size,messages,starCount,callback)
{
this.ratingElementId=ratingElementId;
this.maxStars=maxStars;
this.objectName=objectName;
this.formName=formName;
this.ratingMessageId=ratingMessageId
this.componentSuffix=componentSuffix
this.messages=messages;
this.callback=callback;
this.starTimer=null;
this.starCount=0;
if(starCount){
this.starCount=starCount;
var that=this;
onLoadFunctionList.push(function(){that.drawStars(that.starCount,true);});
}
if(size=='S'){
UT_RATING_IMG='icn_star_full_11x11'
UT_RATING_IMG_HALF='icn_star_half_11x11'
UT_RATING_IMG_BG='icn_star_empty_11x11'
}

function addClass(element,_class){
if(!hasClass(element,_class)){
element.className+=element.className?(" "+_class):_class;
}
}
function hasClass(element,_className){
if(!element){
return;
}
}
function showStars(starNum,skipMessageUpdate){
this.clearStarTimer();
this.greyStars();
this.colorStars(starNum);
if(!skipMessageUpdate)
this.setMessage(starNum,messages);
}
function setMessage(starNum){
if(starNum>0){
if(!this.savedMessage){
this.savedMessage=_gel(this.ratingMessageId).innerHTML;
}
_gel(this.ratingMessageId).innerHTML=this.messages[starNum-1];
}else if(this.savedMessage){
_gel(this.ratingMessageId).innerHTML=this.savedMessage;
}
}
function colorStars(starNum){
var fullStars=Math.floor(starNum+0.25);
var halfStar=(starNum-fullStars>0.25);
for(var i=0;i<fullStars;i++){
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
addClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
}
if(halfStar){
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
addClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
}
}
function _gel(id){
return document.getElementById(id);
}

function greyStars(){
for(var i=0;i<this.maxStars;i++){
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
removeClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
addClass(_gel('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
}
}
function setStars(starNum){
this.starCount=starNum;
this.drawStars(starNum);
document.forms[this.formName]['rating'].value=this.starCount;
var ratingElementId=this.ratingElementId;
that=this;
postForm(this.formName,true,function(req){
replaceDivContents(req,ratingElementId);
if(that.callback){
that.callback();
}
});
}
function drawStars(starNum,skipMessageUpdate){
this.starCount=starNum;
this.showStars(starNum,skipMessageUpdate);
}
function clearStars(){
this.starTimer=window.setTimeout(this.objectName+".resetStars()",300);
}
function resetStars(){
this.clearStarTimer();
if(this.starCount)
this.drawStars(this.starCount);
else
this.greyStars();
this.setMessage(0);
}
function clearStarTimer(){
if(this.starTimer){
window.clearTimeout(this.starTimer);
this.starTimer=null;
}
}
this.clearStars=clearStars;
this.clearStarTimer=clearStarTimer;
this.greyStars=greyStars;
this.colorStars=colorStars;
this.resetStars=resetStars;
this.setStars=setStars;
this.drawStars=drawStars;
this.showStars=showStars;
this.setMessage=setMessage;
}
ratingHoverTimers=[];
function ratingHoverOver(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
_clearHoverTimer(componentSuffix);
hideDiv('defaultRatingMessage'+componentSuffix);
showDiv('hoverMessage'+componentSuffix);
}
function ratingHoverOut(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
ratingHoverTimers[componentSuffix]=window.setTimeout(function(){_ratingHoverClear(componentSuffix);},300);
}
function _ratingHoverClear(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
_clearHoverTimer();
hideDiv('hoverMessage');
showDiv('defaultRatingMessage');
}
function _clearHoverTimer(opt_componentSuffix){
if(opt_componentSuffix==""){
opt_componentSuffix=="reserved"
}
if(ratingHoverTimers[opt_componentSuffix]){
window.clearTimeout(ratingHoverTimers[opt_componentSuffix]);
ratingHoverTimers[opt_componentSuffix]=null;
}
}