var White = "#ffffff";
var Black = "#000000";
var BadInput = "#ffffbb";
var SelectRequiredColor = "#fff7f7";

var digits = "0123456789";
var lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
var upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var alphaChars = lowerCaseLetters + upperCaseLetters + digits + " .-_&";
var stringChars = alphaChars + ",?/<>;:'[]!@#$%&*()+=";
var whiteSpace = " \t\n\r";
var defaultHelp = "Please move mouse onto one of the options to get additional help.";

var IsIE = navigator.userAgent.search(/MSIE/g) > 0;

var ChildID = CalculateChildID();
eval("var childWindowLibraryDM_" + ChildID + ";");

/**** TEST AND VALIDATE FUNCTIONS ************************************/
// IsAmericanExpress(s)
// IsDecimal (s)
// IsDiscover(s)
// IsEmail(s)
// IsEmpty(s)
// IsMajorCreditCard(s)
// IsMasterCard(s)
// IsUrl(s)
// IsValidCreditCard(s, clean)
// IsVisa(s)

/**** FORMATTING FUNCTIONS *******************************************/
// Caps(s, case)
// CutString (s, length, dots)
// FormatCurrency(num, dollar)
// NeatCharsInBag (s, bag, replaceChar)
// Reformat (s)
// StripCharsInBag (s, bag)
// StripCharsNotInBag (s, bag)
// ToggleImage (imageID, newSrc)
// Trim(s)

/**** USER INPUT FUNCTIONS **********************************/
// Blur(element)
// BlurForm(form)
// ValidateCreditCard(inputField, required)
// ValidateDate(inputField, required)
// ValidateEmail(inputField, required)
// ValidateForm(form)
// ValidateMonthYear(inputField, required)
// ValidateNumber(inputField, required, validChars, currency)
// ValidatePhone(inputField, required)
// ValidateRadio(inputField, required)
// ValidateSelection(inputField, required)
// ValidateSsn(inputField, required)
// ValidateString(inputField, required, validChars, case)
// ValidateText(inputField, required, list)
// ValidateTime(inputField, required)
// ValidateUrl(inputField, required)

/**** ADDITIONAL FUNCTIONS *******************************************/
// ChildWindow(url, width, height, scrollbars, resizable)
// Property(objectName, propertyName, propertyValue, notString)
// ShowHelp(s)

