
// Display an error at the top of the page
function DisplayError(s)
{
    // Clear out any existing user messages
    if ( grab("userMessages" ) )
       grab("userMessages").innerHTML = "";
    
    // 12/2/08 CLD wrap error message in h4 tags so that line break is added automatically - stop payment functionality
    if ( grab("errorMessages")) 
       grab("errorMessages").innerHTML = '<h4><span class="iconError">' + s + '</span></h4>';
       //grab("errorMessages").innerHTML = '<span class="iconError">' + s + '</span>';

    // Scroll to the top of the page, per defect 446
    window.scroll(0, 0);
}

function clearErrorMessages()
{
   if ( grab("errorMessages") ) grab("errorMessages").innerHTML = "";
}

function clearUserMessages()
{
   if ( grab("userMessages") ) grab("userMessages").innerHTML = "";
}

function clearErrorField( spanName )
{
   if ( grab(spanName) ) grab(spanName).className = "";
}

function setErrorField( controlName, spanName )
{
   var ctl = grab(controlName);
   if ( ctl ) 
   {
      ctl.focus();
      if ( ctl.type == "text" )
         ctl.select();       
   }
   if ( grab(spanName) ) grab(spanName).className = "iconError";
}

function grab(object)
{	// object = id of object to be manipulated
	//alert(object)
	if(document.getElementById) obj = document.getElementById(object); // method for newer, DOM-compatable browsers
	else if(document.all) obj = document.all[obj]; // method for older versions of IE
	else if(document.layers) obj = document.layers[obj]; // method for older versions of Netscape
	//alert(obj)
	return(obj);
}

function validateInteger( value )
{
   // Validate integer value.  Positive or negative
   var regexInteger = /^-?\d+$/
   if ( value.match( regexInteger ) != null )
      return true;
   else
      return false;

}

function validateDecimal( value )
{
   // Validate value for decimal format.  Formats for decimal numbers include the following:
   //        xxx
   //     xxx.xx
   //    -xxx.xx
   //    (xxx.xx)
   // All of the above formats can support optional currency characters and commas
   //     /^\s*(\d*)?\.{0,1}\d{0,2}\s*$/;
   
   /* This is a long regular expression, broken up into four parts
                        |  Validate 123,456 with optional    |   |  Validate (123,456) with optional  |   | Validate without|   |Validate without commas,|
                        |  decimal point, negative sign      |   |  decimal point and currency sign   |   | commas, optional|   |using parens to signify |
                        |  and currency                      |   |                                    |   | decimal point   |   |negative value          |
   */
   var regexDecimal = /(^\-?\$?\d{1,3}(,?\d{3})*(\.\d{0,2})?$)|(^\(\$?\d{1,3}(,?\d{3})*(\.\d{0,2})?\)$)|(^\-?\$?\d*(\.\d{0,2})?$)|(^\(\$?\d*(\.\d{0,2})?\)$)/
   if ( value.match( regexDecimal ) != null )
      return true;
   else
      return false;
}

function validatePhoneNumber( value ) 
{
   var regexPhoneNumber = /^\(?\d\d\d\)?[\s-\.]*\d\d\d[\s-\.]*\d\d\d\d$/
   if ( value.match( regexPhoneNumber ) != null )
      return true;
   else
      return false;
}

function validatePhoneNumberNonUS( value )
{
   // Allow anywhere from 7 to 18 digits, parens, dashes, dots or whitespace chars
   var regexPhoneNumberNonUS = /^[\s-\.\(\d\)]{1,16}$/
   if ( value.match( regexPhoneNumberNonUS ) != null )
      return true;
   else
      return false;
}

function validateZipCodeUS( value )
{
   var regexZipCode = /^(\d{5}|\d{5}-\d{4})$/;
   if ( value.match( regexZipCode ) != null )
      return true;
   else
      return false;
}

function validateZipCodeNonUS( value )
{
   // Middleware has been updated to allow character data, so we will now allow 
   // any values for Zip Code
   if (( value.length >= 1 ) && ( value.length <= 10 ))
      return true;
   else
      return false;
}

function validateEmailAddress( value )
{
   var regexEmail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   if ( value.match( regexEmail ) != null )
      return true;
   else
      return false;
}

function validatePIN( value ) 
{
   /* Rules for validating PINs:
         - Must be 4 digits long
         - Must be greater than 0010
         - Must be less than 9999
   */
   var regexPIN = /^\d{4}$/;
   if ( value.match( regexPIN ) != null )
   {
      var pinValue = parseInt( value, 10 );
      if ( ( pinValue <= 10 ) || ( pinValue >= 9999 ) )
         return false;
   
      return true;
   }
   else
      return false;

}

