﻿function fOpenDialog(url, param, pos)
{
	var tReturnValue = window.showModalDialog(url, param, pos);
	var tResult = new Object();

	if (typeof(tReturnValue)!="undefined")
	{
		tResult.Error = false;
		tResult.Value = tReturnValue.eValue;
	}
	else
	{
		tResult.Error = true;
	}
	
	return tResult;
}

function fAddZero(data, length, position)
{
	var lResult = data.toString();
	var i;
	
	for (i=lResult.length; i<length; i++)
	{
		switch (position)
		{
			case "F":
				lResult = "0" + lResult;
				break;
			case "B":
				lResult = lResult + "0";
				break;
		}
	}
	
	return lResult;
}

//依傳入的length, 取得所需要的長度數值資料
//data:取資的資料來源
//length:取得幾碼數值資料
//回傳:若依傳入長度的碼數取得, 若是, 取得的其中一個字串非數值,則回傳空值
function fGetNumberData(data, length)
{
	//var lOneStr = "";
	var lStr = "";
	var i;
	
	if (data.length < length)
	{
		return "";
	}
	
	
	lStr = data.substr(0, length)
	if (!isNaN(parseInt(lStr, 10)))
	{
		return lStr;
	}
	else
	{
		return "";
	}
	
	return lStr;
}
//=============================================================================
//=傳入參數： pDate     ->西元日期
//=           pDateType ->日曆格式  "C"->中國   "A"->西元
//=           pType        : W 在視窗(showModelDialog)中呼叫需傳入
//=                          其他情況不傳
//=傳回參數： 物件,包含以下屬性 
//=            eDate   ->西元日期 
//=            eYear   ->西元年 
//=            eMonth  ->月
//=            eDay    ->日
//=            eCDate  ->中國日期 
//=            eCYear  ->年
//=            eCMonth ->月 
//=            eCDay   ->日
//=============================================================================
function fOpenCalendar(pDate,pDateType)
{
    var tUrl;
    var tobjResult = new Object();

	tobjResult.eErr   = false;
	tobjResult.eDate  = ""; 
    tobjResult.eYear  = "";
    tobjResult.eMonth = "";
    tobjResult.eDay   = "";
    tobjResult.eCDate = "";
    tobjResult.eCYear = "";
    tobjResult.eCMonth= "";
    
	tUrl="CALENDAR.htm";
	tarParam = Array(pDate,pDateType);
	
    tPos     = "status:no;help=no;dialogWidth:240px; dialogHeight:225px; dialogTop:200px; dialogLeft:324px";
    tReturnValue = window.showModalDialog(tUrl,tarParam,tPos);
	if (typeof(tReturnValue)!="undefined")
	{
		tobjResult.eDate  = tReturnValue.eDate; 
		tobjResult.eYear  = tReturnValue.eYear;
		tobjResult.eMonth = tReturnValue.eMonth;
		tobjResult.eDay   = tReturnValue.eDay;
		tobjResult.eCDate = tReturnValue.eCDate;
		tobjResult.eCYear = tReturnValue.eCYear;
		tobjResult.eCMonth= tReturnValue.eCMonth;
		if(pDateType.toUpperCase().indexOf("A")>=0)
			tobjResult.UIDate =tobjResult.eDate;
		else
			tobjResult.UIDate =tobjResult.eCDate;	
	}
	else
	{
		tobjResult.eErr   = true;
	}
	return tobjResult;
}
function fOpenDate(pTextObj)
{
	var txt = window.document.getElementById(pTextObj);
	var tReturn = fOpenCalendar(txt.value,"A");
	var lTextObj = txt;
	lTextObj.value = tReturn.eDate;
	/*var tReturn = fOpenCalendar(eval("window.document.forms[0]." + pTextObj + ".value"),"A");
	var lTextObj = eval("window.document.forms[0]." + pTextObj);
	lTextObj.value = tReturn.eDate;*/
}
function fOpenRefWindow(dllName,objTypeName, methodName, parameters, displayFields)
{
	var lObj = new Object();
	lObj.Error=false;
	lObj.Action = "";
	lObj.Result = null;
	
	var i = 0;

	var tUrl     = "../Dialog/CommonRefForm.aspx?DllName=" + dllName + "&ObjTypeName=" + objTypeName + "&MethodName="+ methodName;
	
	if (parameters.length >= 0 )
	{
		var lParamsStr = "";
		for (i = 0 ; i < parameters.length; i++)
		{
			if (lParamsStr != "")
				lParamsStr += ";";
				
			lParamsStr += parameters[i];
		}

		tUrl += "&Parameters=" + escape(lParamsStr);
	}

	if (displayFields.length >= 0)
	{
		var lFieldsStr = "";
		for (i = 0 ; i < displayFields.length; i++)
		{
			if (lFieldsStr != "")
				lFieldsStr += ";";
				
			lFieldsStr += displayFields[i];
		}
		
		if (lFieldsStr != "")
			tUrl += "&DisplayFields=" + escape(lFieldsStr);
	}
		
    var tPos  = "status:no;help=no;dialogWidth:300px; dialogHeight:300px; dialogTop:200px; dialogLeft:324px";
    
    tReturnValue = window.showModalDialog(tUrl,null,tPos);
    /*
    if (typeof(tReturnValue)=="undefined")
    {	lObj.Error = true;}
    else
    {	
		lObj.Result = tReturnValue;
    }
    */
    if (typeof(tReturnValue)=="undefined")
    {	lObj.Error = true;}
    else
    {
		if (tReturnValue.Error)
		{
			lObj.Error = true;
		}
		else
		{
			lObj.Action = tReturnValue.Action;
			lObj.Result = tReturnValue.Value;
		}
	}
    return lObj;
}


