/*
<!-
!! COPYRIGHT (c) 2000 BY
!! NetAmaze, LLC, New York, NY
!! ALL RIGHTS RESERVED.
!!
!! This software is furnished under a license and may be used and copied
!! only  in  accordance  of  the  terms  of  such  license  and with the
!! inclusion of the above copyright notice. This software or  any  other
!! copies thereof may not be provided or otherwise made available to any
!! other person.  No title to and  ownership of the  software is  hereby
!! transferred.
!!
!! The information in this software is  subject to change without notice
!! and  should  not  be  construed  as a commitment by NetAmaze.
!!
!! NetAmaze assumes no responsibility for the use or reliability of its
!! software on systems or syetem configurations not done by NetAmaze.
!!
-->
*/
function formValidation(value_array, type_array, desc_array, object_array, array_size) {
	var i;
	var return_val;

	for (i=0; i<array_size ;i++ )
	{
		if (type_array[i] == "email")
		{
			return_val = testEmailAddress(value_array[i]);
			if (return_val == false)// || testEmptySpace(value_array[i]) == false)
			{
				alert("Please enter a valid e-mail address");
				object_array[i].focus();
				return false;
			}
		}
		else if (type_array[i] == "text")
		{
			return_val = testTextArea(value_array[i]);
			if (return_val == false)//  || testEmptySpace(value_array[i]) == false)
			{
				alert("Please enter a valid field for " + desc_array[i]);
				object_array[i].focus();
				return false;
			}
		}
		else if (type_array[i] == "class")
		{
			return_val = testClassNumber(value_array[i]);
			if (return_val == false)//  || testEmptySpace(value_array[i]) == false)
			{
				alert("Please enter a valid class number for " + desc_array[i] + " must be in the form of : 15127");
				object_array[i].focus();
				return false;
			}
		}
	}
	return true;
}

function testEmptySpace(astring) {
	var size = astring.length;
	var num_empty_spaces = 0;

	for (i=0; i<size ; i++)
	{
		if (astring.charAt(i) == ' ')
			num_empty_spaces++;	
	}

	if (num_empty_spaces == size)
		return false;
	
	return true;
}

function testTextArea(name) {
	if (name == "" || testEmptySpace(name) == false)
		return false;
	
	return true;
}


function testEmailAddress(email) {
	if (email.indexOf("@",0) == -1 || testEmptySpace(email) == false) {
		return false;
	}
	return true;
}

function testClassNumber(classname) {
	if (isNaN(classname) || classname=="" || testEmptySpace(classname) == false) {
		return false;
 	}
	return true;
}

function testRadio(radioObj) {
	var found = false;
	for (i=0; i<radioObj.length; i++) {
		if (radioObj[i].checked == "1") {
			found = true;
		}
	}
	if (found == false) {
		alert("Must select an option");
		return false;
	}
	return true;
}

function testCheckBoxes(formObj) {
	var found = false;
	for (i=0; i<formObj.length ;i++ ) {
		if (formObj[i].checked == "1") {
			found = true;
		}
	}
	if (found == false)
	{
		alert("Must select an option");
		return false;
	}
	return true;
}