

// This Document contains:

// General Functions
// Validation Functions
// Field Formatting Functions
// Get Data Functions
// Get Form Element status


// General Functions
	
	// Returns true if character c is a digit
	// (0 .. 9).
	function isDigit(c) {
		return ((c >= "0") && (c <= "9"))
	}
	
	function isWhite(c) {
		return ((c == ' ') || (c == '\t') || (c == '\n') || (c== '\r'))
	}

	function isLetter(c) {
		return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
	}

	// This function converts any string into a new string containing only
	// numeric characters (0-9)
	//    Precondition:   argument, myString, must be a string of characters
	//    Postcondition: returns newString, which contains only numeric characters.
	function makeNumeric(myString) {
		var newString = ""   // This stores the new string

		// This loop iterates through the old string
		for (var i = 0; i < myString.length; i++) {
			next = myString.charAt(i) // Read a character
			
			if (isDigit(next)) {			// If the character is a number, store it in the new string
				newString += next
			}
		} 
		return newString
	}
	
	function trimString(strText) { 
		// this will get rid of leading spaces 
		while (strText.substring(0,1) == ' ') 
			strText = strText.substring(1, strText.length);
		
		// this will get rid of trailing spaces 
		while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
		return strText;
	}

	function makeAlpha(myString) {
		var newString = ""   // This stores the new string

		// This loop iterates through the old string
		for (var i = 0; i < myString.length; i++) {
			next = myString.charAt(i) // Read a character
			
			if (isLetter(next)) {			// If the character is a letter, store it in the new string
				newString += next
			}
		} 
		return newString
	}
	

	// Finds and replaces a target character in the string
	// Returns the new string
	function replaceTargetChar(myString, targetChar, replacementChar) {
		var newString = ""   // This stores the new string

		// This loop iterates through the old string
		for (var i = 0; i < myString.length; i++) {
			next = myString.charAt(i) // Read a character
			
			if (next == targetChar) {			// If the character is the targetChar, replace it with the replacementChar
				next = replacementChar
			} else {
			}
			newString += next
		} 
		return newString
	}
	
	function getNumberOfCharacters(targetString) {
		numberOfCharacters = 0
		for (var i = 0; i < targetString.length; i++) {   
			numberOfCharacters++
		}
		return numberOfCharacters
	}
	
	
	function containsValidCharacters(targetString) { 
		// Search through string's characters one by one until we find a character that doesn not match one of the allowed characters.
		// When we do, return false; if we don't, return true.

		for (var i = 0; i < targetString.length; i++) {   
		
			// Check that current character is number or letter.
			var c = targetString.charAt(i)

			if (! isWhite(c)) {
				if 	(!(		isLetter(c)
						||	isDigit(c)
						||	c == "~"
						||	c == "`"
						||	c == "!"
						||	c == "@"
						||	c == "#"
						||	c == "$"
						||	c == "%"
						||	c == "^"
						||	c == "&"
						||	c == "*"
						||	c == "("
						||	c == ")"
						||	c == "-"
						||	c == "_"
						||	c == "+"
						||	c == "="
						||	c == "{"
						||	c == "}"
						||	c == "["
						||	c == "]"
						||	c == "\\"
						||	c == "|"
						||	c == ":"
						||	c == ";"
						||	c == "\""
						||	c == "'"
						||	c == "<"
						||	c == ">"
						||	c == ","
						||	c == "."
						||	c == "?"
						||	c == "/"
						||	c.charCodeAt(0) == 8216
						||	c.charCodeAt(0) == 8217
						||	c.charCodeAt(0) == 8220
						||	c.charCodeAt(0) == 8221
					)) {
					//alert("Invalid Character Found: " + c + " (Unicode: " + c.charCodeAt(0) + ")")
					return false
				}
			}
		}
		// All characters are ok
		return true
	}

	function containsEmailCharacters(targetString) { 
		// Search through string's characters one by one
	    	// until we find a special character that's not allowed in an email address.
		// (only letters, numbers and dashes, dots, and "@" symbols are allowed)

		for (var i = 0; i < targetString.length; i++) {   
		
			// Check that current character is number or letter.
			var c = targetString.charAt(i)

			if (!(		isLetter(c)
					||	isDigit(c)
					||	c == "."
					||	c == "-"
					||	c == "_"
					||	c == "@"
				)) {
				return false
			}
		}
		// All characters are ok.
		return true
	}

	function containsWebCharacters(targetString) { 
		// Search through string's characters one by one
	    	// until we find a special character that's not allowed in an Web site address.
		// (only letters, numbers and dashes, and dots symbols are allowed)

		for (var i = 0; i < targetString.length; i++) {   
		
			// Check that current character is number or letter.
			var c = targetString.charAt(i)

			if (!(		isLetter(c)
					||	isDigit(c)
					||	c == "."
					||	c == "-"
				)) {
				return false
			}
		}
		// All characters are ok.
		return true
	}

	function isEmailFormat(targetString) {
		 var result = false;
		 var theStr = new String(targetString);
		 var index = theStr.indexOf("@");

		 if (index > 0)
		 {
			var pindex = theStr.indexOf(".",index);

			if ((pindex > index+1) && (theStr.length > pindex+1))

			result = true;
		 }
		 return result;
	}


	function isWebFormat(targetString) {
		 var theStr = new String(targetString);
		 var index = theStr.indexOf(".");

		 if ((index > 0) && (theStr.length > index+1)) {
			return true;
		 } else {
			 return false;
		 }
	}


	// This function adds hyphens to a string in the format of a phone number
	// (ie. "0123456789" is changed to "012-345-6789")
	//    Precondition:   argument, myString, must be a string of characters
	//    Postcondition: returns newString, which contains two hyphens.   
	function addHyphens(myString) {
		var strHyphen = "-" // This stores a hyphen for later insertion
		var newString = ""   // This stores the new string

		// This loop iterates through the old string
  		for (var i = 1; i <= 10; i++) {
  		
			if ((i == 4)||(i == 7))  {		// If the 4th or 7th positions are being read, insert a hyphen
				newString += strHyphen
			}
			
			newString += myString.charAt(i - 1)
		}
		
		return newString
	}



