<!--
    function GetPasscode()
    {
        var passcode;
        passcode = prompt("Enter members-only pass code:", "");
        if (passcode == null)
        {
            return false;
        }
        else
        {
            document.prereg.passcode.value = passcode;
            return true;
        }
    }
            
    //special function in place for limited-entry events...
    function DisplayRulesBox()
    {
        var msg;
                
        msg = "Special Rules in place for this event:\n\n";
        msg += "1.  This event is limited to 50 entries.\n";
        msg += "2.  You may \"un-pre-register\" using this online form up until\n";
        msg += "    6:00 pm on the Thursday before the event.\n";
        msg += "3.  If you are pre-registered after this time, and do not show up\n";
        msg += "    to the event, you may be charged a $30 penalty and will\n";
        msg += "    not be allowed to run in future Tarheel events until this\n";
        msg += "    penalty is paid.\n";
        msg += "4.  On-site registration will be held from 8:30 until 9:30 am.\n";
        msg += "    Even if you pre-registered, we reserve the right to give\n";
        msg += "    away your slot after 9:30 am to paying customers if you have\n";
        msg += "    not shown up yet.  Don't be late!\n";
        alert(msg);
    }
            
    function DisplaySchoolRulesBox()
    {
        var msg;
                
        msg = "Special Rules in place for this event:\n\n";
        msg += "1.  This school is limited to 20 students.\n";
        msg += "2.  You may \"un-pre-register\" using this online form up until\n";
        msg += "    6:00 pm on the Thursday before the event.\n";
        msg += "3.  If you are pre-registered after this time, and do not show up\n";
        msg += "    to the event, you may be charged a $30 penalty and will\n";
        msg += "    not be allowed to run in future Tarheel events until this\n";
        msg += "    penalty is paid.\n";
        msg += "4.  On-site registration will be held from 8:30 until 9:30 am.\n";
        msg += "    Even if you pre-registered, we reserve the right to give\n";
        msg += "    away your slot after 9:30 am to paying customers if you have\n";
        msg += "    not shown up yet.  Don't be late!\n";
        alert(msg);
    }
            
    function EntryAdd()
    {
        document.prereg.op.value="add";
    }
            
    function EntryUpdate()
    {
        document.prereg.op.value="update";
    }
            
    function EntryDelete ()
    {
        document.prereg.op.value="delete";
    }
            
    function ValidateForm(frm)
    {
        var ret = true;

        // these "required" specifications only indicate if a value is
        // required for the purposes of this JavaScript validation.  The
        // rest of the required field information (which may include data
        // stored on the server) will be verified by a CGI script on the
        // server.
        frm.op.required = true;
        frm.licstate.required = true;
        frm.licnum.required = true;

        frm.licstate.alphaonly = true;
        frm.fname.alphaonly = true;
        frm.lname.alphaonly = true;
        frm.state.alphaonly = true;
        frm.clubaffil.alphaonly = true;

//      frm.eventdate.numonly = true;
        frm.areacode.numonly = true;
        frm.prefix.numonly = true;
        frm.phone.numonly = true;
        frm.caryr.numonly = true;
        frm.carnumber.numonly = true;
        	
        frm.licnum.minlength = 6;
        frm.state.minlength = 2;
        frm.zip.minlength = 5;
        frm.areacode.minlength = 3;
        frm.prefix.minlength = 3;
        frm.phone.minlength = 4;
        frm.caryr.minlength = 2;
        frm.carmake.minlength = 2;
        frm.carmodel.minlength = 2;

        ret = Validate(frm);
        return ret;
    }

    function Validate(frm)
    {
        var msg;
        	
        var empty_fields = "";
        var nonnum_fields = "";
        var nonalpha_fields = "";
        var short_fields = "";
        var st_prob = "";
        var tmp = "\n     eventdate";
        	
        // loop through the elements of the form, looking for all fields
        for (var i=0; i<frm.length; i++)
        {
            var elment = frm.elements[i];
                    
            if (elment.required &&
               (elment.value == null || 
                elment.value == "" || 
                isBlank(elment.value)))
            {
                if (elment.type == "select-one")
                {   // select elements don't have values in Netscape
                    if (elment.selectedIndex != 0)
                        continue;
                }
                empty_fields += "\n     " + elment.name;
		        continue;
            }
        	    
			// find our selected radiobutton
			if (elment.name == "eventdate" && 
				elment.checked)
			{
				// prompt for password only if we're:
				// 1. adding an entry
				// 2. more than 2 weeks from the event
				if (frm.op.value == "add")
				{
					var today = new Date();
					// extact date components from radio button value
					// event dates are in format yyyymmdd
					var eventYear = (elment.value.substr(0,4));
					var eventMonth = (elment.value.substr(4,2));
					var eventDay = (elment.value.substr(6,2));
					var eventDate = new Date(eventYear, eventMonth-1, eventDay);	// month is 0-based

					var eventType = parseInt(elment.value.substr(9,1));	// a separator is at position 8
					
					var isPasscodeRequired;
					
					switch (eventType)
					{
						case 0:
							// no passcode required
							isPasscodeRequired = false;
							break;

						case 2:
							// passcode expires 2 weeks before event (actually that Saturday)
							var ONEMINUTE = 60 * 1000; // milliseconds
							var ONEHOUR = 60 * ONEMINUTE;
							var ONEDAY = 24 * ONEHOUR;
							var FOURTEENDAYS = 14 * ONEDAY;
							var FIFTEENDAYS = 15 * ONEDAY;
							var now = new Date();
							var compareDate;
							
							// find midnight on the Saturday 2 weeks before the event,
							// based on the event date
							switch (eventDate.getDay() )
							{
								case 6:	// Saturday
									compareDate = eventDate - FOURTEENDAYS;
									break;
								case 0:	// Sunday
								default:
									compareDate = eventDate - FIFTEENDAYS;
									break;
							}
							if (now > compareDate)
							{
								isPasscodeRequired = false;
							}
							else
							{
								isPasscodeRequired = true;
							}
							break;

						case 1:
						default:
							// passcode never expires
							isPasscodeRequired = true;
							break;
					}
	
					if (isPasscodeRequired)
					{
						var status;
						status = GetPasscode();
						if (!status)
						{
							return false;
						}
					}
				}
										
				// do this here since we want to do it only once
				if (frm.op.value == "add" || frm.op.value == "update")
				{
					if (elment.value == "20040508")
					{
						DisplaySchoolRulesBox();
					}
					else if (elment.value == "20050709-0")
					{
//						break;
					}
					else if (elment.value == "20051203-0")
					{
//						break;
					}
					else
					{
						DisplayRulesBox();
					}
				}
				
				// clear our error string
				tmp = "";
	
			}
	
			// build error strings
			if (elment.numonly &&
				elment.value != null && 
				!isNum(elment.value))
			{
				nonnum_fields += "\n     " + elment.name;
				continue;
			}
			if (elment.alphaonly && 
				elment.value != null && 
				!isLetters(elment.value))
			{
				nonalpha_fields += "\n     " + elment.name;
				continue;
			}
			if (elment.value != null && 
				elment.value.length != 0 &&
				elment.value.length < elment.minlength)
			{
				short_fields += "\n- The field " + elment.name + " must be at least " +
					elment.minlength + " characters long.";
				continue;
			}
		}
	
		// add error field if it exists
		empty_fields += tmp;
					
		if (!empty_fields && !nonnum_fields && !nonalpha_fields && !short_fields && !st_prob)
			return true;
				
		msg = "___________________________________________________\n\n";
		msg += "The form was not submitted because of the following error(s):\n";
		msg += "Please correct these error(s) and try again. \n";
		msg += "___________________________________________________\n\n";
	
		if (empty_fields)
		{
			msg += "- The following required field(s) are empty:"
				+ empty_fields + "\n";
		}
		if (nonnum_fields)
		{
			msg += "\n- The following field(s) require numbers:"
				+ nonnum_fields + "\n";
		}
		if (nonalpha_fields)
		{
			msg += "\n- The following field(s) require letters only:"
				+ nonalpha_fields + "\n";
		}
		if (short_fields)
		{
			msg += short_fields;
		}
		if (st_prob)
		{
			msg += st_prob;
		}
				
		alert(msg);
		return false;
    }

    function isBlank(str)
    {
        for (var i=0; i<str.length; i++)
        {
            var c = str.charAt(i);
	        if (c != ' ' && c != '\t')
                return false;
        }
        return true;
    }
            
    function isNum(str)
    {
        for (var i=0; i<str.length; i++)
        {
            var c = str.charAt(i);
            if (c < '0' || c > '9')
                return false;
        }
        return true;
    }
            
    function isLetters(str)
    {
        for (var i=0; i<str.length; i++)
        {
            var c = str.charAt(i);
            if ((c < 'A' || c > 'Z') &&
                (c < 'a' || c > 'z') &&
                (c != ' '))
                return false;
        }
        return true;
    }
            
//-->	

