///功能說明：ThickBOX 專用關閉開啟的DIV
function windowEditClose() {
    if (confirm("請確定編輯資料已儲存？"))
        parent.tb_remove()
}
function windowAddClose() {
    if (confirm("請確定新增資料已儲存？"))
        parent.tb_remove()

}
function windowClose() {
    if (confirm("您確定要離開嗎？"))
        parent.tb_remove()

}
//檢驗瀏覽器
function chkBroswer() {
    var isIE = navigator.userAgent.search("MSIE") > -1;
    var isFirefox = navigator.userAgent.search("Firefox") > -1;
    var isOpera = navigator.userAgent.search("Opera") > -1;
    var isSafari = navigator.userAgent.search("Safari") > -1; 
    var isChrome = navigator.userAgent.search("Chrome") > -1;

    if (isIE) { return 'isIE'; }
    if (isFirefox) { return 'isFF'; }
    if (isOpera) { return 'isOP'; }
    if (isSafari) { return 'isSF'; }
    if (isChrome) { return 'isCR'; }
}  
//語系網址直接切換
//ExternalInterface.call("RedirectURL('webe')");  AS3
//getURL("javascript:RedirectURL('webe')");  AS2
//lanNow：語系資料夾
function RedirectURL(lanNow) {
    var lanEng = "webe";
    var lanCht = "webc";
    var reUrl;
    var nowurl = location.href; //取得網址
    var chkLan = nowurl.search(lanCht) >= 0 ? lanCht : nowurl.search(lanEng) >= 0 ? lanEng : "";
    if (chkLan != "") {
        reUrl = nowurl.replace(chkLan, lanNow);
        //alert(reUrl);
        location.href = reUrl;
    }
}
//說明：欄位特殊字元檢查
//參數：obj = 元件this。
//參數：msg = 顯示訊息。
//參數：msgshow = 指定顯示訊息的元件。
function GetMsgPanel(obj, msg, msgshow) {
    var submsg = document.getElementById(msgshow);
    if (!SpecialCharChk(obj.value)) {
        submsg.innerHTML = msg;
        submsg.style.color = "red";
        submsg.align = "center";
        obj.value = "";
        obj.focus();
        return (false);
    } else {
        submsg.innerHTML = "";
    }
}
function SpecialCharChk(obj) {
    var regu = "^[_A-Za-z0-9]+$";
    var re = new RegExp(regu);
    if (re.test(obj)) {
        //alert("正確");
        return true;
    } else {
        //alert("只能輸入英文字母或數字、下底線_");
        return false;
    }
}
//Function Name:writeConsole(content)
//說明：檢驗EMAIL格式
//參數：mail = 填入的EMAIL
//use : checkmail('xx@hotmail.com');
function checkmail(mail) {
    var CheckMail = trim(mail);
    return (new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(CheckMail));
} 
//Function Name:writeConsole(content)
//說明：使用JS建立新的檔案並列印
//參數：content = 要輸出列印的內容。
//use : writeConsole('<div>Hello</div>');
function writeConsole(content) {
    top.consoleRef = window.open('', 'myconsole',
              'width=220,height=450'
               + ',menubar=0'
               + ',toolbar=0'
               + ',status=0'
               + ',scrollbars=0'
               + ',resizable=1')
    top.consoleRef.document.writeln(
              '<html><head><!-- MeadCo ScriptX --><object id=factory style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"codebase="../smsx.cab#Version=6,4,438,06"></object>'
               + '<script language=javascript>function printWindow() {factory.printing.header = "";factory.printing.footer = "";factory.printing.portrait = false;factory.printing.leftMargin = 1.0;factory.printing.topMargin = 1.0;factory.printing.rightMargin = 1.0;factory.printing.bottomMargin = 1.0;factory.printing.Print(true);}</' + 'script>'
               + '</head><body bgcolor=white onLoad="self.focus();printWindow()">'
               + content
               + '</body></html>');
    top.consoleRef.document.close();
}
//Function Name:Get_Resolution(angle)
//說明：取得視窗解析度 讓 ThickBox 調整跳出的DIV視窗大小。
//參數：angle = 取得水平或垂直視窗解析度 W 水平  H 垂直。
//use : Get_Resolution('W')
function Get_Resolution(angle) {

        var viewportwidth;
        var viewportheight;

        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight 

        if (typeof window.innerWidth != 'undefined') {
            viewportwidth = window.innerWidth,
            viewportheight = window.innerHeight
        }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 

        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
            viewportwidth = document.documentElement.clientWidth,
            viewportheight = document.documentElement.clientHeight
        }

        // older versions of IE 

        else {
            viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
            viewportheight = document.getElementsByTagName('body')[0].clientHeight
        }
        if (angle == "W") {
            return viewportwidth;
        } else if (angle == "H") {
            return viewportheight;
        }
        //alert('<p>Your viewport width is ' + viewportwidth + 'x' + viewportheight + '</p>');
}

