/*-----------------------------------------------------------------
          ÇÁ ·Î ±× ·¥  Á¤ º¸ 
----------------------------------------------------------------
          ÇÁ·Î ±×·¥ : Å×ÀÌºí ¹öÆ° 
          ÆÄÀÏ Á¤º¸ : M2Button.js
          ¹ö       Àü : 1.5
          Á¦  ÀÛ  ÀÏ : 2003.09.23 , 2003.12.29
          °³  ¹ß  ÀÚ : yoshikiller (yoshikiller@plusem.com)
-----------------------------------------------------------------
         COPYRIGHT 2003 (ÁÖ)À¥ÆÄÆ®³Ê All Rights Rerserved.
-----------------------------------------------------------------*/

//<script>M2Button("Èò»ö", "javascript:alert('Å×½ºÆ®');", 40, 20, 1, 0, 0,'bt2','#FFFFFF','#FFFFFF','#EAEAEA','#808080','#F5F5F5','#F5F5F5','#CACACA','btGray')</script>

var btID = 0;

function M2Button(btTitle, btLink, btWidth, btHeight, btBorderWidth, btDisable, crView, btStyle, btLiteColor, btMidColor, btDarkColor, btBorderColor, btLiteOverColor, btMidOverColor, btDarkOverColor, btCSS, btImg, btLeftSpace, btRightSpace, btImgSpace) {
  var strTABLE,strText;
  btID++;

  if (!btImgSpace) btImgSpace = 4;

  btLink = btLinkFormat( btLink );

  if (btStyle == "bt2") btHeightChk = 6;

  if (btImg && (btImg.length > 1))  {
	strText = "<table border=0 cellpadding=0 cellspacing=0><tr>";
	if (btLeftSpace) strText += "<td width="+btLeftSpace+"></td>";

	if (btDisable)
	  strText += "<td><img src='"+btImg+"' border=0></td>";
	else
	  strText += "<td><div onClick=window.event.returnValue=false; "+btLink+"; style='margin-bottom:-2px;margin-top:2px;line-height:8pt;'><img src='"+btImg+"' border=0></div></td>";

	strText += "<td width="+btImgSpace+"></td>";
	if (btDisable)
	  strText += "<td class='"+btCSS+"'>"+btTitle+"</td>";
	else
	  strText += "<td class='"+btCSS+"'><div onClick=window.event.returnValue=false; "+btLink+"; style='margin-bottom:-2px;margin-top:2px;line-height:8pt;'>"+btTitle+"</div></td>";

	if (btRightSpace) strText += "<td width="+btRightSpace+"></td>";
	strText += "</tr></table>";
  } else {
	strText = "<table border=0 cellpadding=0 cellspacing=0>";
	strText += "<tr><td class="+btCSS+" valign=center height="+((btHeight-11-btHeightChk)/2)+">";

	if (btDisable)
	  strText += "<div style='margin-bottom:-2px;margin-top:2px;line-height:8pt;'>"+ btTitle + "</div>";
	else
	  strText += "<div onClick=window.event.returnValue=false; "+btLink+"; style='margin-bottom:-2px;margin-top:2px;line-height:8pt;'>"+btTitle+"</div>";

	strText += "</td></tr>";
	strText += "</table>";
  }

if (btStyle == "bt2") {
/*--------------------------- ¹öÆ° ½ºÅ¸ÀÏ 2 (´Ü¼øÇÑ ¹öÆ°) ½ÃÀÛ --------------------------------*/

  if (btDisable)
    strTABLE = 
	"<table id=M2Button border=0 width="+btWidth+" cellpadding=0 cellspacing=0 onmouseover=\"this.style.cursor='default'\">";
  else
    strTABLE = 
	"<table id=M2Button border=0 width="+btWidth+" cellpadding=0 cellspacing=0 onclick="+btLink+" onmousedown=\"M2ButtonCC2("+btID+", '"+btDarkOverColor+"', '"+btMidOverColor+"', '"+btLiteOverColor+"');\" onmouseup=\"M2ButtonCC2("+btID+", '"+btLiteOverColor+"', '"+btMidOverColor+"', '"+btDarkOverColor+"');\" onmouseover=\"this.style.cursor='hand';M2ButtonCC2("+btID+", '"+btLiteOverColor+"', '"+btMidOverColor+"', '"+btDarkOverColor+"');\" onmouseout=\"M2ButtonCC2("+btID+", '"+btLiteColor+"', '"+btMidColor+"', '"+btDarkColor+"');\">";
  document.write(strTABLE);

  strTABLE = 
  "<tr height="+btBorderWidth+"> "+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+(btWidth-6)+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "<tr height="+btBorderWidth+"> "+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "<tr height="+btBorderWidth+"> "+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "<tr height=" + (btHeight-btHeightChk) + "> "+
    "<td width="+btBorderWidth+" bgcolor="+btBorderColor+"></td>"+
    "<td width="+btBorderWidth+" bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td width="+btBorderWidth+" bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td align='center' valign='middle' bgcolor="+btMidColor+" id=M2ButtonMidC"+btID+">";
  document.write(strTABLE);
  document.write(strText);

  strTABLE = 
	"</td>"+
    "<td width="+btBorderWidth+" bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td id=M2ButtonDarkC"+btID+" width="+btBorderWidth+" bgcolor="+btDarkColor+"></td>"+
    "<td width="+btBorderWidth+" bgcolor="+btBorderColor+"></td>"+
  "</tr>"+
  "<tr height="+btBorderWidth+"> "+
   " <td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" id=M2ButtonLiteC"+btID+"></td>"+
    "<td id=M2ButtonDarkC"+btID+" bgcolor="+btDarkColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "<tr height="+btBorderWidth+"> "+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td id=M2ButtonDarkC"+btID+" bgcolor="+btDarkColor+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "<tr height="+btBorderWidth+"> "+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btBorderColor+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
    "<td bgcolor="+btLiteColor+" width="+btBorderWidth+"></td>"+
  "</tr>"+
  "</table>";
  document.write(strTABLE);
/*--------------------------- ¹öÆ° ½ºÅ¸ÀÏ 2 (´Ü¼øÇÑ ¹öÆ°) ³¡ --------------------------------*/

}
 // »ö»ó°ª º¸¿©ÁÖ±â
  if (crView) {
  strStr = 
	"<table border=0>" +
	"<tr><td height=10></td></tr>" +
	"<tr><td><b>Æò»ó½Ã</b></td></tr>" +
	"<tr><td>¹àÀº»ö : <font color="+btLiteColor+">"+ btLiteColor + "</font>, Áß°£»ö : <font color="+btMidColor+">" + btMidColor + "</font>, ¾îµÎ¿î»ö : <font color="+btDarkColor+">" + btDarkColor + "</font></td></tr>" +
	"<tr><td height=10></td></tr>" +
	"<tr><td><b>·Ñ¿À¹ö½Ã</b><br>" + "</td></tr>" +
	"<tr><td>¹àÀº»ö : <font color="+btMidColor+">"+ btMidColor + "</font>, Áß°£»ö : <font color="+btMidOverColor+">" + btMidOverColor + "</font>, ¾îµÎ¿î»ö : <font color="+btDarkOverColor+">" + btDarkOverColor + "</font></td></tr>" +
	"<tr><td height=10></td></tr>" +
	"<tr><td><b>Å×µÎ¸®</b><br>" + "</td></tr>" +
	"<tr><td>Å×µÎ¸® : <font color="+btDarkColor+">"+ btDarkColor + "</font></td></tr>" + 
	"</table>";
  document.write(strStr);
  }	
}


