// form validator page
// form elements need to be in a specific format to be able to use this page
// elements need to end in _tf, _ta, _rb, _cb and checkWho, checkMess and checkCondition need to be defined
// checkWho = array of elements to be checked
// checkMess = parallel array of message to display if there is a problem
// checkCondition = parallel array of regular expression you can include if you want to check a certain format, leave blank if not needed
errorCount = 1;
function checkPage(checkWho, checkMess, checkCondition)
 {
 	var form = document.form1;
	var errors = "";
	errorCount = 1;
	for( i = 0; i < checkWho.length; i++) 
	{
		tempType = checkWho[i].split("_");
		whatType = "-1";
		if( tempType.length > 0 )
			whatType = tempType[tempType.length - 1];
		
		notOk = true;
		if( whatType == "lm" )
			notOk = (form[checkWho[i]].selectedIndex == 0);
		else if( whatType == "rb" )
			notOk = checkRB(checkWho[i]);
		else if( whatType == "cb" )
			notOk = checkCB(checkWho[i]);
		else if( whatType == "ta" || whatType == "tf" ) {
			if( checkCondition[i] != "" ) {
				checkMe = new RegExp(checkCondition[i]);
				notOk = (form[checkWho[i]].value.match(checkMe) == null);
			}
			else
				notOk = (form[checkWho[i]].value == "");
		}
		else
			checkMess[i] = "Type not found: " + whatType;
			
		if( notOk ) {
			errors += errorCount + ") " + checkMess[i] + "\n";
			errorCount++;
		}
	}
	
	return errors;
 }
 
 function checkRB(eName)
 {
 	var form = document.form1;
	var okV = false;
	// use this if only one radio button

	if( !form[eName].length )
		okV = form[eName].checked;
	else {
		rb = 0;
		// if it finds one option checked, it stops the loop
		while( rb < form[eName].length && !okV)
		{
			okV = form[eName][rb].checked;
			rb++;
		}
	}
	return !okV;
 }
 
 function checkCB(elName)
 {
	var form = document.form1;
	var allOk = false;
	
	// assumption is nameCB#_cb
	cbGroupName = elName.substring(0, elName.length - 4);
	
	cb = 1;
	// if it finds one option checked, it stops the loop
	//while( form[cbGroupName + cb + "_cb"] && !allOk)
	//{
		allOk = form[cbGroupName + cb + "_cb"].checked;
	//	cb++;
	//}
		
	//return !allOk;	
 }

