getCookieValue in JavaScript

Here is my version of “getCookieValue” in JavaScript:

function getCookieValue( name ) {
    var all_cookies = document.cookie.split( ';' );
    var cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    for ( i = 0; i < all_cookies.length; i++ ) {
        cookie = all_cookies[i].split( '=' );
        cookie_name = cookie[0].replace(/^\s+|\s+$/g, '');
        if ( cookie_name == name ) {
            cookie_value = unescape( cookie[1].replace(/^\s+|\s+$/g, '') );
            return cookie_value;
            break;
        }
        cookie = '';
        cookie_name = '';
    }
    return null;
}