JezK
Edit File: public.common.js
/* ** nopCommerce custom js functions */ function OpenWindow(query, w, h, scroll) { var l = (screen.width - w) / 2; var t = (screen.height - h) / 2; winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w'; if (scroll) winprops += ',scrollbars=1'; var f = window.open(query, "_blank", winprops); } function setLocation(url) { window.location.href = url; } function displayAjaxLoading(display) { if (display) { $('.ajax-loading-block-window').show(); } else { $('.ajax-loading-block-window').hide('slow'); } } function displayPopupNotification(message, messagetype, modal) { //types: success, error var container; if (messagetype == 'success') { //success container = $('#dialog-notifications-success'); } else if (messagetype == 'error') { //error container = $('#dialog-notifications-error'); } else { //other container = $('#dialog-notifications-success'); } //we do not encode displayed message var htmlcode = ''; if ((typeof message) == 'string') { htmlcode = '<p>' + message + '</p>'; } else { for (var i = 0; i < message.length; i++) { htmlcode = htmlcode + '<p>' + message[i] + '</p>'; } } container.html(htmlcode); var isModal = (modal ? true : false); container.dialog({ modal: isModal, width: 350 }); } function displayPopupContentFromUrl(url, title, modal, width) { var isModal = (modal ? true : false); var targetWidth = (width ? width : 550); $('<div></div>').load(url) .dialog({ modal: isModal, width: targetWidth, title: title, close: function(event, ui) { $(this).dialog('destroy').remove(); } }); } var barNotificationTimeout; function displayBarNotification(message, messagetype, timeout) { clearTimeout(barNotificationTimeout); //types: success, error var cssclass = 'success'; if (messagetype == 'success') { cssclass = 'success'; } else if (messagetype == 'error') { cssclass = 'error'; } //remove previous CSS classes and notifications $('#bar-notification') .removeClass('success') .removeClass('error'); $('#bar-notification .content').remove(); //we do not encode displayed message //add new notifications var htmlcode = ''; if ((typeof message) == 'string') { htmlcode = '<p class="content">' + message + '</p>'; } else { for (var i = 0; i < message.length; i++) { htmlcode = htmlcode + '<p class="content">' + message[i] + '</p>'; } } $('#bar-notification').append(htmlcode) .addClass(cssclass) .fadeIn('slow') .mouseenter(function () { clearTimeout(barNotificationTimeout); }); $('#bar-notification .close').unbind('click').click(function () { $('#bar-notification').fadeOut('slow'); }); //timeout (if set) if (timeout > 0) { barNotificationTimeout = setTimeout(function () { $('#bar-notification').fadeOut('slow'); }, timeout); } } function htmlEncode(value) { return $('<div/>').text(value).html(); } function htmlDecode(value) { return $('<div/>').html(value).text(); } // CSRF (XSRF) security function addAntiForgeryToken(data) { //if the object is undefined, create a new one. if (!data) { data = {}; } //add token var tokenInput = $('input[name=__RequestVerificationToken]'); if (tokenInput.length) { data.__RequestVerificationToken = tokenInput.val(); } return data; }; function Bdaycheck(dayId) { // alert(dInput); var x = parseInt($("#"+dayId).val()); if (x == null || x > 31 || x == 0) { // alert("test") // $("#" + dayId).css("border-color", "rgb(255, 192, 192)"); $("#" + dayId).val(""); return false; } return true; } function Bmonthcheck(monthId) { var dInput = $("#" + monthId).val(); // alert(dInput); var y = parseInt($("#" + monthId).val()); if (y == null || y > 12 || y == 0) { // $("#" + monthId).css("border-color", "rgb(255, 192, 192)"); $("#" + monthId).val(""); return false; } return true; } function Byearcheck(dayId,monthId,yearId) { // var dInput = $(this).val(); // alert(dInput); var x = parseInt($("#" + dayId).val()); var y = parseInt($("#" + monthId).val()); var z = parseInt($("#" + yearId).val()); var d = new Date(); var n = d.getFullYear(); var ind = $("#" + yearId).val().indexOf(1, "0"); if (ind != 0) { $("#" + yearId).css("border-color", "rgb(255, 192, 192)"); $("#" + yearId).val(""); return false; } else { var nine = $("#" + yearId).val().indexOf(9, "1"); if ($("#" + yearId).val().length > 1) { if (nine != 1) { $("#" + yearId).css("border-color", "rgb(255, 192, 192)"); $("#" + yearId).val(""); return false; } } } if (z == null || z < 1900 || z > n) { // $("#" + yearId).css("border-color", "rgb(255, 192, 192)"); // $("#byear").val(""); return false; } else if (x != null && y != null && z != null) { var day = x; var month = y; var year = z; var age = 18; var mydate = new Date(); mydate.setFullYear(year, month - 1, day); var currdate = new Date(); var setDate = new Date(); setDate.setFullYear(mydate.getFullYear() + age, month - 1, day); if ((currdate - setDate) > 0) { // warning.push(i); // alert("above 18"); } else { // alert("below 18"); $("#" + yearId).val(""); $("#" + yearId).css("border-color", "rgb(255, 192, 192)"); return false; } } return true; }