/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This JavaScript file is a part of the DynaHelp Site Integration SDK
// 
// Copyright (C) 2000, eHelp Corporation. All rights reserved.
// 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
// The code contained in this file will assist you in integrating 
// DynaHelp onto your web site.  These functions all essentially
// invoke DynaHelp.
//

// Displaying DynaHelp
//
// There are three ways of displaying DynaHelp; in a new browser window, in an
// existing or embedded frame and in a popup window. The new window model displays 
// DynaHelp in a newly created browser window.  The embedded model displays DynaHelp 
// in an existing frame (default is self).  The popup model displays DynaHelp in a 
// small popup window with a decorated edge.  The popup model is only available to 
// IE4 and better (others see a newly created browser window).
//
// To display DynaHelp in a new window, use the plain function calls
// To display DynaHelp embedded, use the xxxEmbedded function calls
// To display DynaHelp in a popup window, use the xxxPopup function calls
//

// Invoking DynaHelp
//
// There are two methods of invoking DynaHelp; with a context id and by specifying a url.
// If you use a context id, the target of that id can be dynamically changed at runtime
// using DynaHelp Author.  This is the recommended method for accessing Help topics.
// Invoking DynaHelp using a standard url allows you to view any content within the
// DynaHelp customer assistance center.   The url method is static, however, and these
// links cannot be changed without changing the call.
//
// To invoke DynaHelp using a context id, use the DynaHelpContext calls
// To invoke DynaHelp using a standard url, use the DynaHelpUrl calls
//

// Argument Description:
// 
// strServer		- The DNS of your DynaHelp server (ie: 'www.help.com').  This is the only
//                    required parameter to any call.
// strContextId		- The context id.  Should describe where on your site the link is.
//					  (ie: 'Shipping_Form')
// strURL			- Any url that you want displayed in the DynaHelp frame.
// strFrameName		- The name of the frame to display DynaHelp in.
// strWindowId		- The name of the DynaHelp window to be displayed.  These are authored
//                    by DynaHelp Author.
// strTransactionID - You can pass DynaHelp a transaction ID that it will use to track this 
//      			  request with.
// strSessionID		- You can pass DynaHelp a session ID that it will use to track this 
//      			  request with.
// strCustomerID	- You can pass DynaHelp a customer ID that it will use to track this 
//      			  request with.
// strAppData		- You can pass DynaHelp some custom data that it will use to track this 
//      			  request with.
//

// Function Prototypes:
//
// DynaHelpContext( strServer, 
//					strContextID, 
//					strTransactionID, 
//					strSessionID, 
//					strCustomerID, 
//					strAppData );
// 
// DynaHelpContextEmbedded( strServer, 
//							strContextID, 
//							strFrameName, 
//							strTransactionID, 
//							strSessionID, 
//							strCustomerID, 
//							strAppData );
// 
// DynaHelpContextPopup( strServer, 
//						 strContextID, 
//						 nWidth, 
//						 nHeight, 
//						 strTransactionID, 
//						 strSessionID, 
//						 strCustomerID, 
//						 strAppData );
// 
// DynaHelpURL( strServer, 
//			      	  strURL, 
//				  strWindowID, 
//				  strTransactionID, 
//				  strSessionID, 
//				  strCustomerID, 
//				  strAppData );
// 
// DynaHelpURLEmbedded( strServer, 
//						  strURL, 
//						  strFrameName, 
//						  strWindowID, 
//						  strTransactionID, 
//						  strSessionID, 
//						  strCustomerID, 
//						  strAppData );
// 
// DynaHelpURLPopup( strServer, 
//					   strURL, 
//					   strWindowID, 
//					   nWidth, 
//					   nHeight, 
//					   strTransactionID, 
//					   strSessionID, 
//					   strCustomerID, 
//					   strAppData );
// 
// 
// DynaHelpAsk( strServer, strQuestion, strTemplate,
//				  strWindowID, 
//				  strTransactionID, 
//				  strSessionID, 
//				  strCustomerID, 
//				  strAppData );
// 
// DynaHelpAskEmbedded( strServer, strQuestion, strTemplate,
//						  strFrameName, 
//						  strWindowID, 
//						  strTransactionID, 
//						  strSessionID, 
//						  strCustomerID, 
//						  strAppData );
// 
// DynaHelpAskPopup( strServer, strQuestion, strTemplate,
//					   strWindowID, 
//					   nWidth, 
//					   nHeight, 
//					   strTransactionID, 
//					   strSessionID, 
//					   strCustomerID, 
//					   strAppData );
//
// DynaHelpLive( strServer, strQuestion, strQueue, 
//					   strTemplate, strWindowID, 
//					   strTransactionID, strSessionID, 
//					   strCustomerID, strAppData );
//
// DynaHelpLiveEmbedded( strServer, strQuestion, strQueue, 
//						   strTemplate, strFrameName, 
//						   strWindowID, strTransactionID, 
//						   strSessionID, strCustomerID, 
//						   strAppData );
//
// Function Samples:
// 
// HTML code to reference the 'DynaHelp.js' file. 
//	1, if this this script name is Dynahelp.js you need not specify name tag
//	2, don't use id="Dynahelp" if you want to support netscape;
//	3, support name="dynahelp", Name="Dynahelp", NAME="Dynahelp"
// 
//   <SCRIPT LANGUAGE="JavaScript" NAME="DynaHelp" SRC="/ScriptsPath/DynaHelp.JS"></SCRIPT>
// 
// Display DynaHelp in a new window by a context id
// 
//   <A HREF="http://www.help.com/dynahelp/dynahelp.dll?ctxid=ctx101" TARGET="_blank"
// 
// 			ONCLICK="return DynaHelpContext( 'www.help.com', 'ctx101' );">Hyperlink Text</A>
// 
// The above example demonstrates the context id call only. Please refer to the Help for more information and examples.
// 			  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// return the browser information
var c_szDynahelpJSVersion	= 'dhjs2.0.003';
var c_szURLJSVersion		= 'jsver';
var c_szURLContextID		= 'ctxid';
var c_szURLTopicID		= 'tpc';
var c_szURLWindowID		= 'wnd';
var c_szURLTransactionID	= 'tsnid';
var c_szURLCustomerID		= 'cmrid';
var c_szURLSessionID		= 'ssnid';
var c_szURLApplicationData	= 'appdata';
var c_szURLNewSession		= 'newsess';
var c_szURLReferrer		= 'refer';

var c_szURLCommand		= 'cmd';
var c_szURLCommandWindow	= 'newwnd';
var c_szURLCommandEmbedded	= 'embwnd';
var c_szURLCommandPopup		= 'popwnd';

var c_szURLRequestType		= 'rtype';
var c_szURLRequestIEIFrame	= 'iefrm';
var c_szURLRequestNSWindow	= 'nswnd';
var c_szURLStartTime		= 'stime';

