﻿//必須存為 UTF-8 否則無法成功執行 (Must be UTF-8 encoded) 简体ぎ︰

var wndModelessChilds = new Array(0);
var wndModalChild;
var isRootWindow = false;
var wndPopup ;

if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
  wndPopup = window.createPopup();
}

var intervalID=null;
var timeoutID=null;
var timeout_showsubmitting=null;
var discardedThreadIDs = new Array(0);
var intCurrentInterval=0;
var CS_QUERYSTRING_NAME_LAUNCH_PAGE = "_LP";

var dotNet__onsubmit=undefined;
var dotNet__doPostBack=undefined;
var bPostingBack=false;

function processException(e,scope,ignoreAccessDenied)
{
	if(typeof(e)!="undefined" && typeof(e.message)!="undefined" && typeof(e.number)!="undefined")
	{
		if(e.number!=-2146828218 || !ignoreAccessDenied)
		{
			alert("[" + scope + "]" + e.number + " - " + e.message);
		}
	}
	else
	{
		alert("[" + scope + "]" +e.toString());
	}
}
 
function initMsgSending()
{
 
	var w=screen.width/3;
	var h=screen.height/6;
 
	var x=(window.document.body.offsetWidth - w)/2 +   window.document.body.offsetLeft;
    var y=(window.document.body.offsetHeight - h)/2 +  window.document.body.offsetTop;
 
var MsgSending=document.getElementById("MsgSending");
if (MsgSending)
{
MsgSending.style.position="absolute";
MsgSending.style.display="none";
MsgSending.style.top=y;
MsgSending.style.left=x;
MsgSending.style.width=w;
MsgSending.style.height=h;
MsgSending.style.borderTopStyle="ridge";
MsgSending.style.borderRightStyle="ridge";
MsgSending.style.borderLeftStyle="ridge";
MsgSending.style.borderBottomStyle="ridge";
MsgSending.style.backgroundColor="lightyellow";
}
}

function closeSubmitting()
{
//	var e=document.getElementById("MsgSending");
//	if (e)
//	{ 
//	   e.style.display="none";
//	}
//	if (timeout_showsubmitting) clearTimeout(timeout_showsubmitting);
 
// 	var e=document.getElementById("MouseCapturer");
// 	
// 	if (e)
//    {
//        wndPopup.hide();
//    }
//    else
//    {
//        wndPopup.hide();
//       //document.forms[0].style.display='';
//    }
 if(document.releaseCapture)
 {
 	document.releaseCapture();
 	}
 	bPostingBack=false;
	clearTimeout(timeout_showsubmitting);
}
function delayShowSubmitting()
{
//	initMsgSending();
//	var e=document.getElementById("MsgSending");
//	if (e)
//  	   e.style.display="";
    document.getElementById("ctl00_ApplicationBanner1_StatusBar1_lblMessage_lblText").innerHTML='資料傳送中，請稍候...';

} 
function showSubmitting()
{
    if (bPostingBack) {
       alert ('上次的要求尚未處理完畢，請稍候重試.');
	   return false;
	}
 /*
    if ( dotNet__onsubmit )
       if (!dotNet__onsubmit())
          return false;
  */    
	
    var e=document.getElementById("MouseCapturer");
 	
 	if (e)
    {
       //popupMessage('資料傳送中，請稍候...');
       e.setCapture();
	   timeout_showsubmitting=setTimeout(delayShowSubmitting,500);
    }
    else
    {
       popupMessage('資料傳送中，請稍候...');
       document.forms[0].style.display='none';
    }
	
    bPostingBack=true;
    
    return true;
}

function showSubmitting1()
{
	if(typeof(UIIsPreventResubmit) != "undefined" && UIIsPreventResubmit)
	{
	    if (bPostingBack) {
		   popupMessage('資料傳送中，請稍候...');
          // alert ('資料傳送中，請稍候...');
	       return false;
	    }
	 	//document.forms[0].style.display='none';
	}
	bPostingBack=true;
	var e=document.getElementById("MouseCapturer");
	//var e=document.createElement();
	//document.appendChild(e);
 
	if (e)
	{
	//e.onclick="alert('資料傳送中，請稍候...');";
	//e.onlosecapture="this.setCapture();";
	//e.style.cursor="wait";
	e.setCapture();
	//timeout_showsubmitting=setTimeout(delayShowSubmitting,500);
	}
	 popupMessage('資料傳送中，請稍候...');
 	//document.parentWindow.status="資料傳送中，請稍候...";
 	
	return true;
}

function ne__doPostBack(eventTarget, eventArgument) 
{
	if(dotNet__doPostBack!=undefined)
	{
	   if (!showSubmitting()) 
     	   dotNet__doPostBack(eventTarget, eventArgument);
	 //  showSubmitting();
	}
	 
}

//function nePage_ClientValidate() 
//{
//	if(dotNetPage_ClientValidate!=undefined)
//	{
//		var canPostback=true;
//		try
//		{
//			var retVal = dotNetPage_ClientValidate();
//			if(retVal==false)
//			{
//				canPostback=false;
//			}
//		}
//		catch(e)
//		{
//			processException(e,"nePage_ClientValidate#1",false);
//			canPostback=false;
//		}
//		if(canPostback)
//		{
//			if(typeof(appClientValidator)=="function")
//			{
//				try
//				{
//					var retVal = appClientValidator();
//					if(retVal==false)
//					{
//						canPostback=false;
//					}
//				}
//				catch(e)
//				{
//					processException(e,"nePage_ClientValidate#2",false);
//					canPostback=false;
//				}
//			}
//		}
//		return canPostback;
//	}
//}
//控制TextBox輸入長度相關功能{
function getLengthInByte(str)
{
	var len=0;
	for(i=0;i<str.length;i++)
	{
		len++;
		if(str.charCodeAt(i)>255) len++;
	}
	return len;
}

