function confirmDelete()
{
	if (confirm("Are you sure you want to delete these applications?"))
	{
		return true;
	}
	else
	{
		alert("No action taken.");
		return false;
	}
}

function remotePost(appId)
{
	var img = 'img-' + appId;
	$('img-' + appId).src = '/apply/img/loader.gif';
	
	var div = 'app-' + appId;
	new Ajax.Updater(div, 'remote_post.php', {
		method: 'get',
		parameters: {id: appId}
	});
}

function checkReroll()
{
	if ( $('reroll').checked == true )
	{
		$('d-char_played').style.display = 'none';
		$('d-char_doomhammer').style.display = 'none';
		$('d-char_profile').style.display = 'none';
		$('d-char_talents').style.display = 'none';
		$('d-char_owner').style.display = 'none';
	}
	else
	{
		$('d-char_played').style.display = '';
		$('d-char_doomhammer').style.display = '';
		$('d-char_profile').style.display = '';
		$('d-char_talents').style.display = '';
		$('d-char_owner').style.display = '';
	}
}

function validateForm()
{
    var fm = $('application');
    var errors = new Array();

    // This list will be rebuilt as we check the fields
    $('d-errors').style.display = 'none';
    $('errors-list').innerHTML = '';
    
    // Personal Information
    errors[errors.length] = validatePresence('personal_name', 'First name is required.');
    // errors[errors.length] = validateNumericality('personal_age', 'Age');
    errors[errors.length] = validatePresence('personal_experience', 'MMORPG experience is required.');
    errors[errors.length] = validatePresence('personal_reasons', 'Reason for joining is required.');

    //     // Character info
    //     errors[errors.length] = validateField('app_name', 'Name is required');
    //     errors[errors.length] = validateField('app_race', 'Race is required');
    //     errors[errors.length] = validateField('app_class', 'Class is required');
    //     errors[errors.length] = validateField('app_played', '/played is required');
    //     errors[errors.length] = validateField('app_stats', 'Character stats are required');
    //     errors[errors.length] = validateField('app_talents', 'Character talents are required');
    //     errors[errors.length] = validateField('app_ctprofile', 'Character CTProfile is required');
    // 
    //     // Personal info
    //     errors[errors.length] = validateField('app_age', 'Your age is required');
    //     errors[errors.length] = validateField('app_timezone', 'Your timezone is required');
    // errors[errors.length] = validateField('app_guilds', 'Your guild history is required');
    //     errors[errors.length] = validateField('app_hours', 'Your hours are required');
    //     errors[errors.length] = validateField('app_why', 'Your reasons for wanting to join are required');

    // Loop through errors array and see if any validation functions returned true
    for ( var i = 0; i < errors.length; i++ )
    {
        if ( errors[i] )
        {
            // Display the errors div
            $('d-errors').style.display = '';

            // Scroll to the top so they can see the errors
            scroll(0,0);
            return false;
        }
    }

    return true;
}

/**
 * Validate a text field
 *
 * Returns FALSE if NO ERRORS were found, TRUE otherwise
 */
function validatePresence(fieldName, errMsg)
{
    var field = $(fieldName);

    if ( field.value == '' )
    {
        $('d-' + fieldName).className += ' error';

        $('errors-list').innerHTML += '<li>' + errMsg + '</li>';

        return true;
    }
    else
    {
        // No errors, so undo any error-marking we might have already done.
        $('d-' + fieldName).className = 'field';
    }

    return false;
}