function validateAlphaNumeric( value )
{
   // Validate alphanumeric value.
   var regexAlphaNumeric = /^[A-Za-z0-9\s]+$/
   if ( value.match( regexAlphaNumeric ) != null )
      return true;
   else
      return false;

}
function Hashtable()
{
var keysToIndex = {__indexToValue:[],__indexToKeys:[]};
var activeEnum = [];
var tableLength = 0;
var self = this;
/*
This inner Object constructor is used to implement a Java
style Enumerator (and Iterator) Object.
*/
function Enumeration(arrNm)
{
var lastIndex = null;
var enumIndex = 0;
while(typeof activeEnum[enumIndex] == 'number')enumIndex += 1;
activeEnum[enumIndex] = 0;
/*
Returns true if this Enumerator/ has another entry to
return, else returns false.
*/
this.hasNext = this.hasMoreElements = function(){
if(activeEnum[enumIndex] < tableLength){
return true;
}else{
if(typeof activeEnum[enumIndex] == 'number'){
activeEnum[enumIndex] = null;
}
return false;
}
};
/*
Returns the next item from this Enumerator/Iterator (key
or value, depending on whether it was created with the keys
or elements methods).
*/
this.next = this.nextElement = function(){
if(this.hasNext){
lastIndex = activeEnum[enumIndex];
return keysToIndex[arrNm][activeEnum[enumIndex]++];
}else{
return null;
}
};
/*
Removes the last entry (key/value pair) accessed with the
next or nextElement methods of this Enumerator/Iterator
(if any). The key/value pair is removed regardless of whether
the Enumerator/Iterator was accessing keys or values.
*/
this.remove = function(){
if(typeof lastIndex == 'number'){
self.remove(keysToIndex.__indexToKeys[lastIndex]);
lastIndex = null;
}
};
};
// End Enumeration
/*
Returns the value mapped to the provided (String) key, or null
*/
this.get = function(key){
if(typeof keysToIndex[key] == 'number'){
return keysToIndex.__indexToValue[keysToIndex[key]];
}else{
return null;
}
};
/*
Adds the value provided to this Hashtable mapped to the key
provided.
*/
this.put = function(key, value){
if(typeof keysToIndex[key] == 'number'){
keysToIndex.__indexToValue[keysToIndex[key]] = value;
}else{
keysToIndex[key] = tableLength;
keysToIndex.__indexToValue[tableLength] = value;
keysToIndex.__indexToKeys[tableLength++] = key;
}
};
/*
Removes the key and any value mapped to it from this
Hashtable.
*/
this.remove = function(key){
var remIndex = keysToIndex[key];
if(typeof remIndex == 'number'){
delete keysToIndex[key];
tableLength -= 1;
for(var c = remIndex;c < tableLength;c++){
keysToIndex.__indexToValue[c] =
keysToIndex.__indexToValue[c+1];
keysToIndex[(keysToIndex.__indexToKeys[c] =
keysToIndex.__indexToKeys[c+1])] = c;
}
for(var c = 0;c < activeEnum.length;c++){
if((activeEnum[c])&&(remIndex < activeEnum[c])){
activeEnum[c] -= 1;
}
}
}
};
/*
Returns the length of this Hashtable.
*/
this.size = function(){
return tableLength;
};
/*
This method is not intended for external use! use elements
and keys methods instead.
*/
this.__enumerate = function(type){
return new Enumeration(type);
};
/*
Returns an object that is similar to the Java Enumeration
Interface, having hasMoreElements and nextElement Methods. This
object also reproduces the Java Iterator interface, having methods
hasNext, next and remove. This enumeration is of the values stored
in the Hashtable.
*/
Hashtable.prototype.elements = function(){
return this.__enumerate('__indexToValue');
}
/*
Returns an object that is similar to the Java Enumeration
Interface, having hasMoreElements and nextElement Methods. This
object also reproduces the Java Iterator interface, having methods
hasNext, next and remove. This enumeration is of the keys stored
in the Hashtable.
*/
Hashtable.prototype.keys = function(){
return this.__enumerate('__indexToKeys');
}
/*
Removes all entry's from the Hashtable
*/
Hashtable.prototype.clear = function(){
var e = this.keys();
while(e.hasNext()){
this.remove(e.next());
}
}
Hashtable.prototype.toString = function(){
var n,e = this.keys();
var st = '';
while(e.hasNext()){
n = e.next();
st += n+' =&gt; '+this.get(n)+'\r\n';
}
return st;
}
/*
Returns true if this Hashtable contains a value that is equal
to the value provided, else returns false
*/
Hashtable.prototype.contains = function(testVal){
var e = this.elements();
while(e.hasNext()){
if(e.next() == testVal)return true;
}
return false;
}
/*
Returns true if this Hashtable contains a value that is equal
to the value provided, else returns false.
*/
Hashtable.prototype.containsValue = Hashtable.prototype.contains;
/*
Returns true if this Hashtable contains a value mapped to
the value provided, else returns false.
*/
Hashtable.prototype.containsKey = function(testKey){
return (this.get(testKey) != null);
}
/*

Returns true if this Hashtable has zero entry's.
*/
Hashtable.prototype.isEmpty = function(){
return (this.size() == 0);
}
/*
If the parameter provided is another Hashtable object
then all of the key/value pairs from the provided Hashtable
are added to this Hashtable.
*/
Hashtable.prototype.putAll = function(hTable){
if(hTable.constructor == Hashtable){
var n,e = hTable.keys();
while(e.hasNext()){
n = e.next();
this.put(n, hTable.get(n));
}
}
}
/*
Returns a 'shallow' copy of this Hashtable.
*/
Hashtable.prototype.clone = function(){
var ht = new Hashtable();
ht.putAll(this);
return ht;
}
/*
Returns true if this Hashtable equals the parameter
provided, else it returns false.
*/
Hashtable.prototype.equals = function(o){
return (o == this);
}
}