// Standard Form Validation Functions

	// If the value is not an empty string
	//	AND is formatted as an email
	//	AND only contains email-related special characters (numbers, letters, @ . - _ )
	function isValidEmailField(valueString) {
		if (isEmailFormat(valueString) && containsEmailCharacters(valueString)) {
			return true
		} else {
			return false
		}
	}
	
	// If the value is not an empty string
	//	AND is formatted as an email
	//	AND only contains email-related special characters (numbers, letters, @ . - _ )
	function isValidWebField(valueString) {
		if (isWebFormat(valueString) && containsWebCharacters(valueString)) {
			return true
		} else {
			return false
		}
	}
	
	// If the value is not an empty string
	//	AND only contains allowed special characters
	function isValidTextField(valueString) {
		if (containsValidCharacters(valueString)) {
			return true
		} else {
			return false
		}
	}

	// If the value is not an empty string
	//	AND only contains numbers
	//	AND is exactly 5 characters in length
	function isValidZipField(valueString) {
		if (valueString.length == 5 && !(isNaN(valueString))) {
			return true
		} else {
			return false
		}
	}

	// If the value is not an empty string
	//	AND only contains numbers
	//	AND is exactly 4 characters in length
	function isValidZipSuffixField(valueString) {
		if (valueString.length == 4 && !(isNaN(valueString))) {
			return true
		} else {
			return false
		}
	}

	// If the value is exactly 12 characters in length
	function isValidPhoneField(valueString) {
		if (valueString.length == 12) {
			return true
		} else {
			return false
		}
	}

	// If the value is a number
	function isValidPhoneExtField(valueString) {
		if (valueString.length == 0 || !(isNaN(valueString))) {
			return true
		} else {
			return false
		}
	}



