// LDCC_Misc.js

// ==============================================================================
// | Copyright © 2001-2011, LDC Consulting (LDCC). All rights reserved.         |
// | No part of this document may be reproduced, stored in a retrieval system,  |
// | or transmitted in any form or by any means, electronic, mechanical,        |
// | photocopying, recording, or otherwise, without prior permission from LDCC. |
// ==============================================================================

// CSS CONSTANTS

// DISPLAY CONSTANTS

ALL_YEARS        = 0x00001;
BLANK_OPTION     = 0x00002;
COPY_FORM        = 0x00004;
DISABLED         = 0x00008;
FUTURE_YEAR      = 0x00010;
LEADING_ZERO     = 0x00020;
LOCAL_VALIDATION = 0x00040;
PASSWORD         = 0x00080;
PAST_YEAR        = 0x00100;
POPUP            = 0x00200;
PROMPT_AFTER     = 0x00400;
REQUIRED         = 0x00800;
SAME_LINE        = 0x01000;
SELECTED         = 0x02000;
SHOW_LENGTH      = 0x04000;
SHOW_SCORE       = 0x08000;
THIS_YEAR        = 0x10000;
VALUE_ONLY       = 0x20000;

// ENVIRONMENT CONSTANTS

ORG_ABBREV = 'DCHOA';
ORG_NAME   = 'Dane County Hockey Officials Association';

// ==============================================================================

function LDCC_AgeLevelChange (strSelect) {

    var strAssociation = $('#Association' + strSelect).val();
    var strAgeLevel = $('#AgeLevel' + strSelect).val();
    if ((strAssociation == '') || (strAgeLevel == ''))
      $('#Team' + strSelect).html('');
    else LDCC_SelectFill ('#Team' + strSelect, 'Team', '', strAgeLevel,
      strAssociation, '', BLANK_OPTION);
    }

// ==============================================================================

function LDCC_AssociationChange (strSelect) {

    $('#Team' + strSelect).html('');
    //$('#Team' + strSelect).options.length = 0;
    var strAssociationID = $('#Association' + strSelect).val();
    if (strAssociationID == '') $('#AgeLevel' + strSelect).html('');
    //if (intAssociationID == -1) $('#AgeLevel' + strSelect).options.length = 0;
    else LDCC_SelectFill ('#AgeLevel' + strSelect, 'AgeLevelActive', '',
      strAssociationID, '', '', BLANK_OPTION);
    }

// ==============================================================================

function LDCC_DialogBox (strType, strMessage, objOptions) {

    switch(strType) {
        case 'OK':
            var strDisplay =
              '<IMG src="../images/info.png" align="left" alt="OKAY">' +
              strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {OK: 1}, overlayspeed: 'fast'});
            break;
        case 'Mail':
            var strDisplay =
              '<IMG src="../images/info.png" align="left" alt="SENT">' +
              strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {OK: 1}, overlayspeed: 'fast'});
            break;
        case 'Inform':
            var strDisplay =
              '<IMG src="../images/info.png" align="left" alt="INFORM">' +
              strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {OK: 1}, overlayspeed: 'fast'});
            break;
        case 'Warning':
            var strDisplay =
              '<IMG src="../images/warn.png" align="left" alt="WARNING"' +
                ' margin="0 20px 0 0;">' +
              strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {Yes: 1, No: 0}, focus: 0, overlayspeed: 'fast'});
            break;
        case 'Error':
            var strDisplay =
              '<IMG src="../images/error.png" align="left" alt="ERROR"' +
                ' margin="0 100px 0 0;">' +
              strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {'Fix Errors': 1}, overlayspeed: 'fast'});
            break;
        default:
            var strDisplay = strMessage;
            objButtons = ((objOptions != null) ? objOptions :
              {buttons: {OK: 1}, overlayspeed: 'fast'});
            break;
        }
    var intReturn =
      $.prompt(strDisplay, objButtons).children('#jqi').corner('20px');
    return intReturn;
    }

// ==============================================================================

