//-----------------------------------------------------------------------------------
//    MODULE : Null field Validation JavaScript Code
//  FILENAME : formValidate.js
//      PATH : /
//   VERSION : 1.0
//    AUTHOR : Carrie Bernard -- Technical Software Services, Inc.
//   PURPOSE : This module contains scripts which will be used to validate form fields for empty values.
//   CREATED : January 18, 2000
//   Last mod: October 19, 2001 cmbernard
//-----------------------------------------------------------------------------------



function checkForm(theForm) {
	
	var x;
	var element, returnValue;
	for (x=0; x < theForm.elements.length; x++) {
	     
		element = theForm.elements[x];
		switch (element.name) {
		

		  case "email"		: returnValue = checkNull(element);
                                          if (returnValue == false){
                                            return(false);
                                          }
                                          break;
                }		
	}
        return(true);
}

//-----------------------------------------------------------------------------------		
function checkNull(field) {

	if (field.value == "") {
		msg = "No data was entered for the " + field.name + " field.";
		alert(msg);
                field.focus();
                field.select();
		return (false);
	}	
	else return (true);
}		
//------------------------------------------------------------------------------------	

//------------------------------------------------------------------------------------		
function validateChar(OKChars, field) {
	
	for (x=0; x < field.value.length; x++) {
		ch = field.value.charAt(x);
		for (y=0; y < OKChars.length; y++) {	
			if (ch == OKChars.charAt(y)) 
				break;
			if (y == OKChars.length - 1) {
				return (false);
			}	
		}		
	}
	return (true);
}		
//-------------------------------------------------------------------------------------		


function checkEmail(field) {
	
	// Validate all characters in the email field
	//--------------------------------------------------
	
	OKChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.-";
	returnValue = validateChar(OKChars, field);
	if (returnValue == false) {
		msg = "Email address contains invalid characters";	
		alert(msg);
		return (false);
	}
	
	// Check for a '@' and a '.' in the email field 
	//--------------------------------------------------
	
	for (x=0; x < field.value.length; x++) {
		if (field.value.charAt(x) == '@') {
			for (y=x+1; y < field.value.length; y++)			
				if (field.value.charAt(y) == '.')
					return (true);
		}
	}	
	msg = "Email address needs to be in the form:  yourname@anywhere.com";
	alert(msg);
	field.focus();
	field.select();
	return (false);

}

//------------------------------------------------------------------------------------