// Get Form Element status

	// If an array of form elements are passed to this script, it will return true if one of them is checked. Otherwise it returns false
	function hasOneChecked(targetArray) {
		//alert (targetObject.name + " checking to see if one is checked")
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray[element].name + ": " + targetArray[element].checked)
			//alert (targetArray[element].value + ": " + targetArray[element].checked)
			if (targetArray[element]) {
				if (targetArray[element].checked)
					return true
			}
		}
		return false
	}
	
	// If an array of form elements are passed to this script, it will return true if one of them is selected. Otherwise it returns false
	function hasOneSelected(targetArray) {
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray.options[element].value + ": " + targetArray.options[element].selected
			if ((targetArray.options[element].value != "") && (targetArray.options[element].selected))
				return true
		}
		return false
	}
	
	// If an array of form elements are passed to this script, it will return true if two ore more of them are selected. Otherwise it returns false
	function hasMultipleSelected(targetArray) {
		var count = 0
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray.options[element].value + ": " + targetArray.options[element].selected
			if ((targetArray.options[element].value != "") && (targetArray.options[element].selected))
				count++
		}
		if (count > 1)
			return true
		else
			return false
	}
	
	// Return the value of the checked element (in a group of checkboxes or radio buttons)
	function getCheckedValue(targetArray) {
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray[element].name + ": " + targetArray[element].checked)
			//alert (targetArray[element].value + ": " + targetArray[element].checked)
			if (targetArray[element].checked) {
				return targetArray[element].value
			}
		}
		//return "Y"
		return ""
	}
	
	function getSelectedValue(targetArray) {
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray.options[element].value + ": " + targetArray.options[element].selected
			if ((targetArray.options[element].value != "") && (targetArray.options[element].selected))
				return targetArray.options[element].value
		}
		return ""
	}

	function isEmptyField(targetObject) {
		//alert (targetObject.name + " has a type " + targetObject.type)
		switch (targetObject.type) {
			case "text":
			case "textarea":
			case "hidden":
			case "password":
				if (targetObject.value != ""){
					//alert (targetObject.name + " has a value")
					return false
				}
				break
			case "select-one":
			case "select-multiple":
				if (hasOneSelected(targetObject)){
					//alert (targetObject.name + " has one selected")
					return false
				}
				break
			case "checkbox":
				if (targetObject.checked){
					//alert (targetObject.name + " is checked")
					return false
				}
				break
			default:
				// radio button sets are weird in that the main set object does not have a .type property.
				// So one of the individual radio buttons .type property must be used to find out what type of object it is.
				// In this case we're simply looking at the first one (targetObject[0] means radioButtonSet.firstRadioButton)
				
				if (targetObject.type == "radio") {
					if (hasOneChecked(targetObject)){
						//alert (targetObject.name + " has one selected")
						return false
					}
				} else {
					//alert (targetObject.type)
				}
				break
		}
		// If none of the above cases found a field with a value, then return true
		return true
	}


	function isEmptyForm(targetForm) {
		for (elementIndex = 0; elementIndex < targetForm.elements.length; elementIndex++)  {
			nextObject = targetForm.elements[elementIndex]
			//alert ("checking number "+elementIndex+": " + nextObject.name)
			//alert ("targetArray.length is "+targetArray.length)
			// if the next element has value then the form is not empty, so return false
			if (!(isEmptyField(nextObject))) {
				return false
			}
		}
		//alert ("targetArray.length is "+targetArray.length)
		//alert ("element is "+elementIndex)
		//alert(nextObject.name + " broke the loop")
		return true
	}



// Empy Multiple Select Menu
	// Pass the name of the multiple select menu to this function and it will clear all selections
	function clearMultipleSelectMenu(targetArray) {
		for (element = 0; element < targetArray.length; element++)  {
			targetArray.options[element].selected = false;
		}
	}




