function ProductRatingControl(id,_2){
if(id==null){
id=0;
}
this.rowId=id;
this.RatingFromDb=$("#prod_rating-"+id);
this.UserRating=$("#user_rating-"+id);
this.RatingStars=$("#product_rating-"+id);
this.RatingMessage=$("#rating_message-"+id);
this.RatingSegments=$("#product_rating-"+id+" .rating_seg");
this.LoginURL=$("#login_url");
this.onRated=null;
if(_2==null){
_2=true;
}
this.displayOverallRating=_2;
this.Click=function(ra){
if(this.UserRating.val()=="-2"){
if(confirm("You must be logged in to rate products. Would you like to log in?")){
location.href=this.LoginURL.val();
}
}else{
if(this.UserRating.val()=="0"){
this.UserRating.val(ra);
this.UpdateDisplay(ra*2);
if(this.onRated==null){
this.RatingMessage.text("You have rated this item with "+ra+" stars.");
}else{
this.onRated(this);
}
this.Lock();
$.get("shop_xml.asp",{rating:ra,pf_id:$("#pf_id-"+this.rowId).val(),mscssid:$("#rating-shopper").val()},this.HandleXML);
}else{
alert("You have already rated this item with "+this.UserRating.val()+" stars.");
}
}
};
this.UpdateDisplay=function(ra){
for(i=0;i<this.RatingSegments.length;i++){
this.RemoveRatingClasses("#rating-"+i+"-"+this.rowId);
if(i<=(ra*1)){
$("#rating-"+i+"-"+this.rowId).addClass("rating_seg_a");
}else{
$("#rating-"+i+"-"+this.rowId).addClass("rating_seg_i");
}
}
};
this.ResetDisplay=function(){
if(this.displayOverallRating){
this.UpdateDisplay(this.GetSegmentByRating(this.RatingFromDb.val()));
}else{
this.UpdateDisplay(this.UserRating.val()*2);
}
};
this.Lock=function(){
this.RatingSegments.unbind("mouseover").unbind("mouseout").unbind("click");
this.RatingSegments.click(function(e){
e.preventDefault();
alert("You have already rated this product "+this.UserRating.val()+" stars.");
});
};
this.GetRatingBySegment=function(_6){
_6*=1;
return Math.round(((_6+1)/this.RatingSegments.length)*5);
};
this.GetSegmentByRating=function(ra){
return Math.round((ra*2)-1);
};
this.HandleXML=function(_8){
var _9=_8.responseXML.getElementsByTagName("rating");
if(_9.length==0){
alert("rating failure");
}else{
for(i=0;i<_9.length;i++){
var r=_9[i];
ProductRating.RatingFromDb.val(r.getAttribute("overallRating"));
ProductRating.UserRating.val(r.getAttribute("UserRating"));
}
}
};
this.RemoveRatingClasses=function(_b){
$(_b).removeClass("rating_seg_i").removeClass("rating_seg_a");
};
ProductRatingControl.InitializeProductRatingControl(this);
}
ProductRatingControl.InitializeProductRatingControl=function InitializeProductRatingControl(_c){
_c.RatingSegments.mouseover(function(e){
_c.UpdateDisplay(e.target.id.split("-")[1]);
});
_c.RatingSegments.mouseout(function(e){
_c.ResetDisplay();
});
_c.RatingSegments.click(function(e){
e.preventDefault();
_c.Click(_c.GetRatingBySegment(e.target.id.split("-")[1]));
});
_c.ResetDisplay();
};