//透過 OUTLOOK 發信
function sendMail(cname,csubject,cmail){ 
   window.location.href = "mailto:"+cname+"<"+cmail+">?subject="+csubject;   
}   
//插入文字訊息
function insertMSG(msg,id){
	document.getElementById(id).innerHTML = msg;
}
//Function Name：trim
//功能介紹：清除前後空白字串
//參數說明：欲清除的字串
function trim(strvalue) {
    ptntrim = /(^\s*)|(\s*$)/g;
    return strvalue.replace(ptntrim, "");
}
//Function Name：trim
//功能介紹：去除字串左空白
//參數說明：欲清除的字串
function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != "  ") break;
    }
    str = str.substring(i, str.length);
    return str;
}
//Function Name：trim
//功能介紹：去除字串右空白
//參數說明：欲清除的字串
function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != "  ") break;
    }
    str = str.substring(0, i + 1);
    return str;
}
//Function Name：openNewWindow
//功能介嚮：另開子視窗傳訊息後重新導向
//參數說明：視窗路徑、名稱及相關設定
function openNewWindow(url,msg,URLtoOpen, windowName, windowFeatures) { 
  alert(msg);
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
  location.href=url;
}
//Function Name：openMyWindow
//功能介嚮：另開子視窗
//參數說明：視窗路徑、名稱及相關設定
function openMyWindow(URLtoOpen, windowName, windowFeatures) { 
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}
//Function checkAll
//功能介紹：全反選 checkbox 物件
//參數說明：欲全反選的欄位名稱
function checkAll(str) {
	var a = document.getElementsByName(str);
	var n = a.length;
	for (var i=0; i<n; i++)
	a[i].checked = window.event.srcElement.checked;
}

//Function Name：redirectURL
//功能介嚮：更新資料後重新導向網址
//參數說明：msg:跳出的訊息,url:重新導向的網頁
//返回值：alert
function redirectURL(msg,url){
    alert(msg);
	location.href=url;
}

function gotoURL(url){
	location.href=url;
}

//Function Name：logoutURL
//功能介嚮：閒置過久登出重新導向網址
//參數說明：msg:跳出的訊息,url:重新導向的網頁
//返回值：alert
function logoutURL(msg,url){
  alert(msg); 
  setTimeout("parent.location='"+url+"'")
}

//Function Name：Check_user_id
//功能介嚮：檢查輸入的帳號是否有重複
//參數說明：msg:跳出的訊息,chk:檢查輸入的帳號是否有重複
//返回值：alert
function Check_user_id(msg,chk){
  alert(msg); 
  if (chk=="failed"){
	opener.document.reg.id.value=""; 
	opener.document.reg.id.focus();
  }
  window.close();
}
//Function Name：Del_Confirm
//功能介嚮：刪除資料確認檢查
//參數說明：url:刪除的程式網址,mem_no刪除資料的ID值
//返回值：alert
function Del_Confirm(url,mem_no,msg)
{
  if(confirm(msg))
		location.href=url+mem_no;
}
//Function Name：Del_Confirm
//功能介嚮：刪除資料確認檢查
//參數說明：url:刪除的程式網址,mem_no刪除資料的ID值
//返回值：alert
function Point_Confirm(url,mem_no,msg)
{
  if(confirm(msg))
		location.href=url+mem_no;
		//alert(url+mem_no)
}
//Function Name：Del_Confirm
//功能介嚮：刪除資料確認檢查
//參數說明：url:刪除的程式網址,mem_no刪除資料的ID值
//返回值：alert
function Reply_Confirm(url,mem_no,msg)
{
  if(confirm(msg))
  form1.submit()
		//location.href=url+mem_no;
		//alert(url+mem_no)
}
//Function Name：MM_jumpMenuURL
//功能介嚮：跳頁選單
//參數說明：targ:開啟網頁的方式,url:導向的網址,觸發的元件selObj:this,回存restore:0
//返回值：alert
function MM_jumpMenuURL(targ,url,selObj,restore){ //v4.0
  eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//Function Name：POPupwin
//功能介嚮：另開視窗配合表格大小調整置中使用
//參數說明：page：頁面 id：傳值
//返回值：無

function POPupwin(page,id) {
   var vstr, rvalue
   rvalue = window.open(page+id,"popup",'height=400,width=400,toolbar=no,scrollbars=yes,resizable=yes');
}

//Function Name：Resize_Move
//功能介嚮：將開啟的視窗調整至表格欄位的大小並移至中間
//參數說明：myTable：表格的ID名稱
//返回值：w：含有表格寬度 h：含有表格高度

function Resize_Move(myTable){
w=eval(document.all[myTable].width)+32; 
h=eval(document.all[myTable].height)+40;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
//alert(w);
//alert(h);
window.resizeTo(w,h);
window.moveTo(LeftPosition,TopPosition)
}

function text_chk(text){
    alert(text);
	history.back()
}  

function view_class_alert(text){
    alert(text);
	//history.back()
} 
//Function Name：fucPWDchk
//功能介嚮：檢查是否含有非數字或字母
//參數說明：要檢查的字符串
//返回值：0：含有 1：全部數字或字母

/*  var ch,i,temp,check;
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     check = 0;
    }
  }

  if (check==0)
  {
     alert('不得輸入字母及數字以外的值。');
	 return false;
  }

  if (strSource.indexOf(ch)==-1)
  {
     alert('不得輸入字母及數字以外的值。');
	 return false;
  }
*/

//Function checkImg
//功能介紹：依圖片大小開始視窗
var imgObj;
function checkImg(theURL,winName){
  if (typeof(imgObj) == "object"){
    if ((imgObj.width != 0) && (imgObj.height != 0))
      OpenFullSizeWindow(theURL,winName, ",width=" + (imgObj.width+20) + ",height=" + (imgObj.height+30));
    else
      setTimeout("checkImg('" + theURL + "','" + winName + "')", 100)
  }
}

function OpenFullSizeWindow(theURL,winName,features) {
  var aNewWin, sBaseCmd;
  sBaseCmd = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,";
  if (features == null || features == ""){
    imgObj = new Image();
    imgObj.src = theURL;
    checkImg(theURL, winName)
  }
  else{
    aNewWin = window.open(theURL,winName, sBaseCmd + features);
    aNewWin.focus();
  }
}

