/* ---------------------------
    Javascript Collection
    Orb Solutions - 18/07/04
    Peter Stone
   --------------------------- */

// Validate the specified field (Field is Required)
function validateRequired (field, label)
{
    if (field.value == "")
    {
        alert ("The '" + label + "' field is required");
        field.focus ();
        return false;
    }
    else
        return true;
        
}

// Validate the specified field (Field requires valid email)
function validateEmail (field, label)
{
    if (!validateRequired (field, label))
        return false;
    
    var index = field.value.indexOf("@");
    if (index > 0)
    {
        var pindex = field.value.indexOf(".",index);
        if ((pindex > index+1) && (field.value.length > pindex+1))
            return true;
    }
    alert ("Please enter your email address in the form: name@domain.com");
    field.focus ();
    return false;
}

// Call all the functions needed to validate the form
function validateRegisterForm (form)
{
    if (!validateRequired (form.name, "Name"))
        return false;

    if (!validateRequired (form.org, "Organisation"))
        return false;

    if (!validateEmail (form.email, "Email"))
        return false;
        
    if (!validateRequired (form.user, "Username"))
        return false;
        
    if (!validateRequired (form.pass, "Password"))
        return false;

    if (!validateRequired (form.pass2, "Confirm Password"))
        return false;
        
    if (form.pass.value != form.pass2.value)
    {
        alert ("The passwords do not match! Make sure you enter the same password in both fields.");
        return false;
    }
        
    return true;
}

// Call all the functions needed to validate the form
function validateUpdateForm (form)
{
    if (!validateRequired (form.name, "Name"))
        return false;

    if (!validateRequired (form.org, "Organisation"))
        return false;

    if (!validateEmail (form.email, "Email"))
        return false;
        
    return true;
}