<!--
//-----------------------------------------------------------------------------
//	wfxClientCache object manages client side cache for iVelocity
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//  functions either return either true/false or a string/empty string and the
//  following return codes can be checked along with the method package error 
//  code, is not below for system errors. However there are instances where 
//  there were no system COM+ error but there may be a request error, for example
//  trying to delete or update a node that does not exist, xml file failed to 
//  load. You can always get these errors and error descritons in the following
//  parameter section of the method package.
//  gs_RETURN_PARAM = "return"
//  gs_RETURN_DESCRIPTION_PARAM = "return_description"
//
//  return/return description:
//   0  - Successful
//  -1  - Failed / Exception
//  -2  - Parent Node empty
//  -3  - Child Node empty
//  -4  - Cache Data parameter empty
//  -5  - Cache File Name empty.
//  -6  - XML File failed to load
//        XML Cache Data Object failed to load. Check XML string format of object.
//        XML File Does not exist. There is no node to delete or modify.
//  -7  - Cache Identifier empty
//  -8  - Incorrect cache_data_type, must be tag.
//  -9  - The Node requested to update does not exist.
//  -10 - The Node Data requested to retreive does not exist.
//  -11 - The Node requested to delete does not exist.
//  -2147467259 - "Numeric XML Node Error, the node you are trying to 
//                 add/update/delete begins with a number."
//  *****************  REQUIRED INCLUDED SCRIPT FILES *************************
//	<script language="javascript" src="wfxclient.js"></script>
//	<script language="javascript" src="wfxErrorHandler.js"></script>
//	<script language="javascript" src="wfxCookies.js"></script>
//	<script language="javascript" src="wfxClientCache.js"></script>
//
//  ***************** REQUIRED ASP FILE ***************************************
//  wfx_upd_cache.asp 
//
//  ***************** REQUIRED VB COM+ OBJECTS ********************************
//  tsiULWebCache.dll
//  wfxULPkg.dll
//  wfxULGUID.dll
//  ** there may be other framework dlls used by the first wfx files.
//-----------------------------------------------------------------------------
// constants/defines for the Method Package in using the client cache
var gs_RETURN_PARAM = "return";
var gs_RETURN_DESCRIPTION_PARAM = "return_description";
var gs_CACHE_FILE_LOCATION_PARAM = "cache_file_location";
var gs_MAP_PATH_CACHE_FILE_LOCATION_PARAM = "map_path_cache_file_location";
var	gs_PARENT_NODE_PARAM = "parent_node";
var gs_CHILD_NODE_PARAM = "child_node";
var gs_CACHE_DATA_PARAM = "cache_data";
var gs_CACHE_DATA_TYPE = "cache_data_type";     // represents either text or obj
var gs_CACHE_CLIENT_ID = "cache_client_id";     // this represents window handle writing to cache
var gs_COOKIE_CACHE_KEY = "cookie_cache_key";

var gl_CACHE_SUCCESSFUL = 0;
var gs_CACHE_SUCCESSFUL_DESC = "Successful.";
var gl_PARENT_NODE_ERR = -2;
var gs_PARENT_NODE_ERR_DESC = "Parent Node parameter empty."; 
var gl_CHILD_NODE_ERR = -3;
var gs_CHILD_NODE_ERR_DESC = "Child Node parameter empty.";
var gl_CACHE_DATA_ERR = -4;
var gs_CACHE_DATA_ERR_DESC = "Cache Data parameter empty.";
var gl_FILE_NAME_ERR = -5;
var gs_FILE_NAME_ERR_DESC = "Cache File Name empty.";
var gl_XML_FILE_LOAD_ERR = -6;
var gs_XML_FILE_LOAD_ERR_DESC = "No XML file exist, populate xml first.";
var gs_XML_DATA_LOAD_ERR_DESC = "XML Cache Data Object failed to load. Check XML string format of object.";
var gs_XML_FILE_EXIST_ERR_DESC = "XML File Does not exist. There is no node to delete or modify.";
var gs_DELETE_NODE_ERR_DESC = "The Node requested to delete does not exist.";
var gl_CACHE_ID_ERR_ERR = -7;
var gs_CACHE_ID_ERR_ERR_DESC = "Cache Identifier empty.";
var gl_DEL_DATA_TYPE_ERR = -8;
var gs_DEL_DATA_TYPE_ERR_DESC = "Incorrect cache_data_type, must be tag."; //others may be used in future
var gl_UPDATE_NODE_ERR = -9;
var gs_UPDATE_NODE_ERR_DESC = "The Node requested to update does not exist.";
var gl_RETRIEVE_NODE_ERR = -10;
var gs_RETRIEVE_NODE_ERR_DESC = "The Node Data requested to retreive does not exist.";
var gl_DELETE_NODE_ERR = -11
var gs_DELETE_NODE_ERR_DESC = "The Node requested to delete does not exist."