function btLinkFormat( btLink ) {
  var stronBtClick = "";
  var nPos = -1;
  var strHREF = "";
  var strTarget = "";
  var strLow;

  strLow = btLink;
  strLow.toLowerCase();
  nPos = strLow.indexOf( "javascript:" );
  if ( nPos >= 0 ) return QuoteMark( btLink );

  nPos = btLink.indexOf( " " );
  if ( nPos > 0 ) strHREF = btLink.substring( 0, nPos );
  else strHREF = btLink;

  nPos = btLink.indexOf( "target=" );
  if ( nPos > 0 ) strTarget = btLink.substr( nPos + 7 );

  strHREF = QuoteMark( strHREF );
  strTarget = QuoteMark( strTarget );
  stronBtClick = "javascript:onBtClick( " + strHREF + " , " + strTarget + " )";
  stronBtClick = QuoteMark( stronBtClick );

  return stronBtClick;
}

function onBtClick( strLink, strTarget ) {
  if ( strTarget && strTarget.length > 0 ) window.open( strLink, strTarget );
  else document.location = strLink;
}

function QuoteMark( str ) {
  var nDouble = 0;
  var ch;
  var i;

  ch = str.charCodeAt( 0 );
  if ( ( ch == 34 ) || ( ch == 39 ) ) return str;

  for ( i = 1 ; i < str.length - 1 ; i++ )
  {
    ch = str.charCodeAt( i );
    if ( ch == 39 )
    {
      nDouble = 1;
      break;
    }
  }

  if ( nDouble ) strQuote = "\"";
  else strQuote = "'";

  return ( strQuote + str + strQuote );
}

function M2ButtonCC1(currentbtID, btLiteColor, btDarkColor)
{
  var colLiteCR = document.getElementsByName("M2ButtonLiteC"+currentbtID);
  var colDarkCR = document.getElementsByName("M2ButtonDarkC"+currentbtID);

  for (var i=0; i<colLiteCR.length; i++)
    colLiteCR[i].bgColor = btLiteColor;
  for (var i=0; i<colDarkCR.length; i++)
    colDarkCR[i].bgColor = btDarkColor;
}

function M2ButtonCC2(currentbtID, btLiteColor,btMidColor,btDarkColor) {
  var colLiteCR = document.getElementsByName("M2ButtonLiteC"+currentbtID);
  var colMidCR = document.getElementsByName("M2ButtonMidC"+currentbtID);
  var colDarkCR = document.getElementsByName("M2ButtonDarkC"+currentbtID);

  for (var i=0; i<colLiteCR.length; i++)
    colLiteCR[i].bgColor = btLiteColor;
  for (var i=0; i<colMidCR.length; i++)
    colMidCR[i].bgColor = btMidColor;
  for (var i=0; i<colDarkCR.length; i++)
    colDarkCR[i].bgColor = btDarkColor;
}
