function validateEmail() {
    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!regex.test($('#SendCCDATextBox').val())) {
        $('#SendCCDATextBoxImgError').removeClass('imgErrorHide').addClass('imgErrorShow');
        $('#ErrorAddressCCDALabel').css("display", "block");                // If added more fields to validate then need to only this for SendCCDATextBox
        resizeParentIframe('ambulatorySummaryPage', window);             // Defined in iframe.231520.js
        return false;
    }
    return true;
}


function removeError() {
    $('#SendCCDATextBoxImgError').removeClass('imgErrorShow').addClass('imgErrorHide');
    $('#ErrorAddressCCDALabel').css('display', 'none');                 // If added more fields to validate then need to only this for SendCCDATextBox
    resizeParentIframe('ambulatorySummaryPage', window);             // Defined in iframe.231520.js
}

// AX-21790
function limitRangeCheckBox(elem) {

    // Get Browser used. This is needed because IE cannot use 
    var whicBrowser = (function () {
        var ua = navigator.userAgent, tem,
        m = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
        if (/trident/i.test(m[1])) {
            tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
            return 'IE ' + (tem[1] || '');
        }
        if (m[1] === 'Chrome') {
            tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
            if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
        }
        m = m[2] ? [m[1], m[2]] : [navigator.appName, navigator.appVersion, '-?'];
        if ((tem = ua.match(/version\/(\d+)/i)) != null) m.splice(1, 1, tem[1]);
        return m.join(' ');
    })();

    var limit = $(elem);

    // Check if is IE and do different
    if (whicBrowser === 'IE 11') {
        if (limit.prop("checked") === true) {
            $('.rangeDateArea').prop("disabled", false);
            $('#timeFrom').prop("disabled", false);
            $('#timeTo').prop("disabled", false);
        } else {
            $('.rangeDateArea').prop("disabled", true);
            $('#timeFrom').prop("disabled", true);
            $('#timeTo').prop("disabled", true);
        }
    } else {
        if (limit.prop("checked") === true) {
            $('.rangeDateArea').find('input, textarea, button, select').prop("disabled", false);    // Enable controls inside rangeDateArea  (except Icons)
        } else {
            $('.rangeDateArea').find('input, textarea, button, select').prop("disabled", true);     // Disable controls inside rangeDateArea  (except Icons)
        }
    }

    if (limit.prop("checked") === true) {
        $('.clearDate').prop("disabled", false);                                                // Disable Clear button
        $('.clearDate').css({ cursor: 'pointer' });                                             // Hand cursor for Clear button
        $('#DVALIDEMPTY123').datepicker('enable');                                                     // Enable From DatePicker Calender Icon
        $('#DVALIDEMPTY321').datepicker('enable');                                                     // Enable To DatePicker Calender Icon        
    } else {
        $('.clearDate').prop("disabled", true);                                                 // Disable Clear button
        $('.clearDate').css({ cursor: 'default' });                                             // Default cursor for Clear button
        $('#DVALIDEMPTY123').datepicker('disable');                                                    // Disable From DatePicker Calender Icon
        $('#DVALIDEMPTY321').datepicker('disable');                                                    // Disable To DatePicker Calender Icon      
    }


}

// AX-21790
function checkDates() {

    var from = document.getElementById("DVALIDEMPTY123");              // 70889342 Change from long to string so now it has DQ instead of only numbers
    var desFrom = document.getElementById("FromDateField");
    if (from != null && desFrom != null)
        desFrom.value = from.value;

    var to = document.getElementById("DVALIDEMPTY321");                // 70889342 Change from long to string so now it has DQ instead of only numbers
    var desTo = document.getElementById("ToDateField");
    if (to != null && desTo != null)
        desTo.value = to.value;

    // Remove any Error Date and Time
    $('#FromDateImgError').removeClass("imgErrorShow").addClass("imgErrorHide");
    $('#ToDateImgError').removeClass("imgErrorShow").addClass("imgErrorHide");

    $('#FromTimeImgError').removeClass("imgErrorShow").addClass("imgErrorHide");
    $('#ToTimeImgError').removeClass("imgErrorShow").addClass("imgErrorHide");

}

//var comingFromSubmit = false;

//function onSubmitSetValues() {
//    if (!comingFromSubmit) {
//        comingFromSubmit = true;
//        return ($('#AmbSum').valid());
//    }
//    return true;
//};


/*jquery validator library*/

//$(document).ready(function () {
//    $('.selector').validate({
//        errorPlacement: function (error, element) {
//            return true;
//        },
//        highlight: function (element, errorClass) {
//            var imgId = element.id + 'ImgError';            // Id of Image error 'must' be same as TextBox field + 'ImgError'
//            var imgCtrl = $(element.form).find('img[id=' + imgId + ']');
//            imgCtrl.addClass('imgErrorShow').removeClass('imgErrorHide');

//            $('#ErrorAddressCCDALabel').css("display", "block");                // If added more fields to validate then need to only this for SendCCDATextBox  
//            //$('#NotificationSentLabel').css("display", "none");
//            //$('#ErrorSendingCCDALabel').css("display", "none");
//            //resizeParentIframe('ambulatorySummaryPage', window);             // Defined in iframe.231520.js
//        },
//        unhighlight: function (element, errorClass) {
//            var imgId = element.id + 'ImgError';            // Name of Image error 'must' be same as input field + 'ImgError'
//            var imgCtrl = $(element.form).find('img[id=' + imgId + ']');
//            imgCtrl.removeClass('imgErrorShow').addClass('imgErrorHide');

//            $('#ErrorAddressCCDALabel').css('display', 'none');                 // If added more fields to validate then need to only this for SendCCDATextBox
//            //$('#NotificationSentLabel').css("display", "none");
//            //$('#ErrorSendingCCDALabel').css("display", "none");
//            //resizeParentIframe('ambulatorySummaryPage', window);             // Defined in iframe.231520.js
//            //if (comingFromSubmit)
//            //    $('#SendCCDAButton').click();       // After resize the frame need to force to click button

//        }
//    });
//});