var g_aIgnore = Array(8,9,37,38,39,40,35,36,46); function GetResultingValue(ptObject, strInsert) { //IE support var strPostValue = ""; if (document.selection) { var trCaret = window.document.selection.createRange(); var trPrefix = ptObject.createTextRange(); var trSuffix = trPrefix.duplicate(); trPrefix.setEndPoint("EndToStart", trCaret); trSuffix.setEndPoint("StartToEnd", trCaret); strPostValue = trPrefix.text + strInsert + trSuffix.text; } //MOZILLA/NETSCAPE support else if (ptObject.selectionStart || ptObject.selectionStart == '0') { var startPos = ptObject.selectionStart; var endPos = ptObject.selectionEnd; strPostValue = ptObject.value.substring(0, startPos) + strInsert + ptObject.value.substring(endPos, ptObject.value.length); } //SAFARI support, //I know this isn't quite right, but if anyone can get it to work let us know!! else if (window.getSelection) { strPostValue = ptObject.value + strInsert; } return strPostValue; } function IsNotNumber(strValue) { if (strValue == ".") return false; if (isNaN(parseFloat(strValue,10))) return true; if (strValue.match(/.*[\+\-]/) != null) return true; if (strValue.match(/[^0123456789\-\+\.]/) != null) return true; if (strValue.match(/.+\..+\./) != null) return true; return false; } function fireEvent(element,event){ if (document.createEventObject){ // dispatch for IE var evt = document.createEventObject(); return element.fireEvent('on'+event,evt) } else{ // dispatch for firefox + others var evt = document.createEvent("HTMLEvents"); evt.initEvent(event, true, true ); // event type,bubbling,cancelable return !element.dispatchEvent(evt); } } /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ function integer_filter_class() { this.on_key_press = function(ptObject, evt) { //This will allow backspace to work. evt = (evt) ? evt : event; sChar = (evt.charCode) ? evt.charCode : evt.keyCode; for (var n =0; n < g_aIgnore.length; n++) { if (sChar == g_aIgnore[n]) return true; } var strNewVal = GetResultingValue(ptObject, String.fromCharCode(sChar)); return !this.isValueIllegal(strNewVal); } this.onblur = function(ptObject) { //Do nothing for integer } this.onfocus = function(ptObject) { //Do nothing for integer } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); return !this.isValueIllegal(strNewVal); } this.isValueIllegal = function(strValue) { var bIsIllegal = isNaN(parseInt(strValue, 10)); if (!bIsIllegal) { bIsIllegal = (strValue.match(/[^0-9]/) != null); } return bIsIllegal; } } var integer_filter = new integer_filter_class(); /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ function alphanum_filter_class() { this.on_key_press = function(ptObject, evt) { //This will allow backspace to work. evt = (evt) ? evt : event; sChar = (evt.charCode) ? evt.charCode : evt.keyCode; for (var n =0; n < g_aIgnore.length; n++) { if (sChar == g_aIgnore[n]) return true; } // console.debug(sChar); var strNewVal = GetResultingValue(ptObject, String.fromCharCode(sChar)); return !this.isValueIllegal(strNewVal); } this.onblur = function(ptObject) { //Do nothing for integer } this.onfocus = function(ptObject) { //Do nothing for integer } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); return !this.isValueIllegal(strNewVal); } this.isValueIllegal = function(strValue) { //console.debug(strValue); var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/ return !regex.test(strValue); } } var alphanum_filter = new alphanum_filter_class(); /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ function money_filter_class() { this.on_key_press = function(ptObject, evt) { evt = (evt) ? evt : event; sChar = (evt.charCode) ? evt.charCode : evt.keyCode; for (var n =0; n < g_aIgnore.length; n++) { if (sChar == g_aIgnore[n]) return true; } var strOldValue = ptObject.value; var strNewValue = GetResultingValue(ptObject, String.fromCharCode(sChar)); strNewValue = this.FormatUSCurrency(strNewValue, false); if (this.isValueIllegal(strNewValue)) return false; ptObject.value = strNewValue; this.SetCaretPosition(strOldValue, strNewValue,ptObject); return false; } this.onblur = function (ptObject) { ptObject.value = this.FormatUSCurrency(ptObject.value, true); if (ptObject.value != ptObject.previousValue) { // ptObject.fireEvent("change"); fireEvent(ptObject, "change"); } } this.onfocus = function(ptObject) { this.previousValue = ptObject.value } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); return !this.isValueIllegal(strNewVal); } this.isValueIllegal = function(strValue) { var bIsIllegal = false; var temp = strValue.replace(/,/g, ""); if (strValue.match(/[^s]\$/)) bIsIllegal = true; else if (strValue.match(/\..*\./) != null) bIsIllegal = true; else if (strValue.match(/\.+\d{3}/) != null) bIsIllegal = true; else if (parseInt(temp.substr(1)) > 9999999999) bIsIllegal = true; else if (IsNotNumber(strValue.replace(/\$/g, "").replace(/,/g, ""))) bIsIllegal = true; return bIsIllegal; } this.FormatUSCurrency = function(strValue, bIncludeDP) { strValue = strValue.replace(/,/g, ""); var iDPPosition = strValue.indexOf("."); if (iDPPosition == -1) iDPPosition = strValue.length; for (i = iDPPosition -3; i > 0; i -= 3) strValue = strValue.substr(0, i) + "," + strValue.substr(i); strValue = "$" + strValue.replace(/\$/g, ""); strValue = strValue.replace("$,","$"); if (bIncludeDP) { var iDP = strValue.length - strValue.indexOf("."); if (iDP > strValue.length) strValue += ".00"; else if (iDP == 1) strValue += "00"; else if (iDP == 2) strValue += "0"; if (strValue == "$.00") strValue = "$0.00"; } return strValue; } this.SetCaretPosition = function(strOld, strNew, ptObject) { var i = -1; strOld = strOld.replace(/,/g, ""); strOld = strOld.replace(/\$/g, ""); var strTemp = strNew.replace(/,/g, ""); strTemp = strTemp.replace(/\$/g, ""); var newCount = (((strTemp.length - strOld.length)<0)?1:(strTemp.length - strOld.length)); var iInsertPoint = strNew.length; for (var x = 0; x < strNew.length; x++) { if ((strNew.substr(x,1) != "$") && (strNew.substr(x,1) != ",")) { i++; if (strNew.substr(x,1) != strOld.substr(i,1)) { iInsertPoint = x + newCount; break; } } } if (document.selection) { trCaret = ptObject.createTextRange(); trCaret.collapse(true); trCaret.moveStart("character", iInsertPoint); trCaret.select(); } else if (ptObject.selectionStart || ptObject.selectionStart == '0') { ptObject.selectionStart = iInsertPoint; ptObject.selectionEnd = iInsertPoint; } } } var money_filter = new money_filter_class(); /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ function percent_filter_class() { this.on_key_press = function(ptObject, evt) { evt = (evt) ? evt : event; sChar = (evt.charCode) ? evt.charCode : evt.keyCode; //This will allow backspace to work. for (var n =0; n < g_aIgnore.length; n++) { if (sChar == g_aIgnore[n]) return true; } var strNewVal = GetResultingValue(ptObject, String.fromCharCode(sChar)); return !this.isValueIllegal(strNewVal); } this.onblur = function(ptObject) { ptObject.value = this.FormatPercent(ptObject.value, true); if (ptObject.value != ptObject.previousValue) { // ptObject.fireEvent("onchange"); fireEvent(ptObject,"change"); } } this.onfocus = function(ptObject) { this.previousValue = ptObject.value } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); return !this.isValueIllegal(strNewVal); } this.isValueIllegal = function(strValue) { var bIsIllegal = false; if (strValue.match(/\%.*\%/) != null) bIsIllegal = true; else if (strValue.match(/\%.+/) != null) bIsIllegal = true; else if (strValue.match(/\..*\./) != null) bIsIllegal = true; else if (parseInt(strValue) > 999) bIsIllegal = true; else if (strValue.match(/\.+\d{5}/) != null) bIsIllegal = true; else if (IsNotNumber(strValue.replace("%", "").replace(" ", ""))) bIsIllegal = true; return bIsIllegal; } this.FormatPercent = function(strValue, bIncludeDP) { strValue = strValue.replace(/\%/g, ""); if (strValue.length != 0) { while (strValue.charAt(0) == "0") { strValue = strValue.substr(1); } if (strValue.length == 0) strValue = "0"; var iDP = strValue.length - strValue.indexOf("."); if (iDP == strValue.length) strValue = "0" + strValue; if (iDP > strValue.length) strValue += ".00"; else if (iDP == 1) strValue += "00"; else if (iDP == 2) strValue += "0"; else if ((iDP > 2) && (iDP < strValue.length)) strValue = strValue.substr(0,strValue.length - iDP+5); // Ensure number is postfixed strValue = strValue + " %"; } return strValue; } } var percent_filter = new percent_filter_class(); /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ g_rgName = new Array(); function trim(s) { while (s.charAt(0) == " ") { s = s.substr(1); } return s; } function registerRG(name) { g_rgName[g_rgName.length] = name; } function unregisterRG(name) { for (var x = 0; x < g_rgName.length; x++) { if (g_rgName[x] == name) { g_rgName = ""; } } } function checkRG() { for (var x = 0; x < g_rgName.length; x++) { if (g_rgName[x] != "") { alert("Missing required selection for " + decodeURIComponent(g_rgName[x])); return false; } } return true; } function checkRequired(locForm) { for (field in locForm.elements) { if (locForm.elements[field]) { if (locForm.elements[field].getAttribute) { s = locForm.elements[field].getAttribute("required"); if (s != null) { val = trim(locForm.elements[field].value); s = decodeURIComponent(s); //if ((s == val) || (val == "")) { if (locForm.elements[field].type == 'checkbox' || locForm.elements[field].type == 'radio') { if (!locForm.elements[field].checked) { locForm.elements[field].focus(); alert(decodeURIComponent(locForm.elements[field].getAttribute("caption")) + " is a required field."); return false; } for (var i=0; i 0) { alert("This looks like a " + cardname + " number, not a " + card + " number."); return false; } else { alert("This card number is not valid."); return false; } } //alert(card); if (card=='AmExCard' && ccCVV.value.length !=4){ alert("Your CVV number for an American Express card must be 4 digits."); ccCVV.focus(); return false; }else if (card !='AmExCard' && ccCVV.value.length !=3){ alert("Your CVV number for a Visa, Mastercard, or Discover card must be 3 digits."); ccCVV.focus(); return false; } return true; } /*************************************************************************\ Object CardType([String cardtype, String rules, String len, int year, int month]) cardtype : type of card, eg: MasterCard, Visa, etc. rules : rules of the cardnumber, eg: "4", "6011", "34,37". len : valid length of cardnumber, eg: "16,19", "13,16". year : year of expiry date. month : month of expiry date. eg: var VisaCard = new CardType("Visa", "4", "16"); var AmExCard = new CardType("AmEx", "34,37", "15"); /*************************************************************************/ function CardType() { var n; var argv = CardType.arguments; var argc = CardType.arguments.length; this.objname = "object CardType"; var tmpcardtype = (argc > 0) ? argv[0] : "CardObject"; var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9"; var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19"; this.setCardNumber = setCardNumber; // set CardNumber method. this.setCardType = setCardType; // setCardType method. this.setLen = setLen; // setLen method. this.setRules = setRules; // setRules method. this.setExpiryDate = setExpiryDate; // setExpiryDate method. this.setCardType(tmpcardtype); this.setLen(tmplen); this.setRules(tmprules); if (argc > 4) this.setExpiryDate(argv[3], argv[4]); this.checkCardNumber = checkCardNumber; // checkCardNumber method. this.getExpiryDate = getExpiryDate; // getExpiryDate method. this.getCardType = getCardType; // getCardType method. this.isCardNumber = isCardNumber; // isCardNumber method. this.isExpiryDate = isExpiryDate; // isExpiryDate method. this.luhnCheck = luhnCheck;// luhnCheck method. return this; } /*************************************************************************\ boolean checkCardNumber([String cardnumber, int year, int month]) return true if cardnumber pass the luhncheck and the expiry date is valid, else return false. \*************************************************************************/ function checkCardNumber() { var argv = checkCardNumber.arguments; var argc = checkCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; var year = (argc > 1) ? argv[1] : this.year; var month = (argc > 2) ? argv[2] : this.month; this.setCardNumber(cardnumber); this.setExpiryDate(year, month); if (!this.isCardNumber()) return false; return this.isExpiryDate(); } /*************************************************************************\ String getCardType() return the cardtype. \*************************************************************************/ function getCardType() { return this.cardtype; } /*************************************************************************\ String getExpiryDate() return the expiry date. \*************************************************************************/ function getExpiryDate() { return this.month + "/" + this.year; } /*************************************************************************\ boolean isCardNumber([String cardnumber]) return true if cardnumber pass the luhncheck and the rules, else return false. \*************************************************************************/ function isCardNumber() { var argv = isCardNumber.arguments; var argc = isCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; if (!this.luhnCheck()) return false; for (var n = 0; n < this.len.size; n++) if (cardnumber.toString().length == this.len[n]) { for (var m = 0; m < this.rules.size; m++) { var headdigit = cardnumber.substring(0, this.rules[m].toString().length); if (headdigit == this.rules[m]) return true; } return false; } return false; } /*************************************************************************\ boolean isExpiryDate([int year, int month]) return true if the date is a valid expiry date, else return false. \*************************************************************************/ function isExpiryDate() { var argv = isExpiryDate.arguments; var argc = isExpiryDate.arguments.length; year = argc > 0 ? argv[0] : this.year; month = argc > 1 ? argv[1] : this.month; if (!isNum(year+"")) return false; if (!isNum(month+"")) return false; today = new Date(); expiry = new Date(year, month); return today.getTime() <= expiry.getTime(); } /*************************************************************************\ boolean isNum(String argvalue) return true if argvalue contains only numeric characters, else return false. \*************************************************************************/ function isNum(argvalue) { argvalue = argvalue.toString(); if (argvalue.length == 0) return false; for (var n = 0; n < argvalue.length; n++) if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9") return false; return true; } /*************************************************************************\ boolean luhnCheck([String CardNumber]) return true if CardNumber pass the luhn check else return false. Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl \*************************************************************************/ function luhnCheck() { var argv = luhnCheck.arguments; var argc = luhnCheck.arguments.length; var CardNumber = argc > 0 ? argv[0] : this.cardnumber; if (! isNum(CardNumber)) { return false; } var no_digit = CardNumber.length; var oddoeven = no_digit & 1; var sum = 0; for (var count = 0; count < no_digit; count++) { var digit = parseInt(CardNumber.charAt(count)); if (!((count & 1) ^ oddoeven)) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } return sum % 10 == 0; } /*************************************************************************\ ArrayObject makeArray(int size) return the array object in the size specified. \*************************************************************************/ function makeArray(size) { this.size = size; return this; } /*************************************************************************\ CardType setCardNumber(cardnumber) return the CardType object. \*************************************************************************/ function setCardNumber(cardnumber) { this.cardnumber = cardnumber; return this; } /*************************************************************************\ CardType setCardType(cardtype) return the CardType object. \*************************************************************************/ function setCardType(cardtype) { this.cardtype = cardtype; return this; } /*************************************************************************\ CardType setExpiryDate(year, month) return the CardType object. \*************************************************************************/ function setExpiryDate(year, month) { this.year = year; this.month = month; return this; } /*************************************************************************\ CardType setLen(len) return the CardType object. \*************************************************************************/ function setLen(len) { // Create the len array. if (len.length == 0 || len == null) len = "13,14,15,16,19"; var tmplen = len; n = 1; while (tmplen.indexOf(",") != -1) { tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length); n++; } this.len = new makeArray(n); n = 0; while (len.indexOf(",") != -1) { var tmpstr = len.substring(0, len.indexOf(",")); this.len[n] = tmpstr; len = len.substring(len.indexOf(",") + 1, len.length); n++; } this.len[n] = len; return this; } /*************************************************************************\ CardType setRules() return the CardType object. \*************************************************************************/ function setRules(rules) { // Create the rules array. if (rules.length == 0 || rules == null) rules = "0,1,2,3,4,5,6,7,8,9"; var tmprules = rules; n = 1; while (tmprules.indexOf(",") != -1) { tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length); n++; } this.rules = new makeArray(n); n = 0; while (rules.indexOf(",") != -1) { var tmpstr = rules.substring(0, rules.indexOf(",")); this.rules[n] = tmpstr; rules = rules.substring(rules.indexOf(",") + 1, rules.length); n++; } this.rules[n] = rules; return this; } /* * Copyright (c) 2004-2016 OIC Group, Inc. * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * */ function decimal_filter_class() { this.on_key_press = function(ptObject, evt) { evt = (evt) ? evt : event; sChar = (evt.charCode) ? evt.charCode : evt.keyCode; //This will allow backspace to work. for (var n =0; n < g_aIgnore.length; n++) { if (sChar == g_aIgnore[n]) return true; } var strNewVal = GetResultingValue(ptObject, String.fromCharCode(sChar)); return !this.isValueIllegal(strNewVal); } this.onblur = function(ptObject) { var iDPPos = ptObject.value.indexOf("."); if (iDPPos == -1) return; var bValueChanged = false; if (iDPPos == ptObject.value.length -1) { ptObject.value = ptObject.value.substr(0, ptObject.value.length -1); bValueChanged = true; } if (iDPPos == 0) { var dNewValue = "0" + ptObject.value; ptObject.value = dNewValue; bValueChanged = true; } if (bValueChanged) { // ptObject.fireEvent("onchange"); fireEvent(ptObject,"change"); } } this.onfocus = function(ptObject) { //Do nothing for decimal } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); return !this.isValueIllegal(strNewVal); } this.isValueIllegal = function(strValue) { bIsIllegal = IsNotNumber(strValue); if (!bIsIllegal) { if (strValue.match(/\..*\./) != null) bIsIllegal = true; } return bIsIllegal; } } var decimal_filter = new decimal_filter_class();