 function _xmlLoader( oSender, ofResult, fsTarget, bDisable ){
		//oSender : Who call the function, this function will change the sender's cursor to wait.
		//ofResult : Display result object or execute result function.
		//fsTarget : Form or target URL string.
		//bDisable : True or false. only for fsTarget is Form.
		//if( Number( ScriptEngineMajorVersion( ) + '.' + ScriptEngineMinorVersion( ) ) >= 5.5 ){
			if( ofResult && fsTarget ){
				
				var strAction = typeof( fsTarget ) == 'string' ? fsTarget : fsTarget.action;
				var strMethod = typeof( fsTarget ) == 'string' ? 'GET' : fsTarget.method;
				
				if( strAction != '' ){
					
					var objXML = AJAX_create( _stateChanged );
					if( objXML != null ){
						
						AJAX_changeCursor( 'Wait' );
						AJAX_showMessage( ofResult, '<img src="../images/load.gif" />',0);
						
						var strSendData = '';
						if( typeof( fsTarget ) != 'string' ){
							strSendData = AJAX_getFormData( fsTarget, bDisable );
						};
						
						var x = new Date;
						if( strSendData != '' ){
							strSendData += '&';
						};
						strSendData += 'Time=' + x.getTime().toString();
						x = null;
						if( strMethod.toLowerCase() == 'get' ){
							if( strAction.indexOf( '?' ) != -1 ){
								strAction += '&' + strSendData;
							}else{
								strAction += '?' + strSendData;
							};
						};

						objXML.open( strMethod, strAction, true );
						AJAX_setHeader( objXML, strMethod, strSendData );
						setTimeout( _sentData, 50 );
						
					}else{
						objXML = null;
						AJAX_showMessage( ofResult, 'Browser not supported or Scripting for ActiveX might be disabled.');
					};
				}else{
					strAction = null;
					strMethod = null;
					AJAX_showMessage( ofResult, 'No target URL');
				};
			}else{
				AJAX_showMessage( ofResult, 'Invalid property assignment.');
			};
		//}else{
		//	AJAX_showMessage( ofResult, 'Require JScript 5.5 or higher versions.', 1 );
		//};
		//**************************************************
		function _sentData( ){
			if( strMethod.toLowerCase() == 'post' ){
				try{ objXML.send( strSendData ); }catch(e){};
			}else{
				try{ objXML.send( null ); }catch(e){};
			};
		};
		//**************************************************
		function _stateChanged( ){
			
			/* 
				Ray 1/16/2007 ,
			*/

			setTimeout(function(){
									if(objXML!==null){
										try{
											objXML.abort();
											objXML = null;
										}catch(e){};
										AJAX_changeCursor( '' );
										AJAX_showMessage( ofResult,'Server is busy, Please try again later or refresh this page.');
									}
								},
			AJAX_MAX_WAIT_TIME);

			
			if ( objXML.readyState == 4 || objXML.readyState == 'complete' ){
				
				
				//  handle status 
				if( objXML.status == 200 ){
					if( typeof( fsTarget ) != 'string' && bDisable == false ){
						AJAX_disableForm( fsTarget );
					};
					_showResult( );
				}else{
					//Old
					///AJAX_showMessage( ofResult, 'Fail to retrieve the XML data : ' + objXML.statusText + '.', 1 );
					///AJAX_showMessage( ofResult, objXML.responseText, 2 );
					AJAX_showMessage(ofResult,objXML);
				};
				

				strAction = null;
				strMethod = null;
				objXML = null;
				strSendData = null;
				AJAX_changeCursor( '' );
			}
		};
		//**************************************************
		function _showResult( ){
			if( objXML.getResponseHeader('Content-Type').toLowerCase().indexOf( 'text/xml' ) == -1 ){
				AJAX_showMessage( ofResult, 'The \'Content-Type\' of target file must be \'text/xml\' format.');
				AJAX_showMessage( ofResult, objXML.responseText );
			}else{
				var xmlDoc = objXML.responseXML;
				var xmlResult = null;
				try{
					xmlResult = xmlDoc.getElementsByTagName('Result');
				}catch(e){};
				
				if( xmlResult == null || xmlResult.length == 0 ){
					AJAX_showMessage( ofResult, 'The XML tags does not match. Please correct the error and try again.');
					AJAX_showMessage( ofResult, objXML.responseText);
				}else{
					try{
						_runScript( xmlResult[0].getElementsByTagName('InitialScript') );
					}catch(e){
						alert( 'XML \'InitialScript\' section error!' );
					};
					//#Ray 7/13/2006
					//check error first only for checkAccess.php and checkLogin.php;
					//---------------
					var intGlobalErrorCode = 0;
					var intSessionId	  =  0;
					var strRedirectPage    = "";
					var xmlGlobalErrorMessage = null;
					try{
						xmlGlobalErrorMessage = xmlResult[0].getElementsByTagName('GlobalErrorMessage');
					}catch(e){
						alert( 'XML\' GlobalErrorMessage \' section error!');
					}
					if( xmlGlobalErrorMessage!=null){
						if( xmlGlobalErrorMessage.length > 0 ){
							intGlobalErrorCode = xmlGlobalErrorMessage[0].getElementsByTagName('ErrorCode')[0].firstChild.nodeValue;

							strRedirectPage    = xmlGlobalErrorMessage[0].getElementsByTagName('RedirectPage')[0].firstChild.nodeValue;
							try{
								intSessionId = xmlGlobalErrorMessage[0].getElementsByTagName('SessionId')[0].firstChild.nodeValue;
							}catch(e){}
							if(intGlobalErrorCode < 0){
								strRedirectPage+="?ErrorCode="+intGlobalErrorCode
								if(intSessionId != 0){
									//--redirect to pbs.php
									strRedirectPage+="&SID="+intSessionId;
								}

								//--redirect
								location.href=strRedirectPage;
								return false;
							}
						}
					}
					//---------------

					var xmlDisplay = xmlResult[0].getElementsByTagName('Display');
					if( typeof( ofResult ) == 'function' ){
						try{
							
							//if( oSender.className == 'cssMainMenuSelected' || oSender.className == 'cssSubMenuSelected' ){
							if(oSender.objType=="menu"){
								ofResult( oSender, xmlDisplay );
							}else{
								ofResult( xmlDisplay );
							};
							
						}catch(e){
							alert( 'XML loader execute JavaScript function error!' );
							alert( e.message );
						};
					}else{
						if( xmlDisplay.length > 0 ){
							var xmlHTML = xmlDisplay[0].getElementsByTagName('HTML');
							if( xmlHTML.length > 0 ){
								try{
									
									var htmlResult = new String;
									if( window.XMLSerializer ){
										//Firefox
										var xmlSerializer = new XMLSerializer();
										htmlResult = xmlSerializer.serializeToString( xmlHTML[0] );
									}else{
										//IE
										htmlResult = xmlHTML[0].xml;
									};
									htmlResult = htmlResult.substr( 6, htmlResult.length - 13 );
									ofResult.innerHTML = htmlResult;
									
									//if( xmlHTML[0].firstChild.nodeValue != '' ){
									//	ofResult.innerHTML += xmlHTML[i].firstChild.nodeValue;
									//};
									htmlResult = null;
									
								}catch(e){
									AJAX_showMessage( ofResult, 'The HTML tag is empty, Please correct the HTML tag and try again.');
								};
							}else{
								AJAX_showMessage( ofResult, 'The XML result doesn\'t have HTML tag to display, Please correct the XML tag and try again.');
							};
						};
					};
					xmlDisplay = null;
					
					try{
						_runScript( xmlResult[0].getElementsByTagName('LoadedScript') );
					}catch(e){
						alert( 'XML \'LoadedScript\' section error!' );
					};
				};
				xmlDoc = null;
				xmlResult = null;
			};
			//**************************************************
			function _runScript( xmlScript ){
				if( xmlScript.length > 0 ){
					var i;
					//not work for FireFox
					//var execScriptXML = xmlScript[0].getElementsByTagName('execScript');
					//for( i = 0; i < execScriptXML.length; i++ ){
					//	if( execScriptXML[i].firstChild.nodeValue != '' ){
					//		execScript( execScriptXML[i].firstChild.nodeValue );
					//	};
					//};
					var evalXML = xmlScript[0].getElementsByTagName('eval');
					for( i = 0; i < evalXML.length; i++ ){
						//if( evalXML[i].firstChild.nodeValue != '' ){
							eval( evalXML[i].firstChild.nodeValue );
						//};
					};
					i = null;
					evalXML = null;
				};
			};
			//**************************************************
		};
		//**************************************************
	};
	//**************************************************

