function validate(what) {
    var name_err = 0;
    var email_err = 0;

    var pattern = /[\w+]/;
    if (!pattern.test(what.attribute1.value)) {
        name_err = 1;
    }

    if (!(validateAddress(what.email.value))) {
        email_err = 1;
    }

    if (name_err) {
        alert('Please enter your name.');
        return false;
    }
    else if (email_err) {
        alert('Please enter a valid email address.');
        return false;
    }
    else{
        return true;
    }
}

function validateAddress(incoming) {
    var emailstring = incoming;
    var ampIndex = emailstring.indexOf("@");
    var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
    // find a dot in the portion of the string after the ampersand only
    var dotIndex = afterAmp.indexOf(".");
    // determine dot position in entire string (not just after amp portion)
    dotIndex = dotIndex + ampIndex + 1;
    // afterAmp will be portion of string from ampersand to dot
    afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
    // afterDot will be portion of string from dot to end of string
    var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
    var beforeAmp = emailstring.substring(0,(ampIndex));
    var email_regex = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    // index of -1 means "not found"
    if ((emailstring.indexOf("@") != "-1") &&
        (emailstring.length > 5) &&
        (afterAmp.length > 0) &&
        (beforeAmp.length > 1) &&
        (afterDot.length > 1) &&
        (email_regex.test(emailstring)) ) {
        return true;
    } else {
        //alert("Please submit a valid email address.");
        return false;
    }
}   