var gl_NUMERIC_NODE_ERROR = -2147467259; // NodeTest error when numeric value used
var gs_NUMERIC_NODE_ERROR_DESC = "Numeric XML Node Error, the node you are trying to add/update/delete begins with a number.";

// constants data type used in the componet for processing
var gl_XMLTEXT = 1;
var gl_XMLOBJ = 2;
var gl_XMLTAG = 3;

// set global variables for 4:00:00 AM
var gs_hour_cmp = 4;
var gs_min_cmp = 0;
var gs_sec_cmp = 0;

var gs_cache_key = "cache_key";
var gs_cache_key_value = "";


//-----------------------------------------------------------------------------
//	Function : wfxClientCache( as_parent_node, as_child_node, as_cache_data, 
//                             al_data_type)
//
//  Purpose : Constructor; initializes the object members, with the parameters
//            passed in, as well as other cookie initializing routing, and 
//            setting up the methodPackage
//
//  Parameters: as_parent_node - parent XML node used to cache text/object data
//              as_child_node  - child XML node used to cache text/object data
//              as_cache_data  - data used to update/add/delete text/object data
//              al_data_type   - data type which drives text/object/tag 
//                               gl_XMLTEXT = 1;
//                               gl_XMLOBJ = 2;
//	                             gl_XMLTAG = 3;
//
//  Examples shown with individual public calls below.
//-----------------------------------------------------------------------------
function wfxClientCache(as_parent_node, as_child_node, as_cache_data, al_data_type)
{		
	// member variables default initialiation
	this.ms_cache_key = gs_cache_key;
	this.ms_cache_key_value = gs_cache_key_value;
	this.mobj_cache = null;
	this.ms_parent_node = "";
	this.ms_child_node = "";
	this.ms_cache_data = "";
	this.ml_data_type = 0;         // default to text
	this.ms_cache_client_id = "";
	
	// initialize these members with parameter list
	this.ms_parent_node = as_parent_node;
	this.ms_child_node = as_child_node;
	this.ms_cache_data = as_cache_data;
	// check to make sure the window.name has a value before assigning
	__diCheckWindowName();
	this.ms_cache_client_id = window.name;

	// set data type to be used by component for different processing
	switch(al_data_type)
	{
		case gl_XMLTEXT: 
			this.ml_data_type = gl_XMLTEXT;
			break;
		
		case gl_XMLOBJ: 
			this.ml_data_type = gl_XMLOBJ;
			break;
 
		case gl_XMLTAG: 
			this.ml_data_type = gl_XMLTAG;
			break;

	    default:
			this.ml_data_type = gl_XMLTEXT;
	}
	
	// public functions used to update the cache
	this.addItem = __diAddItem;					        //Public function
	this.updateItem = __diUpdateItem;					//Public function
	this.deleteItem = __diDeleteItem;					//Public function
	
	// public functions used to get cache data to use in the client
	this.getCache = __diGetCache;
	this.getCacheTxt = __diGetCacheTxt;
	this.getCacheObj = __diGetCacheObj;
	this.getMachineCache = __diGetMachineCache;
	
	// utility funcitons used to remove browser instance cache node on close
	this.deleteInstanceCache = __diDeleteInstanceCache;
	
	// internal functions
	this.createCookieKey = __diCreateCookieKey;		    // Internal function
	this.setGuidCookie = __diSetGuidCookie;				// Internal function
    this.checkWindowName = __diCheckWindowName;         // Internal function
    
	// check to see if cookies exist, if not create cookie
	if (!CookieExists(this.ms_cache_key))
	{
		// cookie does not exist, create new guid file name, key returned 
		// contains the url path the the xml file, and set the cookie
		if (__diCreateCookieKey())
		{
			__diSetGuidCookie();
			this.ms_cache_key_value = gs_cache_key_value;
		}
		else
		{
			alert("cache cookie is not populated and was not set.");
		}
	}
	else
	{
		// if exist set the ms_cache_key_value
		gs_cache_key_value = GetCookie(this.ms_cache_key);
		this.ms_cache_key_value = gs_cache_key_value;
	}
	
	// initialize the method package parameters	
	this.mobj_cache = new wfxDom();
	this.mobj_cache.setMPObject("JScript");	
	this.mobj_cache.addParam(gs_RETURN_PARAM, 3, 0);
	this.mobj_cache.addParam(gs_RETURN_DESCRIPTION_PARAM, 8, "");
	this.mobj_cache.addParam(gs_CACHE_FILE_LOCATION_PARAM, 8, "");
	this.mobj_cache.addParam(gs_MAP_PATH_CACHE_FILE_LOCATION_PARAM, 8, "");	
	this.mobj_cache.addParam(gs_PARENT_NODE_PARAM, 8, "");
	this.mobj_cache.addParam(gs_CHILD_NODE_PARAM, 8, "");
	this.mobj_cache.addParam(gs_CACHE_DATA_PARAM, 8, "");
	this.mobj_cache.addParam(gs_CACHE_DATA_TYPE, 3, 0);
	this.mobj_cache.addParam(gs_CACHE_CLIENT_ID, 8, "");
}

