ASPxClientRatingControl = _aspxCreateClass(ASPxClientControl, {
 __isASPxRatingControl: true,
 INDEX_DEFAULT: 0,
 INDEX_USER: 1,
 INDEX_CHECKED: 2,
 INDEX_HOVER: 3,
 FILLPRECISION_EXACT: 0,
 FILLPRECISION_HALF: 1,   
 FILLPRECISION_FULL: 2, 
 constructor: function(name){
  this.constructor.prototype.constructor.call(this, name);
  this.itemCount = 0;
  this.itemWidth = 0;
  this.itemHeight = 0;
  this.mainDiv = null;
  this.checkedDiv = null;
  this.hoverDiv = null;
  this.titles = [ ];
  this.fillPrecision = 0;
  this.ItemClick = new ASPxClientEvent();  
 },
 SetDimensions: function(itemCount, itemWidth, itemHeight) {
  this.itemCount = itemCount;
  this.itemWidth = itemWidth;
  this.itemHeight = itemHeight;
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
  this.AddAnchors();
  if(__aspxIE && __aspxBrowserVersion < 7) { 
   this.GetMainDiv().style.fontSize = "0";
   this.GetCheckedDiv().style.fontSize = "0";
   this.GetHoverDiv().style.fontSize = "0";
  }
 },
 AddAnchors: function() {
  var div = this.GetMainDiv();  
  if(div.lastChild.nodeName == "A")
   return;
  for(var i = 0; i < this.itemCount; i++) 
   div.appendChild(this.CreateAnchor(i))
 },
 CreateAnchor: function(index) {
  var anchor = document.createElement("a");  
  anchor.style.width = this.itemWidth + "px";
  anchor.style.height = this.itemHeight + "px";
  anchor.style.marginLeft = index * this.itemWidth + "px";
  anchor.style.marginTop = -this.itemHeight + "px";
  anchor.style.display = "block";
  _aspxSetAttribute(anchor, "DXIndex", index); 
  if(_aspxIsExists(this.titles) && _aspxIsExists(this.titles[index])) {
   _aspxSetAttribute(anchor, "title", this.titles[index]);
  } else if(_aspxIsExists(this.toolTip)) {
     _aspxSetAttribute(anchor, "title", this.toolTip);
  }
  if(!this.GetReadOnly())  
   _aspxSetAttribute(anchor, "href", "javascript:aspxRatingControlVote('" + this.name + "'," + index + ")");
  return anchor;
 },
 GetChildDiv: function(parent){
  for(var i = 0; i < parent.childNodes.length; i++) {
   var child = parent.childNodes[i];
   if(child.tagName == "DIV")
    return child;
  }
 },
 GetMainDiv: function() {
  if(this.mainDiv == null)
   this.mainDiv = this.GetMainElement();
  return this.mainDiv;
 },
 GetCheckedDiv: function() {
  if(this.checkedDiv == null)
   this.checkedDiv = this.GetChildDiv(this.GetMainDiv());
  return this.checkedDiv;
 },
 GetHoverDiv: function() {
  if(this.hoverDiv == null)
   this.hoverDiv = this.GetChildDiv(this.GetCheckedDiv());
  return this.hoverDiv;
 },
 GetHiddenField: function() {
    return _aspxGetElementById(this.name + "S");
 }, 
 GetCurrentState: function() {
  var state = this.GetHiddenField().value.split(";");    
  return [state[0] == "T", Number(state[1])];
 },
 UpdateStateInput: function(readOnly, value) {
  this.GetHiddenField().value = (readOnly ? "T" : "F") + ";" + value;
 }, 
 GetReadOnly: function() {    
  return this.GetCurrentState()[0];
 },
 SetReadOnly: function(readOnly) {
  if(readOnly)
   this.DisabledAnchors();
  else 
   this.EnabledAnchors();
  this.UpdateStateInput(readOnly, this.GetValue());
 },
 DisabledAnchors: function() {
  var collection = this.GetMainDiv().childNodes;
  for(var i = 0; i < collection.length; i++) {
   if(collection[i].nodeName == "A") {       
    _aspxRemoveAttribute(collection[i], "href");
   }
  }
 },
 EnabledAnchors: function() {
  var collection = this.GetMainDiv().childNodes;
  for(var i = 0; i < collection.length; i++) {
   if(collection[i].nodeName == "A") {       
    _aspxSetAttribute(collection[i], "href", "javascript:aspxRatingControlVote('" + 
     this.name + "'," + collection[i].attributes.getNamedItem("DXIndex").value + ")");
   }
  }
 },
 GetValue: function() {
  return this.GetCurrentState()[1];
 },
 SetValue: function(value, isUi){
  if(value > this.itemCount)
   value = this.itemCount;
  this.UpdateStateInput(this.GetReadOnly(), value);
  this.UpdateCheckDiv(value, isUi);
  this.UpdateHoverDiv(-1);
 },
 UpdateCheckDiv: function(value, isUi){
  var div = this.GetCheckedDiv();
  var index = isUi ? this.INDEX_USER : this.INDEX_CHECKED;
  div.style.backgroundPosition = "0 " + (-this.itemHeight * index) + "px";
  if(!isUi)
   value = this.QuantizeValue(value);
  div.style.width = this.itemWidth * value + "px";
 },
 QuantizeValue: function(input) {
  switch(this.fillPrecision) {
   case this.FILLPRECISION_EXACT:
    return input;
   case this.FILLPRECISION_FULL:
    return Math.round(input);
   case this.FILLPRECISION_HALF:
    return Math.round(input * 2) / 2;
  }
 },
 HandleVote: function(index) {
  if(this.GetReadOnly())
   return;
  this.SetValue(index + 1, true);
  var processOnServer = this.RaiseItemClick(index);
  if(processOnServer)
   this.SendPostBack(index);
 },
 HandleMouseMove: function(htmlEvent) {
  var index = this.GetItemIndexAtCursor(htmlEvent);
  if(index != -1)
   this.UpdateHoverDiv(index);  
 },
 HandleMouseOut: function() {
  this.UpdateHoverDiv(-1);
 },
 GetItemIndexAtCursor: function(htmlEvent) {
  if(_aspxGetEventSource(htmlEvent).nodeName == "A")
   return parseInt(_aspxGetEventSource(htmlEvent).attributes.getNamedItem("DXIndex").value);
  return -1;
 },
 UpdateHoverDiv: function(itemIndex) {
  this.GetHoverDiv().style.width = (itemIndex + 1) * this.itemWidth + "px";
 },
 RaiseItemClick: function(index){
  var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ItemClick");
  if(!this.ItemClick.IsEmpty()){
   var args = new ASPxClientRatingControlItemClickEventArgs(processOnServer, index);
   this.ItemClick.FireEvent(this, args);
   processOnServer = args.processOnServer;
  }
  return processOnServer;
 }
});
ASPxClientRatingControl.Cast = ASPxClientControl.Cast;
ASPxClientRatingControl.elementUnderCursor = null;
ASPxClientRatingControl.active = null;
ASPxClientRatingControl.DocMouseMoveHandler = function(htmlEvent) {
 var element = _aspxGetEventSource(htmlEvent);
 if(element == ASPxClientRatingControl.elementUnderCursor)
  return;
 ASPxClientRatingControl.elementUnderCursor = element;
 for(var i = 0; i < 3 && element != null; i++) {
  if(element.id) {
   var obj = aspxGetControlCollection().Get(element.id);
   if(obj != null && obj.__isASPxRatingControl) {
    if(ASPxClientRatingControl.active != null)
     ASPxClientRatingControl.active.HandleMouseOut();   
    ASPxClientRatingControl.active = obj;
    if(!obj.GetReadOnly())
     obj.HandleMouseMove(htmlEvent);
    return;
   }   
  }
  element = element.parentNode;
 }
 if(ASPxClientRatingControl.active != null) {
  ASPxClientRatingControl.active.HandleMouseOut();
  ASPxClientRatingControl.active = null;
 }
};
function aspxRatingControlVote(name, index) {
 var control = aspxGetControlCollection().Get(name);
 if(control)
  control.HandleVote(index);
}
ASPxClientRatingControlItemClickEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
 constructor: function(processOnServer, index){
  this.constructor.prototype.constructor.call(this, processOnServer);
  this.index = index;
 }
});
ASPxClientRatingControl.handlerAssigned = false;
if(!ASPxClientRatingControl.handlerAssigned) {
 _aspxAttachEventToDocument("mousemove", ASPxClientRatingControl.DocMouseMoveHandler);
 ASPxClientRatingControl.handlerAssigned = true;
}