function trimLengthInByte(obj,maxlength)
{
	if(obj == undefined || obj.type == undefined || (obj.type!="text" && obj.type!="textarea")) return 0;
	if(isNaN(maxlength) || maxlength<=0) return 0;
	var str = obj.value;
	var lenB = getLengthInByte(str);
	if(lenB>maxlength)
	{
		var lenC=str.length; //length in char
		while(lenB>maxlength)
		{
			lenC--;
			var cc=str.charCodeAt(lenC);
			if(cc>255) lenB--;
			else if(cc==10 && lenC>1 && str.charCodeAt(lenC-1)==13)
			{
				lenC--;
				lenB--;
			}
			lenB--;
		}
		obj.value = str.substr(0,lenC);
	}
	return lenB;
}

function limitInputLengthInByte(obj,maxlength)
{
	
	if(obj == undefined || obj.type == undefined || (obj.type!="text" && obj.type!="textarea")) return;
	if(isNaN(maxlength) || maxlength<=0) return;
	if(window.event.type=="keydown")
	{
		if(window.event.ctrlKey || window.event.altKey) return;
		var kc=window.event.keyCode;
		if(kc==32 || kc==106 || kc==107 || kc==226 || (kc>=48 && kc<=57)  || (kc>=65 && kc<=90) || (kc>=96 && kc<=105)  || (kc>=109 && kc<=111)  || (kc>=186 && kc<=222))
		{
			if(getLengthInByte(obj.value)>=maxlength)
			{
				window.event.returnValue=false;
				window.event.cancelBubble=true;
			}
		}
	}
	else if(window.event.type=="keyup")
	{
		if(window.event.keyCode==229) return;
		trimLengthInByte(obj,maxlength);
	}
	else if(window.event.type=="select" || window.event.type=="change")
	{
		trimLengthInByte(obj,maxlength);
	}
}
//控制TextBox輸入長度相關功能}

function dbg(msg)
{
	alert(msg);
}


function resizeWindow(intWidth,intHeight,bolCenter)
{
	if(window.top.dialogHeight==undefined)
	{
		window.top.resizeTo(intWidth,intHeight);
		if(bolCenter)
		{
			window.top.moveTo((screen.availWidth-intWidth)/2,(screen.availHeight-intHeight)/2);
		}
	}	
	else
	{
		window.top.dialogWidth = intWidth + "px";
		window.top.dialogHeight = intHeight + "px";
		if(bolCenter)
		{
			window.top.dialogLeft = String((screen.availWidth-intWidth)/2) + "px";
			window.top.dialogTop = String((screen.availHeight-intHeight)/2) + "px";
		}
	}
}

function autoResizeWindow()
{
	//window.status = document.body.scrollWidth + " / " + document.body.scrollHeight + " ; " + document.body.offsetWidth + " / " + document.body.offsetHeight + " ; " + document.body.clientWidth + " / " + document.body.clientHeight + " ; " 

	var offsetX = document.body.scrollWidth - document.body.offsetWidth;
	if(offsetX<0) offsetX=0;
	var offsetY = document.body.scrollHeight - document.body.offsetHeight;
	if(offsetY<0) offsetY=120;
	if(window.top.dialogHeight==undefined)
	{
		window.top.resizeBy(offsetX,100);
		window.top.moveBy(400,400);
	
	}
	else
	{
	
		if(offsetY>0)
		{
			var dH = parseInt(window.top.dialogHeight.substr(0,window.top.dialogHeight.length-2)) + 24;
			
			window.top.dialogHeight = String(dH + offsetY) + "px";
			var dT = parseInt(window.top.dialogTop.substr(0,window.top.dialogTop.length-2));
			window.top.dialogTop = String(dT - (offsetY/2)) + "px" ;
		}
		if(offsetX>0)
		{
			var dW = parseInt(window.top.dialogWidth.substr(0,window.top.dialogWidth.length-2));
			window.top.dialogWidth = dW + offsetX + "px";
			var dL = parseInt(window.top.dialogLeft.substr(0,window.top.dialogLeft.length-2));
			window.top.dialogLeft = String(dL - offsetX/2) + "px";
		}
	}
}

function setFirstTextControlFocus()
{
	if(window.document.forms.length>0)
	{
		for(i=0;i<window.document.forms[0].elements.length;i++)
		{
			if(window.document.forms[0].elements[i].type != undefined && window.document.forms[0].elements[i].type == "text" && window.document.forms[0].elements[i].disabled != undefined && !window.document.forms[0].elements[i].disabled) 
			{
				if(window.document.forms[0].elements[i].isDisabled == undefined || !window.document.forms[0].elements[i].isDisabled)			
				{
					try
					{
						window.document.forms[0].elements[i].focus();
						return true;
					}
					catch(e)
					{
						return false;
					}
				}
			}
		}
	}
	return false;
}