//#############################################################################
//					wfxClientCache() OBJECT FUNCTIONS
//#############################################################################
//-----------------------------------------------------------------------------
//	Function : __diAddItem( )
//
//  Purpose : This function is used to add data to the cache on the server. The
//            data will either be added under a parent or parent/child node, 
//            either add/replace text or object data based on data type. If the 
//            data already exist it will be replaced. 
//  Note*** Object data needs to be passed in string format.
//
//  Constructor Parameters: 
//  ls_parentNode_name - parent XML node used to cache text/object data
//                       example: "parent"
//  ls_childNode_name  - child XML node used to cache text/object data
//                       example: "child" or empty string "" if not used
//  ls_cache_data  - XMLText = "textData"
//                   XMLObj = "<MethodPackage>..</MethodPackage>" string format
//  ll_data_type   - valid AddItem( ) Data Types 
//                   gl_XMLTEXT = 1
//                   gl_XMLOBJ = 2
//	                             
//	Return: true/false - if false check parameters:
//                       gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                     * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//		var ll_data_type = gl_XMLTEXT; 
// 	    lobj_cache = new wfxClientCache(ls_parentNode_name, 
//                                      ls_childNode_name, 
//								        ls_cache_data
//                                      ll_data_type); 
//      if ( !lobj_cache.addItem() )
//   	{   //CHECK ERROR RETURN
//		    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//		}
//	    lobj_cache = null;
//-----------------------------------------------------------------------------
function __diAddItem( ) 
{
	var lobj_errorHandler = null;	
	
	// check to make sure atleast parent node and cache data is populated
	if (this.ms_parent_node == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_PARENT_NODE_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_PARENT_NODE_ERR_DESC);
		return false;
	}
	if (this.ms_cache_data == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_CACHE_DATA_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_CACHE_DATA_ERR_DESC);
		return false;
	}
		
	//this.mobj_cache.copySecure(IncomingPageXML);
	this.mobj_cache.addParam("Action", 8, "add");
	this.mobj_cache.setParameter(gs_CACHE_FILE_LOCATION_PARAM, this.ms_cache_key_value);
	this.mobj_cache.setParameter(gs_PARENT_NODE_PARAM, this.ms_parent_node);
	this.mobj_cache.setParameter(gs_CHILD_NODE_PARAM, this.ms_child_node);
	this.mobj_cache.setParameter(gs_CACHE_DATA_PARAM, this.ms_cache_data);
	this.mobj_cache.setParameter(gs_CACHE_DATA_TYPE, this.ml_data_type);
	this.mobj_cache.setParameter(gs_CACHE_CLIENT_ID, this.ms_cache_client_id);
	this.mobj_cache.sendDataHTTP("wfx_upd_cache.asp", true);
    
    // convert the string return to a xmlDOM object
	var lobj_error_dom = new wfxDom( this.mobj_cache.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		//var lobj_error_handler;
		//lobj_error_handler = new wfxErrorHandler();
		//lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		//lobj_error_handler = null;
		//obj_error_dom = null;
		return false;	
	}
	lobj_error_dom = null;
	return true;
}

