﻿///功能說明：ThickBOX 專用關閉開啟的DIV
function windowEditClose() {
    if (confirm("請確定編輯資料已儲存？"))
        parent.tb_remove()
}
function windowAddClose() {
    if (confirm("請確定新增資料已儲存？"))
        parent.tb_remove()

}
function windowClose() {
    if (confirm("您確定要離開嗎？"))
        parent.tb_remove()

}
//語系網址直接切換
//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(!validate(obj.value))
	{
	  submsg.innerHTML=msg;
	  submsg.style.color="red";
	  submsg.align="center";
	  obj.value="";
	  obj.focus();
	  return (false);
	}else{
	  submsg.innerHTML="";	
	}
}
function validate(obj) { 
	var string = obj;
	var iChars = "*|\":<>[]{}`\';()&$#%";
	for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i)) != -1){
			return false;
		}
	}
return true;
} 
//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>');
}
//Function Name:resizeimg(ImgD,iwidth,iheight)
//功能說明：等比縮放圖片大小
//parma：ImgD = 標籤ID
//parma：iwidth = 圖片寬度
//parma：iheight = 圖片高度
//use : <img name="" src="" onload="javascript:resizeimg(this,100,200)">
function resizeimg(ImgD, iwidth, iheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            ImgD.alt = image.width + "×" + image.height;
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            ImgD.alt = image.width + "×" + image.height;
        }
        ImgD.style.cursor = "pointer"; //改變滑鼠指標 
        ImgD.onclick = function() { window.open(this.src); } //點擊打開大圖片 
        if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判斷流覽器，如果是IE 
            ImgD.title = "請使用滑鼠滾輪縮放圖片，點擊圖片可在新視窗打開";
            ImgD.onmousewheel = function img_zoom() //滾輪縮放 
            {
                var zoom = parseInt(this.style.zoom, 10) || 100;
                zoom += event.wheelDelta / 12;
                if (zoom > 0) this.style.zoom = zoom + "%";
                return false;
            }
        } else { //如果不是IE 
            ImgD.title = "點擊圖片可在新視窗打開";
        }
    }
}
//透過 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,targ){
    alert(msg);
	eval(targ+".location='"+url+"'");
}
function RedirectURLPAGE(url){
	location.href=url;
}
//
function reloadFrame(target){
	//top.frames[target].location.reload();
	//parent.frames[target].location.reload(); 
	//parent.window.location.reload();
	parent.window.frames["mainAREA"].location.reload();
	//document.parent.getElementById(target).src="../menu.php";   
	//document.frames(target).document.location="../menu.php";//
}
function reloadPage(target){
	top.frames[target].location.reload();
}
//Function Name：logoutURL
//功能介紹：閒置過久登出重新導向網址
//參數說明：msg:跳出的訊息,url:重新導向的網頁
//返回值：alert
function logoutURL(msg,url){
  alert(msg); 
  setTimeout("parent.location='"+url+"'")
}
//
function chkdel(url){
if(confirm("資料刪除後即無法回復，且其相關資料可能無法讀取，您確定要刪除？")){
	window.location.href = 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 Filepower_Confirm(url,mem_no,msg,selObj)
{
  if(confirm(msg))
		location.href=url+mem_no+"&file_power="+selObj.options[selObj.selectedIndex].value;
		//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_jumpMenu
//功能介紹：跳頁選單
//參數說明：targ:開啟網頁的方式,連結頁面:restore:
//返回值：alert
//Function Name：MM_jumpMenu
//功能介紹：跳頁選單
//參數說明：targ:開啟網頁的方式,連結頁面:restore:
//返回值：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,url,selObj,restore){ //v3.0
  eval(targ+".location='"+url+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){
var myT=document.getElementById(myTable);
w=eval(myT.width)+35; 
h=eval(myT.height)+60;
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();
  }
}