function openDialog(url, title, size) {

		if(size=="S")
				size = "scrollbars=yes,width=500,height=300;"
		if(size=="M")
				size = "scrollbars=yes,width=500,height=500;"
		if(size=="L")
				size = "scrollbars=yes,width=700,height=600;";
		//url = encodeURI(url).replace(/%/g, "^")
		dialog = window.showModalDialog(url, title, size);
}
function QueryListInit(pTable)
{
	if(typeof(pTable)=="undefined")return;

	if(typeof(rtn)!="undefined")
			clearInterval(rtn);

	setRowColor(pTable);
	
}
function DetailTableInit(pTable)
{
	
	ListTableInit(pTable);
	//if(pTable.rows.length<=1)				
			//document.getElementsByName(pTable.description)[0].style.display='none';
	/*
	for(i=1;i<pTable.rows[0].cells.length;i++)
	{
		if(pTable.rows.length>1){
			var pHeader = pTable.rows[0].cells[i].firstChild;
			for(j=0;j<pTable.rows[1].cells[i].childNodes.length;j++){
				var pType = pTable.rows[1].cells[i].childNodes[j].type	;
				if(pType=='text')
					var pBody = pTable.rows[1].cells[i].childNodes[j];
			}
			
			pHeader.style.width = pBody.style.width;
		}

	}
	*/
}
function DialogTableInit(pTable){
		
		if(typeof(pTable)=="undefined")return;
		if(typeof(rtn)!="undefined")
			clearInterval(rtn);
		
		setAllNonDisplay(pTable);
		//var PAGESIZE = pTable.pageSize;	
		//還原目前筆數
		var PAGESIZE =document.getElementsByName(pTable.pageSizeObj)[0].value;
		PAGESIZE = reStroeTableSize(pTable,PAGESIZE);
		pTable.pageSize = PAGESIZE;
		document.getElementsByName(pTable.pageSizeObj)[0].value =reStroeTableSize(pTable,PAGESIZE); 
				
		culPageStatus(pTable)
		
		var pButton = document.getElementsByName(pTable.pageButton)[0];
		//還原目前所在頁數
		pTable.page=reStroeListPage(pTable);
		
		setPageDisplay(pTable,'');
		checkListPageStatus(pButton,pTable);
				
		setPageDesc(pTable);
		//setRowColor(pTable);
		//置中
			//setDescMiddle(pTable)
		
}
function ListTableInit(pTable){

		if(typeof(pTable)=="undefined")return;

		if(typeof(rtn)!="undefined")
			clearInterval(rtn);
						
		setAllNonDisplay(pTable);
		
		//var PAGESIZE = pTable.pageSize;	
		//還原目前筆數
		var PAGESIZE =document.getElementsByName(pTable.pageSizeObj)[0].value;
		PAGESIZE = reStroeTableSize(pTable,PAGESIZE);
		pTable.pageSize = PAGESIZE;
		document.getElementsByName(pTable.pageSizeObj)[0].value =reStroeTableSize(pTable,PAGESIZE); 
				
		culPageStatus(pTable)
		
		var pButton = document.getElementsByName(pTable.pageButton)[0];
		//還原目前所在頁數
		pTable.page=reStroeListPage(pTable);
		
		setPageDisplay(pTable,'');
		checkListPageStatus(pButton,pTable);
				
		setPageDesc(pTable);
		setRowColor(pTable);
		//置中
			setDescMiddle(pTable)
		
	}
	function storeTableSize(pTable)
	{
		if(typeof(opener)!="undefined")return ;
		if(parent.frames.length<=1)return ;
			parent.frames["hiddenFrame"].parentListTable[location.href+"-"+pTable.name] = pTable.pageSize;
		
				
	}
	function reStroeTableSize(pTable,size)
	{
		if(typeof(opener)!="undefined")return size;
		if(parent.frames.length<=1)return size;
		if(parent.frames["hiddenFrame"].parentListTable[location.href+"-"+pTable.name]!=null)
			return parent.frames["hiddenFrame"].parentListTable[location.href+"-"+pTable.name] ; 
		
		return	size;
	}
	
	function stroeListPage(pTable)
	{
		
		if(typeof(opener)!="undefined")return ;
		if(parent.frames.length<=1)return ;
		parent.frames["hiddenFrame"].parentListPage[location.href+"-"+pTable.name] = pTable.page;
		
		
	}

	function reStroeListPage(pTable)
	{
		
		if(typeof(opener)!="undefined")return 1;
		if(parent.frames.length<=1)return 1;
		if(pTable.page=="10000")return pTable.maxPage; 
		if(parent.frames["hiddenFrame"].parentListPage[location.href+"-"+pTable.name]!=null){
			
			
			var iPage = parent.frames["hiddenFrame"].parentListPage[location.href+"-"+pTable.name] ; 
			return (iPage<=pTable.maxPage)?iPage:pTable.maxPage; 
		}
		return	1;
		
	}
	
	function setRowColor(pTable)
	{
		
		for(i=pTable.pageSize*(pTable.page-1)+1;i<=pTable.pageSize*pTable.page;i++)
		{
			if(typeof(pTable.rows[i])!="undefined"){	
				for(j=1;j<pTable.rows[i].cells.length;j++)
				{
					var td = pTable.rows[i].cells[j];
					if(td.innerText=="")
						td.innerHTML = "&nbsp;";
				}	
				if(i%2==0)
					pTable.rows[i].className += "1";
			}
		}
	}


	function culPageStatus(pTable)
	{
		pTable.maxPage=Math.ceil((pTable.rows.length-1)/pTable.pageSize)
		var pageRows = pTable.rows.length-1
		//if((pageRows>pTable.pageSize)&&(pageRows%pTable.pageSize>0))pTable.maxPage++;
		
	}
	function setPageDesc(pTable)
	{
		var pDesc = document.getElementsByName(pTable.description)[0]	;
		culPageStatus(pTable);
		if(typeof(pDesc) != "undefined")
		{
			pDesc.innerText = "第"+pTable.page+"頁 / 共" + pTable.maxPage + "頁 / 共" +(pTable.rows.length-1)+ "筆";
			
		}
	}
	function setDescMiddle(pTable)
	{
		
		//var pDesc = document.getElementsByName(pTable.description)[0]	;
		//var descHTML = pDesc.parentElement.innerHTML ;
		//descHTML = descHTML.replace(descHTML.substring(0,descHTML.indexOf('每頁')),'<span class="ListDesc">')
		//descHTML = descHTML.replace('每頁','每頁</span>');
		//descHTML = descHTML.replace('筆','<span class="ListDesc" style="width:40%">筆');
		
		//pDesc.parentElement.innerHTML = descHTML;
		
	}
	function chkListTableSize(pTable)
	{
		var pObj = document.getElementsByName(pTable.pageSizeObj)[0];
		var pButton = document.getElementsByName(pTable.pageButton)[0];
		setPageDisplay(pTable,'none')
		if(pObj.value<=0)pObj.value=5;
		if(isNaN(pObj.value))pObj.value=5;
		if(pObj.value.indexOf(".")>0)pObj.value=5;
		
		pTable.pageSize=pObj.value;
		setPageDisplay(pTable,'');
		setPageDesc(pTable);
		checkListPageStatus(pButton,pTable);
		storeTableSize(pTable);
	}

	function MovePage(pButton,pTable,actionWork)
	{
		if(typeof(pTable.page)=="undefined")pTable.page=1;
		setPageDisplay(pTable,'none')
		switch(actionWork)
		{
			case 'first':pTable.page=1;break;
			case 'previous':pTable.page--;break;
			case 'next':pTable.page++;break;
			case 'last':pTable.page=pTable.maxPage;break;
		}
		setPageDisplay(pTable,'');
		checkListPageStatus(pButton,pTable);
		setPageDesc(pTable);
		stroeListPage(pTable);
		setRowColor(pTable)
	}
	
	function setAllNonDisplay(pTable)
	{
		
		for(i=1;i<pTable.rows.length;i++)
		{
			
			if(typeof(pTable.rows[i])!="undefined")
			{
				pTable.rows[i].runtimeStyle.display='none';
				pTable.rows[i].style.display='none';
			}
		}	
	}

	function setPageDisplay(pTable,pDisplay)
	{
			
		var PAGESIZE = pTable.pageSize

		for(i=PAGESIZE*(pTable.page-1)+1;i<=PAGESIZE*pTable.page;i++)
		{
			if(typeof(pTable.rows[i])!="undefined")
			{
				pTable.rows[i].runtimeStyle.display=pDisplay;
				pTable.rows[i].style.display=pDisplay;
			}
		}	
	}

	
	function setNowPageDisabled(pTable)
	{
		for(i=PAGESIZE*(pTable.page-1)+1;i<=PAGESIZE*pTable.page;i++)
		{
			if(typeof(pTable.rows[i])!="undefined")
				pTable.rows[i].runtimeStyle.display='none';
		}
	}
	
	function checkListPageStatus(pButton,pTable)
	{
			document.getElementsByName(pButton.name)[0].style.display='';
			document.getElementsByName(pButton.name)[1].style.display='';
			document.getElementsByName(pButton.name)[2].style.display='';
			document.getElementsByName(pButton.name)[3].style.display='';
			document.getElementsByName(pButton.name)[0].runtimeStyle.display='';
			document.getElementsByName(pButton.name)[1].runtimeStyle.display='';
			document.getElementsByName(pButton.name)[2].runtimeStyle.display='';
			document.getElementsByName(pButton.name)[3].runtimeStyle.display='';
			if(pTable.rows.length<=1)
			{
				document.getElementsByName(pButton.name)[0].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[1].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[2].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[3].runtimeStyle.display='none';
				document.getElementsByName(pTable.description)[0].style.display='none'; 
				return;
			}
			
			if(pTable.page==pTable.maxPage)
			{
					
					document.getElementsByName(pButton.name)[2].runtimeStyle.display='none';
					document.getElementsByName(pButton.name)[3].runtimeStyle.display='none';
					
			}
			if(pTable.page==1)
			{
				document.getElementsByName(pButton.name)[0].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[1].runtimeStyle.display='none';
					
			}
			if(pTable.page==0)
			{
				document.getElementsByName(pButton.name)[0].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[1].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[2].runtimeStyle.display='none';
				document.getElementsByName(pButton.name)[3].runtimeStyle.display='none';	
			}
	}

	function Trim(pStr)
	{
		for(i=0;i<pStr.length;i++)
		{
			pStr = pStr.replace(" ","");
		}
		return pStr;
	}
	

	function reSizeListTable()
	{
		
		if(parent.frames.length> 1){
			parent.frames["hiddenFrame"].parentListTable = new Array();
			parent.frames["hiddenFrame"].parentListPage = new Array();
		}
		
	}


	//=============================================================================
