ClientReportToolbar = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.reportViewer = null;
  this.menu = null;
  this.ignoreItems = new Object();
  this.enabledItems = new Array();
  this.delayUpdate = false;
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
  this.reportViewer = aspxGetControlCollection().Get(this.reportViewerID);
  this.menu = aspxGetControlCollection().Get(this.menuID);
  if(!_aspxIsExists(this.reportViewer) || !_aspxIsExists(this.menu))
   return;
  for(var i = 0; i < this.menu.GetItemCount(); i++) {
   var item = this.menu.GetItem(i);
   if(item.GetEnabled() == false)
    this.ignoreItems[item.name] = item; 
  }
  var instance = this;
  this.reportViewer.PageLoad.AddHandler(function(s, a) { instance.pageLoadEventHanler(s, a) });
  this.reportViewer.BeginCallback.AddHandler(function(s, a) { instance.beginCallbackEventHanler(s, a) });
  this.reportViewer.EndCallback.AddHandler(function(s, a) { instance.endCallbackEventHanler(s, a) });
  this.setElemEnabled("Search", this.reportViewer.IsSearchAllowed());
 },
 AfterInitialize: function() {
  this.constructor.prototype.AfterInitialize.call(this);
  if(this.delayUpdate) {
   this.updateView();
   this.delayUpdate = false;
  }
 },
 beginCallbackEventHanler: function(s, a) {
  this.enabledItems = new Array();
  for(var i = 0; i < this.menu.GetItemCount(); i++) {
   var item = this.menu.GetItem(i);
   if(item.GetEnabled()) {
    this.enabledItems[this.enabledItems.length] = item; 
    item.SetEnabled(false); 
   }
  }
 },
 endCallbackEventHanler: function(s, a) {
  for(var i = 0; i < this.enabledItems.length; i++) {
   this.enabledItems[i].SetEnabled(true); 
  }
  this.updateElements();
 },
 pageLoadEventHanler: function(s, a) {
  this.pageIndex = a.PageIndex;
  this.pageCount = a.PageCount; 
  if(this.isInitialized)
  this.updateView();
  else
   this.delayUpdate = true;
 },
 handleButton: function(btnId) {
  if(!_aspxIsExists(this.reportViewer))
   return;
  if(btnId.indexOf("Search") >= 0) {
   this.reportViewer.Search();
   return;
  }
  if(btnId.indexOf("Print") >= 0) {
   var val = (btnId.indexOf("PrintPage") >= 0) ? this.pageIndex : "";
   this.reportViewer.Print(val);
   return;
  }
  if(btnId.indexOf("SaveToWindow") >= 0) {
   this.reportViewer.SaveToWindow(this.getSaveFormat());
   return;
  }
  if(btnId.indexOf("SaveToDisk") >= 0) {
   this.reportViewer.SaveToDisk(this.getSaveFormat());
   return;
  }
  if(this.pageIndex < 0 || this.pageCount <= 0)
   return;
  var index = this.pageIndex;
  if(btnId.indexOf("FirstPage") >= 0) {
   index = 0;
  } else if(btnId.indexOf("PreviousPage") >= 0) {
   index = this.pageIndex - 1;
  } else if(btnId.indexOf("NextPage") >= 0) {
   index = this.pageIndex + 1;
  } else if(btnId.indexOf("LastPage") >= 0) {
   index = this.pageCount - 1;
  } else if(btnId.indexOf("PageNumber") >= 0) {
   index = this.getControlIntValue("PageNumber") - 1;
  } 
  this.reportViewer.GotoPage(index);
 },
 getSaveFormat: function() {
  return this.getControlValue("SaveFormat");
 },
 updateView: function() {
  this.updatePageIndexes();
  this.setElemSize("PageCount", this.pageCount.toString().length);
  this.setControlValue("PageCount", this.pageCount);
  this.updateElements();
 },
 updateElements: function() {
  var val = this.pageIndex != 0;
  this.setElemEnabled("FirstPage", val);
  this.setElemEnabled("PreviousPage", val);
  val = this.pageIndex < this.pageCount - 1;
  this.setElemEnabled("NextPage", val);
  this.setElemEnabled("LastPage", val);
 },
 updatePageIndexes: function() {
  var cbx = this.getTemplateControl("PageNumber");
  if(cbx == null)
   return;
  if(cbx.GetItemCount() != this.pageCount) {
   cbx.BeginUpdate();
   cbx.ClearItems();
   for(var i = 0; i < this.pageCount; i++)
    cbx.AddItem((i + 1).toString());
   cbx.EndUpdate();
  } 
  cbx.SetSelectedIndex(this.pageIndex);
  if(__aspxWebKitFamily)
   cbx.GetInputElement().value = (this.pageIndex + 1).toString();
 },
 setElemSize: function(name, size) {
  var ctl = this.getTemplateControl(name);
  if(ctl == null) 
   return;
  var el = ctl.GetInputElement();
  if(el == null) 
   return;
  if(__aspxWebKitFamily) {
   var newEl = el.cloneNode(false);
   newEl.size = size;
   el.parentNode.replaceChild(newEl, el);
  } else 
   el.size = size;
 },
 setControlValue: function(name, val) {
  var ctl = this.getTemplateControl(name);
  if(ctl != null)
   ctl.SetValue(val);
 },
 getControlValue: function(name) {
  var ctl = this.getTemplateControl(name);
  if(ctl != null)
   return ctl.GetValue();
  return null;
 },
 getTemplateControl: function(name) {
  var item = this.menu.GetItemByName(name);
  if(item != null) {
   var templateControlName = this.menu.name + "_ITCNT" + item.GetIndexPath() + "_" + name;
   return aspxGetControlCollection().Get(templateControlName);
  }
  return null;
 },
 getControlIntValue: function(name) {
  var val = this.getControlValue(name);
  return (val != null) ? parseInt(val) : -1;
 },
 setElemEnabled: function(name, val) {
  if(this.ignoreItems[name] != null)
   return;
  var item = this.menu.GetItemByName(name);
  if(item != null && item.GetEnabled() != val)
   item.SetEnabled(val);
 }
});