/*********************************************************************/
/**** TEST AND VALIDATE FUNCTIONS ************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsAmericanExpress(s) {
  s = StripCharsNotInBag(s, digits);

  firstdig = s.substring(0, 1);
  seconddig = s.substring(1, 2);
  if (s.length == 15 && firstdig == 3 && (seconddig == 4 || seconddig == 7)) return IsValidCreditCard(s, 1);
  return false;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsDiscover(s) {
  s = StripCharsNotInBag(s, digits);

  first4digs = s.substring(0, 4);

  if (s.length == 16 && first4digs == "6011") return IsValidCreditCard(s, 1);
  return false;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsEmail(s) {
  if (IsEmpty(s)) return false;
  return s.match(/^[A-Za-z0-9_]+([_\-\.]\w+)*\@[A-Za-z0-9_]+([_\-\.]\w+)*\.[A-Za-z0-9]+$/) ? true : false;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsEmpty(s) {
  return ((s == null) || (s.length == 0));
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsMajorCreditCard(s) {
  if (IsVisa(s) == 1) ccType = "Visa";
  else if (IsMasterCard(s)) ccType = "MasterCard";
  else if (IsAmericanExpress(s)) ccType = "American Express";
  else if (IsDiscover(s)) ccType = "Discover";
  else ccType = "";

  return ccType
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsMasterCard(s) {
  s = StripCharsNotInBag(s, digits);

  firstdig = s.substring(0, 1);
  seconddig = s.substring(1, 2);

  if (s.length == 16 && firstdig == 5 && (seconddig >= 1 && seconddig <= 5)) return IsValidCreditCard(s, 1);
  return false;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsUrl(s) {
  if (IsEmpty(s)) return false;

  return s.match(/^(https:\/\/)?[A-Za-z0-9]+([\-\.\?\^\|\+\/~#&=,;]\w+)*(:[0-9]+)?(\/)*$/) ? true : false;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsValidCreditCard(s, clean) {
  if (!clean) s = StripCharsNotInBag(s, digits);
  if (s.length > 16 || s.length < 13) return (false);

  sum = 0; mul = 1; l = s.length;
  for (var i = 0; i < l; i++) {
    digit = s.substring(l - i - 1, l - i);
    tproduct = parseInt(digit, 10) * mul;

    if (tproduct >= 10) sum += (tproduct % 10) + 1;
    else sum += tproduct;

    if (mul == 1) mul++;
    else mul--;
  }

  if ((sum % 10) == 0) return true;
  else return false;
} 

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsVisa(s) {
  s = StripCharsNotInBag(s, digits);
  if ((s.length == 16 || s.length == 13) && s.substring(0, 1) == 4) return IsValidCreditCard(s, 1);
  return false;
}

/*********************************************************************/
/**** FORMATTING FUNCTIONS *******************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function Caps(s, textCase) {
  if (IsEmpty(s)) return "";
  if (s) {
  	s = NeatCharsInBag(s, whiteSpace);
    if (textCase == "upper") s = s.toUpperCase();
    else if (textCase == "lower") s = s.toLowerCase();
    else if(textCase != "none") {
      splitStr = s.split(" ");
      for(var i = 0; i < splitStr.length; i++) splitStr[i] = splitStr[i].substring(0, 1).toUpperCase() + splitStr[i].substring(1);
      s = splitStr.join(" ");
    }
	}
	return s;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CutString (s, length, dots) {
  if (length == null) length = 0

  if (s.length > length) return s.substr(0, length) + dots;
  else return s;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function FormatCurrency(num, dollar) {
  if (num == null || (num == "" && num != 0)) return "";
  
  num = num.toString().replace(/\$|\,/g, '');
  if (isNaN(num)) num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num * 100 + 0.50000000001);
  cents = num % 100;
  num = Math.floor(num / 100).toString();
  if (cents < 10) cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
    num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
  return (((sign) ? '' : '-') + (dollar ? '$' : '') + num + '.' + cents);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function NeatCharsInBag (s, bag, replaceChar) {
var i, j;
var returnString = "";

  if (IsEmpty(s)) return "";
  if (IsEmpty(bag)) bag = " ";
  if (IsEmpty(replaceChar)) replaceChar = " ";
  for (i = 0; i < s.length; i++) {
    if (bag.indexOf(s.charAt(i)) == -1) break;
  }
  for (j = i; j < s.length; j++) {   
    if (bag.indexOf(s.charAt(j)) == -1) returnString += s.charAt(j);
	  else if (j > 0 && bag.indexOf(s.charAt(j - 1)) == -1) returnString += replaceChar;
  }

  return returnString;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function Reformat (s) {
var arg;
var sPos = 0;
var resultString = "";

  if (IsEmpty(s)) return "";
  for (var i = 1; i < Reformat.arguments.length; i++) {
    arg = Reformat.arguments[i];
    if (i % 2 == 1) resultString += arg;
    else {
      resultString += s.substring(sPos, sPos + arg);
      sPos += arg;
    }
  }
  return resultString + s.substring(sPos);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function StripCharsInBag (s, bag) {
var returnString = "";

  if (IsEmpty(s)) return "";
  if (IsEmpty(bag)) bag = "";
 
  for (var i = 0; i < s.length; i++) {   
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }

  return returnString;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function StripCharsNotInBag (s, bag) {
var returnString = "";
var c;

  if (IsEmpty(s)) return "";
  if (IsEmpty(bag)) bag = "";
  for (var i = 0; i < s.length; i++) {   
    c = s.charAt(i);
    if (bag.indexOf(c) != -1) returnString += c;
  }
 
  return returnString;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ToggleImage (imageID, newSrc) {
var image = document.getElementById(imageID);

  if (image && newSrc) image.src = newSrc;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function Trim(s) { 
  if (IsEmpty(s)) return "";
  while (s.substring(0, 1) == ' ' || s.substring(0, 1) == '\t' || s.substring(0, 1) == '\n' || s.substring(0, 1) == '\r') 
    s = s.substring(1, s.length);
  while (s.substring(s.length - 1, s.length) == ' ' || s.substring(s.length - 1, s.length) == '\t' || 
         s.substring(s.length - 1, s.length) == '\n' || s.substring(s.length - 1, s.length) == '\r') 
    s = s.substring(0, s.length - 1);
  return s;
} 

/*********************************************************************/
/**** USER INPUT FUNCTIONS *******************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function Blur(element) {
var required = 0, kind, returnValue = false;

  if (!element) return true;
  kind = "" + element.getAttribute("kind");
  if (kind != null) {
    if (element.className && element.className.match(/required/i)) required = 1;
    switch (kind) {
      case "alpha": returnValue = ValidateString(element, required, alphaChars, element.getAttribute("case")); break;
      case "amount": returnValue = ValidateNumber(element, required, digits + '.-', 1); break;
      case "credit": returnValue = ValidateCreditCard(element, required); break;
      case "date": returnValue = ValidateDate(element, required); break;
      case "decimal": returnValue = ValidateNumber(element, required, digits + '.-'); break;
      case "email": returnValue = ValidateEmail(element, required); break;
      case "monthyear": returnValue = ValidateMonthYear(element, required); break;
      case "number": returnValue = ValidateNumber(element, required, digits + '-'); break;
      case "password": returnValue = ValidateString(element, required, alphaChars, "none"); break;
      case "phone": returnValue = ValidatePhone(element, required); break;
      case "radio": returnValue = ValidateRadio(element, required); break;
      case "select": returnValue = ValidateSelection(element, required); break;
      case "ssn": returnValue = ValidateSsn(element, required); break;
      case "string": returnValue = ValidateString(element, required, stringChars, element.getAttribute("case")); break;
      case "text": returnValue = ValidateText(element, required); break;
      case "textList": returnValue = ValidateText(element, required, 1); break;
      case "time": returnValue = ValidateTime(element, required); break;
      case "username": returnValue = ValidateString(element, required, lowerCaseLetters + upperCaseLetters + digits + '.-_', "none"); break;
      case "url": returnValue = ValidateUrl(element, required); break;
      case "zip": returnValue = ValidateString(element, required, digits + ' -', "upper"); break;
      default: returnValue = true;
    }
  }
  eval("if (window." + element.name.replace(/:/g, "_") + "Blur) " + element.name.replace(/:/g, "_") + "Blur()");
  return returnValue;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function BlurForm(form) {
  for (i = 0; i < form.elements.length; i++) {
    if (form.elements[i].type == "text" && form.elements[i].value)
      Blur (form.elements[i]);
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
var oldSearchType1 = "", oldSearchType2 = "";
function ListSearch(searchForm, same) {
  var alphaSearchOperators = Array("=", "=", "Not = ", "<>", "Exact = ", "==", "Starts", "~", "Between", "BETWEEN")
  var numberSearchOperators = Array("=", "=", "Not = ", "<>", ">=", ">=", "<=", "<=", "Between", "BETWEEN")
  var searchBy = searchForm.searchBy;
  var searchOperator = searchForm.searchOperator;
  var searchOperatorValue = searchOperator.value ? searchOperator.value : "=";

  splitValue = searchBy.value.split(/\^/);
  if (splitValue.length == 2) {
    if (same) {
      if (splitValue[1] == "alpha" && (searchOperator.options.length < 2 || (searchOperator.options.length >= 2 && searchOperator.options[2].value != "=="))) {
        for (i = searchOperator.options.length - 1; i >= 0 ; i--) searchOperator.options[i] = null;
        for (i = 0; i < alphaSearchOperators.length; i += 2)
          searchOperator.options[i / 2] = new Option(alphaSearchOperators[i], alphaSearchOperators[i + 1], false, false);
      }
      else if (splitValue[1] != "alpha" && (searchOperator.options.length < 2 || (searchOperator.options.length >= 2 && searchOperator.options[2].value != ">="))) {
        for (i = searchOperator.options.length - 1; i >= 0 ; i--) searchOperator.options[i] = null;
        for (i = 0; i < numberSearchOperators.length; i += 2)
          searchOperator.options[i / 2] = new Option(numberSearchOperators[i], numberSearchOperators[i + 1], false, false);
      }
    }
    searchOperator.value = searchOperatorValue;

    newInnerHTML2 = ""
    /*if (splitValue[1] == "date") {
      newInnerHTML1 = "<input kind='date' id='dbSearchValue1' class='small requiredNone' name=dbSearchValue1 type=text size=10 maxlength=64 onblur='Blur(this);' accesskey='S'>&nbsp;<a href=\"javascript:PopupCalendar('dbSearchValue1', GetX('icondbSearchValue1'), GetY('icondbSearchValue1') + 17);\"><img id='icondbSearchValue1' src='image/icon_calendar.gif' align=absmiddle width=20 height=16 title='Click here to select a Date'></a>";

      if (document.searchForm.searchOperator.value == "BETWEEN") {
        newInnerHTML2 = "&nbsp;and&nbsp;<input kind='date' id='dbSearchValue2' class='small requiredNone' name=dbSearchValue2 type=text size=10 maxlength=64 onblur='Blur(this);' accesskey='S'>&nbsp;<a href=\"javascript:PopupCalendar('dbSearchValue2', GetX('icondbSearchValue2'), GetY('icondbSearchValue2') + 17);\"><img id='icondbSearchValue2' src='image/icon_calendar.gif' align=absmiddle width=20 height=16 title='Click here to select a Date'></a>";
      }
      else oldSearchType2 = "";
    }*/
    newInnerHTML1 = "<input kind='" + splitValue[1] + "' id='dbSearchValue1' class='small requiredNone' name=dbSearchValue1 type=text size=12 maxlength=32 onblur='Blur(this);' accesskey='S'>";
    if (searchOperator.value == "BETWEEN") {
      newInnerHTML2 = "&nbsp;and&nbsp;<input kind='" + splitValue[1] + "' id='dbSearchValue2' class='small requiredNone' name=dbSearchValue2 type=text size=12 maxlength=32 onblur='Blur(this);' accesskey='S'>";
    }
    else oldSearchType2 = "";

    if (splitValue[1] != oldSearchType1) {
      document.getElementById("tdSearchValue1").innerHTML = newInnerHTML1;
      oldSearchType1 = splitValue[1];
    }
    if (splitValue[1] != oldSearchType2) {
      document.getElementById("tdSearchValue2").innerHTML = newInnerHTML2;
      oldSearchType2 = (newInnerHTML2 != "") ? splitValue[1] : "";
    }
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateCreditCard(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  ccTypeValue = IsMajorCreditCard(newValue);
  if (ccTypeValue == "") inputField.style.background = BadInput, returnValue = false;
  else inputField.style.background = White, returnValue = true;

  ccTypeLabelName = inputField.getAttribute("label");
  if (ccTypeLabelName) {
    if (ccTypeLabelName.match(/label/g))
      document.getElementById(ccTypeLabelName).innerHTML = ccTypeValue;
    else 
      document.getElementByName(ccTypeLabelName).value = ccTypeValue;
  }

  if (newValue.length == 15)
    inputField.value = Reformat(newValue, "", 4, "-", 6, "-", 5);
  else if (newValue.length > 12)
    inputField.value = Reformat(newValue, "", 4, "-", 4, "-", 4, "-", 4);
  else if (newValue.length > 8)
    inputField.value = Reformat(newValue, "", 4, "-", 4, "-", 4);
  else if (newValue.length > 4)
    inputField.value = Reformat(newValue, "", 4, "-", 4);

  return returnValue;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateDate(inputField, required) {
var daysInMonth = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var month, day, year;
var goodInput = false;

  if (!inputField) return false;

  inputField.value = StripCharsNotInBag(inputField.value, digits + " /-");
  if (!required && inputField.value == "") {
    inputField.style.background = White;
    return true;
  }

  inputText = inputField.value.replace(/[- ]/g, "/");
  splitInput = inputText.split("/");
  if (splitInput.length == 1 && (inputText.length == 8 || inputText.length == 6)) {
    inputText = inputText.substring(0, 2) + "/" + inputText.substring(2, 4) + "/" + inputText.substring(4, inputText.length);
    splitInput = inputText.split("/");
  }
  if(splitInput.length == 3) {
    month = parseInt(splitInput[0], 10);
    day = parseInt(splitInput[1], 10);
    year = parseInt(splitInput[2], 10);
    if (!isNaN(month) && !isNaN(day) && !isNaN(year)) {
      year = (year > 25 && year < 100) ? 1900 + year : (year > 0 && year <= 25) ? 2000 + year : year;
      goodInput = (month >= 1 && month <= 12) & (day >= 1 && day <= daysInMonth[month - 1]) &&
                  (month == 2 && day <= ((!(year % 100) && (year % 400)) || (year % 4)) ? 28 : 29);
    }
  }
  if (!goodInput) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    inputField.value = splitInput[0] + "/" + splitInput[1] + "/" + year;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateEmail(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, lowerCaseLetters + upperCaseLetters + digits + '.-_@', "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  if (!IsEmail(newValue)) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateForm(form) {
  if (form == null) return false;
  //if (form.submitButton) form.submitButton.disabled = true;
  for (var i = 0, n = 0, validInputs = 0; i < form.elements.length; i++) {
    if (form.elements[i].type.search(/text|password|textarea|select-one|select-multiple|radio/) > -1)
      validInputs += Blur(form.elements[i]), n++;
  }
  if (validInputs != n) {
    alert('All fields marked in yellow are invalid.\nPlease check and retry.\n\nAlso please make sure all the required fields are filled.');
    //if (form.submitButton) form.submitButton.disabled = false;
    return false;
  }
  if (window.AdditionalValidation && !AdditionalValidation(form)) {
    //if (form.submitButton) form.submitButton.disabled = false;
    return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateMonthYear(inputField, required) {
var goodInput = false;
var today = new Date();
var curMonth = today.getMonth() + 1;
var curYear  = today.getFullYear();

  if (!inputField) return false;

  inputField.value = StripCharsNotInBag(inputField.value, digits + "/-");
  if (!required && inputField.value == "") return true;

  inputText = inputField.value.replace(/-/g, "/");
  inputText = inputText.replace(/ /g, "/");
  splitInput = inputText.split("/");
  if (splitInput.length == 1) {
    if (inputText.length == 6) {
      inputText = inputText.substring(0, 2) + "/" + inputText.substring(2, 6);
      splitInput = inputText.split("/");
    }
    else if (inputText.length == 4) {
      inputText = inputText.substring(0, 2) + "/" + (2000 + parseInt(inputText.substring(2, 4), 10));
      splitInput = inputText.split("/");
    }
  }
  if(splitInput.length == 2) {
    month = parseInt(splitInput[0], 10);
    year = parseInt(splitInput[1], 10);
    year = (year >= 0 && year <= 99) ? 2000 + year : year;
    goodInput = !isNaN(month) && !isNaN(year) && ((year == curYear && month > curMonth && month <= 12) || (month > 0 && month <= 12 && year > curYear && year <= curYear + 25));
    if (!isNaN(month) && !isNaN(year) && month >= 1 && month <= 12)
      inputField.value = (month < 10 ? "0" + month : month) + "/" + year;
  }
  if (!goodInput) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateNumber(inputField, required, validChars, currency) {
var minimum = '', maximum = '';
var isDecimal;

  if (!inputField) return false;
  if (!validChars) validChars = "";

  ValidateString(inputField, required, validChars, "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  isDecimal = (validChars.search(/\./g) > 0);
  newValue = (newValue.substring(0, 1) == "-") ? "-" + StripCharsInBag(newValue.substring(1), "-") : StripCharsInBag(newValue, "-");

  if (isDecimal) {
    newValue = parseFloat(newValue);
    minimum = parseFloat(inputField.getAttribute('minimum'));
    maximum = parseFloat(inputField.getAttribute('maximum'));
    if (!isNaN(minimum) && newValue < minimum) newValue = minimum;
    if (!isNaN(maximum) && newValue > maximum) newValue = maximum;
  }
  else {
    newValue = parseInt(newValue, 10);
    minimum = parseInt(inputField.getAttribute('minimum'), 10);
    maximum = parseInt(inputField.getAttribute('maximum'), 10);
    if (!isNaN(minimum) && newValue < minimum) newValue = minimum;
    if (!isNaN(maximum) && newValue > maximum) newValue = maximum;
  }
  inputField.style.background = White;
  inputField.value = currency ? FormatCurrency(newValue) : newValue;
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidatePhone(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  if (newValue.length == 11 && newValue.substring(0, 1) == "1") newValue = newValue.substring(1);

  if (newValue.length > 5)
    inputField.value = (newValue.length <= 7) ? Reformat(newValue, "", 3, "-", 4) : Reformat(newValue, "", 3, "-", 3, "-", 4);

  if (newValue.length != 7 && newValue.length != 10) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateRadio(inputField, required) {
var i, radioArray;

  radioArray = (eval("inputField.form." + inputField.name));
  if (required) {
    for (i = 0; i < radioArray.length; i++)
      if (radioArray[i].checked) break;
    if (i == radioArray.length) {
      for (i = 0; i < radioArray.length; i++)
        document.getElementById(radioArray[i].name + i + "Back").className = 'bgBadInput';
      return false;
    }
    else {
      for (i = 0; i < radioArray.length; i++)
        document.getElementById(radioArray[i].name + i + "Back").className = 'bgRequired';
      return true;
    }
  }
  else
    return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateSelection(inputField, required) {
  if (!required) {
    inputField.style.background = White;
    return true;
  }
  else if (inputField.value == "" || inputField.value == "0") {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = SelectRequiredColor;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateSsn(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  inputField.value = Reformat(newValue, "", 3, "-", 2, "-", 4);
  if (newValue.length != 9) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateString(inputField, required, validChars, textCase) {
  if (!inputField) return false;
  if (!validChars) validChars = "";

  newValue = Trim(inputField.value);
  inputField.value = (newValue) ? Caps(StripCharsNotInBag(NeatCharsInBag(newValue, whiteSpace), validChars), textCase) : "";
  if (required && inputField.value == "") {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateText(inputField, required, list) {
  if (!inputField) return false;
  validChars = stringChars + "\n";

  newValue = Trim(inputField.value);
  if (list) newValue = NeatCharsInBag(NeatCharsInBag(newValue, " \t"), "\n\r", "\n");
  inputField.value = (newValue) ? StripCharsNotInBag(newValue, validChars) : "";
  if (required && inputField.value == "") {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateTime(inputField, required) {
var hours = -1, mins = 0, amPm;

  if (!inputField) return false;

  inputField.value = StripCharsNotInBag(inputField.value.toLowerCase(), digits + "apm-:");
  if (!required && inputField.value == "") return true;

  inputText = inputField.value;
  if (inputText.substr(inputText.length - 2, 2) == "am" || inputText.substr(inputText.length - 2, 2) == "pm")
    amPm = inputText.substr(inputText.length - 2, 2), inputText = inputText.substr(0, inputText.length - 2);

  inputText = inputField.value.replace(/[- ]/g, ":");
  splitInput = inputText.split(":");
  if (splitInput.length == 2) {
    hours = parseInt(splitInput[0], 10);
    mins = parseInt(splitInput[1], 10);
  }
  else {
    if (inputText.length <= 2) hours = parseInt(inputText, 10);
    else if (inputText.length <= 4) {
      hours = parseInt(inputText.substr(0, inputText.length - 2), 10);
      mins = parseInt(inputText.substr(inputText.length - 2, 2), 10);
    }
  }
  if (hours > 0 && hours < 24 && mins < 60) {
    if (hours < 13) inputText = hours + ":" + (mins < 10 ? "0" + mins : mins) + " " + (amPm ? amPm : "am");
    else inputText = (hours - 12) + ":" + (mins < 10 ? "0" + mins : mins) + " pm";

    inputField.style.background = White;
    inputField.value = inputText;
    return true;
  }
  else {
    inputField.style.background = BadInput;
    return false;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateUrl(inputField, required) {
  if (!inputField) return false;

  newValue = inputField.value;
  if (newValue.substr(0, 7) == "http://") newValue = newValue.substr(7);
  else if (newValue.substr(0, 6) == "http:/") newValue = newValue.substr(6);
  else if (newValue.substr(0, 5) == "http:") newValue = newValue.substr(5);
  inputField.value = newValue;

  ValidateString(inputField, required, lowerCaseLetters + upperCaseLetters + digits + '.,;-_~/#^?&=+|:', "none");
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  if (!IsUrl(newValue)) {
    inputField.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = White;
    return true;
  }
}

/*********************************************************************/
/**** ADDITIONAL FUNCTIONS *******************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CalculateChildID() {
  var url, subIndex;
  var returnInt;
  
  url = location.host + location.pathname;
  subIndex = url.indexOf('/');
  if (url.indexOf('/', subIndex + 1) > -1) subIndex = url.indexOf('/', subIndex + 1);
  url = url.substring(0, subIndex);
  for (i = 0, returnInt = 0; i < url.length; i++ ) returnInt += url.charCodeAt(i);
  return '' + returnInt + url.charCodeAt(url.length - 2) + url.charCodeAt(url.length - 1);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ChildWindow(url, width, height, scrollbars, resizable) {
  var childWindow;

  if (width < 200) width = 200;
  if (height < 180) height = 180;
  wLeft = parseInt(screen.width / 2 - width / 2, 10);
  wTop = parseInt(screen.height / 2 - height / 2, 10);
  scrollbars = (!scrollbars || scrollbars != '1') ? 0 : 1;
  resizable = (!resizable || resizable != '1') ? 0 : 1;
  eval("childWindow = childWindowLibraryDM_" + ChildID);
  if (childWindow && childWindow.open) childWindow.close();
  eval("childWindowLibraryDM_" + ChildID + " = window.open(url, 'childWindowLibraryDM_" + ChildID + "', 'location=0,toolbar=0,menubar=0,resizable=" + resizable + ",status=0,scrollbars=" + scrollbars + ",width=" + width + ",height=" + height + ",left=" + wLeft + ",top=" + wTop + "')");
  eval("childWindowLibraryDM_" + ChildID + ".focus()");
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CloseChildWindow() {
var childWindowObject;

  eval("childWindowObject = childWindowLibraryDM_" + ChildID);
  if (childWindowObject && childWindowObject.open) childWindowObject.close();
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CloseHelpBar() {
  if (document.getElementById('helpBar')) document.getElementById('helpBar').style.visibility = 'hidden';
  location.href = location.href;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function Property(objectName, propertyName, propertyValue, notString) {
var object;

  if (IsEmpty(objectName) || IsEmpty(propertyName)) return null;

  object = document.getElementById(objectName);
  if (!object) return null;
  if (propertyValue != null) eval("object." + propertyName + (notString ? " = " + propertyValue : " = \"" + propertyValue + "\""));
  return eval("object." + propertyName);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ShowHelp(element, focus) {
var kind, helpObject, finalHelp;
var elementHelp = "", elementDefaultHelp = "", requiredHelp = "";

  helpObject = document.getElementById('dmHelpPane');
  if (!helpObject) return false;

  if (element) {
    elementHelp = element.getAttribute("help");
    if (elementHelp == null) elementHelp = "";
    if (element.className && element.className.match(/required/i)) requiredHelp = "<p class='red bold bottomSpace'>Required Field.<br></p>";
    kind = "" + element.getAttribute("kind");
    switch (kind) {
      case "alpha": elementDefaultHelp = ""; break;
      case "amount": elementDefaultHelp = ""; break;
      case "credit": elementDefaultHelp = ""; break;
      case "date": elementDefaultHelp = ""; break;
      case "decimal": elementDefaultHelp = ""; break;
      case "email": elementDefaultHelp = ""; break;
      case "monthyear": elementDefaultHelp = ""; break;
      case "number": elementDefaultHelp = ""; break;
      case "password": elementDefaultHelp = ""; break;
      case "phone": elementDefaultHelp = ""; break;
      case "radio": elementDefaultHelp = ""; break;
      case "select": elementDefaultHelp = ""; break;
      case "ssn": elementDefaultHelp = ""; break;
      case "string": elementDefaultHelp = ""; break;
      case "text": elementDefaultHelp = ""; break;
      case "textList": elementDefaultHelp = ""; break;
      case "time": elementDefaultHelp = ""; break;
      case "url": elementDefaultHelp = ""; break;
      case "username": elementDefaultHelp = ""; break;
      case "zip": elementDefaultHelp = ""; break;
      default: break;
    }
  }
  elementDefaultHelp = "";
  if (!focus) finalHelp = defaultHelp;
  else {
    if (elementHelp) finalHelp = requiredHelp + elementHelp + (elementDefaultHelp ? '<br><br>' + elementDefaultHelp : "");
    else {
      if (elementDefaultHelp) finalHelp = requiredHelp + elementDefaultHelp;
      else finalHelp = requiredHelp;
    }
  }
  finalHelp = finalHelp.replace(/<BR>/g, "<p class='topSpace'></p>");
  finalHelp = finalHelp.replace(/<HR>/g, "<p class='borderTop borderDark bottomSpace'><img src='LibraryDM/empty.gif' width=100% height=1></p>");
  helpObject.innerHTML = finalHelp;
}