//-----------------------------------------------------------------------------
//	Function : __diDeleteItem( )
//
//  Purpose : This function is used to delete data in cache on the server. A 
//            tag name will be supplied to delete under a parent or 
//            parent/child node.
//
//  Constructor Parameters: 
//  ls_parentNode_name - parent XML node used to cache text/object data
//                     example: "parent"
//  ls_childNode_name  - child XML node used to cache text/object data
//                     example: "child" or empty string "" if not used
//  ls_tag_name        - TAG name to be deleted
//  ll_data_type       - valid deleteItem( ) Data Type 
//                     gl_XMLTAG = 3
//	                             
//	Return: true/false - if false check parameters:
//                       gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                     * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//		var ll_data_type = gl_XMLTAG; 
// 	    lobj_cache = new wfxClientCache(ls_parentNode_name, 
//                                      ls_childNode_name, 
//								        ls_tag_name,
//                                      ll_data_type); 
//      if ( !lobj_cache.deleteItem() )
//   	{   //CHECK ERROR RETURN
//		    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//		}
//	    lobj_cache = null;
//-----------------------------------------------------------------------------
function __diDeleteItem( ) 
{
	var lobj_errorHandler = null;	
	
	// check to make sure atleast parent node is populated
	if (this.ms_parent_node == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_PARENT_NODE_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_PARENT_NODE_ERR_DESC);
		return false;
	}
		
	//this.mobj_cache.copySecure(IncomingPageXML);
	this.mobj_cache.addParam("Action", 8, "delete");
	this.mobj_cache.setParameter(gs_CACHE_FILE_LOCATION_PARAM, this.ms_cache_key_value);
	this.mobj_cache.setParameter(gs_PARENT_NODE_PARAM, this.ms_parent_node);
	this.mobj_cache.setParameter(gs_CHILD_NODE_PARAM, this.ms_child_node);
	this.mobj_cache.setParameter(gs_CACHE_DATA_PARAM, this.ms_cache_data);
	this.mobj_cache.setParameter(gs_CACHE_DATA_TYPE, this.ml_data_type);
	this.mobj_cache.setParameter(gs_CACHE_CLIENT_ID, this.ms_cache_client_id);
	this.mobj_cache.sendDataHTTP("wfx_upd_cache.asp", true);
    
    // convert the string return to a xmlDOM object
	var lobj_error_dom = new wfxDom( this.mobj_cache.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		/*var lobj_error_handler;
		lobj_error_handler = new wfxErrorHandler();
		lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		lobj_error_handler = null;
		lobj_error_dom = null;*/
		return false;	
	}
	lobj_error_dom = null;
	return true;	
}

//-----------------------------------------------------------------------------
//  Function __diUpdateItem( )
//
//  Purpose : This function is used to update data to the cache on the server. 
//            The data will either be updated under a parent or parent/child 
//            Item node. Data will be updated by text or object based on data 
//            type. 
//  Note*** Object data needs to be passed in string format.
//
//  Constructor Parameters: 
//  ls_parentNode_name - parent XML node used to cache text/object data
//                     example: "parent"
//  ls_childNode_name  - child XML node used to cache text/object data
//                     example: "child" or empty string "" if not used
//  ls_cache_data  - XMLText = "textData"
//                   XMLObj = "<MethodPackage>..</MethodPackage>" string format
//  ll_data_type   - valid updateItem( ) Data Types 
//                   gl_XMLTEXT = 1
//                   gl_XMLOBJ = 2
//	                             
//	Return: true/false - if false check parameters:
//                       gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                     * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//		var ll_data_type = gl_XMLTEXT; 
// 	    lobj_cache = new wfxClientCache(ls_parentNode_name, 
//                                      ls_childNode_name, 
//								        ls_cache_data
//                                      ll_data_type); 
//      if ( !lobj_cache.updateItem() )
//   	{   //CHECK ERROR RETURN
//		    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//		}
//	    lobj_cache = null;
//-----------------------------------------------------------------------------
function __diUpdateItem( ) 
{
	var lobj_errorHandler = null;	
	
	// check to make sure atleast parent node is populated
	if (this.ms_parent_node == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_PARENT_NODE_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_PARENT_NODE_ERR_DESC);
		return false;
	}
		
	if (this.ms_cache_data == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_CACHE_DATA_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_CACHE_DATA_ERR_DESC);
		return false;
	}

	//this.mobj_cache.copySecure(IncomingPageXML);
	this.mobj_cache.addParam("Action", 8, "update");
	this.mobj_cache.setParameter(gs_CACHE_FILE_LOCATION_PARAM, this.ms_cache_key_value);
	this.mobj_cache.setParameter(gs_PARENT_NODE_PARAM, this.ms_parent_node);
	this.mobj_cache.setParameter(gs_CHILD_NODE_PARAM, this.ms_child_node);
	this.mobj_cache.setParameter(gs_CACHE_DATA_PARAM, this.ms_cache_data);
	this.mobj_cache.setParameter(gs_CACHE_DATA_TYPE, this.ml_data_type);
	this.mobj_cache.setParameter(gs_CACHE_CLIENT_ID, this.ms_cache_client_id);
	this.mobj_cache.sendDataHTTP("wfx_upd_cache.asp", true);
    
    // convert the string return to a xmlDOM object
	var lobj_error_dom = new wfxDom( this.mobj_cache.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		/*var lobj_error_handler;
		lobj_error_handler = new wfxErrorHandler();
		lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		lobj_error_handler = null;
		lobj_error_dom = null;*/
		return false;	
	}
	lobj_error_dom = null;
	return true;	
}

