var IE4, NS4, NS6;

//檢查瀏覽器
if ( document.all )
{

   IE4 = true;

}

else if(document.layers)
{

   NS4 = true;

}

else if (document.getElementById)
{

   NS6 = true;

}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function getSelectBoxOption (ArrayName, BoxObj, DefaultValue)
{

   if ( (typeof (ArrayName) == "undefined") || (typeof (BoxObj) == "undefined") )
   {

      return false;

   }

   for (var i = BoxObj.options.length-1 ; i >= 0 ; i--)
   {

       BoxObj.options[i] = null;

   }

   for (var i = 0 ; i < ArrayName.length ; i++)
   {

       BoxObj.options[i] = new Option(ArrayName[i].text, ArrayName[i].value);

       if (ArrayName[i].value == DefaultValue)
       {

          BoxObj.options[i].selected = true;

       }

   }

}


function redirect (ArrayName, Obj, SelectVar)
{

   if ( (typeof (Obj) == "undefined") || (typeof (ArrayName) == "undefined") )
   {

      return false;

   }

   for (var i = Obj.options.length-1 ; i >= 0 ; i--)
   {

       Obj.options[i] = null;

   }

   for (var i = 0 ; i < ArrayName.length ; i++)
   {

       Obj.options[i] = new Option(ArrayName[i].text, ArrayName[i].value);

       if (ArrayName[i].value == SelectVar)
       {

          Obj.options[i].selected = true;

       }

   }

}


//填塞字串成為指定的長度
///////////////////////////////////////////////////////////////////////////////
//此函式填塞到字串參數 inputStr 的左邊、右邊或是左邊及右邊，成為指定的填塞長 //
//度。如果沒有提供選項 padString ，則使用空白將參數 inputStr 填塞，否則，它會//
//使用 padString 填塞到指定的長度。                                          //
//                                                                           //
//選項 padType 可以是 STR_PAD_RIGHT、STR_PAD_LEFT 或是STR_PAD_BOTH，如果沒有 //
//指定 padType，則假定為 STR_PAD_RIGHT。                                     //
//                                                                           //
//如果 pad_length的值是負數或是小於輸入字串的長度時，則不會填塞              //
///////////////////////////////////////////////////////////////////////////////
function strPad (inputStr, padLength, padString, padType)
{

   if ( (typeof (inputStr) == "undefined") && (typeof (padLength) == "undefined") )
   {

      return "";

   }

   var inputStr = new String (inputStr);

   if (typeof (padString) == "undefined")
   {

      var padString = " ";

   }

   if (typeof (padType) == "undefined")
   {

      var padType = "STR_PAD_RIGHT";

   }

   padLength = Number (padLength);

   if (isNaN(padLength) == true)
   {

      return inputStr;

   }

   if (inputStr.length >= padLength)
   {

      return inputStr;

   }

   var addString = new Array ();
       addString[0] = "";
       addString[1] = "";

   if (padType == "STR_PAD_LEFT")
   {

      for (var i = inputStr.length ; i < padLength ; i++ )
      {

         addString[0] += padString;

      }

      return (addString[0] + inputStr);

   }

   else if (padType == "STR_PAD_BOTH")
   {

      var centerNum = (padLength - inputStr.length) - ( (padLength - inputStr.length) % 2 );

      if (centerNum > 0)
      {

         centerNum = (centerNum / 2);

      }

      centerNum = ( (centerNum + inputStr.length) - 1 );

      for (var i = inputStr.length ; i < padLength ; i++ )
      {

         if ( i <= centerNum )
         {

            addString[0] += padString;

         }

         else
         {

            addString[1] += padString;

         }

      }

      return (addString[0] + inputStr + addString[1]);

   }

   else
   {

      for (var i = inputStr.length ; i < padLength ; i++ )
      {

         addString[0] += padString;

      }

      return (inputStr + addString[0]);

   }

   return inputStr;

}


function getNowDate (DateBox)
{

   if (document.getElementById(DateBox))
   {

      var nowDate = new Date ();
      var nowHours = nowDate.getHours ();
      setTimeout ("getNowDate ('" + DateBox + "')", 1000);
      document.getElementById(DateBox).innerHTML = showMonth[nowDate.getMonth ()] + ". " + nowDate.getDate () + ", " + nowDate.getFullYear () + " " + strPad (nowHours, 2, "0", "STR_PAD_LEFT") + ":" + strPad (nowDate.getMinutes (), 2, "0", "STR_PAD_LEFT") + ":" + strPad (nowDate.getSeconds (), 2, "0", "STR_PAD_LEFT");

   }

}


