Can't help you much with javascript to password protect a webpage but..

Have you considered using htaccess to password protect directories? Very secure, username/passwords are only stored server side and the server/browser will handle the negotiations for you, and simple to implemente.