var __C = new Array();
var __C_bolDCombo = true;
var __C_objList = null;
var __C_bolClick = false;
var __C_imgs = new Array();
__C_imgs['on'] = new Image();
__C_imgs['on'].src = "/_images2005/combo/combo_on.gif";
__C_imgs['off'] = new Image();
__C_imgs['off'].src = "/_images2005/combo/combo_off.gif";

function __C_mouseclick() {
  if(!__C_bolClick && __C_objList)
    __C_objList.showList(false);
  __C_bolClick = false;
}

function Combo(id, idList, strOnChange) {
  this.id = id;
  __C[id] = this;
  this.divList = getE(idList);
  this.scroller = __S[this.divList.childNodes[0].id.replace(/^divScrollerContainer_(.*)$/i, "$1")];
  this.table = getE("__C_"+id);
  this.div = getE("__C_div_"+id);
  this.img = getE("__C_img_"+id);
  this.td1 = getE("__C_td1_"+id);
  this.td2 = getE("__C_td2_"+id);
  this.hidden = getE("__C_hidden_"+id);
  if(!this.divList || !this.table)
    return null;
  
  //alert(this.divList.outerHTML);
  
  //alert(this.scroller.contentHeight + ":" + this.divList.style.height);
  
  if(this.scroller.contentHeight < 200)
    this.divList.style.height = this.scroller.contentHeight + 5;
  //alert(this.scroller.contentHeight + ":" + this.divList.style.height);
  this.showList = Combobox_showList;
  this.doClick = Combobox_click;
  this.onChange = strOnChange.replace(/(\w*\(?.*)this(.*)/i, "$1this.hidden$2");
  this.isSelected = Combobox_isSelected;
  this.mouseover = Combobox_mouseover;
  this.mouseout = Combobox_mouseout;
  this.setTopStyle = Combobox_setTopStyle;
  
  __C_bolDCombo = true;
  
  return this;
}

function Combobox_showList(bolForceStatus) {
  if(!bolForceStatus)
    __C_bolClick = true;
  if(this.divList.style.visibility == "visible" || bolForceStatus===false) {
    this.divList.style.visibility = "hidden";
    this.setTopStyle(false);
    __C_objList = null;
  } else {
    if(__C_objList)
      __C_objList.showList(false);
    if(this.scroller.contentHeight < 200) {
      this.divList.style.height = this.scroller.contentHeight + 5;
      this.scroller.setHeight(this.scroller.contentHeight + getPageY(this.scroller.divContainer) + this.scroller.btmMargin);
    }
    arrPos = getGlobalPosition(this.table)
    this.divList.style.left = arrPos['x'];
    this.divList.style.top = arrPos['y'] + 18;
    this.divList.style.visibility = "visible";
    this.setTopStyle(true);
    __C_objList = this;
  }
}

function Combobox_click(obj) {
  this.div.innerHTML = obj.innerHTML;
  this.divList.style.visibility="hidden";
  objParent = obj.parentNode;
  var l = objParent.childNodes.length;
  for(i=0; i<l; i++)
    objParent.childNodes[i].className = "comboItem";
  obj.className = "comboItemSelected";
  this.hidden.value = obj.id;
  eval(this.onChange);
}

function __C_hlght(obj, bolUnhilight) {
  if(!obj)
    return;
  var classe = obj.className;
  if(classe!="comboItemSelected")
    obj.className = bolUnhilight?"comboItem":"comboItemOver";
}

function Combobox_isSelected() {
  return this.hidden.value!="";
}

function Combobox_mouseover() {
  this.setTopStyle(true);
}

function Combobox_mouseout() {
  if(!__C_objList)
    this.setTopStyle(false);
}

function Combobox_setTopStyle(bON) {
  if(bON) {
    this.img.src = __C_imgs['on'].src;
    this.td1.style.backgroundColor = "#FFFFFF";
    this.td2.style.backgroundColor = "#FFFFFF";
    this.div.style.color = "#1F1513";
    this.div.style.fontWeight = "bold";
  } else {
    this.img.src = __C_imgs['off'].src;
    this.td1.style.backgroundColor = "";
    this.td2.style.backgroundColor = "";
    this.div.style.color = "#FFFFFF";
    this.div.style.fontWeight = "normal";
  }
}


function getGlobalPosition(obj) {
  var x = 0;
  var y = 0;
  var divGlobal = getE(getGlobalDivId());
  while(obj) {
    x += obj.offsetLeft?obj.offsetLeft:0;
    y += obj.offsetTop?obj.offsetTop:0;
    obj = obj.offsetParent;
    if(obj==divGlobal)
      break;
  }
  
  arr = new Array();
  arr['x'] = x;
  arr['y'] = y;
  return arr;
}
