// Valid email address format contained in a textfield
function validEmail(theInput, errorText){
	if (theInput.value.indexOf("@", 1)==-1 || theInput.value.indexOf(".", 4)==-1){
		alert(errorText);
		theInput.focus();
		return false;
	}
	return true;
}

// Valid textfield containing at least 'minLength' characters and no more than 'maxLength' characters
// minLength=0: No minimum
// maxLength=0: No maximum
// charMode=0: All chars
// charMode=1: Numbers only
// charMode=2: Letters only
function validText(theInput, errorText, minLength, maxLength, charMode){
	var Valid=true;
	if (theInput.value.length<minLength){
		Valid=false;
	}
	if (maxLength>0 && theInput.value.length>maxLength){
		Valid=false;
	}
	if (Valid && charMode>0){
		var Loop
		for (Loop=0; Loop<theInput.value.length; Loop++){
			if (charMode==1 && (theInput.value[Loop]<'0' || theInput.value[Loop]>'9')){
				Valid=false;
			}
			if (charMode==2 && (theInput.value[Loop]<'A' || theInput.value[Loop]>'Z') && (theInput.value[Loop]<'a' || theInput.value[Loop]>'z')){
				Valid=false;
			}
		}
	}
	if (!Valid){
		alert(errorText);
		theInput.focus();
		return false;
	}
	return true;
}

// Valid select where value is at least 1 character
function validSelect(theInput, errorText){
	if (theInput.options[theInput.selectedIndex].value.length<1){
		alert(errorText);
		theInput.focus();
		return false;
	}
	return true;
}

// Valid radio button(s) where at least one button is selected
function validRadio(theInput, errorText){
	var foundOne=0;
	for (var loop=0; loop<theInput.length; loop++){
		if(theInput[loop].checked){
			foundOne=1;
		}
	}
	if (!foundOne){
		alert(errorText);
		theInput[0].focus();
		return false;
	}
	return true;
}

// Valid checkboxes where at least one button is selected
function validCheck(theForm, theInput, errorText){
	var foundOne=0;
	var foundAt=-1;

	for (i=0; i<theForm.elements.length; i++){
		if (theForm.elements[i].name==theInput){
			if (foundAt==-1){
				foundAt=i;
			}
			if (theForm.elements[i].checked==true){
				foundOne=1;
			}
		}
	}
	if (!foundOne){
		alert(errorText);
		if (foundAt>=0){
			theForm.elements[foundAt].focus();
		}
		return false;
	}
	return true;
}

// Valid only if the 2 fields are equal
function validEqual(theInput, theInput2, errorText){
	if (theInput.value!=theInput2.value){
		alert(errorText);
		theInput.focus();
		return false;
	}
	return true;
}
