﻿function validateControl(arrayPos, printErrors) {
    var isValid = false;
    var isValid2 = false;
    var errMsg = '';

    switch (arrayPos) {
        case 0: { isValid = Required(UiFirstNameClientID, 'JsFirstNameErr'); if (isValid == false) { errMsg = 'First name required. '; } break; }
        case 1: { isValid = Required(UiLastNameClientID, 'JsLastNameErr'); if (isValid == false) { errMsg = 'Last name required. '; } break; }
        case 2: { isValid = Numeric(UiTelephoneClientID, 'JsTelephoneErr', true); if (isValid == false) { errMsg = 'Telephone number required. '; } break; }
        case 3: { isValid = Numeric(UiMobileClientID, 'JsMobileErr', false); if (isValid == false) { errMsg = 'Mobile phone number required. '; } break; }
        case 4: { isValid = Required(UiAddressLine1ClientID, 'JsAddressErr'); if (isValid == false) { errMsg = 'First line of your address required. '; } break; }
        case 5: { isValid = Required(UiTownClientID, 'JsTownErr'); if (isValid == false) { errMsg = 'Town of your address required. '; } break; }
        case 6: { isValid = Required(UiCountyClientID, 'JsCountyErr'); if (isValid == false) { errMsg = 'County of your address required. '; } break; }
        case 7: { isValid = Required(UiCountryClientID, 'JsCountryErr'); if (isValid == false) { errMsg = 'Country of residence required. '; } break; }
        case 8: { if (CommonUtilsValidatePostcode) { isValid = Required(UiPostcodeClientID, 'JsPostCodeErr'); if (isValid == false) { errMsg = 'Postcode required. '; } } else { isValid = true; } break; }
        case 9: { isValid = Format(UiEmailClientID, 'JsEmailErr', 'email', true); if (isValid == false) { errMsg = 'Email address required. '; } break; }
        case 10: { isValid = Matches(UiConfirmEmailClientID, 'JsConfirmEmailErr', UiEmailClientID, 'JsEmailErr'); if (isValid == false) { errMsg = 'Email address required. '; } break; }
        case 11: { isValid = Required(UiPasswordClientID, 'JsPasswordErr'); if (isValid == false) { errMsg = 'Password required. '; } break; }
        case 12: { isValid = Matches(UiConfirmPasswordClientID, 'JsConfirmPasswordErr', UiPasswordClientID, 'JsPasswordErr'); if (isValid == false) { errMsg = 'Password required. '; } break; }
        case 13: { isValid = Checked(UiAcceptTermsClientID, 'JsTermsErr'); if (isValid == false) { errMsg = 'To proceed you must agree to our terms and conditions. '; } break; }
        case 14: { if (DPAQuestionsItemsCount == 2) { isValid = radioChecked(DPAYes0, DPANo0, JsDPAQuestionErr); if (isValid == false) { errMsg = 'Please select Yes or No to the first question. '; } } else { isValid = true; } break; }
        case 15: { if (DPAQuestionsItemsCount == 2) { isValid = radioChecked(DPAYes1, DPANo1, JsDPAQuestionErr); if (isValid == false) { errMsg = 'Please select Yes or No to the second question. '; } } else { isValid = true; } break; }
        case 16: { if (businessMode) { isValid = Required(UiSalutationsClientID, 'JsSalutationsErr'); if (isValid == false) { errMsg = 'Your salutations required. '; } } else { isValid = true; } break; }
        case 17: { if (businessMode) { isValid = Required(UiFaxClientID, 'JsFaxErr'); if (isValid == false) { errMsg = 'Fax number required. '; } } else { isValid = true; } break; }
        case 18: { if (businessMode) { isValid = Required(UiWebsiteClientID, 'JsWebsiteErr'); if (isValid == false) { errMsg = 'Website required. '; } } else { isValid = true; } break; }
        case 19: { if (businessMode) { isValid = Required(UiJobTitleClientID, 'JsJobTitleErr'); if (isValid == false) { errMsg = 'Job title required. '; } } else { isValid = true; } break; }
        case 20: { if (businessMode) { isValid = Required(UiBusinessTypeClientID, 'JsBusinessTypeErr'); if (isValid == false) { errMsg = 'Business type required. '; } } else { isValid = true; } break; }
    }
    if (printErrors) { document.getElementById(UiWarningClientID).innerHTML += (errMsg); }
    return isValid;
}
function validateControls() {
    var allValid = true;
    var tmp = true;
    var printErrors = true;

    document.getElementById(UiWarningClientID).innerHTML = '';

    for (xx = 0; xx < 21; xx++) {
        tmp = validateControl(xx, true);
        allValid = (allValid && tmp);
    }
    if (allValid) {
        document.getElementById(UiSubmitClientID).click();
        document.getElementById('RegisterLoadingPanel').style.display = 'block';
        document.getElementById('workingArea').style.display = 'none';
    }
}
function DeduceHeight() {
    var deducedHeight = maxHeight;
    if ($(window).height() < deducedHeight) {
        deducedHeight = ($(window).height() - 50);
    }
    return deducedHeight;
}
$(function() {
    $('#' + UiDialogClientID).dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        /*position: 'top',
        /*maxHeight: maxHeight,
        height: DeduceHeight(),*/
        //minWidth: 580,
        //maxWidth: 580,
        width: 680
    });
    $('#' + UiDialogClientID).parent().appendTo($('form:first'));
});
function openRegisterDialog() {
    //$('#' + UiDialogClientID).dialog('option', 'height', DeduceHeight());
    $('#' + UiDialogClientID).dialog('open');
    if (globalThisBrowserIsIeLt8) {
        scrollTo(0, 0);
    }
}