currentPopUp = null;
popupTimer = null;

function TBA() {
	alert('TBA');
}

function $( id ) {
	return document.getElementById(id);	
}

function popUp( divID ) {
	var panel = $(divID);
	var wrapper = $('wrapper');
	var icon = $('icon_' + divID);

	if (panel != undefined) {
		closePopUp();
		if (currentPopUp == undefined || currentPopUp.id != panel.id) {
			panel.style.left = (findPosX(icon) - findPosX(wrapper) + 20) + "px";
			panel.style.top = (findPosY(icon) - findPosY(wrapper) - 20) + "px";
			panel.style.display = "block";
			panel.style.visibility = "visible";
			
			currentPopUp = panel;
		}
		clearTimer();
	}
}


function fadePopUp() {
	popupTimer = setInterval("closePopUp()",500);
}

function closePopUp() {
	if (currentPopUp != null) {
		currentPopUp.style.display = "none";
		currentPopUp = null;
	}
	
	clearTimer();
}

function clearTimer() {
	if (popupTimer != null) {
		clearInterval(popupTimer);
		popupTimer = null;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function nextDigit(field, e) {
	var fieldName = field.name;
	var fields_arr = fieldName.split("_");
	var fieldIndex = parseInt(fields_arr[1]);
	
	if (e.keyCode) keycode=e.keyCode;
	else keycode=e.which;
	
	if (keycode == 37) {
		fieldIndex -= 1;
	} else if (keycode == 39) {
		fieldIndex += 1;
	} else {
		if (field.value == '') {
			fieldIndex -= 1;
		} else {
			fieldIndex += 1;
		}
	}
	
	var nextFieldName = fields_arr[0] + "_" + fieldIndex;
	var nextField = $(nextFieldName);
	
	if (nextField != null) {
		nextField.focus();
		nextField.select();
	}
}