//=   功能說明: 編審年
//=   傳入參數: pY    : YYY(YY) or YYYY
//=             pType : C  傳入中國年
//=                   : A  傳入西元年
//=   傳回參數: 物件  : eErr                   表編審成功/失敗
//=                     eY                     正確格式年 <YYY or YYYY>
//=                     eErrDesc               編審失敗錯誤訊息
//=============================================================================
function gfcChkY(pY,pType)
{
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    tobjResult.eY = "";
    tobjResult.eErrDesc = "";

    if (typeof(pType) == "undefined") {   pType = "C";}

    if (pY == null)
    {
        tobjResult.eY = null;
        return tobjResult;
    }
    if (pY == "") 
    {
        tobjResult.eY = "";
        return tobjResult;
    }
    if (isNaN(pY) || parseInt(pY,10) <= 0)
    {
        tobjResult.eErr = true;
        tobjResult.eY = "";
        if ((pType == "C") || (pType == "c"))
        {   tobjResult.eErrDesc = "格式輸入錯誤(中國年) !";}
        else
        {   tobjResult.eErrDesc = "格式輸入錯誤(西元年) !";}
        return tobjResult;
    }

    if ((pType == "C") || (pType == "c"))
    {   tobjResult.eY = gfcString(pY,3,"0").eLStr;}
    else
    {   tobjResult.eY = gfcString(pY,4,"0").eLStr;}
    return tobjResult;
}

//=============================================================================
//=   功能說明: 編審年月
//=   傳入參數: pYM   : YYYMM(YYMM) or YYY/MM(YY/MM or YY/M)
//=                     YYYYMM or YYYY/MM(YYYY/M)
//=             pType : C  傳入中國年
//=                   : A  傳入西元年
//=   傳回參數: 物件  : eErr         表編審成功/失敗
//=                     eYM          正確格式年月 <YYY/MM or YYYY/MM>
//=                     eErrDesc     編審失敗錯誤訊息
//=============================================================================
function gfcChkYM(pYM,pType)
{
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    tobjResult.eYM = "";
    tobjResult.eErrDesc = "";

    if (typeof(pType) == "undefined") {   pType = "C";}

    if (pYM == null)
    {
        tobjResult.eYM = null;
        return tobjResult;
    }
    if (pYM == "") 
    {
        tobjResult.eYM = "";
        return tobjResult;
    }

    tPos = pYM.indexOf("/");
    if (tPos == -1)    //沒輸入鈄線
    {   pYM = pYM + "01";   }
    else
    {   pYM = pYM + "/01";   }

    if ((pType == "C") || (pType == "c"))
    {
        var tobjResult1 = gfcChkYMD(pYM,"C");
        if (tobjResult1.eErr)
        {
            tobjResult.eErr = true;
            tobjResult.eErrDesc = tobjResult1.eErrDesc;
        }
        else
        {   tobjResult.eYM = tobjResult1.eYMD.substring(0,6);}
    }
    else
    {
        var tobjResult1 = gfcChkYMD(pYM,"A");
        if (tobjResult1.eErr)
        {
            tobjResult.eErr = true;
            tobjResult.eErrDesc = tobjResult1.eErrDesc;
        }
        else
        {   tobjResult.eYM = tobjResult1.eYMD.substring(0,7);}
    }
    return tobjResult;
}

//=============================================================================
//=   功能說明: 編審日期
//=   傳入參數: pYMD  : YYYMMDD(YYMMDD) or YYY/MM/DD(YY/MM/DD or YY/M/D)
//=                     YYYYMMDD or YYYY/MM/DD(YYYY/M/D)
//=             pType : C  傳入中國年
//=                   : A  傳入西元年
//=   傳回參數: 物件  : eErr       表編審成功/失敗
//=                     eYMD       正確格式日期 <YYY/MM/DD or YYYY/MM/DD>
//=                     eErrDesc   編審失敗錯誤訊息
//=============================================================================
function gfcChkYMD(pYMD,pType)
{
	var tPos,tY,tMM,tDD,tY1,tnY,tnM;
    var tobjResult = new Object();
    var tDate;

    //給初值
    tobjResult.eErr = false;
    tobjResult.eYMD = "";
    tobjResult.eErrDesc = "";

    if (typeof(pType) == "undefined") {   pType = "C";}

    if (pYMD == null)
    {
        tobjResult.eYMD = "";
        return tobjResult.eYMD.toString();
    }
    if (pYMD == "") 
    {
        tobjResult.eYMD = "";
        return tobjResult.eYMD.toString();
    }

    tPos = pYMD.indexOf("/");
    if (tPos == -1)     //沒輸入鈄線
    {
        if ((pType == "C") || (pType == "c"))
        {

            //輸入 890101 or 0890101
            if (pYMD.length != 6 && pYMD.length != 7)
            {
							
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "日期格式輸入錯誤(中國年) !";
				return tobjResult.eYMD.toString();
            }
            if (pYMD.length == 6)     //輸入 890101 則補 0
            {   pYMD = "0" + pYMD;   }
            tY = pYMD.substring(0,3);
            tMM = pYMD.substring(3,5);
            tDD = pYMD.substring(5,7);
        }
        else
        {
            //輸入 20000101
            if (pYMD.length != 8) 
            {
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "日期格式輸入錯誤(西元年) !";
                return tobjResult.eYMD.toString();
            }        
            tY = pYMD.substring(0,4);
            tMM = pYMD.substring(4,6);
            tDD = pYMD.substring(6,8);
        }
    }
    else  //輸入鈄線
    {
        if ((pType == "C") || (pType == "c"))
        {
            //輸入 89/01/01 or 089/01/01 or 89/1/1 or 089/1/1
            if (tPos > 3)   //中國年份超過三碼
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "日期格式輸入錯誤(中國年) !";
                return tobjResult.eYMD.toString();
            }
        }
        else
        {
            //輸入 2000/01/01 or 2000/01/1 or 2000/1/01 or 2000/1/1
            if (tPos > 4)  // 西元年份超過四碼
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "日期格式輸入錯誤(西元年) !";
                return tobjResult.eYMD.toString();
            }
        }
        tY = pYMD.substring(0,tPos)     //取年
        pYMD = pYMD.substring(tPos + 1);
        tPos = pYMD.indexOf("/");
        tMM = pYMD.substring(0, tPos);  //取月
        tDD = pYMD.substring(tPos + 1); //取日
        if (tMM.length == 1) {   tMM = "0" + tMM;}
        if (tDD.length == 1) {   tDD = "0" + tDD;}
    }

    if ((isNaN(tY)) || (isNaN(tMM)) || (isNaN(tDD)) || (tMM.length > 2) || (tDD.length > 2))
    {
        tobjResult.eErr = true;
        tobjResult.eYMD     = "";
        if ((pType == "C") || (pType == "c"))
        {   tobjResult.eErrDesc = "日期格式輸入錯誤(中國年) !";}
        else
        {   tobjResult.eErrDesc = "日期格式輸入錯誤(西元年) !";}
        return tobjResult.eYMD.toString();
    }

    if ((pType == "C") || (pType == "c"))
    {   tY1 = parseInt(tY,10) + 1911;}
    else
    {   tY1 = parseInt(tY,10);}

    tDate = new Date(tY1,tMM-1,tDD); // new Date 會將月份自動 + 1
    tnY = tDate.getFullYear();
    tnM = tDate.getMonth() + 1; //getMonth 取得的是真實月份 - 1
    if ((tY1 != tnY) || (tMM != tnM))
    {   
        tobjResult.eErr = true;
        tobjResult.eYMD     = "";
        if ((pType == "C") || (pType == "c"))
        {   tobjResult.eErrDesc = "日期格式輸入錯誤(中國年) !";}
        else
        {   tobjResult.eErrDesc = "日期格式輸入錯誤(西元年) !";}
        return tobjResult.eYMD.toString();
    }

    // 中國年輸入長度不足補 0
    if ((pType == "C") || (pType == "c"))
    {   tY = gfcString(tY,3,"0").eLStr;}
    else
    {   tY = gfcString(tY,4,"0").eLStr;}

    tobjResult.eYMD = tY + "/" + tMM + "/" + tDD;
    //return tobjResult;
    return tobjResult.eYMD.toString();
}