/****************************************************************************************/
/*                                       HTML                                           */
/****************************************************************************************/
	
	function _htmlLoader( oSender, ofResult, fsTarget, bDisable, objLoading ){
		//oSender : Who call the function, this function will change the sender's cursor to wait.
		//ofResult : Display result object or execute result function.
		//fsTarget : Form or target URL string.
		//bDisable : True or false. only for fsTarget is Form.
		
		//if( Number( ScriptEngineMajorVersion( ) + '.' + ScriptEngineMinorVersion( ) ) >= 5.5 ){

			if( ofResult && fsTarget ){
				
				var strAction = typeof( fsTarget ) == 'string' ? fsTarget : fsTarget.action;
				var strMethod = typeof( fsTarget ) == 'string' ? 'GET' : fsTarget.method;
				
				if( strAction != '' ){
					
					var objXML = AJAX_create( _stateChanged );
              
					if( objXML != null ){

						AJAX_changeCursor( 'Wait' );
						if( objLoading )
						AJAX_showMessage( objLoading , 'Loading....',0);

						var strSendData = '';

						if( typeof( fsTarget ) != 'string' ){
							strSendData = AJAX_getFormData( fsTarget, bDisable );
						};

						var x = new Date;
						if( strSendData != '' ){
							strSendData += '&';
						};
						strSendData += 'Time=' + x.getTime().toString();
						x = null;
						if( strMethod.toLowerCase() == 'get' ){
							if( strAction.indexOf( '?' ) != -1 ){
								strAction += '&' + strSendData;
							}else{
								strAction += '?' + strSendData;
							};
						};

						objXML.open( strMethod, strAction, true );
						AJAX_setHeader( objXML, strMethod, strSendData );
						setTimeout( _sentData, 50 );

					}else{
						objXML = null;
						AJAX_showMessage( ofResult, 'Browser not supported or Scripting for ActiveX might be disabled.');
					};
				}else{
					strAction = null;http://www.octagate.com/service/SiteTimer/?Target=AJAX
					strMethod = null;
					AJAX_showMessage( ofResult, 'No target URL');
				};
			}else{
				AJAX_showMessage( ofResult, 'Invalid property assignment.');
			};
		//}else{
		//	AJAX_showMessage( ofResult, 'Require JScript 5.5 or higher versions.', 1 );
		//};
		//**************************************************
		function _sentData( ){
			if( strMethod.toLowerCase() == 'post' ){
				try{ objXML.send( strSendData ); }catch(e){};
			}else{
				try{ objXML.send( null ); }catch(e){};
			};
		};
		//**************************************************
		function _stateChanged(){
			
			/* 
				Ray 1/16/2007 ,
			*/

			setTimeout(function(){
						if(objXML!==null){
							try{
								objXML.abort();
								objXML = null;
							}catch(e){};
							AJAX_changeCursor( '' );
							AJAX_showMessage( ofResult,'Server is busy, Please try again later or refresh this page.');
						}
					},
			AJAX_MAX_WAIT_TIME);

			if ( objXML.readyState == 4 || objXML.readyState == 'complete' ){

				if( objXML.status == 200 ){
					if( typeof( fsTarget ) != 'string' && bDisable == false ){
						AJAX_disableForm( fsTarget );
					};
					_showResult( );
				}else{

					/// Old
					//AJAX_showMessage( ofResult, 'Fail to retrieve HTML data : ' + objXML.statusText + '.', 1);
					//AJAX_showMessage( ofResult, objXML.responseText, 2 );

					AJAX_showMessage(ofResult,objXML);
				};

				strAction = null;
				strMethod = null;
				objXML = null;
				strSendData = null;
				AJAX_changeCursor( '' );
			}
		};
		//**************************************************
		function _showResult( ){
			var xmlText = objXML.responseText;
			if( typeof( ofResult ) == 'function' ){
				try{
					ofResult( xmlText );
				}catch (e){
					alert(ofResult);
				};
			}else{
				ofResult.innerHTML = xmlText;
			}
		};
		//**************************************************
	};
	//**************************************************

