'use strict';

module.exports = {
    exit: function (success, fail, args) {
        curWidget.setPreference('return', 'true');
    },
    launchApp: function (success, fail, args) {
        try {
            var paramAppId = args[0].appId;
            var paramData = args[0].data;
            var paramDataKeys = Object.keys(paramData);

            var webbrowserType = '3010'; // Common.API.EVENT_ENUM.RUN_WEBBROWSER
            var widgetType = '02'; // Common.API.EVENT_ENUM.RUN_SEARCH_WIDGET

            if(paramAppId == '29_fullbrowser') {
                var browserData = window.curWidget.id;
                if(paramData) {
                    browserData += '|?|' + paramData[paramDataKeys[0]];
                }

                /*jshint undef: false */
                var browserWidgetEvent = new WidgetEvent(webbrowserType, browserData);
                sendWidgetEvent('', browserWidgetEvent, false);
            }
            else {
                var data = window.curWidget.id + '?' + encodeURIComponent(paramAppId) + '?' + '&toast_data=' + encodeURIComponent(JSON.stringify(paramData));

                /*jshint undef: false */
                var widgetEvent = new WidgetEvent(widgetType, data);
                sendWidgetEvent('', widgetEvent, false);
            }
            setTimeout(function() {
                success();
            }, 0);
        }
        catch (e) {
            var error = new Error(e.message);
            error.name = e.name;
            setTimeout(function() {
                fail(error);
            }, 0);
        }
    },
    getRequestedAppInfo: function (success, fail, args) {
        try {
            var originalData = window.location.search;
            var reqCallerAppId = parseAppData(originalData, '&callerid=');
            var reqData = parseAppData(originalData, '&toast_data=');

            var reqDataObj = JSON.parse((decodeURIComponent(reqData)));

            setTimeout(function() {
                success({callerAppId: decodeURIComponent(reqCallerAppId), data: reqDataObj});
            }, 0);
        }
        catch (e) {
            var error = new Error(e.message);
            error.name = e.name;
            setTimeout(function() {
                fail(error);
            }, 0);
        }

        function parseAppData(originalData, searchData) {
            var str = originalData.substring(originalData.indexOf(searchData) + 1);
            return str.substring(str.indexOf('=') + 1, str.indexOf('&'));
        }
    }
};

require('cordova/exec/proxy').add('toast.application',module.exports);

@@ -329,24 +329,102 @@
 aramData);%0A%0A
+            var widgetType = '02'; // Common.API.EVENT_ENUM.RUN_SEARCH_WIDGET%0A
             
@@ -492,16 +492,17 @@
 BROWSER%0A
+%0A
         
@@ -505,34 +505,145 @@
         
-var widget
+/*jshint undef: false */%0A            if(device.version %3C 'T-INFOLINK2013-9999') %7B // for 2013'%0A                webbrowser
 Type = '
 02'; // 
@@ -626,34 +626,36 @@
 bbrowserType = '
-02
+3008
 '; // Common.API
@@ -670,29 +670,40 @@
 NUM.RUN_
-SEARCH_WIDGET
+WEBBROWSER%0A            %7D
 %0A%0A      

Fix launchApp api for 2013 deivces