jQuery(document).ready(
      function () {
         var tAllowToSubmit = false;
	jQuery('.thankyou').empty().hide();
         setTimeout(function () { tAllowToSubmit = true; }, 12000);

         var tCheckSubmitPromotionalFormTimeout = false;
         function lkCheckSubmitPromotionalForm(fForm) {
            jQuery('form.js-contact-us-form .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('form.js-contact-us-form').serialize(),
               type: 'POST',
               beforeSend: function () { },
               complete: function () { jQuery('form.js-contact-us-form .preloader').stop(false, true).fadeOut(500); },
               success: function (fData) {
                  jQuery('form.js-contact-us-form .field-validation-error').text('');
                  if (fData.success === true) {
                     //jQuery('#thank-you iframe').attr('src', '/thank-you/');
                     //showPopupBySelector('#thank-you');
                     jQuery('.thankyou').empty().append('<h2 style="padding-right:3px;font-size:30px;color:WHITE;text-align:center;">Thank You</h2>');
                     jQuery('form.js-contact-us-form').children().hide();
		    jQuery('.thankyou').show();
		    var ts=setTimeout("jQuery('form.js-contact-us-form').each(function(){this.reset();}); jQuery('form.js-contact-us-form').children().show();jQuery('.thankyou').empty().hide();jQuery(document).ready();jQuery('form.js-contact-us-form .preloader').stop(false, true).fadeOut(500);",2000);
                  } else if (fData.errors) {
                     for (var tC in fData.errors) {
                        jQuery('#validation-message-' + fData.errors[tC].PropertyName).text(fData.errors[tC].ErrorMessage);
                     }
                  } else if (fData.fatalerrors) {
                     var tErr = '';
                     for (var tC in fData.fatalerrors) {
                        tErr += fData.fatalerrors[tC] + '\n';
                     }
                     alert(tErr);
                  }
               },
               error: function(jqXHR, textStatus, errorThrown){ alert(textStatus) }
            });

            return false;
         }

         jQuery('form.js-contact-us-form').submit(function () { lkCheckSubmitPromotionalForm(this); return false; });
      }
   );

