
	//@cc_on
	//@set @debug = false

	//	by andrew wu, dec 26, 2001
	//
	//	common code library. only function definition was allowed.
	//	any global code, global variable is not available in this area.
	//
	function sprintf(sPattern) {
		if (sPattern == null) return null;
		var array = sPattern.toString().split("%s");
		var sOutput = array[0];
		for(var nIndex = 1; nIndex < array.length && nIndex < arguments.length; nIndex++) {
			sOutput += (arguments[nIndex] + array[nIndex]);
		}
		return sOutput;
	}

	// print formatting string output.
	// equal to Response.Write(sprintf(params...));
	function printf(sPattern) {
		if (sPattern == null) return;
		var array = sPattern.toString().split("%s");
		var sOutput = array[0];
		for(var nIndex = 1; nIndex < array.length && nIndex < arguments.length; nIndex++) {
			sOutput += (arguments[nIndex] + array[nIndex]);
		}
		alert(sOutput);
	}



	//@if(@debug)
	var _div = null;
	//@end
	function trace(sPattern, sPrompt, bIsPopup) {
		//@if(@debug)
		if (bIsPopup == null) bIsPopup = false;
		if (sPrompt == null) sPrompt = "trace-message";
		
		if (bIsPopup) {
			printf("%s(%s)", sPrompt, sPattern);
		}
		
		// init debug area
		if (_div == null) {
			if (document.all.debugArea == null) {
				_div = document.createElement('div');
				_div.innerHTML = '<div style="color:#d0d0d0; background-color:#606060;">Debug Message (client side):</div>';
				_div.style.background = '#ffffff';
				_div.style.borderStyle = "solid";
				_div.style.borderColor = "#B0B0B0";
				document.body.appendChild(_div);
				_div1 = document.createElement('div');
				_div1.id="debugArea";
				_div.appendChild(_div1);
			} 
		}else {
				_div1 = document.all.debugArea;
			}
		var _prompt		= document.createElement('b');
		var _message	= document.createElement('span');
		var _br			= document.createElement('br');
		
		_prompt.innerText = sPrompt + ": ";
		_message.innerText = sPattern;
		_message.style.color = '#880000';
		_message.noWrap = true;
		
		_div1.appendChild(_prompt);
		_div1.appendChild(_message);
		_div1.appendChild(_br);		
		//@end
	}

	function clrDebugArea(){
		if(document.all.debugArea){
			document.all.debugArea.innerHTML="";
		}
	}

	function assert(bCondition, sComment, bIsError) {
		//@if(@debug)
		if (sComment == null) sComment = "assert occur.";
		if (bIsError == null) bIsError = true;
		
		if (bCondition == false) {
			trace(sComment, "assert");

			if (bIsError == true) {
				var e = new Error(null, sprintf("assert: %s", sComment));

				e.name = "assert";
				e.number = 0;
				e.message = sprintf("assert: %s", sComment);

				throw e;
			}
		}
		//@end
	}
	
	var _checkPointCount = 0;
	function checkPoint(sPrompt) {
		if (_checkPointCount == null || isNaN(_checkPointCount) == true) {
			_checkPointCount = 0;
		}
		_checkPointCount++;
		trace(
			"check point at: " + (new Date()).toString(), 
			sprintf("check-point[ %s ]", (sPrompt == null)?(_checkPointCount):(sPrompt)));
	}

	function IsDebugMode() {
		//@if(@debug)
			return true;
		//@else
			return false;
		//@end
	}



	function GetXslProcessor(xslSrc) {
		var oXslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0");
		oXslDoc.async = false;
		
		if (typeof(xslSrc) == "string") {
			oXslDoc.load(xslSrc);
		} else {
			oXslDoc.loadXML(xslSrc.xml);
		}
		
		var oXslTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0");
		oXslTemplate.stylesheet = oXslDoc;
		
		return oXslTemplate.createProcessor();
	}


	///
	/// formatting number to text.
	///
	function FixDigit(nNumber, nDigits) {
		var str = (nNumber + Math.pow(10, nDigits)).toString();
		return str.substr(str.length - nDigits);
	}
	
	function ToFormatDate(oDate) {
		//var oDate = new Date();
		return sprintf("%s-%s-%s", FixDigit(oDate.getFullYear(), 4), FixDigit(oDate.getMonth() + 1, 2), FixDigit(oDate.getDate(), 2));
	}

	function FromFormatDate(sDate) {
		var strList = sDate.split('-', 3);
		var nFullYear = parseInt(strList[0]);
		var nMonth = parseInt(strList[1]);
		var nDay = parseInt(strList[2]);

		return new Date(nFullYear, nMonth - 1, nDay);
	}
	
	function GetRootVDir() {
		return "/";
	}
	
	function GetRootURL() {
		return "http://training.evta.gov.tw/";
	}
	
	
	
	function IsLogin() {
		return false;
	}
	
	function GetCurrentUserPrimaryKey() {
		return 2;
	}
	
	function GetCurrentUserID() {
		return "GUEST";
	}
	
	function GetCurrentTicket() {
		return "";
	}
	
	function GetCurrentStyle() {
		return "3";
	}
	
	
	
	
	

	///	by dino liu, oct 2, 2002
	///   2003/9/1 update by dino liu
	/// <summary>
	///   same as trim() in VBScript, remove preceding and retral empty space
	///     when string type is "undefined", return ""
	/// </summary>
	/// <param name="a_sInputStr">input string</param>
	/// <returns>string after operation</returns>
	/// <example>
	///   trim(" abc ") = "abc"
	/// </example>
	/// <remarks>
	/// </remarks>
	function trim(a_sInputStr) {
		if ("string" == typeof(a_sInputStr)) {
			return a_sInputStr.replace(/^\s+|\s+$/g,"");
		}

		if (null == a_sInputStr) return "";
		if ("undefined" == typeof(a_sInputStr)) return "";

		if ("object" == typeof(a_sInputStr)) {
			return String(a_sInputStr).replace(/^\s+|\s+$/g,"");
		} else {
			return a_sInputStr.toString().replace(/^\s+|\s+$/g,"");
		}
	} // function trim

	function trimOld(a_sInputStr) {
		var l_oRe01 = new RegExp("^[ ]+"); // ltrim(), remove preceding empty space
		var l_oRe02 = new RegExp("[ ]+$"); // rtrim(), remove retral empty space
		var l_sStr; // temp string for operation

		if (null == a_sInputStr) return "";
		if ("undefined" == typeof(a_sInputStr)) return "";
		if ("object" == typeof(a_sInputStr)) {
			l_sStr = String(a_sInputStr);
		} else {
			l_sStr = a_sInputStr;
		}
		l_sStr = l_sStr.replace(l_oRe01,"");
		l_sStr = l_sStr.replace(l_oRe02,"");
//		trace(a_sInputStr,"original string",true);
//		trace(l_sStr,"converted string",true);

		return l_sStr;
	} // function trim


	function ResetDocumentDomain() {
	    //
	    //  make sure this API do not be called twice or more.
	    //
	    //assert(window._ResetDocumentDomainInvokeFlag == true, "ResetDocumentDomain() API was called more than one times.");
	    if (window._ResetDocumentDomainInvokeFlag == true) {
            if (IsDebugMode() == true) {
                alert("DEBUG: ResetDocumentDomain() API was called more than one times.");
            }
	        return;
	    }
        window._ResetDocumentDomainInvokeFlag = true;


//
//		disabled. turn on if CDS / LMS are installed at different host.
//
		return false;

	}
	
	
	function GetDocumentDomain() {
	    var specifiedDocDomain = "";

	
		var segments = document.domain.split(".");

		if (segments.length <= 2) {
			//
			//	domain level must more than 2.
			//
			return null;
		}
		
		var bIsIPAddress = true;
		for (var nPos = 0; nPos < segments.length; nPos++) {
			if (isNaN() == true) {
				bIsIPAddress = false;
			}
		}
		
		if (bIsIPAddress == true) {
			//
			//	domain must be FQDN (www.learningdigital.com), not numeric ip address (xxx.xxx.xxx.xxx)
			//
			return null;
		}

		
		
		if (specifiedDocDomain != null && specifiedDocDomain != "" && document.domain.toLowerCase().indexOf(specifiedDocDomain.toLowerCase()) >= 0) {
		    return specifiedDocDomain;
		}
		
		
		var sParentFQDN = "";
		for (var nPos = 1; nPos < segments.length; nPos++) {
			if (nPos == 1) {
				//
				//	first segment, without prefix "."
				//
				sParentFQDN += segments[nPos];
			} else {
				sParentFQDN += "." + segments[nPos];
			}
		}				

		return sParentFQDN;
	}




	function help(nHelpID) {
		window.showHelp(sprintf("%s_help/LDHELP-%s.html", GetRootVDir(), (10000000000 + nHelpID).toString().substring(1)));
	}


	function hideWaitProcess() {
		if (document.all.waitProcImage != null) {
			//alert(document.all.waitProcImage.innerHTML);
			document.all.waitProcImage.removeNode(true);
		}
	}
	
	function waitProcess(sMode, sMessage, sAnimPath, nWidth, nHeight) {
		//debugger;
		if (sMessage == null) {
			//
			//	plain text.
			//
			sMessage = "please wait...";
		}
		if (sMode == null) {
			//
			//	available mode: flash / gif
			//
			sMode = "flash";
		}
		if (sAnimPath == null && sMode == "flash") {
			sAnimPath = "image/wait_anim.swf";
		}
		if (sAnimPath == null && sMode == "gif") {
			sAnimPath = "image/wait_anim.gif";
		}
		
		if (document.all.waitProcImage != null) {
			hideWaitProcess();
		}
		
		var oDIV = document.createElement("div");
		
		oDIV.setAttribute("id", "waitProcImage");
		
		switch(sMode) {
			case "gif":
				if (nWidth == null) nWidth = 185;
				if (nHeight == null) nHeight = 94;

				var oImg = document.createElement("img");
			
				oImg.setAttribute("alt", sMessage);
				oImg.setAttribute("src", GetRootVDir() + sAnimPath);
		
				oDIV.appendChild(oImg);
				break;

			case "flash":
			default:
				if (nWidth == null) nWidth = 230;
				if (nHeight == null) nHeight = 102;

				var oFlash = document.createElement("object");
				
				//oFlash.setAttribute("id", "waitProcImage");
				oFlash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
				oFlash.setAttribute("codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0");
				
				oFlash.movie = GetRootURL() + sAnimPath;
				oFlash.width = nWidth;
				oFlash.height = nHeight;
				
				oDIV.appendChild(oFlash);
				break;
		}
		
		
		oDIV.style.position = "absolute";
		oDIV.style.pixelLeft = (document.body.clientWidth - nWidth) / 2;
		oDIV.style.pixelTop = (document.body.clientHeight - nHeight) / 2;
	
		trace(oDIV.outerHTML);
	
		document.body.appendChild(oDIV);
	}


	//
	//	bind function(s) to window object.
	//
	//@if (@debug == true)
	if (document.debug == null) {
		document.debug = new Array();
		document.debug.trace = trace;
		document.debug.assert = assert;
	}
	//@end
