// JavaScript Document

interface={
	text_focus:{
		init:function() {interface.text_focus.attachFocus($$("input.focus)"));},
		attachFocus:function(sfEls){
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onfocus=function() {interface.text_focus.OnFocus(this,this.defaultValue);}
			}
		},
		OnFocus:function(txtInput,str){
			if(txtInput.hasFocus){return;}
			txtInput.hasFocus=true;
			if(str=='Password'&&txtInput.value==str){
				txtInput=interface.text_focus.swapInputType(txtInput,str);
			}
			if(txtInput.value==str)txtInput.value='';
			txtInput.className+=" sffocus";
			txtInput.onblur = function(){
				if(txtInput.value==''){
					if(txtInput.type=='password')txtInput=interface.text_focus.swapInputType(txtInput,str);
					txtInput.value=str;
				}
				$(txtInput).removeClassName("sffocus");
				txtInput.hasFocus=false;
			}
		},
		swapInputType:function(txtInput,str){
			var newInput = document.createElement('input');
			if(txtInput.type=='password')newInput.type='text';
			else newInput.type='password';
			newInput.name = txtInput.name;
			newInput.value = txtInput.value;
			newInput.id = txtInput.id;
			newInput.className = txtInput.className;
			objParent=txtInput.parentNode;
			objParent.replaceChild(newInput,txtInput);
			newInput.onfocus = function (){interface.text_focus.OnFocus(newInput,str)};
			newInput.hasFocus=false;
			window.newInput = newInput;
			newInput.onblur = function(){
				if(newInput.value==''){
					if(newInput.type=='password')newInput=swapInputType(newInput,str);
					newInput.value=str;
				}
				newInput.hasFocus=false;
			}
			setTimeout("newInput.hasFocus=true;newInput.focus();",1);
			return newInput;
		}
	}
}


document.observe("dom:loaded",
	function(){
		interface.text_focus.init();
});
