// SaySelect Environment Constants
var SS3_ENV = new Object();
SS3_ENV.IE_Version = new Number(((window.navigator.appVersion.split('; '))[1].split(' '))[1]);
SS3_ENV.CR = new Object();
SS3_ENV.CR.ReverseBackground = '#333333';
SS3_ENV.CR.ReverseText = '#333333';
SS3_ENV.CR.Border = '#cc0000';
SS3_ENV.CR.BorderActive = '#D80007';
SS3_ENV.ImgPrefix = 'http://img.imbc.com/2006_admin/';
SS3_ENV.DefaultHeight = 25;
SS3_ENV.ButtonWidth = 25;
SS3_ENV.OptionsDivStyle = ''
 + '  padding:1 1 1 1;'
 + '  display:none;'
 + '  z-index:10;'
 + '  position:absolute;'
 + ' border-left:1 solid '+ SS3_ENV.CR.Border+';'
 + ' border-right:1 solid '+ SS3_ENV.CR.Border+';'
 + ' border-bottom:1 solid '+ SS3_ENV.CR.Border+';'
 + ' border-top:1 solid '+ SS3_ENV.CR.Border+';'
 + '  background-color:#cc0000;'
 + '  scrollbar-face-color:#D80007;'
 + '  scrollbar-shadow-color:#333333;'
 + '  scrollbar-highlight-color:#FFFFFF;'
 + '  scrollbar-3dlight-color:#D80007;'
 + '  scrollbar-darkshadow-color:#FFFFFF;'
 + '  scrollbar-track-color:#FFFFFF;'
 + '  scrollbar-arrow-color:#F3F3F3;'
SS3_ENV.MouseStyle = 'cursor:hand;'//¹Ú?À§¿¡?¶ó°¬??ÀÇ ¸¶¿ì?¸ð?
SS3_ENV.OptionNobrStyle =''
  + ' font-size:12px;letter-spacing:0'
  + ' font-family:±¼¸²;'
  + ' color:#FFFFFF;'
// SaySelect Variables
var SS3_VAR = new Object();
SS3_VAR.DivDummy = document.createElement("DIV");
SS3_VAR.SelectList = new Array();
SS3_VAR.bEventAttached = false;

var SS3_CreatedElements = new Object();

function unloadObjects()
{
  try {
    if (SS3_VAR && SS3_VAR.SelectList)
    {
      for (key in SS3_VAR.SelectList)
      {
	if (SS3_VAR.SelectList[key])
	{
	  try {
	   SS3_VAR.SelectList[key].select.setAttribute('SS', 0);
	  } catch (e) {};
	  delete SS3_VAR.SelectList[key];
	}
      }
    }
  } catch (e) {};
}

attachEvent("onunload", unloadObjects);

