<!-- Begin
var FirstTime= true

function isValidForm(theForm)
{
	if (!isValidEntries(theForm))
		return false
	if (FirstTime) {
		FirstTime= false
		theForm.validated.value= 'A0K'
		theForm.submit()			//submit form
	} else {
		alert('Information already submitted --- Click Reset before resubmiting.')
		return false
	}
}

function entryLabel(entryName) {
if ((Label= document.getElementById(entryName +'_')) != null)
	return Label.innerHTML
else if ((Label= entry.className.indexOf('label:')) != -1)
	return entry.className.substring(Label+6, entry.className.indexOf(';', Label))
else return entryName
}

function isValidEntries(theForm)
{
var j= 0	//element index

while (j < theForm.elements.length)  {
	entry= theForm.elements[j++]
	if (entry.type == 'hidden')	continue
//	if (entry.parentNode.style.display == 'none') continue
//	if (entry.parentNode.parentNode.style.display == 'none') continue
//	if (entry.parentNode.parentNode.parentNode.style.display == 'none') continue

	if (entry.className.indexOf('required') != -1 || entry.value != '') {
//			alert('name: ' +entry.name +'; type: ' +entry.type +'; value: ' +entry.value +'; class: ' +entry.className)
	if (entry.value == '') {
		if (entry.nodeName == 'SELECT')
			alert('Please select [' +entryLabel(entry.name) +'] and Submit again.')
		else
			alert('Please enter [' +entryLabel(entry.name) +'] and Submit again.')
		entry.focus()
		return false	
	} else if (entry.className.indexOf('email') != -1) {
	    if (isEmail(entry.value)) continue
		alert('Please enter a valid e-mail address [' +entryLabel(entry.name) +']')
		entry.focus()
		return false
	} else if (entry.className.indexOf('date') != -1) {
	    if (isDate(entry.value)) continue
		alert('Please enter a valid date [' +entryLabel(entry.name) +'] in mm/dd/yyyy format.')
		entry.focus()
		return false
	} else if (entry.className.indexOf('phone') != -1) {
		var stripped = entry.value.replace(/[\(\)\.\-\ ]/g, '')
    	if (isNaN(parseInt(stripped)) || !(stripped.length == 10)) {
			alert('Please correct incorrectly formated phone number [' +entryLabel(entry.name) +']')
			entry.focus()
			return false
		} else continue
	} else if (entry.className.indexOf('socSec') != -1) {
		var stripped = entry.value.replace(/[\(\)\.\-\ ]/g, '')
    	if (isNaN(parseInt(stripped)) || !(stripped.length == 9)) {
			alert('Please correct incorrectly formated social security number [' +entryLabel(entry.name) +']')
			entry.focus()
			return false
		} else continue
	} else if (entry.type == 'radio' && entry.className.indexOf('required') != -1) {
		noSelect= true;
		radioButtons= eval('theForm.' +entry.name)
		for (i= 0; i < radioButtons.length; i++)
			if (radioButtons[i].checked) noSelect= false
		if (noSelect) {
			entry.focus()
			alert('Please select one of the options (buttons) for ' + entryLabel(entry.name))
			return false
		}
	} else if (entry.className.indexOf('num1') != -1 && (isNaN(entry.value) || entry.value < 1)) {
	    alert(entryLabel(entry.name) + ' must be greater than 1; reenter and try again.')
	    entry.focus()
	    return false
	} //if null entry
    } //if formrequired
	else if (entry.className.indexOf('Agree') != -1 && !entry.checked) {
		alert(entryLabel(entry.name) + ' - You must indicate acceptance of the agreement before we can process your application.')
		entry.focus()
		return false
	}
} //while
return true
}

function isEmail(Elem)
{
var AtSym    = Elem.indexOf('@')		//first @
var LastDot  = Elem.lastIndexOf('.')	//last period
var FirstDot = AtSym +Elem.substring(AtSym).indexOf('.')	//first period
var Space    = Elem.indexOf(' ')		//first space
var Length   = Elem.length

if ((AtSym < 1) ||		// '@' cannot be in first position
	(FirstDot < AtSym+3) ||	// at least two char between '@' and first dot
	(LastDot > Length-3) ||	// at least two char after last dot
	((LastDot != FirstDot)
	&& (LastDot < FirstDot+3)) ||	// only one dot or two char between them
	(Space  != -1))		// no empty spaces
		return false
return true
}

function isDate(Elem) {
   var re= /^\d{1,2}\/\d{1,2}\/\d{4}$/
   if (re.test(Elem)) {
      var Arg= Elem.split('/');
      var d= new Date(Elem);
      return d.getMonth() +1 == Arg[0] && d.getDate() == Arg[1] && d.getFullYear() == Arg[2];
   }
   else return false;
}

function ResetForm()
{
	FirstTime= true
	validated= false
}


//////////////////// remaining is legacy code ///////////////////


function IsEmailValid(FormName, ElemName)
{
var Elem     = FormName.elements[ElemName]
var AtSym    = Elem.value.indexOf('@')		//first @
var LastDot  = Elem.value.lastIndexOf('.')	//last period
var FirstDot = AtSym +Elem.value.substring(AtSym).indexOf('.')	//first period
var Space    = Elem.value.indexOf(' ')		//first space
var Length   = Elem.value.length

if ((AtSym < 1) ||		// '@' cannot be in first position
    (FirstDot < AtSym+3) ||	// at least two char between '@' and first dot
    (LastDot > Length-3) ||	// at least two char after last dot
    ((LastDot != FirstDot)
  && (LastDot < FirstDot+3)) ||	// only one dot or two char between them
    (Space  != -1))		// no empty spaces
   {
//    code= AtSym*10000 +FirstDot*100 +LastDot + Length/100
//    alert('Invalid e-mail address [' +code +']')
      alert('Please enter a valid e-mail address [' +Elem.value +']')
      Elem.focus()
      return false
   }
return true
}

function AreItemsValid(FormName)
{
var j= 0	//element index

/* add restricted extensions to the list below
 * place between the /^ and / characters
 * separate each extension by a pipe symbol |
 */

while (j < FormName.elements.length)  {
    entry= FormName.elements[j]
    entrytype= entry.datatype
    if (entrytype != 'optional') {
//	alert('name: ' +entry.name +'; type: ' +entry.type +'; value: ' +entry.value +'; datatype: ' +entrytype)
	if (entrytype == 'emailopt') {
	    if ((entry.value != '') && !IsEmailValid(FormName, entry.name)) return false
	} else if (entry.value == '') {
	    alert('Please enter '+entry.name +' and Submit again.')
	    entry.focus()
	    return false	
	} else if (entrytype == 'email') {
	    if (!IsEmailValid(FormName, entry.name)) return false
	} else if ((entrytype == 'phone') && entry.value.length < 12) {
	    alert('Please reformat ' +entry.name +' entry and Submit again.')
	    entry.focus()
	    return false
	} else if ((entrytype == 'num1') && (isNaN(entry.value) || entry.value < 1)) {
	    alert(entry.name + ' must be greater than 1; reenter and try again.')
	    entry.focus()
	    return false
	}
    } //if
    j++
} //while
return true
}

function CheckForm(FormName)
{
   if (!AreItemsValid(FormName))
	   return false
   if (FirstTime) {
	FirstTime= false
	FormName.validated.value = true
	FormName.submit()			//submit upload form
   } else
	alert('Information already submitted --- Click Reset before resending.')
}
//  End -->
