var Darkest = "#3d434c";
var Dark = "#5b6471";
var Medium = "#b2b8c1";
var Light = "#e2e5e8";
var Lightest = "#f7f7f7";
var Orange = "#ffcc33";
var White = "#ffffff";
var Black = "#000000";
var BadInput = "#ffffbb";
var SelectRequiredColor = "#fff7f7";

var digits = "0123456789";
var lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
var upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var idChars = lowerCaseLetters + upperCaseLetters + digits + "-";
var alphaChars = lowerCaseLetters + upperCaseLetters + digits + " .-_&";
var stringChars = alphaChars + ",?/<>;:'[]!@#$%&*()+=\"";
var whiteSpace = " \t\n\r";
var decimalPointDelimiter = ".";
var daysInMonth = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var defaultHelp = "Please move mouse onto one of the options to get additional help.";
var alphaDefaultHelp = "General Information:<br><HR><i>Valid characters:</i><br> [A-Z][a-z][0-9][.-_ ]<br><p class='spaceTop'><i>Examples:</i>"

var childWindow;

var ApplicationName;

var IsIE = navigator.userAgent.search(/MSIE/g) > 0;

/**** TEST AND VALIDATE FUNCTIONS ************************************/
// IsAlpha (s)
// IsAlphaNumeric (s)
// IsAmericanExpress(s)
// IsDate (month, day, year)
// IsDecimal (s)
// IsDiscover(s)
// IsEmail(s)
// IsEmpty(s)
// IsInsideBox(x, y, boxX, boxY, boxW, boxH)
// IsInteger (s)
// IsIntegerInRange (s, a, b)
// IsMajorCreditCard(s)
// IsMasterCard(s)
// IsUrl(s)
// IsValidCreditCard(s, clean)
// IsVisa(s)

/**** FORMATTING FUNCTIONS *******************************************/
// Caps(s, allCaps)
// CutString (s, length, dots)
// FormatCurrency(num, dollar)
// FirstCharInBag (s, bag)
// NeatCharsInBag (s, bag, replaceChar)
// Reformat (s)
// StripCharsInBag (s, bag)
// StripCharsNotInBag (s, bag)
// ToggleImage (imageID, newSrc)
// Trim(s)

/**** USER INPUT FUNCTIONS **********************************/
// Blur(element)
// BlurForm(form)
// SetInputMin(inputFieldName, min)
// SetInputMax(inputFieldName, max)
// SetInputRange(inputFieldName, min, max)
// 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, allCaps)
// ValidateText(inputField, required, list)
// ValidateTime(inputField, required)
// ValidateUrl(inputField, required)
//Checkemail(inputField)

/**** ADDITIONAL FUNCTIONS *******************************************/
// ChildWindow(url, width, height, scroll)
// DateDiff(interval, start, end, rounding )
// HeaderHigh(tdName, on)
// MakeItemSelected(formName, selectName, value, textOrValue)
// Property(objectName, propertyName, propertyValue, notString)
// ShowHelp(s)

/**** CALENDAR FUNCTIONS *********************************************/
// PopupCalendarShow(formElementName, type, cMonth, cYear, x, y, parameter)
// PopupCalendarHide(force)
// PopupCalendar(formElementName, x, y)
// PopupCalendarReturn(formElementName, cMonth, cDay, cYear)