//=============================================================================
//=   功能說明: 編審時間
//=   傳入參數: pHN   : HHNN(HH:NN) [AM/PM/上午/下午]
//=   傳回參數: 物件  : eErr                   表編審成功/失敗
//=                     eHN12                  正確格式時間(HH:NN AM/PM)
//=                     eHN24                  正確格式時間(HH:NN)
//=                     eErrDesc               編審失敗錯誤訊息
//=============================================================================
function gfcChkHN(pHN)
{
    var tPos,tHH12,tHH24,tNN12,tNN24,tHN24,tHN12,tAPM0,tAPM;
    var tobjResult = new Object();
    var tTime;
    var tsw12;

    //給初值
    tobjResult.eErr = false;
    tsw12 = false;
    tobjResult.eHN = "";
    tobjResult.eErrDesc = "";

    if (pHN == null)
    {
        tobjResult.eHN12 = null;
        tobjResult.eHN24 = null;
        return tobjResult;
    }
    if (pHN == "") 
    {
        tobjResult.eHN12 = "";
        tobjResult.eHN24 = "";
        return tobjResult;
    }
    pHN = pHN.replace(" ","");

    //先判斷12小時制, 若是, 則取得 AM/PM
    pHN = pHN.toUpperCase();
    tPos = pHN.search(/AM|PM|上午|下午/);
    if (tPos >= 0)
    {
        //傳入12小時制
        tsw12 = true;
        tAPM0 = pHN.substr(tPos,2);
        tAPM = " " + pHN.substr(tPos,2);
        switch (tAPM0)
        {
            case "上午":
                tAPM0 = "AM";
                tAPM = " AM";
                break;
            case "下午":
                tAPM0 = "PM";
                tAPM = " PM";
                break;
        }
        pHN = pHN.replace(/AM|PM|上午|下午/,"");
    }
    else
    {   tsw12 = false;}

    //再計算時間
    tPos = pHN.indexOf(":");
    if (tPos == -1)
    {
        // 輸入值為 0125
        tHH12 = parseInt(pHN.substring(0,2),10);
        tNN12 = parseInt(pHN.substring(2),10);
        tHH24 = parseInt(pHN.substring(0,2),10);
        tNN24 = parseInt(pHN.substring(2),10);
    }
    else
    {
        // 輸入值為 01:25
        tHH12 = parseInt(pHN.substring(0,tPos),10);
        tNN12 = parseInt(pHN.substring(tPos+1),10);
        tHH24 = parseInt(pHN.substring(0,tPos),10);
        tNN24 = parseInt(pHN.substring(tPos+1),10);
        pHN = pHN.replace(":","");
    }

    //輸入值為 125 or 125 PM
    if ((tPos == -1) && (pHN.length < 4))
    {
        tobjResult.eErr = true;
        tobjResult.eHN12 = "";
        tobjResult.eHN24 = "";
        if (tsw12)
        {   tobjResult.eErrDesc = "時間格式輸入錯誤(12小時制) !";}
        else
        {   tobjResult.eErrDesc = "時間格式輸入錯誤(24小時制) !";}
        return tobjResult;
    }

    if (isNaN(pHN))
    {
        tobjResult.eErr = true;
        tobjResult.eHN12 = "";
        tobjResult.eHN24 = "";
        if (tsw12)
        {   tobjResult.eErrDesc = "時間格式輸入錯誤(12小時制) !";}
        else
        {   tobjResult.eErrDesc = "時間格式輸入錯誤(24小時制) !";}
        return tobjResult;
    }

    if (tsw12)
    {
        //傳入12小時制
        tHN12 = gfcString(tHH12,2,"0").eLStr + 
                gfcString(tNN12,2,"0").eLStr + " " + tAPM0;
        if ((tHH12 >= 13 || tHH12 < 0 || tNN12 >= 60 || tNN12 < 0)) 
        {   
            tobjResult.eErr = true;
            tobjResult.eHN12 = "";
            tobjResult.eHN24 = "";
            tobjResult.eErrDesc = "時間格式輸入錯誤(12小時制) !";
            return tobjResult;
        }

        //將它轉換成24小時制
        if ((tAPM0 == "PM") && (tHH24 != 12))  
        {   
            tHH12 = tHH12 + 12;
            tHH24 = tHH24 + 12;
        }
     }
    else
    {
        //傳入24小時制
        tHN24 = gfcString(tHH24,2,"0").eLStr + 
                gfcString(tNN24,2,"0").eLStr;
        if (tHH24 >= 24 || tHH24 < 0 || tNN24 >= 60 || tNN24 < 0)
        {   
            tobjResult.eErr = true;
            tobjResult.eHN12 = "";
            tobjResult.eHN24 = "";
            tobjResult.eErrDesc = "時間格式輸入錯誤(24小時制) !";
            return tobjResult;
        }
    }

    if (tsw12)
    {
        //傳入12小時制

        //回傳12小時制
        if (tHN12 == "0000 AM")
        {
            tHH12 = 12;
            tDD12 = 0;
            tAPM = " AM";
        }
        else
        {
            if (tHN12.substring(0,2) != "12")
            {
                if ((tHN12 > "0100 PM") && (tAPM0 == "PM")) {   tHH12 = tHH12 - 12;}
            }
        }

        //回傳24小時制
        switch(tHN12)
        {
            case "0000 AM":
                tHH24 = 0;
                tDD24 = 0;
                break;
            case "1200 AM":
                tHH24 = 0;
                tDD24 = 0;
                break;
            case "1200 PM":
                tHH24 = 12;
                tDD24 = 0;
                break;
            default:
                if ((tHN12.substring(0,2) == "12") && (tAPM0 == "AM"))
                {   tHH24 = 0;}
                break;
        }
    }
    else
    {
        //傳入24小時制

        //回傳12小時制
        switch(tHN24)
        {
            case "0000":
                tHH12 = 12;
                tDD12 = 0;
                tAPM = " AM";
                break;
            case "1200":
                tHH12 = 12;
                tDD12 = 0;
                tAPM = " PM";
                break;
            default:
                if (tHN24 > "1200")
                {
                    if (tHN24 > "1300") {   tHH12 = tHH12 - 12;}
                    tAPM = " PM";
                }
                else
                {
                    if (tHN24.substring(0,2) == "00") {   tHH12 = tHH12 + 12;}
                    tAPM = " AM";
                }
        }
    }

    tHH12 = tHH12.toString()
    tNN12 = tNN12.toString()
    tHH24 = tHH24.toString()
    tNN24 = tNN24.toString()
    if (tHH12.length == 1) {   tHH12 = "0" + tHH12;}
    if (tNN12.length == 1) {   tNN12 = "0" + tNN12;}
    if (tHH24.length == 1) {   tHH24 = "0" + tHH24;}
    if (tNN24.length == 1) {   tNN24 = "0" + tNN24;}

    tobjResult.eHN12 = tHH12 + ":" + tNN12 + tAPM;
    tobjResult.eHN24 = tHH24 + ":" + tNN24;
    
    return tobjResult;
}

//=============================================================================
//=   功能說明: 編審日期時間
//=   傳入參數: pDateTime
//=                   : YYYMMDD HHNN(YYMMDD HHNN) [AM/PM]
//=                       or YYY/MM/DD HH:NN(YY/MM/DD HH:NN or YY/M/D HH:NN)  
//=                          [AM/PM]
//=                     YYYYMMDD HHNN [AM/PM]
//=                       or YYYY/MM/DD HH:NN(YYYY/M/D HH:NN) [AM/PM]
//=             pType : C  傳入中國年
//=                   : A  傳入西元年
//=   傳回參數: 物件  : eErr                   表編審成功/失敗
//=                     eDateTime12            正確格式日期時間
//=                      <YYY/MM/DD HH:NN AM/PM or YYYY/MM/DD HH:NN AM/PM>
//=                     eDateTime24            正確格式日期時間
//=                      <YYY/MM/DD HH:NN or YYYY/MM/DD HH:NN>
//=                     eErrDesc               編審失敗錯誤訊息
//=============================================================================
function gfcChkDateTime(pDateTime,pType)
{
    var tPos,tDate,tTime;
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    tobjResult.eDateTime12 = "";
    tobjResult.eDateTime24 = "";
    tobjResult.eErrDesc = "";

    if (typeof(pType) == "undefined") {   pType = "C";}

    if (pDateTime == null)
    {
        tobjResult.eDateTime12 = null;
        tobjResult.eDateTime24 = null;
        return tobjResult;
    }
    if (pDateTime == "") 
    {
        tobjResult.eDateTime12 = "";
        tobjResult.eDateTime24 = "";
        return tobjResult;
    }

    tPos = pDateTime.indexOf(" ");
    tDate = pDateTime.substring(0,tPos);
    tTime = pDateTime.substr(tPos + 1);

    //先編審日期
    var tobjResultD = gfcChkYMD(tDate,pType);
    if (tobjResultD.eErr)
    {
        tobjResult.eErr = true;
        tobjResult.eErrDesc = tobjResultD.eErrDesc;
    }
    else
    {   
        tobjResult.eDateTime12 = tobjResultD.eYMD;
        tobjResult.eDateTime24 = tobjResultD.eYMD;

        //再編審時間
        var tobjResultT = gfcChkHN(tTime);
        if (tobjResultT.eErr)
        {
            tobjResult.eErr = true;
            tobjResult.eErrDesc = tobjResultT.eErrDesc;
        }
        else
        {
            tobjResult.eDateTime12 = tobjResult.eDateTime12 + " " + tobjResultT.eHN12;
            tobjResult.eDateTime24 = tobjResult.eDateTime24 + " " + tobjResultT.eHN24;
        }
    }

    return tobjResult;
}

