/*!
 * Validates registration fields.
 */

function validate_non_academic_checkbox()
{
    var form = get_compatible_element('register');
    if (form.non_academic_understanding.checked != 1)
    {
        alert("You must check the box in order to proceed with your registration");
	return false;
    }
    
    // If we get here, there were no problems so submit the form...
    form.submit();
    return true;

}

function validate_registration_fields()
{
    var form = get_compatible_element('register');
    
    
    var address = form.email_address.value;
    if ( address.length < 1 )
    {
        alert("You must specify your e-mail address");
        return false;
    }
    
    if ( ! string_is_valid_email(address) )
    {
        alert("The e-mail address doesnt appear to be valid");
        return false;
    }
    
    if ( form.first_name.value.length < 1 )
    {
        alert("You must specify your first name");
        return false;
    }
    if ( form.second_name.value.length < 1 )
    {
        alert("You must specify your second name");
        return false;
    }
    if ( form.institution.value.length < 1 )
    {
        alert("You must specify your institution");
        return false;
    }
    if ( form.password.value.length < 1 )
    {
        alert("You must specify a password");
        return false;
    }
    if ( form.password.value.length < 6 )
    {
        alert("Your password must be at least 6 characters long");
        return false;
    }
    if ( form.password.value.length > 15 )    
    {
        alert("Your password cant be longer than 15 characters");
        return false;
    }
    if ( form.confirm_password.value.length < 1 )
    {
        alert("You must confirm your password");
        return false;
    }
    if ( form.confirm_password.value != form.password.value )
    {
        alert("Your password was not confirmed correctly");
        return false;
    }

    // If we get here, there were no problems so submit the form...
    form.submit();
    return true;
}

function validate_update_registration_fields()
{
    var form = get_compatible_element('reregister');  

    if ( form.password.value.length < 1 )
    {
        alert("You must specify an old password");
        return false;
    }
    if ( form.password.value.length < 6 )
    {
        alert("Your old password must be at least 6 characters long");
        return false;
    }
    if ( form.password.value.length > 15 )    
    {
        alert("Your old password cant be longer than 15 characters");
        return false;
    }
    
    if ( form.new_password.value.length < 1 )
    {
        alert("You must specify a new password");
        return false;
    }
    if ( form.new_password.value.length < 6 )
    {
        alert("Your new password must be at least 6 characters long");
        return false;
    }
    if ( form.new_password.value.length > 15 )    
    {
        alert("Your new password cant be longer than 15 characters");
        return false;
    }
    
    if ( form.confirm_new_password.value.length < 1 )
    {
        alert("You must confirm your password");
        return false;
    }
    
    if ( form.confirm_new_password.value != form.new_password.value )
    {
        alert("Your new password was not confirmed correctly");
        return false;
    }
        
    // If we get here, there were no problems so submit the form...
    form.submit();
    return true;    
}

function validate_login_fields()
{
    var form = get_compatible_element('login');
    
    var address = form.email_address.value;
    if ( address.length < 1 )
    {
        alert("You must specify your e-mail address");
        return false;
    }
    
    if ( ! string_is_valid_email(address) )
    {
        alert("The e-mail address doesnt appear to be valid");
        return false;
    }
    
    if ( form.password.length < 1 )
    {
        alert("You must specify a password");
        return false;
    }

    // If we get here, there were no problems so submit the form...
    form.submit();
    return true;
}

function accept_license_conditions()
{
    var form = get_compatible_element('license');  
    form.submit();
    return true;
}