function LDCC_ExpandName(Name) {

    var MyRegExp = /{DOL}/;
    var MyName = Name.replace(MyRegExp, '{DDO}Linesman/');
    MyRegExp = /{DOM}/;
    MyName = MyName.replace(MyRegExp, '{DDO}Miscellaneous/');
    MyRegExp = /{DOP}/;
    MyName = MyName.replace(MyRegExp, '{DDO}Penalties/');
    MyRegExp = /{DOR}/;
    MyName = MyName.replace(MyRegExp, '{DDO}Referee/');
    MyRegExp = /{DOW}/;
    MyName = MyName.replace(MyRegExp, '{DDO}WIAA/');

    MyRegExp = /{DDM}/;
    MyName = MyName.replace(MyRegExp, '{DM}Manuals/');
    MyRegExp = /{DDO}/;
    MyName = MyName.replace(MyRegExp, '{DM}Other/');

    MyRegExp = /{DF}/;
    MyName = MyName.replace(MyRegExp, '{CD}DCHOA/Forms/');
    MyRegExp = /{DM}/;
    MyName = MyName.replace(MyRegExp, '{CD}DCHOA/Documents/');
    MyRegExp = /{DO}/;
    MyName = MyName.replace(MyRegExp, '{CD}DCHOA/Other/');

    MyRegExp = /{UP}/;
    MyName = MyName.replace(MyRegExp, '{CD}USAHockey/Publications/');

    MyRegExp = /{CI}/;
    MyName = MyName.replace(MyRegExp, '{CD}Images/');

    MyRegExp = /{CD}/;
    //MyName = MyName.replace(MyRegExp, '../CD/');
    MyName = MyName.replace(MyRegExp, '{W}DCHOAInfo.org/CD/');

    MyRegExp = /{WE}/;
    MyName = MyName.replace(MyRegExp, '{D}education/');
    MyRegExp = /{WD}/;
    MyName = MyName.replace(MyRegExp, '../documents/');

    MyRegExp = /{WID}/;
    MyName = MyName.replace(MyRegExp, '{WI}document/');
    MyRegExp = /{WI}/;
    MyName = MyName.replace(MyRegExp, '../images/');

    MyRegExp = /{A}/;
    MyName = MyName.replace(MyRegExp, '../admin/');
    MyRegExp = /{B}/;
    MyName = MyName.replace(MyRegExp, '../board/');
    MyRegExp = /{C}/;
    MyName = MyName.replace(MyRegExp, '../coach/');
    MyRegExp = /{D}/;
    MyName = MyName.replace(MyRegExp, '../documents/');
    MyRegExp = /{DD}/;
    MyName = MyName.replace(MyRegExp, '../misc/DisplayDocument\.php');
    MyRegExp = /{E}/;
    MyName = MyName.replace(MyRegExp, '../evaluator/');
    MyRegExp = /{I}/;
    MyName = MyName.replace(MyRegExp, '../images/');
    MyRegExp = /{M}/;
    MyName = MyName.replace(MyRegExp, '../misc/');
    MyRegExp = /{N}/;
    MyName = MyName.replace(MyRegExp, '../news/');
    MyRegExp = /{O}/;
    MyName = MyName.replace(MyRegExp, '../official/');
    MyRegExp = /{P}/;
    MyName = MyName.replace(MyRegExp, '../public/');
    MyRegExp = /{R}/;
    MyName = MyName.replace(MyRegExp, '../teamrep/');
    MyRegExp = /{S}/;
    MyName = MyName.replace(MyRegExp, '../special_events/');
    MyRegExp = /{Y}/;
    MyName = MyName.replace(MyRegExp, '../assigner/');
    MyRegExp = /{W}/;
    MyName = MyName.replace(MyRegExp, 'http://www.');
    return MyName;
    }

  // ============================================================================

  function LDCC_FindDefault (strID, arrDefaults) {

      for (var intX in arrDefaults)
        if (arrDefaults[intX][0] == strID) return arrDefaults[intX][2];
      return '';
      }

  // ============================================================================

  function LDCC_FormDefaults (strForm, blnReset, arrDefaults) {

      if (blnReset) document.getElementById(strForm).reset();
      for (var intX in arrDefaults) {
          switch (arrDefaults[intX][1]) {
              case 'Value':
                  $('#' + arrDefaults[intX][0])
                    .attr({value: arrDefaults[intX][2],
                           disabled: arrDefaults[intX][3]});
                  break;
              case 'Select':
                  $('#' + arrDefaults[intX][0])
                    .attr({disabled: arrDefaults[intX][3]});
                  break;
              case 'Check':
                  $('#' + arrDefaults[intX][0])
                    .attr({checked: arrDefaults[intX][2],
                           disabled: arrDefaults[intX][3]});
                  break;
              case 'CheckArray':
                  var intDisabled = arrDefaults[intX][3];
                  var arrChecked = arrDefaults[intX][2];
                  $('form#' + strForm + ' INPUT[@name="' + arrDefaults[intX][0] +
                      '"][type="checkbox"]')
                    .each(function (){
                        $(this).attr({checked: false,
                                      disabled: intDisabled});
                        for (var intR in arrChecked) {
                            if ($(this).val() == arrChecked[intR])
                              $(this).attr('checked', true);
                            }
                        });
                  break;
              case 'Radio':
                  var intDisabled = arrDefaults[intX][3];
                  $('form#' + strForm + ' INPUT[@name="' + arrDefaults[intX][0] +
                      '"]')
                    .attr('disabled', intDisabled)
                    .each(function (){
                        if ($(this).val() == arrDefaults[intX][2])
                          $(this).attr('checked', true);
                        });
                  break;
              case '':
                  break;
              default:
                  //alert('*' + arrDefaults[intX][1] + '*');
              }
          }
      }

// ==============================================================================

function LDCC_FormInputs (strBefore, objForm) {

    var arrFields = new Array();
    var intFieldCount = objForm.elements.length;
    for (var intC = 0; intC < intFieldCount; intC++) {
        objControl = objForm.elements[intC];
        switch(objControl.type) {
            case 'text':
            case 'textarea':
            case 'hidden':
            case 'password':
            case 'FileUpload':
                arrFields.push(encodeURIComponent(objControl.name) + '=' +
                  encodeURIComponent(objControl.value));
                break;
            case 'radio':
            case 'checkbox':
                if(objControl.checked)
                  arrFields.push(
                    encodeURIComponent(objControl.name) + '=' +
                    encodeURIComponent(objControl.value));
                break;
            case 'select-one':
                arrFields.push(encodeURIComponent(objControl.name) + '=' +
                  encodeURIComponent(objControl.options[
                  objControl.selectedIndex].value));
                break;
            case 'select-multiple':
                for(var intS = 0;
                  intS < objControl.options.length; intS++) {
                    if(objControl.options[intS].selected) {
                        if(objControl.options[intS].value == '')
                          arrFields.push(
                            encodeURIComponent(objControl.name) + '=' +
                            encodeURIComponent(objControl.options[intS].text));
                        else
                          arrFields.push(encodeURIComponent(objControl.name) +
                            '=' +
                            encodeURIComponent(objControl.options[intS].value));
                        }
                    }
                break;
            case 'button':
            case 'submit':
            case 'reset':
                break;
            default:
                break;
            }
        }
    return strBefore + arrFields.join('&');
    }

