jQuery(document).ready(
      function () {
         var tAllowToSubmit = false;
         setTimeout(function () { tAllowToSubmit = true; }, 12000);

         var tCheckSubmitPromotionalFormTimeout = false;
         function lkCheckSubmitPromotionalForm(fForm) {
            jQuery('.ajax-submit .preloader').stop(false, true).fadeIn(500);
            if (tCheckSubmitPromotionalFormTimeout)
               clearTimeout(tCheckSubmitPromotionalFormTimeout);
            if (tAllowToSubmit == false)
               tCheckSubmitPromotionalFormTimeout = setTimeout(function () { lkCheckSubmitPromotionalForm(fForm) }, 1000);
            else
               lkSubmitPromotionalForm(fForm);
            return false;
         }

         function lkSubmitPromotionalForm(fForm) {
            jQuery.ajax({
               url: fForm.action,
               cache: false,
               dataType: 'json',
               data: jQuery(fForm).serialize(),
               type: 'POST',
               beforeSend: function () { },
               complete: function () { jQuery(fForm).parents('.ajax-submit:first').find('.preloader').stop(false, true).fadeOut(500); },
               success: function (fData) {
                  jQuery('.field-validation-error', fForm).text('');
                  if (fData.success === true) {
                     jQuery('#thank-you iframe').attr('src', '/thank-you.asp?email=' + jQuery('#Email').val() + '&name=' + jQuery('#Name').val());
					 showPopupBySelector('#thank-you');
                     jQuery('input[type=text]', fForm).val('');
                     jQuery('#ReasonForConsultId', fForm).val('1');
                     jQuery(fForm).parents('.ajax-submit:first').find('.close').click();
                  } else if (fData.errors) {
                     for (var tC in fData.errors) {
                        jQuery('#validation-message-' + fData.errors[tC].PropertyName, fForm).text(fData.errors[tC].ErrorMessage);
                     }
                  } else if (fData.fatalerrors) {
                     var tErr = '';
                     for (var tC in fData.fatalerrors) {
                        tErr += fData.fatalerrors[tC] + '\n';
                     }
                     alert(tErr);
                  }
               }
            });

            return false;
         }

         jQuery('.ajax-submit form').live('submit', function () { lkCheckSubmitPromotionalForm(this); return false; });
      }
   );

