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 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();
var perline = 9;
var divSet = false;
var curId;
var colorLevels = Array('0', '3', '6', '9', 'C', 'F');
var colorArray = Array();
var ie = false;
var nocolor = 'none';
if (document.all) { ie = true; nocolor = ''; }
function getObj(id) {
if (ie) { return document.all[id]; }
else { return document.getElementById(id); }
}
function addColor(r, g, b) {
var red = colorLevels[r];
var green = colorLevels[g];
var blue = colorLevels[b];
addColorValue(red, green, blue);
}
function addColorValue(r, g, b) {
colorArray[colorArray.length] = '#' + r + r + g + g + b + b;
}
function setColor(color) {
var link = getObj(curId);
var field = getObj(curId + 'field');
var picker = getObj('colorpicker');
field.value = color;
if (color == '') {
link.style.background = nocolor;
link.style.color = nocolor;
color = nocolor;
} else {
link.style.background = color;
link.style.color = color;
}
picker.style.display = 'none';
eval(getObj(curId + 'field').title);
}
function setDiv(id) {
if (divSet) {
getObj('colorpicker').parentNode = getObj(id);
return;
}
if (!document.createElement) { return; }
var elemDiv = document.createElement('div');
if (typeof(elemDiv.innerHTML) != 'string') { return; }
genColors();
elemDiv.id = 'colorpicker';
elemDiv.style.position = 'absolute';
elemDiv.style.display = 'none';
elemDiv.style.border = '#000000 1px solid';
elemDiv.style.background = '#FFFFFF';
elemDiv.innerHTML = 'Pick a color: '
+ '(No color)
'
+ getColorTable() + '';
getObj(id).appendChild(elemDiv);
divSet = true;
}
function pickColor(id) {
setDiv(id);
var picker = getObj('colorpicker');
if (id == curId && picker.style.display == 'block') {
picker.style.display = 'none';
return;
}
curId = id;
var thelink = getObj(id);
picker.style.top = getAbsoluteOffsetTop(thelink) + 20;
picker.style.left = getAbsoluteOffsetLeft(thelink);
picker.style.display = 'block';
}
function genColors() {
addColorValue('0','0','0');
addColorValue('3','3','3');
addColorValue('6','6','6');
addColorValue('8','8','8');
addColorValue('9','9','9');
addColorValue('A','A','A');
addColorValue('C','C','C');
addColorValue('E','E','E');
addColorValue('F','F','F');
for (a = 1; a < colorLevels.length; a++)
addColor(0,0,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,a,5);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,5);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,5);
return colorArray;
}
function getColorTable() {
var colors = colorArray;
var tableCode = '';
tableCode += '