<!-- hide this script from non-javascript-enabled browsers
// VARIABLE DECLARATIONS
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// whitespace characters
var whitespace = " \t\n\r";

// decimal point character differs by language and culture
var decimalPointDelimiter = "."

var defaultEmptyOK = false


var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength)
{
var myForm=document.forms[document.forms.length - 1];
var myField=myForm.elements[fieldName];
myField.nextField=myForm.elements[nextFieldName];

if (myField.maxLength == null)
   myField.maxLength=fakeMaxLength;

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUp;
}

function autojumpSelected(fieldName,nextFieldName,fakeMaxLength)
{
var myForm=document.forms[document.forms.length - 1];
var myField=myForm.elements[fieldName];
myField.nextField=myForm.elements[nextFieldName];

if (myField.maxLength == null)
   myField.maxLength=fakeMaxLength;

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUpSelected;
}

function autojumpforms(form,fieldName,nextFieldName,fakeMaxLength)
{
var myForm=form;
var myField=myForm.elements[fieldName];
myField.nextField=myForm.elements[nextFieldName];

if (myField.maxLength == null)
   myField.maxLength=fakeMaxLength;

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
this.beforeLength=this.value.length;
downStrokeField=this;
}

function autojump_keyUp()
{
if (
   (this == downStrokeField) && 
   (this.value.length > this.beforeLength) && 
   (this.value.length >= this.maxLength)
   )
   this.nextField.focus();
downStrokeField=null;
}

function autojump_keyUpSelected()
{
if (
   (this == downStrokeField) && 
   (this.value.length > this.beforeLength) && 
   (this.value.length >= this.maxLength)
   ) {
   this.nextField.focus();
   this.nextField.select();
   }
downStrokeField=null;
}

function padZeros(field, maxSize){
  var theValue = field.value;
  theValue = trim(theValue);
  var theLength = theValue.length;

  if(maxSize == 4){
    if(theLength == 3){
      field.value = "2"+theValue;
    }else if(theLength == 2){
      field.value = "20"+theValue;
    }else if(theLength == 1){
      field.value = "200"+theValue;
    }
  }else{
    if(theLength == 1){
      field.value = "0"+theValue;
    }
  }
}

function padFieldZeros(field,size){

  var theValue = field.value
  theValue = trim(theValue);
  var fieldLength = theValue.length;
  if(fieldLength>0){
    var padding = size-fieldLength;
    var tempValue = theValue
    for(i=0;i<padding;i++){
       tempValue = "0" + tempValue;
    } 
    field.value = tempValue;
  }
}

function trim(st) {
  var len = st.length
  var begin = 0, end = len - 1;
  while (st.charAt(begin) == " " && begin < len) {
    begin++;
  }
  while (st.charAt(end) == " " && begin < end) {
    end--;
  }
  return st.substring(begin, end+1);
}


// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an floating point (real) number. If signed,
// the sign must be leading only.
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isFloat (s)

{   
    var i;
    var startPos = 0;
    var seenDecimalPoint = false;

    if (s == ".") return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    // skip leading + or -
    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
       startPos = 1;    
    for (i = startPos; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


// numeric fields should have 2 decimal places, if not
// fix it
function fixDecimals(field, specific) {

    // this code is specific to create and edit fy adjustments
    if (specific != null && specific == "ADJ") {
        //alert("in fixDecimals " + field.name + " ->" + field.value + "<-");
        // insert default value if empty
        //if (field.name != "tax_deferred" && field.value == "") {
        if (field.value == "") {
            field.value = "0.00"; // default
            return;
        }
    }
    
    // this code is specific to the cash remittance form fields
    if (specific != null && specific == "blank") {
        if (field.value == "") {
            return; // leave it blank
        }
    }    
    
    // ---- start of generic code

    var theValue = field.value;
    theValue = trim(theValue);
    var theLength = theValue.length;
    
     //alert("in fixDecimals " + field.name + " -> " + field.value);

  // the value must be numeric
  if (isFloat(theValue)) {
    // is there a decimal?
    var isDecimal = theValue.indexOf(".");

    if (isDecimal != -1) {
        // how many digits to the right of the decimal?
        var decPlaces = theLength - (isDecimal + 1);
        //alert("value " + theValue + " decimal places = " + decPlaces);
        if (decPlaces == 0) {
            field.value = theValue + "00";
        } else if (decPlaces == 1) {
            field.value = theValue + "0";
        } else if (decPlaces == 2) {
            // do nothing
        } else if (decPlaces > 2) {
            // truncate extra places
            field.value = theValue.substring(0, (theLength - (decPlaces - 2)));
        }
        // add a zero to the left of the decimal if the number starts with
        // a decimal
        if (isDecimal == 0) {
            field.value = "0" + field.value;
        }
        return;
    }
    if (isDecimal == -1) {
        // no decimal at all
        field.value = theValue + ".00";
    }
  } else {
     alert("Value must be numeric!");
     // next 2 lines only work using an onBlur event -
     // does not work for onChange event
     document.forms[document.forms.length - 1].elements[field.name].focus();
     document.forms[document.forms.length - 1].elements[field.name].select();
  }

}

// used by applications to submit form by Pressing the enter key
// must have a validateForm()javascript function which submits the form
var IE=(document.all) ? true : false;
var NS=(document.layers) ? true : false;
var NS6=(document.getElementById && !document.all) ? true : false;
if (NS || NS6){ 
  document.captureEvents(Event.KEYPRESS); 
}
document.onkeypress = handler; 

function handler(evnt){
  if (NS || NS6){
    keycd = evnt.which; 
  }else{  
    if (IE){
      evnt = window.event; 
      keycd = evnt.keyCode; 
    } 
  }
  if (keycd==13){ 
   if(typeof validateForm == 'function'){
      return validateForm(); 
      return false;
   }
  }
} 


// stop hiding -->





