Everywhere I go I am asked: “Do you have tips on how to sleep better?” There are some things that work for everyone, in general. My “5 Steps for Better Rest” from The Sleep Doctor’s Diet include:

Step 1: Know your Bedtime and Stick to One Sleep Schedule

Of all the sleep tips you could ever read or hear about, the most important one is to stick to one sleep schedule—every day. This means going to bed and waking up at the same time each day. When sleep has a regular rhythm, your biological clock will be in sync and all of your other bodily functions will go smoother, including your sleep. You are probably squirming as you read this tip, thinking about your own sleep issues and how you have anything but a regular sleep routine.

One of my simple tricks is to use the Sleep Calculator tool to know what time you should be going to bed.

[et_pb_video src=”https://www.youtube.com/watch?v=uzAIKHPcds0″ custom_css_main_element=”width:80%;||margin-left:auto;||margin-right:auto;||margin-bottom:50px!important;” /]

Step 2: Eliminate All Caffeine Starting at 2 PM

I know what you are thinking: Is he serious? How can stopping my caffeine intake at 2:00 p.m. help me sleep better? It’s simple! Caffeine has what’s called a “half-life” of about 8 hours, which means that its level is reduced, but still somewhat effective in your system after this time. Caffeine is a stimulant, and it will prevent you from either falling asleep or having good quality sleep.

Step 3: No Alcohol Within 3 Hours of Bedtime

For years sleep researchers have known that alcohol is the number one sleep aid in the world. If you look back at the results of the 2005 Sleep in America poll, you will find that 11 percent of those polled used alcohol as a sleep aid at least a few nights a week.  Another study conducted in the Detroit area showed that 13 percent of those polled had used alcohol as a sleep aid in the past year. However, the reality is alcohol is not the answer to getting better sleep. While alcohol can make you sleepy, it also does the following to detract from sound sleep:

  1. Keeps you from reaching the deep stages of sleep
  2. Dehydrates you
  3. Awakens you in the middle of the night (usually to go to the bathroom)

Having a few drinks before bedtime will increase your NREM sleep (Stages 1 and 2) and reduce your REM sleep. You’ll remember that REM sleep helps you organize and store your memories. Too little REM sleep can be devastating for the brain and body. In addition, REM sleep is the sleep stage where the most calories are burned. And alcohol is filled with empty calories, so drinking is never a good idea when you’re trying to sleep better or lose weight. See more info on REM sleep here.

Step 4: Stop Exercising 4 Hours Before Bed

No one would argue that exercise isn’t good for you. It keeps muscles
and bones strong and maintains good cardiovascular health. Many of my sleep patients who lead sedentary lives and don’t exercise regularly are missing out on an excellent sleep remedy. Data suggest not only that exercising during the day will help you fall asleep more quickly and plunge you into deeper sleep for a longer period of time, but also that exercising causes your body to produce growth hormones, which help it to repair and revitalize itself. Many of my patients report that they sleep better with regular exercise and that they feel more alert and rejuvenated the following day.

Step 5: Give the Sun a “High 5” Every Morning (15 Minutes of Morning Sunlight)

Getting outside in the sun for 15 minutes each morning helps to regulate the production of melatonin, the sleep hormone. Your internal body clock (the circadian rhythm) runs on a 24-hour schedule and functions best when you are exposed to a regular pattern of light and dark. Malfunctions in your circadian rhythms because of changes in light and dark exposure can negatively impact your ability to get a good night’s sleep.

Unfortunately, unlike our cave-dwelling ancestors who rose with the sun and retired with the moon, most of us let the demands of everyday life dictate the times for sleeping and rising. Millions of people today force their bodies to adjust to artificial sleep schedules, negatively affecting both their sleep and their health.

By following these five steps on how to sleep better, you will put yourself on the road to improved rest and greater health. Also visit the Family & Sleep page to gain more valuable advice.

For more tips, download my free ebook:

<!– [et_pb_line_break_holder] –><style><!– [et_pb_line_break_holder] –> #_form_15_ { font-size:14px; line-height:1.6; font-family:arial, helvetica, sans-serif; margin:0; }<!– [et_pb_line_break_holder] –> #_form_15_ * { outline:0; }<!– [et_pb_line_break_holder] –> ._form_hide { display:none; visibility:hidden; }<!– [et_pb_line_break_holder] –> ._form_show { display:block; visibility:visible; }<!– [et_pb_line_break_holder] –> #_form_15_._form-top { top:0; }<!– [et_pb_line_break_holder] –> #_form_15_._form-bottom { bottom:0; }<!– [et_pb_line_break_holder] –> #_form_15_._form-left { left:0; }<!– [et_pb_line_break_holder] –> #_form_15_._form-right { right:0; }<!– [et_pb_line_break_holder] –> #_form_15_ input[type=”text”],#_form_15_ input[type=”date”],#_form_15_ textarea { padding:6px; height:auto; border:#979797 1px solid; border-radius:4px; color:#000 !important; font-size:13px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; }<!– [et_pb_line_break_holder] –> #_form_15_ textarea { resize:none; }<!– [et_pb_line_break_holder] –> #_form_15_ ._submit { -webkit-appearance:none; cursor:pointer; font-family:arial, sans-serif; font-size:14px; text-align:center; background:#333 !important; border:0 !important; -moz-border-radius:4px !important; -webkit-border-radius:4px !important; border-radius:4px !important; color:#fff !important; padding:10px !important; }<!– [et_pb_line_break_holder] –> #_form_15_ ._close-icon { cursor:pointer; background-image:url(‘https://d226aj4ao1t61q.cloudfront.net/esfkyjh1u_forms-close-dark.png’); background-repeat:no-repeat; background-size:14.2px 14.2px; position:absolute; display:block; top:11px; right:9px; overflow:hidden; width:16.2px; height:16.2px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._close-icon:before { position:relative; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-body { margin-bottom:30px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-image-left { width:150px; float:left; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-content-right { margin-left:164px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-branding { color:#fff; font-size:10px; clear:both; text-align:left; margin-top:30px; font-weight:100; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-branding ._logo { display:block; width:130px; height:14px; margin-top:6px; background-image:url(‘https://d226aj4ao1t61q.cloudfront.net/hh9ujqgv5_aclogo_li.png’); background-size:130px auto; background-repeat:no-repeat; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-label,#_form_15_ ._form_element ._form-label { font-weight:bold; margin-bottom:5px; display:block; }<!– [et_pb_line_break_holder] –> #_form_15_._dark ._form-branding { color:#333; }<!– [et_pb_line_break_holder] –> #_form_15_._dark ._form-branding ._logo { background-image:url(‘https://d226aj4ao1t61q.cloudfront.net/jftq2c8s_aclogo_dk.png’); }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element { position:relative; margin-bottom:10px; font-size:0; max-width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element * { font-size:14px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element._clear { clear:both; width:100%; float:none; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element._clear:after { clear:left; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element input[type=”text”],#_form_15_ ._form_element input[type=”date”],#_form_15_ ._form_element select,#_form_15_ ._form_element textarea:not(.g-recaptcha-response) { display:block; width:100%; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; }<!– [et_pb_line_break_holder] –> #_form_15_ ._field-wrapper { position:relative; }<!– [et_pb_line_break_holder] –> #_form_15_ ._inline-style { float:left; }<!– [et_pb_line_break_holder] –> #_form_15_ ._inline-style input[type=”text”] { width:150px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._inline-style:not(._clear) + ._inline-style:not(._clear) { margin-left:20px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element img._form-image { max-width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._clear-element { clear:left; }<!– [et_pb_line_break_holder] –> #_form_15_ ._full_width { width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_full_field { display:block; width:100%; margin-bottom:10px; }<!– [et_pb_line_break_holder] –> #_form_15_ input[type=”text”]._has_error,#_form_15_ textarea._has_error { border:#f37c7b 1px solid; }<!– [et_pb_line_break_holder] –> #_form_15_ input[type=”checkbox”]._has_error { outline:#f37c7b 1px solid; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error { display:block; position:absolute; font-size:13px; z-index:10000001; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error._above { padding-bottom:4px; top:-41px; right:0; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error._below { padding-top:4px; top:100%; right:0; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error._above ._error-arrow { bottom:0; right:15px; border-left:5px solid transparent; border-right:5px solid transparent; border-top:5px solid #f37c7b; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error._below ._error-arrow { top:0; right:15px; border-left:5px solid transparent; border-right:5px solid transparent; border-bottom:5px solid #f37c7b; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error-inner { padding:8px 12px; background-color:#f37c7b; font-size:13px; font-family:arial, sans-serif; color:#fff; text-align:center; text-decoration:none; -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error-inner._form_error { margin-bottom:5px; text-align:left; }<!– [et_pb_line_break_holder] –> #_form_15_ ._button-wrapper ._error-inner._form_error { position:static; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error-inner._no_arrow { margin-bottom:10px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error-arrow { position:absolute; width:0; height:0; }<!– [et_pb_line_break_holder] –> #_form_15_ ._error-html { margin-bottom:10px; }<!– [et_pb_line_break_holder] –> .pika-single { z-index:10000001 !important; }<!– [et_pb_line_break_holder] –> @media all and (min-width:320px) and (max-width:667px) { ::-webkit-scrollbar { display:none; }<!– [et_pb_line_break_holder] –> #_form_15_ { margin:0; width:100%; min-width:100%; max-width:100%; box-sizing:border-box; }<!– [et_pb_line_break_holder] –> #_form_15_ * { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; font-size:1em; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-content { margin:0; width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-inner { display:block; min-width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-title,#_form_15_ ._inline-style { margin-top:0; margin-right:0; margin-left:0; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-title { font-size:1.2em; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form_element { margin:0 0 20px; padding:0; width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-element,#_form_15_ ._inline-style,#_form_15_ input[type=”text”],#_form_15_ label,#_form_15_ p,#_form_15_ textarea:not(.g-recaptcha-response) { float:none; display:block; width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._row._checkbox-radio label { display:inline; }<!– [et_pb_line_break_holder] –> #_form_15_ ._row,#_form_15_ p,#_form_15_ label { margin-bottom:0.7em; width:100%; }<!– [et_pb_line_break_holder] –> #_form_15_ ._row input[type=”checkbox”],#_form_15_ ._row input[type=”radio”] { margin:0 !important; vertical-align:middle !important; }<!– [et_pb_line_break_holder] –> #_form_15_ ._row input[type=”checkbox”] + span label { display:inline; }<!– [et_pb_line_break_holder] –> #_form_15_ ._row span label { margin:0 !important; width:initial !important; vertical-align:middle !important; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-image { max-width:100%; height:auto !important; }<!– [et_pb_line_break_holder] –> #_form_15_ input[type=”text”] { padding-left:10px; padding-right:10px; font-size:16px; line-height:1.3em; -webkit-appearance:none; }<!– [et_pb_line_break_holder] –> #_form_15_ input[type=”radio”],#_form_15_ input[type=”checkbox”] { display:inline-block; width:1.3em; height:1.3em; font-size:1em; margin:0 0.3em 0 0; vertical-align:baseline; }<!– [et_pb_line_break_holder] –> #_form_15_ button[type=”submit”] { padding:20px; font-size:1.5em; }<!– [et_pb_line_break_holder] –> #_form_15_ ._inline-style { margin:20px 0 0 !important; }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> #_form_15_ { position:relative; text-align:left; margin:25px auto 0; padding:20px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; *zoom:1; background:#fff !important; border:2px solid #706c6c !important; width:300px; -moz-border-radius:3px !important; -webkit-border-radius:3px !important; border-radius:3px !important; color:#000 !important; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-title { font-size:22px; line-height:22px; font-weight:600; margin-bottom:0; }<!– [et_pb_line_break_holder] –> #_form_15_:before,#_form_15_:after { content:” “; display:table; }<!– [et_pb_line_break_holder] –> #_form_15_:after { clear:both; }<!– [et_pb_line_break_holder] –> #_form_15_._inline-style { width:auto; display:inline-block; }<!– [et_pb_line_break_holder] –> #_form_15_._inline-style input[type=”text”],#_form_15_._inline-style input[type=”date”] { padding:10px 12px; }<!– [et_pb_line_break_holder] –> #_form_15_._inline-style button._inline-style { position:relative; top:27px; }<!– [et_pb_line_break_holder] –> #_form_15_._inline-style p { margin:0; }<!– [et_pb_line_break_holder] –> #_form_15_._inline-style ._button-wrapper { position:relative; margin:27px 12.5px 0 20px; }<!– [et_pb_line_break_holder] –> #_form_15_ ._form-thank-you { position:relative; left:0; right:0; text-align:center; font-size:18px; }<!– [et_pb_line_break_holder] –> @media all and (min-width:320px) and (max-width:667px) { #_form_15_._inline-form._inline-style ._inline-style._button-wrapper { margin-top:20px !important; margin-left:0 !important; }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –>}<!– [et_pb_line_break_holder] –>._x52722042 input {<!– [et_pb_line_break_holder] –> <!– [et_pb_line_break_holder] –>}<!– [et_pb_line_break_holder] –>._form_15 {<!– [et_pb_line_break_holder] –> <!– [et_pb_line_break_holder] –>}</style><!– [et_pb_line_break_holder] –><form method=”POST” action=”https://thesleepdoctor.activehosted.com/proc.php” id=”_form_15_” class=”_form _form_15 _inline-form _dark” novalidate><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”u” value=”15″ /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”f” value=”15″ /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”s” /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”c” value=”0″ /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”m” value=”0″ /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”act” value=”sub” /><!– [et_pb_line_break_holder] –> <input type=”hidden” name=”v” value=”2″ /><!– [et_pb_line_break_holder] –> <div class=”_form-content”><!– [et_pb_line_break_holder] –> <div class=”_form_element _x38055246 _full_width _clear” ><!– [et_pb_line_break_holder] –> <div class=”_form-title”><!– [et_pb_line_break_holder] –> Ten Things Great Sleepers Do – Get Your FREE eBook!<!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_form_element _x17014814 _full_width _clear” ><!– [et_pb_line_break_holder] –> <div class=”_html-code”><!– [et_pb_line_break_holder] –> <p><!– [et_pb_line_break_holder] –> What are the habits of great sleepers? Discover the 10 things great sleepers do in this informative book. This information will help you improve your sleep tonight.<!– [et_pb_line_break_holder] –> </p><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_form_element _x52722042 _full_width ” ><!– [et_pb_line_break_holder] –> <label class=”_form-label”><!– [et_pb_line_break_holder] –> First Name<!– [et_pb_line_break_holder] –> </label><!– [et_pb_line_break_holder] –> <div class=”_field-wrapper”><!– [et_pb_line_break_holder] –> <input type=”text” name=”firstname” placeholder=”Type your first name” /><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_form_element _x41737965 _full_width ” ><!– [et_pb_line_break_holder] –> <label class=”_form-label”><!– [et_pb_line_break_holder] –> Last Name<!– [et_pb_line_break_holder] –> </label><!– [et_pb_line_break_holder] –> <div class=”_field-wrapper”><!– [et_pb_line_break_holder] –> <input type=”text” name=”lastname” placeholder=”Type your last name” /><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_form_element _x88699416 _full_width ” ><!– [et_pb_line_break_holder] –> <label class=”_form-label”><!– [et_pb_line_break_holder] –> Email*<!– [et_pb_line_break_holder] –> </label><!– [et_pb_line_break_holder] –> <div class=”_field-wrapper”><!– [et_pb_line_break_holder] –> <input type=”text” name=”email” placeholder=”Type your email” required/><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_button-wrapper _full_width”><!– [et_pb_line_break_holder] –> <button id=”_form_15_submit” class=”_submit” type=”submit”><!– [et_pb_line_break_holder] –> Submit<!– [et_pb_line_break_holder] –> </button><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_clear-element”><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –> <div class=”_form-thank-you” style=”display:none;”><!– [et_pb_line_break_holder] –> </div><!– [et_pb_line_break_holder] –></form><script type=”text/javascript”><!– [et_pb_line_break_holder] –>window.cfields = [];<!– [et_pb_line_break_holder] –>window._show_thank_you = function(id, message, trackcmp_url) {<!– [et_pb_line_break_holder] –> var form = document.getElementById(‘_form_’ + id + ‘_’), thank_you = form.querySelector(‘._form-thank-you’);<!– [et_pb_line_break_holder] –> form.querySelector(‘._form-content’).style.display = ‘none’;<!– [et_pb_line_break_holder] –> thank_you.innerHTML = message;<!– [et_pb_line_break_holder] –> thank_you.style.display = ‘block’;<!– [et_pb_line_break_holder] –> if (typeof(trackcmp_url) != ‘undefined’ && trackcmp_url) {<!– [et_pb_line_break_holder] –> // Site tracking URL to use after inline form submission.<!– [et_pb_line_break_holder] –> _load_script(trackcmp_url);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (typeof window._form_callback !== ‘undefined’) window._form_callback(id);<!– [et_pb_line_break_holder] –>};<!– [et_pb_line_break_holder] –>window._show_error = function(id, message, html) {<!– [et_pb_line_break_holder] –> var form = document.getElementById(‘_form_’ + id + ‘_’), err = document.createElement(‘div’), button = form.querySelector(‘button’), old_error = form.querySelector(‘._form_error’);<!– [et_pb_line_break_holder] –> if (old_error) old_error.parentNode.removeChild(old_error);<!– [et_pb_line_break_holder] –> err.innerHTML = message;<!– [et_pb_line_break_holder] –> err.className = ‘_error-inner _form_error _no_arrow’;<!– [et_pb_line_break_holder] –> var wrapper = document.createElement(‘div’);<!– [et_pb_line_break_holder] –> wrapper.className = ‘_form-inner’;<!– [et_pb_line_break_holder] –> wrapper.appendChild(err);<!– [et_pb_line_break_holder] –> button.parentNode.insertBefore(wrapper, button);<!– [et_pb_line_break_holder] –> document.querySelector(‘[id^=”_form”][id$=”_submit”]’).disabled = false;<!– [et_pb_line_break_holder] –> if (html) {<!– [et_pb_line_break_holder] –> var div = document.createElement(‘div’);<!– [et_pb_line_break_holder] –> div.className = ‘_error-html’;<!– [et_pb_line_break_holder] –> div.innerHTML = html;<!– [et_pb_line_break_holder] –> err.appendChild(div);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –>};<!– [et_pb_line_break_holder] –>window._load_script = function(url, callback) {<!– [et_pb_line_break_holder] –> var head = document.querySelector(‘head’), script = document.createElement(‘script’), r = false;<!– [et_pb_line_break_holder] –> script.type = ‘text/javascript’;<!– [et_pb_line_break_holder] –> script.charset = ‘utf-8’;<!– [et_pb_line_break_holder] –> script.src = url;<!– [et_pb_line_break_holder] –> if (callback) {<!– [et_pb_line_break_holder] –> script.onload = script.onreadystatechange = function() {<!– [et_pb_line_break_holder] –> if (!r && (!this.readyState || this.readyState == ‘complete’)) {<!– [et_pb_line_break_holder] –> r = true;<!– [et_pb_line_break_holder] –> callback();<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> head.appendChild(script);<!– [et_pb_line_break_holder] –>};<!– [et_pb_line_break_holder] –>(function() {<!– [et_pb_line_break_holder] –> if (window.location.search.search(“excludeform”) !== -1) return false;<!– [et_pb_line_break_holder] –> var getCookie = function(name) {<!– [et_pb_line_break_holder] –> var match = document.cookie.match(new RegExp(‘(^|; )’ + name + ‘=([^;]+)’));<!– [et_pb_line_break_holder] –> return match ? match[2] : null;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> var setCookie = function(name, value) {<!– [et_pb_line_break_holder] –> var now = new Date();<!– [et_pb_line_break_holder] –> var time = now.getTime();<!– [et_pb_line_break_holder] –> var expireTime = time + 1000 * 60 * 60 * 24 * 365;<!– [et_pb_line_break_holder] –> now.setTime(expireTime);<!– [et_pb_line_break_holder] –> document.cookie = name + ‘=’ + value + ‘; expires=’ + now + ‘;path=/’;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> var addEvent = function(element, event, func) {<!– [et_pb_line_break_holder] –> if (element.addEventListener) {<!– [et_pb_line_break_holder] –> element.addEventListener(event, func);<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> var oldFunc = element[‘on’ + event];<!– [et_pb_line_break_holder] –> element[‘on’ + event] = function() {<!– [et_pb_line_break_holder] –> oldFunc.apply(this, arguments);<!– [et_pb_line_break_holder] –> func.apply(this, arguments);<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> var _removed = false;<!– [et_pb_line_break_holder] –> var form_to_submit = document.getElementById(‘_form_15_’);<!– [et_pb_line_break_holder] –> var allInputs = form_to_submit.querySelectorAll(‘input, select, textarea’), tooltips = [], submitted = false;<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –> var getUrlParam = function(name) {<!– [et_pb_line_break_holder] –> var regexStr = ‘[\?&]’ + name + ‘=([^&#]*)’;<!– [et_pb_line_break_holder] –> var results = new RegExp(regexStr, ‘i’).exec(window.location.href);<!– [et_pb_line_break_holder] –> return results != undefined ? decodeURIComponent(results[1]) : false;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –> for (var i = 0; i < allInputs.length; i++) {<!– [et_pb_line_break_holder] –> var regexStr = “field\\[(\\d+)\\]”;<!– [et_pb_line_break_holder] –> var results = new RegExp(regexStr).exec(allInputs[i].name);<!– [et_pb_line_break_holder] –> if (results != undefined) {<!– [et_pb_line_break_holder] –> allInputs[i].dataset.name = window.cfields[results[1]];<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> allInputs[i].dataset.name = allInputs[i].name;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> var fieldVal = getUrlParam(allInputs[i].dataset.name);<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –> if (fieldVal) {<!– [et_pb_line_break_holder] –> if (allInputs[i].type == “radio” || allInputs[i].type == “checkbox”) {<!– [et_pb_line_break_holder] –> if (allInputs[i].value == fieldVal) {<!– [et_pb_line_break_holder] –> allInputs[i].checked = true;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> allInputs[i].value = fieldVal;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –> var remove_tooltips = function() {<!– [et_pb_line_break_holder] –> for (var i = 0; i < tooltips.length; i++) {<!– [et_pb_line_break_holder] –> tooltips[i].tip.parentNode.removeChild(tooltips[i].tip);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> tooltips = [];<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var remove_tooltip = function(elem) {<!– [et_pb_line_break_holder] –> for (var i = 0; i < tooltips.length; i++) {<!– [et_pb_line_break_holder] –> if (tooltips[i].elem === elem) {<!– [et_pb_line_break_holder] –> tooltips[i].tip.parentNode.removeChild(tooltips[i].tip);<!– [et_pb_line_break_holder] –> tooltips.splice(i, 1);<!– [et_pb_line_break_holder] –> return;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var create_tooltip = function(elem, text) {<!– [et_pb_line_break_holder] –> var tooltip = document.createElement(‘div’), arrow = document.createElement(‘div’), inner = document.createElement(‘div’), new_tooltip = {};<!– [et_pb_line_break_holder] –> if (elem.type != ‘radio’ && elem.type != ‘checkbox’) {<!– [et_pb_line_break_holder] –> tooltip.className = ‘_error’;<!– [et_pb_line_break_holder] –> arrow.className = ‘_error-arrow’;<!– [et_pb_line_break_holder] –> inner.className = ‘_error-inner’;<!– [et_pb_line_break_holder] –> inner.innerHTML = text;<!– [et_pb_line_break_holder] –> tooltip.appendChild(arrow);<!– [et_pb_line_break_holder] –> tooltip.appendChild(inner);<!– [et_pb_line_break_holder] –> elem.parentNode.appendChild(tooltip);<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> tooltip.className = ‘_error-inner _no_arrow’;<!– [et_pb_line_break_holder] –> tooltip.innerHTML = text;<!– [et_pb_line_break_holder] –> elem.parentNode.insertBefore(tooltip, elem);<!– [et_pb_line_break_holder] –> new_tooltip.no_arrow = true;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> new_tooltip.tip = tooltip;<!– [et_pb_line_break_holder] –> new_tooltip.elem = elem;<!– [et_pb_line_break_holder] –> tooltips.push(new_tooltip);<!– [et_pb_line_break_holder] –> return new_tooltip;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var resize_tooltip = function(tooltip) {<!– [et_pb_line_break_holder] –> var rect = tooltip.elem.getBoundingClientRect();<!– [et_pb_line_break_holder] –> var doc = document.documentElement, scrollPosition = rect.top – ((window.pageYOffset || doc.scrollTop) – (doc.clientTop || 0));<!– [et_pb_line_break_holder] –> if (scrollPosition < 40) {<!– [et_pb_line_break_holder] –> tooltip.tip.className = tooltip.tip.className.replace(/ ?(_above|_below) ?/g, ”) + ‘ _below’;<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> tooltip.tip.className = tooltip.tip.className.replace(/ ?(_above|_below) ?/g, ”) + ‘ _above’;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var resize_tooltips = function() {<!– [et_pb_line_break_holder] –> if (_removed) return;<!– [et_pb_line_break_holder] –> for (var i = 0; i < tooltips.length; i++) {<!– [et_pb_line_break_holder] –> if (!tooltips[i].no_arrow) resize_tooltip(tooltips[i]);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var validate_field = function(elem, remove) {<!– [et_pb_line_break_holder] –> var tooltip = null, value = elem.value, no_error = true;<!– [et_pb_line_break_holder] –> remove ? remove_tooltip(elem) : false;<!– [et_pb_line_break_holder] –> if (elem.type != ‘checkbox’) elem.className = elem.className.replace(/ ?_has_error ?/g, ”);<!– [et_pb_line_break_holder] –> if (elem.getAttribute(‘required’) !== null) {<!– [et_pb_line_break_holder] –> if (elem.type == ‘radio’ || (elem.type == ‘checkbox’ && /any/.test(elem.className))) {<!– [et_pb_line_break_holder] –> var elems = form_to_submit.elements[elem.name];<!– [et_pb_line_break_holder] –> if (!(elems instanceof NodeList || elems instanceof HTMLCollection) || elems.length <= 1) {<!– [et_pb_line_break_holder] –> no_error = elem.checked;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> else {<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> for (var i = 0; i < elems.length; i++) {<!– [et_pb_line_break_holder] –> if (elems[i].checked) no_error = true;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (!no_error) {<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, “Please select an option.”);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> } else if (elem.type ==’checkbox’) {<!– [et_pb_line_break_holder] –> var elems = form_to_submit.elements[elem.name], found = false, err = [];<!– [et_pb_line_break_holder] –> no_error = true;<!– [et_pb_line_break_holder] –> for (var i = 0; i < elems.length; i++) {<!– [et_pb_line_break_holder] –> if (elems[i].getAttribute(‘required’) === null) continue;<!– [et_pb_line_break_holder] –> if (!found && elems[i] !== elem) return true;<!– [et_pb_line_break_holder] –> found = true;<!– [et_pb_line_break_holder] –> elems[i].className = elems[i].className.replace(/ ?_has_error ?/g, ”);<!– [et_pb_line_break_holder] –> if (!elems[i].checked) {<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> elems[i].className = elems[i].className + ‘ _has_error’;<!– [et_pb_line_break_holder] –> err.push(“Checking %s is required”.replace(“%s”, elems[i].value));<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (!no_error) {<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, err.join(‘<br/>’));<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> } else if (elem.tagName == ‘SELECT’) {<!– [et_pb_line_break_holder] –> var selected = true;<!– [et_pb_line_break_holder] –> if (elem.multiple) {<!– [et_pb_line_break_holder] –> selected = false;<!– [et_pb_line_break_holder] –> for (var i = 0; i < elem.options.length; i++) {<!– [et_pb_line_break_holder] –> if (elem.options[i].selected) {<!– [et_pb_line_break_holder] –> selected = true;<!– [et_pb_line_break_holder] –> break;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> } else {<!– [et_pb_line_break_holder] –> for (var i = 0; i < elem.options.length; i++) {<!– [et_pb_line_break_holder] –> if (elem.options[i].selected && !elem.options[i].value) {<!– [et_pb_line_break_holder] –> selected = false;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (!selected) {<!– [et_pb_line_break_holder] –> elem.className = elem.className + ‘ _has_error’;<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, “Please select an option.”);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> } else if (value === undefined || value === null || value === ”) {<!– [et_pb_line_break_holder] –> elem.className = elem.className + ‘ _has_error’;<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, “This field is required.”);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (no_error && elem.name == ’email’) {<!– [et_pb_line_break_holder] –> if (!value.match(/^[\+_a-z0-9-‘&=]+(\.[\+_a-z0-9-‘]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i)) {<!– [et_pb_line_break_holder] –> elem.className = elem.className + ‘ _has_error’;<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, “Enter a valid email address.”);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (no_error && /date_field/.test(elem.className)) {<!– [et_pb_line_break_holder] –> if (!value.match(/^\d\d\d\d-\d\d-\d\d$/)) {<!– [et_pb_line_break_holder] –> elem.className = elem.className + ‘ _has_error’;<!– [et_pb_line_break_holder] –> no_error = false;<!– [et_pb_line_break_holder] –> tooltip = create_tooltip(elem, “Enter a valid date.”);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> tooltip ? resize_tooltip(tooltip) : false;<!– [et_pb_line_break_holder] –> return no_error;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var needs_validate = function(el) {<!– [et_pb_line_break_holder] –> return el.name == ’email’ || el.getAttribute(‘required’) !== null;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> var validate_form = function(e) {<!– [et_pb_line_break_holder] –> var err = form_to_submit.querySelector(‘._form_error’), no_error = true;<!– [et_pb_line_break_holder] –> if (!submitted) {<!– [et_pb_line_break_holder] –> submitted = true;<!– [et_pb_line_break_holder] –> for (var i = 0, len = allInputs.length; i < len; i++) {<!– [et_pb_line_break_holder] –> var input = allInputs[i];<!– [et_pb_line_break_holder] –> if (needs_validate(input)) {<!– [et_pb_line_break_holder] –> if (input.type == ‘text’) {<!– [et_pb_line_break_holder] –> addEvent(input, ‘blur’, function() {<!– [et_pb_line_break_holder] –> this.value = this.value.trim();<!– [et_pb_line_break_holder] –> validate_field(this, true);<!– [et_pb_line_break_holder] –> });<!– [et_pb_line_break_holder] –> addEvent(input, ‘input’, function() {<!– [et_pb_line_break_holder] –> validate_field(this, true);<!– [et_pb_line_break_holder] –> });<!– [et_pb_line_break_holder] –> } else if (input.type == ‘radio’ || input.type == ‘checkbox’) {<!– [et_pb_line_break_holder] –> (function(el) {<!– [et_pb_line_break_holder] –> var radios = form_to_submit.elements[el.name];<!– [et_pb_line_break_holder] –> for (var i = 0; i < radios.length; i++) {<!– [et_pb_line_break_holder] –> addEvent(radios[i], ‘click’, function() {<!– [et_pb_line_break_holder] –> validate_field(el, true);<!– [et_pb_line_break_holder] –> });<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> })(input);<!– [et_pb_line_break_holder] –> } else if (input.tagName == ‘SELECT’) {<!– [et_pb_line_break_holder] –> addEvent(input, ‘change’, function() {<!– [et_pb_line_break_holder] –> validate_field(this, true);<!– [et_pb_line_break_holder] –> });<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> remove_tooltips();<!– [et_pb_line_break_holder] –> for (var i = 0, len = allInputs.length; i < len; i++) {<!– [et_pb_line_break_holder] –> var elem = allInputs[i];<!– [et_pb_line_break_holder] –> if (needs_validate(elem)) {<!– [et_pb_line_break_holder] –> if (elem.tagName.toLowerCase() !== “select”) {<!– [et_pb_line_break_holder] –> elem.value = elem.value.trim();<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> validate_field(elem) ? true : no_error = false;<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> if (!no_error && e) {<!– [et_pb_line_break_holder] –> e.preventDefault();<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> resize_tooltips();<!– [et_pb_line_break_holder] –> return no_error;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> addEvent(window, ‘resize’, resize_tooltips);<!– [et_pb_line_break_holder] –> addEvent(window, ‘scroll’, resize_tooltips);<!– [et_pb_line_break_holder] –> window._old_serialize = null;<!– [et_pb_line_break_holder] –> if (typeof serialize !== ‘undefined’) window._old_serialize = window.serialize;<!– [et_pb_line_break_holder] –> _load_script(“//d3rxaij56vjege.cloudfront.net/form-serialize/0.3/serialize.min.js”, function() {<!– [et_pb_line_break_holder] –> window._form_serialize = window.serialize;<!– [et_pb_line_break_holder] –> if (window._old_serialize) window.serialize = window._old_serialize;<!– [et_pb_line_break_holder] –> });<!– [et_pb_line_break_holder] –> var form_submit = function(e) {<!– [et_pb_line_break_holder] –> e.preventDefault();<!– [et_pb_line_break_holder] –> if (validate_form()) {<!– [et_pb_line_break_holder] –> // use this trick to get the submit button & disable it using plain javascript<!– [et_pb_line_break_holder] –> document.querySelector(‘[id^=”_form”][id$=”_submit”]’).disabled = true;<!– [et_pb_line_break_holder] –> var serialized = _form_serialize(document.getElementById(‘_form_15_’));<!– [et_pb_line_break_holder] –> var err = form_to_submit.querySelector(‘._form_error’);<!– [et_pb_line_break_holder] –> err ? err.parentNode.removeChild(err) : false;<!– [et_pb_line_break_holder] –> _load_script(‘https://thesleepdoctor.activehosted.com/proc.php?’ + serialized + ‘&jsonp=true’);<!– [et_pb_line_break_holder] –> }<!– [et_pb_line_break_holder] –> return false;<!– [et_pb_line_break_holder] –> };<!– [et_pb_line_break_holder] –> addEvent(form_to_submit, ‘submit’, form_submit);<!– [et_pb_line_break_holder] –>})();<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –></script>