function SS3_create (srcHTML, ListMax, bAutoDetect, flag)
{
  // property
  this.flag = flag;
  this.ssID = SS3_VAR.SelectList.length;
  this.bOriginalSelect = (bAutoDetect && SS3_ENV.IE_Version < 5.5);
  this.select = SS3_createElement(srcHTML);
  this.selectedIndex = this.select.selectedIndex;
  this.options = this.select.options;
  this.width = parseInt(this.select.style.width);
  this.height = (this.select.style.height) ? parseInt(this.select.style.height) : SS3_ENV.DefaultHeight;
  this.OptionHeight = this.height;
  this.bListDown = (ListMax && '-'==ListMax.toString().substr(0, 1)) ? false : true;
  this.ListMax = (!isNaN(parseInt(ListMax))) ? Math.abs(ListMax) : 100;

  this.Table;
  this.TitleDiv;
  this.TitleTable;
  this.TitleWrapper;
  this.OptionsDiv;
  this.OptionsWrapper;
  this.OptionsTable;
  this.bFocused = false;
  this.bExpanded = false;
  this.bReverse = false;

  // private method
  this.isThisEventToBeCanceled = SS3_isThisEventToBeCanceled;
  this.toggleTitle = SS3_toggleTitle;
  this.syncSelectedIndex = SS3_syncSelectedIndex;
  this.toggleOptions = SS3_toggleOptions;
  this.turnOnOption = SS3_turnOnOption;
  this.turnOffOption = SS3_turnOffOption;
  this.handleMousewheel = SS3_handleMousewheel;
  this.handleOverTitle = SS3_handleOverTitle;
  this.handleOutTitle = SS3_handleOutTitle;
  this.handleOverOption = SS3_handleOverOption;
  this.createTable = SS3_createTable;
  this.createTitleDiv = SS3_createTitleDiv;
  this.checkOptionsDiv = SS3_checkOptionsDiv;
  this.createOptionsDiv = SS3_createOptionsDiv;
  this.createOptionTr = SS3_createOptionTr;
  this.adjustOptionsDiv = SS3_adjustOptionsDiv;
  this.syncOptions = SS3_syncOptions;
  this.pressOption = SS3_pressOption;
  this.moveOption = SS3_moveOption;
  this.releaseOption = SS3_releaseOption;
  this.pressTitle = SS3_pressTitle;
  this.releaseTitle = SS3_releaseTitle;

  // public method
  this.display = SS3_display;
  this.insertOption = SS3_insertOption;
  this.deleteOption = SS3_deleteOption;
  this.changeOption = SS3_changeOption;

  // initiate
  this.createTable(flag);
  this.select.setAttribute('SS3', this);
  if (!this.bOriginalSelect)
    this.select.onpropertychange = SS3_handlePropertychange;
  SS3_VAR.SelectList[this.ssID] = this;
}
function SS3_display ()
{
//  document.write("<div id=SS3_TempDiv></div>\n");
//  document.all.SS3_TempDiv.appendChild(this.Table);
//  document.all.SS3_TempDiv.removeNode();
	try {
  document.write("<div id=SS3_TempDiv></div>\n");
  document.getElementById("SS3_TempDiv").appendChild(this.Table);
  document.getElementById("SS3_TempDiv").removeNode();
	}catch(E) {
	}
}
function SS3_write (srcHTML, ListMax, bAutoDetect, flag)
{
  var oSS = new SS3_create(srcHTML, ListMax, bAutoDetect, flag);
  oSS.display();
  return oSS;
}
function SS3_insertOption (value, innerText, idx)
{
  this.checkOptionsDiv();

  var NewOption = document.createElement("OPTION");
  SS3_CreatedElements[SS3_CreatedElements.length] = NewOption;
  this.options.add(NewOption, idx);
  NewOption.innerText = innerText;
  NewOption.value = value;

  if (!this.bOriginalSelect)
    this.createOptionTr(idx);
  this.syncOptions();
  this.adjustOptionsDiv();
  this.syncSelectedIndex();
}
function SS3_deleteOption (idx)
{
  this.checkOptionsDiv();

  this.options.remove(idx);
  if (!this.bOriginalSelect)
    this.OptionsTable.deleteRow(idx);
  this.syncOptions();
  this.adjustOptionsDiv();
  this.syncSelectedIndex();
}
function SS3_changeOption (idx, value, innerText)
{
  this.checkOptionsDiv();

  this.options[idx].value = value;
  this.options[idx].innerText = innerText;
  this.syncOptions();
  this.syncSelectedIndex();
}

