function qtrans_init()
{
    global $q_config;
    // check if it isn't already initialized
    if (defined('QTRANS_INIT')) {
        return;
    }
    define('QTRANS_INIT', true);
    // load configuration if not beeing reseted
    if (isset($_POST['qtranslate_reset']) && isset($_POST['qtranslate_reset2']) && defined('WP_ADMIN') && current_user_can('manage_options')) {
        // reset all settings
        delete_option('qtranslate_language_names');
        delete_option('qtranslate_enabled_languages');
        delete_option('qtranslate_default_language');
        delete_option('qtranslate_flag_location');
        delete_option('qtranslate_flags');
        delete_option('qtranslate_locales');
        delete_option('qtranslate_na_messages');
        delete_option('qtranslate_date_formats');
        delete_option('qtranslate_time_formats');
        delete_option('qtranslate_use_strftime');
        delete_option('qtranslate_ignore_file_types');
        delete_option('qtranslate_url_mode');
        delete_option('qtranslate_detect_browser_language');
        delete_option('qtranslate_hide_untranslated');
        delete_option('qtranslate_auto_update_mo');
        delete_option('qtranslate_next_update_mo');
        delete_option('qtranslate_hide_default_language');
        if (isset($_POST['qtranslate_reset3'])) {
            delete_option('qtranslate_term_name');
        }
    }
    qtrans_loadConfig();
    if (isset($_COOKIE['qtrans_cookie_test'])) {
        $q_config['cookie_enabled'] = true;
    } else {
        $q_config['cookie_enabled'] = false;
    }
    // init Javascript functions
    qtrans_initJS();
    // update Gettext Databases if on Backend
    if (defined('WP_ADMIN') && $q_config['auto_update_mo']) {
        qtrans_updateGettextDatabases();
    }
    // update definitions if neccesary
    if (defined('WP_ADMIN') && current_user_can('manage_categories')) {
        qtrans_updateTermLibrary();
    }
    // extract url information
    $q_config['url_info'] = qtrans_extractURL($_SERVER['REQUEST_URI'], $_SERVER["HTTP_HOST"], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
    // set test cookie
    setcookie('qtrans_cookie_test', 'qTranslate Cookie Test', 0, $q_config['url_info']['home'], $q_config['url_info']['host']);
    // check cookies for admin
    if (defined('WP_ADMIN')) {
        if (isset($_GET['lang']) && qtrans_isEnabled($_GET['lang'])) {
            $q_config['language'] = $q_config['url_info']['language'];
            setcookie('qtrans_admin_language', $q_config['language'], time() + 60 * 60 * 24 * 30);
        } elseif (isset($_COOKIE['qtrans_admin_language']) && qtrans_isEnabled($_COOKIE['qtrans_admin_language'])) {
            $q_config['language'] = $_COOKIE['qtrans_admin_language'];
        } else {
            $q_config['language'] = $q_config['default_language'];
        }
    } else {
        $q_config['language'] = $q_config['url_info']['language'];
    }
    // detect language and forward if needed
    if ($q_config['detect_browser_language'] && $q_config['url_info']['redirect'] && !isset($_COOKIE['qtrans_cookie_test']) && $q_config['url_info']['language'] == $q_config['default_language']) {
        $prefered_languages = array();
        if (preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\\.]+)[^,]*)?#i", $_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) {
            $priority = 1.0;
            foreach ($matches as $match) {
                if (!isset($match[3])) {
                    $pr = $priority;
                    $priority -= 0.001;
                } else {
                    $pr = floatval($match[3]);
                }
                $prefered_languages[$match[1]] = $pr;
            }
            arsort($prefered_languages, SORT_NUMERIC);
            foreach ($prefered_languages as $language => $priority) {
                if (qtrans_isEnabled($language)) {
                    if ($q_config['hide_default_language'] && $language == $q_config['default_language']) {
                        break;
                    }
                    $target = qtrans_convertURL(get_option('home'), $language);
                    header("Location: " . $target);
                    exit;
                }
            }
        }
    }
    /*
    // Check for WP Secret Key Missmatch
    global $wp_default_secret_key;
    if(strpos($q_config['url_info']['url'],'wp-login.php')!==false && defined('AUTH_KEY') && isset($wp_default_secret_key) && $wp_default_secret_key != AUTH_KEY) {
    	global $error;
    	$error = __('Your $wp_default_secret_key is mismatchting with your AUTH_KEY. This might cause you not to be able to login anymore.','qtranslate');
    }
    */
    // Filter all options for language tags
    if (!defined('WP_ADMIN')) {
        $alloptions = wp_load_alloptions();
        foreach ($alloptions as $option => $value) {
            add_filter('option_' . $option, 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
        }
    }
    // load plugin translations
    load_plugin_textdomain('qtranslate', PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/lang');
    // remove traces of language
    unset($_GET['lang']);
    $_SERVER['REQUEST_URI'] = $q_config['url_info']['url'];
    $_SERVER['HTTP_HOST'] = $q_config['url_info']['host'];
    // fix url to prevent xss
    $q_config['url_info']['url'] = qtrans_convertURL(add_query_arg('lang', $q_config['default_language'], $q_config['url_info']['url']));
}
function qtrans_postInit()
{
    // init Javascript functions
    qtrans_initJS();
    // update definitions if neccesary
    if (defined('WP_ADMIN') && current_user_can('manage_categories')) {
        qtrans_updateTermLibrary();
    }
}