hwc-comms.js

1       /**
2        * Sybase Hybrid App version 2.3.4
3        * 
4        * API.js
5        * This file will not be regenerated, so it is possible to modify it, but it
6        * is not recommended.
7        *
8        * The template used to create this file was compiled on Thu Jun 07 14:57:11 EDT 2012
9        * 
10       * Copyright (c) 2012 Sybase Inc. All rights reserved.
11       */
12      
13      /** 
14       * Holds all the Hybrib Web Container javascript 
15       * @namespace 
16       */
17      hwc = (typeof hwc === "undefined" || !hwc) ? {} : hwc;      // SUP 'namespace'
18      
19      /**
20       * Global Legacy Mapping
21       * Needed because called by generated HTML or hardcoded in workflow.js or XBWUtil.java or in container callbacks.
22       */
23      
24      /**
25       * @deprecated Deprecated since version 2.2 - use hwc.guid()
26       */
27      function guid()               { return hwc.guid(); }
28      
29      /**
30       * @deprecated Deprecated since version 2.2 - use hwc.getXMLHTTPRequest()
31       */
32      function getXMLHTTPRequest()  { return hwc.getXMLHTTPRequest(); }
33      
34      /**
35       * @deprecated Deprecated since version 2.2 - use hwc.log(sMsg, eLevel, notifyUser)
36       */
37      function logToWorkflow(sMsg, eLevel, notifyUser) { return hwc.log(sMsg, eLevel, notifyUser); }
38      
39      /**
40       * @deprecated Deprecated since version 2.2 - use hwc.close()
41       */
42      function closeWorkflow()            { return hwc.close(); }
43      
44      /**
45       * @deprecated Deprecated since version 2.2 - use hwc.clearCacheItem( cachekey )
46       */
47      function clearCacheItem( cachekey ) { return hwc.clearCacheItem( cachekey ); }
48      
49      /**
50       * @deprecated Deprecated since version 2.2 - use hwc.clearCache()
51       */
52      function clearCache()               { return hwc.clearCache(); }
53      
54      /**
55       * @deprecated Deprecated since version 2.2 - use hwc.close()
56       */
57      function expireCredentials()        { return hwc.expireCredentials(); }
58      
59      /**
60       * @deprecated Deprecated since version 2.2 - use hwc.showCertificatePicker()
61       */
62      function showCertificatePicker()    { return hwc.showCertificatePicker(); }
63      
64      /**
65       * @deprecated Deprecated since version 2.2 - use hwc.saveLoginCertificate(certificate)
66       */
67      function saveLoginCertificate(certificate)         { return hwc.saveLoginCertificate(certificate); }
68      
69      /**
70       * @deprecated Deprecated since version 2.2 - use hwc.saveLoginCredentials(userName, password)
71       */
72      function saveLoginCredentials(userName, password)  { return hwc.saveLoginCredentials(userName, password); }
73      
74      /**
75       * @deprecated Deprecated since version 2.2 - use hwc.activationRequired()
76       */
77      function activationRequired()       { return hwc.activationRequired(); }
78      
79      /**
80       * @deprecated Deprecated since version 2.2 - use hwc.showUrlInBrowser(url)
81       */
82      function showUrlInBrowser(url)      { return hwc.showUrlInBrowser(url); }
83      
84      /**
85       * @deprecated Deprecated since version 2.2 - use hwc.markAsProcessed()
86       */
87      function markAsProcessed()      { return hwc.markAsProcessed(); }
88      
89      /**
90       * @deprecated Deprecated since version 2.2 - use hwc.markAsActivated()
91       */
92      function markAsActivated()      { return hwc.markAsActivated(); }
93      
94      /**
95       * Delegate for data message processing details.
96       * In the custom case, the user is expected to provide their own implemenation.
97       * In the default SUP HybridApp case, this updates values then sets the next screen to navigate to.
98       * @param {string} incomingDataMessageValue The XML formatted string for the incoming message
99       * @param {boolean} noUI true if this has no UI
100      * @param {boolean} loading If true, this is being called while the application is loading
101      * @param {boolean} fromActivationFlow If true, this is being called from within an activation flow
102      * @param {string} dataType If supplied, the data type of the value display on target screen
103      */
104     function processDataMessage(incomingDataMessageValue, noUI, loading, fromActivationFlow, dataType) {
105         if( typeof(hwc.processDataMessage) === 'function' ) {
106             return hwc.processDataMessage(incomingDataMessageValue, noUI, loading, fromActivationFlow, dataType);
107         }
108         else {
109             // get the users attention
110             hwc.log("Implementation required for hwc.processDataMessage", "ERROR", true);
111             throw new Error("Implementation required for either global processDataMessage or hwc.processDataMessage");
112         }
113     }
114     
115     /**
116      * @deprecated Deprecated since version 2.2 - use hwc.processDataMessage(incomingDataMessageValue, noUI, loading, fromActivationFlow, dataType)
117      */
118     function processWorkflowMessage(incomingDataMessageValue, noUI, loading, fromActivationFlow, dataType) {
119         return processDataMessage(incomingDataMessageValue, noUI, loading, fromActivationFlow, dataType);
120     }
121     
122     /**
123      * This function is invoked by the container when there is a native error to report.
124      * Use {@link hwc.setReportErrorFromNative} to set the callback funtion this function will call.
125      * This function is not intended to be called except by the container.
126      * @private
127      * @param {string} errString The string contains error message
128      */
129     function reportErrorFromNative(errString) {
130        var reportErrorCallback = hwc.getReportErrorFromNativeCallback();
131        if( typeof reportErrorCallback === "function" )
132        {
133           reportErrorCallback( errString );
134        }
135     }
136     
137     /**
138      * Container API
139      */
140     (function(hwc, window, undefined) {
141         
142         /**
143          * A number representing the logging level.  The logging level must be an integer from the range [1..4]
144          * with the higher numbers being more verbose.
145          *
146          * @type {number}
147          */
148         var requestedLoggingLevel,
149         /**
150          * A callback function used when {@link hwc.log} is invoked with true for the notifyUser parameter.
151          * This callback should notify the user of the log message in an appropriate manner.
152          *
153          * @type {anonymous.alertDialogCallbackFunction}
154          */
155         requestedAlertDialogCallback,
156         /**
157          * A callback function used when there is a native error to report
158          *
159          * @type {anonymous.errorCallbackFunction}
160          */
161         reportErrorFromNativeCallback;
162         
163         /**
164          * This object contains constants representing the status of the hybrid app.
165          */
166         hwc.STATUS = {};
167         
168         /**
169          * A constant indicating the hybrid app has been closed.
170          * @constant
171          * @type {number}
172          * @member of hwc.STATUS
173          * @public
174          */
175         hwc.STATUS.CLOSED = 1;
176         
177         /**
178          * A constant indicating the hybrid app is running.
179          * @constant
180          * @type {number}
181          * @member of hwc.STATUS
182          * @public
183          */
184         hwc.STATUS.RUNNING = 2;
185         
186         /**
187          * A status representing the hybrid app, default is running.
188          *
189          * @type {number}
190          */
191         var status = hwc.STATUS.RUNNING;
192         
193         /**
194          * This function sets the callback used by hwc.log when it is required to notify the user of a log item.
195          *
196          * @param {anonymous.alertDialogCallbackFunction} newAlertDialogCallback The alert dialog to use.
197          *
198          * @example
199          * customLogAlert = function( message )
200          * {
201          *    alert( "New log message: " + message );
202          * }
203          * hwc.setLoggingAlertDialog( customLogAlert );
204          * @memberOf hwc
205          * @public
206          */
207         hwc.setLoggingAlertDialog = function( newAlertDialogCallback )
208         {
209             requestedAlertDialogCallback = newAlertDialogCallback;
210         };
211         
212         /**
213          * This function gets the callback used by hwc.log when it is required to notify the user of a log item.
214          *
215          * @memberOf hwc
216          * @public
217     	 * @returns {anonymous.alertDialogCallbackFunction} The alert dialog callback function.
218          */
219         hwc.getLoggingAlertDialog = function()
220         {   
221             return requestedAlertDialogCallback;
222         };
223         
224         /**
225          * This function sets the logging level. The logging level set with this function only persists as long as this javascript context does.
226          * When the hybrid app is closed, the value set with this function is lost.
227          * @memberOf hwc
228          * @public
229          * @param {number} newLoggingLevel The number representing the new logging level.
230          * Must be an integer in the range [1..4].  The higher numbers represent more verbose logging levels
231          * from 1 for ERROR level logging up to 4 for DEBUG level logging.
232          * @example
233          * // Set the logging level to debug.
234          * hwc.setLoggingCurrentLevel( 4 );
235          */
236         hwc.setLoggingCurrentLevel = function( newLoggingLevel )
237         {
238             requestedLoggingLevel = newLoggingLevel;
239         };
240     
241         /**
242          * This function gets the logging level.
243          *
244     	 * @memberOf hwc
245          * @public
246          * @returns {number} A number representing the logging level.  Will be an integer in the range [1..4].
247          * The higher numbers represent more verbose logging levels from 1 for ERROR level logging up to 4 for DEBUG level logging.
248          * @example
249          * // Get the logging level
250          * var loggingLevel = hwc.getLoggingCurrentLevel();
251          */
252         hwc.getLoggingCurrentLevel = function() {
253             var logLevel;
254             if (requestedLoggingLevel === undefined) {
255                 logLevel = hwc.getQueryVariable("loglevel");
256                 requestedLoggingLevel = logLevel ? parseInt(logLevel, 10) : 1;
257             }
258             return requestedLoggingLevel; 
259         };
260         
261         /**
262          * This function sets the callback function called when there is a native error reported.
263          * Calling this function will replace any callback that had been set previously.
264          * @memberOf hwc
265          * @public
266     	 * @param {function} callbackToSet The callback function.
267          * @example
268          * var errorCallback = function( errorString )
269          * {
270          *    alert( "There was a native error: " + errorString );
271          * }
272          * hwc.setReportErrorFromNativeCallback( errorCallback );
273          */
274         hwc.setReportErrorFromNativeCallback = function( callbackToSet )
275         {
276             reportErrorFromNativeCallback = callbackToSet;
277         };
278         
279         /**
280          * This function returns the callback function that will be called by {@link reportErrorFromNative}.
281          * This function is not intended to be called by any function but {@link reportErrorFromNative}.
282          * @private
283     	 * @returns {function} The callback function.
284          */
285         hwc.getReportErrorFromNativeCallback = function()
286         {
287             return reportErrorFromNativeCallback;
288         };
289     
290         /**
291          * This function looks in the query string on the URL for the value corresponding to the given name.
292          *
293     	 * @memberOf hwc
294          * @public
295          * @param {string} variable The name of the variable in the URL to retrieve the value for.
296     	 * @returns {string} The value corresponding to the given name.
297          * @example
298          * // Get the pageToShow variable from the URL query string
299          * var pageToShow = hwc.getQueryVariable( "pageToShow" );
300          */
301         hwc.getQueryVariable = function(variable) {
302             var query, vars, i, pair;
303             query = window.location.search.substring(1);
304             vars = query.split("&");
305             for (i = 0; i < vars.length; i++) {
306                 pair = vars[i].split("=");
307                 if (pair[0] === variable) {
308     				return unescape(pair[1]);
309                 }
310             }
311         };
312         
313     
314     /**
315      * This object contains constants representing the different types of public native error codes.
316      * Error codes larger than 500 are reserved for server communication errors which may occur as the result of online requests and/or attachment downloads
317      *
318      * @namespace
319      */
320     hwc.NativeErrorCodes = {};
321     /**
322      * A constant indicating there was an unknown error.
323      *
324      * @constant
325      *
326      * @type {number}
327      * @memberOf hwc.NativeErrorCodes
328      * @public
329      */
330     hwc.NativeErrorCodes.UNKNOWN_ERROR = 1;
331     /**
332      * A constant indicating the attachment has not been downloaded.
333      *
334      * @type {number}
335      * @memberOf hwc.NativeErrorCodes
336      * @public
337      */
338     hwc.NativeErrorCodes.ATTACHMENT_NOT_DOWNLOADED = 100;
339     /**
340      * A constant indicating there was an unkown MIME type.
341      *
342      * @type number
343      * @memberOf hwc.NativeErrorCodes
344      * @public
345      */
346     hwc.NativeErrorCodes.UNKNOWN_MIME_TYPE = 101;
347     /**
348      * A constant indicating there was a filename without an extension.
349      *
350      * @type {number}
351      * @memberOf hwc.NativeErrorCodes
352      * @public
353      */
354     hwc.NativeErrorCodes.FILENAME_NO_EXTENSION = 102;
355     /**
356      * A constant indicating a required parameter was not available.
357      *
358      * @type {number}
359      * @memberOf hwc.NativeErrorCodes
360      * @public
361      */
362     hwc.NativeErrorCodes.REQUIRED_PARAMETER_NOT_AVAILABLE = 103;
363     /**
364      * A constant indicating there was no certificate selected by the user.
365      *
366      * @type {number}
367      * @memberOf hwc.NativeErrorCodes
368      * @public
369      */
370     hwc.NativeErrorCodes.CERTIFICATE_NOT_SELECTED = 104;
371     /**
372      * A constant indicating the attachment type is not supported.
373      *
374      * @type {number}
375      * @memberOf hwc.NativeErrorCodes
376      * @public
377      */
378     hwc.NativeErrorCodes.UNSUPPORTED_ATTACHMENT_TYPE = 105;
379     /**
380      * A constant indicating there was an SSO certificate manager exception.
381      *
382      * @type {number}
383      * @memberOf hwc.NativeErrorCodes
384      * @public
385      */
386     hwc.NativeErrorCodes.SSOCERT_EXCEPTION = 106;
387     /**
388      * A constant indicating a failure to save a credential.
389      *
390      * @type {number}
391      * @memberOf hwc.NativeErrorCodes
392      * @public
393      */
394     hwc.NativeErrorCodes.FAIL_TO_SAVE_CREDENTIAL = 107;
395     /**
396      * A constant indicating a failure to save a certificate.
397      *
398      * @type {number}
399      * @memberOf hwc.NativeErrorCodes
400      * @public
401      */
402     hwc.NativeErrorCodes.FAIL_TO_SAVE_CERTIFICATE = 108;
403     /**
404      * A constant indicating the device is not connected.
405      *
406      * @type {number}
407      * @memberOf hwc.NativeErrorCodes
408      * @public
409      */
410     hwc.NativeErrorCodes.DEVICE_NOT_CONNECTED = 109;
411     /**
412      * A constant indicating the response it too large for a javascript variable.
413      *
414      * @type {number}
415      * @memberOf hwc.NativeErrorCodes
416      * @public
417      */
418     hwc.NativeErrorCodes.RESPONSE_TOO_LARGE = 110;
419     /**
420      * A constant indicating that opening the URL failed.
421      *
422      * @type {number}
423      * @memberOf hwc.NativeErrorCodes
424      * @public
425      */
426     hwc.NativeErrorCodes.NAVIGATION_ERROR = 111;
427     /**
428      * A constant indicating an invalid common name was passed while requesting a certificate from Afaria.
429      *
430      * @type {number}
431      * @memberOf hwc.NativeErrorCodes
432      * @public
433      */
434     hwc.NativeErrorCodes.INVALID_COMMON_NAME = 112;
435     
436     
437     
438     /**
439      * A utility function for use in generating a GUID
440      *
441      * @private
442      * @returns {string} The generated GUID.
443      */
444     function S4() {
445         return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
446     }
447     
448     /**
449      * This function generates a GUID (globally unique identifier).
450      *
451      * @memberOf hwc
452      * @public
453      * @returns {string} The generated GUID.
454      * @example
455      * var globallyUniqueName = hwc.guid();
456      */
457     hwc.guid = function() {
458         return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
459     };
460     
461     /**
462      * Reliably returns an XMLHttpRequest object regardless of what platform this code is being executed on.
463      *
464      * @memberOf hwc
465      * @public
466      * @returns {object} An XMLHTTPRequest object.
467      * @example
468      * var request = hwc.getXMLHTTPRequest();
469      */
470     hwc.getXMLHTTPRequest = function getXMLHTTPRequest() {
471         // 
472     	/* 
473     	SMPONP-9439
474     	Avoid this endless loop:
475     		hwc.log()
476     		at hwc.traceEnteringMethod()
477     		at hwc.getXMLHTTPRequest()
478     		at hwc.postDataToContainer()
479     		at hwc.log()
480     	*/
481     	//hwc.traceEnteringMethod("hwc.getXMLHTTPRequest");
482     	try {
483     		var xmlHttpReq;
484     		if (window.XMLHttpRequest) {
485     			xmlHttpReq = new XMLHttpRequest();
486     		}
487     		else {// code for IE6, IE5
488     			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
489     		}
490     		return xmlHttpReq;
491     	} finally {
492     		//hwc.traceLeavingMethod("hwc.getXMLHTTPRequest");
493     	}
494     };
495     
496     
497     /****************** Hybrid App NATIVE FUNCTIONS ************************/
498     
499     /**
500      * Sets the title of the screen.
501      *
502      * @memberOf hwc
503      * @public
504      * @param {string} screenTitle The screen title to use.
505      * @example
506      * hwc.setScreenTitle_CONT( "Custom Screen Title" );
507      */
508     hwc.setScreenTitle_CONT = function(screenTitle) {
509     	hwc.traceEnteringMethod("hwc.setScreenTitle_CONT");
510     	try {
511     		if (hwc.isWindows()) {
512     			document.title = screenTitle; 
513     		}      
514     		else {
515     			 if (hwc.isIOS() || hwc.isAndroid()) {
516     				 hwc.getDataFromContainer("setscreentitle", "&title=" + encodeURIComponent(screenTitle));
517     			  }
518     			  else {
519     				 hwc.postDataToContainer("setscreentitle", "&title=" + encodeURIComponent(screenTitle));
520     			  }
521     		}
522     	} finally {
523     		hwc.traceLeavingMethod("hwc.setScreenTitle_CONT");
524     	}
525     };
526     
527     /**
528      * This class represents a collection of menu items.
529      * @memberOf hwc
530      * @public
531      * @classdesc
532      * @example
533      * // This is the function we'll use as a callback for the first menu item.
534      * var callback = function()
535      * {
536      *    alert( "You clicked the first menu item!" );
537      * }
538      * 
539      * // This is the function we'll use as a callback for the second menu item.
540      * var callback2 = function()
541      * {
542      *    alert( "You clicked the second menu item!" );
543      * }
544      *
545      * // This function creates and adds a menu item collection.
546      * var addMenuItems = function()
547      * {
548      *    var menuItemCollection = new hwc.MenuItemCollection();
549      *    menuItemCollection.addMenuItem("menu item 1", "callback()");
550      *    menuItemCollection.addMenuItem("menu item 2", "callback2()");
551      *    hwc.addMenuItemCollection( menuItemCollection );
552      * }
553      */
554     hwc.MenuItemCollection = function() {
555         this.menuItems = [];
556         this.subMenuName = null;
557         this.okAction = null;
558     };
559     
560     /**
561      * This function adds a menu item to the collection.
562      *
563      * @memberOf hwc.MenuItemCollection
564      * @public
565      * @param {string} title The display text for the menu item.
566      * @param {anonymous.genericCallbackFunction} callback The function to call when the menu item is clicked.
567      * @param {boolean} [isDefault] Determines if the menu item is selected by default on BlackBerry.
568      * If more than one menu item is added to the same collection with true for this parameter, the
569      * last menu item added with true for this parameter will be selected by default on Blackberry.
570      * @example
571      * var callbackFunctionName = function()
572      * {
573      *    alert( "Menu item clicked!" );
574      * }
575      * var menuItemCollection = new hwc.MenuItemCollection();
576      * menuItemCollection.addMenuItem("menu item name", "callbackFunctionName()", true);
577      * 
578      */
579     hwc.MenuItemCollection.prototype.addMenuItem = function(title, callback, isDefault) {
580     	hwc.traceEnteringMethod("hwc.MenuItemCollection.addMenuItem");
581     	try {
582     		this.menuItems.push( { "name" : title, "action" : callback, "default" : isDefault ? "true" : "false" } );
583     	} finally {
584     		hwc.traceLeavingMethod("hwc.MenuItemCollection.addMenuItem");
585     	}
586     };
587          
588     /**
589      * This function sets the sub menu name to use on Windows Mobile.
590      *
591      * @memberOf hwc.MenuItemCollection
592      * @public
593      * @param {string} name The sub menu name to use.
594      * @example
595      * var callbackFunctionName = function()
596      * {
597      *    alert( "Menu item clicked!" );
598      * }
599      * var menuItemCollection = new hwc.MenuItemCollection();
600      * menuItemCollection.setSubMenuName( "Custom Menu" );
601      * menuItemCollection.addMenuItem("menu item name", "callbackFunctionName()");
602      */
603     hwc.MenuItemCollection.prototype.setSubMenuName = function(name) {
604         this.subMenuName = name;
605     };
606         
607     /**
608      * This function sets the OK action to use on WM.
609      * @memberOf hwc.MenuItemCollection
610      * @public
611      * @param {anonymous.genericCallbackFunction} callback The function to call when the OK button is pressed.
612      *
613      * @example
614      * var callbackFunctionName = function()
615      * {
616      *    alert( "Menu item clicked!" );
617      * }
618      * var okActionFunction = function()
619      * {
620      *    alert( "A OKAY!" );
621      * }
622      * var menuItemCollection = new hwc.MenuItemCollection();
623      * menuItemCollection.setOKAction( "okActionFunction()" );
624      * menuItemCollection.addMenuItem("menu item name", "callbackFunctionName()");
625      */
626     hwc.MenuItemCollection.prototype.setOKAction = function(callback) {
627         this.okAction = callback;
628     };
629     
630     /**
631      * This function converts the menu item collection to a JSON string.  This function
632      * is used as a helper for {@link hwc.addMenuItemCollection}.
633      *
634      * @memberOf hwc.MenuItemCollection
635      * @public
636      * @returns {string} The JSON string representing this menu item collection.
637      * @example
638      * var callbackFunctionName = function()
639      * {
640      *    alert( "Menu item clicked!" );
641      * }
642      * var menuItemCollection = new hwc.MenuItemCollection();
643      * var jsonMenuItemCollection = menuItemCollection.stringify();
644      */
645     hwc.MenuItemCollection.prototype.stringify = function()
646     {
647         return JSON.stringify({
648             "menuitems" : this.menuItems,
649             "submenuname" : this.subMenuName,
650             "OK" : this.okAction
651         }); 
652     };
653     
654     /**
655      * This function adds a menu item collection to the menu items for the screen.
656      *
657      * @memberOf hwc
658      * @public
659      * @param {hwc.MenuItemCollection} collection The collection of menu items to add to the screen.
660      * @example
661      * var callbackFunctionName = function()
662      * {
663      *    alert( "Menu item clicked!" );
664      * }
665      * var menuItemCollection = new hwc.MenuItemCollection();
666      * menuItemCollection.addMenuItem("menu item name", "callbackFunctionName()");
667      * hwc.addMenuItemCollection( menuItemCollection );
668      */
669     hwc.addMenuItemCollection = function(collection) {
670     	hwc.traceEnteringMethod("hwc.addMenuItemCollection");
671     	try {
672     		if (isBlackBerry() || isWindowsMobile() || isAndroid()) {
673     			var request = "menuitems=" + encodeURIComponent(collection.stringify());
674     			  hwc.postDataToContainer("addallmenuitems", request);
675     		}
676     	} finally {
677     		hwc.traceLeavingMethod("hwc.addMenuItemCollection");
678     	}
679     };
680     
681     /**
682      * Allows the user to add a menuitem with the specified name and with the specified
683      * callback, which will be invoked when the menuitem is clicked.  This function should
684      * only be used in hybrid apps generated with the Unwired Workspace designer.
685      *
686      * @memberOf hwc
687      * @private
688      *
689      * @param {string} menuItemName The specified menuitem name.
690      * @param {string} functionName The string representing the call to the {@link anonymous.genericCallbackFunction} callback function.
691      * @param {string} subMenuName The specific sub-menu name for Windows Mobile.
692      * @param {string} screenToShow The screen about to be shown.
693      * @param {string} [menuItemKey] The menuItem's key.
694      * @example
695      * var callbackFunction = function()
696      * {
697      *    alert( "Menu Item Clicked!" );
698      * }
699      * hwc.addMenuItem_CONT( "Custom Menu Item", "callbackFunction()", "Custom Sub Menu", "Start" );
700      */
701     hwc.addMenuItem_CONT = function(menuItemName, functionName, subMenuName, screenToShow, menuItemKey) {
702         var div, menuStr, idxOfMenuItemName, comma, request;
703     	hwc.traceEnteringMethod("hwc.addMenuItem_CONT");
704     	try {
705     		//first add the item to sup_menuitems
706     		div = document.getElementById(screenToShow + "ScreenDiv");
707     		menuStr = div.getAttribute("sup_menuitems");
708     		idxOfMenuItemName = menuStr.indexOf(menuItemName);
709     		if (idxOfMenuItemName !== -1) {
710     			return;
711     		}
712     		comma = (menuStr.length > 0) ? "," : "";
713     		menuStr = menuStr + comma + menuItemName + "," + menuItemKey;
714     		try {
715     			div.setAttribute("sup_menuitems", menuStr);  //has no affect on Windows Mobile
716     		}
717     		catch (e) {
718     		}
719     
720     		request = "menuitemname=" + encodeURIComponent(menuItemName);
721     		request += ("&onmenuclick=" + encodeURIComponent(functionName) + "()");
722     		if (hwc.isWindowsMobile()) {
723     			request += "&submenuname=";
724     			if (subMenuName) {
725     				request += encodeURIComponent(subMenuName);
726     			}
727     			else {
728     				if (resources) {
729     					request += encodeURIComponent(resources.getString("MENU"));
730     				}
731     				else {
732     					request += "Menu";
733     				}
734     			}
735     			  hwc.postDataToContainer("addMenuItem", request);
736     		}
737     		else if (hwc.isAndroid() || hwc.isBlackBerry()) {
738     			  hwc.postDataToContainer("addMenuItem", request);
739     		}    
740     	} finally {
741     		hwc.traceLeavingMethod("hwc.addMenuItem_CONT");
742     	}
743     };
744     
745     
746     /**
747      * This function removes all menu items that were added by the hybrid app.
748      * Note: This API does not support on iOS platform.
749      * @memberOf hwc
750      * @public
751      * @example
752      * hwc.removeAllMenuItems();
753      */
754     hwc.removeAllMenuItems = function() {
755     	hwc.traceEnteringMethod("hwc.removeAllMenuItems");
756     	try {
757     		if (hwc.isAndroid() || hwc.isWindowsMobile() || hwc.isBlackBerry() ) {
758     			hwc.getDataFromContainer("removeallmenuitems");
759     		} 
760     	} finally {
761     		hwc.traceLeavingMethod("hwc.removeAllMenuItems");
762     	}
763     };
764     
765     /**
766      * This function sets the activation required state of this hybrid app to true.  After calling this
767      * function, the current hybrid app will need to be activated.
768      * @memberOf hwc
769      * @public
770      * @example
771      * hwc.activationRequired();
772      */
773     hwc.activationRequired = function() {
774     	hwc.traceEnteringMethod("hwc.activationRequired");
775     	try {
776     		hwc.getDataFromContainer("requiresactivation");      
777     	} finally {
778     		hwc.traceLeavingMethod("hwc.activationRequired");
779     	}
780     };
781     
782     /**
783      * This function sets the activation required state for the current hybrid app to false.  After calling this
784      * function, the current hybrid app will not need to be activated.
785      * @memberOf hwc
786      * @public
787      * @example
788      * hwc.markAsActivated();
789      */
790     hwc.markAsActivated = function() {
791     	hwc.traceEnteringMethod("hwc.markAsActivated");
792     	try {
793     		hwc.getDataFromContainer("markasactivated");     
794     	} finally {
795     		hwc.traceLeavingMethod("hwc.markAsActivated");
796     	}
797     };
798     
799     /**
800      * Allows the user to set the processed state to true for the current message.
801      * @memberOf hwc
802      * @public
803      * @example
804      * hwc.markAsProcessed()
805      */
806     hwc.markAsProcessed = function() {
807     	hwc.traceEnteringMethod("hwc.markAsProcessed");
808     	try {
809     		hwc.getDataFromContainer("markasprocessed");
810     	} finally {
811     		hwc.traceLeavingMethod("hwc.markAsProcessed");
812     	}
813     };
814     
815     /**
816      * Allows the user to set the credentials to the expired state for the current hybrid app.
817      * @memberOf hwc
818      * @public
819      * @example
820      * hwc.expireCredentials();
821      */
822     hwc.expireCredentials = function() {
823     	hwc.traceEnteringMethod("hwc.expireCredentials");
824     	try {
825     		hwc.getDataFromContainer("expirecredentials");   
826     	} finally {
827     		hwc.traceLeavingMethod("hwc.expireCredentials");
828     	}
829     };
830     
831     /**
832      * This function clears the contents of the on-device request result cache for the current hybrid app.
833      * @memberOf hwc
834      * @public
835      * @example
836      * hwc.clearCache();
837      */
838     hwc.clearCache = function() {
839     	hwc.traceEnteringMethod("hwc.clearCache");
840     	try {
841     		hwc.getDataFromContainer("clearrequestcache");
842     	} finally {
843     		hwc.traceLeavingMethod("hwc.clearCache");
844     	}
845     	
846     };
847     
848     /**
849      * This function clears an item from the contents of the on-device request result cache for the current hybrid app.
850      *
851      * @memberOf hwc
852      * @public 
853      * @param {string} cachekey The key for the cache item to be removed.  This is the same key that was passed to hwc.doOnlineRequest.
854      * @example
855      * // The cache key is set when calling hwc.doOnlineRequest_CONT
856      * hwc.doOnlineRequest( ., ., ., ., ., ., ., cacheKey, ., .);
857      * // At some later point if we want to clear the cache for the above request, we use the following code:
858      * hwc.clearCacheItem( cacheKey );
859      */
860     hwc.clearCacheItem = function( cachekey ) {
861         var request;
862     	hwc.traceEnteringMethod("hwc.clearCacheItem");
863     	try {
864     		request = "cachekey=" + encodeURIComponent(cachekey);
865     	   
866     		hwc.postDataToContainer("clearrequestcacheitem", request);
867     	} finally {
868     		hwc.traceLeavingMethod("hwc.clearCacheItem");
869     	}
870     };
871     
872     
873     /**
874      * Allows the user to log a message to the device trace log which can be remotely retrieved from the server. 
875      * Whether the message actually gets logged will depend on how the log level that the administrator has selected
876      * for this device user compares with the log level of this message.
877      * The logging level and alert dialog callback can be set with {@link hwc.setLoggingCurrentLevel} and {@link setLoggingAlertDialog}.
878      *  
879      * @memberOf hwc
880      * @public
881      * @param {string} sMsg The message to be logged.
882      * @param {string} eLevel The error level for this message.  This parameter must be one of: "ERROR", "WARN", "INFO" or "DEBUG".
883      * @param {boolean} notifyUser Whether the logging alert callback will be invoked.  This parameter is independent of the
884      * logging level (the logging alert callback will always be invoked if this is true, and never if this is false).
885      * @example
886      * var logAlert = function( message )
887      * {
888      *    alert( "New log message: " + message );
889      * }
890      * hwc.setLoggingAlertDialog( logAlert );
891      * hwc.setLoggingCurrentLevel( 3 );
892      * // The following will be logged, and the logging alert dialog will be invoked.
893      * hwc.log( "info message notify", "INFO", true );
894      * // The following will be logged, but the logging alert dialog will not be invoked.
895      * hwc.log( "info message", "INFO", false );
896      * // The following will not be logged, but the logging alert dialog will be invoked.
897      * hwc.log( "debug message notify", "DEBUG", true );
898      * // The following will not be logged, and the logging alert dialog will not be invoked.
899      * hwc.log( "debug message", "DEBUG", false );
900      * 
901      */
902     hwc.log = function log(sMsg, eLevel, notifyUser) {
903         var msgLogLevel;
904         if( !sMsg ) {
905             return; 
906         } 
907         if (notifyUser && hwc.getLoggingAlertDialog()) {
908             (hwc.getLoggingAlertDialog())(sMsg);
909         }
910         
911         switch (eLevel) {
912             case "ERROR":
913                 msgLogLevel = 1;
914                 break;
915             case "WARN":
916                 msgLogLevel = 2;
917                 break;
918             case "INFO":
919                 msgLogLevel = 3;
920                 break;
921             case "DEBUG":
922                 msgLogLevel = 4;
923                 break;
924             default:
925                 msgLogLevel = 1;
926         }
927         if((sMsg === "") || (msgLogLevel > hwc.getLoggingCurrentLevel()) || (hwc.isWindows())) {
928             return;
929         }
930     
931         if (hwc.isAndroid()) {
932             _HWC.log(sMsg, msgLogLevel);
933         } else {
934             hwc.postDataToContainer("logtoworkflow", "loglevel=" + msgLogLevel + "&logmessage=" + encodeURIComponent(sMsg));
935         }
936     
937     };
938     
939     /**
940      * This function opens a form on the device that allows the user to specify the credentials for the use of
941      * certificate-based authentication. If the user picks a certificate, then that certificate is saved in the
942      * credentials cache.
943      * @memberOf hwc
944      * @public
945      * @example
946      * hwc.showCertificatePicker();
947      */
948     hwc.showCertificatePicker = function() {
949     	hwc.traceEnteringMethod("hwc.showCertificatePicker");
950     	try {
951     		hwc.getDataFromContainer("showcertpicker");
952     	} finally {
953     		hwc.traceLeavingMethod("hwc.showCertificatePicker");
954     	}
955     };
956     
957     
958     /**
959      * This function saves login credentials from a certificate to the credential cache.
960      * The common name is used for the username and the signed certificate is used for the password.
961      *
962      * @memberOf hwc
963      * @public
964      * @param {object} certificate The values certificate.subjectCN and certificate.signedCertificate must be defined.
965      * @example
966      * var certInfo = {};
967      * certInfo.subjectCN = "sampleCommonName";
968      * certInfo.signedCertificate = "samplePassword";
969      * hwc.saveLoginCertificate( certInfo );
970      */
971     hwc.saveLoginCertificate = function(certificate) {
972     	hwc.traceEnteringMethod("hwc.saveLoginCertificate");
973     	try {
974     		hwc.saveLoginCredentials(certificate.subjectCN, certificate.signedCertificate, true);
975     	} finally {
976     		hwc.traceLeavingMethod("hwc.saveLoginCertificate");
977     	}
978     };
979     
980     /**
981      * This function saves login credentials to the credential cache.
982      *
983      * @memberOf hwc
984      * @public
985      * @param {string} userName The user name to save
986      * @param {string} password The password to save
987      * @example
988      * hwc.saveLoginCredentials( "sampleUserName", "samplePassword" );
989      */
990     hwc.saveLoginCredentials = function(userName, password) {
991         var requestData;
992     	hwc.traceEnteringMethod("hwc.saveLoginCredentials");
993     	try {
994     		requestData = "supusername=" + encodeURIComponent(userName) + "&suppassword=" + encodeURIComponent(password);
995     
996     		if (hwc.isAndroid()) {
997     			_HWC.saveCredentials( userName, password );
998     		}  else {
999     			 hwc.postDataToContainer("savecredential", requestData);
1000    		}
1001    		
1002    	} finally {
1003    		hwc.traceLeavingMethod("hwc.saveLoginCredentials");
1004    	}
1005    };
1006    
1007    /**
1008     * This function opens the supplied URL in a browser.  The browser opens on top of the hybrid app - the
1009     * context of the hybrid app is undisturbed.
1010     *
1011     * @memberOf hwc
1012     * @public
1013     * @param {string} url The URL to be shown in a browser.
1014     * @example
1015     * hwc.showUrlInBrowser( "http://www.google.com" );
1016     */
1017    hwc.showUrlInBrowser = function showUrlInBrowser(url)
1018    {
1019        var idxOfColon;
1020    	hwc.traceEnteringMethod("hwc.showUrlInBrowser");
1021    	try {
1022    		url = hwc.trimSpaces(url, true);
1023    		idxOfColon = url.indexOf(":");
1024    		if (idxOfColon === -1 || (idxOfColon > 7)) {
1025    			url = "http://" + url;
1026    		}
1027    		
1028    		if (hwc.isWindowsMobile() || hwc.isAndroid() || hwc.isIOS() || hwc.isBlackBerry()) {
1029    			hwc.getDataFromContainer("showInBrowser", "&url=" + encodeURIComponent(url));
1030    		} else {
1031    			window.open(url);
1032    		}
1033    	} finally {
1034    		hwc.traceLeavingMethod("hwc.showUrlInBrowser");
1035    	}
1036    };
1037    
1038    /**
1039     * Shows the given file contents in a content-appropriate way. The type of the content is
1040     * supplied by either the MIME type or the filename, at least one of which must be supplied.
1041     * The content itself should be presented as a base64-encoded string. Not all file types may
1042     * be supported on all platforms.
1043     *
1044     * @memberOf hwc
1045     * @public
1046     * @param {string} contents The base-64 encoded version of the binary content of the attachment to be displayed.
1047     * @param {string} mimeType The MIME type of the file.
1048     * @param {string} fileName The name of the file.
1049     * @param {anonymous.genericCallbackFunction} waitDialogCallbackString The callback function used to close a wait dialog once the attachment
1050     * is done opening.
1051     * @example
1052     * var openAttachmentBase64StringPng = function()
1053     * {
1054     *    // How you want get the base 64 encoding of the file is up to you. This string represents a small png image.
1055     *    var data = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA0SURBVFhH7dAxEQAACAMx3CAT6eVQwZKh8/dSmc7n6jN+bQcIECBAgAABAgQIECBAgACBBb3SkJeQ67u1AAAAAElFTkSuQmCC";
1056     *    hwc.showProgressDialog();
1057     *    // Don't have to pass the filename because we are passing the MIME type.
1058     *    hwc.showAttachmentContents_CONT( data, "image/png", null, "hwc.hideProgressDialog()" );
1059     * }
1060     * 
1061     * @example
1062     * var openAttachmentBase64StringTxt = function()
1063     * {
1064     *    // How you want get the base 64 encoding of the file is up to you. This string represents a short text file.
1065     *    var data = "VGhpcyBpcyBwYXJ0IG9mIGEgaHlicmlkIGFwcC4=";
1066     *    // Don't have to pass the MIME type because we are passing the filename.
1067     *    hwc.showAttachmentContents_CONT( data, null, "attach.txt" );
1068     * }
1069     */
1070    hwc.showAttachmentContents_CONT = function(contents, mimeType, fileName, waitDialogCallbackString) {
1071        var request;
1072    	hwc.traceEnteringMethod("hwc.showAttachmentContents_CONT");
1073    	try {
1074    		request = "callback=" + waitDialogCallbackString;
1075    
1076    		if (hwc.isWindowsMobile()) {
1077    			contents = contents.replace(/=/g, "~");
1078    			request += "&Attachmentdata=" + contents;
1079    		} else {
1080    			request += "&Attachmentdata=" + encodeURIComponent(contents);
1081    		}
1082    		if (mimeType) {
1083    			request += "&mimetype=" + encodeURIComponent(mimeType);
1084    		}
1085    		if (fileName) {
1086    		   request += "&filename=" + encodeURIComponent(fileName);
1087    		}
1088    		 
1089    		hwc.postDataToContainer("showattachment", request);
1090    	} finally {
1091    		hwc.traceLeavingMethod("hwc.showAttachmentContents_CONT");
1092    	}
1093    };
1094    
1095    /**
1096     * Shows the given file contents in a content-appropriate way. The type of the content is
1097     * supplied by either the MIME type or the filename, at least one of which must be supplied.
1098     * The content itself will be a unique key supplied earlier to a call to doAttachmentDownload.
1099     * @memberOf hwc
1100     * @public 
1101     * @param {string} uniqueKey The unique key for the attachment.
1102     * @param {string} mimeType The MIME type of the file.
1103     * @param {string} fileName The name of the file.
1104     * @param {string} waitDialogCallbackString string with the value for the 'callback=' parameter. 
1105     */
1106    hwc.showAttachmentFromCache_CONT = function(uniqueKey, mimeType, fileName, waitDialogCallbackString) {
1107        var request;
1108    	hwc.traceEnteringMethod("hwc.showAttachmentFromCache_CONT");
1109    	try {
1110    		request = "callback=" + waitDialogCallbackString;
1111    
1112    		request += "&uniquekey=" + encodeURIComponent(uniqueKey);
1113    		if (mimeType) {
1114    			request += "&mimetype=" + encodeURIComponent(mimeType);
1115    		}
1116    		if (fileName) {
1117    		   request += "&filename=" + encodeURIComponent(fileName);
1118    		}
1119    		 
1120    		hwc.postDataToContainer("showattachment", request);
1121    	} finally {
1122    		hwc.traceLeavingMethod("hwc.showAttachmentFromCache_CONT");
1123    	}
1124    };
1125    
1126    /**
1127     * Shows a local attachment.
1128     *
1129     * @memberOf hwc
1130     * @public
1131     * @param {string} key The key of the attachment.  This is the path to the file, with the root being the
1132     * folder that manifest.xml is located.
1133     * @example
1134     * hwc.showLocalAttachment( "html/images/samplePic.gif" );
1135     */
1136    hwc.showLocalAttachment = function showLocalAttachment(key) {
1137    	hwc.traceEnteringMethod("hwc.showLocalAttachment");
1138        try {
1139    		if (hwc.isWindowsMobile() || hwc.isAndroid() || hwc.isIOS()) { 
1140    			hwc.getDataFromContainer("showlocalattachment", "&key=" + encodeURIComponent(key));
1141    		} else if (hwc.isBlackBerry()) {
1142    			if (key.indexOf("file://") > -1){
1143    				window.location = key;
1144    			} else {
1145    				window.location = "http://localhost/" + key;
1146    			}
1147    		} else {
1148    			window.open(key);
1149    		}
1150    
1151    	} finally {
1152    		hwc.traceLeavingMethod("hwc.showLocalAttachment");
1153    	}
1154    };
1155    
1156    /**
1157     * Internal function to allow the user to cause an operation/object query to be invoked.  This function should probably
1158     * only be used by designer generated javascript.
1159     *
1160     * @memberOf hwc
1161     * @private
1162     *
1163     * @param {string} credInfo Credential info in the format "supusername=usernameValue&suppassword=passwordValue"
1164     * @param {string} serializeDataMessageToSend The data message, already serialized.  This parameter should be obtained by calling serializeToString
1165     * on the result from hwc.getMessageValueCollectionForOnlineRequest.
1166     * @param {boolean} hasFileMessageValue Whether the data message to send has a file message value.  This parameter should be obtained by calling
1167     * getHasFileMessageValue on the result from hwc.getMessageValueCollectionForOnlineRequest.
1168     * @param {number} timeout Specifies the time, in seconds, to wait before giving up waiting for a response.
1169     * @param {string} cacheTimeout Specifies the time, in seconds, since the last invocation with the same input parameter values to use the same
1170     * response as previously retrieved without making a new call to the server.  If this parameter is NEVER, the cache content will never expire.
1171     * @param {string} errorMessage Specifies the string to display if an online request fails.
1172     * @param {anonymous.errorCallbackFunction} errorCallback Name of the function to be called if an online request fails. If  this parameter is null,
1173     * 'reportRMIError' will be used.
1174     * @param {string} cacheKey String used as the key for this request in the on-device request result cache.
1175     * @param {string} cachePolicy Specifies cache lookup policy used by container. If this parameter is 'serverfirst' (ignoring case) then the cache policy
1176     * used for this online request will be to check the server before the cache.  If this parameter is any other value then a cache first policy will be used.
1177     * If this parameter is absent and cache is enabled, the container uses default cache lookup policy to get data from cache if it is not expired.
1178     * @param {boolean} asynchronous Specifies whether container will make the request in synchronous or asynchronous mode.
1179     * If this parameter is absent, the container makes the request to the server in synchronous mode.
1180     */
1181    hwc.doOnlineRequest_CONT = function( credInfo, 
1182            serializeDataMessageToSend,
1183            hasFileMessageValue,
1184            timeout, cacheTimeout, 
1185            errorMessage, errorCallback, 
1186            cacheKey, cachePolicy, 
1187            asynchronous) {
1188    		
1189    	hwc.traceEnteringMethod("hwc.doOnlineRequest_CONT");
1190        
1191    	try {
1192    		var request, xmlhttp, response, encodedMessage, url, funcCall, responseDataType;
1193    		request = "xmlWorkflowMessage=" + encodeURIComponent(serializeDataMessageToSend);
1194    		
1195    		if (credInfo) {
1196    			request += ("&" + credInfo);
1197    		}
1198    		request += ("&cachekey=" + encodeURIComponent(cacheKey));
1199    		if (timeout) {
1200    			request += ("&rmitimeout=" + timeout);
1201    		}
1202    		if (cacheTimeout) {
1203    			request += ("&RequestExpiry=" + cacheTimeout);
1204    		}
1205    		if (hasFileMessageValue) {
1206    			request += ("&parse=true");
1207    		}
1208    		if (errorMessage) {
1209    			if( hwc.isBlackBerry() ) {
1210    				encodedMessage = encodeURIComponent(escape(errorMessage));
1211    			} else {
1212    				// This is a temporary fix for a bug in the container that calls
1213    				// encodeURIComponent on the whole query string for Android.  See
1214    				// IR 676161-2.
1215    				encodedMessage = encodeURIComponent(errorMessage);
1216    			}
1217    			request += ("&onErrorMsg=" + encodedMessage);
1218    		}
1219    		if (!errorCallback) {
1220    			errorCallback = "hwc.reportRMIError";
1221    		}
1222    		if (cachePolicy) {
1223    			request += ("&cachePolicy=" + cachePolicy);
1224    		}
1225    		if (asynchronous) {
1226    			request += ("&asynchronous=" + asynchronous);
1227    		}
1228    		request += ("&onErrorCallback=" + errorCallback);
1229    
1230    		if (hwc.isWindowsMobile() || hwc.isWindows()) {
1231    			//make xmlhttp request to load the rmi response from server
1232    			xmlhttp = hwc.getXMLHTTPRequest();
1233    
1234    			if (hwc.isWindowsMobile()) {
1235    				xmlhttp.open("POST", "/sup.amp?querytype=rmi&" + hwc.versionURLParam, true );  
1236    		
1237    				xmlhttp.onreadystatechange = function() {
1238    					if (xmlhttp.readyState === 4) {
1239    						if (xmlhttp.status === 200 || xmlhttp.status === 0) {
1240    							response = xmlhttp.responseText;
1241    							var responseDataType = xmlhttp.getResponseHeader("OnlineRequest-Response-Data-Type");
1242    							processDataMessage(response, null, null, null, responseDataType);
1243    						 }
1244    					}
1245    				};
1246    
1247    				try {
1248    					xmlhttp.send(request);
1249    				}
1250    				catch (excep1) {
1251    					hwc.log("Error:  Unable to retrieve the message from the server", "ERROR", true);
1252    				}
1253    			}
1254    			else { // hwc.isWindows() 
1255    				xmlhttp.open("POST", "rmi.xml", false );
1256    				xmlhttp.send(request);
1257    		
1258    				//Win32 returns 200 for OK, WM returns 0 for OK
1259    				if (xmlhttp.status === 200 || xmlhttp.status === 0) {
1260    					response = xmlhttp.responseText;
1261    					processDataMessage(response);
1262    				}
1263    				else {
1264    					hwc.log("Error:  Unable to retrieve the message from the server", "ERROR", true);
1265    				}
1266    			}
1267    		}
1268    		
1269    		else if (hwc.isAndroid()) {
1270    			url = 'http://localhost/sup.amp?querytype=rmi&' + hwc.versionURLParam;
1271    			funcCall = "_HWC.postData('" + url + "', '" +  request + "')";
1272    			// method processDataMessage invoked by native container.
1273    			// funcCall = "processDataMessage(" + funcCall + ")";
1274    			setTimeout(funcCall, 5);
1275    		}  
1276    		else { //BB and iPhone
1277    			xmlhttp = hwc.getXMLHTTPRequest();   
1278    			xmlhttp.open("POST", "http://localhost/sup.amp?querytype=rmi&" + hwc.versionURLParam, true);            
1279    			
1280    			 if (hwc.isBlackBerry()) {
1281    				xmlhttp.onreadystatechange = function() {
1282    					if (xmlhttp.readyState === 4) {
1283    						if (xmlhttp.status === 200) {
1284    							response = xmlhttp.responseText;
1285    							responseDataType = xmlhttp.getResponseHeader("OnlineRequest-Response-Data-Type");
1286    							processDataMessage(response, null, null, null, responseDataType);
1287    						}
1288    					}
1289    				};
1290    			}
1291    			try {
1292    				xmlhttp.send(request);
1293    			}
1294    			catch (excep2) {
1295    				hwc.log("Error:  Unable to retrieve the message from the server", "ERROR", true);
1296    			}
1297    		}                           
1298    	} finally {
1299    		hwc.traceLeavingMethod("hwc.doOnlineRequest_CONT");
1300    	}
1301    };
1302    
1303    /**
1304     * Allows the user to cause an operation/object query to be invoked.  This function should probably only be used by
1305     * designer generated javascript.
1306     *
1307     * @memberOf hwc
1308     * @private
1309     *
1310     * @param {string} credInfo Credential info in the format "supusername=usernameValue&suppassword=passwordValue"
1311     * @param {string} serializeDataMessageToSend The data message, already serialized.  This parameter should be obtained by calling serializeToString
1312     * on the result from hwc.getMessageValueCollectionForOnlineRequest.
1313     * @param {string} attachmentKey The specified key of the result will not be returned in the data message but will instead be stored on the
1314     * device for later access via {@link hwc.showAttachmentFromCache_CONT}.
1315     * @param {string} requestGUID Represents a unique key that can be used to store/access the cached key value from the request results.
1316     * @param {callback function} downloadCompleteCallback A function that will be invoked when the attachment has been downloaded to the device
1317     * and is ready to be accessed.
1318     */
1319    hwc.doAttachmentDownload_CONT = function(credInfo, serializeDataMessageToSend, attachmentKey, requestGUID, downloadCompleteCallback) {
1320    	hwc.traceEnteringMethod("hwc.doAttachmentDownload_CONT");
1321    	try {
1322    		var request, xmlhttp;
1323    		request = "xmlWorkflowMessage=" + encodeURIComponent(serializeDataMessageToSend);
1324    		
1325    		if (credInfo) {
1326    			request += ("&" + credInfo);
1327    		}
1328    		request += ("&attachmentkey=" + attachmentKey);
1329    		request += ("&uniquekey="     + requestGUID);
1330    		request += ("&ondownloadcomplete=" + downloadCompleteCallback);
1331    		if (hwc.isWindowsMobile() || hwc.isWindows()) {
1332    			xmlhttp = hwc.getXMLHTTPRequest();
1333    			xmlhttp.open("POST", "/sup.amp?querytype=downloadattachment&" + hwc.versionURLParam, true );
1334    			xmlhttp.onreadystatechange = function() {
1335    				if (xmlhttp.readyState === 4) {
1336    					if (xmlhttp.status === 200) {
1337    						window[downloadCompleteCallback].call(this, decodeURIComponent(requestGUID), xmlhttp.responseText);
1338    					}
1339    				}
1340    			};
1341    			try {
1342    				xmlhttp.send(request);          
1343    			}
1344    			catch (e3) {}                                
1345    		}
1346    		else if (hwc.isAndroid()) {
1347    			hwc.postDataToContainer("downloadattachment", request);
1348    		}   
1349    		else {
1350    			xmlhttp = hwc.getXMLHTTPRequest();
1351    			xmlhttp.open("POST", "http://localhost/sup.amp?querytype=downloadattachment&" + hwc.versionURLParam, true);
1352    			if (hwc.isBlackBerry()) {
1353    				xmlhttp.onreadystatechange = function() {
1354    					if (xmlhttp.readyState === 4) {
1355    						if (xmlhttp.status === 200) {
1356    							window[downloadCompleteCallback].call(this, decodeURIComponent(requestGUID), xmlhttp.responseText);
1357    						}
1358    					}
1359    				};
1360    			}
1361    			try {
1362    				xmlhttp.send(request);
1363    			}
1364    			catch (e1) {}
1365    		}
1366    	} finally {
1367    		hwc.traceLeavingMethod("hwc.doAttachmentDownload_CONT");
1368    	}
1369    };
1370    
1371    /**
1372     * Allows the user to cause an operation/object query to be invoked. Will close the hybrid app application when finished.  This function should probably only be used by
1373     * designer generated javascript.
1374     *
1375     * @memberOf hwc
1376     * @private
1377     *
1378     * @param {string} credInfo Credential info in the format "supusername=usernameValue&suppassword=passwordValue"
1379     * @param {string} serializeDataMessageToSend The data message, already serialized.  This parameter should be obtained by calling serializeToString
1380     * on the result from hwc.getMessageValueCollectionForOnlineRequest.
1381     * @param {boolean} hasFileMessageValue Whether the data message to send has a file message value.  This parameter should be obtained by calling
1382     * getHasFileMessageValue on the result from hwc.getMessageValueCollectionForOnlineRequest.
1383     */
1384    hwc.doSubmitWorkflow_CONT = function(credInfo, serializeDataMessageToSend, hasFileMessageValue) {
1385    	hwc.traceEnteringMethod("hwc.doSubmitWorkflow_CONT");
1386    	try {
1387    		var request = "xmlWorkflowMessage=" + encodeURIComponent(serializeDataMessageToSend);
1388    		
1389    		if (credInfo) {
1390    			request += ("&" + credInfo);
1391    		}
1392    		if (hasFileMessageValue) {
1393    			request += ("&parse=true");
1394    		} 
1395    		 
1396    		 hwc.postDataToContainer("submit", request);
1397    	} finally {
1398    		hwc.traceLeavingMethod("hwc.doSubmitWorkflow_CONT");
1399    	}
1400    };
1401    
1402    /**
1403     * Internal function to allow the user to cause an operation/object query to be invoked.  This function should probably only be used by
1404     * designer generated javascript.
1405     *
1406     * @memberOf hwc
1407     * @private
1408     *
1409     * @param {string} credInfo Credential info in the format "supusername=usernameValue&suppassword=passwordValue"
1410     * @param {string} serializeDataMessageToSend The data message, already serialized.  This parameter should be obtained by calling serializeToString
1411     * on the result from hwc.getMessageValueCollectionForOnlineRequest.
1412     */
1413    hwc.doActivateWorkflow_CONT = function(credInfo, serializeDataMessageToSend ) {
1414        var request, xmlhttp;
1415    	hwc.traceEnteringMethod("hwc.doActivateWorkflow_CONT");
1416    	try {
1417    		request = "xmlWorkflowMessage=" + encodeURIComponent(serializeDataMessageToSend);
1418    
1419    		if (credInfo) {
1420    			request += ("&" + credInfo);
1421    		}
1422    		 
1423    		hwc.postDataToContainer("activate", request);
1424    	} finally {
1425    		hwc.traceLeavingMethod("hwc.doActivateWorkflow_CONT");
1426    	}
1427    };
1428    
1429    /**
1430     * This function should probably only be used by designer generated javascript.
1431     *
1432     * @memberOf hwc
1433     * @private
1434     
1435     * @param {string} credInfo Credential info in the format "supusername=usernameValue&suppassword=passwordValue"
1436     * @param serializeDataMessageToSend The data message, already serialized.  This parameter should be obtained by calling serializeToString
1437     * on the result from hwc.getMessageValueCollectionForOnlineRequest.
1438     */
1439    hwc.doCredentialsSubmit_CONT = function(credInfo, serializeDataMessageToSend ) {
1440    	hwc.traceEnteringMethod("hwc.doCredentialsSubmit_CONT");
1441    	try {
1442    		var request = "xmlWorkflowMessage=" + encodeURIComponent(serializeDataMessageToSend);
1443    
1444    		if (credInfo) {
1445    			request += ("&" + credInfo);
1446    		}
1447    
1448    		hwc.postDataToContainer("credentials", request);
1449    	} finally {
1450    		hwc.traceLeavingMethod("hwc.doCredentialsSubmit_CONT");
1451    	}
1452    };
1453    
1454    /**
1455     * This function shows a progress dialog with spinner.  The dialog created by this function will block all
1456     * user input until {@link hwc.hideProgressDialog} is called.  It is important to be sure that
1457     * {@link hwc.hideProgressDialog} will be called after a call to this function.
1458     *
1459     * @memberOf hwc
1460     * @public
1461     * @param {string} [message] The message to show on the progress dialog. This message is displayed on Android
1462     * platforms only - other platforms show only a spinner.
1463     * @example
1464     * var showProgress = function()
1465     * {
1466     *    hwc.showProgressDialog( "a message" );
1467     *    setTimeout( hideProgress, 10000 );
1468     * }
1469     * 
1470     * var hideProgress = function()
1471     * {
1472     *    hwc.hideProgressDialog();
1473     * }
1474     */
1475    hwc.showProgressDialog = function(message) {
1476    	hwc.traceEnteringMethod("hwc.showProgressDialog");
1477    	try {
1478    		hwc.getDataFromContainer("showprogressdialog",  "&message=" + message);
1479    	} finally {
1480    		hwc.traceLeavingMethod("hwc.showProgressDialog");
1481    	}
1482    };
1483    
1484    /**
1485     * This function hides the progress dialog displaying the  spinner.  This function should be used to hide
1486     * the progress dialog after a call to {@link hwc.showProgressDialog}.  If this function is called while there
1487     * is no progress dialog, then nothing will happen.
1488     * @memberOf hwc
1489     * @public
1490     * @example
1491     * var showProgress = function()
1492     * {
1493     *    hwc.showProgressDialog( "a message" );
1494     *    setTimeout( hideProgress, 10000 );
1495     * }
1496     * 
1497     * var hideProgress = function()
1498     * {
1499     *    hwc.hideProgressDialog();
1500     * }
1501     */
1502    hwc.hideProgressDialog = function() {
1503    	hwc.traceEnteringMethod("hwc.hideProgressDialog");
1504    	try {
1505    		hwc.getDataFromContainer("hideprogressdialog");
1506    	} finally {
1507    		hwc.traceLeavingMethod("hwc.hideProgressDialog");
1508    	}
1509    };
1510    
1511    
1512    /**
1513     * Displays an alert dialog to the user.  This function blocks until it receives a response from the user.
1514     *
1515     * @memberOf hwc
1516     * @public
1517     * @param {string} message The message to display
1518     * @param {string} [title] The title doesn't actually get displayed.
1519     * @example
1520     * hwc.showAlertDialog( "This is a fancy alert dialog", "With a Title" );
1521     */
1522    hwc.showAlertDialog = function(message, title) {
1523    	if(hwc.isIOS()){
1524            // For ios client, creating an IFRAME element for the alert message, so as to hide the
1525            // title bar in the alert box
1526    	    var iframe = document.createElement("IFRAME");
1527    	    iframe.setAttribute("src", 'data:text/plain');
1528    	    document.documentElement.appendChild(iframe);
1529    	    window.frames[window.frames.length-1].alert(message);
1530    	    iframe.parentNode.removeChild(iframe);
1531    	}
1532        else{
1533    		alert(message);
1534    	}
1535    };
1536    
1537    /**
1538     * Shows a confirm dialog to the user.  This function blocks until it receives a response from the user.
1539     *
1540     * @memberOf hwc
1541     * @public
1542     * @param {string} message The message to display in the dialog.
1543     * @param {string} [title] The title doesn't actualy get displayed.
1544     *
1545     * @returns {boolean} The user's choice from the confirm dialog.
1546     * @example
1547     * var userConfirm = hwc.showConfirmDialog( "Are you sure you want to see an alert message?", "Confirm Alert" );
1548     * if( userConfirm )
1549     * {
1550     *    alert( "This is what you wanted." );
1551     * }
1552     */
1553    hwc.showConfirmDialog = function(message, title) {
1554        return confirm(message);
1555    };
1556    
1557    /**
1558     * This function closes the hybrid app.
1559     * @memberOf hwc
1560     * @public
1561     * @example
1562     * hwc.close();
1563     */
1564    hwc.close = function() {
1565        workflowMessage = "";
1566        hwc.supUserName = "";
1567    	hwc.traceEnteringMethod("hwc.close");
1568    	try {
1569    		if (hwc.isWindowsMobile()) {
1570    			if(typeof(hwc.setWindowBlankScreen) === 'function')
1571    			{
1572    				 hwc.setWindowBlankScreen();
1573    			}
1574    			  
1575    			  hwc.getDataFromContainer("close");
1576    		}
1577    		else if (hwc.isIOS()) {
1578    			  hwc.getDataFromContainer("close");
1579    		}
1580    		else if (hwc.isAndroid()) {
1581    			hwc.log("Closing Hybrid App" , "INFO");
1582    			_HWC.close();
1583    		}         
1584    		else {
1585    			window.close();
1586    		}
1587    		
1588    		status = hwc.STATUS.CLOSED; 
1589    	} finally {
1590    		hwc.traceLeavingMethod("hwc.close");
1591    	}
1592    };
1593    
1594    /**
1595     * This function checks if the hybrid app has been closed.
1596     * @returns {boolean} true if hybrid app is closed, otherwise false.
1597     * @memberOf hwc
1598     * @public
1599     * @example 
1600     * hwc.isClosed();
1601     */
1602    hwc.isClosed = function() {
1603        return status === hwc.STATUS.CLOSED;
1604    };
1605    
1606    })(hwc, window);
1607     
1608    /**
1609     * A callback function invoked when {@link hwc.log} is invoked with true for the notifyUser parameter.
1610     * This callback should notify the user of the log message in an appropriate manner.
1611     *
1612     * @name anonymous.alertDialogCallbackFunction
1613     *
1614     * @param {string} message The message that the user should be notified of.
1615     *
1616     * @function
1617     */
1618     
1619    /**
1620     * A callback function invoked if there is an error.
1621     *
1622     * @name anonymous.errorCallbackFunction
1623     *
1624     * @param {string} errorMessage The message describing the error.
1625     *
1626     * @function
1627     */
1628     
1629    /**
1630     * A generic callback function that takes no parameters.  Used to execute code when a certain event occurs.
1631     *
1632     * @name anonymous.genericCallbackFunction
1633     *
1634     * @function
1635     */