function setDefaultFocus()
{
	if(strDefaultFocusControlClientID.length>0)
	{
		if(window.document.all[strDefaultFocusControlClientID]!=undefined 
			&& window.document.all[strDefaultFocusControlClientID].focus!=undefined 
			&& window.document.all[strDefaultFocusControlClientID].disabled != undefined 
			&& !window.document.all[strDefaultFocusControlClientID].disabled) 
		{
			try
			{
				window.document.all[strDefaultFocusControlClientID].focus();
			}
			catch(e)
			{
				window.status="無法設定控制項-" + strDefaultFocusControlClientID + "的輸入焦點!";
			}
			return;
		}
	}
	else setFirstTextControlFocus();
}

function popupMessage(msg,w,h)
{
	window.focus();
	if(w==undefined) w=screen.width/3;
	if(h==undefined) h=screen.height/6;
    var oBody = wndPopup.document.body;
	oBody.style.overflow="auto";
	oBody.innerHTML="<table width='100%' height='100%' cellpadding='0' cellspacing='0' style='OVERFLOW: auto; BORDER-TOP-STYLE: ridge; BORDER-RIGHT-STYLE: ridge; BORDER-LEFT-STYLE: ridge; BACKGROUND-COLOR: lightyellow; BORDER-BOTTOM-STYLE: ridge'><tr height=100%><td align=center valign=center >" + msg + "<p><a href='' onclick='javascript:parent.wndPopup.hide();return false;'>確定</a></p></td></tr></table>"
    //wndPopup.show((screen.width-w)/2, (screen.height-h)/2, w, h);
    var x=(window.top.document.body.offsetWidth - w)/2 + window.top.screenLeft + window.top.document.body.offsetLeft;
    var y=(window.top.document.body.offsetHeight - h)/2 + window.top.screenTop + window.top.document.body.offsetTop;
    //var x=(window.document.body.offsetWidth - w)/2 + window.screenLeft + window.document.body.offsetLeft;
    //var y=(window.document.body.offsetHeight - h)/2 + window.screenTop + window.document.body.offsetTop;
    wndPopup.show(x,y,w,h);
}

function setCookie(sName, sValue, expireDate)
{
	document.cookie = sName + "=" + escape(sValue) + ";path=/" + ((expireDate == undefined || expireDate == null) ? "" : ("; expires=" + expireDate.toGMTString()));
}

function getCookie(sName)
{	var a = document.cookie.split("; ");
	for(var i=0;i<a.length;i++)
	{	var a1=a[i].split("=");
		if(sName==a1[0])
		{	return unescape(a1[1]);
		}
	}
	return null;
}

function removeCookie(sName)
{
	var sValue=getCookie(sName);
	if(sValue)
	{
		setCookie(sName,sValue,new Date());
	}
}

function isLogout()
{
	return (getCookie(strFormsCookieName) == undefined);
}

function forceLogout()
{
	removeCookie(strFormsCookieName);
}

function focusOpenner()
{
	if(window.opener!=undefined) window.opener.focus();
}

function focusMainMenu()
{
	var wnd = getRootFrameContainer();
	if(typeof(wnd)!="undefined")
	{
		if(wnd.isRootWindow)
		{
			wnd.focus();
		}
	}
}

function removeClosedChilds()
{
	for(i=wndModelessChilds.length-1;i>=0;i--)
	{
		try
		{
			if(wndModelessChilds[i][0].closed==true) wndModelessChilds.splice(i,1);
		}
		catch(e)
		{
			processException(e,"removeClosedChilds",true,false);
			wndModelessChilds.splice(i,1);
		}
	}
}

function isAnyChildNotClosed()
{
	for(i=0;i<wndModelessChilds.length;i++)
	{
		try
		{
			if(wndModelessChilds[i][0].closed==false)
			{
				return true;
			}
		}
		catch(e)
		{
			processException(e,"isAnyChildNotClosed",false);
		}
	}
	return false;
}

function appendArg(url,argName,argValue)
{
	if(url.indexOf("?")==-1) url += "?";
	else url += "&";
	url = url + argName + "=" + encodeURIComponent(argValue);
	return url;
}

function openQueryDialog(url,feature,form,frameTitle,argValue)
{

	if(urlFrameControl!=undefined)
	{
		var urlPage = appendArg(url,"argValue",argValue);
		var modalArguments = new Object();
		modalArguments.LaunchPage = urlPage;
		modalArguments.ParentWindow = window;
		modalArguments.argValue = argValue;
		if(feature==undefined) feature=strModalWindowFeature;
		urlDialog = urlFrameControl;
		if(typeof(frameTitle)!="undefined")
		{  
		   if(urlDialog.indexOf("?")>0)
		   {
		     urlDialog = urlDialog + "&Title=" + encodeURIComponent(frameTitle);
		   }
		   else
		   {
		      urlDialog = urlDialog + "?Title=" + encodeURIComponent(frameTitle);
		   }
	     }
		var retval = window.showModalDialog(urlDialog, modalArguments, feature);
		wndModalChild = undefined;
		return retval;
	}
	else
	{
		alert("系統錯誤! urlFrameControl 值未設定!");
	}
}

