$(document).ready(function() { $('div#divRequestJournal').hide(); $("#txtSignatureBox").val("Please select the above checkbox before entering your Full Legal Name"); $('#txtBarcode').focus(); $('#txtaNotes').on("input", function(){ var maxlength = $(this).attr("maxlength"); var currentLength = $(this).val().length; $('#txtaNotesCount').text('('+currentLength+'/'+maxlength+')'); }); }); $(function() { // validate the comment form when it is submitted $("#frmPatronRequest").validate({ rules: { txtBarcode: { required: true, digits: true, minlength: 14, maxlength: 14, }, txtFName: { required: true, }, txtLName: { required: true, }, txtEmailAddy: { required: true, email: true, }, slctBranch: { required: true, }, txtAuthor: { required: true, }, txtTitle: { required: true, }, txtJDate: { required: true, date: true, }, txtJVolume: { digits: true, }, txtJNumber: { digits: true, }, txtJPages: { digits: true, }, txtSignatureBox: { required: true, }, }, messages: { txtBarcode: { required: "Please enter your Library Card Number", digits: "Please enter only whole numeric values", minlength: "You can enter a minimum length of 14 characters", maxlength: "You can enter a maximum length of 14 characters", }, txtFName: { required: "Please enter your First Name", }, txtLName: { required: "Please enter your Last Name", }, txtEmailAddy: { required: "Please enter your Email Address", email: "That doesn't appear to be a valid email address", }, slctBranch: { required: "Please select a Library Branch", }, txtAuthor: { required: "Please enter the Author", }, txtTitle: { required: "Please enter the Title", }, txtJDate: { required: "Please enter the Journal Date", date: "Please enter a valid Date", }, txtJVolume: { digits: "Please enter only whole numbers", }, txtJNumber: { digits: "Please enter only whole numbers", }, txtJPages: { digits: "Please enter only whole numbers", }, txtSignatureBox: { required: "Please mark checkbox and enter your Full Legal Name", }, }, }); }); function addInterLibJournal() { var strReturn = ''; strReturn += '
Journal Details:'; strReturn += '


'; strReturn += '


'; strReturn += '


'; strReturn += '


'; strReturn += '


'; strReturn += '
'; $('div#divRequestJournal').fadeOut('fast', function() { $('div#divRequestJournal').html(strReturn); $('div#divRequestJournal').fadeIn('fast'); }); return false; } // END function addInterLibJournal() function removeInterLibJournal() { $('div#divRequestJournal').fadeOut('fast', function() { $('div#divRequestJournal').html(''); $('div#divRequestJournal').fadeIn('fast'); }); return false; } // END function removeInterLibJournal() function changeFormatType() { var strFormatType = $('#slctCategoryFormat').val(); switch (strFormatType) { case 'jnl': addInterLibJournal(); break; default: removeInterLibJournal(); } // END switch return false; } // END function changeFormatType() function changeSignatureChk() { if($("#chkSignatureChk")[0].checked) { $("#txtSignatureBox").attr("readonly", false); $("#txtSignatureBox").val(""); $("#txtSignatureBox").focus(); } else { $("#txtSignatureBox").attr("readonly", true); $("#txtSignatureBox").val("Please select the above checkbox before entering your Full Legal Name"); $("#chkSignatureChk").focus(); } // END if return false; } // END function changeSignatureChk() function clickClearForm() { removeInterLibJournal(); togglePatronAccountInfo(true); $('#txtaNotesCount').text(''); return false; } // END function clickClearForm() function disableEnterKey() { $('input').bind("keyup keypress", function(e) { var code = e.keyCode || e.which; if (code == 13) { e.preventDefault(); return false; } // END if }); } // END function disableEnterKey() function changeBarcodeNum() { var valBarcodeNum = $("#txtBarcode").val(); if (verifyBarcodeNum(valBarcodeNum)) { getPatronsAccountsInfo(valBarcodeNum); } else { togglePatronAccountInfo(true); resetPatronAccountInfo(); } // END if return false; } // END function changeBarcodeNum() function verifyBarcodeNum(bc) { if (bc == "" || bc == null || bc === 'undefined') { return false } else { if (bc.length < 14 || bc.length > 14) { return false } else { if (isNaN(bc)) { return false; } else { return true; } // END if } // END if } // END if } // END function verifyBarcodeNum() function getPatronsAccountsInfo(bc) { $.ajax({ method: "GET", url: '/wp-content/themes/clean-education-pro-washco/inc_funcs/request_patron_json.php', data: { barcode: bc }, dataType: "text", success: function(getJSON) { if (getJSON != "") { fillPatronAccountInfo(getJSON); togglePatronAccountInfo(false); } else { togglePatronAccountInfo(false); } // END if }, failure: function() { alert('Error in retrieving Patron Information. Please try again later.'); } }); return false; } // END function getPatronsAccountsInfo() function fillPatronAccountInfo(getJSON) { getJSON = getJSON.split(","); $("#txtFName").val(getJSON[1]); $("#txtMName").val(getJSON[2]); $("#txtLName").val(getJSON[3]); if (getJSON[0][4] == "" || getJSON[0][4] == null || getJSON[0][4] === 'undefined') { var txtEmailPrompt = $.trim(prompt("NO Email Address found in records. Please enter an email address.", "")); setFieldReadOnly("txtEmailAddy", false); $("#txtEmailAddy").val(txtEmailPrompt); } else { $("#txtEmailAddy").val(getJSON[4]); } // END if $("#txtPhone").val(getJSON[5]); $("#slctBranch").val(getJSON[6]); return false; } // END function fillPatronAccountInfo() function setFieldReadOnly(fid, bReadOnly) { $("#"+fid).attr("readonly", bReadOnly); return false } // END function setFieldReadOnly() function resetPatronAccountInfo() { $("#txtFName").val(""); $("#txtMName").val(""); $("#txtLName").val(""); $("#txtEmailAddy").val(""); $("#txtPhone").val(""); $('#txtBarcode').focus(); $("#slctBranch").val(""); return false; } // END function resetPatronAccountInfo() function togglePatronAccountInfo(bReadOnly) { setFieldReadOnly("txtFName", bReadOnly); setFieldReadOnly("txtMName", bReadOnly); setFieldReadOnly("txtLName", bReadOnly); setFieldReadOnly("txtEmailAddy", bReadOnly); setFieldReadOnly("txtPhone", bReadOnly); return false; } // END function togglePatronAccountInfo()