var comboOnFocusClass = 'combo-itemfocus';
var comboOffFocusClass = 'combo-item';
var comboBulletURL = '/images/bullet.gif';
var comboSpacerURL = '/images/combo_spacer.gif';
var comboRegArray = new Array();
var comboDisplay = '0'
function comboTriggerMenu(divName) {
  var obj = document.getElementById(divName);
  if(obj) {
    if(obj.style.display=='none') {
      for (var i=0; i<comboRegArray.length;i++) {
        var objHide = document.getElementById(comboRegArray[i]);
        objHide.style.display='none';
      }
      obj.style.display='block';
    }
    else {
      obj.style.display='none';
    }
  }
}
function comboSelectItem(obj, path, link_type, user, comboBoxInput, comboBoxItems) {
  var comboBoxDiv = document.getElementById(comboBoxItems);
  if (comboBoxDiv) {
    comboBoxDiv.style.display = 'none';
  }
  if (link_type=='1' || link_type=='2') {
    if (user=='1') {
      mod_path = '/wps/myportal' + path;
    }
    else {
      mod_path = '/wps/portal' + path;
    }
    
    if (link_type == '1') {
      window.location = mod_path;
    }
    else if (link_type == '2') {
      wcmWin = window.open(mod_path, '_blank');
      wcmWin.focus();
    }
  }
  else if (link_type == '5') {
    window.location = path;
  }
  else if (link_type == '6') {
    wcmWin = window.open(path, '_blank');
    wcmWin.focus();
  }
  else if (link_type=='0') {
    wcmWin = window.open(path, '_blank');
    wcmWin.focus();
  }
  else if (link_type=='7') {
    window.location = path;
  }
}
function comboEvent() {
  if (comboDisplay=='0') {
    for (var i=0; i<comboRegArray.length;i++) {
      var obj = document.getElementById(comboRegArray[i]);
      obj.style.display='none';
    }
  }
}
function comboFocusOn(obj){
  obj.className = comboOnFocusClass;
}
function comboFocusOff(obj){
  obj.className = comboOffFocusClass;
}
function comboMouseOut() {
  comboDisplay = '0';
}
function comboMouseOver() {
  comboDisplay = '1';
}
function comboRegister(id) {
  comboRegArray[comboRegArray.length]=id;
}

ComboBoxObject = function(id, title, user_type, boxwidth, optionwidth, optionheight) {
  this.id = id;
  this.divid = id+'_div';
  this.title = title;
  this.user_type = user_type;
  this.name = new Array();
  this.url_type = new Array();
  this.url = new Array();
  if (boxwidth) {
   this.boxwidth = boxwidth;
  }
  else {
    this.boxwidth = 150;
  }
  if (optionwidth) {
   this.optionwidth = optionwidth;
  }
  else {
    this.optionwidth = 215;
  }
  if (optionheight) {
   this.optionheight = optionheight;
  }
  else {
    this.optionheight = 156;
  }
}
ComboBoxObject.prototype = {
  add: function(name, url, type) {
    this.name[this.name.length] = name;
    this.url[this.url.length] = url;
    this.url_type[this.url_type.length] = type;
  },
  build: function() {
    var html = '';
    if (this.name.length > 0) {
      html += '<table cellpadding="0" cellspacing="0" border="0" onmouseout="comboMouseOut();" onmouseover="comboMouseOver();">';
      html += '<tr onclick="comboTriggerMenu(\''+this.divid+'\');" ondoubleclick="comboTriggerMenu(\''+this.divid+'\');">';
      html += '<td width="1"><input id="comboBoxInput" type="text" class="combo-list-input" style="width:'+this.boxwidth+'px;" value=\''+this.title+'\' readonly></td>';
      html += '<td align="left"><input type="button" class="combo-list-button"></td>';
      html += '</tr>';
      html += '<tr>';
      html += '<td colspan="2">';
      html += '<div id="'+this.divid+'" class="combo-list" style="width:'+this.optionwidth+'px;height:'+this.optionheight+'px;display:none;">';
      html += '<table style="width:'+(this.optionwidth-20)+'px;" cellpadding="0" cellspacing="0">';

      for (var i=0; i<this.name.length; i++) {
        if (this.url_type[i] == '0' || this.url_type[i] == '1' || this.url_type[i] == '2' || this.url_type[i] == '5' || this.url_type[i] == '6' || this.url_type[i] == '7') {
          html += '<tr><td width="10" style="padding-right:4px;padding-left:2px;padding-top:4px;" valign="top"><img src="'+comboBulletURL+'"></td><td valign="top" class="combo-item" onClick="comboSelectItem(this, \''+this.url[i]+'\', \''+this.url_type[i]+'\', \''+this.user_type+'\',\'comboBoxInput\', \''+this.divid+'\');" onMouseOver="comboFocusOn(this);" onMouseOut="comboFocusOff(this);">'+this.name[i]+'</td></tr>';
        }
        else if (this.url_type[i] == '3') {
          html += '<tr><td width="10" style="padding-right:4px;padding-left:2px;padding-top:4px;" valign="top"></td><td valign="top" class="combo-label"><b><u>'+this.name[i]+'</u></b></td></tr>';
        }
        else if (this.url_type[i] == '4') {
          html += '<tr><td width="10" style="padding-right:4px;padding-left:2px;padding-top:7px;" valign="top"><img src="'+comboSpacerURL+'"/></td><td valign="top" class="combo-label"></td></tr>';
        }
      }
      html += '</table></div></td></tr></table>';
    }
    if (document.getElementById) {
      x = document.getElementById(this.id);
      x.innerHTML = '';
      x.innerHTML = html;
    }
    else if (document.all) {
      x = document.all[this.id];
      x.innerHTML = html;
    }
    comboRegArray[comboRegArray.length]=this.divid;
  }
}