// ============================================================================

function LDCC_Help (objDisplay) {

    var strTopic = objDisplay.Topic;
    var strContext = '';
    if (objDisplay.Context == null) objDisplay.Context = '';
    if (objDisplay.Context != '') strTopic += '&Context=' + objDisplay.Context;
    switch (objDisplay.Container) {
        case 'StickyNote':
            var strGet = '../serv/GetTopic.php?Type=Help&Topic=' + strTopic;
            if (typeof(window.innerWidth) == 'number') // Non-IE
              var intWindowWidth = window.innerWidth + 11;
            else if (document.documentElement &&
              (document.documentElement.clientWidth ||
              document.documentElement.clientHeight))// IE 6+ standard compliant
                var intWindowWidth = document.documentElement.clientWidth;
            else if (document.body && (document.body.clientWidth ||
              document.body.clientHeight)) // IE 4 compatible
                 var intWindowWidth = document.body.clientWidth;
            var intLeft = intWindowWidth - 300;
            var strHTML = $.ajax({url:   strGet,
                                  async: false
                                  }).responseText;
            $('#HelpTopic').remove();
            $('body').append("<DIV id='HelpTopic' class='StickyNote' " +
              "style='left: " + intLeft + "px;'>" +
              "<DIV id='HelpText' class='StickyNoteText'>" +
              strHTML + "</DIV></DIV>");
            var strMenu = [
/*
              {'Print': {onclick: function (menuItem, menu) {
                             window.print();
                             },
                         icon: '../images/SmallPrinter.png'}},
*/
              {'Close': {onclick: function (menuItem, menu) {
                             $('#HelpTopic').remove();
                             },
                         icon: '../images/SmallDoor.png'}},
              $.contextMenu.separator,
              {'Save': {icon: '../images/SmallDisk.gif',
                        disabled: true}}];
            // Give the topic a context menu (close)
            // Make the topic drabbable
            $(function () {
                var intTop = $(window).scrollTop() + 50;
                $('#HelpTopic')
                  .contextMenu(strMenu, {theme: 'ldcc'})
                  .draggable()
                  .resizable({alsoResize: '#HelpText',
                              resize: function (event, ui) {
                                  if (navigator.appName ==
                                    "Microsoft Internet Explorer") {
                                      var intHeight =
                                        parseInt($('#HelpText').css('height')) +
                                        10;
                                      var intWidth =
                                        parseInt($('#HelpText').css('width')) +
                                        8;
                                      $('#HelpText')
                                        .css({height: intHeight,
                                              width: intWidth});
                                      }
                                  },
                              handles: 'n, ne, e, se, s, sw, w, nw'
                              })
                  .animate({top: intTop + 'px'},
                           {queue: false, duration: 'fast'});
              	});
            //scroll the topic to the top offset
            $(window).scroll( function() {
                var intTop = $(window).scrollTop() + 50;
                $('#HelpTopic').animate({top: intTop + 'px'},
                                        {queue: false, duration: 'fast'});
                });
            //when the close button at right corner of the message box is clicked
            $('#CloseTopic').click(function () {
                $('#HelpTopic').remove();
                });
            if (navigator.appName == "Microsoft Internet Explorer") {
                var intHeight = parseInt($('#HelpText').css('height')) + 10;
                var intWidth = parseInt($('#HelpText').css('width')) + 8;
                $('#HelpText').css({height: intHeight, width: intWidth});
/*
                $('#HelpTopic').bind('resize', function (event, ui) {
                    var intHeight = parseInt($('#HelpText').css('height')) + 10;
                    var intWidth = parseInt($('#HelpText').css('width')) + 8;
                    $('#HelpText').css({height: intHeight, width: intWidth});
                    });
*/
                }
            break;
        default:
            strWindow = (objDisplay.Window == null) ?
              'resizable,scrollbars,width=400,height=400,left=100,top=100' :
              objDisplay.Window;
            window.open('../misc/PopupHelp.php?Topic=' + strTopic, '_blank',
              strWindow);
        }
    }

// ==============================================================================

function LDCC_InvalidPassword (strSuffix, objForm, blnRequired) {

    switch (strSuffix) {
        case '':
            var strKind = '';
            break;
        case 'Confirm':
            var strKind = ' confirmation of your new';
            break;
        default:
            var strKind = ' ' + strSuffix.toLowerCase();
        }
    if (objForm['Password' + strSuffix].value == '') {
        if (blnRequired) {
            alert('You must include your' + strKind + ' password.');
            return true;
            }
        else return false;
        }
    else return LDCC_InvalidString (objForm['Password' + strSuffix].value,
      'your' + strKind + ' password', 6, 32, '1234567890!@#%&*-_=+^', true);
    }

