﻿function STAFCheck(ReferenceName) {
    var emailexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    with (document) {
        with (getElementById('STAF_FN_' + ReferenceName)) {
            value = trim(value);
            if (value == '') {
                alert('Please enter your friend\'s name.');
                focus();
                return false;
            }
        }
        with (getElementById('STAF_YN_' + ReferenceName)) {
            value = trim(value);
            if (value == '') {
                alert('Please enter your name.');
                focus();
                return false;
            }
        }
        with (getElementById('STAF_FE_' + ReferenceName)) {
            value = trim(value);
            if (value == '') {
                alert('Please enter your friend\'s email.');
                focus();
                return false;
            }
            if (emailexp.test(value) == false) {
                alert('The e-mail address you have entered for your friend is not valid. Please correct.');
                focus();
                return false;
            }
        }
        with (getElementById('STAF_YE_' + ReferenceName)) {
            value = trim(value);
            if (value == '') {
                alert('Please enter your email.');
                focus();
                return false;
            }
            if (emailexp.test(value) == false) {
                alert('The e-mail address you have entered for yourself is not valid. Please correct.');
                focus();
                return false;
            }
        }
        if (getElementById('STAF_MSG_' + ReferenceName) != null) {
            getElementById('STAF_MSG_' + ReferenceName).value = trim(getElementById('STAF_MSG_' + ReferenceName).value);
        }
        with (getElementById('STAF_BD_' + ReferenceName)) {
            value = trim(value);
            if (value == '') {
                alert('Please enter the code exactly as shown.');
                focus();
                return false;
            }
        }
    }
    return true;
}

function STAFClear(ReferenceName) {
    with (document) {
        getElementById('STAF_FN_' + ReferenceName).value = '';
        getElementById('STAF_YN_' + ReferenceName).value = '';
        getElementById('STAF_FE_' + ReferenceName).value = '';
        getElementById('STAF_YE_' + ReferenceName).value = '';
        if (getElementById('STAF_MSG_' + ReferenceName) != null) {
            getElementById('STAF_MSG_' + ReferenceName).value = '';
        }
        if (getElementById('STAF_BD_' + ReferenceName) != null) {
            getElementById('STAF_BD_' + ReferenceName).value = '';
        }
    }
}

