1jQuery(document).ready(function() {
2
3 var cvvname = "";
4 if (jQuery("#cccvv").length) {
5 cvvname = "#cccvv";
6 } else {
7 cvvname = "#cardcvv";
8 }
9
10 function isAmex()
11 {
12 // Check if AMEX was selected from the dropdown.
13 var cc = jQuery("#cctype").val();
14 var ccInfo = jQuery("[name='ccinfo']:checked").val();
15 if (cc.toLowerCase().indexOf("american express") !== -1) {
16 return true;
17 }
18 if (typeof ccInfo != 'undefined') {
19 return (ccInfo.toLowerCase() == 'useexisting');
20 }
21 return false;
22 }
23
24 function isCardTypeVisible()
25 {
26 return jQuery("#ccTypeButton:visible").length > 0;
27 }
28
29 jQuery(cvvname).focus(function() {
30 if (isAmex() || !isCardTypeVisible()) {
31 jQuery(cvvname).attr("maxlength", "4");
32 } else {
33 jQuery(cvvname).attr("maxlength", "3");
34 }
35 });
36
37 jQuery("#cctype").change(function() {
38 var cardcvv = jQuery(cvvname).val();
39 if (!isAmex() && cardcvv.length > 3) {
40 // Reset the CVV, since it's too long now.
41 jQuery(cvvname).val("");
42 }
43 });
44});
45
46