function swapPairs(s){ var res = ""; for (var i=0; i>2) + ((ch & 0x03)<<2) ); } return res; } function toggleLayer(whichLayer) { if (document.getElementById) { // this is the way the standards work var style2 = document.getElementById(whichLayer).style; style2.display = style2.display=="block"?"none":"block"; } else if (document.all) { // this is the way old msie versions work var style2 = document.all[whichLayer].style; style2.display = style2.display=="block"?"none":"block"; } else if (document.layers) { // this is the way nn4 works var style2 = document.layers[whichLayer].style; style2.display = style2.display=="block"?"none":"block"; } } function getLayer(whichLayer) { if (document.getElementById) { // this is the way the standards work return document.getElementById(whichLayer); } else if (document.all) { // this is the way old msie versions work return document.all[whichLayer]; } else if (document.layers) { // this is the way nn4 works return document.layers[whichLayer]; } } function hideLayer(whichLayer) { var style2 = document.getElementById(whichLayer).style; style2.display = "none"; } function showLayer(whichLayer) { var style2 = document.getElementById(whichLayer).style; style2.display = "block"; } function GetRadioValue(rArray) { for (var i=0;i0)) { var elems = formValue.split("/"); result = (elems.length == 2); // should be two components var expired = false; if (result) { var month = parseInt(elems[0],10); var year = parseInt(elems[1],10); if (elems[1].length == 2) year += 2000; var now = new Date(); var nowMonth = now.getMonth() + 1; var nowYear = now.getFullYear(); expired = (nowYear > year) || ((nowYear == year ) && (nowMonth > month)); result = allDigits(elems[0]) && (month > 0) && (month < 13) && allDigits(elems[1]) && ((elems[1].length == 2) || (elems[1].length == 4)); } if (!result) { alert('Please enter a date in the format MM/YY for the "' + fieldLabel +'" field.'); formField.focus(); } else if (expired) { result = false; alert('The date for "' + fieldLabel +'" has expired.'); formField.focus(); } } return result; } function isValidCreditCardNumber(formField,ccType,fieldLabel,required) { var result = true; var ccNum = formField.value; if (result && (formField.value.length>0)) { if (!allDigits(ccNum)) { result = false; } if (result) { if (!LuhnCheck(ccNum) || !validateCCNum(ccType,ccNum)) { result = false; } } } return result; } function LuhnCheck(str) { var result = true; var sum = 0; var mul = 1; var strLen = str.length; for (i = 0; i < strLen; i++) { var digit = str.substring(strLen-i-1,strLen-i); var tproduct = parseInt(digit ,10)*mul; if (tproduct >= 10) sum += (tproduct % 10) + 1; else sum += tproduct; if (mul == 1) mul++; else mul--; } if ((sum % 10) != 0) result = false; return result; } function validateCCNum(cardType,cardNum) { var result = false; cardType = cardType.toUpperCase(); var cardLen = cardNum.length; var firstdig = cardNum.substring(0,1); var seconddig = cardNum.substring(1,2); var first4digs = cardNum.substring(0,4); switch (cardType) { case "VISA": result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4"); break; case "AMEX": case "AMERICAN EXPRESS": var validNums = "47"; result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0); break; case "MASTERCARD": var validNums = "12345"; result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0); break; case "DISCOVER": result = (cardLen == 16) && (first4digs == "6011"); break; case "DINERS": var validNums = "068"; result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0); break; } return result; }