﻿
                        $(function () {
                            $("#emf-form").validationEngine({
                                validationEventTriggers: "blur",
                                scroll: false
                            });

                            $('.datepicker').datepicker({
                                showOn: 'button',
                                buttonImage: base_url + 'images/calendar.png',
                                buttonImageOnly: true,
                                onSelect: function (dateText, inst) {
                                    var selectedDate = new Date(dateText);
                                    $('#' + inst.id + 'year').val(selectedDate.getFullYear());
                                    $('#' + inst.id + 'year-mm').val(((selectedDate.getMonth() + 1) > 9) ? (selectedDate.getMonth() + 1) : ('0' + (selectedDate.getMonth() + 1)));
                                    $('#' + inst.id + 'year-dd').val(selectedDate.getDate() > 9 ? selectedDate.getDate() : '0' + selectedDate.getDate());
                                    $('.' + inst.id + 'yearformError').remove();
                                    $('.' + inst.id + 'year-mmformError').remove();
                                    $('.' + inst.id + 'year-ddformError').remove();
                                },
                                changeMonth: true,
                                changeYear: true
                            });
                            if (document.getElementById('captcha_image') != null) {
                                get_valid_captcha();
                            }

                            if (document.getElementById('captcha_image') != null) {
                                var isSafari = (/Safari/.test(navigator.userAgent));
                                var firstTimeSession = 0;
                                function process_captcha() {
                                    $('a#captcha_code_refresh').trigger('click');
                                    get_valid_captcha();
                                }
                                function safari_submit_session_form() {
                                    if (firstTimeSession == 0) {
                                        firstTimeSession = 1;
                                        $("#safari_sessionform").submit();
                                        setTimeout('process_captcha()', 2000);
                                    }
                                }
                                if (isSafari) {
                                    $("body").append('<iframe id="safari_sessionframe" name="safari_sessionframe" onload="safari_submit_session_form();" src="http://www.emailmeform.com/get_safari_cookies.php" style="display:none;"><\/iframe><form id="safari_sessionform" enctype="application/x-www-form-urlencoded" action="http://www.emailmeform.com/get_safari_cookies.php" target="safari_sessionframe" action="post"><\/form>');
                                }
                            }

                        });


