
        
        // Global QB objects.
        var g_objQB = null;
        var g_objPrefs = null;
        var g_objApp = null;

        // Initialize QB objects.
        //  Create QB objects and assign them to global variables.
        function InitializeQB() {
          try {
            g_objQB = new ActiveXObject( "QuickBooks.CoLocator" );
          }
          catch( err ) {
          }
          if( g_objQB ) {
            try {
               g_objPrefs = g_objQB.Create( "QBPrefs.Preferences" );
               
            } 
            catch( err ) {
            }
            try {
              g_objApp = g_objQB.Create( "QBPrefs.AppParameters" );
            } 
            catch( err ) {
            }
          }
        }        

        // Returns whether or not browser is running within QB.
        function IsInQB() {
            return ( g_objPrefs != null && g_objApp != null );
        }

        function ResizeWindow() 
        {
            var src_value = getQuerystring('src')

            if (src_value == 'iconbar' || src_value == 'menu')
            {
                Set_Cookie('QBGATrackerSrc', src_value, '', '/', '', true );
                window.location = 'qbks://qbw:browser?url=https://' + document.domain + '/appcenter/default.aspx?inqb=' + src_value + '&browserSize=fullClient&unique=y&hideurl=y';
                var cmd = "qbks2://qbw:closebrowser";
                window.location = cmd;
            }
        }

        function UpdateQBLinks() 
        {
            if( IsInQB() )
            {
                
                //Find try,buy links
                var searchkey = "QBDPTryBuy";
                var searchkey2 = "WorkplaceSignIn";

                var siteLinks = document.getElementsByTagName("a");
                for(var idx = 0; idx < siteLinks.length; idx++)
                {
                    var link = siteLinks[idx].href;
                    var externallink = "";

                    if ( link.indexOf(searchkey) != -1 || link.indexOf(searchkey2) != -1)
                    {
                        // create link to redirect function
                        siteLinks[idx].href = "javascript: Redirect('" + link + "');";
                    }
                }
            }
        }
        
        function Redirect(ext_url)
        {
            // split between domain and querystring name/values
            var url_delimiter = ext_url.indexOf("?");
            var qb_url = ext_url.substring(0,url_delimiter);
            var qb_qs = ext_url.substring(url_delimiter + 1,ext_url.length);
                       
            // save querystring to ACE variable            
            var cmd = "qbks://qbw:SaveArguments?SaveAs=AppCenter&" + qb_qs;
            window.location = cmd;
            
            // redirect to external browser, pass in saved ACE variabls
            var goto_url = "qbks://qbw:browser/?url=" + qb_url + "&AddACEToURL=SaveArgumentsCommand.AppCenter&external=y";
            window.location = goto_url;
        }
        
        function IsInQBGATracker()
        {
            if( IsInQB() )
            {
                var src_value = getQuerystring('inqb')
                 
                if (src_value == 'iconbar' || src_value == 'menu')
                {
                    var objProfile = g_objQB.Create("QBPrefs.AppParameters");
                    var flavor = objProfile.Flavor;
                    WorkplaceGALinksTracker('InProduct', flavor, '', src_value, 'ClickfromQB');
                }
            }
         }
        
        // Set a cookie value.
        function Set_Cookie( name, value, expires, path, domain, secure )
        {
	        // set time, it's in milliseconds
	        var today = new Date();
	        today.setTime( today.getTime() );

	        if ( expires )
	        {
		        expires = expires * 1000 * 60 * 60 * 24;
	        }
	        var expires_date = new Date( today.getTime() + (expires) );

	        document.cookie = name + "=" +escape( value ) +
	        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	        ( ( path ) ? ";path=" + path : "" ) +
	        ( ( domain ) ? ";domain=" + domain : "" ) +
	        ( ( secure ) ? ";secure" : "" );
        }

        // Read a cookie value.
        function GetCookie( name ) 
        {
            var search = name + "=";
            var returnvalue = "";
            if (document.cookie.length > 0) 
            {
              offset = document.cookie.indexOf(search)
              // if cookie exists
              if (offset != -1) 
              {
                offset += search.length;
                // set index of beginning of value
                end = document.cookie.indexOf(";", offset);
                // set index of end of cookie value
                if (end == -1) end = document.cookie.length;
                returnvalue=unescape(document.cookie.substring(offset, end));
              }
            }
            return returnvalue;
        }
          
        function getQuerystring(key, default_) 
        {
            if (default_ == null) default_ = "";

            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
            var qs = regex.exec(window.location.href);

            if (qs == null)
                return default_;
            else
                return qs[1];
        }
        
        function openWin( windowTitle )
        {
	        if ( windowTitle == 'Feedback')
	        {
		        windowURL = 'https://www.quickbase.com/db/bepqm7ur6?a=nwr';
		        windowFeatures = 'width=675,height=500,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0';
		        ShowPopUp = 1;
	        }
         
	        if (ShowPopUp)
	        {
		        newWindow = window.open( windowURL, windowTitle, windowFeatures ) ;
		        newWindow.focus();
	        }
        }

        function WorkplaceGALinksTracker(process, application, page, userAction, Conversion)
        {
            if (useGA == "true")
            {
                param = '/Workplace/AppCenter/Process=' + process + '?Application=' + application + '&Page=' + page + '&UserAction=' + userAction + '&Conversion=' + Conversion;
                WorkplaceGATracker._trackPageview(param);
            }            
		}        

        //Initialize
        InitializeQB();
        
        $(document).ready(function() {
		UpdateQBLinks();
		IsInQBGATracker();
		
	});
        
        