// ==============================================================================

function LDCC_InvalidString (strString, strDescription, intMin, intMax,
                             strAllowed, blnAllowAlpha) {

    var strAlpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    if (strString == '') {
        if (intMin < 0) {
            alert('You must include ' + strDescription + '.');
            return true;
            }
        else return false;
        }
    else if ((strString.length < Math.abs(intMin))
      || (strString.length > intMax)) {
        alert(strDescription.charAt(0).toUpperCase() + strDescription.substr(1) +
          ' must be from ' + Math.abs(intMin) + ' to ' + intMax +
          ' characters.');
        return true;
        }
    for (var intX = 0; intX < strString.length; intX++) {
        if (strAllowed.indexOf(strString.charAt(intX)) == -1) {
            if ((!blnAllowAlpha) ||
              (strAlpha.indexOf(strString.charAt(intX).toUpperCase()) == -1)) {
                alert(strDescription.charAt(0).toUpperCase() +
                  strDescription.substr(1) + ' may not contain [' +
                  strString.charAt(intX) + '].');
                return true;
                }
            }
        }
    return false;
   }

// ==============================================================================

function LDCC_InvalidUserName (strSuffix, objForm, blnRequired) {

    switch (strSuffix) {
        case '':
            var strKind = '';
            break;
        case 'Confirm':
            var strKind = ' confirmation of your new';
            break;
        default:
            var strKind = ' ' + strSuffix.toLowerCase();
        }
    if (objForm['UserName' + strSuffix].value == '') {
        if (blnRequired) {
            alert('You must include your' + strKind + ' user name.');
            return true;
            }
        else return false;
        }
    else return LDCC_InvalidString (objForm['UserName' + strSuffix].value,
      'your' + strKind + ' user name', 2, 16, '0123456789', true);
    }

// ==============================================================================

function LDCC_LeagueAgeLevelChange (strSelect, League) {

    var strAssociation = $('#Association' + strSelect).val();
    var strAgeLevel = $('#AgeLevel' + strSelect).val();
    if ((strAssociation == '') || (strAgeLevel == ''))
      $('#Team' + strSelect).html('');
    else LDCC_SelectFill ('#Team' + strSelect, 'LeagueTeam', '', strAgeLevel,
      strAssociation, '', BLANK_OPTION, League);
    }

// ==============================================================================

function LDCC_LeagueAssociationChange (strSelect, League) {

    $('#Team' + strSelect).html('');
    var strAssociationID = $('#Association' + strSelect).val();
    if (strAssociationID == '') $('#AgeLevel' + strSelect).html('');
    else LDCC_SelectFill (('#AgeLevel' + strSelect), 'LeagueAgeLevel', '',
      strAssociationID, League, '', BLANK_OPTION);
    }

// ==============================================================================

// objOptions
//   Buttons:  arrays of [name, class, callback]
//   Header: string
//   Image: 'OK', 'Mail', 'Inform', 'Warning', 'Error', ''
//   Message: string (HTML)

function LDCC_ModalBox (objOptions) {

    var strHeader = '';
    switch(objOptions.Image) {
        case 'OK':
            strHeader =
              '<IMG src="../images/info.png" align="left" alt="OKAY">';
            if (objOptions.Header == null) objOptions.Header = 'Notice';
            break;
        case 'Mail':
            strHeader =
              '<IMG src="../images/info.png" align="left" alt="MAIL">';
            if (objOptions.Header == null) objOptions.Header = 'Sent Mail';
            break;
        case 'Inform':
            strHeader =
              '<IMG src="../images/info.png" align="left" alt="INFORM">';
            if (objOptions.Header == null) objOptions.Header = 'Notice';
            break;
        case 'Warning':
            strHeader =
              '<IMG src="../images/warn.png" align="left" alt="WARNING"' +
                ' margin="0 20px 0 0;">';
            if (objOptions.Buttons == null)
              objOptions.Buttons = [['Yes', null, null], ['No', null, null]];
            if (objOptions.Header == null) objOptions.Header = 'Warning';
            break;
        case 'Error':
            strHeader =
              '<IMG src="../images/error.png" align="left" alt="ERROR"' +
                ' margin="0 100px 0 0;">';
            if (objOptions.Buttons == null)
              objOptions.Buttons = [['Fix Errors', null, null]];
            if (objOptions.Header == null) objOptions.Header = 'Error';
            break;
        default:
            strHeader = '';
            break;
        }
    if (objOptions.Header != null) strHeader += objOptions.Header;
    var strMessage = (objOptions.Message != null) ? objOptions.Message : '';
    if (objOptions.Buttons == null)
      objOptions.Buttons = [['OK', null, null]];
    var strButtons = '';
    for (intX in objOptions.Buttons) {
        var strText = objOptions.Buttons[intX][0];
        var strClass = (objOptions.Buttons[intX][1] != null) ?
          objOptions.Buttons[intX][1] : 'simplemodal-close';
        var strClick = (objOptions.Buttons[intX][2] != null) ?
          objOptions.Buttons[intX][2] : '';
        var strName = strText.replace(/ /g, '');
        strButtons +=
          //strText + strName;
          '<INPUT type=\'image\' src="../images/button/' + strName +
          '.png" alt=\'' + strText + '\' ' + 'class=\'' + strClass + '\' ' +
          'onMouseOut=\'this.src="../images/button/' + strName +
          '.png"\' border=\'0\' ' + strClick +
          'onMouseOver=\'this.src="../images/button/' + strName +
          'Focus.png"\' style=\'margin: 0 0 0 5px;\'/>';
        }
    if (strHeader != '')
      strHeader = '<DIV id=\'ModalHeader\'>' + strHeader + '</DIV>';
    if (strMessage != '')
      strMessage = '<DIV id=\'ModalMessage\'>' + strMessage + '</DIV>';
    if (strButtons != '')
      strButtons = '<DIV id=\'ModalButtons\'>' + strButtons + '</DIV>';
    //alert(strHeader + '\r\n' + strMessage + '\r\n' + strButtons);
    var strContent =
      '<DIV id=\'modal\'>' + strHeader + strMessage + strButtons + '</DIV>';
    var strTop = (objOptions.Top != null) ? objOptions.Top : '10%';
    var strLeft = (objOptions.Left != null) ? objOptions.Left : '10%';
    var strWidth = (objOptions.Width != null) ? objOptions.Width : '450px';
    $.modal(strContent, {containerCss: ({width: strWidth}),
                         containerId: 'ModalContainer',
                         overlayId:   'ModalOverlay',
                         position:    [strTop, strLeft]});
    return false;
    }