function openModalFrameChild(url,feature,form,frameTitle)
{

	if(urlFrameControl!=undefined)
	{
		var modalArguments = new Object();
		modalArguments.LaunchPage = url;
		modalArguments.ParentWindow = window;
		if(feature==undefined) feature=strModalWindowFeature;
		//form.document.parentWindow.status="對話框視窗開啟中，請稍候...";
		urlDialog = urlFrameControl;
		if(typeof(frameTitle)!="undefined") urlDialog = urlDialog + "?Title=" + encodeURIComponent(frameTitle);
		var retval = window.showModalDialog(urlDialog, modalArguments, feature);
		if(wndModalChild != undefined)
		{
			var wnd = wndModalChild;
			wndModalChild = undefined;
		


 	        if (typeof(form.document.parentWindow.Sys) != "undefined")
            {
                setTimeout( form.document.parentWindow.PageReturnTrigger,10);
            }
            else
            {
                form.document.parentWindow.bPostingBack=false;
                form.document.parentWindow.showSubmitting();
  			    form.submit();
  			}
		}
		return retval;
	}
	else
	{
		alert("系統錯誤! urlFrameControl 值未設定!");
	}
}
function openWindow(url,feature,form,frameTitle)
{


	if(urlFrameControl!=undefined)
	{

		var modalArguments = new Object();
		
		modalArguments.LaunchPage = url;
		modalArguments.ParentWindow = window;
		
		if(feature==undefined) feature=strModalWindowFeature;
		 

		//form.document.parentWindow.status="對話框視窗開啟中，請稍候...";
		 
		urlDialog = urlFrameControl;
		
		if(typeof(frameTitle)!="undefined") urlDialog = urlDialog + "?Title=" + encodeURIComponent(frameTitle)+"&_LP="+encodeURIComponent(url);
	
       // frameTitle=encodeURIComponent(frameTitle);
    // alert("urlDialog"+urlDialog);
//       alert("frameTitle"+frameTitle);
//      alert("feature"+feature);
		var retval =window.open(urlDialog,frameTitle,feature);
 
		if(wndModalChild != undefined)
		{
			var wnd = wndModalChild;
			wndModalChild = undefined;
		 	       
		}
		return retval;
	}
	else
	{
		alert("系統錯誤! urlFrameControl 值未設定!");
	}
}
function openExistModelessChildIndex(windowName,url,overrideExistWindow)
{
	if(windowName!=undefined && windowName.length>0 && windowName!="_blank")
	{
		for(i=0;i<wndModelessChilds.length;i++)
		{
			if(wndModelessChilds[i][2]==windowName)
			{
				if(wndModelessChilds[i][0] != undefined && !wndModelessChilds[i][0].closed)
				{
					if(overrideExistWindow!=undefined && overrideExistWindow==true)
					{
						//dbg("openExistModelessChildIndex : " + url);
						wndModelessChilds[i][0].open(url,"_self");
					}
					wndModelessChilds[i][0].focus();
					return true;
				}
			}
		}
	}
	return false;
}

function openModelessFrameChild(url,feature,windowName,overrideExistWindow)
{
	if(urlFrameControl!=undefined)
	{
		removeClosedChilds();
		if(feature==undefined || feature.length==0) feature=strModelessWindowFeature;
		if(windowName == undefined || windowName.length<=0) windowName = "_blank";
		windowName=windowName.replace(" ","_");
		launchUrl=urlFrameControl + "?" + CS_QUERYSTRING_NAME_LAUNCH_PAGE + "=" + encodeURIComponent(url);
		if(openExistModelessChildIndex(windowName,launchUrl,overrideExistWindow)) return;
		//dbg("openModelessFrameChild : " + launchUrl);
		var child = window.open(launchUrl,windowName,feature);
		var wndInfo = new Array();
		wndInfo.push(child);
		wndInfo.push(launchUrl);
		wndInfo.push(windowName);
		wndModelessChilds.push(wndInfo);
	}
	else
	{
		alert("系統錯誤! urlFrameControl 值未設定!");
	}
}

function openModelessPage(url,feature,windowName,overrideExistWindow)
{
	removeClosedChilds();
	if(feature==undefined) feature=strModelessWindowFeature;
	if(windowName == undefined || windowName.length<=0) windowName = "_blank";
	if(openExistModelessChildIndex(windowName,url,overrideExistWindow)) return;
	//dbg("openModelessPage : " + url);
	var child = window.open(url,windowName,feature);
	var wndInfo = new Array();
	wndInfo.push(child);
	wndInfo.push(url);
	wndInfo.push(windowName);
	wndModelessChilds.push(wndInfo);
}

function openStateViewer()
{
	window.open(urlControlPath + "/StateViewer.aspx","StateViewer",strModelessWindowFeature);
}

function isAnyChildOpened()
{
	if(wndModalChild != undefined && wndModalChild.closed != undefined && !wndModalChild.closed) return true;
	for(i=wndModelessChilds.length-1;i>=0;i--)
	{
		try
		{
			if(wndModelessChilds[i][0].closed==false)
			{
				return true;
			}
		}
		catch(e)
		{
		}
	}
	
}
function closeModalChild()
{

	if(wndModalChild != undefined && wndModalChild.closed != undefined && !wndModalChild.closed)
	{
		var wnd = wndModalChild;
		wndModalChild = undefined;
		wnd.forceClose();
	}
	
	for(i=0;i<wndModelessChilds.length;i++)
	{
		try
		{
			if(wndModelessChilds[i][0].closed==false)
			{
				if(wndModelessChilds[i][0].closeModalChild != undefined)
				{
					wndModelessChilds[i][0].closeModalChild();
				}
			}
		}
		catch(e)
		{
			processException(e,"closeModalChild",true);
		}
	}
}