//-----------------------------------------------------------------------------
//  Functon __diGetCache( ) 
// 
//	Purpose: This function is used to Get the entire xml specific to the 
//           calling browser instance and it stores the data in the CDATA 
//           section "cache", it also returns the XML in string format. The 
//           specific root <GUID> is specific to each instance on that machine
//           running, root <GUID> can be obtained by calling {window.name}
//  ** CDATA population only happens on getCache() and getMachineCache()
//    
//	Return: string - if empty "" string check parameters :
//                   gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                 * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//   	var ls_xml = "";
//  	lobj_cache = new wfxClientCache();	
//  	ls_xml = lobj_cache.getCache();
//  	if (ls_xml == "") //CHECK ERROR RETURN
//  	{
//  	    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//  	}
//  	else 
//  	{
//  		// *** use XML
//  	}
//  	lobj_cache = null;
//-----------------------------------------------------------------------------
function __diGetCache( ) 
{
	var bret = false;
	var lobj_xmlDom = null;
	var ls_nodePath = "";
	var ls_xml = "";
	//this.mobj_cache.setMPName("LoadCache");	
	lobj_xmlDom = new ActiveXObject("Microsoft.XMLDOM");
	lobj_xmlDom.async = false;
	var bret = lobj_xmlDom.load(this.ms_cache_key_value);
	if (!bret)
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_XML_FILE_LOAD_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_XML_FILE_LOAD_ERR_DESC);
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", "");
	}
	else
	{   // Get the client id cache section
		ls_nodePath = ls_nodePath = "//" + this.ms_cache_client_id;
		lobj_node = lobj_xmlDom.selectSingleNode(ls_nodePath);
	    if (lobj_node != null)
	    {
			ls_xml = lobj_node.xml;
		}
		else
		{
		   // node does not exist gl_RETRIEVE_NODE_ERR
			this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_RETRIEVE_NODE_ERR);
			this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_RETRIEVE_NODE_ERR_DESC);
		}
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", ls_xml);
		this.mobj_cache.setMPReturn(0)
		this.mobj_cache.setMPSuccessful("True");
	}
	lobj_xmlDom = null;
	return ls_xml;
}