// ==============================================================================

  function LDCC_PleaseWait (intStripes) {

      var intHeight = (arguments.length < 1) ? 10 : intStripes;
      return LDCC_PleaseWaitMessage ('&nbsp;Please Wait&nbsp;', intHeight);
      }

// ==============================================================================

  function LDCC_PleaseWaitMessage (strDisplayMessage, intStripes) {

      var intHeight = (arguments.length < 2) ? 10 : intStripes;
      var strStripes = (intHeight <= 0) ? '' :
        ('<TR height="' + intHeight + '">' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD><TD BGCOLOR="white"></TD>' +
           '<TD></TD>' +
           '</TR>');
      var strHTML =
        '<SPAN style="float: left">' +
        '<TABLE bgcolor="black" align="top" border="0" cellspacing="0">' +
          '<COLGROUP width="20" span="13" />' +
          strStripes +
          '<TR height="4">' +
            '<TD colspan="13"></TD>' +
            '</TR>' +
          '<TR>' +
            '<TD colspan="13" bgcolor="#FF6200"' +
                ' align="center" valign="top"' +
                ' style="margin: 0; font-size: 25px">' +
              '<B>&nbsp;&nbsp;' + strDisplayMessage + '&nbsp;&nbsp;</B>' +
              '</TD>' +
            '</TR>' +
          '<TR height="4"><TD colspan="13"></TD>' +
            '</TR>' +
          strStripes +
          '</TABLE></SPAN>';
      return strHTML;
      }

// ==============================================================================

function LDCC_PreloadImage (arrImage) {

    $(arrImage).each(function () {
        var imgLoad = new Image();
        imgLoad.src = '../images/' + this;
        });
    }

// ==============================================================================

function LDCC_SelectFill (strSelect, strSource, strSelected, strParent,
                          strGrandParent, strWhere, intOptions,
                          strGreatGrandParent) {

    $('select' + strSelect).html('');
    var intValueOnly = ((intOptions & VALUE_ONLY) == VALUE_ONLY) ? 1 : 0;
    if (arguments.length > 7) strGreatGrandParent = arguments[7];
    else strGreatGrandParent = "";
    var strAction = 'action=SelectFill' +
                    '&Source='           + strSource +
                    '&Selected='         + strSelected +
                    '&Parent='           + strParent +
                    '&GrandParent='      + strGrandParent +
                    '&Where='            + strWhere +
                    '&ValueOnly='        + intValueOnly +
                    '&GreatGrandParent=' + ((arguments.length < 8) ? '' :
                                            strGreatGrandParent);
    $.ajax({
      type: 'POST',
      url: '../serv/AjaxServer.php',
      data: strAction,
      success: function (strResponse) {
          var objResponse = eval('(' + strResponse + ')');
          var strStatus = objResponse.status;
          if (strStatus == 'OK') {
              var intS = -1;
              var intO = 0;
              if ((intOptions & BLANK_OPTION) == BLANK_OPTION) {
                  $('select' + strSelect)
                    .append('<OPTION value=""></OPTION>');
                  if (strSelected == '') intS = intO;
                  intO++;
                  }
              for (var intX = 0; intX < objResponse.options.length; intX++) {
                  switch (objResponse.options[intX][3]) {
                      case 'O':
                          var strValue = objResponse.options[intX][0];
                          $('select' + strSelect).append('<OPTION value="' +
                            strValue + '"' + objResponse.options[intX][2] + '>' +
                            objResponse.options[intX][1] + '</OPTION>');
                          if (strValue == strSelected) intS = intO;
                          intO++;
                          break;
                      case 'G':
                          $('select' + strSelect).append('<OPTGROUP label="' +
                            objResponse.options[intX][1] + '"' +
                            objResponse.options[intX][2] + '>');
                          break;
                      case 'E':
                          $('select' + strSelect).append('</OPTGROUP>');
                          break;
                      }
                  }
              if (intS >= 0)
                $('select' + strSelect).each(function () {
                    this.selectedIndex = intS;
                    if (intValueOnly == 1) this.disabled = true;
                    });
              }
          else alert(strStatus);
          }
      });
    }

