static function setUpReporticoSession($namespace)
    {
        // Get current session
        $session_name = session_id();

        // Check for Posted Session Name and use that if specified
        if (isset($_REQUEST['reportico_session_name'])) {
            $session_name = $_REQUEST['reportico_session_name'];
            if (preg_match("/_/", $session_name)) {
                $ar = explode("_", $session_name);
                ReporticoApp::set("session_namespace", $ar[1]);
                if (ReporticoApp::get("session_namespace")) {
                    ReporticoApp::set("session_namespace_key", "reportico_" . ReporticoApp::get("session_namespace"));
                }

                // Set session to join only if it is not NS meaning its called from framework and existing session
                // should be used
                if ($ar[0] != "NS") {
                    $session_name = $ar[0];
                }

            }
        } 

        // If the session_name starts with NS_ then it is a namespace for reportico
        // embedded in a framework or for multiple concurrent reportico instances
        // , so set the current namespace. All sessiion variables for this namespace
        // will be stored in a namspaces specific session array
        if (strlen($session_name) >= 3 && substr($session_name, 0, 3) == "NS_") {
            if (!$session_name || !isset($_SESSION)) {
                session_start();
            }

            ReporticoApp::set("session_namespace", substr($session_name, 3));

            // IF NS_NEW passed then autogenerate session namespace from current time
            if (ReporticoApp::get("session_namespace") == "NEW") {
                ReporticoApp::set("session_namespace", date("YmdHis"));
            }
            if (ReporticoApp::get("session_namespace")) {
                ReporticoApp::set("session_namespace_key", "reportico_" . ReporticoApp::get("session_namespace"));
            }

            if (isset($_REQUEST['clear_session']) && isset($_SESSION)) {
                self::initializeReporticoNamespace(self::reporticoNamespace());
            }
            return;
        }

        // If no current or specified session start one, or if request to clear session (it really means clear namespace)
        // then clear this out
        if (!$session_name || isset($_REQUEST['clear_session'])) {

            // If no session current then create a new one
            if (!$session_name || !isset($_SESSION)) {
                session_start();
            }

            if (isset($_REQUEST['new_session']) && $_REQUEST['new_session']) {
                session_regenerate_id(false);
            }

            //unsetReporticoSessionParam("template");
            //session_regenerate_id(false);
            $session_name = session_id();

            
            // If no session set ( a new session ) set the namespace to be called default
            if ( !$namespace ) {
                $namespace = "default";
            }

            if (isset($_REQUEST['clear_session'])) {
                ReporticoApp::set("session_namespace", $namespace);
                ReporticoApp::set("session_namespace_key", "reportico_" . ReporticoApp::get("session_namespace"));
                self::initializeReporticoNamespace(self::reporticoNamespace());
            }
        } else {
            if (session_id() != $session_name) {
                session_id($session_name);
                session_start();
            }

            if ( !$namespace ) {
                $namespace = "default";
            }
                //ReporticoApp::set("session_namespace", $namespace);
                ReporticoApp::set("session_namespace_key", "reportico_" . ReporticoApp::get("session_namespace"));
            $namespace = ReporticoApp::get("session_namespace");
            $session_name = session_id();
        }
        
        ReporticoLog::debug("Final session name : $session_name");
    }