/*********************************************************************/
/**** TEST AND VALIDATE FUNCTIONS ************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
// IsAlpha(s)
//  - Tests whether the given string is an alphabet (upper or lowercase)
///////////////////////////////////////////////////////////////////////
function IsAlpha (s) {
  if (IsEmpty(s)) return false;

  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (!(c >= "a" && c <= "z") || (c >= "A" && c <= "Z")) return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////
// IsAlphaNumeric(s)
//  - Tests whether the given string is an alphabet (upper or lowercase)
 //   or a digit or "_" or "-" or "."
///////////////////////////////////////////////////////////////////////
function IsAlphaNumeric (s) {
  if (IsEmpty(s)) return false;

  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (!((c >= "a" && c <= "z") || (c >= "A" && c <= "Z") || (c >= "0" && c <= "9") || c == "_" || c == "-" || c == ".")) return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
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 IsDate (month, day, year) {
var today = new Date();

  if (IsEmpty(year)) year = "" + today.getFullYear();
  if (!(IsInteger(year) && (year.length == 2 || year.length == 4)
      && IsIntegerInRange(month, 1, 12) && IsIntegerInRange (day, 1, 31))) return false;

    var intYear = parseInt(year, 10);
    var intMonth = parseInt(month, 10);
    var intDay = parseInt(day, 10);
    if (intDay > daysInMonth[intMonth - 1]) return false;
    if (intMonth == 2 && intDay > (!(year % 100 == 0) && (year % 4 == 0 || year % 400 == 0) ? 29 : 28)) return false;

    return true;
}

///////////////////////////////////////////////////////////////////////
// IsDecimal(s)
//  - Tests whether the given string is an alphabet (upper or lowercase)
///////////////////////////////////////////////////////////////////////
function IsDecimal (s) {
var i;
var decimalPointPresent = false;

  if (IsEmpty(s)) return false;

  if (s == decimalPointDelimiter) return false;

  var startPos = (s.charAt(0) == "-" || s.charAt(0) == "+") ? 1 : 0;
  for (var i = startPos; i < s.length; i++) {   
    var c = s.charAt(i);
    if ((c == decimalPointDelimiter) && !decimalPointPresent) decimalPointPresent = true;
    else if (!(c >= "0" && c <= "9")) return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
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 IsInsideBox(x, y, boxX, boxY, boxW, boxH) {
  return (x >= boxX && x <= boxX + boxW && y >= boxY && y <= boxY + boxH);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsInteger(s) {
var i;

  if (IsEmpty(s)) return false;

  var startPos = (s.charAt(0) == "-" || s.charAt(0) == "+") ? 1 : 0;
  for (var i = startPos; i < s.length; i++) {   
    var c = s.charAt(i);
    if (!(c >= "0" && c <= "9")) return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function IsIntegerInRange (s, a, b) {
  if (IsEmpty(s) || a == null || b == null) return false;
  if (!IsInteger(s, false)) return false;

  var num = parseInt (s, 10);
  return ((num >= parseInt(a, 10)) && (num <= parseInt(b, 10)));
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
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, allCaps) {
  if (IsEmpty(s)) return "";
  if (s) {
  	s = NeatCharsInBag(s, whiteSpace);
    if (allCaps && allCaps != -1) s = s.toUpperCase();
    else if(allCaps != -1) {
      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 FirstCharInBag (s, bag) {
var i;

  if (IsEmpty(s) || IsEmpty(bag)) return "";
  for (var i = 0; i < s.length; i++) {   
    if (bag.indexOf(s.charAt(i)) != -1) return s.charAt(i);
  }
 
  return "";
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
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;

  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); break;
      case "amount": returnValue = ValidateNumber(element, required, digits + '.-', 1); break;
      case "creditCard": 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 "checkmail":returnValue=Checkemail(element);break;
      case "id": returnValue = ValidateString(element, required, idChars, 1); break;
      case "monthYear": returnValue = ValidateMonthYear(element, required); break;
      case "number": returnValue = ValidateNumber(element, required, digits + '-'); break;
      case "password": returnValue = ValidateString(element, required, alphaChars, -1); 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 "state": returnValue = ValidateString(element, required, alphaChars, 1); break;
      case "string": returnValue = ValidateString(element, required, stringChars); 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 + '.-_', -1); break;
      case "zip": returnValue = ValidateString(element, required, digits + ' -', 1); break;
      case "url": returnValue = ValidateUrl(element, required); break;
      default: returnValue = true;
    }
  }
  eval("if (window." + element.name + "Blur) " + element.name + "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]);
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function SetInputMin(inputFieldName, min) {
var inputField;

  inputField = document.getElementById(inputFieldName);
  if (!inputField || (min && isNaN(min))) return;
  else inputField.setAttribute('range', min + '|-', 0);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function SetInputMax(inputFieldName, max) {
var inputField;

  inputField = document.getElementById(inputFieldName);
  if (!inputField || (max && isNaN(max))) return;
  else inputField.setAttribute('range', '-|' + max, 0);
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function SetInputRange(inputFieldName, min, max) {
var inputField;

  inputField = document.getElementById(inputFieldName);
  if (!inputField || (min && isNaN(min) && max && isNaN(max))) return;
  else {
    if (isNaN(min)) min = '-';
    if (isNaN(max)) max = '-';
    if (min != '-' && max != '-' && min > max) swap = max, max = min, min = swap;
    inputField.setAttribute('range', min + '|' + max, 0);
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateCreditCard(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, -1);
  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 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) {
    year = parseInt(splitInput[2], 10);
    if (!isNaN(year)) {
      year = (year > 25 && year < 100) ? 1900 + year : (year > 0 && year < 25) ? 2000 + year : year;
      goodInput = IsDate(splitInput[0], splitInput[1], year.toString());
    }
  }
  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 + '.-_@', -1);
  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) {
  if (!inputField) return false;
  if (!validChars) validChars = "";

  ValidateString(inputField, required, validChars);
  newValue = inputField.value;
  if (newValue == "") return (required ? false : true);

  newValue = (newValue.substring(0, 1) == "-") ? "-" + StripCharsInBag(newValue.substring(1), "-") : StripCharsInBag(newValue, "-");
  newValue = (validChars.search(/\./g) > 0) ? parseFloat(newValue) : parseInt(newValue, 10);
  if (inputField.getAttribute('range')) {
    minMax = inputField.getAttribute('range').split(/\|/);
    if (minMax[0] != '-' && minMax[1] != '-') {
      if (newValue < parseInt(minMax[0])) newValue = parseInt(minMax[0]);
      else if (newValue > parseInt(minMax[1])) newValue = parseInt(minMax[1]);
    }
    else if (minMax[0] != '-') {
      if (newValue < parseInt(minMax[0])) newValue = parseInt(minMax[0]);
    }
    else {
      if (newValue > parseInt(minMax[1])) newValue = parseInt(minMax[1]);
    }
  }
  inputField.style.background = White;
  inputField.value = currency ? FormatCurrency(newValue) : newValue;
  return true;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidatePhone(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, -1);
  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.style.background = BadInput;
    return false;
  }
  else {
    inputField.style.background = SelectRequiredColor;
    return true;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ValidateSsn(inputField, required) {
  if (!inputField) return false;

  ValidateString(inputField, required, digits, -1);
  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, allCaps) {
  if (!inputField) return false;
  if (!validChars) validChars = "";

  newValue = Trim(inputField.value);
  inputField.value = (newValue) ? Caps(StripCharsNotInBag(NeatCharsInBag(newValue, whiteSpace), validChars), allCaps) : "";
  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 + '.,;-_~/#^?&=+|:', -1);
  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 ChildWindow(url, width, height, scroll) {
  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);
  if (!scroll || scroll != '1') scroll = 0;
  else scroll = 1;
  eval("childWindowObject = childWindow" + ApplicationName);
  if (eval("childWindow" + ApplicationName + " && childWindow" + ApplicationName + ".open")) eval("childWindow" + ApplicationName + ".close()");
  eval("childWindow" + ApplicationName + " = window.open(url, 'childWindow" + ApplicationName + "', 'location=0,toolbar=0,menubar=0,resizable=0,status=0,scrollbars=" + scroll + ",width=" + width + ",height=" + height + ",left=" + wLeft + ",top=" + wTop + "')");
  eval("childWindow" + ApplicationName + ".focus()");
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CloseChildWindow(url) {
var childWindowObject;
  eval('childWindowObject = childWindow' + ApplicationName);
  if (childWindowObject && childWindowObject.open) {
    if (url == 'reload') opener.location.href = opener.location.href;
    else if (url) opener.location.href = url;
    childWindowObject.close();
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function CloseHelpBar() {
  if (document.getElementById('helpBar')) document.getElementById('helpBar').style.visibility = 'hidden';
  location.href = location.href;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function DateDiff(interval, start, end) {
  var iOut = 0;
  
  var bufferA = Date.parse(start);
  var bufferB = Date.parse(end);
    
  if (isNaN(bufferA) || isNaN(bufferB)) return 0;

  var number = bufferB - bufferA;
  
  switch (interval.charAt(0))
  {
    case 'h':
      iOut = parseInt(number / 3600000, 10) + parseInt((number % 3600000) / 1800001, 10);
      break;
    case 'm':
      iOut = parseInt(number / 60000, 10) + parseInt((number % 60000) / 30001, 10);
      break;
    case 's':
      iOut = parseInt(number / 1000, 10) + parseInt((number % 1000) / 501, 10);
      break;
    default:
      iOut = parseInt(number / 86400000, 10) + parseInt((number % 86400000) / 43200001, 10);
      break;
  }
  return iOut;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function GetX(objName) {
var object = typeof objName == "object" ? objName : document.getElementById(objName);

	for (var sumLeft = 0; object != document.body; sumLeft += object.offsetLeft, object = object.offsetParent);
	return sumLeft;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function GetY(objName) {
var object = typeof objName == "object" ? objName : document.getElementById(objName);

  for (var sumTop = 0; object != document.body; sumTop += object.offsetTop, object = object.offsetParent);
	return sumTop;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function HeaderHigh(tdName, on) {
  tdTop = document.getElementById("headerTD" + tdName);
  tdBottom = document.getElementById("headerBottomTD" + tdName);
  if (on) tdTop.style.background = Lightest, tdBottom.style.background = Orange;
  else tdTop.style.background = Light, tdBottom.style.background = Medium;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function MakeItemSelected(formName, selectName, value, textOrValue) {
var selectObject;

  if (IsEmpty(formName) || IsEmpty(selectName)) return;
  if (textOrValue != "value") textOrValue = "text";

  selectObject = eval('document.' + formName + '.' + selectName);
  for (var i = 0; i < selectObject.options.length; i++) {
    if ((textOrValue == "value" && selectObject.options[i].value == value) || (textOrValue == "text" && selectObject.options[i].text == value)) {
      selectObject.options[i].selected = true;
      break;
    }
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
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 ShowCalendarDetail(detailStr) {
var calendarDetailObject;

  calendarDetailObject = document.getElementById('calendarDetailPane');
  if (!calendarDetailObject) return;

  calendarDetailObject.innerHTML = detailStr.replace(/<HR>/g, "<p class=bottomSpace><img src='image/dot_dark.gif' width=100% height=1></p>");
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function ShowHelp(element, focus) {
var kind, helpObject, finalHelp;
var elementHelp = "", elementDefaultHelp = "", requiredHelp = "";

  helpObject = document.getElementById('helpPane');
  if (!helpObject) return;

  if (eval("window." + element.id + "Help")) eval("elementHelp = " + element.id + "Help");

  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 = alphaDefaultHelp; break;
    case "amount": elementDefaultHelp = "amount"; break;
    case "creditCard": elementDefaultHelp = "creditCard"; break;
    case "date": elementDefaultHelp = "date"; break;
    case "decimal": elementDefaultHelp = "decimal"; break;
    case "email": elementDefaultHelp = "email"; break;
    case "id": elementDefaultHelp = "id"; break;
    case "list": elementDefaultHelp = "list"; break;
    case "monthYear": elementDefaultHelp = "monthYear"; break;
    case "number": elementDefaultHelp = "number"; break;
    case "password": elementDefaultHelp = "password"; break;
    case "phone": elementDefaultHelp = "phone"; break;
    case "radio": elementDefaultHelp = "radio"; break;
    case "select": elementDefaultHelp = "select"; break;
    case "ssn": elementDefaultHelp = "ssn"; break;
    case "state": elementDefaultHelp = "state"; break;
    case "string": elementDefaultHelp = "string"; break;
    case "text": elementDefaultHelp = "text"; break;
    case "textList": elementDefaultHelp = "textList"; break;
    case "time": elementDefaultHelp = "time"; break;
    case "username": elementDefaultHelp = "username"; break;
    case "zip": elementDefaultHelp = "zip"; break;
    case "url": elementDefaultHelp = "url"; break;
    default: break;
  }

  if (!focus) finalHelp = defaultHelp;
  else {
    if (elementHelp) finalHelp = requiredHelp + elementHelp + (elementDefaultHelp ? '<br><br>' + elementDefaultHelp : "");
    else {
      if (elementDefaultHelp) finalHelp = requiredHelp + elementDefaultHelp;
      else finalHelp = "No help is associated with this item.";
    }
  }
  helpObject.innerHTML = finalHelp.replace(/<HR>/g, "<p class=bottomSpace><img src='image/dot_dark.gif' width=100% height=1></p>");
}

/*********************************************************************/
/**** CALENDAR FUNCTIONS *********************************************/
/*********************************************************************/
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
var closePopupCalendar;

