(function ($) { // Init Page var pageInfo; Customerville.pageInit(function () { pageInfo = $('#hiddenFields'); $.unblockUI(); $('form').submit(function (evt) { BlockUI(); }); $('#prevbutton').click(function (evt) { prevButtonClicked(evt); }); $('#nextbutton').click(function (evt) { nextButtonClicked(evt); }); ValidateForm(); }); function BlockUI(fadeTime) { if (fadeTime === undefined) { fadeTime = 100; } $.blockUI.defaults.css = {}; $.blockUI({ message: '

Just a moment...

', fadeIn: fadeTime, fadeOut: fadeTime, centerY: false, centerX: false, css: { width: '100%', left: '0%', top: '30%', cursor: 'wait' }, overlayCSS: { opacity: 0.0 } }); } function HideErrors() { $('div.errorrect').text(''); $('label.error').css('display', 'none'); $('.error').removeClass('error'); } function prevButtonClicked(evt) { evt.preventDefault(); var pageNum = pageInfo.data("pagenum"); pageNum = pageNum - 1; if (pageNum == 0) { window.location = 'Default.aspx'; } else if (pageNum > 0) { window.location = 'Survey' + pageNum + '.aspx'; } } function nextButtonClicked(evt) { HideErrors(); if (!$('form').validate().form()) { evt.preventDefault(); } } function ValidateForm() { $('.page_landing form').each(function () { $(this).validate({ rules: { QUEST1_ddlfld: "required" }, errorPlacement: function (error, element) { var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST1_ddlfld: $('#QUEST1').data('errormsg') } }); }); $('.page_location form').each(function () { // append an icon onto the date text field and when its click... // give the text field focus (which will bring up the date calendar) var $dateIcon = $('
', { 'id': "dateicon", 'class': "dateicon" }) .appendTo($("#QUEST37_textfld").parent()) .on('click', function (evt) { evt.preventDefault(); $("#QUEST37_textfld").focus(); }); $("#QUEST37_textfld").datepicker({ maxDate: "today", showButtonPanel: true }); var $timeIcon = $('
', { 'id': "timeicon", 'class': "timeicon" }) .appendTo($("#QUEST38_textfld").parent()) .on('click', function (evt) { evt.preventDefault(); $("#QUEST38_textfld").focus(); }); $("#QUEST38_textfld").timepicker({ 'scrollDefaultNow': true }); }); $('.page_recommend form').each(function () { $(this).validate({ rules: { QUEST23: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST23: $('#QUEST23').data('errormsg') } }); }); $('.page_staff form').each(function () { $(this).validate({ rules: { QUEST101: "required", QUEST102: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST101: $('#QUEST101').data('errormsg'), QUEST102: $('#QUEST102').data('errormsg'), } }); }); $('.page_meal form').each(function () { $(this).validate({ rules: { QUEST103: "required", QUEST104: "required", QUEST105: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST103: $('#QUEST104').data('errormsg'), QUEST104: $('#QUEST104').data('errormsg'), QUEST105: $('#QUEST105').data('errormsg') } }); }); $('.page_restaurant form').each(function () { $(this).validate({ rules: { QUEST110: "required", QUEST112: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST110: $('#QUEST110').data('errormsg'), QUEST112: $('#QUEST110').data('errormsg') } }); }); $('.page_overall form').each(function () { $(this).validate({ rules: { QUEST30: "required", QUEST114: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(error.text()); } }, messages: { QUEST30: $('#QUEST30').data('errormsg'), QUEST114: $('#QUEST114').data('errormsg') } }); }); $('.page_contact form').each(function () { $(this).validate({ rules: { QUEST5_textfld: "required", QUEST6_textfld: { required: true, email: true }, QUEST7_textfld: "required", QUEST110_textfld: "required", QUEST111_textfld: "required" }, errorPlacement: function (error, element) { // invalid handler will place the error var errorRect = $('div.errorrect'); var message = error.text(); if (isNullOrWhiteSpace(errorRect.text())) { errorRect.text(message); } }, messages: { QUEST5_textfld: $('#QUEST5').data('errormsg'), QUEST6_textfld: $('#QUEST6').data('errormsg'), QUEST7_textfld: $('#QUEST7').data('errormsg'), QUEST110_textfld: $('#QUEST110').data('errormsg'), QUEST111_textfld: $('#QUEST111').data('errormsg') } }); }); } })(jQuery);