function SS3_cancelEvent (event)
{
  event.cancelBubble = true;
  event.returnValue = false;
}
function SS3_isThisEventToBeCanceled (event)
{
  if ('object' == typeof(event)) {
    switch (event.type) {
      case 'mousedown':
        if (!(event.button & 1)) return true;
        break;
      case 'mouseup':
        if (!(event.button & 1)) return true;
        if (SS3_ENV.IE_Version >= 5.5 && event.srcElement != this.srcElementOfLastMousedown && this.srcElementOfLastMousedown != null) {
          this.srcElementOfLastMousedown = null;
          return true;
        }
        break;
      case 'mouseout':
        if (!(SS3_ENV.IE_Version < 5.5 && event.srcElement == this.srcElementOfLastMousedown))
          return true;
        break;
      case 'mousemove':
        if (SS3_ENV.IE_Version >= 5.5 && event.srcElement != this.srcElementOfLastMousedown && this.srcElementOfLastMousedown != null)
          return true;
        break;
    }
  }
  return false;
}
function SS3_createElement (html)
{
  SS3_VAR.DivDummy.insertAdjacentHTML('afterBegin', html);
  var oEl = SS3_VAR.DivDummy.children(0);
  while (SS3_VAR.DivDummy.children.length > 0) {
    SS3_VAR.DivDummy.removeChild(SS3_VAR.DivDummy.children(0));
  }
  return oEl;
}
function SS3_blurExcept (except)
{
  SS3_cancelEvent(window.event);

  except = ('number'==typeof(except)) ? except : -1;

  var bHasToDetachEvent = true;
  for (var i=0; i < SS3_VAR.SelectList.length; i++) {
    if (-1==except && SS3_VAR.SelectList[i].bFocused && SS3_VAR.SelectList[i].bExpanded) {
      SS3_VAR.SelectList[i].toggleOptions(false, true);
      SS3_VAR.SelectList[i].toggleTitle(true);
      bHasToDetachEvent = false;
    }
    else if (i!=except) {
      if (SS3_VAR.SelectList[i].bExpanded)
        SS3_VAR.SelectList[i].toggleOptions(false, true);
      if (SS3_VAR.SelectList[i].bReverse)
        SS3_VAR.SelectList[i].toggleTitle(false);
      SS3_VAR.SelectList[i].bFocused = false;
    }
  }

  if (SS3_VAR.bEventAttached && bHasToDetachEvent) {
    document.detachEvent('onmousedown', SS3_blurExcept);
    document.detachEvent('ondblclick', SS3_blurExcept);
    SS3_VAR.bEventAttached = false;
  }
}
function SS3_syncSelectedIndex ()
{
  this.selectedIndex = this.select.selectedIndex;

  if (this.bOriginalSelect) return;

  if (this.TitleTable.cells(0).childNodes(0).innerText != this.options[this.selectedIndex].innerText)
    this.TitleTable.cells(0).childNodes(0).innerText = this.options[this.selectedIndex].innerText;
  if (this.bExpanded)
    this.toggleOptions(false);
}
function SS3_toggleTitle (bReverse)
{
  this.bReverse = ('undefined'!=typeof(bReverse)) ? bReverse: (!this.bReverse);
  this.TitleTable.cells(0).style.backgroundColor = this.bReverse ? SS3_ENV.CR.ReverseBackground : '';
  this.TitleTable.cells(0).style.color = this.bReverse ? SS3_ENV.CR.ReverseText : '';
}
function SS3_checkOptionsDiv ()
{
  if (!this.OptionsDiv) {
    this.createOptionsDiv();
    this.Table.cells(0).appendChild(this.OptionsDiv);
  }
}
function SS3_toggleOptions (bExpanded, bStrict)
{
  this.checkOptionsDiv();

  if (!bStrict && !this.bFocused) {
    SS3_blurExcept(this.ssID);
  }
  this.bExpanded = ('undefined'!=typeof(bExpanded)) ? bExpanded: (!this.bExpanded);
  if (this.bExpanded) {
    this.adjustOptionsDiv();
    this.OptionsDiv.style.display = 'block';
    if (!bStrict) {
      this.toggleTitle(false);
      this.handleOverOption(this.selectedIndex);
    }
    this.handleOutTitle();
  }
  else {
    this.OptionsDiv.style.display = 'none';
    if (!bStrict) {
      this.toggleTitle(true);
    }
  }
  if (!bStrict) {
    this.bFocused = true;

    if (!SS3_VAR.bEventAttached) {
      document.attachEvent('onmousedown', SS3_blurExcept);
      document.attachEvent('ondblclick', SS3_blurExcept);
      SS3_VAR.bEventAttached = true;
    }
  }
}
function SS3_handlePropertychange ()
{
  if ('propertychange'==window.event.type && 'selectedIndex'==window.event.propertyName) {
    var oSS = window.event.srcElement.SS3;
    oSS.syncSelectedIndex();

    if (null != oSS.select.onchange)
      oSS.select.onchange();
  }
}
function SS3_handleMousewheel (event)
{
  var idx = this.selectedIndex;
  if ('mousewheel'==event.type && this.bFocused && this.bReverse) {
    for (var i=0; i < event.wheelDelta; i += 120)
      idx--;
    for (var i=0; i > event.wheelDelta; i -= 120)
      idx++;
  }
  idx = Math.max(idx, 0);
  idx = Math.min(idx, this.options.length - 1);
  this.select.selectedIndex = idx;
}
function SS3_handleOverTitle ()
{
  if (this.bExpanded)
    return;

  this.TitleTable.style.borderColor = SS3_ENV.CR.BorderActive;
  this.TitleTable.cells(1).style.display = 'none';
  this.TitleTable.cells(2).style.display = 'block';
}
function SS3_handleOutTitle ()
{
  this.TitleTable.style.borderColor = SS3_ENV.CR.Border;
  this.TitleTable.cells(2).style.display = 'none';
  this.TitleTable.cells(1).style.display = 'block';
}
function SS3_handleOverOption (idx)
{
  for (var i=0; i < this.options.length; i++) {
    if (i==idx)
      this.turnOnOption(i);
    else
      this.turnOffOption(i);
  }
}
function SS3_turnOnOption (idx)
{
  this.OptionsTable.cells(idx).style.color = SS3_ENV.CR.ReverseText;
  this.OptionsTable.cells(idx).style.backgroundColor = SS3_ENV.CR.ReverseBackground;
}
function SS3_turnOffOption (idx)
{
  this.OptionsTable.cells(idx).style.color = '';
  this.OptionsTable.cells(idx).style.backgroundColor = '';
}
function SS3_adjustOptionsDiv ()
{
  if (this.bOriginalSelect) return;

  this.OptionsDiv.style.width = this.width;
  this.OptionsDiv.style.height = Math.min(this.options.length, this.ListMax) * this.OptionHeight + 2;
  this.OptionsWrapper.style.height = this.options.length * this.OptionHeight;
  this.OptionsDiv.style.overflowY = (this.options.length > this.ListMax) ? 'scroll' : '';

  var top = this.Table.offsetTop;
  var left = this.Table.offsetLeft;
  for (var El = this.Table.offsetParent; 'BODY'!=El.tagName && 'absolute'!=El.style.position && 'relative'!=El.style.position; El = El.offsetParent) {
    if ('TABLE' != El.tagName) {
      top += El.clientTop;
      left += El.clientLeft;
    }
    top += El.offsetTop;
    left += El.offsetLeft;
  }
  this.OptionsDiv.style.top = (this.bListDown) ? (top + this.height) : (top - parseInt(this.OptionsDiv.style.height));
  this.OptionsDiv.style.left = left;

  this.TitleWrapper.style.top = 0;
  this.TitleWrapper.style.left = 0;
}
function SS3_syncOptions ()
{
  if (this.bOriginalSelect) return;

  for (var i=0; i < this.options.length; i++) {
    this.OptionsTable.cells(i).setAttribute('index', i);
    if (this.OptionsTable.cells(i).childNodes(0).innerText != this.options[i].innerText)
      this.OptionsTable.cells(i).childNodes(0).innerText = this.options[i].innerText;
  }
}
function SS3_pressTitle (event)
{
  SS3_cancelEvent(event);

  this.srcElementOfLastMousedown = event.srcElement;

  this.toggleOptions();
}
function SS3_releaseTitle (event)
{
  SS3_cancelEvent(event);

  if (this.isThisEventToBeCanceled(event)) return;

  this.srcElementOfLastMousedown = null;
}
function SS3_pressOption (event)
{
  SS3_cancelEvent(event);

  this.srcElementOfLastMousedown = event.srcElement;
}
function SS3_moveOption (event)
{
  SS3_cancelEvent(event);

  if (this.isThisEventToBeCanceled(event)) return;
  if (!(event.offsetX >= 0 && event.offsetX <= this.OptionsTable.offsetWidth)) return;

  this.handleOverOption(Math.floor(event.offsetY / this.OptionHeight));
}
function SS3_releaseOption (event)
{
  SS3_cancelEvent(event);

  if (this.isThisEventToBeCanceled(event)) return;

  this.srcElementOfLastMousedown = null;

  if (event.offsetX >= 0 && event.offsetX <= this.OptionsTable.offsetWidth) {
    this.toggleOptions(false);
    this.select.selectedIndex = Math.floor(event.offsetY / this.OptionHeight);
  }
}