var c_szURLAskResult		= 'askrlt';
var c_szURLTargetFrame		= 'frm';
var c_szURLQueue		= 'queue';
var c_szURLQuestion		= 'quesn';
var c_szURLTemplate		= 'templ';

var c_szURLManagerTag		= 'mgr';
var c_szURLManagerAgent		= 'agm';
var c_szURLAgentCur		= 'curagt';
var c_szURLAgentTag		= 'agt';
var c_szURLAgentNLS		= 'nls';
var c_szURLAgentLive		= 'live';
var c_szURLMonikerJScript	= 'js';
var c_szURLMonikerWSMTopicType	= 'tpctype';
var c_szURLMonikerWSMTopic2PaneBlank	= '2panebnk';
var c_szURLMonikerWCheckSessionCookie	= 'chkssck';
var c_szURLMonikerLiveCloseWindow = 'liveclosewnd';

function CBrowserInfo()
{
	this.m_nVersion = 0;
	this.m_bIsNetscape = false;
	this.m_bIsExplorer = false;
	this.m_bIsExplorer3 = false;
	this.m_bIsExplorer5 = false;
	this.m_bIsPrimary = false;
	this.m_bIsJavaEnabled = false;

	var strAgent = navigator.userAgent.toLowerCase();
	var nIdx = strAgent.indexOf('msie');
	if( nIdx >= 0 )
	{
		this.m_bIsExplorer = true;
		this.m_nVersion = parseInt( strAgent.substring(nIdx+5, nIdx+6) );
		this.m_bIsPrimary = this.m_nVersion >= 4 && strAgent.indexOf( 'windows' ) >= 0;	// take out the other platform
		this.m_bIsExplorer5 = this.m_nVersion >= 5;
		this.m_bIsExplorer3 = this.m_nVersion <= 3;
		if( this.m_bIsPrimary == true )
			this.m_bIsJavaEnabled = navigator.javaEnabled();
	}else
	if( navigator.appName.toLowerCase() == 'netscape' )
	{
		this.m_bIsNetscape = true;
		this.m_nVersion = parseInt(navigator.appVersion);
		this.m_bIsPrimary = this.m_nVersion >= 4;

		if( this.m_bIsPrimary == true )
			this.m_bIsJavaEnabled = navigator.javaEnalbed;
	}else
	{
		//...
	};
};
// add a new tag to url
function doEscape( strText )
{
	var strValue = escape( strText );	// stupid netscape 4.0x can not handle var1=fn(var1) correctly.
	var nPos = -1;
	while( true )
	{
		nPos = strValue.indexOf( '+' );		if( nPos < 0 )	break;
		strValue = strValue.substring( 0, nPos ) + '%2B' + strValue.substring( nPos+1, strValue.length );
	};
	return strValue;
};

function doAppendURLTag( strURL, strTag, strValue )
{
	if( strValue != null )
	{
		strURL += (strURL.indexOf( '?' ) >= 0) ? '&' : '?';
		strURL += strTag + '=' + doEscape(strValue);
	};
	return strURL;
};

function doReplace( strText, strOld, strNew )
{
	var nPos = 0;
	var nLenOld = strOld.length;
	var nLenNew = strNew.length;
	while( true )
	{
		var nPos = strText.indexOf( strOld, nPos );	if( nPos < 0 )	break;
		strText = strText.substring( 0, nPos ) + strNew + strText.substring( nPos + nLenOld, strText.length );
		nPos += nLenNew;
	};
	return strText;
};

function doGetLocation()
{
	var strRet = location.href;
	strRet = doReplace( strRet, '|/', ':/' );
	strRet = strRet.toLowerCase()
	strRet = doReplace( strRet, 'file:///', 'file://' );
	strRet = doReplace( strRet, 'file://', 'file:///' );	// the formal url
	return unescape(strRet);
};

function doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( strTransactionID != null )	strURL = doAppendURLTag( strURL, c_szURLTransactionID, strTransactionID );
	if( strSessionID != null )		strURL = doAppendURLTag( strURL, c_szURLSessionID, strSessionID );
	if( strCustomerID != null )		strURL = doAppendURLTag( strURL, c_szURLCustomerID, strCustomerID );
	if( strAppData != null )		strURL = doAppendURLTag( strURL, c_szURLApplicationData, strAppData );
	return strURL;
};
// load DynaHelp system into a popup window
function doGetSizeX( strValue )
{
	var nRet = 0;
	var bPerc = false;
	
	strValue = String(strValue);
	var nPos = strValue.indexOf( '%' );
	if( nPos >= 0 )
	{
		nRet = parseInt( strValue.substring( 0, nPos ) ); bPerc = true;
	}else
	{
		nRet = parseInt( strValue );
	};
	if( isNaN( nRet ) == true )
	{
		nRet = 50; bPerc = true;
	};
	if( bPerc == true )
	{
		var cInfo = new CBrowserInfo;
		if( cInfo.m_bIsExplorer && cInfo.m_bIsPrimary )
		{
			nRet = window.document.body.clientWidth * nRet / 100;
		}else
		{
			var nScreenWidth = (window.screen != null) ? window.screen.availWidth : 640;
			nRet = nScreenWidth * nRet / 100;
		};
	};
	return parseInt(nRet);
};

function doGetSizeY( strValue )
{
	var nRet = 0;
	var bPerc = false;
	
	strValue = String(strValue);
	var nPos = strValue.indexOf( '%' );
	if( nPos >= 0 )
	{
		nRet = parseInt( strValue.substring( 0, nPos ) ); bPerc = true;
	}else
	{
		nRet = parseInt( strValue );
	};
	if( isNaN( nRet ) == true )
	{
		nRet = 50; bPerc = true;
	};
	if( bPerc == true )
	{
		var cInfo = new CBrowserInfo;
		if( cInfo.m_bIsExplorer && cInfo.m_bIsPrimary )
		{
			nRet = window.document.body.clientHeight * nRet / 100;
		}else
		{
			var nScreenHeight = (window.screen != null) ? window.screen.availHeight : 460;
			nRet = nScreenHeight * nRet / 100;
		};
	};
	return parseInt(nRet);
};
function doCheckSupport()
{
	var bRet = true;

	var cInfo = new CBrowserInfo;
	if( cInfo.m_bIsExplorer3 == true )		// ie3 has problem with onclick in the a link, it doesn't care what the return value is
		bRet = false;
	return bRet;
};

