function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

function initInputFields() {
    var formInputs = document.getElementsByTagName('input');

    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (((theInput.type == 'text' || theInput.type == 'password') && theInput.className.match(/\bcleardefault\b/)) ||
            ((theInput.type == 'text' || theInput.type == 'password') && theInput.className.match(/\blogincleardefault\b/)))
         {
            /* Add event handlers */
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            addEvent(theInput, 'keyup', setPwd, false);

            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
            if(typeof(fieldValues) != "undefined") {
        	if(fieldValues[theInput.id]) theInput.value = fieldValues[theInput.id];
    	    }
        }
    }
}

function setPwd(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if(!target) return;
    if(target.id == "pwd" || target.id == "fh_pwd") {
	if(target.value == '' || target.value == target.defaultText) {
	    //target.type="text";
	}
	else {
	    //target.type="password";
	}
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    if (target.value == target.defaultText) target.value = '';
}
function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    if (target.value == '' && target.defaultText) target.value = target.defaultText;
}

