function checkSubmit(form,progBar) {
 submitOK = true;
 emailOK = true;
 dateOK = true; 
 emailMatch = true;
 passMatch = true;
 alertVal = '';
 for(i=0,n=form.elements.length;i<n;i++) {
  addAlert = false;
  if(form.elements[i].name == 'reqFld') {
   theFld = form.elements[i-1];
   fldName = theFld.name;
   theFld.style.background = '#ffffff';
   if(theFld.type.toLowerCase().indexOf('select') > -1) {
    if(theFld.options[theFld.selectedIndex].value == '') {
     theFld.style.background = '#ffff99';
	 submitOK = false;
	 addAlert = true;
	}
   } else if(theFld.name.indexOf('_CHX') > -1) {
    fldName = theFld.name.substring(0,theFld.name.indexOf('_CHX'));
	if(document.getElementById(fldName + '_BOX')) document.getElementById(fldName + '_BOX').style.background = '#ffffff';
	fldBad = true;
	addAlert = true;
	for(j=0,m=form.elements.length;j<m;j++) {
	 if(form.elements[j].name == fldName && form.elements[j].checked) {
	  fldBad = false;
	  addAlert = false;
	 }
	}
	if(fldBad) {
	 if(document.getElementById(fldName + '_BOX')) document.getElementById(fldName + '_BOX').style.background = '#ffff99';
	 submitOK = false;
	 addAlert = true;
	}
   } else if(trim(theFld.value) == '') {
    theFld.style.background = '#ffff99';
	submitOK = false;
	addAlert = true;
   } else if(theFld.name.toUpperCase().indexOf('EMAIL') > -1) {
    email = trim(theFld.value);
	firstAtSign = email.indexOf('@');
	atSignPos = email.lastIndexOf('@');
	periodPos = email.lastIndexOf('.');
	spacePos = email.lastIndexOf(' ');
	if(spacePos > -1 || firstAtSign != atSignPos || atSignPos > periodPos || email.length - periodPos < 3 || periodPos - atSignPos < 2 || atSignPos < 2) {
	 theFld.style.background = '#ffff99';
	 emailOK = false;
    }
   } else if(form.elements[i].value == 'date') {
    if (!validDate(theFld.value)) {
	 theFld.style.background = '#ffff99';
     submitOK = false;
 	 addAlert = true;
	 dateOK = false;
    }
   }
   
   if(form.elements[fldName+'_MSX'] && addAlert) {
    alertVal = alertVal + form.elements[fldName+'_MSX'].value + '\n\n';
   }
  }
 }
 
 if(form.password && form.password2) {
  if(trim(form.password.value) != trim(form.password2.value)) {
   form.password.style.background = '#ffff99';
   form.password2.style.background = '#ffff99';
   passMatch = false;
  }
 }
 
 if(form.email && form.email2) {
  if(trim(form.email.value) != trim(form.email2.value)) {
   form.email.style.background = '#ffff99';
   form.email2.style.background = '#ffff99';
   emailMatch = false;
  }
 }
 
 if(!submitOK || !emailOK || !passMatch || !emailMatch || !dateOK) {
  if(!submitOK) {
   alertVal = alertVal + 'Please complete all required fields';
   if(!emailOK || !passMatch || !dateOK) {
    alertVal = alertVal + '\n\n';
   }
  }
  if(!dateOK) {
   alertVal = alertVal + 'Please make sure all date fields are valid and are in MM-DD-YYYY format';
   if(!passMatch || !emailMatch || !emailOK) {
    alertVal = alertVal + '\n\n';
   }
  }
  if(!emailOK) {
   alertVal = alertVal + 'Please provide a valid email address';
   if(!passMatch || !emailMatch) {
    alertVal = alertVal + '\n\n';
   }
  }
  if(!passMatch) {
   alertVal = alertVal + 'Your password does not match in both fields';
   if(!emailMatch) {
    alertVal = alertVal + '\n\n';
   }
  }
  if(!emailMatch) {
   alertVal = alertVal + 'Your email address does not match in both fields';
  }
 }
 
 if(alertVal != '') {
  alert(alertVal);
 } else {
  if(typeof(progBar)!='undefined' && progBar)ShowProgress();
  form.submit();
 }
}



function submitEnter(myfield,e) {
 var keycode;
 if (window.event) keycode = window.event.keyCode;
 else if (e) keycode = e.which;
 else return true;
 if (keycode == 13) {
  return true;
 } else return false;
}


function addIndexes(theForm) {
 for ( var i=0,n=theForm.elements.length; i<n; i++ )
   theForm.elements[i].index=i;
}

function validDate(dateVal) {
	var result = true;
	var elems = dateVal.split("-");
	result = (elems.length == 3); // should be three components
	if (result)	{
		var month = parseInt(elems[0],10);
		var day = parseInt(elems[1],10);
		var year = parseInt(elems[2],10);
		result = (elems[0].length == 2) && (month > 0) && (month < 13) && (elems[1].length == 2) && (day > 0) && (day < 32) && (elems[2].length == 4) && (year > 1990) && (year < 2045);
	}
	if (result) {
		if(month == 2) {
			result = ((year % 4 == 0 && day < 30) || day < 29);
		} else if (month == 4 || month == 6 || month == 9 || month == 1) {
			result = (day < 31);
		}
	}
	return result;
}
