/* Custom App code and JQuery additions. */ $(document).ready(function () { // assign a click event to all selection group checkboxes that set the class $(".inputSelectionsGroup input[type=checkbox]").click(function(){ if ($(this).attr("checked")) { $(this).parent().attr("class", "checked"); } else { $(this).parent().attr("class", "notChecked"); } var containerID = "#" + $(this).parent().parent().attr("id").toString(); synchronize(containerID); }); $.validator.addMethod("dateAU", function(value, element){ if (this.optional(element)) return true; var objRegEx = /^(\d{1,2})\/(\d{1,2})\/(\d{2}|\d{4})$/; var re_match = objRegEx.exec(value) if (re_match) { if (Number(re_match[1]) <= 31) { switch (Number(re_match[2])) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: { return true; break; } case 4: case 6: case 9: case 11: { // Sep, Apr, Jun, Nov return Number(re_match[1]) <= 30; break; } case 2: { // Feb if (isLeapYear(Number(re_match[3]))) return Number(re_match[1]) <= 29; else return Number(re_match[1]) <= 28; break; } default: // all other values return false; break; } } else return false; } return false; }, "Please select a valid date"); }); function Select_UnSelectAll(containerID) { // if not items are selected then select all, otherwise deselect all // select/deselect all if ($(containerID).find("input:checked").length == $(containerID).find("input").length) { $(containerID).find("input").attr("checked", false); } else { $(containerID).find("input").attr("checked", true); } // sync the classes and selection text title synchronize(containerID); } function synchronize(containerID) { // update the class of the label that contains the checkbox $(containerID).find("label input:not(:checked)").parent().attr("class", "notChecked"); $(containerID).find("label input:checked").parent().attr("class", "checked"); synchronizeSelectText(containerID); } function synchronizeSelectText(containerID) { var sUnselectLinkID = containerID + "_SelectAll"; var sLinkText = "Select All"; if ($(containerID).find("input:checked").length == $(containerID).find("input").length) sLinkText = "Deselect All"; $(sUnselectLinkID).text(sLinkText); } function validateElement() { // $('#testForm').validate().check('#BusinessType'); // #OrderUrl, BusinessType -- only works for single elements with an ID } function ExpandForEditing(containerID) { var sExpandLinkID = containerID + "_Expand"; var sLinkText = "- Collapse"; if ($(containerID).css("maxHeight") == "420px") { $(containerID).animate({maxHeight:"90px"}, 1000); sLinkText = "+ Expand"; } else { $(containerID).animate({maxHeight:"420px"}, 1000); } $(sExpandLinkID).html(sLinkText); } function isLeapYear(nYear) { return (nYear%4 == 0); } /* Auto complete functions: START */ function findValue(li) { if( li == null ) return alert("No match!"); // if coming from an AJAX call, let's use the CityId as the value if( !!li.extra ) var sValue = li.extra[0]; // otherwise, let's just display the value in the text box else var sValue = li.selectValue; // alert("The value you selected was: " + sValue); } function selectItem(li) { findValue(li); } function formatItem(row) { return row[0] + " (id: " + row[1] + ")"; } function lookupAjax(){ var oSuggest = $("#CityAjax")[0].autocompleter; oSuggest.findValue(); return false; } function lookupLocal(){ var oSuggest = $("#inpProductValue")[0].autocompleter; oSuggest.findValue(); return false; } /* Auto complete functions: END */