var IsPreExistingPerson = '';

function setPreExistingPerson( isPreExistingPerson )
{ 
	IsPreExistingPerson = isPreExistingPerson;
}

function verifyName( LoginName ) 
{
	IsPreExistingPerson = '';
	
	if ( !isValidEmail( LoginName ) ) 
		return;
					
	goAsync( 'LoginNameVerification&loginname=' + LoginName );
}

var continueCount = 0;

function checkLogin() 
{
    
	continueCount = 0;
	checkLoginLoop();
}

function checkLoginLoop()
{
	if ( IsPreExistingPerson != '' ) 
	{ 
		save(); 
		return; 
	}
	
	if ( continueCount >= 300 ) 
	{
		alert( 'There was a temporary problem with your connection. Please try again.' );
		return; 
	} 
	
	continueCount++;
	
	window.setTimeout( 'checkLoginLoop()', 100 ); 
} 

function checkPreExistingPerson()
{
    if ( document.getElementById('LoginName').value == '' )
	{
		IsPreExistingPerson = 'False';
		return;
	}
	
	if ( IsPreExistingPerson == '' ) 
	{ 
	    verifyName( document.getElementById('LoginName').value );
		checkLogin();
		return; 
	}
	
	if ( IsPreExistingPerson != 'False' ) 
	{
		alert('The Login Name you have chosen is not unique. Please choose another Login Name.\n' +
			'NOTE: Please make sure the person you are adding is not already in the system.');			
		return; 
	}
}