function doResetServer( strServer )
{
	if( strServer == null || strServer == '' )
	{
		strServer = '/Dynahelp/Dynahelp.dll';
	}else
	{
		var strHttp = 'http://';
		var strHttps = 'https://';
		var nLen = strHttp.length;
		if( strServer.substring( 0, strHttp.length ).toLowerCase() != strHttp &&
		    strServer.substring( 0, strHttps.length ).toLowerCase() != strHttps )
		{
			if( location.protocol == 'https:' )	strServer = strHttps + strServer;
			else					strServer = strHttp + strServer;
		};
		nLen = strServer.length;
		if( nLen <=4 || strServer.substring(nLen-4, nLen).toLowerCase() != '.dll' )
		{
			if( strServer.substring( nLen-1, nLen ) != '/' )
				strServer += '/';
			strServer += 'DynaHelp/DynaHelp.dll';
		};
	};
	return doAppendJSVersion(strServer);
};

function doAppendJSVersion( strURL )
{
	var strRet = '';
	var strVer = c_szURLJSVersion + '=' + c_szDynahelpJSVersion;
	if( strURL.indexOf( strVer ) < 0 )
		strRet = doAppendURLTag( strURL, c_szURLJSVersion, c_szDynahelpJSVersion );
	else
		strRet = strURL;

	return strRet;
};

// load DynaHelp system into a new window
function DynaHelpContext( strServer, strContextID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var strURL = doAppendURLTag( strServer, c_szURLContextID, strContextID );
	return doDynaHelp( strURL, strTransactionID, strSessionID, strCustomerID, strAppData )
};
// load DynaHelp system into a frame
function DynaHelpContextEmbedded( strServer, strContextID, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var strURL = doAppendURLTag( strServer, c_szURLContextID, strContextID );
	return doDynaHelpEmbedded( strURL, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData );
};
// load DynaHelp system into a popup window
function DynaHelpContextPopup( strServer, strContextID, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var strURL = doAppendURLTag( strServer, c_szURLContextID, strContextID );

	return doDynaHelpPopup( strURL, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData );
};

// load DynaHelp system into a new window
function DynaHelpURL( strServer, strURL, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var str = doAppendURLTag( strServer, c_szURLTopicID, strURL );
	str = doAppendURLTag( str, c_szURLWindowID, strWindowID );
	return doDynaHelp( str, strTransactionID, strSessionID, strCustomerID, strAppData )
};
// load DynaHelp system into a frame
function DynaHelpURLEmbedded( strServer, strURL, strFrameName, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var str = doAppendURLTag( strServer, c_szURLTopicID, strURL );
	str = doAppendURLTag( str, c_szURLWindowID, strWindowID );
	return doDynaHelpEmbedded( str, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData );
};
// load DynaHelp system into a popup window
function DynaHelpURLPopup( strServer, strURL, strWindowID, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	strServer = doResetServer( strServer )
	var str = doAppendURLTag( strServer, c_szURLTopicID, strURL );
	str = doAppendURLTag( str, c_szURLWindowID, strWindowID );
	return doDynaHelpPopup( str, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData );
};

// Ask supports
function doGetAskURL( strServer, strQuestion, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	var strURL = '';
	strURL = doResetServer( strServer );
	strURL = doAppendURLTag( strURL, c_szURLManagerTag, c_szURLManagerAgent );
	strURL = doAppendURLTag( strURL, c_szURLAgentTag, c_szURLAgentNLS );
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );
	strURL = doAppendURLTag( strURL, c_szURLTemplate, strTemplate );
	strURL = doAppendURLTag( strURL, c_szURLAskResult, "1" );
	strURL = doAppendURLTag( strURL, c_szURLMonikerJScript, "1" );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );
	strURL = doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData );

	return strURL;
};
// load DynaHelp system into a new window
function DynaHelpAsk( strServer, strQuestion, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	var strNLS = doGetAskURL( strServer, strQuestion, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData );
	var strURL = doResetServer( strServer );
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );		// append the ask question
	strURL = doAppendURLTag( strURL, c_szURLAgentCur, c_szURLAgentNLS );		// append the current agent
	strURL = doAppendURLTag( strURL, c_szURLMonikerWSMTopicType, c_szURLMonikerWSMTopic2PaneBlank );	// tell wsm let the topic to be blank
	strURL = doAppendURLTag( strURL, c_szURLTopicID, strNLS );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );

	return doDynaHelp( strURL, strTransactionID, strSessionID, strCustomerID, strAppData )
};
// load DynaHelp system into a frame
function DynaHelpAskEmbedded( strServer, strQuestion, strTemplate, strFrameName, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	var strNLS = doGetAskURL( strServer, strQuestion, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData );
	var strURL = doResetServer( strServer )
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );		// append the ask question
	strURL = doAppendURLTag( strURL, c_szURLAgentCur, c_szURLAgentNLS );		// append the current agent
	strURL = doAppendURLTag( strURL, c_szURLMonikerWSMTopicType, c_szURLMonikerWSMTopic2PaneBlank );	// tell wsm let the topic to be blank
	strURL = doAppendURLTag( strURL, c_szURLTopicID, strNLS );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );

	return doDynaHelpEmbedded( strURL, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData );
};
// load DynaHelp system into a popup window
function DynaHelpAskPopup( strServer, strQuestion, strTemplate, strWindowID, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	var strNLS = doGetAskURL( strServer, strQuestion, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData );
	var strURL = doResetServer( strServer )
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );		// append the ask question
	strURL = doAppendURLTag( strURL, c_szURLAgentCur, c_szURLAgentNLS );		// append the current agent
	strURL = doAppendURLTag( strURL, c_szURLMonikerWSMTopicType, c_szURLMonikerWSMTopic2PaneBlank );	// tell wsm let the topic to be blank
	strURL = doAppendURLTag( strURL, c_szURLTopicID, strNLS );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );
	return doDynaHelpPopup( strURL, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData );
};

