$(function() { // validate the comment form when it is submitted $("#frmEPPAccount").validate({ rules: { txtTaxAcctNum: { required: true, minlength: 2, maxlength: 7, regex: /^[pP]{1}\d{6}$/, }, txtBusinessName: { required: true, }, txtEmailAddy: { required: true, email: true, }, txtPhone: { required: true, }, txtMAddress1: { required: true, }, txtMCity: { required: true, }, slctMState: { required: true, }, txtMZip: { required: true, }, txtPAddress1: { required: true, }, txtPCity: { required: true, }, slctPState: { required: true, }, txtPZip: { required: true, }, txtSignatureBox: { required: true, }, }, messages: { txtTaxAcctNum: { required: "Please enter your Tax Account Number", minlength: "You must enter at least 2 character", maxlength: "You can enter a maximum length of 7 characters", regex: "Please enter a proper Tax Account Number (e.g., P123456)", }, txtBusinessName: { required: "Please enter your Business Name", }, txtEmailAddy: { required: "Please enter your Email Address", email: "That doesn't appear to be a valid email address", }, txtPhone: { required: "Please enter your current Phone Number", }, txtMAddress1: { required: "Please enter your current Mailing Address", }, txtMCity: { required: "Please enter your current Mailing City", }, slctMState: { required: "Please enter your current Mailing State", }, txtMZip: { required: "Please enter your current Mailing Zip Code", }, txtPAddress1: { required: "Please enter this property's current Physical Address", }, txtPCity: { required: "Please enter this property's current Physical City", }, slctPState: { required: "Please enter this property's current Physical State", }, txtPZip: { required: "Please enter this property's current Physical Zip Code", }, txtSignatureBox: { required: "Please mark checkbox and enter your Full Legal Name", }, }, }); }); function getPPAccountsInfo(tanid) { var valThis = tanid; $.ajax({ method: "GET", url: "ppaccounts_json.php", data: { taxacctnum: valThis }, dataType: "json", success: function(getJSON) { if (getJSON === null) { invalidTaxAcctNum(); } else { fillPPCompanyInfo(getJSON); fillPPMAddressInfo(getJSON); fillPPPAddressInfo(getJSON); fillPPPComments(getJSON); } // END if }, failure: function() { alert('Error in retrieving Tax Account Information. Please try again later.'); } }); return false; } // END function getPPAccountsInfo() function fillPPCompanyInfo(getJSON) { $("#txtBusinessName").val(getJSON[0][1]); $("#txtOName").val(getJSON[0][2]); if (getJSON[0][3] == "" || getJSON[0][3] == null || getJSON[0][3] === 'undefined') { var txtEmailPrompt = $.trim(prompt("NO Email Address found in records. Please enter an email address.", "")); setCompanyInfoReadOnly(false); $("#chkCompanyInfoChk").prop("checked", true); if (txtEmailPrompt != "") { $("#txtEmailAddy").val(txtEmailPrompt); } else { $("#txtEmailAddy").val(getJSON[0][3]); } // END if $("#txtEmailAddy").focus(); } else { setCompanyInfoReadOnly(true); $("#chkCompanyInfoChk").prop("checked", false); $("#txtEmailAddy").val(getJSON[0][3]); } // END if if (getJSON[0][4] == "" || getJSON[0][4] == null || getJSON[0][4] === 'undefined') { var txtPhonePrompt = $.trim(prompt("NO Phone Number found in records. Please enter a phone number.", "")); setCompanyInfoReadOnly(false); $("#chkCompanyInfoChk").prop("checked", true); if (txtPhonePrompt != "") { $("#txtPhone").val(txtPhonePrompt); } else { $("#txtPhone").val(getJSON[0][4]); } // END if $("#txtPhone").focus(); } else { setCompanyInfoReadOnly(true); $("#chkCompanyInfoChk").prop("checked", false); $("#txtPhone").val(getJSON[0][4]); } // END if $("#txtMobile").val(getJSON[0][5]); $("#txtFax").val(getJSON[0][6]); return false; } // END function fillPPCompanyInfo() function fillPPMAddressInfo(getJSON) { $("#txtMAddress1").val(getJSON[0][7]); $("#txtMAddress2").val(getJSON[0][8]); $("#txtMCity").val(getJSON[0][9]); $("#slctMState").val(getJSON[0][10]); $("#txtMZip").val(getJSON[0][11]); $("#txtMCountry").val(getJSON[0][12]); return false; } // END function fillPPMAddressInfo() function fillPPPAddressInfo(getJSON) { $("#txtPAddress1").val(getJSON[0][13]); $("#txtPAddress2").val(getJSON[0][14]); $("#txtPCity").val(getJSON[0][15]); $("#slctPState").val(getJSON[0][16]); $("#txtPZip").val(getJSON[0][17]); return false; } // END function fillPPPAddressInfo() function fillPPPComments(getJSON) { $("#txtaComments").val(getJSON[0][19]); return false; } // END function fillPPPComments() function getPPCompanyInfo(tanid) { var valThis = tanid; $.ajax({ method: "GET", url: "ppaccounts_json.php", data: { taxacctnum: valThis }, dataType: "json", success: function(getJSON) { if (getJSON === null) { invalidTaxAcctNum(); } else { fillPPCompanyInfo(getJSON); } // END if }, failure: function() { alert('Error in retrieving Company Information. Please try again later.'); } }); return false; } // END function getPPCompanyInfo() function getPPMAddressInfo(tanid) { var valThis = tanid; $.ajax({ method: "GET", url: "ppaccounts_json.php", data: { taxacctnum: valThis }, dataType: "json", success: function(getJSON) { if (getJSON === null) { invalidTaxAcctNum(); } else { fillPPMAddressInfo(getJSON) } // END if }, failure: function() { alert('Error in retrieving Mailing Address Information. Please try again later.'); } }); return false; } // END function getPPMAddressInfo() function getPPPAddressInfo(tanid) { var valThis = tanid; $.ajax({ method: "GET", url: "ppaccounts_json.php", data: { taxacctnum: valThis }, dataType: "json", success: function(getJSON) { if (getJSON === null) { invalidTaxAcctNum(); } else { fillPPPAddressInfo(getJSON); } // END if }, failure: function() { alert('Error in retrieving Physical Address Information. Please try again later.'); } }); return false; } // END function getPPPAddressInfo() function getPPComments(tanid) { var valThis = tanid; $.ajax({ method: "GET", url: "ppaccounts_json.php", data: { taxacctnum: valThis }, dataType: "json", success: function(getJSON) { if (getJSON === null) { invalidTaxAcctNum(); } else { fillPPPComments(getJSON); } // END if }, failure: function() { alert('Error in retrieving Physical Address Information. Please try again later.'); } }); return false; } // END function getPPComments() function changeCompanyInfoChk(){ var valTaxAcctNum = $("#txtTaxAcctNum").val(); if (valTaxAcctNum != "") { if($("#chkCompanyInfoChk").prop("checked")) { setCompanyInfoReadOnly(false); } else { getPPCompanyInfo(valTaxAcctNum); setCompanyInfoReadOnly(true); $("#chkCompanyInfoChk").focus(); } // END if } else { $("#chkCompanyInfoChk").prop("checked", false); } // END if return false; } // END function changeCompanyInfoChk() function changeMAddressChk(){ var valTaxAcctNum = $("#txtTaxAcctNum").val(); if (valTaxAcctNum != "") { if($("#chkMAddressChk").prop("checked")) { setMAddressReadOnly(false); $("#txtMAddress1").focus(); } else { getPPMAddressInfo(valTaxAcctNum); setMAddressReadOnly(true); $("#chkMAddressChk").focus(); } // END if } else { $("#chkMAddressChk").prop("checked", false); } // END if return false; } // END function changeMAddressChk() function changePAddressChk(){ var valTaxAcctNum = $("#txtTaxAcctNum").val(); if (valTaxAcctNum != "") { if($("#chkPAddressChk").prop("checked")) { setPAddressReadOnly(false); $("#txtPAddress1").focus(); } else { getPPPAddressInfo(valTaxAcctNum); setPAddressReadOnly(true); $("#chkPAddressChk").focus(); } // END if } else { $("#chkPAddressChk").prop("checked", false); } // END if return false; } // END function changePAddressChk() function changeCommentsChk(){ var valTaxAcctNum = $("#txtTaxAcctNum").val(); if (valTaxAcctNum != "") { if($("#chkCommentsChk").prop("checked")) { setCommentsReadOnly(false); $("#txtaComments").focus(); } else { getPPComments(valTaxAcctNum); setCommentsReadOnly(true); $("#chkCommentsChk").focus(); } // END if } else { $("#chkCommentsChk").prop("checked", false); } // END if return false; } // END function changeCommentsChk() function setCompanyInfoReadOnly(bReadOnly) { $("#txtBusinessName").prop("readonly", bReadOnly); $("#txtOName").prop("readonly", bReadOnly); $("#txtEmailAddy").prop("readonly", bReadOnly); $("#txtPhone").prop("readonly", bReadOnly); $("#txtMobile").prop("readonly", bReadOnly); $("#txtFax").prop("readonly", bReadOnly); return false } // END function setCompanyInfoReadOnly() function setMAddressReadOnly(bReadOnly) { $("#txtMAddress1").prop("readonly", bReadOnly); $("#txtMAddress2").prop("readonly", bReadOnly); $("#txtMCity").prop("readonly", bReadOnly); $("#slctMState").prop("readonly", bReadOnly); $("#txtMZip").prop("readonly", bReadOnly); $("#txtMCountry").prop("readonly", bReadOnly); return false; } // END function setMAddressReadOnly() function setPAddressReadOnly(bReadOnly) { $("#txtPAddress1").prop("readonly", bReadOnly); $("#txtPAddress2").prop("readonly", bReadOnly); $("#txtPCity").prop("readonly", bReadOnly); $("#slctPState").prop("readonly", bReadOnly); $("#txtPZip").prop("readonly", bReadOnly); return false; } // END function setPAddressReadOnly() function setCommentsReadOnly(bReadOnly) { $("#txtaComments").prop("readonly", bReadOnly); return false; } // END function setCommentsReadOnly() function invalidTaxAcctNum() { alert("Please enter a valid Tax Account Number"); $("#frmEPPAccount")[0].reset(); if($("#chkCompanyInfoChk").prop("checked")) { $("#chkCompanyInfoChk").prop("checked", false); } // END if $("#txtTaxAcctNum").focus(); return false; } // END function invalidTaxAcctNum()