function closeModelessChilds()
{
	for(i=wndModelessChilds.length-1;i>=0;i--)
	{
		try
		{
			if(wndModelessChilds[i][0].closed==false)
			{
				if(wndModelessChilds[i][0].forceClose != undefined)
				{
					wndModelessChilds[i][0].forceClose();
				}
				else
				{
					wndModelessChilds[i][0].close();
				}
			}
		}
		catch(e)
		{
			processException(e,"closeModelessChilds",true);
		}
	}
	wndModelessChilds.length=0;
}

function closeAllChilds()
{
	closeModalChild();
	closeModelessChilds();
}

function confirmUnclosedChild()
{
	removeClosedChilds();
	if(isAnyChildNotClosed())
	{
		event.returnValue = "此動作將會關閉其他子視窗!";
	}
}

function closeWindowHandler()
{
	closeAllChilds();
	var wndRoot = getRootFrameContainer();
	if(!isLogout() && wndRoot != undefined)
	{
		var ids = new Array(0);
		for(i=0;i<window.frames.length;i++)
		{
			if(window.frames[i].getAllThreadID != undefined)
			{
				window.frames[i].getAllThreadID(ids);
			}
		}
		while(ids.length>0) wndRoot.discardedThreadIDs.push(ids.pop());
		wndRoot.discardThreadID(window==wndRoot);
	}
}

function forceClose()
{
	window.onunload = null;
	closeWindowHandler();
	window.top.close();
}

function getThreadID()
{
	if(window.document.forms[0]._PAGESI != undefined)
	{
		return window.document.forms[0]._PAGESI.value;
	}
	return undefined;
}

function setTitle()
{
	//dbg("setTitle : " + window.document.title);
	try
	{
		window.top.document.title=window.document.title;
	}
	catch(e)
	{
		//window.status="Fail to set document's title!" + e;
	}
}

function contextMenuHandler()
{
	event.returnValue = false;
}

function getAllThreadID(ids)
{
	for(i=0;i<window.frames.length;i++)
	{
		if(window.frames[i].getAllThreadID != undefined)
		{
			window.frames[i].getAllThreadID(ids);
		}
	}
	var threadID = getThreadID();
	if(threadID != undefined)
	{
		ids.push(threadID);
	}
}

function removeDiscardedThreadID()
{
	timeoutID = null;
	var threadID;
	try
	{
		if(discardedThreadIDs.length>0)
		{
			threadID = discardedThreadIDs.join(",");
			discardedThreadIDs.length=0;
			getTopFrameContainer().frames["ServiceFrame"].location = window.urlRemoveThread + "?_PAGESI=" + threadID;
		}
		if(discardedThreadIDs.length>0 && timeoutID == null) timeoutID = window.setTimeout(removeDiscardedThreadID,1000);
	}
	catch(e)
	{
		processException(e,"removeDiscardedThreadID",false);
	}
}

function discardThreadID(sync)
{
	if(discardedThreadIDs.length<=0) return;
	if(sync)
	{
		if(timeoutID != null) 
		{
			window.clearTimeout(timeoutID);
			timeoutID=null;
		}
		removeDiscardedThreadID();
	}
	else
	{
		if(timeoutID == null) timeoutID = window.setTimeout(removeDiscardedThreadID,2000);
	}
}

function countdownTimeout()
{
	var secondsTimeout=parseInt(getCookie("secondsTimeout"),10);
	if(isNaN(secondsTimeout)) 
	{
		alert("找不到連線逾時 Cookie 值, 已取消連線逾時控制功能!");
		window.clearInterval(intervalID);
		intervalID = null;
		intCurrentInterval=0;
		return;
	}
	//var secondsRemain = secondsTimeout - Math.round((new Date().valueOf()/1000));
	var secondsRemain = secondsTimeout - intCurrentInterval/1000;
	setCookie("secondsTimeout",secondsRemain.toString());
	//window.status="window.parent=" + window.parent + ";secondsTimeout=" + secondsTimeout + ";secondsRemain=" + secondsRemain + ";intCurrentInterval=" + intCurrentInterval;
	var msg;
	//debug msg="您的連線作業將於" + secondsRemain + "秒鐘後失效!";
	//debug window.status = msg;
	if(secondsRemain <= 0 || isLogout())
	{
		window.clearInterval(intervalID);
		intervalID = null;
		intCurrentInterval=0;
		closeWindowHandler();
		if(!isLogout())
		{
			msg = "您的連線作業已因逾時而失效!";
			window.status = msg;
			forceLogout();
			if(isPopupSessionTimeout)
			{
				popupMessage(msg);
			}
			window.defaultStatus = msg;
			msg = msg + "<p><a href='" + window.location.href + "'>你可以按此重新連線</a></p>";
			var htm  = "<table width='100%' height='100%' cellpadding='0' cellspacing='0' style='OVERFLOW: auto; BORDER-TOP-STYLE: ridge; BORDER-RIGHT-STYLE: ridge; BORDER-LEFT-STYLE: ridge; BACKGROUND-COLOR: lightyellow; BORDER-BOTTOM-STYLE: ridge'><tr height=100%><td align=center valign=center >" + msg + "</td></tr></table>"
			window.document.body.innerHTML = htm;
		}
	}
	else
	{
		if(secondsRemain <= 300)
		{
			if(secondsRemain >= 60)
			{
				var minutesRemain = Math.round(secondsRemain/60);
				msg = "由於系統設有閒置期限, 您的連線作業將於 " + minutesRemain + " 分鐘後失效！";
				window.status = msg;
				if(isAnyChildOpened() && isPopupSessionTimeout) 
				{
					popupMessage(msg + "請在這段閒置期限內送出您的表單資料!");
				}
			}
			else
			{
				msg = "您的連線作業即將於 " + secondsRemain + " 秒鐘後失效...";
				window.status = msg;
				if(isAnyChildOpened() && isPopupSessionTimeout) popupMessage(msg);
				window.clearInterval(intervalID);
				intCurrentInterval = secondsRemain*1000;
				intervalID=window.setInterval("countdownTimeout()",intCurrentInterval);
			}
		}
		else
		{
			if(window.status.indexOf("連線作業")>=0)
			{
				window.status = "";
			}
			if(intCurrentInterval != intSessionTimeoutDetectInterval && intervalID != null)
			{
				window.clearInterval(intervalID);
				intCurrentInterval = intSessionTimeoutDetectInterval;
				intervalID=window.setInterval("countdownTimeout()",intCurrentInterval);
			}
		}
	}
}

