//
// More reliable than getElementById?
// ----------------------------------------------
//
function getElement(elemName)
{
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[elemName] : document[elemName];
}

//
// FLASH ExternalAPI methods ref: http://livedocs.macromedia.com/flash/8/main/00001600.html
// ----------------------------------------------------------------------------------------------------------------------------
//
function flash_SetURL(playerName, str)
{
  //var player = getElementById(playerName);
  var player = getElement(playerName);
  player.exURL(str);
	
}

//
// Flash Player Setup
// -----------------------
//
function Player_Setup()
{
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '0',
			'height', '0',
			'src', 'birthday_music',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'birthday_music',
			'bgcolor', '#ffffff',
			'name', 'birthday_music',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','always',
			'movie', 'birthday_music',
			'salign', ''
			); //end AC code
	}
}


//
// alertIfElementsNotEqualById
// ---------------------------------------
// Id1:  Id Of 1st Element
// Id2:  Id Of 2nd Element
// Message: Alert Message
//
// Description:  Alerts If Field Values Are Not Equal
//
function alertIfElementsNotEqualById(Id1,Id2,Message)
{
  if(document.getElementById(Id1).value != document.getElementById(Id2).value)
  {
    alert(Message);
  }
}

//
// changeInnerHTMLById
// -----------------------
// id:  Id of Element (Unique)
// Value:  Value to assign to InnerHTML
//
// Description: Assigns InnerHTML To Value
//
function changeInnerHTMLById(Id,Value)
{
  document.getElementById(Id).innerHTML = Value;
}

//
// changeValueById
// -----------------------
// id:  Id of Element (Unique)
// Value:  Value to assign to the Element
//
// Description: Assigns A Value To An Element
//
function changeValueById(Id,Value)
{
  document.getElementById(Id).value = Value;
}