// ==============================================================================

function LDCC_SelectYear (strSelect, arrBefore, arrAfter, intSelelctedValue,
                          arrBefore, arrAfter, strText, intOptions) {

    $('select' + strSelect).html('');
    var datNow = new Date();
    var intYear = datNow.getFullYear();
    var intSelected = -1;
    var intCurrent = -1;
    if ((intOptions & BLANK_OPTION) == BLANK_OPTION) {
        intCurrent++;
        $('select' + strSelect).append('<OPTION value=""></OPTION>');
        }
    for (var ix = 0; ix < arrBefore.length; ix++) {
        intCurrent++;
        var intValue = arrBefore[ix][0];
        if (intValue == intSelectedValue) intSelelcted = intCurrent;
        $('select' + strSelect).append('<OPTION value="' + intValue + '">' +
          arrBefore[ix][1] + '</OPTION>');
        }
    for (ix = (intYear - intBefore); ix <= (intYear + intAfter); ix++) {
        intCurrent++;
        if (ix == intSelectedValue) intSelelcted = intCurrent;
        $('select' + strSelect).append('<OPTION value="' + ix + '">' +
          strText + ix + '</OPTION>');
        }
    for (var ix = 0; ix < arrAfter.length; ix++) {
        intCurrent++;
        var intValue = arrAfter[ix][0];
        if (intValue == intSelectedValue) intSelelcted = intCurrent;
        $('select' + strSelect).append('<OPTION value="' + intValue + '">' +
          arrAfter[ix][1] + '</OPTION>');
        }
    }

// ==============================================================================

function LDCC_SendMail (strSubject, strTo, strCC, strBCC) {

    var strLinkTo = 'mailto:' + strTo;
    var strSeparator = '?';
    if (strCC != '') {
        strLinkTo += strSeparator + 'cc=' + strCC;
        strSeparator = '&';
        }
    if (strBCC != '') {
        strLinkTo += strSeparator + 'bcc=' + strBCC;
        strSeparator = '&';
        }
    if (strSubject != '') {
        strLinkTo += strSeparator + 'subject=' + strSubject;
        strSeparator = '&';
        }
    window.open(strLinkTo);
    }

// ==============================================================================

function LDCC_SendTo (strSubject, strTo, strToAt, strToCom, strCC, strCCAt,
                      strCCCom) {

    if (strToAt == '') var strISP = 'DCHOA.org';
    else var strISP = strToAt + '.' + strToCom;
    var strLinkTo = 'mailto:' + strTo + '@' + strISP;
    var strSeparator = '?';
    if (strCC != '') {
        if (strCCAt == '') strISP = 'DCHOA.org';
        else strISP = strCCAt + '.' + strCCCom;
        strLinkTo += strSeparator + 'cc=' + strCC + '@' + strISP;
        strSeparator = '&';
        }
    if (strSubject != '') {
        strLinkTo += strSeparator + 'subject=' + strSubject;
        strSeparator = '&';
        }
    window.open(strLinkTo);
    }

// ==============================================================================

function LDCC_SentAt() {

    var arrMonths = new Array('January', 'February', 'March', 'April', 'May',
      'June', 'July', 'August', 'September', 'October', 'November', 'December');
    var arrWeekdays = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday',
      'Thursday', 'Friday', 'Saturday');

    var datNow = new Date();
    var intHour = datNow.getHours();
    var intMinutes = datNow.getMinutes();
    var strHalf = 'PM';
    if (intHour > 12) {
        intHour -= 12;
        if (intHour == 12) strHalf = 'AM';
        }
    else if (intHour < 12) strHalf = 'AM';
    return arrWeekdays[datNow.getDay()] + ', ' +
      arrMonths[datNow.getMonth()] + ' ' + datNow.getDate() + ', ' +
      datNow.getFullYear() + ' ' + intHour + ':' +
        ((intMinutes < 10) ? '0' : '') + intMinutes + ' ' + strHalf;
    }

// ============================================================================

Holidays = [[1, 1, -1, 'US'],          // New Years Day
            [1, 16, 2009, 'US'],       // Martin Luther King Day
            [5, 25, 2009, 'US'],       // Memorial Day
            [7, 4, -1, 'Fourth'],      // Fourth of July
            [9, 7, 2009, 'US'],        // Labor Day
            [11, 27, 2008, 'US'],      // Thanksgiving
            [12, 24, -1, 'Christmas'], // Christmas Eve
            [12, 25, -1, 'Christmas'], // Christmas Day
            [12, 31, -1, 'US']];       // New Years Eve

function LDCC_ShowHolidays (date) {

    for (var i = 0; i < Holidays.length; i++) {
        if (date.getMonth() == (Holidays[i][0] - 1)) {
            if (date.getDate() == Holidays[i][1]) {
                if ((Holidays[i][2] == -1) ||
                    (date.getFullYear() == Holidays[i][2]))
                  return [true, Holidays[i][3] + '_day'];
                }
            }
        }
    return [true, ''];
    }

// ==============================================================================

function LDCC_StatusLine (strMessage) {

    window.status = strMessage;
    }

// ==============================================================================

