// Validation.js

// ==============================================================================
// Copyright © 2001-2004, 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 the prior permission of LDCC.
// ==============================================================================

// ==============================================================================

function ExpandName(Name) {

    MyRegExp = /{DOL}/;
    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 GoNew (NewPage, WindowName, Properties) {

    if (WindowName == "")
        window.open(ExpandName (NewPage));
    else {
        MyProperties = Properties;
        if (MyProperties == '') MyProperties = 'status=no toolbar=no' +
          ' menubar=no location=no resizable=yes scrollbars=yes';
        newWin = window.open('', WindowName, MyProperties);
        newWin.document.open();
        newWin.document.write('<HTML><HEAD>' + '<TITLE>' +
          WindowName.replace('_', ' ') +
          ' - Dane County Hockey Officials Association</TITLE>' +
          '<META http-equiv="Content-Type"' +
          ' content="text/html; charset=iso-8859-1"></head>');
        newWin.document.write(
          '<FRAMESET cols="1,*" border=0>' +
            '<FRAME marginwidth=0 marginheight=0 border=0>' +
              '<FRAME src="' + ExpandName (NewPage) +
              '" marginwidth=0 marginheight=0>' +
              '</FRAMESET>' +
            '</HTML>');
        newWin.document.close();
        }
    }

// ==============================================================================

function GoPage (NewPage) {

    parent.fraMain.location.href = ExpandName(NewPage);
    }

// ==============================================================================

function GoWin (NewPage, WindowName) {

    if (WindowName == "")
        window.open(ExpandName (NewPage));
    else {
        newWin = window.open('', WindowName,
          'status=no toolbar=no menubar=no location=no resizable=yes' +
          ' scrollbars=yes');
        newWin.document.open();
        newWin.document.write('<html><head>' +
          '<title>Dane County Hockey Officials Association</title>' +
          '<meta http-equiv="Content-Type"' +
          ' content="text/html; charset=iso-8859-1"></head>');
        newWin.document.write(
          '<frameset cols="1,*" border=0>' +
            '<frame marginwidth=0 marginheight=0 border=0>' +
              '<frame src="' + ExpandName (NewPage) +
              '" marginwidth=0 marginheight=0>' +
              '</frameset>' +
            '</html>');
        newWin.document.close();
        }
    }

// ==============================================================================

function InvalidAddress(Suffix, form, required) {

    if (form["Address" + Suffix].value == "") {
        if (required) {
            alert("You must include the street.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["Address" + Suffix].value, "the street",
      1, 35, "'.-,# 0123456789", true);
    }

// ==============================================================================

function InvalidAgeClassification(Suffix, form, required) {

    if ((form["AgeClassification" + Suffix].value == "") && (required)) {
        switch (Suffix) {
            case "1":
                alert("You must include the first age level.");
                break;
            case "2":
                alert("You must include the second age level.");
                break;
            default:
                alert("You must include the age level.");
                break;
            }
        return true;
        }
    else {
        form["AgeClassification" + Suffix + "Name"].value =
          form["AgeClassification" +
          Suffix].options[form["AgeClassification" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidAgeLevel(Suffix, form, required) {

    if ((form["Level" + Suffix].value == "") && (required)) {
        alert("You must include the level.");
        return true;
        }
    else {
        form["Level" + Suffix + "Name"].value =
          form["Level" +
          Suffix].options[form["Level" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidAssociationID(Suffix, form, required) {

    if ((form["AssociationID" + Suffix].value == "") && (required)) {
        switch (Suffix) {
            case "1":
                alert("You must include the first association.");
                break;
            case "2":
                alert("You must include the second association.");
                break;
            default:
                alert("You must include the association.");
                break;
            }
        return true;
        }
    else {
        form["AssociationID" + Suffix + "Name"].value =
          form["AssociationID" +
          Suffix].options[form["AssociationID" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidAuxAddress(Suffix, form, required) {

    if (form["AuxAddress" + Suffix].value == "") {
        if (required) {
            alert("You must include the second line of the street.");
            return true;
            }
        else return false;
        }
    else if (form["Address" + Suffix].value == "") {
        form["Address" + Suffix].value = form["AuxAddress" + Suffix].value;
        form["AuxAddress" + Suffix].value = "";
        return InvalidAddress(Suffix, form, required);
        }
    else return InvalidString(form["AuxAddress" + Suffix].value,
      "the second line of the street", 1, 35, "'.-,# 0123456789", true);
    }

// ==============================================================================

function InvalidBusinessPhone(Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Business" + Suffix, required, "your work phone",
                        true, separatefields);
    }

// ==============================================================================

function InvalidCity(Suffix, form, required) {

    if (form["City" + Suffix].value == "") {
        if (required) {
            alert("You must include the city.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["City" + Suffix].value, "the city", 1, 35,
      "'.-,# ", true);
    }

// ==============================================================================

function InvalidCoachName(Suffix, form, required) {

    if ((form["CoachName" + Suffix].value == "") && (required)) {
        alert("You must include the coach's name.");
        return true;
        }
    else return false;
    }

// ==============================================================================

function InvalidComments(Suffix, form, required, minlength, maxlength) {

    if (form["Comments" + Suffix].value == "") {
        if (required) {
            alert("You must include your comments.");
            return true;
            }
        else return false;
        }
    else if (form["Comments" + Suffix].value.length < minlength) {
        alert("Your comments must contain at least " + minlength +
          " characters.");
        return true;
        }
    else if ((maxlength != 0) && (form["Comments" + Suffix].value.length >
      maxlength)) {
        alert("Your comments may not exceed " + maxlength + " characters.");
        return true;
        }
    else return false;
    }

// ==============================================================================

function InvalidDate(Suffix, form, required) {

    if ((form["Date" + Suffix].value == "") && (required)) {
        alert("You must include the date.");
        return true;
        }
    else return false;
    }

// ==============================================================================

function InvalidDCHOA(Suffix, form, required) {

    var min = 1;
    if (required) min = -1;
    return InvalidString(form["DCHOA" + Suffix].value, "your DCHOA number",
      min, 5, "0123456789", false);
    }

// ==============================================================================

function InvalidEmail(Suffix, form, required) {

    if (form["Email" + Suffix].value.length > 96) {
        alert("Your email address may not be more than 96 characters.");
        return true;
        }
    else {
        var isvalid = 0;
        if (form["Email" + Suffix].value == "") {
            if (required) {
                alert("You must enter your email address.");
                return true;
                }
            else return false;
            }
        else if ((form["Email" + Suffix].value.indexOf (" ")) > -1) isvalid = 0;
        else {
            // are regular expressions supported?
            var supported = 0;
            if (window.RegExp) {
                var tempStr = "a";
                var tempReg = new RegExp(tempStr);
                if (tempReg.test(tempStr)) supported = 1;
                }
            if (!supported)
                isvalid = (form["Email" + Suffix].value.indexOf(".") > 2) &&
                          (form["Email" + Suffix].value.indexOf("@") > 0);
            else {
                var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
                var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+" +
                                    "\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
                isvalid = (!r1.test(form["Email" + Suffix].value) &&
                           r2.test(form["Email" + Suffix].value));
                }
            }
        if (!isvalid) {
            alert("That is not a valid email address.");
            return true;
            }
        else return false;
        }
    }

// ==============================================================================

function InvalidFaxPhone (Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Fax" + Suffix, required, "your fax number", false,
                        separatefields);
    }

// ==============================================================================

function InvalidFirstName (Suffix, form, required) {

    if (form["FirstName" + Suffix].value == "") {
        if (required) {
            alert("You must include your first name.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["FirstName" + Suffix].value,
      "your first name", 1, 15, "'.-", true);
    }

// ==============================================================================

function InvalidFullName (Suffix, form, required) {

    var str = form["FullName" + Suffix].value;
    if (str == "") {
        if (required) {
            alert("You must include your full name.");
            return true;
            }
        else return false;
        }
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") return false;
        }
    alert("You must include your full name.");
    return true;
   }

// ==============================================================================

function InvalidHomePhone (Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Home" + Suffix, required, "your home phone",
      false, separatefields);
    }

// ==============================================================================

function InvalidHourMinuteAMPM(Suffix, form, required) {

    var hour = form["Hour" + Suffix].value;
    var minute = form["Minute" + Suffix].value;
    var ampm = form["AMPM" + Suffix].value;

    if ((hour + minute + ampm) == "") {
        if (required) {
            alert("You must enter a time.");
            return true;
            }
        else {
            form["Time" + Suffix].value = "";
            return false;
            }
        }
    else if (hour == "") {
        alert ("You must specify the hour.");
        return true;
        }
    else if (minute == "") {
        alert ("You must specify the minutes.");
        return true;
        }
    else if (ampm == "") {
        alert ("You must specify AM or PM.");
        return true;
        }
    else {
        if (hour.length == 1) hour = '0' + hour;
        if (minute.length == 1) minute = '0' + minute;
        form["Time" + Suffix].value = hour + ":" + minute + " " + ampm;
        return false;
        }
   }

// ==============================================================================

function InvalidLastName(Suffix, form, required) {

    if (form["LastName" + Suffix].value == "") {
        if (required) {
            alert("You must include your last name.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["LastName" + Suffix].value,
      "your last name", 1, 24, "-.,' ", true);
    }

// ==============================================================================

function InvalidLeague(Suffix, form, required) {

    if ((form["League" + Suffix].value == "") && (required)) {
        alert("You must include the league.");
        return true;
        }
    else {
        form["League" + Suffix + "Name"].value =
          form["League" +
          Suffix].options[form["League" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidLength(Suffix, form, required) {

    if ((form["Length" + Suffix].value == "") && (required)) {
        alert("You must include the game length.");
        return true;
        }
    else return false;
   }

// ==============================================================================

function InvalidLevel(Suffix, form, required) {

    if ((form["Level" + Suffix].value == "") && (required)) {
        switch (Suffix) {
            case "1":
                alert("You must include the first USA Hockey Level.");
                break;
            case "2":
                alert("You must include the second USA Hockey Level.");
                break;
            default:
                alert("You must include your USA Hockey Level.");
                break;
            }
        return true;
        }
    else {
        form["Level" + Suffix + "Name"].value = form["Level" +
          Suffix].options[form["Level" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidLinesman(Suffix, form, required) {

    if ((form["Linesman" + Suffix].value == "") && (required)) {
        alert("You must include the linesman's name.");
        return true;
        }
    else return false;
   }

// ==============================================================================

function InvalidLocation(Suffix, form, required) {

    if ((form["Location" + Suffix].value == "") && (required)) {
        alert("You must include the rink.");
        return true;
        }
    else {
        form["Location" + Suffix + "Name"].value =
          form["Location" +
          Suffix].options[form["Location" + Suffix].selectedIndex].text;
        return false;
        }
    }

// ==============================================================================

function InvalidMailAddress (Suffix, form, required, description) {

    if (InvalidAddress (Suffix, form, false)) return true;
    if (InvalidAddress ('2' + Suffix, form, false)) return true;
    Address = form['Address' + Suffix].value;
    Address2 = form['Address2' + Suffix].value;
    if (Address == '') {
        if (Address2 != '') {
            form['Address' + Suffix].value = form['Address2' + Suffix].value;
            form['Address2' + Suffix].value = '';
            }
        }
    if (Address == '') {
        if (required) {
            alert('You must include the ' + description + ' street.');
            return true;
            }
        }
    if (InvalidCity (Suffix, form, required)) return true;
    City = form['City' + Suffix].value;
    if (City == '') {
        if (Address != '') {
            alert('You must include the ' + description + ' city.');
            return true;
            }
        }
    else if (Address == '') {
        alert('You must include the ' + description + ' street.');
        return true;
        }
    if (InvalidState (Suffix, form, required)) return true;
    State = form['State' + Suffix].value;
    if (State == '') {
        if (City != '') {
            alert('You must include the ' + description + ' state.');
            return true;
            }
        }
    else if (City == '') {
        alert('You must include the ' + description + ' city.');
        return true;
        }
    if (InvalidZip (Suffix, form, required, description + ' zip code', true))
      return true;
    Zip = form["Zip" + Suffix].value;
    if (Zip == '') {
        if (State != '') {
            alert('You must include the ' + description + ' zip code.');
            return true;
            }
        }
    else if (State == '') {
        alert('You must include the ' + description + ' state.');
        return true;
        }
    return false;
    }

// ==============================================================================

function InvalidMiddleName(Suffix, form, required) {

    if (form["MiddleName" + Suffix].value == "") {
        if (required) {
            alert("You must include your middle name.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["MiddleName" + Suffix].value,
      "your middle name", 1, 15, "-.'", true);
    }

// ==============================================================================

function InvalidMobilePhone(Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Mobile" + Suffix, required, "your mobile phone",
                        false, separatefields);
    }

// ==============================================================================

function InvalidMonthDayYear(Suffix, form, required, allowed) {

    var month = form["Month" + Suffix].value + '';
    var day = form["Day" + Suffix].value + '';
    var year = form["Year" + Suffix].value + '';

    if ((month + day + year) == "") {
        if (required) {
            alert("You must enter a " + Suffix + "date.");
            return true;
            }
        else {
            form["Date" + Suffix].value = "";
            return false;
            }
        }
    else if (month == "") {
        alert("You must specify the " + Suffix + "month.");
        return true;
        }
    else if (day == "") {
        alert("You must specify the " + Suffix + "day.");
        return true;
        }
    else if (year == "") {
        alert("You must specify the " + Suffix + "year.");
        return true;
        }
    if (month.length == 1) month = '0' + month;
    if (day.length == 1) day = '0' + day;
    var date = new Date(month + "/" + day + "/" + year);
    if (date.getMonth() != (month - 1)) {
        alert ("That is not a valid " + Suffix + "day.");
        return true;
        }
    var today = new Date();
    var checkdate = new Date((today.getMonth() + 1) + "/" + today.getDate() +
      "/" + today.getFullYear());
    if (date < checkdate) {
        if (allowed.indexOf("P") == -1) {
            alert("You may not specify a " + Suffix + "date in the past.");
            return true;
            }
        else {
            form["Date" + Suffix].value = year + "-" + month + "-" + day;
            return false;
            }
        }
    else if (date > checkdate) {
        if (allowed.indexOf("F") == -1) {
            alert("You may not specify a " + Suffix + "date in the future.");
            return true;
            }
        else {
            form["Date" + Suffix].value = year + "-" + month + "-" + day;
            false;
            }
        }
    else {
        if (allowed.indexOf("T") == -1) {
            alert("You may not specify today.");
            return true;
            }
        else {
            form["Date" + Suffix].value = year + "-" + month + "-" + day;
            return false;
            }
        }
   }

// ==============================================================================

function InvalidOtherPhone(Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Other" + Suffix, required, "your other phone",
                        false, separatefields);
    }

// ==============================================================================

function InvalidPagerPhone(Suffix, form, required, separatefields) {

    return InvalidPhone(form, "Pager" + Suffix, required, "your fax number",
                        false, separatefields);
    }

// ==============================================================================

function InvalidPassword(Suffix, form, required) {

    switch (Suffix) {
        case "":
            kind = "";
            break;
        case "Confirm":
            kind = " confirmation of your new";
            break;
        default:
            kind = " " + Suffix.toLowerCase();
        }
    if (form["Password" + Suffix].value == "") {
        if (required) {
            alert("You must include your" + kind + " password.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["Password" + Suffix].value,
      "your" + kind + " password", 6, 32, "1234567890!@#%&*-_=+^", true);
    }

// ==============================================================================

function InvalidPhone(form, strType, required, description, allowextension,
                      separatefields) {

    if (separatefields) {
        var areacode = form["Phone" + strType + "A"].value;
        var exchange = form["Phone" + strType + "E"].value;
        var phone = form["Phone" + strType + "N"].value;
        if (allowextension) var extension = form["Phone" + strType + "X"].value;
        else var extension = "";
        if ((areacode + exchange + phone + extension) == "") {
            if (required) {
                alert ("You must include " + description + ".");
                return true;
                }
            else {
                form["Phone" + strType].value = "";
                return false;
                }
            }
        else {
            if (areacode.length != 3) {
                alert (description.charAt(0).toUpperCase() +
                  description.substr(1) + " area code must be 3 digits.");
                return true;
                }
            else if (InvalidString(areacode, description + " area code", 3, 3,
              "0123456789", false)) return true;
            else if (exchange.length != 3) {
                alert (description.charAt(0).toUpperCase() +
                  description.substr(1) + " exchange must be 3 digits.");
                return true;
                }
            else if (InvalidString(exchange, description, 3, 3, "0123456789",
              false)) return true;
            else if (phone.length != 4) {
                alert (description.charAt(0).toUpperCase() +
                  description.substr(1) + " number must be 4 digits.");
                return true;
                }
            else if (InvalidString(phone, description, 4, 4, "0123456789",
              false)) return true;
            else if (InvalidString(extension, description, 0, 5, "0123456789",
              false)) return true;
            else {
                form["Phone" + strType].value = areacode + exchange + phone +
                  extension
                return false;
                }
            }
        }
    else {
        var min = 8;
        if (required) min = -8;
        if (allowextension)
          return InvalidString(form[strType + "Phone"].value, description,
                               min, 22, "0123456789-() Xx", false);
        else return InvalidString(form[strType + "Phone"].value, description,
                                  min, 14, "0123456789-() ", false);
        }
   }

// ==============================================================================

function InvalidReferee(Suffix, form, required) {

    if ((form["Referee" + Suffix].value == "") && (required)) {
        alert("You must include the referee's name.");
        return true;
        }
    else return false;
   }

// ==============================================================================

function InvalidRefereeLinesman(Suffix, form, required) {

    if ((form["RefereeLinesman" + Suffix].value == "") && (required)) {
        alert("You must include the referee/linesman's name.");
        return true;
        }
    else return false;
   }

// ==============================================================================

function InvalidRink(Suffix, form, required) {

    if ((form["Rink" + Suffix].value == "") && (required)) {
        alert("You must include the rink.");
        return true;
        }
    else {
        form["Rink" + Suffix + "Name"].value =
          form["Rink" +
          Suffix].options[form["Rink" + Suffix].selectedIndex].text;
        return false;
        }
    }

// ==============================================================================

function InvalidScore(Suffix, form, required) {

    switch (Suffix) {
        case "1":
            var identify = "score for the first team";
            break;
        case "2":
            var identify = "score for the second team";
            break;
        default:
            var identify = "score for the team";
            break;
        }
    if ((form["Score" + Suffix].value == "") && (required)) {
        alert("You must include the " + identify + ".");
        return true;
        }
    else return InvalidString(form["Score" + Suffix].value, identify,
      1, 2, "0123456789", false);
    }

// ==============================================================================

function InvalidSkillLevel(Suffix, form, required) {

    if ((form["SkillLevel" + Suffix].value == "") && (required)) {
        switch (Suffix) {
            case "1":
                alert("You must include the first skill level.");
                break;
            case "2":
                alert("You must include the second skill level.");
                break;
            default:
                alert("You must include the skill level.");
                break;
            }
        return true;
        }
    else {
        form["SkillLevel" + Suffix + "Name"].value =
          form["SkillLevel" +
          Suffix].options[form["SkillLevel" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidSSN(Suffix, form, required, separatefields) {

    if (separatefields) {
        var SSN1 = form["SSN" + Suffix + "F1"].value;
        var SSN2 = form["SSN" + Suffix + "F2"].value;
        var SSN3 = form["SSN" + Suffix + "F3"].value;
        if ((SSN1 + SSN2 + SSN3) == "") {
            if (required) {
                alert ("You must include your SSN.");
                return true;
                }
            else {
                form["SSN" + Suffix].value = "0";
                return false;
                }
            }
        else {
            if (SSN1.length != 3) {
                alert ("The first part of your SSN must be 3 digits.");
                return true;
                }
            else if (InvalidString(SSN1, "your SSN first part",
              3, 3, "0123456789", false)) return true;
            else if (SSN2.length != 2) {
                alert ("The second part of your SSN must be 2 digits.");
                return true;
                }
            else if (InvalidString(SSN2, "your SSN second part", 2, 2,
              "0123456789", false)) return true;
            else if (SSN3.length != 4) {
                alert ("The third part of your SSN must be 4 digits.");
                return true;
                }
            else if (InvalidString(SSN3, "your SSN third part", 4, 4,
              "0123456789", false)) return true;
            else {
                form["SSN" + Suffix].value = (((SSN1 * 1000000.) +
                  (SSN2 * 10000.)) + (SSN3 * 1.));
                return false;
                }
            }
        }
    else {
        var min = 11;
        if (required) min = -11;
        return InvalidString(form["SSN" + Suffix].value, "your SSN",
          min, 11, "0123456789-", false);
        }
   }

// ==============================================================================

function InvalidState(Suffix, form, required) {

    var min = 2;
    if (required) min = -2;
    return InvalidString(form["State" + Suffix].value, "the state", min, 2, "",
      true);
    }

// ==============================================================================

function InvalidString(string, description, min, max, allowed, allowalpha) {

    var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if (string == "") {
        if (min < 0) {
            alert("You must include " + description + ".");
            return true;
            }
        else return false;
        }
    else if ((string.length < Math.abs(min)) || (string.length > max)) {
        firstchar = description.charAt(0);
        alert(description.charAt(0).toUpperCase() + description.substr(1) +
          " must be from " + Math.abs(min) + " to " + max + " characters.");
        return true;
        }
    for (i = 0; i < string.length; i++) {
        if (allowed.indexOf(string.charAt(i)) == -1) {
            if ((!allowalpha) ||
                    (alpha.indexOf(string.charAt(i).toUpperCase()) == -1)) {
                alert(description.charAt(0).toUpperCase() +
                  description.substr(1) + " may not contain [" +
                  string.charAt(i) + "].");
                return true;
                }
            }
        }
    return false;
   }

// ==============================================================================

function InvalidTeamNumber(Suffix, form, required) {

    if ((form["TeamNumber" + Suffix].value == "") && (required)) {
        switch (Suffix) {
            case "1":
                alert("You must include the first team.");
                break;
            case "2":
                alert("You must include the second team.");
                break;
            default:
                alert("You must include the team.");
                break;
            }
        return true;
        }
    else {
        form["TeamNumber" + Suffix + "Name"].value =
          form["TeamNumber" +
          Suffix].options[form["TeamNumber" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidTime(Suffix, form, required) {

    field = form["Time" + Suffix].value;
    if (field == "") {
        if (required) {
            alert("You must include the time.");
            return true;
            }
        else return false;
        }
    var timePat = /^(\d{1,2}):(\d{2})?(\s?(AM|am|PM|pm))?$/;
    var aTime = field.match(timePat);
    if (aTime == null) {
        alert("Time is not in a valid format.");
        return true;
        }
    hour = aTime[1];
    if ((hour < 0) || (hour > 23)) {
        alert("Hour must be between 1 and 12.");
        return true;
        }
    minute = aTime[2];
    if ((minute < 0) || (minute > 59)) {
        alert ("Minute must be between 0 and 59.");
        return true;
        }
    ampm = aTime[4];
    if (ampm=="") {
        alert("You must specify AM or PM.");
        return true;
        }
    return false;
    }

// ==============================================================================

function InvalidUserName(Suffix, form, required) {

    switch (Suffix) {
        case "":
            kind = "";
            break;
        case "Confirm":
            kind = " confirmation of your new";
            break;
        default:
            kind = " " + Suffix.toLowerCase();
        }
    if (form["UserName" + Suffix].value == "") {
        if (required) {
            alert("You must include your" + kind + " user name.");
            return true;
            }
        else return false;
        }
    else return InvalidString(form["UserName" + Suffix].value,
      "your" + kind + " user name", 2, 16, "0123456789", true);
    }

// ==============================================================================

function InvalidWIAALevel(Suffix, form, required) {

    if (form["WIAALevel" + Suffix].value == "") {
        if (required) {
            switch (Suffix) {
                case "1":
                    alert("You must include the first WIAA Level.");
                    break;
                case "2":
                    alert("You must include the second WIAA Level.");
                    break;
                default:
                    alert("You must include the WIAA Level.");
                    break;
                }
            return true;
            }
        else
            form["WIAALevel" + Suffix + "Name"].value = "";
        }
    else {
        form["WIAALevel" + Suffix + "Name"].value =
          form["WIAALevel" +
          Suffix].options[form["WIAALevel" + Suffix].selectedIndex].text;
        return false;
        }
   }

// ==============================================================================

function InvalidZip(suffix, form, required, description, separatefields) {

    if (separatefields) {
        var Zip5 = form["Zip" + suffix + "5"].value;
        var Zip4 = form["Zip" + suffix + "4"].value;
        if ((Zip5 + Zip4) == "") {
            if (required) {
                alert ("You must include " + description + ".");
                return true;
                }
            else {
                form["Zip" + suffix].value = "";
                return false;
                }
            }
        else {
            if (Zip5.length != 5) {
                alert ("The first part of " +
                  description.charAt(0).toUpperCase() +
                  description.substr(1) + " must be 5 digits.");
                return true;
                }
            else if (InvalidString(Zip5, description, 5, 5,
              "0123456789", false)) {
                return true;
                }
            else {
                if (Zip4 != "") {
                    if (Zip4.length != 4) {
                        alert ("The second part of " +
                          description.charAt(0).toUpperCase() +
                          description.substr(1) + " must be 4 digits.");
                        return true;
                        }
                    else if (InvalidString(Zip4, description, 4, 4, "0123456789",
                      false)) {
                        return true;
                        }
                    else {
                        form["Zip" + suffix].value = Zip5 + "-" +Zip4;
                        return false;
                        }
                    }
                else {
                    form["Zip" + suffix].value = Zip5;
                    return false;
                    }
                }
            }
        }
    else {
        var valid = "0123456789-";
        var hyphencount = 0;
        var field = form["Zip" + suffix].value;
        if (field == "") {
            if (required) {
                alert("You must enter " + description + ".");
                return true;
                }
            else return false;
            }
        if ((field.length != 5) && (field.length != 10)) {
            alert("Please enter your 5 digit or 5 digit+4 in " + description +
              ".");
            return true;
            }
        for (var i = 0; i < field.length; i++) {
            temp = "" + field.substring(i, i + 1);
            if (temp == "-") hyphencount++;
            if (valid.indexOf(temp) == "-1") {
                alert("There are invalid characters in " + description + ".");
                return true;
                }
            }
        if ((hyphencount > 1) || ((field.length == 10) &&
          ("" + field.charAt(5) != "-"))) {
            alert("The hyphen character should be used with a properly" +
                  " formatted 5 digit+four ZIP Code, like '12345-6789'.");
            return true;
            }
        }
    return false;
    }

// ==============================================================================

function JumpNext(thisfield, count, nextfield) {

    var myCount = count;
    if (myCount == 0) myCount = thisfield.value.maxlength;
    if (thisfield.value.length == myCount) nextfield.focus();
    }

// ==============================================================================

function Marquee (doc, Message, Style) {

    doc.write('<font color=Red>');
    if (navigator.appName == "Microsoft Internet Explorer")
        doc.write('<marquee height=22 width=470 behavior=scroll' +
          ' direction=left scrolldelay=30' +
          Style +'>' + Message + '</marquee>');
    else
        doc.write("<BLINK>" + Message + "</BLINK>");
    doc.write('</FONT>');
    }

// ==============================================================================

function PageTitle(Title) {

    }

// ==============================================================================

function ReplaceText(string, findtext, replacetext) {

    var stringlen = string.length;
    var findlen = findtext.length;
    if ((stringlen == 0) || (findlen == 0)) return string;
    var mystring = string;
    var ix = mystring.indexOf(findtext);
    while (ix != -1) {
        mystring = mystring.substring(0, ix) + replacetext +
          mystring.substring(ix + findlen);
        ix = mystring.indexOf(findtext);
        }
    return mystring;
    }

// ==============================================================================

function SendTo (subject, to, toat, tocom, cc, ccat, cccom) {

    if (toat == "")
        ISP = "DCHOA.org";
    else
        ISP = toat + "." + tocom;
    LinkTo = "mailto:" + to + "@" + ISP;
    Separator = "?";
    if (cc != "") {
        if (ccat == "")
            ISP = "DCHOA.org";
        else
            ISP = ccat + "." + cccom;
        LinkTo += Separator + "cc=" + cc + "@" + ISP;
        Separator = "&";
        }
    if (subject != "") {
        LinkTo += Separator + "subject=" + subject;
        Separator = "&";
        }
    window.open(LinkTo);
    }

// ==============================================================================

function SentAt(form) {

    var aMonths = new Array("January", "February", "March", "April", "May",
      "June", "July", "August", "September", "October", "November", "December");

     var aWeekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
      "Thursday", "Friday", "Saturday");

    var Now = new Date();
    var Hour = Now.getHours();
    var Minutes = Now.getMinutes();
    var Half = "AM";
    if (Hour == 12) Half = "PM";
    else if (Hour > 12) {
        Hour = Hour - 12;
        if (Hour != 12) Half = "PM";
        }
    if (Minutes < 10) Minutes = "0" + Minutes;
    form.Sent.value = aWeekdays[Now.getDay()] + ", " +
      aMonths[Now.getMonth()] + " " + Now.getDate() + ", " +
      Now.getFullYear() + " " + Hour + ":" + Minutes + " " + Half;
    }

// ==============================================================================

function SentPHP(form) {

    var Now = new Date();
    var Month = Now.getMonth() + 1;
    if (Month < 10) Month = "0" + Month;
    var Day = Now.getDate();
    if (Day < 10) Day = "0" + Day;
    var Hour = Now.getHours();
    if (Hour < 10) Hour = "0" + Hour;
    var Minute = Now.getMinutes();
    if (Minute < 10) Minute = "0" + Minute;
    var Second = Now.getSeconds();
    if (Second < 10) Second = "0" + Second;
    form.SentPHP.value = Now.getFullYear() + "-" + Month + "-" +
      Day + " " + Hour + ":" + Minute + ":" + Second;
    }

// ==============================================================================

function SetButtons(Buttons) {

    parent.fraLeft.location.href = "../misc/Buttons.php?C=" + Buttons;
    }

// ==============================================================================

function SetDate(Suffix, form) {

    if ((form["Month" + Suffix].value + form["Day" + Suffix].value +
      form["Year" + Suffix].value) != "") {
        if (form["Month" + Suffix].value.length == 1)
          var mymonth = "0" + form["Month" + Suffix].value;
        else var mymonth = form["Month" + Suffix].value;
        if (form["Day" + Suffix].value.length == 1)
          var myday = "0" + form["Day" + Suffix].value;
        else var myday = form["Day" + Suffix].value;
        form["Date" + Suffix].value = mymonth + "/" + myday + "/" +
          form["Year" + Suffix].value;
        }
    else form["Date" + Suffix].value = "";
    }

// ==============================================================================

function SetTime(Suffix, form) {

    if ((form["Hour" + Suffix].value + form["Minute" + Suffix].value +
      form["AMPM" + Suffix].value) != "") {
        if (form["Hour" + Suffix].value.length == 1)
          var myhour = "0" + form["Hour" + Suffix].value;
        else var myhour = form["Hour" + Suffix].value;
        if (form["Minute" + Suffix].value.length == 1)
          var myminute = "0" + form["Minute" + Suffix].value;
        else var myminute = form["Minute" + Suffix].value;
        form["Time" + Suffix].value = myhour + ":" + myminute + " " +
          form["AMPM" + Suffix].value;
        }
    else form["Time" + Suffix].value = "";
    }

// ==============================================================================

function StatusLine(Message) {

    window.status = Message;
    }

// ==============================================================================

function View (NewPage, WinType, WindowName, Properties) {

    if (WinType == 1) // Same window
        parent.fraMain.location.href = ExpandName (NewPage);
    else if (WinType == 2) // Special popup
        window.open(ExpandName (NewPage), WindowName, Properties);
    else if (WinType == 3) { // Restricted new window
        if (Properties == '') newWin =
          window.open('', WindowName, 'scrollbars,resizable=yes');
        else newWin = window.open('', WindowName, Properties);
        newWin.document.open();
        if (WindowName == '') Title = '';
        else Title = WindowName.replace('_', ' ') + ' - ';
        newWin.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>');
        newWin.document.write(
          '<FRAMESET cols="1,*" border=0>' +
            '<FRAME marginwidth=0 marginheight=0 border=0>' +
              '<FRAME src="' + ExpandName (NewPage) +
              '" marginwidth=0 marginheight=0>' +
              '</FRAMESET>' +
            '</HTML>');
        newWin.document.close();
        }
    else { // Unrestricted new window
        if (WindowName == '') {
            if (Properties == '') window.open(ExpandName (NewPage));
            else window.open(ExpandName (NewPage), '', Properties);
            }
        else window.open(ExpandName (NewPage), WindowName, Properties);
        }
    }