function OpenPopupWindow (WindowUrl, WindowName, WindowWidth, WindowHeight, WindowTop, WindowLeft, WindowStatus, WindowScrollbars)
{

   WindowName = ( ( typeof (WindowName) == "undefined") || (WindowName == "") ) ? "PopupWindow" : WindowName;
   WindowWidth = ( (typeof (WindowWidth) == "undefined") || (WindowWidth == "") ) ? 0 : WindowWidth;
   WindowHeight = ( (typeof (WindowHeight) == "undefined") || (WindowHeight == "") ) ? 0 : WindowHeight;
   WindowTop = ( (typeof (WindowTop) == "undefined") || (WindowTop == "") ) ? ( (eval (WindowHeight) == 0) ? 0 : (((screen.availHeight - WindowHeight) - ((screen.availHeight - WindowHeight) % 2)) / 2) ) : WindowTop;
   WindowLeft = ( (typeof (WindowLeft) == "undefined") || (WindowLeft == "") ) ? ( (eval (WindowWidth) == 0) ? 0 : (((screen.availWidth - WindowWidth) - ((screen.availWidth - WindowWidth) % 2)) / 2) ) : WindowLeft;
   WindowStatus = ( (typeof (WindowStatus) == "undefined") || (WindowStatus == "") ) ? "" : WindowStatus;
   WindowScrollbars = ( (typeof (WindowScrollbars) == "undefined") || (WindowScrollbars == "") ) ? "" : WindowScrollbars;

   var WindowConfig = "";

   WindowConfig = ( (eval (WindowWidth) == 0) ? "" : "width=" + eval (WindowWidth) + "px" );
   WindowConfig += ( (eval (WindowHeight) == 0) ? "" : ( (WindowConfig == "") ? "" : ", " ) + "height=" + eval (WindowHeight) + "px" );
   WindowConfig += ( (WindowConfig == "") ? "" : ", " ) + ( (eval (WindowTop) == 0) ? "top=" + ((screen.availHeight - (screen.availHeight % 2)) / 2) + "px" : "top=" + eval (WindowTop) + "px" );
   WindowConfig += ( (eval (WindowLeft) == 0) ? "" : ( (WindowConfig == "") ? "" : ", " ) + "left=" + eval (WindowLeft) + "px" );
   WindowConfig += ( (WindowStatus == "") ? "" : ( (WindowConfig == "") ? "" : ", " ) + "status=" + WindowStatus );
   WindowConfig += ( (WindowScrollbars == "") ? "" : ( (WindowConfig == "") ? "" : ", " ) + "scrollbars=" + WindowScrollbars );

   window.open (WindowUrl, WindowName, WindowConfig);

}

function changeImg (DivName, ImgSrc, ImgWidth, ImgHeight)
{

   if (document.getElementById(DivName))
   {

      document.getElementById(DivName).innerHTML = ('<img src="' + ImgSrc + '" width="' + ImgWidth + '" height="' + ImgHeight + '" border="0" title="" alt="" />');

   }

}


function changeFlash (DivName, FlashSrc, FlashWidth, FlashHeight)
{

   if (document.getElementById(DivName))
   {

      document.getElementById(DivName).innerHTML = ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + FlashWidth + '" height="' + FlashHeight + '"><param name="movie" value="' + FlashSrc + '"><param name="wmode" value="transparent"><param name="quality" value="high"><embed src="' + FlashSrc + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="' + FlashWidth + '" height="' + FlashHeight + '"></embed></object>');

   }

}


function changePicItem (IdName, ExceptionId)
{

   var i = 0;

   while (document.getElementById(IdName + "[" + i + "]"))
   {

       if (document.getElementById(IdName + "[" + i + "]"))
       {

          if ( i == ExceptionId)
          {

             document.getElementById(IdName + "[" + i + "]").style.display = "none";

          }

          else
          {

             document.getElementById(IdName + "[" + i + "]").style.display = "";

          }

       }

       i++;

   }

}

function changeText (IdName, TextString)
{

   if ( (document.getElementById(IdName)) && (typeof (TextString) != "undefined") && (TextString != "") )
   {

      document.getElementById(IdName).innerHTML = TextString;

   }

}