//-----------------------------------------------------------------------------
//	Function __diGetCacheTxt( ) 
// 
//  Purpose: This function is used to Get a single text value of an xml doc,
//           the following information is supplied when constructed, 
//           parent tag name, child tag name and text is returned. If child is 
//           empty then only parent is used.
//
//  Constructor Parameters: 
//  ls_parentNode_name - parent XML node used to cache text/object data
//                     example: "parent"
//  ls_childNode_name  - child XML node used to cache text/object data
//                     example: "child" or empty string "" if not used
//
//	Return: string - if empty "" string check parameters :
//                   gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                 * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//   	var ls_xml = "";
//  	lobj_cache = new wfxClientCache(ls_parentNode_name, ls_childNode_name);	
//  	ls_xml = lobj_cache.getCacheTxt();
//  	if (ls_xml == "") //CHECK ERROR RETURN
//  	{
//  	    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//  	}
//  	else 
//  	{
//  		// *** use XML
//  	}
//  	lobj_cache = null;
//-----------------------------------------------------------------------------
function __diGetCacheTxt( ) 
{
	var bret = false;
	var lobj_xmlDom = null;
	var ls_nodePath = "";
	var ls_xml = "";
	var lobj_node = null;
	
	// check to make sure atleast parent node is populated
	if (this.ms_parent_node == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_PARENT_NODE_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_PARENT_NODE_ERR_DESC);
		return gs_PARENT_NODE_ERR_DESC;
	}
	lobj_xmlDom = new ActiveXObject("Microsoft.XMLDOM");
	lobj_xmlDom.async = false;
	var bret = lobj_xmlDom.load(this.ms_cache_key_value);	
	if (!bret)
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_XML_FILE_LOAD_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_XML_FILE_LOAD_ERR_DESC);
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", "");
	}
	else
	{   
	    // build path based if parent and child
		if (this.ms_child_node == "")
		{
			ls_nodePath = "//" + this.ms_cache_client_id + "/" + this.ms_parent_node;
		}
		else
		{
			ls_nodePath = "//" + this.ms_cache_client_id + "/" + this.ms_parent_node + "/" + this.ms_child_node;
		}
		lobj_node = lobj_xmlDom.selectSingleNode(ls_nodePath);
	    if (lobj_node != null)
	    {
			ls_xml = lobj_node.firstChild.xml;
		}
		else
		{
		   // node does not exist gl_RETRIEVE_NODE_ERR
			this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_RETRIEVE_NODE_ERR);
			this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_RETRIEVE_NODE_ERR_DESC);
		}
		//this.mobj_cache.addCDATA("cache", "", "8");		
		//this.mobj_cache.setCDATA("cache", ls_xml);
		this.mobj_cache.setMPReturn(0)
		this.mobj_cache.setMPSuccessful("True");
	}
	lobj_xmlDom = null;
	lobj_node = null;
	ls_nodePath = null;
	return ls_xml;
}

//-----------------------------------------------------------------------------
//	Function __deGetCacheObj( )
//
//  Purpose: This function is used to Get an object data of an xml doc,
//           the following information is supplied when constructed, 
//           parent tag name, child tag name and the object under the tag is 
//           returned. If child is empty then only parent is used. The object 
//           data is returned in string format.
//
//  Constructor Parameters: 
//  ls_parentNode_name - parent XML node used to cache text/object data
//                     example: "parent"
//  ls_childNode_name  - child XML node used to cache text/object data
//                     example: "child" or empty string "" if not used
//
//	Return: string - if empty "" string check parameters :
//                   gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                 * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//   	var ls_xml = "";
//  	lobj_cache = new wfxClientCache(ls_parentNode_name, ls_childNode_name);	
//  	ls_xml = lobj_cache.getCacheObj();
//  	if (ls_xml == "") //CHECK ERROR RETURN
//  	{
//  	    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//  	}
//  	else 
//  	{
//  		// *** use XML
//  	}
//  	lobj_cache = null;
//-----------------------------------------------------------------------------
function __diGetCacheObj( ) 
{
	var bret = false;
	var lobj_xmlDom = null;
	var ls_nodePath = "";
	var ls_xml = "";
	var lobj_node = null;
	
	// check to make sure atleast parent node is populated
	if (this.ms_parent_node == "")
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_PARENT_NODE_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_PARENT_NODE_ERR_DESC);
		return gs_PARENT_NODE_ERR_DESC;
	}
	lobj_xmlDom = new ActiveXObject("Microsoft.XMLDOM");
	lobj_xmlDom.async = false;
	var bret = lobj_xmlDom.load(this.ms_cache_key_value);	
	if (!bret)
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_XML_FILE_LOAD_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_XML_FILE_LOAD_ERR_DESC);
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", "");
	}
	else
	{   
	    // build path based if parent and child
		if (this.ms_child_node == "")
		{
			ls_nodePath = "//" + this.ms_cache_client_id + "/" + this.ms_parent_node;
		}
		else
		{
			ls_nodePath = "//" + this.ms_cache_client_id + "/" + this.ms_parent_node + "/" + this.ms_child_node;
		}
		lobj_node = lobj_xmlDom.selectSingleNode(ls_nodePath);
	    
	    if (lobj_node != null)
	    {
			ls_xml = lobj_node.firstChild.xml;
		}
		else
		{
		   // node does not exist gl_RETRIEVE_NODE_ERR
			this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_RETRIEVE_NODE_ERR);
			this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_RETRIEVE_NODE_ERR_DESC);
		}
		//this.mobj_cache.addCDATA("cache", "", "8");		
		//this.mobj_cache.setCDATA("cache", ls_xml);
		this.mobj_cache.setMPReturn(0)
		this.mobj_cache.setMPSuccessful("True");
	}
	lobj_xmlDom = null;
	lobj_node = null;
	ls_nodePath = null;
	return ls_xml;
}

