
function buyersValidationCustomCB(elt, formData, f) {

    var ok = true;
    if (elt.name == 'email') {
        if (!validateEmail(elt.value)) {
            ok = false;
            elt.errStr = 'Please enter a VALID email';
        }
    }
    return ok;
}

function validateBuyerForm(f)
{
    var msgs = {
        email_create :      'Please enter your email',
        email_update:       'Please enter an email',
        password_create :   'Please create a password',
        password_update:    'Please enter a password',
        password_confirm:   'Please re-enter your password',
        passwords_mismatch: 'Passwords don\'t match!'
    }

    var rules = window.formData;
    
    var isEditProfile = f.name == 'profile_edit_frm';
    var key = isEditProfile ? 'update' : 'create';
    
    if (! rules.email) {
        rules.email = ['', '', 'Yes', msgs['email_' + key], 'Email'];
    }
    if (! rules.pwd) {
        rules.pwd = ['', '', 'Yes', msgs['password_' + key], 'Password'];
    }
    if (isEditProfile) {
        if (!rules.pwd2) {
            rules.pwd2 = ['', '', 'Yes', msgs['password_confirm'], 'Password Confirmation'];
        }
    }
    
    var result = validateForm(f, rules, buyersValidationCustomCB);
    if (result && isEditProfile) {
        var pwd1 = f.pwd.value;
        var pwd2 = f.pwd2.value;
        if (pwd1 != pwd2) {
            alert(msgs['passwords_mismatch']);
            f.pwd2.focus();
            f.pwd2.style.backgroundColor = '#fdfcd8';
            result = false;
        }
    }
    return result;
}

