/////////////////////////////////////////////////////////////////
// Scripts.js
//
// This file contains scripts used by the eContinuity web site.
//
// Arguments: None
/////////////////////////////////////////////////////////////////
	
// --------------  Reuseable Variables & Functions ----------------

// Declare regular expression variables.
var ssnexp		= /^([0-7]\d{2})(\d{2})(\d{4})$/	// Any nine digit numeric within U.S. Government-specified range.
var c2kssnexp	= /^\d{9}$/							// Any nine digit numeric.
var charexp		= /./								// Any char including whitespace.
var charexp2	= /\w/								// Any letter, numeral or underscore.
var charexp3	= /\S/								// Any non-whitespace char.
var letterexp	= /[a-z]/i							// Any letter.
var stateexp	= /[a-z]{2}/i						// Any two letter expression.
var numexp		= /\d/								// Any number.
var decimalexp	= /[.]+/							// Any number containing a decimal.
var nondigitexp = /[^0-9]/g							// Any expression containing no numbers.
var zipexp		= /^\d{5}$|^\d{5}[\-\s]?\d{4}$/		// Any valid U.S. zip code (zip, zip + 4).
var phonexp		= /^\d{10}$/						// Any 10 digit numeric.
var emailexp	= /^([a-zA-Z0-9_\-\+])([a-zA-Z0-9_\-\.\+]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/

// Validation functions using regular expressions.
function validSSN(str)
{
	return ssnexp.test(str)
}

function validC2KSSN(str)
{
	return c2kssnexp.test(str)
}

function hasLetter(str)
{
	return letterexp.test(str)
}

function hasTwoLetters(str)
{
	return stateexp.test(str)
}

function hasNum(str)
{
	return numexp.test(str)
}

function hasChar(str)
{
	return charexp.test(str)
}

function hasChar2(str)
{
	return charexp2.test(str)
}

function hasChar3(str)
{
	return charexp3.test(str)
}

function validEmail(str)
{
	return emailexp.test(str)
}

function isValid(pattern, str)
{
	return pattern.test(str)
}

function hasDecimal(str)
{
	return decimalexp.test(str)
}

function hasNonDigit(str)
{
	return nondigitexp.test(str)
}

// Check for date entered in specified format (1=mm/dd/yyyy, 2=dd/mm/yyyy).
function isDate(date,date_format)
{
	var date_array = date.split("/")
	
	if (date_format == 1)
	{
	    if ((date_array.length == 3) &&
		    (date_array[0] > 0) && (date_array[0] < 13) &&
		    (date_array[1] > 0) && (date_array[1] < 32) &&
		    (date_array[2] >= 1753) && (date_array[2] <= 9999))
	    {
		    return true
	    } 
    }
    else
    {
	    if ((date_array.length == 3) &&
		    (date_array[1] > 0) && (date_array[1] < 13) &&
		    (date_array[0] > 0) && (date_array[0] < 32) &&
		    (date_array[2] >= 1753) && (date_array[2] <= 9999))
	    {
		    return true
	    } 
    }    
}

// Check for money entered as decimal hundredths, e.g., "15.75".
function isCurrency(money) 
{
	var money_array = money.split(".")
	if ((money_array.length == 2) &&
		(money_array[0] >= 0) && (money_array[0] < 1000000000) &&
		(money_array[1] >= 0) && (money_array[1] < 100) && (money_array[1].length == 2)) 
	{
		return true
	}
	if ((money_array.length == 1) &&
		(money_array[0] >= 0) && (money_array[0] < 1000000000)) 
	{
		return true
	} 
}

// Strip all non-numeric characters from the string.
function stripNonDigits(str)
{
	return str.replace(nondigitexp,"")
}

// Check for valid "C2K SSN" (i.e., any 9 digit numeric).
function isC2KSSN(Frm,ssn)
{
	var matchArr = ssn.match(c2kssnexp);
	if (matchArr == null) 
	{
		alert('Invalid SSN.  SSN must be 9 digit numeric.');
		Frm.ssn.focus();
		return false;
	}
	else
	{
		return true;
	}
}

// Validate SSN entered once.  Validation rules for ssn's are as follows:
//   1. Nine digit numeric.
//   2. May not begin with 8, 9, 000 or 666.
//   3. Considering three number sections in format NNN-NN-NNNN, none of the sections may consist of all zeroes.
function checkOneSSN(Frm,ssn) 
{
	var matchArr = ssn.match(ssnexp);
	if (matchArr == null) 
	{
		alert('Invalid SSN.  Your SSN is required.');
		Frm.ssn.focus();
		return false;
	}
	else
	{ 
		if ((parseInt(matchArr[1],10)==0) || (parseInt(matchArr[1],10)==666) || 
		    (parseInt(matchArr[2],10)==0) || (parseInt(matchArr[3],10)==0))
		{
			alert('Invalid SSN.  Your SSN is required.');
			Frm.ssn.focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function checkFormNewSignIn013(Frm, email, email2)
{
	var matchArr = email.match(emailexp);
	if (email != email2) 
	{
		alert('Your email entries did not match.  Please recheck your entries for errors.');
		Frm.ssn.focus();
		return false;
	}
	else
    {
	    // Validate last name
	    if (Frm.firstname.value  == "")
	    {
		    alert("First name is required.")
		    Frm.firstname.focus()
		    return false
	    }
    			
	    // Validate first name.
	    if (Frm.lastname.value  == "")
	    {
		    alert("Last name is required.")
		    Frm.lastname.focus()
		    return false
	    }
    	
	    // Validate SSN.
	    if (!checkOneSSN(Frm, Frm.ssn.value))
	    {
		    return false
	    }

	    // Validate birthdate.
	    if (Frm.birthdate.value == "")
	    {
		    alert("Birthdate is required.")
		    Frm.birthdate.focus()
		    return false
	    }

	    // Verify that the birthdate is properly formatted.
	    if (!isDate(Frm.birthdate.value,date_format))
	    {
            var strAlertDateFormat
            
            if (date_format = 1)
            {
                strAlertDateFormat = "mm/dd/yyyy"
            }
            else 
            {
                strAlertDateFormat = "dd/mm/yyyy"    
            }
    	
		    alert("Please clear blank space(s) or enter a valid birthdate in the specified format (" +strAlertDateFormat+ ").")
		    Frm.birthdate.focus()
		    return false
	    }
	    return true
    }
}

function checkFormSignIn013(Frm)
{
	// Validate global_id.
	if (Frm.global_id.value == "")
	{
		alert("Global ID is required.")
		Frm.global_id.focus()
		return false
	}

	// Validate password.
	if (Frm.password.value == "")
	{
		alert("Password is required.")
		Frm.password.focus()
		return false
	}

	return true
}

// --------------  Breakout.asp ----------------

// If a user checks or unchecks a breakout or fee, this function will set all dependent input options appropriately.
function setDependentInput(Frm, input, breakout_id, inputType, fee_id)	// inputType 1 = breakout session, 2 = fee
{
	var breakout_id_string = String(breakout_id) + "|"

	// Set checked_flag to true or false based on the clicked element.
	checked_flag = input.checked
		
	if (inputType == 1)
	{
		// 1. If a breakout is checked, all other breakouts with the same breakout_id should be checked.
		if (checked_flag == true)
		{
			// Loop through all inputs on the form.
			for(var i=0; i<Frm.elements.length; i++)
			{
				// If same breakout_id as clicked element, set checked value to checked_flag.
				if (Frm.elements[i].type == "radio" || Frm.elements[i].type == "checkbox")
				{
					if (Frm.elements[i].value == breakout_id_string)
					{
						Frm.elements[i].checked = true
					}
				}
			}		
		}
		// 2. If a breakout is unchecked, all other breakouts and breakout fees with the same breakout_id should be unchecked.
		else
		{
			// Loop through all inputs on the form.
			for(var i=0; i<Frm.elements.length; i++)
			{
				// If same breakout_id as clicked element, set checked value to checked_flag.
				if (Frm.elements[i].type == "radio" || Frm.elements[i].type == "checkbox")
				{
					var value_string = Frm.elements[i].value
					var value_array = value_string.split("|")
					var breakout_value = value_array[0]

					if (breakout_value == breakout_id_string)
					{
						Frm.elements[i].checked = false
					}
				}
			}					
		}
	}
	else
	{
		var boid_fid_string = breakout_id_string + String(fee_id)	// breakout_id|fee_id string

		// 3. if a breakout fee is checked, all breakouts with the same breakout_id, and all breakout fees with the same fee_id should be checked.
		if (checked_flag == true)
		{
			// Loop through all inputs on the form.
			for(var i=0; i<Frm.elements.length; i++)
			{
				// If same breakout_id or fee_id as clicked element, set checked value to checked_flag.
				if (Frm.elements[i].type == "radio" || Frm.elements[i].type == "checkbox")
				{
					// Check breakout session if it is parent to the clicked fee.
					if (Frm.elements[i].value == breakout_id_string)
					{
						Frm.elements[i].checked = true
					}
					// Check breakout fee if it is the same as the clicked fee (e.g., fee in concurrent breakout session which is included in multiple concurrent session groups).
					if (Frm.elements[i].value == boid_fid_string)
					{
						Frm.elements[i].checked = true
					}
				}
			}		
		}

		// 4. if a breakout fee is unchecked, all other breakouts and breakout fees with the same breakout_id should be unchecked.		
		else
		{
			// Loop through all inputs on the form.
			for(var i=0; i<Frm.elements.length; i++)
			{
				// If same breakout_id as clicked element, set checked value to checked_flag.
				if (Frm.elements[i].type == "radio" || Frm.elements[i].type == "checkbox")
				{
					var value_string = Frm.elements[i].value
					var value_array = value_string.split("|")
					var breakout_value = value_array[0]
					
					if (breakout_value == breakout_id)
					{
						Frm.elements[i].checked = false
					}
				}
			}					
		}
	}
		
	// Second pass through all inputs on the form.
	for(var i=0; i<Frm.elements.length; i++)
	{
		var value_string2 = Frm.elements[i].value
		var value_array2 = value_string2.split("|")
		var breakout_value2 = value_array2[0]

		// If breakout was automatically unchecked, then loop through all elements again, and set breakouts and breakout fees with same breakout_id to unchecked.
		if ((Frm.elements[i].checked == false) && (value_array2[1] < 1))
		{
			// Loop through all inputs on the form.
			for(var j=0; j<Frm.elements.length; j++)
			{
				// If same breakout_id as clicked element, set checked value to checked_flag.
				if (Frm.elements[j].type == "radio" || Frm.elements[j].type == "checkbox")
				{
					var value_string3 = Frm.elements[j].value
					var value_array3 = value_string3.split("|")
					var breakout_value3 = value_array3[0]

					if (breakout_value2 == breakout_value3)
					{
						Frm.elements[j].checked = false
					}
				}
			}
		}
	}
}
	
// If a breakout is selected, and it has a fee group, this function will alert the user if a fee was not selected.
function checkFormBreakout(Frm)
{
	var testOk = true;
		
	// Loop through all elements on the form.
	for(var i=0; i<Frm.elements.length; i++)
	{
		// Determine element type by checking its value.  A breakout is a one item array.
		var value_string = Frm.elements[i].value
		var value_array = value_string.split("|")
		var breakout_value = value_array[0]
			
		// If this element is a breakout AND it is checked...
		if ((value_array[1] < 1) && (Frm.elements[i].checked == true))
		{
			// Loop through all elements on the form again to see if the checked breakout has a fee group...
			for(var j=0; j<Frm.elements.length; j++)
			{
				// Determine element type by checking its value.  A breakout fee is a two item array.
				var element_name = Frm.elements[j].name
				var value_string2 = Frm.elements[j].value
				var value_array2 = value_string2.split("|")
				var breakout_value2 = value_array2[0]
					
				// If this element is a breakout fee for the current breakout...
				if ((value_array2[1] >= 1) && (breakout_value2 == breakout_value))
				{
					// Loop through all radio buttons for this breakout fee to make sure at least one is selected.
					var selectTotal = 0;
					for(var k=0; k<Frm.elements.length; k++)
					{
						if ((Frm.elements[k].name == Frm.elements[j].name) && (Frm.elements[k].checked == true))
						{
							selectTotal++;
						}
					}
					// Alert the registrant if no items have been checked.		
					if (selectTotal != 1) 
					{
						var sessionText = Frm.elements[j].getAttribute('alt');
						alert('"' + sessionText + '" ' + 'requires you to select an enrollment option before proceeding.');
						Frm.elements[j].focus();
						return false;						
					}					
				}
			}
		}
	}
}

// --------------  ChangePassSignIn.asp ----------------
function checkFormChangePass(Frm)
{
		// Check firstname text box for an entry.
		if  (!hasChar2(Frm.firstname.value)) 
		{
			alert("First name is required")
			Frm.firstname.focus()
			return false
		}
		// Check lastname text box for an entry.
		if  (!hasChar2(Frm.lastname.value)) 
		{
			alert("Last name is required")
			Frm.lastname.focus()
			return false
		}
        // Check ssn if required.
        if (Frm.ssn.type != 'hidden')
        {
		    if (!validC2KSSN(Frm.ssn.value))
		    {
			    alert("Please enter your 9-digit social security number.")
			    Frm.ssn.focus()
			    return false
		    }
        }
	return true
}

// --------------  CourseListing.asp ----------------

// If a course listing is selected, and it has a fee group, this function will alert the user if a fee was not selected.
function checkFormCourseListing(Frm)
{
	var testOk = false;
		
	// Loop through all the form's elements.
	for (var i=0; i<Frm.elements.length; i++) 
	{
		// Get the validator (alt) attribute, if it exists, thereby starting the validation.
		if (Frm.elements[i].getAttribute('alt')) 
		{
			var validateType = Frm.elements[i].getAttribute('alt');
			var validateObj = Frm.elements[i];
			testOk = false;
				
			if (validateType == 'radio')
			{
				// Loop through all radio buttons for this fee group to make sure at least one is selected.
				var selectTotal = 0;
				for(var k=0; k<Frm.elements.length; k++)
				{
					if ((Frm.elements[k].name == Frm.elements[i].name) && (Frm.elements[k].checked == true))
					{
						selectTotal++;
					}
				}
				// Alert the registrant if no items have been checked.		
				if (selectTotal != 1) 
				{
					alert('You must select an enrollment option.');
					Frm.elements[i].focus();
					return false;						
				}					
			}
		}
	}
	// Form has been validated
	return true;
}

function submitForm(Frm)
{
	if (checkFormCourseListing(Frm))
	{
		Frm.submit();
	}
}


// --------------  GatherBillingInfo.asp ----------------

function checkFormBilling(Frm)
{
    // Check billing_street1 text box for an entry.
    if  (!hasChar2(Frm.billing_street1.value)) 
    {
	    alert("Invalid Street Address")
	    Frm.billing_street1.focus()
	    return false
    }

    // Check billing_city text box for an entry.
    if  (!hasLetter(Frm.billing_city.value)) 
    {
	    alert("Invalid City")
	    Frm.billing_city.focus()
	    return false
    }

    // Check billing_state text box for an entry (USA and Canada only).
    if	((Frm.billing_country_id.value == 1) || (Frm.billing_country_id.value == 2))
    {
	    if  (!hasTwoLetters(Frm.billing_state.value)) 
	    {
		    alert("Invalid State")
		    Frm.billing_state.focus()
		    return false
	    }
    }
			
    // Check billing_postal_code text box for an entry (USA and Canada only).
    if	((Frm.billing_country_id.value == 1) || (Frm.billing_country_id.value == 2))
    {
	    if  (!hasChar2(Frm.billing_postal_code.value)) 
	    {
		    alert("Invalid Postal Code")
		    Frm.billing_postal_code.focus()
		    return false
	    }
    }	

	return true	
}


// --------------  GatherDemographicInfo.asp ----------------

// Validates demographic elements if they are asked, and takes into account whether they are required or optional.
// Excludes SSN validation.
function checkFormDemographic(Frm, date_format, ssn_opt, bir_opt, cit_opt, edu_opt, eth_opt, gen_opt, mar_opt, vet_opt)
{
	// Verify the user has entered a birthdate, if required.
	if (bir_opt == 2)
	{
		if (Frm.birthdate.value  == "")
		{
			alert("Birthdate is required.")
			Frm.birthdate.focus()
			return false
		}
	}
	// Verify that the birthdate is properly formatted.
	if (bir_opt != 0)
	{
		if (hasChar(Frm.birthdate.value))
		{
			if (!isDate(Frm.birthdate.value,date_format))
	        {
                var strAlertDateFormat
                
                if (date_format = 1)
                {
                    strAlertDateFormat = "mm/dd/yyyy"
                }
                else 
                {
                    strAlertDateFormat = "dd/mm/yyyy"    
                }
        	
		        alert("Please clear blank space(s) or enter a valid birthdate in the specified format (" +strAlertDateFormat+ ").")
		        Frm.birthdate.focus()
		        return false
	        }
		}
	}
	// Verify the user has selected a citizenship value, if required.
	if (cit_opt == 2)
	{		
		if (Frm.citizenship.value  == "")
		{
			alert("A citizenship selection is required.")
			Frm.citizenship.focus()
			return false
		}
	}
	// Verify the user has selected an education level, if required.
	if (edu_opt == 2)
	{
		if (Frm.education_level.value  == "")
		{
			alert("An education level selection is required.")
			Frm.education_level.focus()
			return false
		}
	}
	// Verify the user has selected an ethnicity, if required.
	if (eth_opt == 2)
	{
		if (Frm.ethnicity.value  == "")
		{
			alert("An ethnicity selection is required.")
			Frm.ethnicity.focus()
			return false
		}
	}
	// Verify the user has selected a gender, if required.
	if (gen_opt == 2)
	{
		if (Frm.gender.value  == "")
		{
			alert("A gender selection is required.")
			Frm.gender.focus()
			return false
		}
	}
	// Verify the user has selected a marital status, if required.
	if (mar_opt == 2)
	{
		if (Frm.marital_status.value  == "")
		{
			alert("A marital status selection is required.")
			Frm.marital_status.focus()
			return false
		}
	}
	// Verify the user has selected a veteran status, if required.
	if (vet_opt == 2)
	{
		if (Frm.veteran_status.value  == "")
		{
			alert("A veteran status selection is required.")
			Frm.veteran_status.focus()
			return false
		}
	}
	return true
}

// Validates demographic elements if they are asked, and takes into account whether they are required or optional.
// Includes SSN validation.
function checkFormDemographicSSN(Frm, date_format, ssn_opt, bir_opt, cit_opt, edu_opt, eth_opt, gen_opt, mar_opt, vet_opt)
{
	// Verify the user has not cleared the SSN.  SSN may never be cleared.
	if (Frm.ssn.value  == "")
	{
		alert("Social Security Number is required.")
        Frm.ssn.focus()
		return false
	}
    // Verify that the SSN is properly formatted, if asked for.
    if (ssn_opt == 1)
    {
		if (!validC2KSSN(Frm.ssn.value))
		{
			alert("Please enter your 9-digit social security number.")
			Frm.ssn.focus()
			return false
		}
	}
    // Verify that the SSN is properly formatted, if required.
    if (ssn_opt ==2)
    {
		if (!validSSN(Frm.ssn.value))
		{
			alert("Please enter your 9-digit social security number.")
			Frm.ssn.focus()
			return false
		}
	}
    // Verify that the SSN was correctly repeated.
    if (ssn_opt != 0)
    {
		if (Frm.ssn.value != Frm.ssn_repeat.value)
		{
			alert("The social security number was incorrectly repeated.")
			Frm.ssn.focus()
			return false
		}
	}
	// Verify the user has entered a birthdate, if required.
	if (bir_opt == 2)
	{
		if (Frm.birthdate.value  == "")
		{
			alert("Birthdate is required.")
			Frm.birthdate.focus()
			return false
		}
	}
	// Verify that the birthdate is properly formatted.
	if (bir_opt != 0)
	{
		if (hasChar(Frm.birthdate.value))
		{
			if (!isDate(Frm.birthdate.value,date_format))
	        {
                var strAlertDateFormat
                
                if (date_format = 1)
                {
                    strAlertDateFormat = "mm/dd/yyyy"
                }
                else 
                {
                    strAlertDateFormat = "dd/mm/yyyy"    
                }
        	
		        alert("Please clear blank space(s) or enter a valid birthdate in the specified format (" +strAlertDateFormat+ ").")
		        Frm.birthdate.focus()
		        return false
	        }
		}
	}
	// Verify the user has selected a citizenship value, if required.
	if (cit_opt == 2)
	{		
		if (Frm.citizenship.value  == "")
		{
			alert("A citizenship selection is required.")
			Frm.citizenship.focus()
			return false
		}
	}
	// Verify the user has selected an education level, if required.
	if (edu_opt == 2)
	{
		if (Frm.education_level.value  == "")
		{
			alert("An education level selection is required.")
			Frm.education_level.focus()
			return false
		}
	}
	// Verify the user has selected an ethnicity, if required.
	if (eth_opt == 2)
	{
		if (Frm.ethnicity.value  == "")
		{
			alert("An ethnicity selection is required.")
			Frm.ethnicity.focus()
			return false
		}
	}
	// Verify the user has selected a gender, if required.
	if (gen_opt == 2)
	{
		if (Frm.gender.value  == "")
		{
			alert("A gender selection is required.")
			Frm.gender.focus()
			return false
		}
	}
	// Verify the user has selected a marital status, if required.
	if (mar_opt == 2)
	{
		if (Frm.marital_status.value  == "")
		{
			alert("A marital status selection is required.")
			Frm.marital_status.focus()
			return false
		}
	}
	// Verify the user has selected a veteran status, if required.
	if (vet_opt == 2)
	{
		if (Frm.veteran_status.value  == "")
		{
			alert("A veteran status selection is required.")
			Frm.veteran_status.focus()
			return false
		}
	}
	return true
}

function clearForm(Frm)
{
    for (var i=0; i<Frm.elements.length; i++)
    {
        if ((Frm.elements[i].type == "password") || (Frm.elements[i].type == "text"))
        {
            Frm.elements[i].value="";
        }
    }
}

function checkSSNChange(Frm)
{
	if (!validSSN(Frm.ssn.value))
	{
		alert("Invalid value entered.")
		Frm.reset()
		Frm.ssn.focus()
		return false
	}
}

// --------------  GatherPaymentInfo.asp ----------------

function enableCreditCard(Frm, TPPPFlag) 
{
    if (TPPPFlag != 1)
    {
        // Enable credit card entry fields.
	    Frm.payment_method_id.disabled      = false;
	    Frm.card_number.disabled            = false;
	    Frm.card_expire_month.disabled      = false;
	    Frm.card_expire_year.disabled       = false;
	    Frm.card_security_code.disabled     = false;
	    Frm.payer_name.disabled             = false;
	    Frm.cardholder_street1.disabled     = false;
	    Frm.cardholder_street2.disabled     = false;
	    Frm.cardholder_street3.disabled     = false;
	    Frm.cardholder_city.disabled        = false;
	    Frm.cardholder_state.disabled       = false;
	    Frm.cardholder_postal_code.disabled = false;
	    Frm.cardholder_country_id.disabled  = false;
	}
	else
    {
        // Enable credit card entry fields.
	    Frm.payer_name.disabled             = false;
	    Frm.cardholder_street1.disabled     = false;
	    Frm.cardholder_street2.disabled     = false;
	    Frm.cardholder_street3.disabled     = false;
	    Frm.cardholder_city.disabled        = false;
	    Frm.cardholder_state.disabled       = false;
	    Frm.cardholder_postal_code.disabled = false;
	    Frm.cardholder_country_id.disabled  = false;
	}	
	
	// Disable PO number entry field.
	if (Frm.purchase_order_number)
	{
	    Frm.purchase_order_number.disabled  = true;	
	}
	
	// Disable "bill me" entry fields.
	if (Frm.bill_me_name)
	{
	    Frm.bill_me_name.disabled           = true;
	    Frm.billing_street1.disabled        = true;
	    Frm.billing_street2.disabled        = true;
	    Frm.billing_street3.disabled        = true;
	    Frm.billing_city.disabled           = true;
	    Frm.billing_state.disabled          = true;
	    Frm.billing_postal_code.disabled    = true;
	    Frm.billing_country_id.disabled     = true;
	}
	
	// Disable "bill my company" entry field.
	if (Frm.billing_company_id)
	{
	    Frm.billing_company_id.disabled     = true;	
	}
}

function enablePO(Frm, TPPPFlag) 
{
    if (TPPPFlag != 1)
    {
        // Disable credit card entry fields.
	    Frm.payment_method_id.disabled      = true;
	    Frm.card_number.disabled            = true;
	    Frm.card_expire_month.disabled      = true;
	    Frm.card_expire_year.disabled       = true;
	    Frm.card_security_code.disabled     = true;
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}
	else
    {
        // Enable credit card entry fields.
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}	
	
	// Enable PO number entry field.
	if (Frm.purchase_order_number)
	{
	    Frm.purchase_order_number.disabled  = false;	
	}
	
	// Disable "bill me" entry fields.
	if (Frm.bill_me_name)
	{
	    Frm.bill_me_name.disabled           = true;
	    Frm.billing_street1.disabled        = true;
	    Frm.billing_street2.disabled        = true;
	    Frm.billing_street3.disabled        = true;
	    Frm.billing_city.disabled           = true;
	    Frm.billing_state.disabled          = true;
	    Frm.billing_postal_code.disabled    = true;
	    Frm.billing_country_id.disabled     = true;
	}
	
	// Disable "bill my company" entry field.
	if (Frm.billing_company_id)
	{
	    Frm.billing_company_id.disabled     = true;	
	}
}

function enableBillMe(Frm, TPPPFlag) 
{
    if (TPPPFlag != 1)
    {
        // Disable credit card entry fields.
	    Frm.payment_method_id.disabled      = true;
	    Frm.card_number.disabled            = true;
	    Frm.card_expire_month.disabled      = true;
	    Frm.card_expire_year.disabled       = true;
	    Frm.card_security_code.disabled     = true;
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}
	else
    {
        // Enable credit card entry fields.
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}	
	
	// Disable PO number entry field.
	if (Frm.purchase_order_number)
	{
	    Frm.purchase_order_number.disabled  = true;	
	}
	
	// Enable "bill me" entry fields.
	if (Frm.bill_me_name)
	{
	    Frm.bill_me_name.disabled           = false;
	    Frm.billing_street1.disabled        = false;
	    Frm.billing_street2.disabled        = false;
	    Frm.billing_street3.disabled        = false;
	    Frm.billing_city.disabled           = false;
	    Frm.billing_state.disabled          = false;
	    Frm.billing_postal_code.disabled    = false;
	    Frm.billing_country_id.disabled     = false;
	}
	
	// Disable "bill my company" entry field.
	if (Frm.billing_company_id)
	{
	    Frm.billing_company_id.disabled     = true;	
	}
}

function enableBillCompany(Frm, TPPPFlag) 
{
    if (TPPPFlag != 1)
    {
        // Disable credit card entry fields.
	    Frm.payment_method_id.disabled      = true;
	    Frm.card_number.disabled            = true;
	    Frm.card_expire_month.disabled      = true;
	    Frm.card_expire_year.disabled       = true;
	    Frm.card_security_code.disabled     = true;
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}
	else
    {
        // Enable credit card entry fields.
	    Frm.payer_name.disabled             = true;
	    Frm.cardholder_street1.disabled     = true;
	    Frm.cardholder_street2.disabled     = true;
	    Frm.cardholder_street3.disabled     = true;
	    Frm.cardholder_city.disabled        = true;
	    Frm.cardholder_state.disabled       = true;
	    Frm.cardholder_postal_code.disabled = true;
	    Frm.cardholder_country_id.disabled  = true;
	}	
	
	// Disable PO number entry field.
	if (Frm.purchase_order_number)
	{
	    Frm.purchase_order_number.disabled  = true;	
	}
	
	// Disable "bill me" entry fields.
	if (Frm.bill_me_name)
	{
	    Frm.bill_me_name.disabled           = true;
	    Frm.billing_street1.disabled        = true;
	    Frm.billing_street2.disabled        = true;
	    Frm.billing_street3.disabled        = true;
	    Frm.billing_city.disabled           = true;
	    Frm.billing_state.disabled          = true;
	    Frm.billing_postal_code.disabled    = true;
	    Frm.billing_country_id.disabled     = true;
	}
	
	// Enable "bill my company" entry field.
	if (Frm.billing_company_id)
	{
	    Frm.billing_company_id.disabled     = false;	
	}

}

function checkFormPayment(Frm, TPPPFlag)
{
    //  Loop through the payment_option_id radio button elements.
    for (var i=0; i<Frm.payment_option_id.length; i++) 
    {
        
        //  For each element, check if it is selected.
        if (Frm.payment_option_id[i].checked == true)
        {
            // When the selected element is found, do the appropriate field validations.

            //  Credit Card was selected.
            if (TPPPFlag != 1)
            {
                if (Frm.payment_option_id[i].value == 1)
                {
                    // Clear PO.
	                if (Frm.purchase_order_number)
	                {
                        Frm.purchase_order_number.value = ""
                    }
                    
                    // Check card number field for an entry.
	                if (!hasChar2(Frm.card_number.value))
	                {
		                alert("Please enter the credit card number.")
		                Frm.card_number.focus()
		                return false    
	                }
                
	                // Check cardholder name box for an entry.
	                if  (!hasChar2(Frm.payer_name.value)) 
	                {
		                alert("Invalid Cardholder Name")
		                Frm.payer_name.focus()
		                return false
	                }	

	                // Check cardholder_street1 text box for an entry.
	                if  (!hasChar2(Frm.cardholder_street1.value)) 
	                {
		                alert("Invalid Street Address")
		                Frm.cardholder_street1.focus()
		                return false
	                }

	                // Check cardholder_city text box for an entry.
	                if  (!hasLetter(Frm.cardholder_city.value)) 
	                {
		                alert("Invalid City")
		                Frm.cardholder_city.focus()
		                return false
	                }

	                // Check cardholder_state text box for an entry (USA and Canada only).
	                if	((Frm.cardholder_country_id.value == 1) || (Frm.cardholder_country_id.value == 2))
	                {
		                if  (!hasTwoLetters(Frm.cardholder_state.value)) 
		                {
			                alert("Invalid State")
			                Frm.cardholder_state.focus()
			                return false
		                }
	                }
                			
	                // Check cardholder_postal_code text box for an entry (USA and Canada only).
	                if	((Frm.cardholder_country_id.value == 1) || (Frm.cardholder_country_id.value == 2))
	                {
		                if  (!hasChar2(Frm.cardholder_postal_code.value)) 
		                {
			                alert("Invalid Postal Code")
			                Frm.cardholder_postal_code.focus()
			                return false
		                }
	                }
	            }
	        }

	        // Purchase Order was selected.
            if (Frm.payment_option_id[i].value == 2)
	        {
	            // Clear the credit card number.
	            Frm.card_number.value = ""
        	    
	            // Check PO # field for an entry.
	            if (!hasChar2(Frm.purchase_order_number.value))
	            {
		            alert("Please enter the Purchase Order number.")
		            Frm.purchase_order_number.focus()
		            return false    
	            }
	        }	
        	
	        // Bill Me was selected.
            if (Frm.payment_option_id[i].value == 3)
	        {
	            // Clear the credit card number.
	            Frm.card_number.value = ""
        	    
                // Clear PO.
	            if (Frm.purchase_order_number)
	            {
                    Frm.purchase_order_number.value = ""
                }
                
	            // Check billing_street1 text box for an entry.
	            if  (!hasChar2(Frm.billing_street1.value)) 
	            {
		            alert("Invalid Street Address")
		            Frm.billing_street1.focus()
		            return false
	            }

	            // Check billing_city text box for an entry.
	            if  (!hasLetter(Frm.billing_city.value)) 
	            {
		            alert("Invalid City")
		            Frm.billing_city.focus()
		            return false
	            }

	            // Check billing_state text box for an entry (USA and Canada only).
	            if	((Frm.billing_country_id.value == 1) || (Frm.billing_country_id.value == 2))
	            {
		            if  (!hasTwoLetters(Frm.billing_state.value)) 
		            {
			            alert("Invalid State")
			            Frm.billing_state.focus()
			            return false
		            }
	            }
            			
	            // Check billing_postal_code text box for an entry (USA and Canada only).
	            if	((Frm.billing_country_id.value == 1) || (Frm.billing_country_id.value == 2))
	            {
		            if  (!hasChar2(Frm.billing_postal_code.value)) 
		            {
			            alert("Invalid Postal Code")
			            Frm.billing_postal_code.focus()
			            return false
		            }
	            }	
	        }	
        	
	        // Bill My Company was selected.
            if (Frm.payment_option_id[i].value == 4)
	        {
	            // Clear the credit card number.
	            Frm.card_number.value = ""
        	    
                // Clear PO.
	            if (Frm.purchase_order_number)
	            {
                    Frm.purchase_order_number.value = ""
                }
            }        
	    }
    }
	return true	
}

// --------------  GatherPersonInfo.asp ----------------

function checkFormPerson(Frm)
{
	// If preferred address is home, validate the required fields.
    if (Frm.preferred_address[0].checked)
	{
		// Check home_street1 text box for an entry.
		if  (!hasChar2(Frm.home_street1.value)) 
		{
			alert("Invalid Home Street Address")
			Frm.home_street1.focus()
			return false
		}

		// Check home_city text box for an entry.
		if  (!hasLetter(Frm.home_city.value)) 
		{
			alert("Invalid Home City")
			Frm.home_city.focus()
			return false
		}

		// Check home_state text box for an entry (USA and Canada only).
		if	((Frm.home_country_id.value == 1) || (Frm.home_country_id.value == 2))
		{
			if  (!hasTwoLetters(Frm.home_state.value)) 
			{
				alert("Invalid Home State")
				Frm.home_state.focus()
				return false
			}
		}
			
		// Check home_postal_code text box for an entry (USA and Canada only).
		if	((Frm.home_country_id.value == 1) || (Frm.home_country_id.value == 2))
		{
			if  (!hasChar2(Frm.home_postal_code.value)) 
			{
				alert("Invalid Home Postal Code")
				Frm.home_postal_code.focus()
				return false
			}
		}

		// Check home_phone_city text box for an entry.
		if  (!hasChar2(Frm.home_phone_city.value)) 
		{
			alert("Invalid Home Phone Code")
			Frm.home_phone_city.focus()
			return false
		}

		// Check home_phone_local select list for an entry.
		if  (!hasChar2(Frm.home_phone_local.value)) 
		{
			alert("Invalid Home Phone Number")
			Frm.home_phone_local.focus()
			return false
		}
		// Check home_email text box for an entry.
		if  (!validEmail(Frm.home_email.value)) 
		{
			alert("Invalid Home E-mail")
			Frm.home_email.focus()
			return false
		}
	}
	}
	// If preferred address is work, validate the required fields.
	else
	{

		// Check work_title text box for an entry.
		if  (!hasChar2(Frm.work_title.value)) 
		{
			alert("Invalid Work Title")
			Frm.work_title.focus()
			return false
		}

		// Check work_company text box for an entry.
		if  (!hasChar2(Frm.work_company.value))
		{
			alert("Invalid Work Company")
			Frm.work_company.focus()
			return false
		}

		// Check work_street1 text box for an entry.
		if  (!hasChar2(Frm.work_street1.value)) 
		{
			alert("Invalid Work Street Address")
			Frm.work_street1.focus()
			return false
		}

		// Check work_city text box for an entry.
		if  (!hasChar2(Frm.work_city.value)) 
		{
			alert("Invalid Work City")
			Frm.work_city.focus()
			return false
		}

		// Check work_state text box for an entry (USA and Canada only).
		if	((Frm.work_country_id.value == 1) || (Frm.work_country_id.value == 2))
		{
			if  (!hasTwoLetters(Frm.work_state.value)) 
			{
				alert("Invalid Work State")
				Frm.work_state.focus()
				return false
			}
		}

		// Check work_postal_code text box for an entry (USA and Canada only).
		if	((Frm.work_country_id.value == 1) || (Frm.work_country_id.value == 2))
		{
			if  (!hasChar2(Frm.work_postal_code.value)) 
			{
				alert("Invalid Work Postal Code")
				Frm.work_postal_code.focus()
				return false
			}
		}

		// Check work_phone_city text box for an entry.
		if  (!hasChar2(Frm.work_phone_city.value)) 
		{
			alert("Invalid Work Phone Code")
			Frm.work_phone_city.focus()
			return false
		}

		// Check work_phone_local select list for an entry.
		if  (!hasChar2(Frm.work_phone_local.value)) 
		{
			alert("Invalid Work Phone Number")
			Frm.work_phone_local.focus()
			return false
		}
		// Check work_email text box for an entry.
		if  (!validEmail(Frm.work_email.value)) 
		{
			alert("Invalid Work E-mail")
			Frm.work_email.focus()
			return false
		}
	}

	// If preferred email is home, validate the home email.
    /*if (Frm.preferred_email[0].checked)
	{
		// Check home_email text box for an entry.
		if  (!validEmail(Frm.home_email.value)) 
		{
			alert("Invalid Home E-mail")
			Frm.home_email.focus()
			return false
		}
	}
	else
	{
		// Check work_email text box for an entry.
		if  (!validEmail(Frm.work_email.value)) 
		{
			alert("Invalid Work E-mail")
			Frm.work_email.focus()
			return false
		}
	}*/
		
	// If preferred shipping flag is on, validate the preferred shipping address.
	if (Frm.preferred_shipping_flag.value == 1)
	{
		// If preferred shipping address is home, validate the required fields.
		if (Frm.preferred_shipping_address[0].checked)
		{
			// Check home_street1 text box for an entry.
			if  (!hasChar2(Frm.home_street1.value)) 
			{
				alert("Invalid Home Street Address")
				Frm.home_street1.focus()
				return false
			}

			// Check home_city text box for an entry.
			if  (!hasLetter(Frm.home_city.value)) 
			{
				alert("Invalid Home City")
				Frm.home_city.focus()
				return false
			}

			// Check home_state text box for an entry (USA and Canada only).
			if	((Frm.home_country_id.value == 1) || (Frm.home_country_id.value == 2))
			{
				if  (!hasTwoLetters(Frm.home_state.value)) 
				{
					alert("Invalid Home State")
					Frm.home_state.focus()
					return false
				}
			}
						
			// Check home_postal_code text box for an entry (USA and Canada only).
			if	((Frm.home_country_id.value == 1) || (Frm.home_country_id.value == 2))
			{
				if  (!hasChar2(Frm.home_postal_code.value)) 
				{
					alert("Invalid Home Postal Code")
					Frm.home_postal_code.focus()
					return false
				}
			}

			// Check home_phone_city text box for an entry.
			if  (!hasChar2(Frm.home_phone_city.value)) 
			{
				alert("Invalid Home Phone Code")
				Frm.home_phone_city.focus()
				return false
			}

			// Check home_phone_local select list for an entry.
			if  (!hasChar2(Frm.home_phone_local.value)) 
			{
				alert("Invalid Home Phone Number")
				Frm.home_phone_local.focus()
				return false
			}
		}
		// If preferred shipping address is work, validate the required fields.
		else
		{

			// Check work_title text box for an entry.
			if  (!hasChar2(Frm.work_title.value)) 
			{
				alert("Invalid Work Title")
				Frm.work_title.focus()
				return false
			}

			// Check work_company text box for an entry.
			if  (!hasChar2(Frm.work_company.value))
			{
				alert("Invalid Work Company")
				Frm.work_company.focus()
				return false
			}

			// Check work_street1 text box for an entry.
			if  (!hasChar2(Frm.work_street1.value)) 
			{
				alert("Invalid Work Street Address")
				Frm.work_street1.focus()
				return false
			}

			// Check work_city text box for an entry.
			if  (!hasChar2(Frm.work_city.value)) 
			{
				alert("Invalid Work City")
				Frm.work_city.focus()
				return false
			}

			// Check work_state text box for an entry (USA and Canada only).
			if	((Frm.work_country_id.value == 1) || (Frm.work_country_id.value == 2))
			{
				if  (!hasTwoLetters(Frm.work_state.value)) 
				{
					alert("Invalid Work State")
					Frm.work_state.focus()
					return false
				}
			}

			// Check work_postal_code text box for an entry (USA and Canada only).
			if	((Frm.work_country_id.value == 1) || (Frm.work_country_id.value == 2))
			{
				if  (!hasChar2(Frm.work_postal_code.value)) 
				{
					alert("Invalid Work Postal Code")
					Frm.work_postal_code.focus()
					return false
				}
			}

			// Check work_phone_city text box for an entry.
			if  (!hasChar2(Frm.work_phone_city.value)) 
			{
				alert("Invalid Work Phone Code")
				Frm.work_phone_city.focus()
				return false
			}

			// Check work_phone_local select list for an entry.
			if  (!hasChar2(Frm.work_phone_local.value)) 
			{
				alert("Invalid Work Phone Number")
				Frm.work_phone_local.focus()
				return false
			}
		}
	}	

	// Verify the user has selected a marketing code.
	if (Frm.marketing_code.value  == "--SELECT--")
	{
		alert("Please tell us how you heard about us.");
		return false
	}

	return true
}


// --------------  NewSignIn.asp ----------------

function checkFormNewSignIn(Frm, email, email2)
{
	var matchArr = email.match(emailexp);
	if (email != email2) 
	{
		alert('Your email entries did not match.  Please recheck your entries for errors.');
		Frm.ssn.focus();
		return false;
	}
	else
    {
	    // Validate last name
	    if (Frm.firstname.value  == "")
	    {
		    alert("First name is required.")
		    Frm.firstname.focus()
		    return false
	    }
    			
	    // Validate first name.
	    if (Frm.lastname.value  == "")
	    {
		    alert("Last name is required.")
		    Frm.lastname.focus()
		    return false
	    }
    	
	    // Validate email.
	    if (Frm.email.value == "")
	    {
		    alert("Email is required.")
		    Frm.birthdate.focus()
		    return false
	    }

	    // Verify that the email is properly formatted.
	    if (!validEmail(Frm.email.value))
	    {
		    alert("Please enter a valid email address.")
		    Frm.email.focus()
		    return false
	    }
	    return true
    }
}

// Validate SSN entered twice.  Validation rules for ssn are as follows:
// 1.  SSN must match SSN2 entered.
// 2.  Nine digit numeric.
// 3.  May not begin with 8, 9, 000 or 666.
// 4.  Considering three number sections in format NNN-NN-NNNN, none of the sections may consist of all zeroes.
function checkTwoSSN(Frm, ssn, ssn2) 
{
	var matchArr = ssn.match(ssnexp);
	if (ssn != ssn2) 
	{
		alert('Your SSN entries did not match.  Please recheck your entries for errors.');
		Frm.ssn.focus();
		return false;
	}
	else
	{ 
		if (matchArr == null)
		{
			alert('Invalid SSN.  Your SSN is required to create sign-in.');
			Frm.ssn.focus();
			return false;
		}
		else
		{ 
			if ((parseInt(matchArr[1],10)==0) || (parseInt(matchArr[1],10)==666) || 
				(parseInt(matchArr[2],10)==0) || (parseInt(matchArr[3],10)==0))
			{
				alert('Invalid SSN.  Your SSN is required to create sign-in.');
				Frm.ssn.focus();
				return false;
			}
			else 
			{
				return true;
			}
		}
	}
}

// --------------  RegSignIn.asp ----------------
// No custom javascript.

// --------------  RequestExam.asp ----------------
function checkFormRequestExam(Frm)
{
    //  Check whether a proctor is required.
    if (Frm.proctor_required_flag.value == 1)
    {
        // Either work company or first_name & last_name must be specified.
        // Check work company box for an entry.
        if  (!hasChar2(Frm.work_company.value)) 
        {
            // Check first name box for an entry.
            if  (!hasChar2(Frm.first_name.value)) 
            {
                alert("The proctor's name and/or company is required.")
                Frm.first_name.focus()
                return false
            }	

            // Check last name box for an entry.
            if  (!hasChar2(Frm.last_name.value)) 
            {
                alert("The proctor's name and/or company is required.")
                Frm.last_name.focus()
                return false
            }	
        }

        // Check street1 text box for an entry.
        if  (!hasChar2(Frm.street1.value)) 
        {
            alert("The proctor's address is required.")
            Frm.street1.focus()
            return false
        }

        // Check city text box for an entry.
        if  (!hasLetter(Frm.city.value)) 
        {
            alert("The city is required.")
            Frm.city.focus()
            return false
        }

        // Check state text box for an entry (USA and Canada only).
        if	((Frm.country_id.value == 1) || (Frm.country_id.value == 2))
        {
            if  (!hasTwoLetters(Frm.state.value)) 
            {
                alert("The state is required.")
	            Frm.state.focus()
	            return false
            }
        }
    			
        // Check postal_code text box for an entry (USA and Canada only).
        if	((Frm.country_id.value == 1) || (Frm.country_id.value == 2))
        {
            if  (!hasChar2(Frm.postal_code.value)) 
            {
                alert("The postal code is required.")
	            Frm.postal_code.focus()
	            return false
            }
        }
    }				
	return true
}


// --------------  SignIn.asp ----------------
// No custom javascript.

// --------------  Survey.asp ----------------

// Check Text Response.
function checkText(formElement) 
{
	if (hasChar(formElement.value)) 
	{
		if (!hasChar3(formElement.value)) 
		{
			alert("Please clear blank space(s) or enter text")
			formElement.focus()
			return false
		}
	}
} 

// Check Integer Response.
function checkInteger(formElement)
{
	if (hasChar(formElement.value))
	{
		if (hasDecimal(formElement.value)) 
		{
			alert("Please do not include decimal points in the value entered")
			formElement.focus()
			return false
		}
		if (hasNonDigit(formElement.value)) 
		{
			alert("Please include only digits (0-9) in the value entered")
			formElement.focus()
			return false
		}
		if (!isValid(numexp,(formElement.value))) 
		{
		    alert("Please enter an integer")
			formElement.focus()
			return false
		}
	}
}

// Check Date Response.
function checkDate(formElement,date_format) 
{
    var strAlertDateFormat
    
    if (date_format = 1)
    {
        strAlertDateFormat = "mm/dd/yyyy"
    }
    else 
    {
        strAlertDateFormat = "dd/mm/yyyy"    
    }
    
	if (hasChar(formElement.value)) 
	{
		if (!isDate(formElement.value,date_format)) {
			alert("Please clear blank space(s) or enter a valid date in the specified format (" +strAlertDateFormat+ ").")
			formElement.focus()
			return false
		}
	}
}

// Check Currency Response.
function checkCurrency(formElement) 
{
	if (hasChar(formElement.value)) 
	{
		if (!isCurrency(formElement.value)) 
		{
			alert("Please enter a currency value in ####.## format.  Do not include commas or blank spaces.")
			formElement.focus()
			return false
		}
	}
}

// Validate that required responses were given, and max/min number of multi-choice responses were obeyed.
function checkFormSurvey(Frm) 
{
	var testOk = false;
	
	// Loop through all the form's elements.
	for (var i=0; i<Frm.elements.length; i++) 
	{
		// Get the validator (alt) attribute, if it exists, thereby starting the validation.
		if (Frm.elements[i].getAttribute('alt')) 
		{
			var validateType = Frm.elements[i].getAttribute('alt');
			var validateObj = Frm.elements[i];
			testOk = false;

			// Separate the validation string into parameters.
			var params = validateType.split("|");

			// Call appropriate validation function based on type.
			switch (params[0]) 
			{
				case 'blank':
					if (validateBlank(validateObj, params[1]))
					{
						testOk = true;
					}
					break;
				case 'checkbox':
					if (validateCheckbox(validateObj, params[1], params[2], params[3], params[4]))
					{
						testOk = true;
					}
					break;
				case 'radio':
					if (validateRadio(validateObj, params[1], params[2]))
					{
						testOk = true;
					}
					break;
			}
			if (!testOk) 
			{
				return false;
			}
		}
	}
	
	// Form has been validated
	return true;
}

function validateBlank(formObj, sqText) 
{
	var objName = formatName(formObj);
	var formObj = formObj.form.elements[formObj.name];
	if (!hasChar3(formObj.value)) 
	{
		alert('A response is required for the question, \n"'+sqText+'..."');
		formObj.focus();
		return false;
	}
	else 
	{
		return true;
	}
}

function validateCheckbox(formObj, webReq, minC, maxC, sqText) 
{
	var objName = formatName(formObj);
	var formObj = formObj.form.elements[formObj.name];
	var checkTotal = formObj.length;
	var checkCount = 0;

	// Count the number of checked items.
    for (var i=0; i<checkTotal; i++) 
    {
		if (formObj[i].checked) 
		{
			checkCount++;
		}
	}
	// If a response is required...
	if (webReq == 1)
	{
		// Alert the registrant if no items have been checked.
		if (checkCount == 0)
		{
			alert('A response is required for the question, \n"'+sqText+'..."');
			formObj[0].focus();
			return false;
		}

		// Alert the registrant if too many or too few items have been checked.
		if (checkCount < minC || checkCount > maxC) 
		{
			alert('Please select between '+minC+' and '+maxC+' options for the question, \n "'+sqText+'...". \nYou currently have '+checkCount+' selected.');
			formObj[0].focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
	// If a response is NOT required...
	else
	{
		// If no items have been checked, that is fine.
		if (checkCount == 0)
		{
			return true;
		}
		else
		{
			// Alert the registrant if too many or too few items have been checked (zero is acceptable even if below minimum because response not required).
			if (checkCount < minC || checkCount > maxC) 
			{
				alert('Please select between '+minC+' and '+maxC+' options for the question, \n "'+sqText+'...". \nYou currently have '+checkCount+' selected.');
				formObj[0].focus();
				return false;
			}
			else 
			{
				return true;
			}
		}
	}
}

function validateRadio(formObj, webReq, sqText) 
{    
	var objName = formatName(formObj);
	var formObj = formObj.form.elements[formObj.name];
	var selectTotal = 0;
	for (i=0; i<formObj.length; i++) 
	{
		if (formObj[i].checked) 
		{
			selectTotal++;
		}
	}
	// If a response is required...
	if (webReq == 1)
	{
		// Alert the registrant if no items have been checked.		
		if (selectTotal != 1) 
		{
			alert('A response is required for the question, \n"'+sqText+'..."');
			formObj[0].focus();
			return false;
		}
		else
		{
			return true;
		}		
	}        
	else 
	{
		return true;
	}
}

function formatName(o) 
{
	var wStr = (o.name) ? o.name : o.id;
	wStr = wStr.replace(/_/g," ");
	return wStr;
}


// --------------  TermsOfUse.asp ----------------
function checkAccept(Frm) 
{
	if (Frm.acceptance[0].checked)
	{
		return true
	}
	else
	{
		alert("To proceed with your registration, you must accept these terms of use.");
		return false
	}
}


// --------------  SchoolExternal.asp (CUST-008) ----------------

// Sets form fields to empty when user clicks the "Reset" button.
function clearInputs(Frm) 
{
	Frm.school_type_id.value = "";
	Frm.county_name.value = "";
	Frm.district_name.value = "";
	Frm.school_name.value = "";
	Frm.proctor_first_name.value = "";
	Frm.proctor_last_name.value = "";
	Frm.proctor_street1.value = "";
	Frm.proctor_street2.value = "";
	Frm.proctor_street3.value = "";
	Frm.proctor_city.value = "";
	Frm.proctor_state.value = "";
	Frm.proctor_postal_code.value = "";
	Frm.proctor_country_id.value = "";
	Frm.proctor_phone_country.value = "";
	Frm.proctor_phone_city.value = "";
	Frm.proctor_phone_local.value = "";
	Frm.proctor_phone_extension.value = "";
}
	
// Verify the user has selected an item from the drop-down list provided (school_type, county, district, or school).
function checkFormSchoolExternal(Frm)
{
	if (Frm.school_type_id.value  == "-- Please Select One")
	{
		alert("Please select a school type.");
		return false
	}
	if (Frm.county_name.value  == "-- Please Select One")
	{
		alert("Please select a county.");
		return false
	}
	if (Frm.district_name.value  == "-- Please Select One")
	{
		alert("Please select a district.");
		return false
	}
	if (Frm.school_name.value  == "-- Please Select One")
	{
		alert("Please select a school.");
		return false
	}
	return true
}

// --------------  Waitlist.asp (CUST-009) ----------------

function checkFormWaitlist(Frm)
{
		// Check rp_first_name text box for an entry.
		if  (!hasChar2(Frm.rp_first_name.value)) 
		{
			alert("Responsible Party name is required")
			Frm.rp_first_name.focus()
			return false
		}
		// Check rp_last_name text box for an entry.
		if  (!hasChar2(Frm.rp_last_name.value)) 
		{
			alert("Responsible Party name is required")
			Frm.rp_last_name.focus()
			return false
		}
		// Check first_name text box for an entry.
		if  (!hasChar2(Frm.first_name.value)) 
		{
			alert("Student name is required")
			Frm.first_name.focus()
			return false
		}
		// Check last_name text box for an entry.
		if  (!hasChar2(Frm.last_name.value)) 
		{
			alert("Student name is required")
			Frm.last_name.focus()
			return false
		}
		// Check preferred_email text box for an entry.
		if  (!validEmail(Frm.preferred_email.value)) 
		{
			alert("Valid e-mail address is required")
			Frm.preferred_email.focus()
			return false
		}
		// Check preferred_phone_city text box for an entry.
		if  (!hasChar2(Frm.preferred_phone_city.value)) 
		{
			alert("Invalid phone number")
			Frm.preferred_phone_city.focus()
			return false
		}

		// Check preferred_phone_local select list for an entry.
		if  (!hasChar2(Frm.preferred_phone_local.value)) 
		{
			alert("Invalid phone number")
			Frm.preferred_phone_local.focus()
			return false
		}


	return true
}


// --------------  NewSignIn.asp (CUST-013) ----------------
// No custom javascript.

// --------------  RegSignIn.asp (CUST-013) ----------------
// No custom javascript.

// --------------  SignIn.asp (CUST-013) ----------------
// No custom javascript.

