// JavaScript Document

function validateForm(f) {
var i,j;
var numE=f.elements.length;
var oldR='',oldVal='',oldAlt='';
var blankMsg="The following survey questions have been left blank:\n";
var errorMsg="The following numeric fields have non-numeric values:\n";
var foundBError=false,foundNError=false;
var errofFld='';

for (i=0; i<numE; i++) {
	thisE=f.elements[i].name;
	thisT=f.elements[i].type;
	thisCls=f.elements[i].className;
	thisAlt=f.elements[i].alt;
	thisVal='';
	//alert('checking element '+i+': name='+thisE+' type='+thisT+' thisAlt='+thisAlt);

	switch (thisT) {
		case 'text':
		case 'textarea':
		case 'password':
			thisVal=f.elements[i].value;
			break;
		case 'hidden':
		case 'submit':
			thisVal=f.elements[i].value;
			if (thisVal == '') thisVal='.';
			break;
		case 'radio':
			elemR=f.elements[i];
			if (elemR.checked) thisVal=elemR.value;
			break;
	/*	case 'select-one':
			elemS=f.elements[i];
			selS=elemS.selectedIndex;
			if (selS>=0)
				thisVal=elemS.options[selS].value;
			}
			break;
		case 'select-multiple':
			elemS=f.elements[i];
			numS=elemS.length;
			for (j=0;j<numS;j++)
				v=elemS.options[j];
				if (v.selected)	thisVal=(thisval=='' ? v.value : ','+v.value);
			}
			break;	*/
	}
	//alert('1. oldR='+oldR+'; thisE='+thisE+'; oldVal='+oldVal+'; thisVal='+thisVal);
	if (thisE.search(/_[0-9]{1,4}_/) != -1) {
		m = 1;
	} else {
		if ((oldR != thisE) && (oldR != '') && (thisCls != 'noReq')) { 			// was radio left blank?
			if (oldVal == '') {
				blankMsg += "\t"+oldAlt+"\n";
				if (!foundBError) errorFld=thisE;		//first error found
				foundBError = true;
			}
			oldR=''; oldVal='';
		}
		if ((thisT !='radio') && (thisVal == '') && (thisCls != 'noReq')) {		// anything else left blank?
			blankMsg += "\t"+thisAlt+"\n";
				if (!foundBError) errorFld=thisE;		//first error found
			foundBError = true;
		}
	}
	if (thisT =='radio') {
		oldR=thisE; oldAlt=thisAlt;
		oldVal=(oldVal=='' ? thisVal : oldVal);
	}
	//alert('2. oldR='+oldR+'; thisE='+thisE+'; oldVal='+oldVal+'; thisVal='+thisVal);


}
//alert('3. oldR='+oldR+'; thisE='+thisE+'; oldVal='+oldVal+'; thisVal='+thisVal);
if (thisE.search(/_[0-9]{1,4}_/) != -1) {
	m = 1;
} else {
		if ((oldR != thisE) && (oldR != '')) { 			// last radio left blank?
			if (oldVal == '') {
				blankMsg += "\t"+oldAlt+"\n";
				if (!foundBError) errorFld=thisE;		//first error found
				foundBError = true;
			}
	}
}
	if (foundBError) {
	alert(blankMsg+'Please Go back and fill in these questions and then resubmit the survey.');
	elem=eval('f.'+errorFld);
	return false;
}
return true;
	
}

