arrLinks = new Array();
arrTargets = new Array();
document.onkeydown=onPressShortCut;

function onPressShortCut()
{
	var objFocus = document.activeElement;
	if ( objFocus != document.body ) return;

	var cKey = String.fromCharCode( event.keyCode );
	var strLink = arrLinks[ cKey ];
	if ( !strLink ) return;

	var strLow = strLink;
	strLow.toLowerCase();
	var strTarget = arrTargets[ cKey ];
	var nPos = -1;
	
	nPos = strLow.indexOf( "javascript:" );
	if ( nPos >= 0 ) eval( strLink );
	else onClickHref( strLink, strTarget );
}

function addShortcut( cKey, strLink )
{
	var nPos = -1;
	var strHREF = "";
	var strTarget = "";
	var cUpperKey = cKey;
	cUpperKey.toUpperCase();

	nPos = strLink.indexOf( " " );
	if ( nPos > 0 ) 
	{
		strHREF = strLink.substring( 0, nPos );
		nPos = strLink.indexOf( "target=" );
		if ( nPos > 0 ) strTarget = strLink.substr( nPos + 7 );
	}
	else strHREF = strLink;

	arrLinks[ cUpperKey ] = strHREF;
	arrTargets[ cUpperKey ] = strTarget;
}

function onClickHref( strLink, strTarget )
{
  if ( strTarget && strTarget.length > 0 ) window.open( strLink, strTarget );
  else document.location = strLink;
}

function getStrWidth( str, nUnit )
{
  var i, nCode;
  var nWidth = 0;
  if ( !str ) return 0;

  for ( i = 0 ; i < str.length; i++ )
  {
    nCode = str.charCodeAt( i );
    if ( ( nCode < 0 ) || ( nCode > 127 ) ) nWidth += nUnit * 2;
    else nWidth += nUnit;
  }

  return nWidth;
}

