﻿//友善列印
/*
   CSS             所要使用的CSS樣式表的位置
   oL_F_PC         所要列印的內容Tag
   oL_F_PC_Style   所要列印的內容Tag的Style
   oL_F_CR         所要顯示的版權宣告
*/
function FriendlyPrint(CSS, oL_F_PC, oL_F_PC_Style, oL_F_CR) {
   if (window.print) {
      //將所取得的內容、內容Style與版權宣告重新組合成所要呈現的主體
      var str_Style = (oL_F_PC_Style == '') ? '' : ' style="' + oL_F_PC_Style + '"';
      var str_Body = '<table align="center" cellpadding="5" cellspacing="0"' + str_Style + '>' + 
                     '   <tr><td>' + document.getElementById(oL_F_PC).innerHTML + '</td></tr>' + 
                     '   <tr><td align="center">' + document.getElementById(oL_F_CR).innerHTML + '</td></tr>' + 
                     '</table>';
      //重設文件的主體，列印文檔準備就緒
      document.body.innerHTML = (CSS == '') ? str_Body : '<link href="' + CSS + '" rel="stylesheet" type="text/css" />' + str_Body;
      //呼叫列印命令
      window.print();
      //返回到列印前的畫面
      window.history.go(0);
   }
}

//設定預設字型為12字型並存入Cookies
var DefaultFontSize = 12;

//載入預設字型或存入Cookie的字型
/*
   oL_F_FS   所要使用字型的內容Tag
*/
function LoadDefaultOrCookiesFontSize(oL_F_FS) {
    document.getElementById(oL_F_FS).style.fontSize = (GetCookie('MyCookies_FontSize') == '') ? DefaultFontSize : GetCookie('MyCookies_FontSize');
}

//放大字體
function SetFontSizeLarge(oL_F_FS) {
   var int_Size = (document.getElementById(oL_F_FS).style.fontSize == '') ? DefaultFontSize : parseInt(document.getElementById(oL_F_FS).style.fontSize.replace('px', ''));
   document.getElementById(oL_F_FS).style.fontSize = int_Size + 1;
   
   SetCookie('MyCookies_FontSize', int_Size + 1, 0);
}

//縮小字體
function SetFontSizeSmall(oL_F_FS) {
   var int_Size = (document.getElementById(oL_F_FS).style.fontSize == '') ? DefaultFontSize : parseInt(document.getElementById(oL_F_FS).style.fontSize.replace('px', ''));
   document.getElementById(oL_F_FS).style.fontSize = int_Size - 1;
   
   SetCookie('MyCookies_FontSize', int_Size - 1, 0);
}

//建立Cookie記錄
/*
   oC_Name    Cookie名稱
   oC_Value   Cookie所要存的值
   oC_Days    Cookie的有效日期(0表瀏覽器一關閉就消失)
*/
function SetCookie(oC_Name, oC_Value, oC_Days) {
   var date = new Date();
   date.setTime(date.getTime() + (oC_Days * 24 * 60 * 60 * 1000));
   var expires = (oC_Days == 0) ? '' : '; expires=' + date.toGMTString();
   document.cookie = oC_Name + '=' + escape(oC_Value) + expires + '; path=/';
}

//讀取Cookie記錄
/*
   oC_Name    Cookie名稱
*/
function GetCookie(oC_Name) {
   var str_CN = oC_Name + '=';
   var ary_CN = document.cookie.split(';');
   
   for (var i = 0; i < ary_CN.length; i++) {
      var str_C = ary_CN[i];
      while (str_C.charAt(0) == ' ') str_C = str_C.substring(1, str_C.length);
      if (str_C.indexOf(str_CN) == 0) return unescape(str_C.substring(str_CN.length, str_C.length));
   }
   
   return '';
}

//刪除Cookie
/*
   oC_Name    Cookie名稱
*/
function DelCookie(oC_Name) {
   SetCookie(oC_Name, '', -1);
}