//-----------------------------------------------------------------------------
//	Function __diGetMachineCache( ) 
// 
//  Purpose: This function is used to Get the entire machine xml cache and it 
//           stores the data in the CDATA section "cache", it also returns the 
//           XML in string format.
//  ** CDATA population only happens on getCache() and getMachineCache()
//    
//	Return: string - if empty "" string check parameters :
//                   gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                 * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
//   	var ls_xml = "";
//  	lobj_cache = new wfxClientCache();	
//  	ls_xml = lobj_cache.getMachineCache();
//  	if (ls_xml == "") //CHECK ERROR RETURN
//  	{
//  	    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//  	}
//  	else 
//  	{
//  		// *** use XML
//  	}
//  	lobj_cache = null;
//-----------------------------------------------------------------------------
function __diGetMachineCache( ) 
{
	var bret = false;
	var lobj_xmlDom = null;
	//this.mobj_cache.setMPName("LoadCache");	
	lobj_xmlDom = new ActiveXObject("Microsoft.XMLDOM");
	lobj_xmlDom.async = false;
	var bret = lobj_xmlDom.load(this.ms_cache_key_value);
	if (!bret)
	{
		this.mobj_cache.setParameter(gs_RETURN_PARAM, gl_XML_FILE_LOAD_ERR);
		this.mobj_cache.setParameter(gs_RETURN_DESCRIPTION_PARAM, gs_XML_FILE_LOAD_ERR_DESC);
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", "");
	}
	else
	{
		this.mobj_cache.addCDATA("cache", "", "8");		
		this.mobj_cache.setCDATA("cache", lobj_xmlDom.xml);
		this.mobj_cache.setMPReturn(0)
		this.mobj_cache.setMPSuccessful("True");
	}
	lobj_xmlDom = null;
	return this.mobj_cache.getCDATA("cache");
}

//-----------------------------------------------------------------------------
//	Function : __diDeleteInstanceCache( )
//
//  Purpose : This function is used to delete the parent/root browser instance
//            cache when closing the browser window and logging out. Be careful 
//            calling this function, because if there is application data cached
//            for a specific window it will be removed
//
//  Constructor Parameters: 
//	                             
//	Return: true/false - if false check parameters:
//                       gs_RETURN_PARAM and gs_RETURN_DESCRIPTION_PARAM
//                     * secondary error check is in DOM of method package
//
//  Example: 
//		var lobj_cache = null; 
// 	    lobj_cache = new wfxClientCache(); 
//      if ( !lobj_cache.deleteInstanceCache() )
//   	{   //CHECK ERROR RETURN
//		    alert(lobj_cache.mobj_cache.getParameter(gs_RETURN_PARAM) + " : " + 
//                lobj_cache.mobj_cache.getParameter(gs_RETURN_DESCRIPTION_PARAM));
//		}
//	    lobj_cache = null;
//-----------------------------------------------------------------------------
function __diDeleteInstanceCache( ) 
{
	var lobj_errorHandler = null;	
	
	//this.mobj_cache.copySecure(IncomingPageXML);
	this.mobj_cache.addParam("Action", 8, "deleteinstance");
	this.mobj_cache.setParameter(gs_CACHE_FILE_LOCATION_PARAM, this.ms_cache_key_value);
	this.mobj_cache.setParameter(gs_CACHE_CLIENT_ID, this.ms_cache_client_id);
	this.mobj_cache.sendDataHTTP("wfx_upd_cache.asp", true);
    
    // convert the string return to a xmlDOM object
	var lobj_error_dom = new wfxDom( this.mobj_cache.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		/*var lobj_error_handler;
		lobj_error_handler = new wfxErrorHandler();
		lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		lobj_error_handler = null;
		lobj_error_dom = null;*/
		return false;	
	}
	lobj_error_dom = null;
	return true;	
}

