var bTopKeyExists = false;
var sCurrTopKey = '';

/* 
** Checks the bTopKeyExists-flag
*/
function topKeyAlreadyExists()
{
	return bTopKeyExists;
}

function TopKeyDoesNotExist()
{
	bTopKeyExists = false;
}

/* 
** Gets username info in the hidden frame
*/
function checkTopKey(sTopKey, sFrame)
{
	//Assume that the name is valid (does not exist)
	// Do not check when the name has not changed
	if (sTopKey == sCurrTopKey)
		return;

	parent.frames['hidden'].location.href = '/top/asp/modCheckUserName.aspx?frame=' + sFrame + '&chrUsrNm=' + sTopKey;
}

function checkUserName(sUserName, sFrame)
{
	checkTopKey(sUserName, sFrame);
}

function checkShortName(sShortName)
{
	checkTopKey(sShortName, 'leaf');
}


/*
** This function is called from the hidden frame when a username is found
*/			
function WarnTopKeyAllReadyExists(sTopKey)
{
	bTopKeyExists = true;
	alert('The username or shortname \'' + sTopKey + '\' already exists. Please enter a different one');
}
						
function SetCurrentTopKey(sTopKey)
{
	sCurrTopKey = sTopKey;
}

