public static function javascriptProtect($str = '', $protect_quotes = false)
    {
        $str = preg_replace('/\s\s+/', ' ', $str);
        $str = htmlentities($str);
        if (true===$protect_quotes) {
            $str = str_replace("'", "\'", $str);
            $str = str_replace('"', '\"', $str);
        }
        return $str;
    }