//*****************************************************
// loginFocus - Nicolai Goncalves
// Set focus on login fields
//*****************************************************


function loginFocus(textBoxID, textBoxID_alt) {
	objBox = document.getElementById(textBoxID);
	objBox_alt = document.getElementById(textBoxID_alt);
	
	if (objBox){
		if(objBox.value.length == 0) {
			objBox.focus();
		}
		else {
			objBox_alt.focus();
		}
	}
} 

//*****************************************************
// CapsDetect
// Detect if Caps Lock is engaged when a key is pressed
//*****************************************************


	//you must either define capsError as a function or a message to be alerted

	//this will make the script alert a message if Caps Lock is engaged
	//var capsError = 'WARNING:\n\nCaps Lock is enabled\n\nThis field is case sensitive';

	//this will make the script run a function and pass it a parameter saying if Caps Lock is engaged
	//function format NOT compatible with v1 - it will now be run even if Caps Lock is not enabled
	function capsError( capsEngaged ) {
		if( capsEngaged ) {
			//do something to warn the user that caps lock is engaged
			document.getElementById("CapsMessage").style.display = "block";
		} else {
			//remove any warnings that caps lock is engaged
			document.getElementById("CapsMessage").style.display = "none";
		}
	}

function capsDetect( e ) {
	if( !e ) { e = window.event; } if( !e ) { Say_Caps( false ); return; }
	//what  key was pressed (case sensitive in good browsers)
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	Say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}
function Say_Caps( oC ) {
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError ); } } else { capsError( oC ); }
}


//*****************************************************
// Object Coordinates - Nicolai Goncalves
// Get and set coords
//*****************************************************

function getCoordinates(obj) {
	var theObj = obj;
    var coords = {x: 0, y: 0};

    while (theObj) {
      coords.x += theObj.offsetLeft;
      coords.y += theObj.offsetTop;
      theObj = theObj.offsetParent;
    }
	return coords;
}

function setCoordinates(textboxId) {
	theObj = document.getElementById("CapsMessage");
	coords = getCoordinates(document.getElementById(textboxId));
	theObj.style.top = (coords.y +10) + "px";
	theObj.style.left = (coords.x +130) + "px";
	}