// Field Formatting Functions

	// Attempts to deduce whether the user intends AM or PM
	// If the string contains the letter "a" then returns AM
	// If the string contains the letter "p" then returns PM
	// If both of the above tests fail, and the target name contains the string "b", 
	// 	then the field is the "begin" field (as opposed to the "end" field) and so it returns AM else PM
	function getValidAMPM(myAMPM, targetName) {
		if (myAMPM.indexOf("A") >= 0 || myAMPM.indexOf("a") >= 0)
			return "AM"
		else if (myAMPM.indexOf("P") >= 0 || myAMPM.indexOf("p") >= 0)
			return "PM"
		
		else if (targetName.indexOf("b") >= 0 || targetName.indexOf("B") >= 0)
			return "AM"
		else
			return "PM"
	}
	function getValidHours(myHours, myAMPM) {
		if (myHours == "") {
			if (myAMPM == "AM")
				return "9"
			if (myAMPM == "PM")
				return "5"
		}
			
		myHoursNumber = Number(myHours)
		if ((myHoursNumber < 1) || (myHoursNumber > 12)) {
			if (myAMPM == "AM")
				return "9"
			if (myAMPM == "PM")
				return "5"
		} else {
			return myHoursNumber
		}
	}
	function getValidMinutes(myMinutes, myAMPM) {
		if (myMinutes == "")
			return "00"
			
		myMinutesNumber = Number(myMinutes)
		if ((myMinutesNumber < 0) || (myMinutesNumber > 59)) {
			return "00"
		} else {
			if (myMinutesNumber < 10)
				return "0" + myMinutesNumber
			else {
				return myMinutesNumber
			}
		}
	}
	function getValidTime(myHours, myMinutes, myAMPM, targetName) {
		myAMPM = getValidAMPM(myAMPM, targetName)
		myHours = getValidHours(myHours, myAMPM)
		myMinutes = getValidMinutes(myMinutes, myAMPM)
		return myHours + ":" + myMinutes + myAMPM
	}
	
	
	function handleChangeTime(targetObject)
	{
		var targetValue = targetObject.value
		var targetName = targetObject.name
		
		var myArray = targetName.split("_")
		var dayObject = targetObject.form.elements[myArray[0]]
    		
		if (targetValue != "") {
			myArray = targetValue.split(":")
			myHours = makeNumeric(myArray[0])
			if (myArray.length > 1) {
				endValue = myArray[1]
				myMinutes = makeNumeric(endValue)
				myAMPM = makeAlpha(endValue)
			} else {
				//alert("Error: targetValue: " + targetValue)
				myMinutes = ""
				myAMPM = ""
			}
			
			myNewValue = getValidTime(myHours, myMinutes, myAMPM, targetName)
    			targetObject.value = myNewValue
			
			dayObject.checked = true
			/*if (targetObject.form.elements[dayObject.name+"_begin_hours"].value == "")
				targetObject.form.elements[dayObject.name+"_begin_hours"].focus()
			if (targetObject.form.elements[dayObject.name+"_end_hours"].value == "")
				targetObject.form.elements[dayObject.name+"_end_hours"].focus()*/
    		}
	}

	function handleClickDay(targetObject) {
		//alert (targetObject.value + ": " + targetObject.checked)
		if (targetObject.checked) {
			//alert (targetObject.form.elements[targetObject.value+"_begin_hours"].name)
			if (targetObject.form.elements[targetObject.name+"_begin_hours"].value == "")
				targetObject.form.elements[targetObject.name+"_begin_hours"].value = "9:00AM";
			if (targetObject.form.elements[targetObject.name+"_end_hours"].value == "")
				targetObject.form.elements[targetObject.name+"_end_hours"].value = "5:00PM";
		} else {
			//alert (targetObject.form.elements[targetObject.value+"_begin_hours"].name)
			targetObject.form.elements[targetObject.name+"_begin_hours"].value = "";
			targetObject.form.elements[targetObject.name+"_end_hours"].value = "";
		}
	}
	
	// This function is called from the textfield's onchange() event-handler. It calles two
	// functions which remove any non-numeric characters from the string and then format
	// the string with the proper parentheses and hyphens.
	function handleChangePhone(targetObject)
	{
		var myValue = targetObject.value
    		
		if (myValue != "") {
			myValue = makeNumeric(myValue)
    			myValue = addHyphens(myValue)
    			targetObject.value = myValue
    		}
	}

	function trimTextFields(targetArray) {
		for (elementIndex = 0; elementIndex < targetArray.length; elementIndex++)  {
			nextObject = targetArray[elementIndex]
			// if the next elementIndex has value and is type "text"
			if ((nextObject.value != "") && (nextObject.type == "text")) {
				nextObject.value = trimString(nextObject.value)
			}
		}
		return true
	}
	
	// If an array of checkbox form elements are passed to this script, it will check all of them.
	function checkAll(targetArray) {
		//alert (targetObject.name + " checking to see if one is checked")
		for (element = 0; element < targetArray.length; element++)  {
			//alert (targetArray[element].name + ": " + targetArray[element].checked)
			//alert (targetArray[element].value + ": " + targetArray[element].checked)
			if (targetArray[element]) {
				targetArray[element].checked = true
			}
		}
	}
	
	// Returns true if the enter key was just pressed.
	function enterWasPressed() {
		evt = event
		
		if (evt.which) {
			charCode = evt.which
		} else {
			charCode = evt.keyCode
		}
		
		if (charCode == 13) {
			return true
		} else {
			return false
		}
	}
	
	

