// JavaScript Document

//read element
function choose(id){
	input = document.getElementById(id);
	return input;
}

//clear input (initial value, input id)
function clearInput(initValue, id){
	if (id)	choose(id);
	if (!initValue) initValue = '';

	input.value = (input.value == initValue) ? '' : input.value;
}

//change input type (change input to type, input id)
function changeInputType(t, id){
	if (id)	choose(id);
	
	replaceT(input,t);
//	input.setAttribute('type',t);
//	input.type = t;
}

//on focus to input, clear and change input to password (input id, initial value)
function passwordFocus(id, initValue){
	choose(id);
	clearInput((!initValue)?initValue='':initValue);
	changeInputType('password');
	choose(id);
	input.focus();
}

function replaceT(obj, type){
	var newO=document.createElement('input');
	newO.setAttribute('type','password');
	if (obj.getAttribute('name'))
		newO.setAttribute('name',obj.getAttribute('name'));
	if (obj.getAttribute('id'))
		newO.setAttribute('id',obj.getAttribute('id'));
	if (obj.getAttribute('tabindex'))
		newO.setAttribute('tabindex',obj.getAttribute('tabindex'));
	obj.parentNode.replaceChild(newO,obj);
	newO.focus();
}
