﻿function pageLoad() {
    var btnSend = $get('main_body_btnSend');
    var ddlContactType = $get('main_body_ddlContactType');

    if (btnSend != null)
        $addHandler(btnSend, 'click', validateForm);
}

function pageUnload() {
    var btnSend = $get('main_body_btnSend');
    var ddlContactType = $get('main_body_ddlContactType');
    
    if(btnSend != null)
        $clearHandlers(btnSend);

}

function validateForm() {
    var errors = '';
    var firstname = $get('main_body_txtFirstName');
    var lastname = $get('main_body_txtSurname');
    var email = $get('main_body_txtEmailAddress')
    var details = $get('main_body_txtDetails');

    if (firstname.value == '') {
        errors += 'Please enter your first name.\n';
    }
    if (lastname.value == '') {
        errors += 'Please enter your surname.\n';
    }

    if (email.value == '' || !ValidateEmail(email.value)) {
        if (errors.length == 0) { email.focus(); email.select(); }
        errors += 'Please enter a valid e-mail address.\n';
    }
    if (details.value == '') //not a sales enquiry
    {
        if (errors.length == 0) details.focus();
        errors += 'Please enter the details of your enquiry.\n';
    }

    if (errors.length > 0) {
        alert(errors);
        return false;
    }
    else return true;
}
