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; } /* * Copyright (c) 2004-2006 OIC Group, Inc. * Written and Designed by James Hunt * * 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)); if (this.isValueIllegal(strNewVal)) { return false; } return true; } this.onblur = function(ptObject) { ptObject.value = this.FormatPercent(ptObject.value, true); if (ptObject.value != ptObject.previousValue) ptObject.fireEvent("onchange"); } this.onfocus = function(ptObject) { this.previousValue = ptObject.value } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); if (this.isValueIllegal(strNewVal)) { return false; } return true; } 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(" ", "")) == true) 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-2006 OIC Group, Inc. * Written and Designed by James Hunt * * 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 " + unescape(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 = unescape(s); //if ((s == val) || (val == "")) { //alert (locForm.elements[field].type); if (locForm.elements[field].type == 'checkbox') { if (!locForm.elements[field].checked) { locForm.elements[field].focus(); alert(unescape(locForm.elements[field].getAttribute("caption")) + " is a required field."); return false; } } else { if (val == "") { locForm.elements[field].focus(); alert(unescape(locForm.elements[field].getAttribute("caption")) + " is a required field."); return false; } } } if (locForm.elements[field].name == "checker" && locForm.elements[field].checked == true && locForm.elements[field].value != 0 ) { alert ("You must choose the correct answer in the anti-spam question to proceed"); return false; } } } } if (!checkRG()) return false; return true; } /* * Copyright (c) 2004-2006 OIC Group, Inc. * Written and Designed by James Hunt * * 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("onchange"); } this.onfocus = function(ptObject) { this.previousValue = ptObject.value } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); if (this.isValueIllegal(strNewVal)) { return false; } return true; } 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, "")) == true) 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-2006 OIC Group, Inc. * Written and Designed by James Hunt * * 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)); if (this.isValueIllegal(strNewVal)) { return false; } return true; } 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); if (this.isValueIllegal(strNewVal)) { return false; } return true; } this.isValueIllegal = function(strValue) { var bIsIllegal = isNaN(parseInt(strValue, 10)); if (bIsIllegal == false) { bIsIllegal = (strValue.match(/[^0-9]/) != null); } return bIsIllegal; } } var integer_filter = new integer_filter_class(); /* * Copyright (c) 2004-2006 OIC Group, Inc. * Written and Designed by James Hunt * * 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)); if (this.isValueIllegal(strNewVal)) { return false; } return true; } 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"); } this.onfocus = function(ptObject) { //Do nothing for decimal } this.onpaste = function(ptObject, evt) { var strNewVal = GetResultingValue(ptObject, String.fromCharCode(evt.charCode)); alert(strNewVal); if (this.isValueIllegal(strNewVal)) { return false; } return true; } this.isValueIllegal = function(strValue) { bIsIllegal = IsNotNumber(strValue); if (bIsIllegal == false) { if (strValue.match(/\..*\./) != null) bIsIllegal = true; } return bIsIllegal; } } var decimal_filter = new decimal_filter_class();