/**
 * @author nbalsaras
 */

 function forms(){
	pwL = document.getElementById('passwordLabel');
	unL = document.getElementById('usernameLabel');
	if (pwL) {
		pwL.style.position = 'absolute';
		pwL.style.left = '-5000px';
	}
	if (unL) {
		unL.style.position = 'absolute';
		unL.style.left = '-5000px';
	}
	
 	var inputs = document.getElementsByTagName('input');
 	for (i = 0; i < inputs.length; i++) {
 		focusInput(inputs[i], null);
 		
 		inputs[i].onfocus = function(){
 			focusInput(this, true);
 		};
 		inputs[i].onblur = function(){
 			focusInput(this, false);
 		};
 	}
 }
 
 function focusInput(t, isFocus){
	if (t.id == 'username') {
		if (t.value == 'Username' && isFocus == true) {
			t.value = '';
			t.style.color = '';
		}
		if (t.value == '' && isFocus == false) {
			t.value = 'Username';
			t.style.color = '#AAA';
		}
		if (isFocus == null){
			t.value = 'Username';
			t.style.color = '#AAA';
		}
	}
	else if (t.id == 'password') {
		if (t.value == 'Password' && isFocus == true) {
			t.value = '';
			t.style.color = '';
			if (checkIE < 9) {
				changeInputType(t, 'password', true);
			}
			else {
				t.type = 'password';
			}
		}
		if (t.value == '' && isFocus == false) {
			t.value = 'Password';
			t.style.color = '#AAA';
			if (checkIE < 9) {
				changeInputType(t, '');
			}
			else {
				t.type = '';
			}
		}
		if (isFocus == null){
			t.value = 'Password';
			t.style.color = '#AAA';
			if (checkIE < 9) {
				changeInputType(t, '');
			}
			else {
				t.type = '';
			}
		}
	}
}

// change input type for ie6
var oID;
function changeInputType(oldObject, oType, isFocus) {
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.style.color)  newObject.style.color = oldObject.style.color;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	if (isFocus) {
		oID = oldObject.id;
		setTimeout('document.getElementById(oID).focus()', '10');
	}
	newObject.onfocus = function(){	focusInput(this, true);};
	newObject.onblur = function(){focusInput(this, false);};
	return newObject;
}