var Focus = {

	'NORMAL' : 0,
	'PASSWORD' : 1,
	
	bindAll : function(){
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i ++){
			var node = inputs[i];
			if (node.className == 'focus_normal' || node.className == 'focus_password'){
				Focus.bind(node, node.className == 'focus_password' ? Focus.PASSWORD : Focus.NORMAL);
			}
		}		
	},
	
	bind : function(node, mode){
		if (mode == Focus.NORMAL){
			Focus.bindNormal(node);
		}
		else if (mode == Focus.PASSWORD){
			Focus.bindPassword(node);
		}
		else{
			throw new Error('Invalid focus binding mode.');
		}
	},
	
	bindNormal : function(node){
		node.onfocus = function(){
			if (!this.state){
				this.value = '';
			}
			this.state = true;
		}
	},
	
	bindPassword : function(node){
		node.onfocus = function(){
			var newNode = document.createElement('input');
			newNode.type = 'password';
			newNode.id = this.id ? this.id : 'input' + Math.round(100000 * Math.random());
			newNode.name = this.name;
			newNode.value = '';
			setTimeout('document.getElementById("' + newNode.id + '").focus()', 20);
			this.parentNode.replaceChild(newNode, this);
		}
	}
	
}

try{
	window.addEventListener('load', function(){
		Focus.bindAll();
	}, false);
}
catch (error){
	window.attachEvent('onload', function(){
		Focus.bindAll();
	});
}
