var  PasswordInput=Class.create();

PasswordInput.prototype={
	initialize:function(input){
		this.input=$(input);
		this.changeType("text");
		Event.observe(this.input, "focus", this.clear.bind(this));
		Event.observe(this.input, "blur", this.checkRestore.bind(this));
	},
	clear:function(){
		this.changeType("password");
		this.input.focus();
		this.input.removeClassName("password_input");
		if(!this.preset || this.preset==this.input.value){
			this.preset=this.input.value;
			this.input.value="";
		}
	},
	checkRestore:function(){
		
		this.input.addClassName("password_input");
		
		if(this.input.value==""){
			this.input.value=this.preset;
			this.changeType("text");
		}
	},
	changeType:function(type){
		if(this.input.type==type){
			return this.input;
		}
		tmpInput=new Element("input", {type:type, name:this.input.name, value:this.input.value, });
		tmpInput.className=this.input.className;
		tmpInput.size=this.input.size;
		this.input.parentNode.insertBefore(tmpInput, this.input);
		this.input.parentNode.removeChild(this.input);
		this.input=tmpInput;
		Event.observe(this.input, "focus", this.clear.bind(this));
		Event.observe(this.input, "blur", this.checkRestore.bind(this));
		return this.input
	}
}
document.observe('dom:loaded', function () {
	inputs=$$(".password_input");
	inputs.each(function(input){new PasswordInput(input)});
});