     return {link:link}
 
 module.directive("tgRegister", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgNavUrls", "$tgConfig",
-                                "$routeParams", "$tgAnalytics", "$translate", RegisterDirective])
+                                "$routeParams", "$tgAnalytics", "$translate", "$window", RegisterDirective])
 
 
 #############################################################################

## Register Directive
#############################################################################

RegisterDirective = ($auth, $confirm, $location, $navUrls, $config, $routeParams, $analytics, $translate) ->
    link = ($scope, $el, $attrs) ->
        if not $config.get("publicRegisterEnabled")
            $location.path($navUrls.resolve("not-found"))

        $scope.data = {}
        form = $el.find("form").checksley({onlyOneErrorElement: true})

        console.log $routeParams['forceNext']

        if $routeParams['forceNext'] and $routeParams['forceNext'] != $navUrls.resolve("register")
            $scope.nextUrl = decodeURIComponent($routeParams['forceNext'])
        else
            $scope.nextUrl = $navUrls.resolve("home")

        onSuccessSubmit = (response) ->
            $analytics.trackEvent("auth", "register", "user registration", 1)

            if $scope.nextUrl.indexOf('http') == 0
                $window.location.href = $scope.nextUrl
            else
                $location.url($scope.nextUrl)

        onErrorSubmit = (response) ->
            if response.data._error_message
