//
// dhtmlXProtobarObject
//

/**
 * @return dhtmlXProtobarObject
 */
function dhtmlXProtobarObject() {
  return this;
} // end func dhtmlXProtobarObject


/**
 * @param function
 * @return void
 */
dhtmlXProtobarObject.prototype.setOnShowHandler = function(func) {
  if ('function' == typeof func) {
    this.onShow = func;
  } else {
    this.onShow = eval(func);
  }
}; // end func setOnShowHandler

/**
 * @param string
 * @return number
 */
dhtmlXProtobarObject.prototype._getItemIndex = function(id) {
  for (var i = 0; i < this.itemsCount; i++) {
    if (this.items[i].id == id) {
      return i;
    }
  }
  return -1;
}; // end func _getItemIndex

/**
 * @param string
 * @return void
 */
dhtmlXProtobarObject.prototype.setGfxPath = function(path) {
  this.sysGfxPath = path;
}; // end func setGfxPath

/**
 * @param function
 * @return void
 */
dhtmlXProtobarObject.prototype.setOnHideHandler = function(func) {
  if ('function' == typeof func) {
    this.onHide = func;
  } else {
    this.onHide = eval(func);
  }
}; // end func setOnHideHandler

/**
 * @param string
 * @param ?
 */
dhtmlXProtobarObject.prototype.setItemAction = function(id, action) {
  var z = this._getItemIndex(id);
  if (z >= 0) {
    this.items[z].setSecondAction(action);
  }
}; // end func setItemAction

/**
 * @param string
 * @return ?
 */
dhtmlXProtobarObject.prototype.getItem = function(itemId) {
  var z = this._getItemIndex(itemId);
  if (z >= 0) {
    return this.items[z];
  }
}; // end func getItem

/**
 * @param string
 * @return void
 */
dhtmlXProtobarObject.prototype.hideButtons = function(idList) {
  if(!idList) {
    for (var i=0; i < this.itemsCount; i++) {
      this.items[i].getTopNode().style.display = 'none';
      this.items[i].hide = 1;
    }
    return 0;
  }
  
  var temp = idList.split(",");
  for (var i = 0; i < temp.length; i++) {
    this.hideItem(temp[i]);
  }
}; // end func hideButtons

/**
 * @param string
 * @return void
 */
dhtmlXProtobarObject.prototype.showButtons = function(idList) {
  if (!idList) {
    for (var i = 0; i < this.itemsCount; i++) {
      this.items[i].getTopNode().style.display = '';
      this.items[i].hide = 0;
    }
    return 0;
  }
  
  var temp  =idList.split(",");
  for(var i = 0; i < temp.length; i++) {
    this.showItem(temp[i]);
  }
}; // end func showButtons

/**
 * @param string
 * @return void
 */
dhtmlXProtobarObject.prototype.disableItem = function(itemId) {
  var z = this.getItem(itemId);
  if (z) {
    if (z.disable) {
      z.disable();
    }
  }
}; // end func disableItem

/**
 * @param string
 * @return void
 */
dhtmlXProtobarObject.prototype.enableItem = function(itemId) {
  var z = this.getItem(itemId);
  if (z) {
    if (z.enable) {
      z.enable();
    }
  }
}; // end func enableItem

/**
 *
 */
dhtmlXProtobarObject.prototype.hideItem = function(itemId) {
  var z = this.getItem(itemId);
  if (z) {
    z.getTopNode().style.display = 'none';
    z.hide = 1;
  }
}; // end func hideItem

/**
 *
 */
dhtmlXProtobarObject.prototype.showItem = function(id) {
  var z = this.getItem(id);
  if (z) {
    z.getTopNode().style.display = '';
    z.hide = 0;
  }
}; // end func showItem

/**
 *
 */
dhtmlXProtobarObject.prototype.setOnClickHandler = function(func) {
  if ('function' == typeof(func)) {
    this.defaultAction = func;
  } else {
    this.defaultAction = eval(func);
  }
}; // end func setOnClickHandler

