// JavaScript Document
<!---------------------------------------------------------------------------------->
// BRTRC Technology Marketing Group for DoD BIOMETRICS MANAGEMENT OFFICE
// Mina Haeri -- mhaeri@brtrc.com

<!------ IMAGE SWAP AND PRELOAD JS  ----------------------------------->
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

<!---------------------------------------------------------------------------------->
<!------ THIS IS TO VALIDATE IF A FIELD IS BLANK ----------------------------------->
function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}
<!---------------------------------------------------------------------------------->
<!------ THIS IS TO VALIDATE MENU ITEM HAS NOT BEEN SELECTED (DEFAULT VALUE = "---" >
function validSelectItem(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "---")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}
<!---------------------------------------------------------------------------------->
function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}
<!---------------------------------------------------------------------------------->
function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
<!---------------------------------------------------------------------------------->
<!------ THIS IS TO VALIDATE THE EMAIL ADDRESS  ------------------------------------>
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
<!---------------------------------------------------------------------------------->
<!------ THIS IS TO VALIDATE IF AN VALID EMAIL ADDRESS IS ENTERED ------------------>
function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}
<!---------------------------------------------------------------------------------->
<!---------------------------------------------------------------------------------->
<!---------------------------------------------------------------------------------->
/***************************************************************************/
<!------- THIS IS TO SET ALL THE FIELDS IN THE FORM TO THE CORRECT FUNCTIONS ------->
<!---------------------------------------------------------------------------------->
<!---------------------------------------------------------------------------------->
function CheckRadioButtons() {
var errormessage = new String();
// Put field checks below this point.
if(NoneWithCheck(document.subscribe.cBox_Newsletter))
	{ errormessage += "\nPlease Check the Checkbox to confirm you would like to begin receiving the bimonthly email newsletter."; }
// Put field checks above this point.
if(errormessage.length > 2) {
	alert(errormessage);
	return false;
	}
return true;
} // end of function CheckRequiredFields()
function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].checked) { return false; }
	}
return true;
}
<!---------------------------------------------------------------------------------->
<!---------------------------------------------------------------------------------->
<!---------------------------------------------------------------------------------->
// ColdFusion JavaScript function error messages ----------------------------------->
function _CF_onError(form_object, input_object, object_value, error_message)
{
	alert(error_message);
	return false;	
}

<!---------------------------------------------------------------------------------->
function validateBlank(formObj) {
	var objName = formatName(formObj);
	if (formObj.value == "") {
		if (fv['groupError']) { addError(formObj); return true; }
		alert((formObj.getAttribute(fv['emsg'])) ? formObj.getAttribute(fv['emsg']) : 'Please enter the '+objName);		
		errorProcess(formObj,0,1);
		return false;
		}
	var regex = new RegExp(/\S/);
	if (!regex.test(formObj.value)) {
		if (fv['groupError']) { addError(formObj); return true; }
		alert((formObj.getAttribute(fv['emsg'])) ? formObj.getAttribute(fv['emsg']) : 'Please enter the '+objName);
		errorProcess(formObj,1,1);
		return false;			
		}
	return true;
	}
	
<!---------------------------------------------------------------------------------->
// for valid email address - not being used right now ------------------------------>
function validateEmail(formObj)	{	
	if (fv['bok'] && checkBlank(formObj))
		{ fv['bok']=false; return true; }

	var emailStr = formObj.value;
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/; // valid
	if (!emailReg1.test(emailStr) && emailReg2.test(emailStr)) {// if syntax is valid
		return true;
		}
	else {
		if (fv['groupError']) { addError(formObj); return true; }
		alert((formObj.getAttribute(fv['emsg'])) ? formObj.getAttribute(fv['emsg']) : "Please enter a valid Email address.");
		errorProcess(formObj,1,1);
		return false;
		}
	return true;
	}
/***************************************************************************/
function checkme() {
missinginfo = "";
if (!document.aac_app.questionA.checked) {
missinginfo += "\n   You must agree to item 1";
} 
if (missinginfo != "") {
missinginfo ="                                    \n" +
"Required information is missing: \n" +
missinginfo + "\n                                 " +
"\nPlease complete and resubmit.";
alert(missinginfo);
return false;
}
else { 
return true;
}
}
/***************************************************************************/
<!---------------------------------------------------------------------------------->
<!------- THIS IS TO SET ALL THE FIELDS IN THE FORM TO THE CORRECT FUNCTIONS ------->
function validateSubForm(theForm){
	// <--------- Start
	if (!validRequired(subscribe.txt_Fname,"First Name",false))
		return false;		
		
	if (!validRequired(subscribe.txt_Lname,"Last Name",false))
		return false;
		
	if (!validRequired(subscribe.txt_Organization,"Organization",false))
		return false;
		
	if (!validRequired(subscribe.txt_Email,"Email",false))
		return false;

	if (!checkme(subscribe.cBox_Newsletter,"Check Box",false))
		return false;		


	// <--------- End
	
	return true;
}
<!---------------------------------------------------------------------------------->

