window.onload = initForms;function initForms() {//	alert("check form init");	for (var i=0; i< document.forms.length; i++) {		document.forms[i].onsubmit = function() {			return checkNewUser();			}	}}function checkNewUser() {	var allGood = true;	var allTags = document.getElementsByTagName("input");	for (var i=0; i<allTags.length; i++) {		if (!validTag(allTags[i])) {			allGood = false;			}	}	return allGood;		function validTag(thisTag) {	// is inside validForm function to be able to pass information		var outClass = "";		var allClasses = thisTag.className.split(" ");		for (var j=0; j<allClasses.length; j++) {			outClass +=validBasedOnClass(allClasses[j]) + " ";			}				thisTag.className = outClass;				if (outClass.indexOf("invalid") > -1) {	// invalid = error is in that string			thisTag.focus();	// forces to be in focus, puts cursor into field			if (thisTag.nodeName == "INPUT") {				thisTag.select();				}			return false;		}		return true;						function validBasedOnClass(thisClass) {			var classBack = "";				switch(thisClass) {				case "":				case "invalid":					break;				case "reqd":	// this input field is required class					if (allGood && thisTag.value == "") {						classBack = "invalid ";						}					classBack += thisClass;					break;				case "email":					if (allGood && !validEmail(thisTag.value)) {						classBack = "invalid ";	// not valid email address						}					classBack +=thisClass;					break;				default:					classBack += thisClass;			}			return classBack;		}				function validEmail(email) {	// checks whether email addr is valid, does not check for all problems			var invalidChars = " /:,;";						if (email == "") {				return false;				}			for (var k=0; k<invalidChars.length; k++) {				var badChar = invalidChars.charAt(k);				if (email.indexOf(badChar) > -1) {	// if invalid chars are in there return false					return false;					}			}			var atPos = email.indexOf("@",1);	// is @ after the first character?			if (atPos == -1) {				return false;				}			if (email.indexOf("@",atPos+1) != -1) {	// is there more than one @ in there?				return false;				}			var periodPos = email.indexOf(".",atPos);			if (periodPos == -1) {				return false;				}			if (periodPos+3 > email.length) {	// position of . needs to be not at end but at least 2 chars before end				return false;				}			return true;					}	}}