JavaScript: fix checking cookies condition