/**
 *
 */
dhtmlXProtobarObject.prototype.setTitleText = function(newText) {
  this.tname = newText;
  this.nameCell.innerHTML = newText;
  this.preNameCell.innerHTML = newText;
}; // end func setTitleText
 

/**
 *
 */
dhtmlXProtobarObject.prototype.setBarSize = function(width, height) {
  if (width) {
    this.topNod.width = width;
  }
  if (height) {
    this.topNod.height = height;
  }
}; // end func setBarSize

/**
 *
 */
dhtmlXProtobarObject.prototype.resetBar = function(idList) {
  for (var i = 0; i < this.itemsCount; i++) {
    this.hideItem(this.items[i].id);
    this.items[i].persAction = 0;
  }
  
  var temp = idList.split(',');
  for (var i = 0; i < temp.length; i++) {
    this.showItem(temp[i]);
  }
}; // end func resetBar

/**
 *
 */
dhtmlXProtobarObject.prototype.loadXML = function(file, afterCall) {
  this.waitCall = afterCall || 0;
  this.xmlUnit.loadXML(file);
}; // end func loadXML

/**
 *
 */
dhtmlXProtobarObject.prototype.loadXMLString = function(xmlString, afterCall) {
  this.waitCall = afterCall || 0;
  this.xmlUnit.loadXMLString(xmlString);
}; // end func loadXMLString

/**
 *
 */
dhtmlXProtobarObject.prototype.showBar = function() {
  this.topNod.style.display = '';
  
  if ((this.topNod.ieFix) && (this.topNod.style.position == 'absolute')) {
    this.topNod.ieFix.style.display = '';
    this.topNod.ieFix.style.width   = this.topNod.offsetWidth + 'px';
    this.topNod.ieFix.style.height  = this.topNod.offsetHeight + 'px';
    
    this.topNod.ieFix.style.position = 'absolute';
    this.topNod.ieFix.style.top      = this.topNod.style.top;
    this.topNod.ieFix.style.left     = this.topNod.style.left;
  }
  
  if(this.onShow) {
    this.onShow();
  }
}; // end func showBar

/**
 *
 */
dhtmlXProtobarObject.prototype.hideBar = function() {
  this.topNod.style.display = 'none';
  
  if (this.topNod.ieFix) {
    this.topNod.ieFix.style.display = 'none';
  }
  
  if (this.onHide) {
    this.onHide();
  }
}; // end func hideBar

/**
 *
 */
dhtmlXProtobarObject.prototype.setBarAlign = function(align) {
  if (('left' == align) || ('top' == align)) {
    this.preNameCell.innerHTML = '';
    this.preNameCell.style.display = 'none';
    
    this.nameCell.innerHTML = this.tname;
    this.nameCell.style.display = '';
    this.nameCell.width = '100%';
    
  } else if (('center' == align) || ('middle' == align)) {
    this.preNameCell.innerHTML = this.tname;
    this.preNameCell.style.display = '';
    this.preNameCell.width = '50%';
    
    this.nameCell.innerHTML = this.tname;
    this.nameCell.style.display = '';
    this.nameCell.width = '50%';
    
  } else if (('right' == align) || ('bottom' == align)) {
    this.preNameCell.innerHTML = this.tname;
    this.preNameCell.style.display = '';
    this.preNameCell.width = '100%';
    
    this.nameCell.innerHTML = '';
    this.nameCell.style.display = 'none';

  }
}; // end func setBarAlign

// dummy functions
dhtmlXProtobarObject.prototype.dummyFunc = function() { return true; };
dhtmlXProtobarObject.prototype.badDummy  = function() { return false; };


//
// dhtmlXButtonPrototypeObject
//

/**
 * @return object
 */