function enableCountdownTimeout()
{
	if(!isLogout())
	{
		//dbg("enableCountdownTimeout!");
		window.status="";
		if(intervalID!=null)
		{	
			try
			{
				window.clearInterval(intervalID);
			}
			catch(e)
			{
			}
			intervalID=null;
		}
		intCurrentInterval = intSessionTimeoutDetectInterval;
		intervalID=window.setInterval("countdownTimeout()",intCurrentInterval);
	}
}

function enableConfirmUnclosedChild()
{
	window.onbeforeunload = confirmUnclosedChild;
}

function getTopFrameContainer()
{

	var wndFrameContainer=undefined;
	var wnd = window;
	while(wnd != wnd.top)
	{
		if(wnd.isFrameContainer) wndFrameContainer = wnd;
		wnd=wnd.parent;
	}
	if(wnd.isFrameContainer) wndFrameContainer = wnd;

	return wndFrameContainer;
}

function getRootFrameContainer()
{
	var wnd = getTopFrameContainer();
	while(wnd != undefined)
	{ 
		try
		{
			if(!(wnd.top.opener != undefined && !wnd.top.opener.closed && wnd.top.opener.getTopFrameContainer!=undefined))
			{
				break;
			}
		}
		catch(e)
		{
			break;
		}
		wnd = wnd.top.opener.getTopFrameContainer();
	}
	if(wnd != undefined && wnd.isFrameContainer) return wnd;
	return undefined;
}

function setRootWindow()
{
	try
	{
		if(typeof(window.parent.isRootWindow) != "undefined") window.parent.isRootWindow=true;
	}
	catch(e)
	{
	}
	if(window.isRootWindow != undefined) window.isRootWindow=true;
}

function initPage()
{

 
	window.status="";
	//dbg("window.opener=" + window.opener);
	var wndTopFrameContainer = getTopFrameContainer();
	
	if(window.isFrameContainer)
	{
		if(window == wndTopFrameContainer)
		{
			window.onunload = closeWindowHandler;
			//dbg("isFrameContainer!\nwindow.parent==undefined : " + (window.parent==undefined) + "\nwindow.name : " + (window.name) + "\nwindow.parent==window.top : " + (window.parent==window.top) + "\nwindow.parent==window : " + (window.parent==window)  + "\nwindow.location : " + window.location);
		}
	}
	else
	{
	
		//dbg("Not isFrameContainer!\nwindow.name : " + (window.name) + "\nwindow.opener==undefined : " + (window.opener==undefined) + "\nwindow.top.opener==undefined : " + (window.top.opener==undefined) + "\nwindow.parent==undefined : " + (window.parent==undefined) + "\nwindow.parent==window.top : " + (window.parent==window.top)  + "\nwindow.location : " + window.location);
		if(wndTopFrameContainer==undefined)
		{
			//dbg("wndTopFrameContainer==undefined");
			var url=window.location.href;
			
		
			var threadID = getThreadID();
			if(threadID!=undefined  && threadID.length>0)
			{	
				if(url.indexOf("?")>=0)
				{
					url=url+"&_PAGESI="+threadID;
				}
				else
				{
					url=url+"?_PAGESI="+threadID;
				}
			}
		
			window.location = urlFrameControl + "?_LP=" + encodeURIComponent(url);
			return;
		}
		var wndRoot = getRootFrameContainer();
		if(wndRoot == undefined)
		{
			alert("Cannot getRootFrameContainer()");//impossible here!
			return;
		}
		if(wndTopFrameContainer==wndRoot)
		{
			window.status = "";
			if(isLogout())
			{
				wndTopFrameContainer.closeWindowHandler();
			}
			else
			{
				wndTopFrameContainer.enableCountdownTimeout();
				wndTopFrameContainer.enableConfirmUnclosedChild();
			}
		}
		if(!isFrameContainer)
		{
			setTitle();
			setDefaultFocus();
		}
	}
	 
	 // 註冊 PostBack
	 if (typeof(Sys) != "undefined")
     {
     Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function() {Sys.WebForms.PageRequestManager.getInstance()._asyncPostBackControlClientIDs.push( "PageReturn" );} );
     }
       