/****************************************************************************************/
/*                             SHARED FUNCTIONS                                         */
/****************************************************************************************/
	function AJAX_create( handler ){

		var objResult = null;
		if ( navigator.userAgent.indexOf( 'Opera' ) >= 0 ){
			//
		}else if ( navigator.userAgent.indexOf( 'MSIE' ) >= 0 ){
			
			if( window.ActiveXObject ){
				var MSXML = new Array( 'MSXML3.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' );
				for( var n = 0; n < MSXML.length; n++ ){
					try{
						objResult = new ActiveXObject( MSXML[n] );
						objResult.onreadystatechange = handler;
						break;
					}catch(e){};
				};
				MSXML = null;
				n = null;
			};
		}else if ( navigator.userAgent.indexOf( 'Mozilla' ) >= 0 ){
			
			objResult = new XMLHttpRequest();
			objResult.onload = handler;
			objResult.onerror = handler;
		};
		return objResult;
	};
	//**************************************************
	function AJAX_setHeader( objAJAX, strMethod, strData ){

		objAJAX.setRequestHeader( 'Cache-Control', 'no-cache' );
		//objAJAX.setRequestHeader( 'Content-Type','text/html, charset=utf-8' );

		//--  Ray, cancel header close -- 4/24/2007
		//objAJAX.setRequestHeader( 'Connection', 'close' ); // Connection is to be closed after transfer

		//objAJAX.setRequestHeader( 'Connection', 'Keep-Alive' );
		//objAJAX.setRequestHeader( 'Pragma', 'no-cache' );
		//objAJAX.setRequestHeader( 'Expires', 'Wed, 26 Oct 2005 10:10:00 GMT' );//x.toUTCString() );//'Sat, 1 Jan 2005 05:00:00 GMT' );
		//objAJAX.setRequestHeader( 'Last-Modified', 'Wed, 26 Oct 2005 10:10:00 GMT' );//x.toUTCString() );//'Sat, 1 Jan 2005 05:00:00 GMT' );

		if( strMethod.toLowerCase() == 'post' ){
			objAJAX.setRequestHeader( 'Content-Length', strData.length );
			objAJAX.setRequestHeader( 'CONTENT-TYPE','application/x-www-form-urlencoded' );
		};

		//objAJAX.setRequestHeader( 'Cookie', 'MyCookie=Value' );
		//objAJAX.setRequestHeader( 'Host', 'MyHostName' );
		//objAJAX.setRequestHeader( 'Referer', 'http://website/path/filename' );
		objAJAX.setRequestHeader( 'User-Agent', navigator.userAgent + ' (IISIC XML Loader)' );

	};
	//**************************************************
	function AJAX_disableForm( objForm ){
		for( var i = 0; i < objForm.elements.length; i++ ){
			switch ( objForm.elements[i].type ){
				case 'reset':
				case 'button':
				case 'submit':
					try{ objForm.elements[i].disabled = false; }catch(e){};
					break;
				default:
					break;
			};
		};
	};
	//**************************************************
	function AJAX_getFormData( objForm, blnDisableButton ){
		var strResult = '';
		for( var i = 0; i < objForm.elements.length; i++ ){
			
			/// Ray 11/2/2006
			if(objForm.elements[i].type){
				switch ( objForm.elements[i].type ){
					case 'select-multiple':
						if( objForm.elements[i].name != '' ){
							for( var j = 0; j < objForm.elements[i].length; j++ ){
								if( objForm.elements[i].options[j].selected == true ){
									if( strResult != '' ){
										strResult += '&';
									};
									strResult += objForm.elements[i].name + '=' + encodeURIComponent( objForm.elements[i].options[j].value );
								};
							};
						};
						
						break;
					case 'reset':
					case 'button':
					case 'submit':
						if( blnDisableButton != undefined ){
							objForm.elements[i].disabled = true;
						};
						
						break;
					case 'radio':
					case 'checkbox':
						if( objForm.elements[i].checked != true ){
							break;
						};
						
					case 'text':
					case 'password':
					case 'textarea':
					case 'select-one':
					
					default:
						
						if( objForm.elements[i].name != '' ){
							if( strResult != '' ){
								strResult += '&';
							};
							strResult += objForm.elements[i].name + '=' + encodeURIComponent( objForm.elements[i].value );
						};
				};
			}
		};
		i = null;
		
		return strResult;
	};
	//**************************************************
	
	function AJAX_showMessage(objResult,objXMLorString,intOption){
		
		// intOption  : 0 ->loading...

		var booFunction = (( ! objResult || typeof( objResult ) == 'function' )?true:false);
		var strMSG = '';
		
		switch (typeof(objXMLorString)){
			// ----------------
			case 'object':

				if(objXMLorString!=null){
					switch(objXMLorString.status){
						// -----------------
						case 0:
							// on IE , avoid alert twice warning
							break;
						case 400:
							strMSG = ' Bad Request ( Http Status :'+objXMLorString.status+').';
							break;
						case 401:
							strMSG =' Unauthorized ( Http Status :'+objXMLorString.status+').';
							break;
						case 404:
							strMSG = ' Not Found ( Http Status :'+objXMLorString.status+').';
							break;
						case 405:
							strMSG = ' Method Not Allowed ( Http Status :'+objXMLorString.status+').';
							break;
						case 406:
							strMSG = ' Not Acceptable ( Http Status :'+objXMLorString.status+').';
							break;
						case 407:
							strMSG = ' Proxy Authentication Required( Http Status :'+objXMLorString.status+').';
							break;
						case 408:
							strMSG = 'Request Timeout ( Http Status :'+objXMLorString.status+').';
							break;
						// -----------------
						case 12003:	// IE only
						case 12029: 
						case 12030: 
						case 12031: 
						case 12152: 
						case 12159:
						default:
							if(objXMLorString.status){
								strMSG = 'Server is busy now. (Http Status :'+objXMLorString.status+').';
							}
						// -----------------
					}
				}else{
					// Check readystatus only
					strMSG = 'Server is busy, Please try again later.';
				}
				
				break;
			// ----------------
			case 'string':
				strMSG = objXMLorString;
				break;
		}
		// -------------------
		// Handle error message output
		if(strMSG){
			if(booFunction){
				if(intOption!=0){
					alert(strMSG);
				}
			}else{
				objResult.innerHTML = '<B style="color:red">'+strMSG+'<B>'
			}
		}
		// -------------------
	}
	function AJAX_encodeText( strText ){
		return strText.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace( /\n/g, '<BR/>').replace(/ /g, '&nbsp;').replace( /\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
	};
	//**************************************************
	function AJAX_changeCursor( strCursor ){
		document.body.style.cursor = strCursor;
	};
	//**************************************************
	
	function _getDisplayPanel( objSender ){

		if( objSender.className == 'CSS_DisplayPanel' ){

				return objSender;

		}else{

				return _getDisplayPanel( objSender.parentNode );

		}
	};

	
	function _getElementById( objParentNode, strTagName, strId ){

		var resultObj = null;

		var tmpObj = objParentNode.getElementsByTagName(strTagName);

		for( var i = 0; i < tmpObj.length; i++ ){

			if( tmpObj[i].id == strId ){

				resultObj = tmpObj[i];

				break;

			};
		};
	
		tmpObj = null;

		return resultObj;

	};