function dhtmlXButtonPrototypeObject() {
  return this;
}; // end func dhtmlXButtonPrototypeObject

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.setAction = function(func) {
  if ('function' == typeof func) {
    this.action = func;
  } else {
    this.action = eval(func);
  }
}; // end func setAction

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.setSecondAction = function(func) {
  if ('function' == typeof func) {
    this.persAction = func;
  } else {
    this.persAction = eval(func);
  }
}; // end func setSecondAction

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.enable = function() {
  if (this.disableImage) {
    this.imageTag.src = this.src;
  } else {
    if (!this.className) {
      this.topNod.className = this.objectNode.className;
    } else {
      this.topNod.className = this.className;
    }
  }
  
  if (this.textTag) {
    this.textTag.className = this.textClassName;
  }
  
  this.topNod.onclick     = this._onclickX;
  this.topNod.onmouseover = this._onmouseoverX;
  this.topNod.onmouseout  = this._onmouseoutX;
  this.topNod.onmousedown = this._onmousedownX;
  this.topNod.onmouseup   = this._onmouseupX;
}; // end func enable

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.disable = function() {
  if (this.disableImage) {
    this.imageTag.src = this.disableImage;
  } else {
    this.topNod.className = 'iconGray';
  }
  
  if (this.textTag) {
    this.textTag.className = 'buttonTextDisabled';
  }
 
  this.topNod.onclick     = this.dummy;
  this.topNod.onmouseover = this.dummy;
  this.topNod.onmouseout  = this.dummy;
  this.topNod.onmousedown = this.dummy;
  this.topNod.onmouseup   = this.dummy;
}; // end func disable

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onclickX = function(e, that) {
  if (!that) {
    that = this.objectNode;
  }
  if (that.topNod.dstatus) {
    return;
  }
  
  if ((!that.persAction) || (that.persAction())) {
    if (that.action) {
      that.action(that.id);
    }
  }
}; // end func _onclickX

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.setHTML = function(htmlText) {
  this.topNod.innerHTML = htmlText;
}; // end func setHTML

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.setAltText = function(imageText) {
  this.imageTag.alt = imageText;
}; // end func setAltText

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.setImage = function(imageSrc, disabledImageSrc) {
  this.src = imageSrc;
  
  if (disabledImageSrc) {
    this.disableImage = disabledImageSrc;
  }
  
  if (this.topNod.onclick == this.dummy) {
    if (disabledImageSrc) {
      this.imageTag.src = disabledImageSrc;
    }
  } else {
    this.imageTag.src = imageSrc;
  }
}; // end func setImage

// dummy functions
dhtmlXButtonPrototypeObject.prototype.dummy=function(){};

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype.getTopNode = function() {
  return this.topNod;
}; // end func getTopNode

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmouseoverY = function() {
  if (this.topNod.className != this.className + 'Over') {
    this.topNod.className = this.className + 'Over';
  }
  return true;
}; // end func _onmouseoverY

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmouseoutY = function() {
  this.topNod.className = this.className;
  return true;
}; // end func _onmouseoutY

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmousedownX = function() {
  this.className = this.objectNode.className + 'Down';
  return true;
}; // end func _onmousedownX

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmouseupX = function() {
  this.className = this.objectNode.className;
  return true;
}; // end func _onmouseupX

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmouseoutX = function(e) {
  if (!e) {
    e = event;
  }
  
  if (this.timeoutop) {
    clearTimeout(this.timeoutop);
  }
  
  this.timeoutop = setTimeout(this.objectNode._delayedTimerCall(this.objectNode, '_onmouseoutY'), 100);
}; // end func _onmouseoutX

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._onmouseoverX = function(e){
  if (!e) {
    e = event;
  }
  
  if (this.timeoutop) {
    clearTimeout(this.timeoutop);
  }
  
  this.timeoutop = setTimeout(this.objectNode._delayedTimerCall(this.objectNode, '_onmouseoverY'), 50);
}; // end func _onmouseoverX

/**
 *
 */
dhtmlXButtonPrototypeObject.prototype._delayedTimerCall = function(object, functionName, time) {
  this.callFunc = function() {
    eval('object.' + functionName + '();');
  }
  return this.callFunc;
}; // end func _delayedTimerCall