// Get Data Functions

	// Returns a value from the QueryString
	function getQueryStringValue(strFieldName) {
		var strFieldValue;
		var objRegExp = new RegExp(strFieldName + "=([^&]+)","gi");
	
		if (objRegExp.test(location.search))strFieldValue = unescape(RegExp.$1);
		else strFieldValue="";

		return strFieldValue;
	 }



// Pop Up a Window
	// function popWindow(url, widthNumber, heightNumber) {
	function popWindow(url) {
		widthNumber = 300
		heightNumber = 450
//		heightNumber = (screen.availHeight - 60)
// //	topNumber = 50
//		topNumber = 0
// //	leftNumber = 200
		topNumber = (screen.availHeight - heightNumber) / 2
		leftNumber = (document.documentElement.clientWidth - widthNumber)
		mypopwindow = window.open(url, "popupwindow", "width=" + widthNumber + ",height=" + heightNumber + ",top=" + topNumber + ",left=" + leftNumber + ",alwaysRaised=yes,toolbar=no,directories=no,menubar=no,status=yes,resizable=yes,location=no,scrollbars=yes,copyhistory=no")
		mypopwindow.focus()
	}


	function selectCheckBox(frm,fieldName,checkCategory) 
	{
		//alert(fieldName)

		if (frm.elements[fieldName].type == "text")
		{
			if (frm.elements[fieldName].value != "")
			{
				frm.elements[checkCategory].checked = true
			}
		}
		else if (frm.elements[fieldName].type == "select-one")
		{
			for (i = 0; i < frm.elements[fieldName].length; i++)
			{
				if (frm.elements[fieldName].options[i].selected == true)
				{
					if (frm.elements[fieldName].options[i].value != "")
						frm.elements[checkCategory].checked = true
				}
			}
		}

	}

	function clearCheckBox(frm,fieldName) 
	{
		if (frm.elements[fieldName].checked != true)
		{
			if (frm.elements[fieldName].name == "service_area")
			{
				frm.program_city.value = ""
				frm.program_state.value = ""
			}
			else if (frm.elements[fieldName].name == "office_location")
			{
				frm.location_city.value = ""
				frm.location_state.value = ""
			}
			else if (frm.elements[fieldName].name == "specific_hours")
			{
				frm.weekday.value = ""
				frm.before_after.value = ""
				frm.program_hours.value = ""
			}
		}
	}
	
	
	

 