//=============================================================================
//=   功能說明: 編審數值
//=   傳入參數: pNumber  : 數值
//              pCompare : 比較運算子 (>,>=,<,<=,==,!=,不比較則傳 "")
//              pComNum  : 比較運算元 (要比較的數值)
//              pIntLen  : 最大整數位數 (0 表不可有小數)
//=   傳回參數: 物件     : eErr          表編審成功/失敗
//=                        eErrDesc      編審失敗錯誤訊息
//=============================================================================
function gfcChkNum(pNumber,pCompare,pComNum,pIntLen)
{   
    var tobjRtn = new Object();  //-傳回Object
    tobjRtn.eErr = false;
    tobjRtn.eErrDesc = "";

    if ((gfcTrim(pNumber) == "") || (pNumber == null))
    {   return tobjRtn;}

    if (isNaN(pNumber))
    {
        tobjRtn.eErr = true;
        tobjRtn.eErrDesc = "必須輸入數值 !";
        return tobjRtn;
    }
    if (pCompare == ">" || pCompare == "<" || pCompare == ">=" || pCompare == "<="
    ||  pCompare == "==" || pCompare == "!=")
    {
        if (! eval(parseFloat(pNumber,10).toString() + pCompare + pComNum)) 
        {
            tobjRtn.eErr = true;
            tobjRtn.eErrDesc = "必須 " + pCompare + " " + pComNum + " !";
            return tobjRtn;
        }
    }
    if (pIntLen == 0)
    {

        if (pNumber - parseInt(pNumber,10) != 0)
        {
            tobjRtn.eErr = true;
            tobjRtn.eErrDesc = "必須輸入整數 !";
            return tobjRtn;
        }
		else
		{

			tobjRtn.value = parseInt(pNumber,10);
		}
    }
    else
    {
        if (pNumber >= (Math.pow(10,pIntLen)))
        {
            tobjRtn.eErr = true;
            tobjRtn.eErrDesc = "整數位數不可超過" + pIntLen + "位 !";
            return tobjRtn;
        }
		else
		{
			tobjRtn.value = pNumber;
		}
    }
    return tobjRtn;
}

//=============================================================================
//=   功能說明: 編審身份證字號是否正確
//=   傳入參數: pUserID : 要編審的號碼(身份證字號:10位文數字)
//=   傳回參數: 物件    : eErr           表編審成功/失敗
//=                       eErrDesc       編審失敗錯誤訊息
//=============================================================================
function gfcChkIdCard(pUserID)
{
    var tobjRtn = new Object();  //-傳回Object
    var ixI;
    var tAreaNo;
    var tSum;
    var tAreaCode;
    var tSecondID;         //身份證第二碼

    if (pUserID == "" || pUserID == null)
    {
        tobjRtn.eErr = false;
        return tobjRtn;
    }
    tobjRtn.eErr = true;
    pUserID = pUserID.toUpperCase(); 
    if (pUserID.length != 10)//確定身份證字號有10碼
    {   
        tobjRtn.eErrDesc = "輸入無效的身份證字號 (ex:資料長度錯誤) !";
        return tobjRtn;             
    }       
    tAreaCode = pUserID.substr(0,1);
    if (tAreaCode.valueOf() < "A" || tAreaCode.valueOf() > "Z")//確定首碼在A-Z之間
    {   
        tobjRtn.eErrDesc = "輸入無效的身份證字號 (ex:首碼應介於A-Z之間) !";
        return tobjRtn;
    }  
    if (isNaN(parseInt(pUserID.substring(1,10),10)) == true) //確定2-10碼是數字
    {   
        tobjRtn.eErrDesc = "輸入無效的身份證字號 (ex:第2-10碼須是數字) !";
        return tobjRtn;
    }   
    //身份證號碼第 2 碼必須為 1 或 2
    tSecondID = pUserID.substr(1,1);
    if (tSecondID != "1" && tSecondID != "2")
    {   
        tobjRtn.eErrDesc = "輸入無效的身份證字號 !";
        return tobjRtn;
    }
    //取得首碼對應的區域碼，A ->10, B->11, ..H->17,I->34, J->18...
    tAreaNo = "ABCDEFGHJKLMNPQRSTUVXYWZIO".search(tAreaCode) + 10;
    pUserID = tAreaNo.toString(10) + pUserID.substring(1,10);   
   
    //  取得CheckSum的值
    //  核對身份證號碼是否正確
    //  A  = 身份證號碼區域碼第 1碼
    //  A0 = 身份證號碼區域碼第 2碼 * (10 - 1)
    //  A1 = 身份證號碼第 2碼 * (10 - 2)
    //  A2 = 身份證號碼第 3碼 * (10 - 3)
    //  A3 = 身份證號碼第 4碼 * (10 - 4)
    //  A4 = 身份證號碼第 5碼 * (10 - 5)
    //  A5 = 身份證號碼第 6碼 * (10 - 6)
    //  A6 = 身份證號碼第 7碼 * (10 - 7)
    //  A7 = 身份證號碼第 8碼 * (10 - 8)
    //  A8 = 身份證號碼第 9碼 * (10 - 9)
    //  CheckSum = A + A0 + A1 + A2 + ........ + A7 + A8

    tSum = parseInt(pUserID.substr(0,1),10) + parseInt(pUserID.substr(10,1),10);   

    for(ixI=1;ixI<=9;ixI++)
    {   
		
        tSum = tSum + parseInt(pUserID.substr(ixI,1),10)*(10-ixI);

    }  
	
    if ((tSum % 10) != 0)
    {
        tobjRtn.eErrDesc = "輸入無效的身份證字號 !";
        return tobjRtn;
    }
    tobjRtn.eErr = false;
    return tobjRtn;
}