//
// changeDateString
// ------------------------
// DateStr:  Date String To Check
// Value:  Value to assign to the Element
//
// Return Value: Boolean (True/False)
//
// Description: Checks Date Values
//
function checkDateString(DateStr,DateOrder1,DateOrder2,DateOrder3)
{
  var MonthArr = new Array();
  MonthArr[1]  = 31;
  MonthArr[2]  = 28;
  MonthArr[3]  = 31;
  MonthArr[4]  = 30;
  MonthArr[5]  = 31;
  MonthArr[6]  = 30;
  MonthArr[7]  = 31;
  MonthArr[8]  = 31;
  MonthArr[9]  = 30;
  MonthArr[10] = 31;
  MonthArr[11] = 30;
  MonthArr[12] = 31;
  //
  // Get First Numeric Value
  //
  var TmpStr = '';
  var Pos = 0;
  var DateItem1 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr++)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      Pos = Ctr + 1;
      break;
    }
    DateItem1 = DateItem1 + TmpStr;
  }
  //
  // If End Of Date String Then Date Is Incomplete
  //
  if(Pos == DateStr.length)
  {
    alert('1: Incomplete Date!');
    return(false);
  }
  //
  // Find Start Of Second Numeric Value
  //
  for(Ctr = Pos; Ctr < DateStr.length; Ctr++)
  {
    Pos = Ctr;
    TmpStr = DateStr.substr(Ctr,1);
    if(!isNaN(TmpStr))
    {
      break;
    }
  }
  //
  // If End Of Date String Then Date Is Incomplete
  //
  if(Pos == DateStr.length)
  {
    alert('2: Incomplete Date!');
    return(false);
  }
  //
  // Get Second Numeric Value
  //
  var DateItem2 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr++)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      Pos = Ctr + 1;
      break;
    }
    DateItem2 = DateItem2 + TmpStr;
  }
  //
  // If End Of Date String Then Date Is Incomplete
  //
  if(Pos == DateStr.length)
  {
    alert('3: Incomplete Date!');
    return(false);
  }
  //
  // Find Start Of Third Numeric Value
  //
  for(Ctr = Pos; Ctr < DateStr.length; Ctr++)
  {
    Pos = Ctr;
    TmpStr = DateStr.substr(Ctr,1);
    if(!isNaN(TmpStr))
    {
      break;
    }
  }
  //
  // If End Of Date String Then Date Is Incomplete
  //
  if(Pos == DateStr.length)
  {
    alert('4: Incomplete Date!');
    return(false);
  }
  //
  // Get Third Numeric Value
  //
  var DateItem3 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr++)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      break;
    }
    DateItem3 = DateItem3 + TmpStr;
  }
  //
  // If End Of Date String Then Date Is Incomplete
  //
  if(Pos == DateStr.length)
  {
    alert('5: Incomplete Date!');
    return(false);
  }
  //
  // Initialize Variables
  //
  var Month = ''
  var Day   = ''
  var Year  = ''
  //
  // Assign Month To First Numeric Value
  //
  if(DateOrder1 == 'mm')
  {
    Month = String(DateItem1);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  //
  // Assign Day To First Numeric Value
  //
  if(DateOrder1 == 'dd')
  {
    Day = String(DateItem1);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  //
  // Assign Year To First Numeric Value
  //
  if(DateOrder1 == 'yyyy')
  {
    Year = String(DateItem1);
  }
  //
  // Assign Month To Second Numeric Value
  //
  if(DateOrder2 == 'mm')
  {
    Month = String(DateItem2);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  //
  // Assign Day To Second Numeric Value
  //
  if(DateOrder2 == 'dd')
  {
    Day = String(DateItem2);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  //
  // Assign Year To Second Numeric Value
  //
  if(DateOrder2 == 'yyyy')
  {
    Year = String(DateItem2);
  }
  //
  // Assign Month To Third Numeric Value
  //
  if(DateOrder3 == 'mm')
  {
    Month = String(DateItem3);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  //
  // Assign Day To Third Numeric Value
  //
  if(DateOrder3 == 'dd')
  {
    Day = String(DateItem3);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  //
  // Assign Year To Third Numeric Value
  //
  if(DateOrder3 == 'yyyy')
  {
    Year = String(DateItem3);
  }
  //
  // Any Null Value Is An Incomplete Dates
  //
  if((Month == '') || (Day == '') || (Year == ''))
  {
    alert('6: Incomplete Date!');
    return(false);
  }
  //
  // Validate Year Value
  //
  if(Number(Year) < 1900)
  {
    alert('7: Invalid Year Value!'+' ['+Year+']');
    return(false);
  }
  //
  // If Leap Year Then Set February Days To 29
  //
  if(Number(Year) % 4 == 0)
  {
    MonthArr[2] = MonthArr[2] + 1;
  }
  //
  // Validate Month Value
  //
  if((Number(Month) < 1) || (Number(Month) > 12))
  {
    alert('8: Invalid Month Value!'+' ['+Month+']');
    return(false);
  }
  //
  // Validate Day Value
  //
  if((Number(Day) < 1) || (Number(Day) > MonthArr[Number(Month)]))
  {
    alert('9: Invalid Day Value!'+' ['+Day+']');
    return(false);
  }
  return(true);
}

// 
// combineCheckBoxValues
// --------------------------------
// Id:  Id Of Element To Assign Values As A Comma Delimited String
// ArrName:  Array Name Of Checkboxes To Get Values From And Join Together As A Comma Delmited String
// 
// Description: Concatenates Checkbox Values Into A Comma Delimited String Which Is Assigned To Another Element
//
function combineCheckboxValues(Id,ArrName)
{
  document.getElementById(Id).value = document.getElementsByName(ArrName).join(',');
}

// 
// combineDateValuesById
// --------------------------------
// Id:  Id Of Element To Assign Date
// YearId:  Id Of Element That Contains Year Value
// MonthId:  Id Of Element That Contains Month Value
// DayId:  Id Of Element That Contains Day Value
// 
// Return Format: Year-Month-Day
//
// Description: Concatenates three field values into ISO Date Format
//
function combineDateById(Id,YearId,MonthId,DayId)
{
  document.getElementById(Id).value = document.getElementById(YearId).value + '-' + document.getElementById(MonthId).value + '-' + document.getElementById(DayId).value;
}

// 
// copyValueById
// ------------------------
// SrcId:  Id Of Element To Copy From
// DstId:  Id Of Element To Copy To
//
// Description: Copies Value Of One Element To Another Element
//
function copyValueById(SrcId,DstId)
{
  document.getElementById(DstId).value = document.getElementById(SrcId).value;
}

// 
// displayElementById
// -------------------------
// Id:  Id Of Element
// 
// Description:  Change Display Property Of Element To Make It Visible
//
function displayElementById(Id) 
{
  document.getElementById(Id).style.display = "";
}

// 
// displayElementOnTriggerById
// ---------------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Take Action On
//
// Description:  When Active Element Value's Length Is Equal To The Max Length Of The Element Then Set Focus To Another Element
//
function displayElementOnTriggerById(ActiveId,ActionId,TriggerOperator,TriggerValue) 
{
  if(TriggerOperator == '=')
  {
    if(document.getElementById(ActiveId).value == TriggerValue)
    {
      document.getElementById(ActionId).style.display = "";
    }
  }
  else if(TriggerOperator == '!=')
  {
    if(document.getElementById(ActiveId).value != TriggerValue)
    {
      document.getElementById(ActionId).style.display = "";
    }
  }
}

// 
// displayElementByName
// ------------------------------
// Name:  Array Name Of Elements
// Index: Array Index Of Element
// 
// Description:  Change Display Property Of Element To Make It Visible
//
function displayElementByName(Name)
{
  document.getElementsByName(Name)[Index].style.display = "";
}

// 
// fitSize
// ----------
// Id:  Id Of Element
//
// Description: Changes the MaxLength property of a field to fit the value that it currently contains (mainly for Input Fields)
//
function fitSize(Id) 
{
  document.getElementById(Id).size = document.getElementById(Id).value.length + 4;
}

// 
// forceAlpha
// ---------------
// EventObject:  Reference To The Event Object
//
// Return: Boolean (True/False)
//
// Description: Makes An Input Field Ignore Non-Alpha Keystroke Characters
//
function forceAlpha(EventObject)
{
  var KeyVal;
  var KeyChr;
  var StrChk;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browser Code
    KeyVal = EventObject.which;
  }
  //
  // If Event Is Not A Standard Keystroke Then Pass Value Through
  //
  if((KeyVal < 32) || (KeyVal > 126) || (KeyVal == undefined))
  {
    return(true);
  }
  //
  // Convert Character Code To Character
  //
  KeyChr = String.fromCharCode(KeyVal);
  //
  // Set Filter String
  //
  StrChk = /[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]/;
  //
  // Check For KeyChar In StrChk String And Return True Or False
  //
  return(StrChk.test(KeyChr));
}

// 
// forceDigit
// ---------------
// EventObject:  Reference To The Event Object
//
// Return: Boolean (True/False)
//
// Description: Makes An Input Field Ignore Non-Digit Keystroke Characters
//
function forceDigit(EventObject)
{
  var KeyVal;
  var KeyChr;
  var StrChk;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browser Code
    KeyVal = EventObject.which;
  }
  //
  // If Event Is Not A Standard Keystroke Then Pass Value Through
  //
  if((KeyVal < 32) || (KeyVal > 126) || (KeyVal == undefined))
  {
    return(true);
  }
  //
  // Convert Character Code To Character
  //
  KeyChr = String.fromCharCode(KeyVal);
  //
  // Set Filter String
  //
  StrChk = /\\d/;
  //
  // Check For KeyChar In StrChk String And Return True Or False
  //
  return(StrChk.test(KeyChr));
}

// 
// forcePhone
// ---------------
// Id: Id Of Element
// FormatString: Phone Format String: (aaa) xxxx-nnnn, aaa-xxx-nnnn, xxx-nnnn
// EventObject:  Reference To The Event Object
//
// Return: Boolean (True/False)
//
// Description: Makes An Input Field Ignore Non-Phone Format Specific Keystroke Characters
//
function forcePhone(Id,FormatString,EventObject)
{
  var KeyVal;
  var KeyChr;
  var StrChk;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browser Code
    KeyVal = EventObject.which;
  }
  //
  // If Event Is Not A Standard Keystroke Then Pass Value Through
  //
  if((KeyVal < 32) || (KeyVal > 126) || (KeyVal == undefined))
  {
    return(true);
  }
  //
  // Convert Character Code To Character
  //
  KeyChr = String.fromCharCode(KeyVal);
  //
  // Get Format Position
  //
  FmtPos = document.getElementById(Id).value.length;
  //
  // Execute Code Based On Format String
  //
  if(FormatString == '(aaa) xxx-nnnn')
  {
    if(FmtPos == 0)
    { // '(' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      { 
        //
        // Character Keystroke Is Digit
        // Insert '(' Character
        // Pass Digits Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '(';
        return(true);
      }
      if(KeyVal == 40)
      {
        //
        // Character Keystroke Is '(' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if((FmtPos >= 1) && (FmtPos <= 3))
    { // Area Code Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 4)
    { // ')' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert ')' Character
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + ') ';
        return(true);
      }
      if(KeyVal == 41)
      {
        //
        // Character Keystroke Is ')' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 5)
    { // ' ' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert ' ' Character
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + ' ';
        return(true);
      }
      if(KeyVal == 32)
      {
        //
        // Character Keystroke Is ' ' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if((FmtPos >= 6) && (FmtPos <= 8))
    { // Exchange Number Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Digits Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 9)
    { // '-' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert '-' Character
        // Pass Digits Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '-';
        return(true);
      }
      if(KeyVal == 45)
      {
        //
        // Character Keystroke Is '-' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos > 9)
    { // Phone Number Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Digits Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
  }
  if(FormatString == 'aaa-xxx-nnnn')
  {
    if((FmtPos >= 0) && (FmtPos <= 2))
    { // Area Code Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 3)
    { // '-' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert '-' Character
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '-';
        return(true);
      }
      if(KeyVal == 45)
      {
        //
        // Character Keystroke Is Digit '-' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if((FmtPos >= 4) && (FmtPos <= 6))
    { // Exchange Number Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      return(false);
    }
    if(FmtPos == 7)
    { // '-' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert '-' Character
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '-';
        return(true);
      }
      if(KeyVal == 45)
      {
        //
        // Character Keystroke Is '-' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos >= 7)
    { // Phone Number Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
  }
  if(FormatString == 'xxx-nnnn')
  {
    if((FmtPos >= 0) && (FmtPos <= 2))
    { // Exchange Number Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 3)
    { // '-' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert '-' Character
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '-';
        return(true);
      }
      if(KeyVal == 45)
      {
        //
        // Character Keystroke Is '-' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos >= 4)
    {
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
  }
  return(false);
}

// 
// forceZipcode
// ---------------
// Id: Id Of Element
// FormatString: Zipcode Format String: zzzzz-xxxx, aaa-xxx-nnnn, xxx-nnnn
// EventObject:  Reference To The Event Object
//
// Return: Boolean (True/False)
//
// Description: Makes An Input Field Ignore Non-Zipcode Format Specific Keystroke Characters
//
function forceZipcode(Id,FormatString,EventObject)
{
  var KeyVal;
  var KeyChr;
  var StrChk;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browswer Code
    KeyVal = EventObject.which;
  }
  //
  // If Event Is Not A Standard Keystroke Then Pass Value Through
  //
  if((KeyVal < 32) || (KeyVal > 126) || (KeyVal == undefined))
  {
    return(true);
  }
  //
  // Convert Character Code To Character
  //
  KeyChr = String.fromCharCode(KeyVal);
  //
  // Get Format Position
  //
  FmtPos = document.getElementById(Id).value.length;
  //
  // Execute Code Based On Format String
  //
  if(FormatString == 'zzzzz-xxxx')
  {
    if((FmtPos >= 0) && (FmtPos <= 4))
    { // Zipcode Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos == 5)
    { // '-' Character Position
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Insert '-' Character Keystroke
        // Pass Character Keystroke Through
        //
        document.getElementById(Id).value = document.getElementById(Id).value + '-';
        return(true);
      }
      if(KeyVal == 45)
      {
        //
        // Character Keystroke Is '-' Character
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
    if(FmtPos > 5)
    { // Plus Four Positions
      if((KeyVal >= 48) && (KeyVal <= 57))
      {
        //
        // Character Keystroke Is Digit
        // Pass Character Keystroke Through
        //
        return(true);
      }
      //
      // Ignore All Other Standard Character Keystrokes
      //
      return(false);
    }
  }
  return(false);
}

// 
// formSubmit
// -----------------
// Id: Id Of Form
//
// Description: Submits Form
//
function formSubmit(Id)
{
  document.getElementById(Id).submit();
}

// 
// getKeyCode
// ---------------
// EventObject:  Reference To The Event Object
//
// Return: Key Code Value
//
// Description: Gets Ascii Key Code Value Of A Keystroke
//
function getKeyCode(EventObject)
{
  var KeyCodeVal;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyCodeVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browser Code
    KeyCodeVal = EventObject.which;
  }
  return(KeyCodeVal);
}

// 
// hideElementById
// ----------------------
// Id:  Id Of Element
//
// Description:: Makes An Element Insvisible 
//
function hideElementById(Id)
{
  document.getElementById(Id).style.display = "none";
}

// 
// hideElementByName
// --------------------------
// Name:  Name Of Element
// Index:  Array Index (Elements With Identical Names Are Placed In Array. First Element Is Index 0)
//
// Description:: Makes An Element Insvisible 
//
function hideElementByName(Name,Index) 
{
  document.getElementsByName(Name)[Index].style.display = "none";
}

// 
// hideElementOnTriggerById
// -----------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Take Action On
//
// Description:  When Active Element Value's Length Is Equal To The Max Length Of The Element Then Set Focus To Another Element
//
function hideElementOnTriggerById(ActiveId,ActionId,TriggerOperator,TriggerValue) 
{
  if(TriggerOperator == '=')
  {
    if(document.getElementById(ActiveId).value == TriggerValue)
    {
      document.getElementById(ActionId).style.display = "none";
    }
  }
  else if(TriggerOperator == '!=')
  {
    if(document.getElementById(ActiveId).value != TriggerValue)
    {
      document.getElementById(ActionId).style.display = "none";
    }
  }
}

// 
// inputFilter
// --------------
// RegExpPattern:  Regular Expression Pattern
// EventObject:  Reference To An Event Object
//
// Return: Boolean (True/False)
//
// Description:  Forces An Input Element To Ingore All Standard Character Keystrokes Not In Filter (Defined By RegExpPattern)
//
function inputFilter(RegExpPattern,EventObject)
{
  var KeyVal;
  var KeyChr;
  var StrChk;
  if(window.event)
  { // Internet Explorer Browser Code
    KeyVal = EventObject.keyCode;
  }
  else if(EventObject.which)
  { // Firefox Browser Code
    KeyVal = EventObject.which;
  }
  //
  // If Event Is Not A Standard Keystroke Then Pass Value Through
  //
  if((KeyVal < 32) || (KeyVal > 126) || (KeyVal == undefined))
  {
    return(true);
  }
  //
  // Convert Character Code To Character
  //
  KeyChr = String.fromCharCode(KeyVal);
  //
  // Set Filter String
  //
  StrChk = RegExpPattern;
  //
  // Check For KeyChar In StrChk String And Return True Or False
  //
  return(StrChk.test(KeyChr));
}

// 
// isNumberInRange
// -----------------------
// Id:  Id Of Element
// MinVal:  Minimum Value
// MaxVal:  Maximum Value
//
// Return:  Boolean (True/False)
//
// Description:  Checks If Numeric Value Is In Range Inclusively
//
function isNumberInRange(Id,MinVal,MaxVal) 
{
  if(isNaN(document.getElementById(Id).value))
  { // If Value Is Not-A-Number Then Return False
    alert('Value is not a number!');
    return(false);
  }
  else if(document.getElementById(Id).value < MinVal || document.getElementById(Id).value > MaxVal)
  { // If Value Is Not In Range Then Return False
    alert('Number out of range! [' + String(MinVal) + '-' + String(MaxVal) + ']');
    return(false);
  }
  //
  // Value Is A Number And Is In Range
  //
  return(true);
}

// 
// isValueEqualById
// -----------------------
// Id:  Id Of Element
// Value:  Compare Value
//
// Return:  Boolean (True/False)
//
// Description:  Checks If An Element's Value Is Equal To Value
//
function isValueEqualById(Id,Value)
{
  return(document.getElementById(Id).value == Value);
}

// 
// isValidAreacodeUSA(this.value)
// ---------------------------
// TestValue:  Phone String To Test
//
// Return:  Boolean (True/False)
//
// Description:  Checks Area Code Against Valid Area Codes For The USA
//
function isValidAreacodeUSA(TestValue)
{
  ValidAreacodes = '|201|202|203|205|206|207|208|209|210|212|213|214|215|216|217|218|219|224|225|228|229|231|234|236|239|240|248|251|252|253|254|256|260|262|267|269|270|276|278|281|283|301|302|303|304|305|307|308|309|310|312|313|314|315|316|317|318|319|320|321|323|325|330|331|334|336|337|339|341|347|351|352|360|361|369|380|385|386|401|402|404|405|406|407|408|409|410|412|413|414|415|417|419|423|424|425|430|432|434|435|440|442|443|464|469|470|475|478|479|480|484|501|502|503|504|505|507|508|509|510|512|513|515|516|517|518|520|530|540|541|551|557|559|561|562|563|564|567|570|571|573|574|575|580|585|586|601|602|603|605|606|607|608|609|610|612|613|614|615|616|617|618|619|620|623|626|627|628|630|631|636|641|646|650|651|660|661|662|669|678|679|682|689|701|702|703|704|706|707|708|712|713|714|715|716|717|718|719|720|724|727|731|732|734|737|740|747|754|757|760|762|763|764|765|769|770|772|773|774|779|781|785|786|801|802|803|804|805|806|808|810|812|813|814|815|816|817|818|828|830|831|832|835|843|845|847|848|850|856|857|858|859|860|862|863|864|865|870|872|878|901|903|904|906|907|908|909|910|912|913|914|915|916|917|918|919|920|925|927|928|931|935|936|937|940|941|947|949|951|952|954|956|957|959|970|971|972|973|975|978|979|980|984|985|989|';
  Digits = '0123456789';
  Areacode = '';
  StrMax = TestValue.length;
  for(StrIdx = 0; StrIdx < StrMax; StrIdx = StrIdx + 1)
  {
    TmpChr = TestValue.charAt(StrIdx);
    if(Digits.indexOf(TmpChr) >= 0)
    {
      Areacode = Areacode + String(TmpChr);
    }
    if(Areacode.length == 3)
    {
      break;
    }
  }
  if(Areacode.length < 3)
  {
    alert('Incomplete Area Code: '+Areacode);
    return(false);
  }
  if(ValidAreacodes.indexOf(Areacode) < 0)
  {
    alert('Invalid USA Area Code: '+Areacode);
    return(false);
  }
  return(true);
}

// 
// isValueChangedById
// ---------------------------
// Id:  Id Of Element
//
// Return:  Boolean (True/False)
//
// Description:  Checks If An Element's Value Ha Equal To Value
//
function isValueChangedById(Id) 
{
  return(document.getElementById(Id).value != document.getElementById(Id).defaultValue)
}

// 
// onBackspaceSetFocusById
// -----------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Set Focus To
// EventObject:  Reference To An Event Object
//
// Description:  When Backspace Keystroke Is Pressed And Backspace Would Make Element Value Empty Then Set Focus To Another Element
//
function onBackspaceSetFocusById(ActiveId,ActionId,EventObject)
{
  if(document.getElementById(ActiveId).value.length == 1)
  {
    var KeyVal;
    if(window.event)
    { // Internet Explorer Browser Code
      KeyVal = EventObject.keyCode;
    }
    else if(EventObject.which)
    { // Firefox Browser Code
      KeyVal = EventObject.which;
    }
    //
    // If Keystroke Is Backspace Then Clear Value Of Active Element And Move Focus To Another Element
    //
    if(KeyVal == 8)
    {
      document.getElementById(ActiveId).value = '';
      document.getElementById(ActionId).focus();
      return(false);
    }
  }
  //
  // Pass Keystroke Through
  //
  return(true);
}

// 
// onFullFieldSetFocusById
// --------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Set Focus To
//
// Description:  When Active Element Value's Length Is Equal To The Max Length Of The Element Then Set Focus To Another Element
//
function onFullFieldSetFocusById(ActiveId,ActionId)
{
  if(document.getElementById(ActiveId).value.length == document.getElementById(ActiveId).maxLength)
  {
    document.getElementById(ActionId).focus();
  }
}

// 
// openLinkInCurrentWindow
// -----------------------------------
// Link:  Web Address
//
// Description:  Open Hyperlink In Current Browser Window
//
function openLinkInCurrentWindow(Link)
{
  window.open(Link,'_self');
}

// 
// openLinkInNewWindow
// -------------------------------
// Link:  Web Address
//
// Description:  Open Hyperlink In A New Browser Window
//
function openLinkInNewWindow(Link)
{
  window.open(Link,'_blank');
}

// 
// reformatDate
// ------------------
// ActionId:  Id Of Element To Take Action On
// DateValue
//
// Description:  Open Hyperlink In A New Browser Window
//
function reformatDateString(ActionId,OrgDate,OrgDateOrder1,OrgDateOrder2,OrgDateOrder3,NewDateOrder1,NewDateOrder2,NewDateOrder3,Delimiter)
{
  var TmpStr = '';
  var Pos = 0;
  var DateItem1 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr = Ctr + 1)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      Pos = Ctr + 1;
      break;
    }
    DateItem1 = DateItem1 + TmpStr;
  }
  DateItem2 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr = Ctr + 1)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      Pos = Ctr + 1;
      break;
    }
    DateItem2 = DateItem2 + TmpStr;
  }
  DateItem3 = '';
  for(Ctr = Pos; Ctr < DateStr.length; Ctr = Ctr + 1)
  {
    TmpStr = DateStr.substr(Ctr,1);
    if(isNaN(TmpStr))
    {
      break;
    }
    DateItem3 = DateItem3 + TmpStr;
  }
  Month = ''
  Day   = ''
  Year  = ''
  if(OrgDateOrder1 == 'mm')
  {
    Month = String(DateItem1);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  if(OrgDateOrder1 == 'dd')
  {
    Day = String(DateItem1);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  if(OrgDateOrder1 == 'yyyy')
  {
    Year = String(DateItem1);
  }
  if(OrgDateOrder2 == 'mm')
  {
    Month = String(DateItem2);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  if(OrgDateOrder2 == 'dd')
  {
    Day = String(DateItem2);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  if(OrgDateOrder2 == 'yyyy')
  {
    Year = String(DateItem2);
  }
  if(OrgDateOrder3 == 'mm')
  {
    Month = String(DateItem3);
    if(Month.length == 1)
    {
      Month = '0' + Month;
    }
  }
  if(OrgDateOrder3 == 'dd')
  {
    Day = String(DateItem3);
    if(Day.length == 1)
    {
      Day = '0' + Day;
    }
  }
  if(OrgDateOrder3 == 'yyyy')
  {
    Year = String(DateItem3);
  }
  NewDate = ''
  if(NewDateOrder1 == 'mm')
  {
    NewDate = NewDate + String(Month);
  }
  if(NewDateOrder1 == 'dd')
  {
    NewDate = NewDate + String(Day);
  }
  if(NewDateOrder1 == 'yyyy')
  {
    NewDate = NewDate + String(Year);
  }
  NewDate = NewDate + Delimiter;
  if(NewDateOrder2 == 'mm')
  {
    NewDate = NewDate + String(Month);
  }
  if(NewDateOrder2 == 'dd')
  {
    NewDate = NewDate + String(Day);
  }
  if(NewDateOrder2 == 'yyyy')
  {
    NewDate = NewDate + String(Year);
  }
  NewDate = NewDate + Delimiter;
  if(NewDateOrder3 == 'mm')
  {
    NewDate = NewDate + String(Month);
  }
  if(NewDateOrder3 == 'dd')
  {
    NewDate = NewDate + String(Day);
  }
  if(NewDateOrder3 == 'yyyy')
  {
    NewDate = NewDate + String(Year);
  }
  document.getElementById(Id).value = NewDate;
}

// 
// refreshElementLengthCounterById
// ---------------------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Take Action On
//
// Description:  Refreshes Action Element's Value When Active Element's Value Is Changed
//
function refreshElementLengthCounterById(ActiveId,ActionId)
{
  document.getElementById(ActionId).value = document.getElementById(ActiveId).value.length;
}

// 
// setAllCheckBoxesById
// -----------------------------
// Name:  Name Prefix Of Checkboxes
// Start:  Name Postfix Number (Start Number)
// Stop:   Name Postfix Number (Stop Number)
// Value:  Boolean (true or false)
// Width:  Zero Fill Width Of Postfix Number
//
// Description:  Checks/Unchecks All Checkboxes
//
function setAllCheckBoxesById(Name,Start,Stop,Value,Width)
{
  PreFix = String(Name);
  for(Ctr = Start; Ctr <= Stop; Ctr++)
  {
    PostFix = String(Ctr);
    while(PostFix.length < Width)
    {
      PostFix = '0' + PostFix;
    }
    Id = Prefix + PostFix;
    document.getElementById(Id).checked = Value;
  }
}

// 
// setAllCheckBoxesByName
// ---------------------------------
// Name:  Array Name Of Checkboxes
// Value:  Boolean (true or false)
//
// Description:  Checks/Unchecks All Checkboxes
//
function setAllCheckBoxesByName(Name,Value)
{
  ObjPtr = document.getElementsByName(Name);
  for(Ctr = 1; Ctr <= ObjPtr.length; Ctr++)
  {
    ObjPtr[Ctr-1].checked = Value;
  }
}

// 
// setCookie
// -------------
// Name:  Name Of Cookie
// Value:  Value Of Cookie
// Duration:  Duration Time Of Cookie (Minutes)
//
// Description:  Sets Cookie Value And Expiration
//
function setCookie(Name,Value,Duration)
{
  var ErrorName     = "";
  var ErrorValue    = "";
  var ErrorDuration = "";
  
  var currentDateTime = Date.parse(Date()); // Current Date And Time in Milliseconds
  var cookieDateTime  = new Date();
  cookieDateTime.setTime(currentDateTime); // Current Date And Time 
  
  if(isNaN(Duration))
  {
    ErrorName     = "SetCookieError03";
    ErrorValue    = "Invalid Expiration Value";
    ErrorDuration = 60;
    Duration      = 0;
  }
  else
  {
    Duration = Number(Duration);
  }
  
  if(String(Value) == "")
  {
    ErrorName     = "SetCookieError02";
    ErrorValue    = "Null Cookie Value";
    ErrorDuration = 60;
    Value         = cookieDateTime.toString();
  }
  
  if(String(Name) == "")
  {
    ErrorName     = "SetCookieError01";
    ErrorValue    = "Name Parameter Empty";
    ErrorDuration = 60;
  }
  else
  {
    cookieDateTime.setTime(currentDateTime+(Duration*60*1000));
    document.cookie = String(Name) + "=" + String(Value) + ";expires=" + cookieDateTime.toGMTString() + ";path=/";
  }
  
  if(ErrorName != "")
  {
    cookieDateTime.setTime(currentDateTime+(ErrorDuration*60*1000));
    document.cookie = ErrorName + "=" + ErrorValue + ";expires=" + cookieDateTime.toGMTString() + ";path=/";
  }
}

//
// setDisplayOnTriggerById
// ----------------------------------
// ActiveId:  Id Of Active Element
// ActionId:  Id Of Element To Take Action On
// TriggerOperator:  Comparison Operator: =, !=
// TriggerValue:  Value To Compare Element's Value To
// DisplayMode:  String Value To Set Display Property To: '' is visible, 'none' is invisible
//
// Description:  If Trigger Condition Is True For Active Element Then Set Display Property Of Action Element To DisplayMode
//
function setDisplayOnTriggerById(ActiveId,ActionId,TriggerOperator,TriggerValue,DisplayMode) 
{
  if(TriggerOperator == '=')
  {
    if(document.getElementById(ActiveId).value == TriggerValue)
    {
      document.getElementById(ActionId).style.display = DisplayMode;
    }
  }
  else if(TriggerOperator == '!=')
  {
    if(document.getElementById(ActiveId).value != TriggerValue)
    {
      document.getElementById(ActionId).style.display = DisplayMode;
    }
  }
}

// 
// setFocusById
// ------------------
// Id:  Id Of Element To Take Action On
//
// Description:  Sets Focus To Element
//
function setFocusToId(Id) 
{
  document.getElementById(Id).focus();
}

// 
// setFocusByName
// ----------------------
// Name:  Array Name Of Elements
// Index: Array Index Of Element
//
// Description:  Sets Focus To Element
//
function setFocusToName(Name,Index)
{
  document.getElementsByName(Name)[Index].focus();
}

// 
// setFocusToNextFormElementById
// -------------------------------------------
// Id:  Id Of Element
//
// Description:  Sets Focus To Next Element In The Form
//
function setFocusToNextFormElementById(Id) 
{
  NextIndex = document.getElementById(Id).tabIndex;
  document.getElementById(document.getElementById(Id).form.id).elements[NextIndex].focus();
}

// 
// setFocusToPrevFormElementById
// -------------------------------------------
// Id:  Id Of Element
//
// Description:  Sets Focus To Previous Element In The Form
//
function setFocusToPrevFormElementById(Id)
{
  NextIndex = document.getElementById(Id).tabIndex;
  if(NextIndex >= 2)
  {
    NextIndex = NextIndex - 2;
  }
  document.getElementById(document.getElementById(Id).form.id).elements[NextIndex].focus();
}

// 
// submitFormById
// ---------------------
// Id:  Id Of Form
//
// Description:  Submits Form
//
function submitFormById(Id)
{
  document.getElementById(Id).submit();
}

// 
// toggleDisplayById
// ------------------------
// Id:  Id Of Element
//
// Description: Toggles Display Property Of Element Between Visible And Invisible
//
function toggleDisplayById(Id)
{
  if(document.getElementById(Id).style.display == '')
  {
    document.getElementById(Id).style.display = 'none';
  }
  else
  {
    document.getElementById(Id).style.display = '';
  }
}

// 
// toggleDisplayByName
// ----------------------------
// Name:  Array Name Of Elements
// Index:  Array Index Of Element
//
// Description: Toggles Display Property Of Element Between Visible And Invisible
//
function toggleDisplayByName(Name)
{
  if(document.getElementsByName(Name)[Index].style.display == '')
  {
    document.getElementsByName(Name)[Index].style.display = 'none';
  }
  else
  {
    document.getElementsByName(Name)[Index].style.display = '';
  }
}

// 
// toggleValueById
// ---------------------
// Id:  Id Of Element
// Value1:  First Value
// Value2:  Second Value
//
// Description: Toggles Value Of Element Between Value1 And Value2
//
function toggleValueById(Id,Value1,Value2)
{
  document.getElementById(Id).value = (document.getElementById(Id).value == Value1) ? Value2 : Value1;
}