function SS3_createTable (flag)
{
  this.Table = SS3_createElement("\
    <table border=0 cellpadding=0 cellspacing=0 style='table-layout:fixed; cursor:default'>\
    <tr><td></td></tr>\
    </table>"
  );
  if (!isNaN(this.width))
    this.Table.style.width = this.width;
  this.Table.style.height = this.height;

  if (!this.bOriginalSelect) {
    this.createTitleDiv(flag);
    this.Table.cells(0).appendChild(this.TitleDiv);
  }
  else {
    this.Table.cells(0).appendChild(this.select);
  }
}
function SS3_createTitleDiv (flag)
{
  this.TitleDiv = SS3_createElement("\
    <div style='position:relative;background:#d80007; top:0; left:0;'>\
      <table border=0 cellpadding=0 cellspacing=0\
        height="+this.height+"\
        style='table-layout:fixed; border:0 1 1 1 solid "+SS3_ENV.CR.Border+";'\
        onmouseover=''\
      >\
      <tr>\
        <td style='padding:0 1 0 5'><nobr style='text-oveflow:hidden;"+SS3_ENV.OptionNobrStyle+"'></nobr></td>\
        <td width="+SS3_ENV.ButtonWidth+" align=center style='word-wrap:normal'></td>\
        <td style='display:none' width="+SS3_ENV.ButtonWidth+" align=center style='word-wrap:normal'></td>\
        <td style='display:none'></td>\
      </tr>\
      </table>\
    </div>"
  );
  this.TitleTable = this.TitleDiv.childNodes(0);
  this.TitleTable.cells(0).childNodes(0).innerText = this.options[this.selectedIndex].innerText;
if ( flag == "1" ) {
  this.TitleTable.cells(1).innerHTML = "<img src='"+SS3_ENV.ImgPrefix+"images/arrow_image.gif' border=0 align=absmiddle>";
  this.TitleTable.cells(2).innerHTML = "<img src='"+SS3_ENV.ImgPrefix+"images/arrow_image.gif' border=0 align=absmiddle>";
} else if ( flag == "2" ) {
  this.TitleTable.cells(1).innerHTML = "<img src='"+SS3_ENV.ImgPrefix+"images/ico_search02.gif' border=0 align=absmiddle>";
  this.TitleTable.cells(2).innerHTML = "<img src='"+SS3_ENV.ImgPrefix+"images/ico_search02.gif' border=0 align=absmiddle>";
}
  this.TitleTable.cells(3).appendChild(this.select);
  this.TitleWrapper = document.createElement(""
    + "<img src='"+SS3_ENV.ImgPrefix+"images/null.gif'"
    + "  style='position:absolute; top:0; left:0; z-index:2; width:100%;height:"+this.height+";'"
    + "  onmouseover='SS3_VAR.SelectList["+this.ssID+"].handleOverTitle()'"
    + "  onmouseout='SS3_VAR.SelectList["+this.ssID+"].handleOutTitle(); SS3_VAR.SelectList["+this.ssID+"].releaseTitle(window.event);'"
    + "  onmousedown='SS3_VAR.SelectList["+this.ssID+"].pressTitle(window.event)'"
    + "  ondblclick='SS3_VAR.SelectList["+this.ssID+"].pressTitle(window.event); SS3_VAR.SelectList["+this.ssID+"].releaseTitle(window.event);'"
    + "  onmouseup='SS3_VAR.SelectList["+this.ssID+"].releaseTitle(window.event)'"
    + "  onmousewheel='SS3_VAR.SelectList["+this.ssID+"].handleMousewheel(window.event)'"
    + "  ondragstart='SS3_cancelEvent(window.event)'"
    + ">"
  );
  SS3_CreatedElements[SS3_CreatedElements.length] = this.TitleWrapper;
  this.TitleDiv.appendChild(this.TitleWrapper);
}
function SS3_createOptionsDiv ()
{
  this.OptionsDiv = SS3_createElement("\
    <div style='"+SS3_ENV.OptionsDivStyle+"'\
      onscroll='SS3_VAR.SelectList["+this.ssID+"].moveOption(window.event)'\
      onmousedown='SS3_cancelEvent(window.event)'\
    >\
      <table border=0 cellpadding=0 cellspacing=0 width=100% style='table-layout:fixed'>\
      </table>\
    </div>"
  );
  this.OptionsTable = this.OptionsDiv.childNodes(0);
  for (var i=0; i < this.options.length; i++) {
    this.createOptionTr(i);
  }
  this.syncOptions();
  this.OptionsWrapper = document.createElement(""
    + "<img src='"+SS3_ENV.ImgPrefix+"images/null.gif'"
    + "  style='position:absolute; top:0; left:0; width:100%;'"
    + "  onmousedown='SS3_VAR.SelectList["+this.ssID+"].pressOption(window.event)'"
    + "  onmousemove='SS3_VAR.SelectList["+this.ssID+"].moveOption(window.event)'"
    + "  onmouseup='SS3_VAR.SelectList["+this.ssID+"].releaseOption(window.event)'"
    + "  onmouseout='SS3_VAR.SelectList["+this.ssID+"].releaseOption(window.event)'"
    + "  ondragstart='SS3_cancelEvent(window.event)'"
    + ">"
  );
  SS3_CreatedElements[SS3_CreatedElements.length] = this.OptionsWrapper;
  this.OptionsDiv.appendChild(this.OptionsWrapper);
}
function SS3_createOptionTr (idx)
{
  idx = ('undefined'!=typeof(idx)) ? idx : this.options.length - 1;
  var OptionTr = this.OptionsTable.insertRow(-1);
  var OptionTd = document.createElement("<td height="+this.OptionHeight+" style='padding:2 0 0 2'></td>");
  SS3_CreatedElements[SS3_CreatedElements.length] = this.OptionsTd;
  OptionTd.appendChild(document.createElement("<nobr style='"+SS3_ENV.OptionNobrStyle+"'></nobr>"));
  OptionTr.appendChild(OptionTd);
}