function setForceQuote( 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 getBtnHREF( strLink )
{
  var strOnClickHref = "";
  var nPos = -1;
  var strHREF = "";
  var strTarget = "";
  var strLow;

  strLow = strLink;
  strLow.toLowerCase();
  nPos = strLow.indexOf( "javascript:" );
  if ( nPos >= 0 ) return setForceQuote( strLink );

  nPos = strLink.indexOf( " " );
  if ( nPos > 0 ) strHREF = strLink.substring( 0, nPos );
  else strHREF = strLink;

  nPos = strLink.indexOf( "target=" );
  if ( nPos > 0 ) strTarget = strLink.substr( nPos + 7 );

  strHREF = setForceQuote( strHREF );
  strTarget = setForceQuote( strTarget );
  strOnClickHref = "javascript:onClickHref( " + strHREF + " , " + strTarget + " )";
  strOnClickHref = setForceQuote( strOnClickHref );

  return strOnClickHref;
}

function makeBtn2( strBtnTitle, strLink, nWidth, strLiteCR, strMidCR, strDarkCR, strCSS, strImg, nLeftGap, nImgGap, nRiteGap, cKey )
{
	var strFormat;

	if ( !strBtnTitle ) strBtnTitle = ls_btn_ok;
	if ( !strLink ) strLink = "#";

	if ( cKey ) 
	{
		addShortcut( cKey, strLink );
		strBtnTitle += " (" + cKey + ")";
	}

	strLink = getBtnHREF( strLink );

	if ( !nWidth || ( nWidth <= 0 ) ) nWidth = getStrWidth( strBtnTitle, 10 );

	if ( !strLiteCR ) strLiteCR = "#FFFFFF";
	if ( !strMidCR ) strMidCR = "#E5E5E5";
	if ( !strDarkCR ) strDarkCR = "#999999";
	if ( !strCSS ) strCSS = "csbtn2";
	if ( !nImgGap ) nImgGap = 4;

	strFormat = "<table id=makeBtn2 border=0 width=" + nWidth + " cellpadding=0 cellspacing=0 onclick="+strLink+" onmouseover=\"this.style.cursor='hand'\">";
	document.write( strFormat );

	strFormat = "<tr><td colspan=2 width=2></td><td colspan=3 width=" +
	( nWidth - 4 ) + " bgcolor=black></td><td colspan=2 width=2></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1></td><td width=1 bgcolor=black></td><td width=1 bgcolor=" + strLiteCR + "></td><td width=" +
	( nWidth - 6 ) + " bgcolor=" + strLiteCR + "></td><td width=1 bgcolor=" + strDarkCR +
	"></td><td width=1 bgcolor=black></td><td width=1></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1 bgcolor=black></td><td width=2 colspan=2 bgcolor=" + strLiteCR + "></td><td colspan=2 width=" +
	( nWidth - 5 ) + " bgcolor=" + strMidCR + "></td><td width=1 bgcolor=" + strDarkCR + "></td><td colspan=1 width=1 bgcolor=black></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1 bgcolor=black></td><td width=1 bgcolor=" + strLiteCR + "></td><td  colspan=3 width=" + 
	( nWidth - 4 ) + " bgcolor=" + strMidCR + "></td><td width=1 bgcolor=" + strDarkCR + "></td><td width=1 bgcolor=black></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1 bgcolor=black></td><td width=1 bgcolor=" + strLiteCR + "></td>";
	strFormat += "<td class=" + strCSS + " colspan=3 width=" + ( nWidth - 4 ) + " bgcolor=" + strMidCR + " align=center>";
	if ( strImg && ( strImg.length > 1 ) )
	{
	strFormat += "<table border=0 cellpadding=0 cellspacing=0><tr>";
	if ( nLeftGap ) strFormat += "<td width=" + nLeftGap + "></td>";
	strFormat += "<td><a href=" + strLink + " onclick='window.event.returnValue=false'><img src='" + strImg + "' border=0></a></td>";
	strFormat += "<td width=" + nImgGap + "></td>";
	strFormat += "<td class='" + strCSS + "'><a href=" + strLink + " onclick='window.event.returnValue=false'>" + strBtnTitle + "</a></td>";
	if ( nRiteGap ) strFormat += "<td width=" + nRiteGap + "></td>";
	strFormat += "</tr></table></td>";
	}
	else
	{
	strFormat += "<a href=" + strLink + " onclick='window.event.returnValue=false'>" + strBtnTitle + "</a></td>";
	}
	strFormat += "<td width=1 bgcolor=" + strDarkCR + "></td><td width=1 bgcolor=black></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1 bgcolor=black></td><td width=1 bgcolor=" + strDarkCR + "></td><td colspan=2 width=" + 
	( nWidth - 5 ) + " bgcolor=" + strMidCR + "></td><td colspan=2 width=2 bgcolor=" + strDarkCR + "></td><td width=1 bgcolor=black></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td width=1></td><td width=1 bgcolor=black></td><td colspan=3 width=" +
	( nWidth - 4 ) + " bgcolor=" + strDarkCR + "></td><td width=1 bgcolor=black></td><td width=1></td></tr>";
	document.write( strFormat );

	strFormat = "<tr><td colspan=2 width=2></td><td colspan=3 width=" + ( nWidth - 4 ) +
	" bgcolor=black></td><td colspan=2 width=2></td></tr></table>";
	document.write( strFormat );
}

function makeBtnChangeCR(currentBtnID, strLiteCR, strMidCR, strDarkCR)
{
  var colLiteCR = document.getElementsByName("makeBtnLiteCR_"+currentBtnID);
  var colMidCR = document.getElementsByName("makeBtnMidCR_"+currentBtnID);
  var colDarkCR = document.getElementsByName("makeBtnDarkCR_"+currentBtnID);

  for (var i=0; i<colLiteCR.length; i++)
    colLiteCR[i].bgColor = strLiteCR;
  for (var i=0; i<colMidCR.length; i++)
    colMidCR[i].bgColor = strMidCR;
  for (var i=0; i<colDarkCR.length; i++)
    colDarkCR[i].bgColor = strDarkCR;
}

var btnID = 0;
function makeBtn(strBtnTitle, strLink, nWidth, nHeight, disable, strLiteCR, strMidCR, strDarkCR, strBorderCR, strLiteOverCR, strMidOverCR, strDarkOverCR, strCSS, strImg, nLeftGap, nImgGap, nRiteGap, cKey)
{
  var strFormat;

  btnID++;
  if (!strBtnTitle) strBtnTitle = ls_btn_ok;
  if (!strLink) strLink = "#";
  if (!nWidth || (nWidth <= 0)) nWidth = getStrWidth(strBtnTitle, 10);
  if (!nHeight || (nHeight <= 0)) nHeight = 20;
  if (!strLiteCR) strLiteCR = "#FFFFFF";
  if (!strMidCR) strMidCR = "#E5E5E5";
  if (!strDarkCR) strDarkCR = "#999999";
  if (!strBorderCR) strBorderCR = "#222222";

  if (!strLiteOverCR) strLiteOverCR = strLiteCR;
//  if (!strMidOverCR) strMidOverCR = strMidCR;
  if (!strMidOverCR) strMidOverCR = "#F1FAFF";
  if (!strDarkOverCR) strDarkOverCR = strDarkCR;

  if (!strCSS) strCSS = "csbtn3";
  if (!nImgGap) nImgGap = 4;

  strLink = getBtnHREF( strLink );
  if (cKey) 
  {
    addShortcut(cKey, strLink);
    strBtnTitle += " ("+cKey+")";
  }

  if (disable)
    strFormat = 
"<table id=makeBtn border=0 width="+nWidth+" cellpadding=0 cellspacing=0 onmouseover=\"this.style.cursor='default'\">";
  else
    strFormat = 
"<table id=makeBtn border=0 width="+nWidth+" cellpadding=0 cellspacing=0 onclick="+strLink+" onmousedown=\"makeBtnChangeCR("+btnID+", '"+strDarkOverCR+"', '"+strMidOverCR+"', '"+strLiteOverCR+"');\" onmouseup=\"makeBtnChangeCR("+btnID+", '"+strLiteOverCR+"', '"+strMidOverCR+"', '"+strDarkOverCR+"');\" onmouseover=\"this.style.cursor='hand';makeBtnChangeCR("+btnID+", '"+strLiteOverCR+"', '"+strMidOverCR+"', '"+strDarkOverCR+"');\" onmouseout=\"makeBtnChangeCR("+btnID+", '"+strLiteCR+"', '"+strMidCR+"', '"+strDarkCR+"');\">";
  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td width=1></td>"+
  "<td width=1></td>"+
  "<td width=1 bgcolor="+strBorderCR+"></td>"+
  "<td width="+( nWidth - 6 )+" bgcolor="+strBorderCR+"></td>"+
  "<td width=1 bgcolor="+strBorderCR+"></td>"+
  "<td width=1></td>"+
  "<td width=1></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnLiteCR_"+btnID+" colspan=2 bgcolor="+strLiteCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" bgcolor="+strDarkCR+"></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td></td>"+
"</tr>";
  document.write( strFormat );

  strFormat = 
"<tr height=1>"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnLiteCR_"+btnID+" colspan=2 bgcolor="+strLiteCR+"></td>"+
  "<td id=makeBtnMidCR_"+btnID+" rowspan=4 bgcolor="+strMidCR+" class="+strCSS+" align=center>";

  if (strImg && (strImg.length > 1))
  {
    strFormat += "<table border=0 cellpadding=0 cellspacing=0><tr>";
    if (nLeftGap) strFormat += "<td width="+nLeftGap+"></td>";

    if (disable)
      strFormat += "<td><img src='"+strImg+"' border=0></td>";
    else
      strFormat += "<td><a href="+strLink+" onclick='window.event.returnValue=false'><img src='"+strImg+"' border=0></a></td>";

    strFormat += "<td width="+nImgGap+"></td>";
    if (disable)
      strFormat += "<td class='"+strCSS+"'>"+strBtnTitle+"</td>";
    else
      strFormat += "<td class='"+strCSS+"'><a href="+strLink+" onclick='window.event.returnValue=false'>"+strBtnTitle+"</a></td>";

    if (nRiteGap) strFormat += "<td width="+nRiteGap+"></td>";
    strFormat += "</tr></table>";
  }
  else
  {
    strFormat += "<table border=0 cellpadding=0 cellspacing=0>";
 //   strFormat += "<tr height="+((nHeight-11-4)/2)+"><td></td></tr>";
    strFormat += "<tr><td class="+strCSS+" style='padding:1 0 1 0'>";

    if (disable)
      strFormat += strBtnTitle;
    else
      strFormat += "<a href="+strLink+" onclick='window.event.returnValue=false'>"+strBtnTitle+"</a>";

    strFormat += "</td></tr>";
    strFormat += "</table>";
  }

  strFormat += 
  "</td>"+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" bgcolor="+strDarkCR+"></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
"</tr>";

  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnLiteCR_"+btnID+" bgcolor="+strLiteCR+"></td>"+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  ""+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" bgcolor="+strDarkCR+"></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = 
"<tr height="+(nHeight-7)+">"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnLiteCR_"+btnID+" bgcolor="+strLiteCR+"></td>"+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  ""+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" bgcolor="+strDarkCR+"></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" bgcolor="+strDarkCR+"></td>"+
  "<td id=makeBtnMidCR_"+btnID+" bgcolor="+strMidCR+"></td>"+
  ""+
  "<td id=makeBtnDarkCR_"+btnID+" colspan=2 bgcolor="+strDarkCR+"></td>"+
  "<td bgcolor="+strBorderCR+"></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td width=1></td>"+
  "<td width=1 bgcolor="+strBorderCR+"></td>"+
  "<td id=makeBtnDarkCR_"+btnID+" colspan=3 bgcolor="+strDarkCR+"></td>"+
  "<td width=1 bgcolor="+strBorderCR+"></td>"+
  "<td width=1></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = 
"<tr height=1>"+
  "<td colspan=2 width=2></td>"+
  "<td colspan=3 bgcolor="+strBorderCR+"></td>"+
  "<td colspan=2 width=2></td>"+
"</tr>";
  document.write(strFormat);

  strFormat = "</table>";
  document.write(strFormat);
}


function makeTabMenu( strBtnTitle, strLink, nWidth, nHeight, strCR, strBDCR, strCSS, cKey ) {
	var strFormat;

	if ( !strBtnTitle ) strBtnTitle = ls_tab_sel;
	if ( !strLink ) strLink = "#";

	if ( cKey ) 
	{
		addShortcut( cKey, strLink );
		strBtnTitle += " (" + cKey + ")";
	}

	strLink = getBtnHREF( strLink );
	if ( !nWidth ) nWidth = getStrWidth( strBtnTitle, 20 );
	if ( !nHeight ) nHeight = 15;
	if ( !strCR ) strCR = "#D1D1D1";
	if ( !strBDCR ) strBDCR = "black";
	if ( !strCSS ) strCSS = "cstab";

	strFormat = "<table border=0 cellpadding=0 cellspacing=0 width=" + nWidth + " onmouseover=\"this.style.cursor='hand'\" onclick=" + strLink + " STYLE='table-layout:fixed'>";
	document.write( strFormat );

	strFormat = "<tr HEIGHT=1><td colspan=3 HEIGHT=1 width=3></td><td width=" + ( nWidth - 6 ) + " bgcolor=" + strBDCR + "></td><td colspan=3 width=3></td></tr>";
	document.write( strFormat );

	strFormat = "<tr HEIGHT=1><td HEIGHT=1 width=1></td><td colspan=2 width=2 bgcolor=" + strBDCR + "></td><td width=" + ( nWidth - 6 ) + " bgcolor=" + strCR + "></td><td colspan=2 width=2 bgcolor=" + strBDCR + "></td><td width=1></td></tr>";
	document.write( strFormat );

	strFormat = "<tr HEIGHT=1><td HEIGHT=1 width=1></td><td width=1 bgcolor=" + strBDCR + "></td><td colspan=3 width=" + ( nWidth - 4 ) + " bgcolor=" + strCR + "></td><td width=1 bgcolor=" + strBDCR + "></td><td width=1></td></tr>";
	document.write( strFormat );

	strFormat = "<tr HEIGHT=1><td HEIGHT=1 width=1 bgcolor=" + strBDCR + "></td><td colspan=5 width=" + ( nWidth - 2 ) + " bgcolor=" + strCR + "><table border=0 cellspacing=1 cellpadding=0><tr><td></td></tr></table> </td><td width=1 bgcolor=" + strBDCR + "></td></tr>";
	document.write( strFormat );

	strFormat = "<tr height=" + (nHeight - 5) + "><td width=1 HEIGHT=" + (nHeight - 5) + " bgcolor=" + strBDCR + "></td><td colspan=5 width=" + ( nWidth - 2 ) + " bgcolor=" + strCR + " class='" + strCSS + "' align=center><a href=" + strLink + " onclick='window.event.returnValue=false'>" + strBtnTitle + "</a></td><td width=1 bgcolor=" + strBDCR + "></td></tr>";
	document.write( strFormat );

	strFormat = "<tr HEIGHT=1><td HEIGHT=1 width=1 bgcolor=" + strBDCR + "></td><td colspan=5 width=" + ( nWidth - 2 ) + " bgcolor=" + strCR + "><table border=0 cellspacing=1 cellpadding=0><tr><td></td></tr></table> </td><td width=1 bgcolor=" + strBDCR + "></td></tr>";
	document.write( strFormat );

	document.write( "</table>" );
}

// CSS definition
document.write ("\
<style type=text/css>\
.csbtn { font-size:9pt; color: #F7F7FF; line-height: 11pt; text-decoration: none; }\
.csbtn a { color: #F7F7FF; text-decoration: none; }\
.csbtn a:visited { color: #F7F7FF; text-decoration: none; }\
.csbtn a:active { color: #F7F7FF; text-decoration: none; }\
.csbtn a:hover { color: #F7F7FF; text-decoration: none; cursor: hand; }\
.csbtn2 { font-size:9pt; color: #000000; line-height: 11pt; text-decoration: none; }\
.csbtn2 a { color: #000000; text-decoration: none; }\
.csbtn2 a:visited { color: #000000; text-decoration: none; }\
.csbtn2 a:active { color: #000000; text-decoration: none; }\
.csbtn2 a:hover { color: #000000; text-decoration: none; cursor: hand; }\
.csbtn3 { font-size:9pt; color: #000000; line-height: 11pt; text-decoration: none; }\
.csbtn3 a { color: #000000; text-decoration: none; }\
.csbtn3 a:visited { color: #000000; text-decoration: none; }\
.csbtn3 a:active { color: #000000; text-decoration: none; }\
.csbtn3 a:hover { color: #000000; line-height: 11pt; text-decoration: none; cursor: hand; }\
.csbtn4 { font-size:9pt; color: #F7F7FF; line-height: 11pt; text-decoration: none; }\
.csbtn4 a { color: #F7F7FF; text-decoration: none; }\
.csbtn4 a:visited { color: #F7F7FF; text-decoration: none; }\
.csbtn4 a:active { color: #F7F7FF; text-decoration: none; }\
.csbtn4 a:hover { color: #F7F7FF; line-height: 11pt; text-decoration: none; cursor: hand; }\
.cstab { font-size:9pt; color: #ffffff; line-height: 11pt; text-decoration: none; }\
.cstab a { color: #ffffff; text-decoration: none; }\
.cstab a:hover { color: #ffffff; line-height: 11pt; text-decoration: none; cursor: hand; position:relative; top:1px; left:1px;}\
</style>\
");