function LDCC_ValueString (strBefore, strSelect, blnSendEmpty, strBetween) {

    var arrFields = new Array();
    $(strSelect).each(function () {
        switch (this.type) {
            case 'text':
            case 'textarea':
            case 'hidden':
            case 'password':
            case 'FileUpload':
                if ((this.value != '') || blnSendEmpty)
                  arrFields.push(encodeURIComponent(this.name) + '=' +
                    encodeURIComponent(this.value));
                break;
            case 'radio':
            case 'checkbox':
                if (this.checked)
                  arrFields.push(
                    encodeURIComponent(this.name) + '=' +
                    encodeURIComponent(this.value));
                break;
            case 'select-one':
                var intIndex = (this.selectedIndex) ? this.selectedIndex : 0;
                var strName = this.name;
                if ((intIndex >= 0) && (intIndex < this.options.length)) {
                    var strValue = this.options[intIndex].value;
                    arrFields.push(encodeURIComponent(strName) + '=' +
                      encodeURIComponent(strValue));
                    strName += 'Text';
                    strValue = this.options[intIndex].text;
                    arrFields.push(encodeURIComponent(strName) + '=' +
                      encodeURIComponent(strValue));
                    }
                else
                  arrFields.push(encodeURIComponent(strName) + '=' +
                    encodeURIComponent("ix out of range"));
/*
                if (this.selectedIndex) {
                    var intIndex = this.selectedIndex;
                    if ((intIndex >= 0) && (intIndex < this.options.length)) {
                        var strName = this.name;
                        var strValue = this.options[intIndex].value;
                        arrFields.push(encodeURIComponent(strName) + '=' +
                          encodeURIComponent(strValue));
                        strName += 'Text';
                        strValue = this.options[intIndex].text;
                        arrFields.push(encodeURIComponent(strName) + '=' +
                          encodeURIComponent(strValue));
                        }
                    else
                      arrFields.push(encodeURIComponent(this.name) + '=' +
                        encodeURIComponent("ix out of range"));
                    }
                else
                  arrFields.push(encodeURIComponent(this.name) + '=' +
                    encodeURIComponent("ix undefined"));
*/
                break;
            case 'select-multiple':
                for (var intS = 0;
                  intS < this.options.length; intS++) {
                    if (this.options[intS].selected) {
                        if(this.options[intS].value == '')
                          arrFields.push(
                            encodeURIComponent(this.name) + '=' +
                            encodeURIComponent(this.options[intS].text));
                        else
                          arrFields.push(encodeURIComponent(this.name) + '=' +
                            encodeURIComponent(this.options[intS].value));
                        }
                    }
                break;
            default:
                break;
            }
        });
    var strSeparate = (arguments.length < 4) ? '&' : strBetween;
    return strBefore + arrFields.join(strSeparate);
    }

// ==============================================================================

function LDCC_View (strNewPage, intWinType, strWindowName, strProperties) {

    if (intWinType == 1) // Same window
        document.location.href = LDCC_ExpandName (strNewPage);
    else if (intWinType == 2) // Special popup
        window.open(LDCC_ExpandName (strNewPage), strWindowName, strProperties);
    else if (intWinType == 3) { // Restricted new window
        if (strProperties == '') var objNewWin =
          window.open('', strWindowName, 'scrollbars,resizable=yes');
        else var objNewWin = window.open('', strWindowName, strProperties);
        objNewWin.document.open();
        if (strWindowName == '') var strTitle = '';
        else var strTitle = strWindowName.replace('_', ' ') + ' - ';
        objNewWin.document.write('<html><head>' + '<title>' + Title +
          'Dane County Hockey Officials Association</title>' +
          '<meta http-equiv="Content-Type"' +
          ' content="text/html; charset=iso-8859-1" /></head>');
        objNewWin.document.write(
          '<frameset cols="1,*" border="0">' +
            '<frame marginwidth="0" marginheight="0" border="0">' +
              '<frame src="' + LDCC_ExpandName (strNewPage) +
              '" marginwidth="0" marginheight="0">' +
              '</frameset>' +
            '</html>');
        objNewWin.document.close();
        }
    else { // Unrestricted new window
        if (strWindowName == '') {
            if (strProperties == '') window.open(LDCC_ExpandName (strNewPage));
            else window.open(LDCC_ExpandName (strNewPage), '', strProperties);
            }
        else
          window.open(LDCC_ExpandName (strNewPage), strWindowName,
            strProperties);
        }
    }

// ==============================================================================