// Live supports
function doGetLiveURL( strServer, strQuestion, strQueue, strTemplate, strTarget, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	var strURL = '';
	strURL = doResetServer( strServer );
	strURL = doAppendURLTag( strURL, c_szURLManagerTag, c_szURLManagerAgent );
	strURL = doAppendURLTag( strURL, c_szURLAgentTag, c_szURLAgentLive );
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );
	strURL = doAppendURLTag( strURL, c_szURLQueue, strQueue );
	strURL = doAppendURLTag( strURL, c_szURLTemplate, strTemplate );
	strURL = doAppendURLTag( strURL, c_szURLTargetFrame, strTarget );
	strURL = doAppendURLTag( strURL, c_szURLMonikerJScript, "1" );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );
	strURL = doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData );

	return strURL;
};
// load DynaHelp system into a new window
function DynaHelpLive( strServer, strQuestion, strQueue, strTemplate, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	var strLive = doGetLiveURL( strServer, strQuestion, strQueue, strTemplate, '', strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData );
	strLive = doAppendURLTag( strLive, c_szURLMonikerLiveCloseWindow, "1" );	// tell the live server to close the original window

	var strURL = doResetServer( strServer );
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );
	strURL = doAppendURLTag( strURL, c_szURLQueue, strQueue );
	strURL = doAppendURLTag( strURL, c_szURLAgentCur, c_szURLAgentLive );
	strURL = doAppendURLTag( strURL, c_szURLMonikerWSMTopicType, c_szURLMonikerWSMTopic2PaneBlank );
	strURL = doAppendURLTag( strURL, c_szURLTopicID, strLive );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );

	return doDynaHelp( strURL, strTransactionID, strSessionID, strCustomerID, strAppData )
};
// load DynaHelp system into a frame
function DynaHelpLiveEmbedded( strServer, strQuestion, strQueue, strTemplate, strFrameName, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( doCheckSupport() == false  )	return true;

	var strLive = doGetLiveURL( strServer, strQuestion, strQueue, strTemplate, strFrameName, strWindowID, strTransactionID, strSessionID, strCustomerID, strAppData );
	var strURL = doResetServer( strServer );
	strURL = doAppendURLTag( strURL, c_szURLQuestion, strQuestion );
	strURL = doAppendURLTag( strURL, c_szURLQueue, strQueue );
	strURL = doAppendURLTag( strURL, c_szURLAgentCur, c_szURLAgentLive );
	strURL = doAppendURLTag( strURL, c_szURLMonikerWSMTopicType, c_szURLMonikerWSMTopic2PaneBlank );
	strURL = doAppendURLTag( strURL, c_szURLTopicID, strLive );
	strURL = doAppendURLTag( strURL, c_szURLWindowID, strWindowID );

	return doDynaHelpEmbedded( strURL, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData );
};

function doDynaHelp_BeforeUnload()
{
	var strFrmID = 'idDynaHelpFrame';
	var eFrm = document.all(strFrmID);
	if( eFrm != null )
	{
		var eDiv = eFrm.parentElement;
		if( eDiv != null )	eDiv.outerHTML = '';
	};
	if( window.m_bHookBeforeunload == true )
	{
		if( window.m_fnBeforeUnload != null )	window.m_fnBeforeUnload();
		document.body.onbeforeunload = window.m_fnBeforeUnload;
		window.m_fnBeforeUnload = null;
		window.m_bHookBeforeunload = false;
	};
};

function doDynaHelp_OpenIFrame( strURL )
{
//	strURL = doAppendURLTag( strURL, c_szURLStartTime, (new Date()).getTime() );		// add the start time

	if( window.m_bHookBeforeunload != true )
	{
		window.m_fnBeforeUnload = document.body.onbeforeunload;
		document.body.onbeforeunload = doDynaHelp_BeforeUnload;
		window.m_bHookBeforeunload = true;
	};

	var strFrmID = 'idDynaHelpFrame';
	var eFrm = document.all(strFrmID);
	// to avoid the browser histroy
	// IE55 has problem with window.open(,,,true)
	if( eFrm != null )
	{
		var eDiv = eFrm.parentElement;
		if( eDiv != null )	eDiv.outerHTML = '';
	};
	// create a new iframe
	var strHtml = '<div><iframe id="'+strFrmID+'" name="'+strFrmID+'" width=1 height=1 style="visibility: hidden;position: absolute;top: 1; left: 1" src="' + strURL + '"></iframe></div>';
	document.body.insertAdjacentHTML( 'beforeEnd', strHtml );
};

// load DynaHelp system into a new window
function doDynaHelp( strURL, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	var strFrame	= '_blank';
	var strParam	= '';
	var cInfo = new CBrowserInfo();

	strURL = doAppendURLTag( strURL, c_szURLCommand, c_szURLCommandWindow );		// window type: new window
	strURL = doAppendURLTag( strURL, c_szURLNewSession, '1' );						// tell server to create a new session
	strURL = doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData );
	strURL = doAppendURLTag( strURL, c_szURLReferrer, doGetLocation() );
//	if( cInfo.m_bIsPrimary && cInfo.m_bIsExplorer )
	if( cInfo.m_bIsExplorer && cInfo.m_nVersion >= 4 )
	{
		strURL = doAppendURLTag( strURL, c_szURLRequestType, c_szURLRequestIEIFrame );
		strURL = doAppendURLTag( strURL, c_szURLMonikerWCheckSessionCookie, '1' );	// ask server to check the session cookie
		doDynaHelp_OpenIFrame( strURL );
	}else
	if( cInfo.m_bIsPrimary && cInfo.m_bIsNetscape )
	{
		strURL = doAppendURLTag( strURL, c_szURLRequestType, c_szURLRequestNSWindow );
		strParam = 'left='+screen.width+',top='+screen.height;				// put the window out of the screen
		window.open( strURL, strFrame, strParam );
	}else
	{
		window.open( strURL, strFrame );
	};
	return false;																	// return false so the browser doesn't continue the href link.
};
// load DynaHelp system into a frame
function doDynaHelpEmbedded( strURL, strFrameName, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	if( strFrameName == null || strFrameName == '' )	strFrameName = '_self';

	strURL = doAppendURLTag( strURL, c_szURLCommand, c_szURLCommandEmbedded );			// tell server we don't want to use window property
	strURL = doAppendURLTag( strURL, c_szURLNewSession, '1' );						// tell server to create a new session
	strURL = doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData );
	strURL = doAppendURLTag( strURL, c_szURLReferrer, doGetLocation() );

	window.open( strURL, strFrameName );												// open the window
	return false;																	// return false so the browser doesn't continue the href link.
};
// load DynaHelp system into a popup window
function doDynaHelpPopup( strURL, nWidth, nHeight, strTransactionID, strSessionID, strCustomerID, strAppData )
{
	var bRet = true;
	var cInfo = new CBrowserInfo();

	strURL = doAppendURLTag( strURL, c_szURLCommand, c_szURLCommandPopup );		// tell server we don't want to use window property
	strURL = doAppendURLTag( strURL, c_szURLNewSession, '1' );						// tell server to create a new session
	strURL = doAppendSiteData( strURL, strTransactionID, strSessionID, strCustomerID, strAppData );
	strURL = doAppendURLTag( strURL, c_szURLReferrer, doGetLocation() );
	if( cInfo.m_bIsPrimary && cInfo.m_bIsExplorer )
	{
		if( nWidth == null || nWidth == '' )	nWidth = '75%';
		if( nHeight == null || nHeight == '' )	nHeight = '75%';
		nWidth = doGetSizeX( nWidth ); nHeight = doGetSizeY( nHeight );				// reset the popup window size

		var cPopup = window.m_cDynahelpPopup;
		if( cPopup == null )
		{
			cPopup = new CDynahelpPopup();
			window.m_cDynahelpPopup = cPopup;
		};
		cPopup.Popup( strURL, null, null, nWidth, nHeight );

		bRet = false;
	}else
	{
		if( nWidth == null || nWidth == '' )	nWidth = '50%';
		if( nHeight == null || nHeight == '' )	nHeight = '50%';
		nWidth = doGetSizeX( nWidth ); nHeight = doGetSizeY( nHeight );				// reset the popup window size

		var nLeft = 0; nTop = 0;
		var strParam = '';
//		if( window.event != null )
//		{
//			nLeft = window.event.screenX;	nTop = window.event.screenY;			
//		};
		strParam = 'left='+nLeft+',top='+nTop+',screenX='+nLeft+',screenY='+nTop+',width='+nWidth+',height='+nHeight;
		strParam += ',resizable=1,scrollbars=1';
		window.open( strURL, '_blank', strParam );
		bRet = false;
	};
	return bRet;
};