//	 if(typeof(__doPostBack) != "undefined")
//	 {
//	    if (typeof(ne__doPostBack) == "undefined") 
//	    {
//		    dotNet__doPostBack=__doPostBack;
//		    __doPostBack = ne__doPostBack;
//		}
//	}

    // 串接 onsubmit 
    // 使用此段則 clientside validation 才會正常
    /*
    if (typeof(WebForm_OnSubmit)!="undefined") 
    {
        if (typeof(dotNet__onsubmit) == "undefined")
        {
	      dotNet__onsubmit=WebForm_OnSubmit;
	      WebForm_OnSubmit=showSubmitting;
	    }
 	}
 	*/

//    if (typeof(document.forms[0].onsubmit)!="undefined")
//    {
//        if (typeof(dotNet__onsubmit) == "undefined")
//        {
//	      dotNet__onsubmit=document.forms[0].onsubmit;
//	      document.forms[0].onsubmit=showSubmitting;
//	    }
//	 }
//	 else
//	 {
//	    document.forms[0].onsubmit=showSubmitting;
//	 }
 


//	if(typeof(Page_ClientValidate) == "function")
//	{
//		dotNetPage_ClientValidate=Page_ClientValidate;
//		Page_ClientValidate = nePage_ClientValidate;
//	}

    closeSubmitting();

   
}

function SetFormDirty()
{
	if(typeof(Form1._UIFormIsDirty) != "undefined" && typeof(Form1._UIFormIsDirty.value) != "undefined")
	{
		Form1._UIFormIsDirty.value="true";
		if(typeof(ShowDirtyImage)=='function')
		{
			ShowDirtyImage();
		}
	}
}

function PageReturnTrigger()
{ 
      // 因為 ctl00$ApplicationBanner1$Banner1$btnHome 這個Client Control存在, 所以才可用
      //__doPostBack('ctl00$ApplicationBanner1$Banner1$btnHome','');
      __doPostBack('ctl00$PageReturnTriger','');
      
     // 因為 PageReturn 這個Client Control不存在, 所以不可用
     // __doPostBack('PageReturn','');
       
}
var m_cardholder = '請輸入卡主姓名';
var m_cardholder2 = '格式輸入有誤, 請填寫顯示於信用卡上的名字\n請重新輸入。';
var m_cardno = '信用卡號碼有誤';
var m_cardno2 = '格式輸入有誤';
var m_cvv = 'CVV2 / CVC2 資料有誤';

function chk_holder(obj){
	if(obj.value != ""){
		var ho_pat = /^([a-zA-Z ])+$/;
		
		if(!ho_pat.test(obj.value)){
			alert(m_cardholder2);
			obj.value = "";
			obj.focus();
		}
	}
}

function chk_card(obj){
	
	var card_no = obj.value;
	
	if(card_no != "" && card_no.length == 16){
		if(!chk_card_valid(card_no)){
			
			alert(m_cardno);
			obj.focus();
		}
	}
	else
	{
	        alert(m_cardno);
			obj.focus();
	}
	
}

function chk_card_valid(cn){
	sum = 0; mul = 1; l = cn.length;
	
	if(l == 16){
		for (i = 0; i < l; i++) {
			digit = cn.substring(l-i-1,l-i);
			tproduct = parseInt(digit ,10)*mul;
					
			if (tproduct >= 10)
				sum += (tproduct % 10) + 1;
			else
				sum += tproduct;
						
			if (mul == 1)
				mul++;
			else
				mul--;
		}
	}else{
		sum++;
	}
	
			
	if ((sum % 10) == 0){
		return true;
	}else{
		return false;
	}
}


function AddressChange(val,txtAddressZip,txtAddress,Label10,Label11,post,area,lblPost,lbl)
{
   if(val=="YJ")
   {
     txtAddressZip.style.display ="";
     txtAddress.style.display ="";
     Label10.style.visibility ="";
     Label11.style.visibility ="";
     lblPost.style.visibility ="";
     lbl.style.visibility ="";
     post.style.display ="";
     var isSelect=false;
     for (var i = 0; i < post.options.length; i++) { 
	 
        if (post.options[i].value == area.value) 
		{
		 
		   lblPost.value=post.options[i].text;
		   isSelect=true;
		   break;
		}
	 }
	 if(isSelect==false)
	 {
	    for (var i = 0; i < post.options.length; i++) 
	    {
	       if (post.options[i].value == "OTHER")
	       {
	           lblPost.value=post.options[i].text;
		       isSelect=true;
		       break;
	       } 
	    }
	 }
   }
   else
   {
    txtAddressZip.style.display ="none";
     txtAddress.style.display ="none";
     Label10.style.visibility ="hidden";
     Label11.style.visibility ="hidden";
     lblPost.style.visibility ="hidden";
     lbl.style.visibility ="hidden";
     post.style.display ="none";
   }
   
}
function AreaChange(val,getMethod,post,lblpost)
{
  if(getMethod.text=="Post")
  {
      var isSelect=false;
     for (var i = 0; i < post.options.length; i++) { 
	 
        if (post.options[i].value == val) 
		{
		 
		   lblpost.value=post.options[i].text;
		   isSelect=true;
		   break;
		}
	 }
	 if(isSelect==false)
	 {
	    for (var i = 0; i < post.options.length; i++) 
	    {
	       if (post.options[i].value == "OTHER")
	       {
	           lblpost.value=post.options[i].text;
		       isSelect=true;
		       break;
	       } 
	    }
	 }
  }
}
function ReportChange(value)
{
   window.open(value,"reportFrame");
}

