Выбор параметра cookie [javascript]

var getCookieVar : function (name)
{
    var ar = document.cookie.split(';');
    for( var i = 0; i < ar.length; i++ )
    {
        if( ar[i].split('=')[0].replace(' ', '') == name)
            return ar[i].split('=')[1]; 
    }
}