// eHelp Corporation.
// Dynahelp Server Version 1.20
// the codes for Dynahelp Cool popup
// 9/8/00, version 1.0

function tuAttr( strName, strValue )
{
	return ' ' + strName + '="' + strValue + '"';
};
function CDynahelpPopup()
{
	// Constructor
	{
		this.m_nValueSize 	= 32;
		this.m_strPrefixWidth	= 'dh_nWidth';
		this.m_strPrefixHeight	= 'dh_nHeight';
		this.m_strPrefixTime	= 'dh_nTime';
		this.m_strFramePopup	= 'dh_frmPopup';
		this.m_nMinFrameWidth	= 200;
		this.m_nMinFrameHeight	= 100;
		this.m_nDefaultWidth	= 300;
		this.m_nDefaultHeight	= 200;
		
		window.m_cDynahelpPopup = this;
		this.m_cBubble		= new CDynahelpBubble();
		this.m_nReloadTime	= 0;
		this.m_cBrowser		= new CBrowserInfo();
		this.m_bPopupDone 	= true;
		this.m_nPosX		= -1;
		this.m_nPosY		= -1;
		this.m_nPosW		= -1;
		this.m_nPosH		= -1;
	};
	this.ConvertBinValue = function ConvertBinValue( strValue )
	{
		var nRet = 0;
		var nLen = strValue;
		for( var nIdx = 0; nIdx < strValue.length; nIdx ++ )
		{
			nRet = nRet << 1;
			if( strValue.charAt(nIdx) != '0' )		nRet = nRet + 1;
		};
		return nRet;
	};
	this.GetScrollValue = function GetScrollValue( strPrefix, eWnd )
	{
		var strValue = '';
		var strType = '';
		for( var nIdx = 0; nIdx < this.m_nValueSize; nIdx ++ )
		{
			strType = eval( 'typeof(eWnd.' + strPrefix + nIdx + ')' );
			strValue += (strType == 'undefined') ? '0' : '1';
		};
		return this.ConvertBinValue( strValue );
	};
	this.GetScrollWidth = function GetScrollWidth( eWnd )
	{
		var nRet = window.document.body.clientWidth;
		if( this.m_cBrowser.m_bIsExplorer5 )
			nRet = this.GetScrollValue( this.m_strPrefixWidth, eWnd );
		else
			nRet = this.m_nDefaultWidth;
		return nRet;
	};
	this.GetScrollHeight = function GetScrollHeight( eWnd )
	{
		var nRet = window.document.body.clientHeight;
		if( this.m_cBrowser.m_bIsExplorer5 )
			nRet = this.GetScrollValue( this.m_strPrefixHeight, eWnd );
		else
			nRet = this.m_nDefaultHeight;
		return nRet;
	};
	this.GetScrollReadyTime = function GetScrollReadyTime( eWnd )
	{
		var nRet = this.GetCurrentTime();
		if( this.m_cBrowser.m_bIsExplorer5 )
			nRet = parseInt( this.GetScrollValue( this.m_strPrefixTime, eWnd ) );
		return nRet;
	};
	this.CreatePopup = function CreatePopup( strURL )
	{
		if( strURL == null )		strURL = 'about:blank';
		
		var strHtml = '<div><iframe';
		strHtml += tuAttr( 'id', this.m_strFramePopup );
		strHtml += tuAttr( 'frameborder', '0' );
		strHtml += tuAttr( 'scrolling', 'no' );
		strHtml += tuAttr( 'style', 'left: 0; top: 0; width: '+this.m_nMinFrameWidth+'; height: '+this.m_nMinFrameHeight+'; visibility: hidden; position: absolute' );
		strHtml += tuAttr( 'src', strURL );
		strHtml += '></iframe></div>';
		
		window.document.body.insertAdjacentHTML( 'beforeEnd', strHtml );
	};
	this.GetPopupObject = function GetPopupObject( strURL )
	{
		var cFrm = eval( 'window.' + this.m_strFramePopup );
		if( cFrm == null )
		{
			if( strURL != null )
			{
				this.CreatePopup( strURL );
				cFrm =  eval( 'window.' + this.m_strFramePopup );
			};
		}else
		{
			if( strURL != null )
			{
				cFrm.location.href = strURL;
			};
		};
		return cFrm;
	};
	this.GetPopupElement = function GetPopupElement( strURL )
	{
		var eFrm = window.document.all( this.m_strFramePopup );
		if( eFrm == null )
		{
			if( strURL != null )
			{
				this.CreatePopup( strURL );
				eFrm = window.document.all( this.m_strFramePopup );
			};
		}else
		{
			if( strURL != null )
			{
				eFrm.src = strURL;
			};
		};
		return eFrm;
	};
	this.ShowPopup = function ShowPopup( bShow )
	{
		this.m_cBubble.ShowBubble( bShow );

		var eFrm = this.GetPopupElement();
		if( eFrm != null )
		{
			if( bShow == true )
			{
				eFrm.style.visibility = 'visible';
			}else
			{
//				eFrm.style.visibility = 'hidden';
//				eFrm.style.posWidth = this.m_nMinFrameWidth;
//				eFrm.style.posHeight = this.m_nMinFrameHeight;
				// to avoid the browser histroy
				// IE55 has problem with window.open(,,,true);
				var eDiv = eFrm.parentElement;
				if( eDiv != null )	eDiv.outerHTML = '';
			};
		};		
	};
	this.GetCurrentTime = function GetCurrentTime()
	{
		var nRet = 0;
		var cDate = new Date();
		nRet = cDate.getHours();
		nRet = nRet * 60 + cDate.getMinutes();
		nRet = nRet * 60 + cDate.getSeconds();
		nRet = nRet * 1000 + cDate.getMilliseconds();
		return nRet;
	};
	
	
	this.Popup = function Popup( strURL, nPosX, nPosY, nPosW, nPosH )
	{
		if( nPosX == null && window.event != null )	nPosX = window.event.clientX + window.document.body.scrollLeft;
		if( nPosY == null && window.event != null )	nPosY = window.event.clientY + window.document.body.scrollTop;
		var nMaxX = parseInt(document.body.clientWidth * 3 / 4);
		var nMaxY = parseInt(document.body.clientHeight * 3 / 4);
		if( nPosW == null || nPosW > nMaxX )	nPosW = nMaxX;
		if( nPosH == null || nPosH > nMaxY )	nPosH = nMaxY;

		this.m_nPosX = nPosX;
		this.m_nPosY = nPosY;
		this.m_nPosW = nPosW;
		this.m_nPosH = nPosH;		

		var eFrm = this.GetPopupElement( strURL );
		if( eFrm != null && this.m_bPopupDone == true )
		{
			this.m_bPopupDone = false;
			this.m_nReloadTime = this.GetCurrentTime();
			setTimeout( 'window.m_cDynahelpPopup.PopupSetPosition()', 0 );
		};
	};
	this.PopupSetPosition = function PopupSetPosition()
	{
		var eFrm = this.GetPopupElement();
		var cFrm = this.GetPopupObject();
		if( eFrm != null && cFrm != null )
		{
			var nTime = this.GetScrollReadyTime( cFrm );
			if( this.m_nReloadTime <= nTime )
			{
				var nWidth = this.GetScrollWidth( cFrm );
				var nHeight = this.GetScrollHeight( cFrm );
				// adjacent for the scroll bar and maximize size
				if( nWidth >= this.m_nPosW )	{ nWidth = this.m_nPosW; nHeight += 16; }
				if( nHeight >= this.m_nPosH )	{ nHeight = this.m_nPosH; nWidth += 16; }

				eFrm.style.posWidth = nWidth;
				eFrm.style.posHeight = nHeight;
				this.m_cBubble.Bubble( this.m_nPosX, this.m_nPosY, nWidth, nHeight );
				this.m_cBubble.LocateInCell( eFrm );
	
				this.ShowPopup( true );
				document.body.DH_OnMousedown = document.body.onmousedown;
				if( document.body.DH_OnMousedown == null )
					document.body.DH_OnMousedown = '';
				document.body.onmousedown = DH_OnMousedown;
				
				this.m_bPopupDone = true;
				
			};
		};
		if( this.m_bPopupDone == false )
		{
//			var nTime = this.GetCurrentTime() - this.m_nReloadTime;
//			if( nTime >= 5000 )
//			{
//				this.m_bPopupDone = true;
//				alert( 'The server is not responding.  The page could not be loaded.' );
//			}else
			{
				setTimeout( 'window.m_cDynahelpPopup.PopupSetPosition()', 10 );
			};
		};
	};
};