//=============================================================================
//=   功能說明 : 編審統一編號是否正確
//=   傳入參數 : pUserID : 要編審的號碼(統一編號:8位數字)
//=   傳回參數 : 物件    : eErr      表編審成功/失敗
//=                        eErrDesc  編審失敗錯誤訊息
//=============================================================================
function gfcChkUnity(pUserID)
{   
    var tobjRtn = new Object();  //-傳回Object
    var ixI;
    var tSum = 0;
    var tDiv = 0;
    var tMod = 0;
    var tStr = "12121241";        
   
    tobjRtn.eErr = false;
    if (pUserID == "")
    {   return tobjRtn;    }
    //tobjRtn.eErr = true;
    if (pUserID.length != 8) //確定統一編號有8碼
    {   
        tobjRtn.eErr = true;
        tobjRtn.eErrDesc = "輸入無效的統一編號 (ex:資料長度錯誤) !";
        return tobjRtn;
    } 
    if (isNaN(parseInt(pUserID,10)) == true) //確定1-8碼是數字
    {   
        tobjRtn.eErr = true;
        tobjRtn.eErrDesc = "輸入無效的統一編號 (ex:須為8位數字) !";
        return tobjRtn;
    } 
    for(ixI=0; ixI<=7; ixI++)//套公式編審
    {     
        tDiv = parseInt(parseInt(pUserID.substr(ixI,1),10) * parseInt(tStr.substr(ixI,1))/10);
        tMod = parseInt(parseInt(pUserID.substr(ixI,1),10) * parseInt(tStr.substr(ixI,1))%10);
        tSum = tSum + tDiv + tMod;      
    }         
    tSum=parseInt(tSum%10);

    if ((tSum == 0 || tSum == 9) && pUserID.substr(6,1) == "7")//正確
    {    
		tobjRtn.eErr = false;
		return tobjRtn;    
	}
    if (tSum == 0)//正確
    {    
		tobjRtn.eErr = false;
		return tobjRtn;
	} 
    else
    {    
        tobjRtn.eErr = true;
        tobjRtn.eErrDesc = "輸入無效的統一編號 !"; //不正確
        return tobjRtn;
    }
    tobjRtn.eErr = false;
    return tobjRtn;
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//*************************************************************************************
//*   類    別: 格式轉換函式庫(cTrnValue)
//*   說    明: 內含各類格式轉換所需用到的函式
//*   作    者: 葛豐嘉, 葉怡君
//*   內含 Sub: gfcCDate                  - 西元年 -> 中國年
//*             gfcDate                   - 中國年 -> 西元年
//*             gfcGetSysDate             - 取得系統日期
//*             gfcTrnNum                 - 數值 -> 四捨五入, 無條件捨去, 無條件進位
//*             gfcTrnNumFormat           - 數值 -> 三位一撇
//*************************************************************************************

//===============================================================================
//=   功能說明: 西元年 -> 中國年
//=   傳入參數: pDate : YYYY/MM/DD [HH:NN:SS]       或
//=                     YYYY/MM/DD [HH:NN:SS AM/PM] 或
//=                     日期(西元年)
//=   傳回參數: 物件  : eErr                    表傳入無效的日期型態
//=                     eNY,eNM,eND             年,月,日
//=                     eNH,eNN,eNS             時,分,秒
//=                     eY,eYM,eYMD             年,年月,年月日
//=                     eHNS12,eHN12            時分秒,時分(12小時制)
//=                     eHNS24,eHN24            時分秒,時分(24小時制)
//=                     eYMDHN12,eYMDHN24       年月日時分(12小時制,24小時制)
//=                     eDateTime12,eDateTime24 年月日時分秒(12小時制,24小時制)
//===============================================================================
function gfcCDate(pDate)
{
    var tPos,tDate;
    var tYYY,tMM,tDD,tHH,tNN,tSS;
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    gfcObjInit(tobjResult,"space");

    if (pDate == null)
    {
        gfcObjInit(tobjResult,"null");
        return tobjResult;
    }

    if (typeof(pDate) == "string")
    {
        if (pDate == "")
        {   return tobjResult;}
        else
        {
            //只傳入年或年月的況狀
            tDate = pDate
            tPos = tDate.indexOf("/");
            if (tPos == -1)
            {
                pDate = pDate + "/01/01 00:00:01 AM";
            }
            else
            {
                tDate = tDate.substring(tPos+1);
                tPos = tDate.indexOf("/");
                if (tPos == -1)
                {
                    pDate = pDate + "/01 00:00:01 AM";
                }
            }
        }
    }

    pDate = new Date(pDate);
    if (isNaN(pDate))
    {
        tobjResult.eErr = true;
        return tobjResult;
    }

    tobjResult.eNY = "" + (pDate.getFullYear() - 1911);
    tobjResult.eNM = "" + (pDate.getMonth() + 1);
    tobjResult.eND = "" + pDate.getDate();
    tobjResult.eNH = "" + pDate.getHours();
    tobjResult.eNN = "" + pDate.getMinutes();
    tobjResult.eNS = "" + pDate.getSeconds();

    tYYY = gfcString(tobjResult.eNY,3,"0").eLStr;
    tMM = gfcString(tobjResult.eNM,2,"0").eLStr;
    tDD = gfcString(tobjResult.eND,2,"0").eLStr;
    tHH = gfcString(tobjResult.eNH,2,"0").eLStr;
    tNN = gfcString(tobjResult.eNN,2,"0").eLStr;
    tSS = gfcString(tobjResult.eNS,2,"0").eLStr;
    tobjResult.eY = tYYY;
    tobjResult.eYM = tYYY + "/" + tMM;
    tobjResult.eYMD = tYYY + "/" + tMM + "/" + tDD;

    //24小時制
    tobjResult.eHNS24 = tHH + ":" + tNN + ":" + tSS;
    tobjResult.eHN24 = tHH + ":" + tNN;
    tobjResult.eYMDHN24 = tYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN;
    tobjResult.eDateTime24 = tYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + ":" + tSS;

    //12小時制
    if (tHH + tNN > "1159")
    {
        if (tHH + tNN > "1300")
        {   tHH = "" + (tHH - 12);}
        tHH = gfcString(tHH,2,"0").eLStr;
        tAPM = " PM";
    }
    else
    {   tAPM = " AM";}
    tobjResult.eHNS12 = tHH + ":" + tNN + ":" + tSS + tAPM;
    tobjResult.eHN12 = tHH + ":" + tNN + tAPM;
    tobjResult.eYMDHN12 = tYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + tAPM;
    tobjResult.eDateTime12 = tYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + ":" + tSS + tAPM;
    return tobjResult;
}

//===============================================================================
//=   功能說明: 中國年 -> 西元年
//=   傳入參數: pCDate: YYY/MM/DD [HH:NN:SS]   或
//=                     YYY/MM/DD [HH:NN:SS AM/PM]
//=   傳回參數: 物件  : eErr                    表傳入無效的日期型態
//=                     eNY,eNM,eND             年,月,日
//=                     eNH,eNN,eNS             時,分,秒
//=                     eY,eYM,eYMD             年,年月,年月日
//=                     eHNS12,eHN12            時分秒,時分(12小時制)
//=                     eHNS24,eHN24            時分秒,時分(24小時制)
//=                     eYMDHN12,eYMDHN24       年月日時分(12小時制,24小時制)
//=                     eDateTime12,eDateTime24 年月日時分秒(12小時制,24小時制)
//===============================================================================
function gfcDate(pCDate)
{
    var tPos,tCDate,tYYYY,tMM,tDD,tHH,tNN,tSS;
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    gfcObjInit(tobjResult,"space");

    if (pCDate == null)
    {
        gfcObjInit(tobjResult,"null");
        return tobjResult;
    }

    if (typeof(pCDate) == "string")
    {
        if (pCDate == "")
        {   return tobjResult;}
        else
        {
            //只傳入年或年月的況狀
            tCDate = pCDate
            tPos = tCDate.indexOf("/");
            if (tPos == -1)
            {
                pCDate = pCDate + "/01/01 00:00:01 AM";
            }
            else
            {
                tCDate = tCDate.substring(tPos+1);
                tPos = tCDate.indexOf("/");
                if (tPos == -1)
                {
                    pCDate = pCDate + "/01 00:00:01 AM";
                }
            }

            tPos = pCDate.indexOf("/");
            if (tPos != -1)
            {   
                tYYYY = parseInt(pCDate.substring(0,tPos),10) + 1911;
                pCDate = "" + tYYYY + pCDate.substring(tPos);
            }
        }
    }

    pCDate = new Date(pCDate);
    if (isNaN(pCDate))
    {
        tobjResult.eErr = true;
        return tobjResult;
    }

    tobjResult.eNY = "" + pCDate.getFullYear();
    tobjResult.eNM = "" + (pCDate.getMonth() + 1);
    tobjResult.eND = "" + pCDate.getDate();
    tobjResult.eNH = "" + pCDate.getHours();
    tobjResult.eNN = "" + pCDate.getMinutes();
    tobjResult.eNS = "" + pCDate.getSeconds();

    tYYYY = tobjResult.eNY;
    tMM = gfcString(tobjResult.eNM,2,"0").eLStr;
    tDD = gfcString(tobjResult.eND,2,"0").eLStr;
    tHH = gfcString(tobjResult.eNH,2,"0").eLStr;
    tNN = gfcString(tobjResult.eNN,2,"0").eLStr;
    tSS = gfcString(tobjResult.eNS,2,"0").eLStr;
    tobjResult.eY = tYYYY;
    tobjResult.eYM = tYYYY + "/" + tMM;
    tobjResult.eYMD = tYYYY + "/" + tMM + "/" + tDD;

    //24小時制
    tobjResult.eHNS24 = tHH + ":" + tNN + ":" + tSS;
    tobjResult.eHN24 = tHH + ":" + tNN;
    tobjResult.eYMDHN24 = tYYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN;
    tobjResult.eDateTime24 = tYYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + ":" + tSS

    //12小時制
    if (tHH + tNN > "1159")
    {
        if (tHH + tNN > "1300")
        {   tHH = "" + (tHH - 12);}
        tHH = gfcString(tHH,2,"0").eLStr;
        tAPM = " PM";
    }
    else
    {   tAPM = " AM";}
    tobjResult.eHNS12 = tHH + ":" + tNN + ":" + tSS + tAPM;
    tobjResult.eHN12 = tHH + ":" + tNN + tAPM;
    tobjResult.eYMDHN12 = tYYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + tAPM;
    tobjResult.eDateTime12 = tYYYY + "/" +tMM + "/" + tDD + " " + tHH + ":" + tNN + ":" + tSS + tAPM;
    return tobjResult;
}

//=============================================================================
//=   功能說明: 取得系統日期
//=   傳入參數: 無
//=   傳回參數: 物件  : eCDate      中國系統日期
//=                     eDate       西元系統日期
//=                       eErr                    表傳入無效的日期型態
//=                       eNY,eNM,eND             年,月,日
//=                       eNH,eNN,eNS             時,分,秒
//=                       eY,eYM,eYMD             年,年月,年月日
//=                       eHNS12,eHN12            時分秒,時分(12小時制)
//=                       eHNS24,eHN24            時分秒,時分(24小時制)
//=                       eYMDHN12,eYMDHN24       年月日時分(12小時制,24小時制)
//=                       eDateTime12,eDateTime24 年月日時分秒(12小時制,24小時制)
//===============================================================================
function gfcGetSysDate()
{
    var tobjResult = new Object();
	var tobjServerDate = new Object();

    //給初值
	tobjResult.eErr = false;

	tobjServerDate = gfcGetServerDate();

	if (!tobjServerDate.eErr)
	{   tobjResult.eCDate = gfcCDate(new Date(tobjServerDate.eDate));}
	else
	{   tobjResult.eCDate = gfcCDate(new Date());}

	tobjResult.eDate = gfcDate(tobjResult.eCDate.eDateTime24);

	return tobjResult;
}
function gfcGetServerDate()
{
	if (window.clientInformation.appVersion.indexOf("Windows NT 5.0")!=-1)
    {
		try
		{	var txhttpSender = new ActiveXObject("Microsoft.XMLHTTP");}
		catch (e)
		{	var txhttpSender = new ActiveXObject("Msxml2.XMLHTTP");}
	}
	else
	{	var txhttpSender = new ActiveXObject("Microsoft.XMLHTTP");}

    var tobjResult = new Object();

    var tUrl="../../global/pub/GetServerDate.asp";

    txhttpSender.Open("POST",tUrl, false);
    txhttpSender.Send("");

    tarParam = txhttpSender.responseText.split("|");
    switch (tarParam[0])
    {
        case "OK":
            tobjResult.eErr  = false;
            tobjResult.eDate = tarParam[1];
            break;
        case "ERR":
            tobjResult.eErr  = true;
            tobjResult.eDate = "";
            tobjResult.eErrDesc = tarParam[1];
            break;
        default:
            tobjResult.eErr  = true;
            tobjResult.eDate = "";
            break;
    }
    return tobjResult;
}

//=============================================================================
//=   功能說明: 數值 -> 四捨五入, 無條件捨去, 無條件進位
//=   傳入參數: pNumStr : 數值
//=             pPoint  : 小數部分長度, 亦即計算到小數第N位(0,1,2....)
//=   傳回參數: 物件    : eErr                 表傳入無效的數值型態
//=                       eRound               四捨五入到小數第 pPoint 位
//=                       eFix                 無條件捨去到小數第pPoint位
//=                       eAdd                 無條件進位到小數第pPoint位
//=                       ePos                 表正數/負數  +/-
//=============================================================================
function gfcTrnNum(pNumStr,pPoint)
{
    var tobjRtn = new Object();
    var tDecLen = 0;             //-數值的小數部分長度
    var tNumStr                  //-傳入數值轉成字串
    var tDecPos                  //-小數點所在位置
    var tPointPow                //-傳入小數位數的10乘羃
    if (isNaN(pNumStr) == true)  //-判斷傳入值 非數值；傳回錯誤
    {   
        tobjRtn.eErr = true;
        return tobjRtn;
    }
    tobjRtn.eErr = false;
    if (pNumStr == null || pNumStr == "")  //-為 Null / 空白 時; 傳入值=傳回值
    {
        tobjRtn.eRound = pNumStr;
        tobjRtn.eFix   = pNumStr;
        tobjRtn.eAdd   = pNumStr;
        tobjRtn.ePos   = pNumStr;
        return tobjRtn;
    }
    if (isNaN(pPoint) == true || pPoint == null || pPoint == "") //-未傳入小數位數, Default=0
    {   pPoint = 0  }

    //-取數值的小數位數, 放在變數 tDecLen 中
    tNumStr = pNumStr.toString()
    tDecPos = tNumStr.indexOf(".");  
    if (tDecPos > 0)
    {   tDecLen = tNumStr.substr(tDecPos + 1).length;    }

    //-取數值的正負數
    if (tNumStr >= 0)
    {   tobjRtn.ePos = "+";    }
    else
    {   tobjRtn.ePos = "-";   }
    tNumStr = Math.abs(tNumStr)
    //-若小數位數超過定義則轉換格式
    if (tDecLen > pPoint)
    {
        tPointPow = Math.pow(10,pPoint)  //-要取到小數點n位就有n個0
        tNumStr   = (parseFloat(tNumStr) * tPointPow);
        tobjRtn.eRound = gfcAddZero(Math.round(tNumStr) / tPointPow, pPoint);
	    tobjRtn.eFix   = gfcAddZero(parseInt(tNumStr, 10) / tPointPow, pPoint);
        tobjRtn.eAdd   = gfcAddZero((parseInt(tNumStr, 10) + 1) / tPointPow, pPoint);
    }
    else  //若是小數位數不足則傳原數值回去
    {
        tobjRtn.eRound = gfcAddZero(tNumStr, pPoint);
        tobjRtn.eFix   = gfcAddZero(tNumStr, pPoint);
        tobjRtn.eAdd   = gfcAddZero(tNumStr, pPoint);
    }
    if (tobjRtn.ePos == "-")   //-若為負數則補負號
    {
        tobjRtn.eRound = "-" + tobjRtn.eRound;
        tobjRtn.eFix   = "-" + tobjRtn.eFix;
        tobjRtn.eAdd   = "-" + tobjRtn.eAdd;
    }
    return tobjRtn;
}

//=============================================================================
//=   功能說明: 數值 -> 三位一撇
//=   傳入參數: pNum     : 數值或字串
//=             pTypeStr : "" 三位一撇的分隔字串(ex , ...)
//=             pDSign   : "" 傳回數值三位一撇
//=                      : "$" 傳回數值三位一撇且加 $
//=   傳回參數: 物件     : eErr       表處理成功/失敗
//=                        eNum       正確格式數值(原值)
//=                        eNum999    正確格式數值
//=                        eErrDesc   處理失敗錯誤訊息
//=============================================================================
function gfcTrnNumFormat(pNum,pTypeStr,pDSign)
{
    var tNum;
    var tNumStr;
    var tDecStr = "";
    var tPos;
    var ixCount,ixI;
    var tobjResult = new Object();

    //給初值
    tobjResult.eErr = false;
    tobjResult.eNum = pNum;
    tobjResult.eNum999 = "";
    tobjResult.eErrDesc = "";

    //例外處理(傳入空白或 null)
    if (typeof(pDSign) == "undefined") {   pDSign = "";}

    if (pNum == null)
    {
        tobjResult.eNum999 = null;
        return tobjResult;
    }
    if (pNum == "")
    {
        tobjResult.eNum999 = "";
        return tobjResult;
    }

    //例外處理(傳入非數值(字串)或數值位數小於 4)
    if (typeof(pNum) == "string")
    {   
        tNum = parseFloat(pNum,10);
        tNumStr = pNum;

        tPos = tNumStr.indexOf(".");
        if (tPos != -1)
        {
            tDecStr = gfcMid(tNumStr,tPos)
            tNumStr = gfcMid(tNumStr,0,tPos)
            tNum = parseInt(tNumStr,10)
        }
    }
    else
    {   
        tNum = pNum;
        tNumStr = pNum.toString();

        tPos = tNumStr.indexOf(".");
        if (tPos != -1)
        {
            tDecStr = gfcMid(tNumStr,tPos)
            tNumStr = gfcMid(tNumStr,0,tPos)
            tNum = parseInt(tNumStr,10)
        }
    }

    if (isNaN(tNum) || tNum != tNumStr)
    {
        tobjResult.eErr = true;
        tobjResult.eNum999 = pNum;
        tobjResult.eErrDesc = "格式錯誤,欲轉換的值不是數值型態 !";
        return tobjResult;
    }
    else
    {
        if (tNumStr.length <= 3)
        {
            if (gfcTrim(pDSign) == "$")
            {   tobjResult.eNum999 = "$ " + pNum;}
            else
            {   tobjResult.eNum999 = pNum;}
            return tobjResult;
        }
    }

    //開始轉換三位一撇
    ixCount = parseInt(tNumStr.length,10) % 3
    if (ixCount == 0)
    {   ixCount = 3;}

    tNum999 = "";
    tNum999 = tNum999 +  pTypeStr + gfcMid(tNumStr,0,ixCount)
    for (ixI=ixCount;ixI<tNumStr.length;ixI=ixI+3)
    {
        tNum999 = tNum999 +  pTypeStr + gfcMid(tNumStr,ixI,3);
    }

    if (gfcTrim(pDSign) == "$")
    {   tobjResult.eNum999 = "$ " + tNum999.substring(1) + tDecStr;}
    else
    {   tobjResult.eNum999 = tNum999.substring(1) + tDecStr;}

    return tobjResult;
}


function CheckMMDD(X)
{
	// Check MM/DD 格式
	var leap=0;
	if (X==null) return false;
	if (X=="") return false;
	if(X.length<4||X.length>5)return false;

	if(X.indexOf("/")>=0)
	{
		var ArrDate=X.split("/");
	}
	else
	{
		var ArrDate=new Array()
		ArrDate[0] = X.substr(0,2);
		ArrDate[1] = X.substr(2,2);
	}
			
		if(isNaN(ArrDate[0]))return false;
		if(ArrDate[0] < "0"||ArrDate[0]>"12")return false;
		var MM = new Array();
		MM["01"] = "31";
		MM["02"] = "29";
		MM["03"] = "31";
		MM["04"] = "30";
		MM["05"] = "31";
		MM["06"] = "30";
		MM["07"] = "31";
		MM["08"] = "30";
		MM["09"] = "30";
		MM["10"] = "31";
		MM["11"] = "30";
		MM["01"] = "31";
		
		if(ArrDate[1]<"0"||ArrDate[1]>MM[ArrDate[0]])return false;
		
		return ArrDate[0]+""+ArrDate[1]
}

//=============================================================================
//=   功能說明: 傳回一指定長度的字串,若長度不足,補上特殊字元
//=   傳入參數: pStr  : 要補特殊字元的字串
//=             pLen  : 指定長度
//=             pCode : 特殊字元
//=   傳回參數: 物件  : eLStr                  左方補特殊字元
//=                     eRStr                  右方補特殊字元
//=============================================================================
function gfcString(pStr,pLen,pCode)
{
    var tobjResult = new Object();
    var tStr = "";

    if (typeof(pStr) == "number") {   pStr = pStr.toString();}

    for(var ixI=0;ixI<pLen-pStr.length;ixI++)
    {
        tStr = tStr + pCode;
    }
    tobjResult.eLStr = tStr + pStr;
    tobjResult.eRStr = pStr + tStr;
    
    return tobjResult;
}

function SysplusXMLHttp()
{
		if (window.clientInformation.appVersion.indexOf("Windows NT 5.0")!=-1)
		{
			try
			{	var txhttpSender = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e)
			{	var txhttpSender = new ActiveXObject("Msxml2.XMLHTTP");}
			}
		else
		{	var txhttpSender = new ActiveXObject("Microsoft.XMLHTTP");}
		return txhttpSender;
}


function gfcOnBlur(pMethod,pObj)
{
	var arrInputElement = pObj.inputElement.split(",");
	var arrInputValue = new Array();
	for(i=0;i<arrInputElement.length;i++){
		if(arrInputElement[i].indexOf("'")==0)
			arrInputValue[i] =eval(arrInputElement[i]);
		else
			arrInputValue[i] = document.getElementsByName(arrInputElement[i])[0].value;
	}	
	var txhttpSender = new SysplusXMLHttp();
	var tobjResult = new Object();
	var tUrl="../Util/ClientOnBlurUtil.aspx";
	txhttpSender.Open("POST",tUrl, false);
	txhttpSender.Send("<Data><Method>"+pMethod+"</Method><Param>"+arrInputValue.toString()+"</Param></Data>");
	var tarParam = new ActiveXObject("Microsoft.XMLDOM");

	tarParam.loadXML(txhttpSender.responseText);
	return tarParam;
}	

function gfcOnClick(pMethod,pObj,pDisplayFields)
{
	var arrInputElement;
	var arrInputValue = "";

	if(typeof(pObj.inputElement)!='undefined'){
		 arrInputElement = pObj.inputElement.split(",");
		 arrInputValue = new Array();
			for(i=0;i<arrInputElement.length;i++){
				if(arrInputElement[i].length==0)
					arrInputValue[i] = null;
				else if(arrInputElement[i].indexOf("'")==0)
					arrInputValue[i] =eval(arrInputElement[i]);
				else 
					arrInputValue[i] = document.getElementsByName(arrInputElement[i])[0].value;
			}	
			var tUrl     = encodeURI("../Dialog/CommonClickForm2.aspx?Method=" + pMethod + "&Param=" + arrInputValue.toString() + "&DisplayFields="+ pDisplayFields);
	}
	else
	{
		var tUrl     = encodeURI("../Dialog/CommonClickForm2.aspx?Method=" + pMethod +  "&DisplayFields="+ pDisplayFields);
	}
	
	var txhttpSender = new SysplusXMLHttp();
	var tobjResult = new Object();
	debugger;
	txhttpSender.Open("POST",tUrl, false);
	txhttpSender.Send("<Data><Method>"+pMethod+"</Method><Param>"+arrInputValue.toString()+"</Param></Data>");
	var tarParam = new ActiveXObject("Microsoft.XMLDOM");
	var div = document.createElement("<div>");
	div.innerHTML = txhttpSender.responseText;
	div.id = "divDialog"
	div.className = "divDialog"
	div.style.width = "200px"
	div.style.height = "300px"	
	document.body.appendChild(div)
	//document.write(txhttpSender.responseText)
	return
	tarParam.loadXML(txhttpSender.responseText);
	return tarParam;
    //var tPos  = "status:no;help=no;dialogWidth:350px; dialogHeight:350px; dialogTop:200px; dialogLeft:324px";
    
   return window.showModalDialog(tUrl,"",tPos);
	
}	

function gfcChanged()
{
	parent.frames["hiddenFrame"].gfcHasChanged = true;
}

function gfcIsChanged()
{
	
	return parent.frames["hiddenFrame"].gfcHasChanged;
}

function gfcGetErrDesc(errCode)
{
	return parent.frames['hiddenFrame'].tblError[errCode];
}

function isNumber(pObj)
{
	if(pObj.value=="")return true;
	if(isNaN(pObj.value))
	{
		alert(parent.frames['hiddenFrame'].tblError['E001'])	;
		pObj.select();
		return false;
	}
	return true;
}

function isNumeric(pObj,pType)
{
	var pErrCode = "";
	if(pObj.value=="")return true;
	if(! isNumber(pObj))return false;
	switch(pType)
	{
			case ">0":
				if(pObj.value<=0)pErrCode="E002";break;
			case ">=0":
				if(pObj.value<0)pErrCode="E003";break;
			case "<0":
				if(pObj.value>=0)pErrCode="E004";break;
			case "<=0":
				if(pObj.value<0)pErrCode="E005";break;
	}

	if(pErrCode!="")
	{
		
			alert(parent.frames['hiddenFrame'].tblError[pErrCode])	;
			pObj.select();	
			return false;
	}
	return true;
}

function isNaCode(pObj)
{
	var re = new RegExp("[^A-Za-z0-9'_.-]","i");
	var str = pObj.value;
	if(re.test(str))
	{
		alert(parent.frames['hiddenFrame'].tblError["E006"])	;
		pObj.select();	
		return false;
	}
	return true;
}

function gfcElementClear(pObj)
{
	var arrOutputElement = pObj.outputElement.split(',');
	for(i=0;i<arrOutputElement.length;i++)
			document.getElementsByName(arrOutputElement[i])[0].value = "";
	 	
}

function gfcShowQueryImage(pObj,pImg)
{
	if(pObj.length<=0)return;
	if(pImg.length<=0)return;
	var src = pImg[0].src;
	src = (pObj[0].style.height!="0%")?src.replace("bs.gif","bo.gif"):src.replace("bo.gif","bs.gif");
	pImg[0].src = src;
}


function gfcTrim(pValue)
{
	var value=pValue;
	if(value.substring(0,1)==" ")
		value = value.substring(1,value.length);
	if(value.substring(value.length-1,value.length)==" ")
		value = value.substring(0,value.length-1);
	return value;
}