function isNumber(obj)
{
   if(isNaN(obj.value))
   {
      alert("請輸入數字！");
      obj.value="0";
      obj.focus();
   }
}
function OrderCount(value,txtOrder)
{
txtOrder.value=value;

}
 function EnableBtn(ob,obj)
{

if(ob.checked)
{
document.getElementById(obj).Enabled=true;
}
else
{
document.getElementById(obj).Enabled=false;
}
alert(document.getElementById(obj).Enabled);

}

function showLayer(obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj8,obj9)
{

  document.getElementById(obj1).style.display="";   

  document.getElementById(obj2).style.display="none";   
  document.getElementById(obj3).style.display="none";   
  document.getElementById(obj4).style.backgroundImage= "url('" + defaulturl + "/Shopping/images/index_05_05.jpg')";
  document.getElementById(obj5).style.backgroundImage=  "url('" + defaulturl + "/Shopping/images/index_05_04.jpg')";
  document.getElementById(obj6).style.backgroundImage= "url('" + defaulturl + "/Shopping/images/index_05_04.jpg')";
  document.getElementById(obj7).className= "orange";
  document.getElementById(obj8).className= "black_2";
  document.getElementById(obj9).className= "black_2";


}
function showtLayer(obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj8,obj9)
{

  document.getElementById(obj1).style.display="";   

  document.getElementById(obj2).style.display="none";   
  document.getElementById(obj3).style.display="none";   
  document.getElementById(obj4).style.backgroundImage= "url('" + defaulturl + "/Shopping/images/cen_09_06.jpg')";
  document.getElementById(obj5).style.backgroundImage=  "url('" + defaulturl + "/Shopping/images/index_05_04.jpg')";
  document.getElementById(obj6).style.backgroundImage= "url('" + defaulturl + "/Shopping/images/index_05_04.jpg')";
  document.getElementById(obj7).className= "green";
  document.getElementById(obj8).className= "black_2";
  document.getElementById(obj9).className= "black_2";
 

}

function showjLayer(obj1,obj2,obj4,obj5,obj7,obj8)
{
 document.getElementById(obj1).style.display="";   

  document.getElementById(obj2).style.display="none";   

  document.getElementById(obj4).style.backgroundImage= "url('" + defaulturl + "/Shopping/images/ad_cen_13.jpg')";
  document.getElementById(obj5).style.backgroundImage=  "url('" + defaulturl + "/Shopping/images/ad_cen_12.jpg')";

  document.getElementById(obj7).className= "orange";
  document.getElementById(obj8).className= "black_2";

}
function showGigtLayer(obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj8)
{
 document.getElementById(obj1).style.display="";   

 document.getElementById(obj2).style.display="none";   
 document.getElementById(obj3).style.display="none";   
 document.getElementById(obj4).style.display="none";   

  if(obj1=="divlh")
  {
    document.getElementById(obj5).src= defaulturl + "/Shopping/images/cen_14_02"+imageEx+".jpg";
    document.getElementById(obj6).src=  defaulturl + "/Shopping/images/cen_15"+imageEx+".jpg";
     document.getElementById(obj7).src=  defaulturl + "/Shopping/images/cen_16"+imageEx+".jpg";
      document.getElementById(obj8).src=  defaulturl + "/Shopping/images/cen_17"+imageEx+".jpg";
  }
  else if(obj1=="divxr")
  {
   document.getElementById(obj5).src= defaulturl + "/Shopping/images/cen_15_02"+imageEx+".jpg";
   document.getElementById(obj6).src=  defaulturl + "/Shopping/images/cen_14"+imageEx+".jpg";
   document.getElementById(obj7).src=  defaulturl + "/Shopping/images/cen_16"+imageEx+".jpg";
   document.getElementById(obj8).src=  defaulturl + "/Shopping/images/cen_17"+imageEx+".jpg";
  }
   else if(obj1=="divegg")
  {
   document.getElementById(obj5).src= defaulturl + "/Shopping/images/cen_16_02"+imageEx+".jpg";
   document.getElementById(obj6).src=  defaulturl + "/Shopping/images/cen_15"+imageEx+".jpg";
   document.getElementById(obj7).src=  defaulturl + "/Shopping/images/cen_14"+imageEx+".jpg";
   document.getElementById(obj8).src=  defaulturl + "/Shopping/images/cen_17"+imageEx+".jpg";
  }
    else if(obj1=="divcow")
  {
   document.getElementById(obj5).src= defaulturl + "/Shopping/images/cen_17_02"+imageEx+".jpg";
     document.getElementById(obj6).src=  defaulturl + "/Shopping/images/cen_15"+imageEx+".jpg";
   document.getElementById(obj7).src=  defaulturl + "/Shopping/images/cen_16"+imageEx+".jpg";
   document.getElementById(obj8).src=  defaulturl + "/Shopping/images/cen_14"+imageEx+".jpg";
  }
}