function DH_OnMousedown()
{
	if( window.m_cDynahelpPopup != null )
		window.m_cDynahelpPopup.ShowPopup( false );
	if( document.body.DH_OnMousedown != null )
		document.body.onmousedown = document.body.DH_OnMousedown;
};

function CDynahelpBubble()
{
	// constructor
	{
		this.m_strImgBrdTop 		= 'dh_pop_brd_top.gif';
		this.m_strImgBrdLeftTop 	= 'dh_pop_brd_ltop.gif';
		this.m_strImgBrdLeft 		= 'dh_pop_brd_left.gif';
		this.m_strImgBrdLeftBtm 	= 'dh_pop_brd_lbtm.gif';
		this.m_strImgBrdBtm 		= 'dh_pop_brd_btm.gif';
		this.m_strImgBrdRightBtm 	= 'dh_pop_brd_rbtm.gif';
		this.m_strImgBrdRight 		= 'dh_pop_brd_right.gif';
		this.m_strImgBrdRightTop 	= 'dh_pop_brd_rtop.gif';
		
		this.m_strImgArwTopLeft		= 'dh_pop_arw_tleft.gif';
		this.m_strImgArwTopRight	= 'dh_pop_arw_tright.gif';
		this.m_strImgArwLeftTop		= 'dh_pop_arw_ltop.gif';
		this.m_strImgArwLeftBtm		= 'dh_pop_arw_lbtm.gif';
		this.m_strImgArwBtmLeft		= 'dh_pop_arw_bleft.gif';
		this.m_strImgArwBtmRight	= 'dh_pop_arw_bright.gif';
		this.m_strImgArwRightBtm	= 'dh_pop_arw_rbtm.gif';
		this.m_strImgArwRightTop	= 'dh_pop_arw_rtop.gif';
		// others
		this.m_strScriptID		= 'Dynahelp';
		this.m_strScriptName		= 'Dynahelp.js';
		this.m_strIDTable		= 'dh_pop_table';
		this.m_strIDCell		= 'dh_pop_cell';
		this.m_strIDArrow		= 'dh_pop_arrow';
		this.m_nBorderWidth		= 6;
		this.m_nBorderHeight		= 6;
		this.m_nArrowWidth		= 20;
		this.m_nArrowHeight		= 20;
		// object
		this.m_eBody			= window.document.body;
		// set self
		window.m_cDynahelpBubble	= this;
		this.m_cNames			= new Array;
		this.m_cNames[0] = 'name';
		this.m_cNames[1] = 'Name';
		this.m_cNames[2] = 'NAME';
		this.m_cNames[3] = 'id';
	};
	// I have to admit it's to bad
	// I have to backward support
	this.DoesMatchID = function DoesMatchID( eElm )
	{
		var bRet = false;
		if( eElm != null )
		{
			var strJSID = this.m_strScriptID.toLowerCase();
			for( var nIdx = 0; nIdx < this.m_cNames.length; nIdx ++ )
			{
				var strName = eval('eElm.'+this.m_cNames[nIdx]);
				if( typeof( strName ) == 'string' && strName.toLowerCase() == strJSID )
				{
					bRet = true;
					break;
				};
			};
		};
		return bRet;
	};
	this.GetScriptPath = function GetScriptPath()
	{
		var strRet = null;
		var cScript = null;
		var nSum = document.scripts.length;
		for( var nIdx = 0; nIdx < nSum; nIdx ++ )
		{
			cScript = document.scripts[nIdx];
			if( cScript != null )
			{
				var strPath = '';
				var strSrc = cScript.src;
				var nPos = strSrc.lastIndexOf( '/' );

				if( nPos >= 0 )
				{
					strPath = strSrc.substring( 0, nPos + 1 );
					strSrc = strSrc.substring( nPos + 1, strSrc.length );
				};
				if( this.DoesMatchID( cScript ) == true )
				{
					strRet = strPath;
					break;
				};
				// remember this first dynahelp.js path
				// in code the we can not found the id="dynahelp"
				// we can still use this path
				if( strRet == null && strSrc.toLowerCase() == this.m_strScriptName.toLowerCase() )
				{
					strRet = strPath;
				};
			};
		};
		if( strRet == null )	strRet = '';
		return strRet;
	};
	this.ResetImageURL = function ResetImageURL()
	{
		var strPath = this.GetScriptPath();
		
		this.m_strImgBrdTop 		= strPath + this.m_strImgBrdTop;
		this.m_strImgBrdLeftTop 	= strPath + this.m_strImgBrdLeftTop;
		this.m_strImgBrdLeft 		= strPath + this.m_strImgBrdLeft;
		this.m_strImgBrdLeftBtm 	= strPath + this.m_strImgBrdLeftBtm;
		this.m_strImgBrdBtm 		= strPath + this.m_strImgBrdBtm;
		this.m_strImgBrdRightBtm 	= strPath + this.m_strImgBrdRightBtm;
		this.m_strImgBrdRight 		= strPath + this.m_strImgBrdRight;
		this.m_strImgBrdRightTop 	= strPath + this.m_strImgBrdRightTop;
		
		this.m_strImgArwTopLeft		= strPath + this.m_strImgArwTopLeft;
		this.m_strImgArwTopRight	= strPath + this.m_strImgArwTopRight;
		this.m_strImgArwLeftTop		= strPath + this.m_strImgArwLeftTop;
		this.m_strImgArwLeftBtm		= strPath + this.m_strImgArwLeftBtm;
		this.m_strImgArwBtmLeft		= strPath + this.m_strImgArwBtmLeft;
		this.m_strImgArwBtmRight	= strPath + this.m_strImgArwBtmRight;
		this.m_strImgArwRightBtm	= strPath + this.m_strImgArwRightBtm;
		this.m_strImgArwRightTop	= strPath + this.m_strImgArwRightTop;
	};
	this.GetBubbleTD = function GetBubbleTD( strImg, nIdx )
	{
		return '<td background="'+strImg+'"><img border="0" src="'+strImg+'"></td>';
	};
	this.CreateBubble = function CreateBubble()
	{
		this.ResetImageURL();
		
		var strHtml = '';
		
		strHtml += '<table border="0" cellspacing="0" cellpadding="0"';
		strHtml += tuAttr( 'id', this.m_strIDTable );
		strHtml += tuAttr( 'style', 'position: absolute; left: 0; top: 0; visibility: hidden' );
		strHtml += '><tr>';
		strHtml += this.GetBubbleTD( this.m_strImgBrdLeftTop );
		strHtml += this.GetBubbleTD( this.m_strImgBrdTop );
		strHtml += this.GetBubbleTD( this.m_strImgBrdRightTop );
		strHtml += '</tr><tr>';
		strHtml += this.GetBubbleTD( this.m_strImgBrdLeft );
		strHtml += '<td';
		strHtml += tuAttr( 'id', this.m_strIDCell );
		strHtml += tuAttr( 'style', 'width: 1; height: 1' );
		strHtml += '>';
		strHtml += this.GetBubbleTD( this.m_strImgBrdRight );
		strHtml += '</tr><tr>';
		strHtml += this.GetBubbleTD( this.m_strImgBrdLeftBtm );
		strHtml += this.GetBubbleTD( this.m_strImgBrdBtm );
		strHtml += this.GetBubbleTD( this.m_strImgBrdRightBtm );
		strHtml += '</tr></table>';
		strHtml += '<img';
		strHtml += tuAttr( 'id', this.m_strIDArrow );
		strHtml += tuAttr( 'style', 'position: absolute; left: 0; top: 0; visibility: hidden' );
		strHtml += '>';
		
		this.m_eBody.insertAdjacentHTML( 'beforeEnd', strHtml );
	};
	this.GetBubbleTable = function GetBubbleTable()
	{
		var eRet = null;
		eRet = this.m_eBody.all( this.m_strIDTable );
		if( eRet == null )
		{
			this.CreateBubble();
			eRet = this.m_eBody.all( this.m_strIDTable );
		};
		return eRet;
	};
	this.GetBubbleCell = function GetBubbleCell()
	{
		var eRet = null;
		eRet = this.m_eBody.all( this.m_strIDCell );
		if( eRet == null )
		{
			this.CreateBubble();
			eRet = this.m_eBody.all( this.m_strIDCell );
		};
		return eRet;
	};
	this.GetBubbleArrow = function GetBubbleArrow()
	{
		var eRet = null;
		eRet = this.m_eBody.all( this.m_strIDArrow );
		if( eRet == null )
		{
			this.CreateBubble();
			eRet = this.m_eBody.all( this.m_strIDArrow );
		};
		return eRet;
	};
	this.ShowBubble = function ShowBubble( bShow )
	{
		var eBubble = this.GetBubbleTable();
		if( eBubble != null )
		{
			if( bShow == true )
			{
				eBubble.style.visibility = 'visible';
			}else
			{
				eBubble.style.visibility = 'hidden';
				this.ShowArrow( false );
			};
		};		
	};
	this.ShowArrow = function ShowArrow( bShow )
	{
		var eArrow = this.GetBubbleArrow();
		if( eArrow != null )
		{
			if( bShow == true )
			{
				eArrow.style.visibility = 'visible';
			}else
			{
				eArrow.style.visibility = 'hidden';
			};
		};		
	};
	this.LocateAtTop = function LocateAtTop( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			var nCltLeft = this.m_eBody.scrollLeft;
			var nCltTop = this.m_eBody.scrollTop;
			var nCltRight = nCltLeft + this.m_eBody.clientWidth;
			var nCltBtm = nCltTop + this.m_eBody.clientHeight;
			var nHeight = eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;
			var nWidth = eCell.style.posWidth +  this.m_nBorderWidth + this.m_nBorderWidth;
			var nLeft = nPosX - this.m_nBorderWidth;
			var nTop = nPosY - nHeight - (this.m_nArrowHeight - this.m_nBorderHeight);
			if( nTop >= nCltTop )
			{
				if( nLeft + nWidth > nCltRight )	nLeft = nCltRight - nWidth;		// bubble can't outside the rigth border
				if( nLeft >= nCltLeft )
				{
					eTable.style.posLeft = nLeft;	eTable.style.posTop = nTop;
					bRet = true;
				};
			};			
		};
		return bRet;
	};
	this.LocateAtBtm = function LocateAtBtm( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			var nCltLeft = this.m_eBody.scrollLeft;
			var nCltTop = this.m_eBody.scrollTop;
			var nCltRight = nCltLeft + this.m_eBody.clientWidth;
			var nCltBtm = nCltTop + this.m_eBody.clientHeight;
			var nHeight = eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;
			var nWidth = eCell.style.posWidth +  this.m_nBorderWidth + this.m_nBorderWidth;
			var nLeft = nPosX - this.m_nBorderWidth;
			var nTop = nPosY + (this.m_nArrowHeight - this.m_nBorderHeight);
			if( nTop + nHeight <= nCltBtm )
			{
				if( nLeft + nWidth > nCltRight )	nLeft = nCltRight - nWidth;		// bubble can't outside the rigth border
				if( nLeft >= nCltLeft )
				{
					eTable.style.posLeft = nLeft;	eTable.style.posTop = nTop;
					bRet = true;
				};
			};			
		};
		return bRet;
	};
	this.LocateAtLeft = function LocateAtLeft( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			var nCltLeft = this.m_eBody.scrollLeft;
			var nCltTop = this.m_eBody.scrollTop;
			var nCltRight = nCltLeft + this.m_eBody.clientWidth;
			var nCltBtm = nCltTop + this.m_eBody.clientHeight;
			var nHeight = eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;
			var nWidth = eCell.style.posWidth +  this.m_nBorderWidth + this.m_nBorderWidth;
			var nLeft = nPosX - nWidth - (this.m_nArrowWidth - this.m_nBorderWidth);
			var nTop = nPosY - this.m_nBorderHeight;
			if( nLeft >= nCltLeft )
			{
				if( nTop + nHeight > nCltBtm )	nTop = nCltBtm - nHeight;		// bubble can't outside the bottom border
				if( nTop >= nCltTop )
				{
					eTable.style.posLeft = nLeft;	eTable.style.posTop = nTop;
					bRet = true;
				};
			};			
		};
		return bRet;
	};
	this.LocateAtRight = function LocateAtRight( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			var nCltLeft = this.m_eBody.scrollLeft;
			var nCltTop = this.m_eBody.scrollTop;
			var nCltRight = nCltLeft + this.m_eBody.clientWidth;
			var nCltBtm = nCltTop + this.m_eBody.clientHeight;
			var nHeight = eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;
			var nWidth = eCell.style.posWidth +  this.m_nBorderWidth + this.m_nBorderWidth;
			var nLeft = nPosX + (this.m_nArrowWidth - this.m_nBorderWidth);
			var nTop = nPosY - this.m_nBorderHeight;
			if( nLeft + nWidth <= nCltRight )
			{
				if( nTop + nHeight > nCltBtm )	nTop = nCltBtm - nHeight;		// bubble can't outside the bottom border
				if( nTop >= nCltTop )
				{
					eTable.style.posLeft = nLeft;	eTable.style.posTop = nTop;
					bRet = true;
				};
			};			
		};
		return bRet;
	};
	this.LocateAtTopLeft = function LocateAtTopLeft( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			var nCltLeft = this.m_eBody.scrollLeft;
			var nCltTop = this.m_eBody.scrollTop;
			var nCltRight = nCltLeft + this.m_eBody.clientWidth;
			var nCltBtm = nCltTop + this.m_eBody.clientHeight;
			var nHeight = eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;
			var nWidth = eCell.style.posWidth +  this.m_nBorderWidth + this.m_nBorderWidth;
			var nLeft = nCltRight - nWidth;
			var nTop = nCltTop;
			if( nLeft < 0 )	nLeft = 0;
			if( nTop < 0 )	nTop = 0;
			eTable.style.posLeft = nLeft;	eTable.style.posTop = nTop;
		};
		return bRet;
	};
	this.LocateArrow = function LocateArrow( nPosX, nPosY )
	{
		var bRet = false;
		var eTable = this.GetBubbleTable();
		var eArrow = this.GetBubbleArrow();
		var eCell = this.GetBubbleCell();
		
		if( eTable != null && eArrow != null && eCell != null )
		{
			var strImg = '';
			var nLeft = eTable.style.posLeft;
			var nTop = eTable.style.posTop;
			var nRight = nLeft + eCell.style.posWidth + this.m_nBorderWidth + this.m_nBorderWidth;
			var nBtm = nTop + eCell.style.posHeight + this.m_nBorderHeight + this.m_nBorderHeight;

			if( nPosY <= nTop )
			{
				if( nPosX < (nLeft + nRight) / 2 )		
				{
					strImg = this.m_strImgArwTopLeft;
					nLeft = nPosX;	nTop = nPosY;
				}else
				{
					strImg = this.m_strImgArwTopRight;
					nLeft = nPosX - this.m_nBorderWidth;	nTop = nPosY;
				};
			}else
			if( nPosX <= nLeft )
			{
				if( nPosY < (nTop + nBtm) / 2 )
				{	
					strImg = this.m_strImgArwLeftTop;
					nLeft = nPosX;	nTop = nPosY;
				}else
				{
					strImg = this.m_strImgArwLeftBtm;
					nLeft = nPosX;	nTop = nPosY - this.m_nBorderHeight;
				};
			}else
			if( nPosY >= nBtm )
			{
				if( nPosX < (nLeft + nRight) / 2 )
				{
					strImg = this.m_strImgArwBtmLeft;
					nLeft = nPosX;	nTop = nPosY - this.m_nArrowHeight;
				}else
				{
					strImg = this.m_strImgArwBtmRight;	
					nLeft = nPosX - this.m_nBorderWidth;	nTop = nPosY - this.m_nArrowHeight;
				};
			}else
			if( nPosX >= nRight )
			{
				if( nPosY < (nTop + nBtm) / 2 )
				{
					strImg = this.m_strImgArwRightTop;
					nLeft = nPosX - this.m_nArrowWidth;	nTop = nPosY;
				}else
				{
					strImg = this.m_strImgArwRightBtm;
					nLeft = nPosX - this.m_nArrowWidth;	nTop = nPosY - this.m_nBorderHeight;
				};
			};
			if( strImg != '' )
			{
				eArrow.src = strImg;
				eArrow.style.posLeft = nLeft;
				eArrow.style.posTop = nTop;
				bRet = true;			
			};
		};
		return bRet;
	};
	
	
	this.Bubble = function Bubble( nPosX, nPosY, nPosW, nPosH )
	{
		this.ShowBubble( false );
		
		var eTable = this.GetBubbleTable();
		var eCell = this.GetBubbleCell();
		if( eTable != null && eCell != null )
		{
			eCell.style.posWidth = nPosW;
			eCell.style.posHeight = nPosH;

			if( this.LocateAtTop( nPosX, nPosY ) == false &&
				this.LocateAtLeft( nPosX, nPosY ) == false &&
				this.LocateAtBtm( nPosX, nPosY ) == false &&
				this.LocateAtRight( nPosX, nPosY ) == false )
			{
				this.LocateAtTopLeft( nPosX, nPosY );
			}else
			{
				if( this.LocateArrow( nPosX, nPosY ) == true )
					this.ShowArrow( true );
			};
			this.ShowBubble( true );
		};
	};
	this.LocateInCell = function LocateInCell( eWnd )
	{
		var eTable = this.GetBubbleTable();
		if( eTable != null && eWnd != null )
		{
			eWnd.style.posLeft = eTable.style.posLeft + this.m_nBorderWidth;
			eWnd.style.posTop = eTable.style.posTop + this.m_nBorderHeight;
		};
	};
};