$(document).ready(function() {

    $('.HiLightBack')
      .mouseover(function () {
          $(this).addClass('HiLight');
          })
      .mouseout(function () {
          $(this).removeClass('HiLight');
          });
    $('.HelpButton')
      .attr('src', '../images/Help5.bmp')
      .mouseover(function () {
          $(this).attr('src', '../images/Help5R.bmp').css({cursor: 'help'});
          })
      .mouseout(function () {
          $(this).attr('src', '../images/Help5.bmp');
          })
    $('DIV.PanelButtonLink')
      .mouseover(function () {
          $(this).css({backgroundPosition: '0 -27px'});
          })
      .mouseout(function () {
          $(this).css({backgroundPosition: '0 0'});
          })
/*
      .mouseover(function () {
          $(this).css({backgroundImage:
            "url(../images/button/PanelButtonFocus.png)", cursor: "pointer"});
          })
      .mouseout(function () {
          $(this).css({backgroundImage:
            "url(../images/button/PanelButton.png)"});
          });
*/
    $('.Linker') // Find all Linker elements
/*
      .mouseover(function () {
          window.status = this.title;
          return true;
          })
      .mouseout(function () {
          window.status = 'Done';
          return true;
          })
*/
      .filter('<IMG>').attr('border', 0)
      .end().filter('.DocLink') // Find all DocLink elements
        .wrap('<A class="LinkNoUnderline" href=""></A>')
        .hover(
          function () { $(this).addClass('ExternalOver'); },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strTarget = $(this).data().XTarget;
            if (strTarget) strTarget = LDCC_ExpandName (strTarget);
            else strTarget = 'about:blank';
            var strName = $(this).data().XName;
            if (! strName) strName = '';
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = '';
            window.open(strTarget, strName, strWindow);
            })
      .end().filter('.ExternalLink') // Find all ExternalLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () { $(this).addClass('ExternalOver'); },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strTarget = $(this).data().XTarget;
            if (strTarget) strTarget = LDCC_ExpandName (strTarget);
            else strTarget = 'about:blank';
            var strName = $(this).data().XName;
            if (! strName) strName = '';
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = '';
            window.open(strTarget, strName, strWindow);
            })
      .end().filter('.HelpLink') // Find all HelpLink elements
        .attr('src', '../images/Help5.bmp')
        .css('cursor', 'help')
        //.attr('border', 0)
        .hover(
          function () { $(this).attr('src', '../images/Help5R.bmp'); },
          function () { $(this).attr('src', '../images/Help5.bmp'); })
        .click(function () {
            $.meta.setType('class');
            var strTopic = $(this).data().XTopic;
            if (! strTopic) strTopic = 'Unknown';
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = 'resizable,scrollbars,' +
              'width=400,height=400,left=100,top=100';
            window.open('../misc/PopupHelpItem.php?Topic=' + strTopic, strTopic,
              strWindow);
            })
      .end().filter('.InternalLink') // Find all InternalLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () { $(this).addClass('InternalOver'); },
          function () { $(this).removeClass('InternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strTarget = $(this).data().XTarget;
            if (! strTarget) strTarget = '';
/*
            window.open('../misc/PopupHelpItem.php?Topic=' + strTopic, strTopic,
              strWindow);
*/
            })
      .end().filter('.MailLink') // Find all MailLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () { $(this).addClass('ExternalOver'); },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strSubject = $(this).data().XSubject;
            if (! strSubject) strSubject = '';
            var strTo = $(this).data().XToName + '@' +
              $(this).data().XToHost;
            var strCC = $(this).data().XCCName;
            if (strCC) strCC = strCC + '@' + $(this).data().XCCHost;
            else strCC = '';
            var strBCC = $(this).data().XBCCName;
            if (strBCC) strbCC = strbCC + '@' + $(this).data().XBCCHost;
            else strBCC = '';
            LDCC_SendMail (strSubject, strTo, strCC, strBCC);
            })
      .end().filter('.MapLink') // Find all MapLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () {
              $(this).addClass('ExternalOver');
              $.meta.setType('class');
              var strMessage = $(this).data().XStatus;
              if (! strMessage) strMessage = '';
              //LDCC_StatusLine (strMessage);
              //window.status = strMessage;
              },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strAddress = $(this).data().XValue;
            if (! strAddress) strAddress = '';
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = '';
            window.open('http://www.maps.google.com?q=' + strAddress, '',
              'scrollbars,resizable,menubar,' +
              'top=50,left=50,height=550,width=750');
            return false;
            })
      .end().filter('.NewsLink') // Find all NewsLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () {
              $(this).addClass('ExternalOver');
              $.meta.setType('class');
              var strMessage = $(this).data().XStatus;
              if (! strMessage) strMessage = '';
              LDCC_StatusLine (strMessage);
              },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            var strTitle = $(this).data().XTitle;
            if (! strTitle) strTitle = '';
            var strTarget = $(this).data().XTarget;
            if (strTarget) strToDo = '{N}PopupNewsItem.php?Topic=' + strTarget;
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = '';
            window.open(LDCC_ExpandName (strToDo), strTitle, strWindow);
            })
      .end().filter('.PopupLink') // Find all PopupLink elements
        .wrap('<A href=""></A>')
        .hover(
          function () { $(this).addClass('ExternalOver'); },
          function () { $(this).removeClass('ExternalOver'); })
        .click(function () {
            $.meta.setType('class');
            strLead = '?';
            var strTodo = '{M}PopupItem.php';
            var strProp = $(this).data().XNoSave;
            if (strProp) {
                strToDo = strToDo + strLead + 'NoSave=';
                strLead = '&';
                }
            var strTitle = $(this).data().XTitle;
            if (strTitle) {
                strToDo = strDoDo + strLead + 'Title=' + strTitle;
                strLead = '&';
                }
            else strTitle = '';
            var strTarget = $(this).data().XTarget;
            if (strTarget) strToDo = strToDo + strLead + 'Todo=' + strTarget;
            var strWindow = $(this).data().XWindow;
            if (! strWindow) strWindow = '';
            window.open(LDCC_ExpandName (strToDo), strTitle, strWindow);
            });
    });
