var authOffsetX = 5;
var authOffsetY = 20;
var x = 0;
var y = 0;

//window.onload = initHint;
function initHint() {
	
	if (window.attachEvent) 	{
		document.attachEvent("onmousemove",getXY);
	} else {
		document.addEventListener("mousemove",getXY,false);
	}
	
	/*if (window.Event) {
		document.captureEvents(Event.CLICK);
	}
	document.onmousemove = getXY;*/
}

function getXY(e) {
	if (window.attachEvent) {
		x = parseInt(event.clientX) + parseInt(document.documentElement.scrollLeft);
		y = parseInt(event.clientY) + parseInt(document.documentElement.scrollTop);		
	} else {

		x = e.pageX;
		y = e.pageY;
	}
	
	//x = (window.Event) ? e.pageX : (parseInt(event.clientX) + parseInt(document.documentElement.scrollLeft));
	//y = (window.Event) ? e.pageY : (parseInt(event.clientY) + parseInt(document.documentElement.scrollTop));
}

function showAuthHint(object) {
	var hint = document.getElementById("auth_hint");
	hint.style.display = "block";
	
	hint.style.left = parseInt(x + authOffsetX) + 'px';
	hint.style.top = parseInt(y + authOffsetY) + 'px';
	hint.innerHTML = getAuthDescription(object.id);
}

var objectId = false;
var objectTitle = false;
function showAuthError(object) {
	initHint();
	var hint = document.getElementById("auth_hint");
	hint.style.display = "block";
	
	hint.style.left = parseInt(x + authOffsetX) + 'px';
	hint.style.top = parseInt(y + authOffsetY) + 'px';
	if (objectId) {
		hint.innerHTML = objectTitle;
	} else {
		hint.innerHTML = object.title;
		objectId = object;
		objectTitle = object.title;
		object.title = "";
	}
}

function hideAuthHint() {
	document.getElementById("auth_hint").style.display = "none";
}

function hideAuthError() {
	if (objectId) {
		objectId.title = objectTitle;
		objectId = false;
		objectTitle = false;
	}
	document.getElementById("auth_hint").style.display = "none";
}

function getAuthDescription(id) {
	var value;
	switch(id) {
		case "username"	: value = authDescriptionsArray[0];	break;
		case "password"	: value = authDescriptionsArray[1];	break;
		case "email"		: value = authDescriptionsArray[2];	break;
		case "lost_password"	: value = authDescriptionsArray[3];	break;
		case "birthday"		: value = authDescriptionsArray[4];	break;
	}
	
	return value;
}