function PopupCalendar(formElementName, x, y, parameter, cMonth, cYear) {
var showType, tagName;

  if (formElementName == "Initiate") {
    if (IsIE) document.write ("<iframe id='calendarBackLayer' frameborder=0 scrolling=no style='visibility:hidden; position:absolute; z-index:100'></iframe>");
    document.write ("<div id='calendarLayer' kind='calendarLayer' style='visiblity:hidden; position:absolute; top:0px; left:0px; z-index=101;'></div>");
    return;
  }
  if (!document.getElementById('calendarLayer')) return;
  if (y < 0) y = 0;
  showType = (parameter == "noDay") ? "Year" : "Month";

  tagName = document.getElementById(formElementName).tagName;
  if (tagName == "SELECT") {
    prefix = formElementName.substring(0, formElementName.search(/Month/g));
    if (prefix != "") {
      cMonth = document.getElementById(prefix + "Month").value;
      cYear = document.getElementById(prefix + "Year").value;
      PopupCalendarShow(formElementName, showType, cMonth, cYear, x, y, parameter);
    }
  }
  else if (tagName == "INPUT") {
    inputField = document.getElementById(formElementName);
    ValidateDate(inputField);
    if (inputField && !IsEmpty(inputField.value) && inputField.style.background != BadInput) {
      splitInput = inputField.value.split("/");
      PopupCalendarShow(formElementName, showType, splitInput[0], splitInput[2], x, y, parameter);
    }
    else PopupCalendarShow(formElementName, showType, (new Date().getMonth()) + 1, new Date().getFullYear(), x, y, parameter);
  }
  else if (tagName == "A") {
    if (cMonth && cYear)
      PopupCalendarShow(formElementName, showType, cMonth, cYear, x, y, parameter);
    else
      PopupCalendarShow(formElementName, showType, (new Date().getMonth()) + 1, new Date().getFullYear(), x, y, parameter);
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function PopupCalendarHide() {
  cObj = document.getElementById('calendarLayer');
  cbObj = document.getElementById('calendarBackLayer');
  if (cObj && cObj.style.visibility == "visible") {
    if (!closePopupCalendar) { closePopupCalendar = true; return; }
    cObj.style.left = 0;
    cObj.style.top = 0;
    cObj.style.visibility = 'hidden';
    if (cbObj) {
      cbObj.style.left = 0;
      cbObj.style.top = 0;
      cbObj.style.visibility = 'hidden';
    }
    cObj.innerHTML = "";
    document.onmousedown = null;
  }
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function PopupCalendarReturn(formElementName, cMonth, cDay, cYear) {
var tagName;

  tagName = document.getElementById(formElementName).tagName;
  if (tagName == "SELECT") {
    prefix = formElementName.substring(0, formElementName.search(/Month/g));
    if (prefix != "") {
      if (document.getElementById(prefix + "Month")) document.getElementById(prefix + "Month").value = cMonth;
      if (document.getElementById(prefix + "Day")) document.getElementById(prefix + "Day").value = cDay;
      if (document.getElementById(prefix + "Year")) document.getElementById(prefix + "Year").value = cYear;
    }
  }
  else if (tagName == "INPUT") {
    inputField = document.getElementById(formElementName);
    if (inputField) inputField.value = cMonth + "/" + cDay + "/" + cYear;
    Blur(inputField);
  }
  else if (tagName == "A") {
    anchorElement = document.getElementById(formElementName);
    if (anchorElement && anchorElement.getAttribute('url')) {
      url = anchorElement.getAttribute('url');
      document.location.href = url + ((url.search(/\?/g) > -1) ? "&" : "?") + "date=" + cMonth + "/" + cDay + "/" + cYear;
    }
  }
  closePopupCalendar = true;
  PopupCalendarHide();
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function PopupCalendarShow(formElementName, type, cMonth, cYear, x, y, parameter) {
  var daysOfMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
  var monthName = ["January","February","March","April","May","June","July","August","September","October","November","December"];
  var weekDay = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  var minYear = 2000;
  var maxYear = 2025;

  cMonth = parseInt(cMonth, 10) - 1;
  cYear = parseInt(cYear);
  if (cYear == "") cYear = minYear;
  if (cYear < minYear || cYear > maxYear) return;
  if (type != "Year" && type != "Years") type = "Month";
  parameterStr = (parameter) ? ", '" + parameter + "'" : "";

  function GetHTML(cMonth, cYear, type) {
    var today = new Date();

    if (type == "Month") {
      var vDate = new Date();
      vDate.setDate(1);
      vDate.setMonth(cMonth);
      vDate.setFullYear(cYear);
      var vFirstDay = vDate.getDay();
      var vDay = 1;
      var vLastDay = LastDay(cMonth, cYear);

      if (cMonth == 0) var pLastDay = 31;
      else var pLastDay = LastDay(cMonth - 1, cYear);

      var vOnLastDay = 0;
      var pDays = pLastDay - vFirstDay;
      var vCode = "";

      for (i = 0; i < vFirstDay; i++, pDays++) vCode += (vCode ? "|" : "") + pDays;
      for (i = vFirstDay; i < 7; i++, vDay++) vCode += (vCode ? "|" : "") + vDay;
      vCode += "\n";
      for (i = 2; i < 7; i++) {
        for (j = 0; j < 7; j++) {
          vCode += (j != 0 ? "|" : "") + vDay;
          vDay ++;
          if (vDay > vLastDay) { vOnLastDay = 1; break; }
        }
        if (j == 7) vCode = vCode + "\n";
        if (vOnLastDay == 1) break;
      }
      for (i = 1; i < (7 - j); i++) vCode += "|" + i;

      pMonth = (cMonth + 11) % 12;
      pYear = (pMonth == 11) ? cYear - 1 : cYear;
      nMonth = (cMonth + 1) % 12;
      nYear = (nMonth == 0) ? (cYear + 1) : cYear;
    }
    else if (type == "Years") {
      cYear = minYear + parseInt((cYear - minYear) / 9) * 9;
    }

    code  = "<table class='border borderDark bgLightest' width=172 onMouseDown='javascript:closePopupCalendar=false;'>";
    code += "<tr>";
    code += "  <td align=center>";
    code += "    <table align=center width=152>";
    code += "    <tr height=25>";
    code += "      <td class=bold width=136>";
    if (type == "Month") {
      code += "        <a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Month', " + (pMonth + 1) + ", " + pYear + ", " + x + ", " + y + parameterStr + ");\" title='Previous Month'><img src='image/arrows_left.gif'></a>&nbsp;&nbsp;&nbsp;";
      code += "<a class=under href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Year', 0, " + cYear + ", " + x + ", " + y + parameterStr + ");\" title='Show Full Year'>" + monthName[cMonth].substr(0, 3) + " " + cYear + "</a>&nbsp;&nbsp;&nbsp;";
      code += "<a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Month', " + (nMonth + 1) + ", " + nYear + ", " + x + ", " + y + parameterStr + ");\" title='Next Month'><img src='image/arrows_right.gif'></a>";
    }
    else if (type == "Year") {
      code += "        <a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Year', 0, " + (cYear - 1) + ", " + x + ", " + y + parameterStr + ");\" title='Previous Year'><img src='image/arrows_left.gif'></a>&nbsp;&nbsp;&nbsp;";
      code += "<a class=under href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Years', 0, " + cYear + ", " + x + ", " + y + parameterStr + ");\" title='Show All Years'>Year " + cYear + "</a>&nbsp;&nbsp;&nbsp;";
      code += "<a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Year', 0, " + (cYear + 1) + ", " + x + ", " + y + parameterStr + ");\" title='Next Year');\"><img src='image/arrows_right.gif'></a>";
    }
    else if (type == "Years") {
      code += "        <a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Years', 0, " + (cYear - 9) + ", " + x + ", " + y + parameterStr + ");\" title='Previous 9 years'><img src='image/arrows_left.gif'></a>&nbsp;&nbsp;";
      code += cYear + " - " + (cYear + 8) + "&nbsp;&nbsp;";
      code += "<a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Years', 0, " + (cYear + 9) + ", " + x + ", " + y + parameterStr + ");\" title='Next 9 years'><img src='image/arrows_right.gif'></a>";
    }
    code += "      </td>";
    code += "      <td align=right><a href='javascript:closePopupCalendar=true; PopupCalendarHide();' title='Click here to close'><img src='image/icon_close.gif' width=14 height=13></a><img src='image/empty.gif' width=1 height=1></td>";
    code += "    </tr>";
    code += "    <tr>";
    code += "      <td colspan=3 align=center class=box>";
    code += "        <table class='border borderMedium bgWhite' width=152>";
                      if (type == "Month") {
                        code += "        <tr>";
                        code += "          <td class=pad width=15% align=center>S</td>";
                        code += "          <td class=pad width=14% align=center>M</td>";
                        code += "          <td class=pad width=14% align=center>T</td>";
                        code += "          <td class=pad width=14% align=center>W</td>";
                        code += "          <td class=pad width=14% align=center>T</td>";
                        code += "          <td class=pad width=14% align=center>F</td>";
                        code += "          <td class=pad width=15% align=center>S</td>";
                        code += "        </tr>";
                        code += "        <tr height=1>";
                        code += "          <td style='padding:0px 2px 0px 2px;' colspan=7><img src='image/dot_medium.gif' width=100% height=1></td>";
                        code += "        </tr>";
                        weeks = vCode.split("\n");
                        for (i = 0; i < weeks.length; i++) {
                          days = weeks[i].split("|");
                          code += "        <tr>";
                          for (j = 0; j < days.length; j++) {
                            var iDay = parseInt(days[j], 10)
                            if ((i == 0 && iDay > 7) || (i == weeks.length - 1 && iDay < 7)) {
                              code += "          <td class='border borderLight pad medium small' align=center>" + iDay + "</td>";
                            }
                            else {
                              if (cMonth == today.getMonth() && iDay == today.getDate() && cYear == today.getFullYear())
                                code += "          <td class='border borderLight small' align=center bgcolor=#fffae0>";
                              else
                                code += "          <td class='border borderLight pad small' align=center>";
                              code += "            <a href=\"javascript:PopupCalendarReturn('" + formElementName + "', " + (cMonth + 1) + ", " + iDay + ", " + cYear + ");\">" + iDay + "</a>";
                              code += "          </td>";
                            }
                          }
                          code += "        </tr>";
                        }
                      }
                      else if (type == "Year") {
                        for (i = 0; i < 4; i++) {
                          code += "        <tr>";
                          for (j = 0; j < 3; j++) {
                            code += "          <td class='pad small border borderLight' align=center height=27>";
                            if (parameter == "noDay")
                              code += "            <a href=\"javascript:PopupCalendarReturn('" + formElementName + "', " + (i * 3 + j + 1) + ", 1, " + cYear + ");\">" + monthName[i * 3 + j].substr(0, 3) + "</a>"
                            else
                              code += "            <a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Month', " + (i * 3 + j + 1) + ", " + cYear + ", " + x + ", " + y + parameterStr + ");\">" + monthName[i * 3 + j].substr(0, 3) + "</a>";
                            code += "          </td>";
                          }
                          code += "        </tr>";
                        }
                      }
                      else if (type == "Years") {
                        for (i = 0; i < 3; i++) {
                          code += "        <tr>";
                          for (j = 0; j < 3; j++) {
                            if ((cYear + i * 3 + j) > maxYear) {
                              code += "          <td class='pad medium small' align=center>" + (cYear + i * 3 + j) + "</td>";
                            }
                            else {
                              code += "          <td class='pad small border borderLight' align=center height=36>";
                              code += "            <a href=\"javascript:PopupCalendarShow('" + formElementName + "', 'Year', 0, " + (cYear + i * 3 + j) + ", " + x + ", " + y + parameterStr + ");\">" + (cYear + i * 3 + j) + "</a>";
                              code += "          </td>";
                            }
                          }
                          code += "        </tr>";
                        }
                      }
    code += "        </table>";
    code += "      </td>";
    code += "    </tr>";
    code += "    <tr><td class=pad colspan=3 align=center>Today:<a class=under href=\"javascript:PopupCalendarReturn('" + formElementName + "', " + (today.getMonth() + 1) + ", " + today.getDate() + ", " + today.getFullYear() + ");\">" + weekDay[today.getDay()] + ", " + monthName[today.getMonth()].substr(0, 3) + " " + today.getDate() + "</a></td></tr>";
    code += "    </table>";
    code += "    <img src='image/empty.gif' width=1 height=2><br>";
    code += "  </td>";
    code += "</tr>";
    code += "</table>";
    return code;
  }

  function LastDay(cMonth, cYear) {
    if (cMonth == 1 && !(cYear % 4) && ((cYear % 100) || !(cYear % 400))) return daysOfMonth[cMonth] + 1;
    return daysOfMonth[cMonth];
  }

  var code = GetHTML (cMonth, cYear, type);
  var cObj = document.getElementById('calendarLayer');
  var cbObj = document.getElementById('calendarBackLayer');
  cObj.style.left = x;
  cObj.style.top = y;
  cObj.style.width = 172;
  cObj.style.visibility = 'visible';
  if (cbObj) {
    cbObj.style.left = x;
    cbObj.style.top = y;
    cbObj.style.width = 172;
    cbObj.style.height = 74 + (weeks.length * 21);
    cbObj.style.visibility = 'visible';
  }

  cObj.innerHTML = code;
  document.onmousedown = PopupCalendarHide;
  closePopupCalendar = true;
}
//////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
function Checkemail(o){
	if(typeof(o)=="object")
		{
			trim(o);
			emailStr=o.value;
		}
	else
		{
			emailStr=trim(o);
		}	
	if(emailStr!="")
	{
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		
		var matchArray=emailStr.match(emailPat)		
		if (matchArray==null) {
		alert("Email address is invalid (check @ and .'s)")
		if(typeof(o)=="object")
		o.focus();
		return false
	    }
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) {
	    alert("Email - Username doesn't seem to be valid.")
	    if(typeof(o)=="object")
	    o.focus();
	    return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null){
	      for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Email - Destination IP address is invalid!")
		        if(typeof(o)=="object")
		        o.focus();
				return false
		    }
	    }
	    return true
	  }
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email - Domain name doesn't seem to be valid.")
		if(typeof(o)=="object")
		o.focus();
	
	
	return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   alert("Email address must end in a three letter domain or two letter country.")
	   if(typeof(o)=="object")
	   o.focus();
	   return false
	}
	if (len<2) {
	   var errStr="Email - address is missing a hostname!"
	   alert(errStr)
	   if(typeof(o)=="object")
	   o.focus();
	   return false
	}
	if(isEmail(emailStr)==false)
		{
			alert("Email address is invalid");
			if (typeof(o)=="object")
			{
				o.focus();
				o.select();
			}
			return false;
		}
  }
return true;
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function trim(o)
{
	var val=(typeof(o)=="object")?o.value:o;
	while(val.indexOf("  ")>0)
	val=val.replace("  "," ");	
	while(val.charAt(0)==" ")
	val=val.slice(1);
	while(val.charAt(val.length-1)==" ")
	val=val.slice(0,-1);
	if (typeof(o)=="object")
		o.value=val;
	else
		return val;
}