// ************************************************************
// The following code implements the validation for the date fields
// The functions are:
//
//     1) getDaysInMonth(month, year)
//     2) getNext(string, myTarget)
//     3) isDate(string)
// ************************************************************



	// Read the next item in a string (myFlag is a flag string of any length,
	// to indicate when the end of the next item has been reached)
	// returns the next item as a string
	// Note: 	Returns an empty string if there are no characters preceding the myTarget string
	// 			Returns myFlag if the myTarget string was not found
	function getDaysInMonth (month, year) {
	
		var feb = 28
		if ((year % 4) == 0) {
			feb = 29			// If it's a leap year
		}
		var monthArray = [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
	
		return monthArray[month - 1]	
	}


	// Attempts to find myTarget in myString and returns the position if found, else returns failed
	function findTargetPosition(myString, myTarget) {
	
		//if (debug) alert ("finding myTarget: " + myTarget + "in" + myString)
	
		// Searches for myTarget in myString
		for (var i = 0; i < myString.length; i++) {
			if (myString.substring(i,i + myTarget.length) == myTarget) {
				return i
			}
		}
		return "failed"
	}
	
	
	
	// Read the next item in a string (myFlag is a flag string of any length,
	// to indicate when the end of the next item has been reached)
	// returns the next item as a string
	// Note: 	Returns an empty string if there are no characters preceding the myTarget string
	// 		Returns myFlag if the myTarget string was not found
	function getNext (myString, myFlag) {
	
		//alert ("Getting from: " + myString + " until: " + myFlag)
		
		var next = ""
		var result = ""
		var position = 0
		
		
		while (position == 0) {
			result = findTargetPosition(myString, myFlag)
			if (result == "failed") {
				// if myTarget wasn't found, return myTarget
				return myFlag
			} else {
				position = Number(result)
				if (position > 0) {
					// give the "next" string the value of the characters before the flag
					next = myString.substring(0, position - myFlag.length + 1)
					return next
				}
			}
		}
	}
	


	// Returns a new string with the myTarget string removed
	function removeTarget (myString, myTarget) {
		var newString = ""
		var remainingString = ""
		var characterCount = 0
	
		var nextPart = ""
		
				
		if (myString.length > 0) {
			do {
				remainingString = myString.substring(characterCount, myString.length)
				nextPart = getNext(remainingString, myTarget)
				if (nextPart == myTarget) { // Target was not found so the rest of the string should be selected
					nextPart = remainingString
					characterCount = myString.length
				}
				characterCount += nextPart.length + myTarget.length
				
				newString += nextPart
						
			} while (characterCount < myString.length)	
		}
		return newString
	}

	
	// If dateString is in the format mm/dd/yyyy this function will
	// remove any non-numeric characters other than "/" from
	// the dateString and then return it. 
	// Else returns "failed"
	function makeValidDate(dateString) {
		//alert("makeValidDate: " + dateString)
		
		var remainingString = ""
		var characterCount = 0
	
		var nextPart = ""
		var nextNumber = 0
		var myTarget = "/"
		var month
		var day
		var year
		
		var dateArray = []
		var loopCount = 0
		
		
		if (dateString.length > 0) {
			do {
				remainingString = dateString.substring(characterCount, dateString.length)
				nextPart = getNext(remainingString, myTarget)
				if (nextPart == myTarget) {	// Target was not found so the rest of the string should be selected
					nextPart = remainingString
					characterCount = dateString.length
				}
				characterCount += nextPart.length + myTarget.length
				
				nextPart = makeNumeric(nextPart)
				nextNumber = Number(nextPart)
				
				dateArray[loopCount] = nextNumber
				loopCount++
						
			} while (characterCount < dateString.length)	
		}
		
		//alert("month: " + dateArray[0] + "day: " + dateArray[1] + "year: " + dateArray[2])
		
		
		month = dateArray[0]
		day = dateArray[1]
		year = dateArray[2]
		
		if 	(	((month >= 1) 	&& (month <= 12)) 	&&
				((day >= 1) 		&& (day <= getDaysInMonth(month, year)))		&&
				((year >= 1900) 	&& (year <= 2100)) 	){
				
			return month + "/" + day + "/" + year
			
		} else {
			return "failed"
		}
	}
	
	

// ************************************************************
// End Date Functions
// ************************************************************ 





// Manipulate DOM

	/*function showObject(targetName) {
		var targetObject = getObject(targetName);
		targetObject.style.display = "block";
	}
	function hideObject(targetName) {
		var targetObject = getObject(targetName);
		targetObject.style.display = "none";
	}*/
	function getObject(targetID) {
		//alert("getObject( "+targetID+" )");
		if (!document.getElementById) {
			//alert ("error! browser does not support: getElementById()")
			return null;
		} else {
			//alert ("success! browser does support: getElementById()")
		}
		return document.getElementById(targetID);
	}
	function getElementsByClass(parentObject, targetClass) {
		//alert("getElementsByClass( "+parentObject+", "+targetClass+" )");
		if (!parentObject.firstChild) {
			//alert ("error! browser does not support: .firstChild")
			return null;
		} else {
			//alert ("success! browser does support: .firstChild")
		}
		var targetObjectsArray = new Array();
		var counter = 0;
		var nextNode = parentObject.firstChild;
		while (nextNode != parentObject.lastChild) {
			//alert(nextNode.className);
			if (nextNode.className == targetClass) {
				//alert("match");
				targetObjectsArray[counter] = nextNode;
				counter++;
			}
			nextNode = nextNode.nextSibling;
		}
		//alert ("finished");
		return targetObjectsArray;
	}




	// Open an external link
	function openExternalLink(url) {
		if (confirm("\nNOTICE: You are now leaving the Assistance Program Pages Web site.\n\n\nDISCLAIMER OF ENDORSEMENT: The appearance of external hyperlinks does not constitute endorsement by the Department of Veterans Affairs of the linked web sites, or the information, products or services contained therein. For other than authorized VA activities, the Department does not exercise any editorial control over the information you may find at these locations. All links are provided with the intent of meeting the mission of the Department and the VA web site. Please let us know about existing external links which you believe are inappropriate and about specific additional external links which you believe ought to be included.")) {
			window.open (url, "transferring")
		}
	}