//-----------------------------------------------------------------------------
//	Purpose: This function will create the filepath in the form URL/Guid.xml 
//           file which contains the cached data on the web server, it is used 
//           during the construction of the object and modification of cache.
//       **  This function is internal to this object.
//-----------------------------------------------------------------------------
function __diCreateCookieKey() 
{
	var lobj_xml = new wfxDom();
	var ls_cookieKey;
	//lobj_xml.copySecure(IncomingPageXML);
	lobj_xml.addParam("Action", 8, "createcookiekey");
	lobj_xml.sendDataHTTP("wfx_upd_cache.asp", true);
	var lobj_error_dom = new wfxDom( lobj_xml.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		/*var lobj_error_handler;
		lobj_error_handler = new wfxErrorHandler();
		lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		lobj_error_handler = null;
		lobj_xml = null;
		lobj_error_dom = null;*/
		return false;	
	}
	// this has to be done here for the variables to retain their value 
	// associated to the object
	this.ms_cache_key = gs_cache_key;
	gs_cache_key_value = lobj_xml.getParameter(gs_COOKIE_CACHE_KEY);
	lobj_xml = null;
	lobj_error_dom = null;
	return true;
}

//-----------------------------------------------------------------------------
//	Purpose: This function sets the client side cookie that contains the 
//           URL/guid.xml location and also sets the expiration of the cookie.
//       **  This function is internal to this object.
//-----------------------------------------------------------------------------
function __diSetGuidCookie( )
{
	var dt;
	var dtExpiration;
	// initialize two dates for comparison
	dt = new Date();
	dtExpiration = new Date();
	// set expiration date to 4:00 AM
	dtExpiration.setHours(gs_hour_cmp, gs_min_cmp, gs_sec_cmp);
	
	// if between 12:00 AM and Expiration time of today set the expiration to 
	// today 4:00 AM else if after Expiration today set to tomorrow Expiration, 
	// cookies expire at Expiration becasue we will be running a scheduled job 
	// to clean up the cache xml files
	if (dt.valueOf() < dtExpiration.valueOf())
	{
		SetCookie(this.ms_cache_key, gs_cache_key_value, dtExpiration);
	}
	else
	{
		// move the expiration date to tomorrow at 4:00 AM and set cookie
		dtExpiration.setDate(dtExpiration.getDate() + 1);
		SetCookie(this.ms_cache_key, gs_cache_key_value, dtExpiration);
	}
	// DEBUGGING INFO ON CACHE FILE NAME
	// alert(this.ms_cache_key + " : " + gs_cache_key_value + " : " + dtExpiration);
	
	// set dates to null
	dt = null;
	dtExpiration = null;
}

//-----------------------------------------------------------------------------
//	Function __diCheckWindowName()
//
//  Purpose: This function is interal to this object and checks to see if 
//           window.name has value, if not then window.name is set.
//
//	Return: nothing
//
//-----------------------------------------------------------------------------
function __diCheckWindowName()
{
	var ls_window_name = "";
	ls_window_name = window.name;
	if (ls_window_name == "")
	{
        window.name = createNodeGUID();
		this.ms_cache_client_id = window.name;
	}
}

//-----------------------------------------------------------------------------
//	Function createNodeGUID()
//
//  Purpose: This function creates a GUID and returns to calling client, this 
//           is used to set the window.name that will create a unique 
//           root/parent in the machine xml cache file. The returned GUID is 
//           is used as a parent and an "A" is added to the front of the GUID
//           so there is no failure when adding the node if there should be
//           a number as the first character.
//
//	Return: string - if string empty "" check error in DOM of method package
//
//  Example: 
//   	var ls_guid = "";
//  	ls_guid = createNodeGUID()
//  	if (ls_guid == "") //CHECK ERROR RETURN
//  	{
//  	    check for MP DOM error
//  	}
//-----------------------------------------------------------------------------
function createNodeGUID()
{
	var lobj_xml = new wfxDom();
	var ls_guidName;
	//lobj_xml.copySecure(IncomingPageXML);
	lobj_xml.addParam("Action", 8, "createguid");
	lobj_xml.sendDataHTTP("wfx_upd_cache.asp", true);
	var lobj_error_dom = new wfxDom( lobj_xml.domObj.xml );	
	var lb_successful = lobj_error_dom.getMPSuccessful();
	if ( ! lb_successful ) 
	{
		//var lobj_error_handler;
		//lobj_error_handler = new wfxErrorHandler();
		//lobj_error_handler.checkErrors( lobj_error_dom.domObj );
		//lobj_error_handler = null;
		//lobj_xml = null;
		//lobj_error_dom = null;
		return "";	
	}
	
	// This is done in case first value of GUID is number, XML nodes cannot be numbers
	ls_guidName = "A";
	ls_guidName = ls_guidName + lobj_xml.getParameter("guid");
	lobj_xml = null;
	lobj_error_dom = null;
	return ls_guidName;
}


