doWarning   = true;
doEmail     = false;
wasSubmit   = false;

function doSave()
{
    doWarning                                       = false;
    doEmail                                         = true;
    document.getElementById('IsComplete').value     = 0;
	honorFieldRequirements                          = false;
	wasSubmit                                       = false;
	save();
}

function doSubmit( collectEmail )
{
    doWarning                                   = true;
    doEmail                                     = collectEmail;
    document.getElementById('IsComplete').value = 1;
	honorFieldRequirements                      = true;
	wasSubmit                                   = true;
	save();
}

function afterValidation()
{
    if ( doWarning ) 
    { 
        if ( !confirm( 'WARNING: Your application is about to be submitted.\nYou will not be able to change your submission after it is made.\n\nAre you sure you want to continue?' ) ) 
            return false; 
    }
    
    if ( doEmail )
    {
        var email = document.getElementById('ReturnEmail').value;
        
        if ( email == "" )
        {
            if ( wasSubmit )
                email = prompt( 'Please provide an email address at which we can send you a confirmation of your submission, as well as links for any addition steps in the submission process.', email );
            else
                email = prompt( 'Please provide an email address at which we can send you a Return Link.', email );
        }
        else
            email = prompt( 'Is this your correct email address?', email );
        
        if ( email == null )
            return false;
        
        while ( !isEmailAddress( email ) )
        {
            email = prompt( 'The provided email address was not valid.\nPlease enter a valid email address', email );
            
            if ( email == null )
                return false;
        }
        
        document.getElementById('ReturnEmail').value = email;
    }
    
    return true;
}

function onClick( fieldIDString )
{	
	var ids			= fieldIDString.toString().split( '|' );
	var hideField	= true;
	
	for ( var i = 1; i <= ( ids.length - 1 ); i++ )
	{
		if ( document.getElementById('cf_' + ids[i]).value == 1 )
			hideField = false;
	}
	
	if ( hideField )
		document.getElementById(ids[0]).style.display = 'none';
	else
		document.getElementById(ids[0]).style.display = '';
}