
function changeClass(num){
	var id = "q"+num;	
	document.getElementById(id).className = "appBadQuestion";
	if(document.getElementById(id+"err") != null){
		document.getElementById(id+"err").style.visibility = "visible";
	}
}

function validateForm()
{	var count = 1;
	var errorCount = 0;
	var foundError = false;

	//validate name
	var test = document.getElementById("name");
	var tmp = "[A-Za-z]{4,}"
	if(test.value.search(tmp)==-1){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate level	
	test = document.getElementById("level");
	tmp = "[1-9]{1,2}"
	if(test.value.search(tmp)==-1){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;

	//validate class
	test = document.getElementById("class");

	if(test.value=="NUL"){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate timezone
	test = document.getElementById("timeZone");
	checks = document["application"].raidTimeCheck;
	if(test.value=="err"){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		var foundCheck = false;
		for(check in checks){
			if(check.checked){
				foundCheck = true;
				break;
			}
		}
		if(!foundCheck){
			if(!foundError)test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate job/school req
	checks = document.getElementsByName("jobCheck");
	test = document.getElementById("jobExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate hi-speed network
	checks = document.getElementsByName("netCheck");
	test = document.getElementById("netExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate sound/speakers
	checks = document.getElementsByName("soundCheck");
	test = document.getElementById("soundExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
		
	// Validate requirements check
	test = document.getElementById("reqCheck");	
	
	if(!test.checked){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//hearAbout count++
	count++
	
	//validate readCheck
	checks = document.getElementsByName("readCheck");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
		
	//validate aaCount
	test = document.getElementById("aaCount");
	
	if(test.value.search("[0-9]+")==-1){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate korafax
	checks = document.getElementsByName("koraCheck");
	test = document.getElementById("koraExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate raidPkg
	test = document.getElementById("raidPkg");
	
	if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate raidChallenge
	test = document.getElementById("raidChallenge");
	
	if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate factionCheck
	test = document.getElementById("factionCheck");	
	
	if(!test.checked){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate killCheck
	test = document.getElementById("killCheck");	
	
	if(!test.checked){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate policy check
	test = document.getElementById("policyCheck");	
	
	if(!test.checked){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} 
	count++;
	
	//validate previous guilds
	test = document.getElementById("prevGuilds");
	
	if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate conflict
	test = document.getElementById("conflict");
	
	if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate mageloid
	test = document.getElementById("conflict");
	
	if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate altChars count++
	count++;
	
	//validate nameChange
	checks = document.getElementsByName("nameCheck");
	test = document.getElementById("maneExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate originalOwner
	checks = document.getElementsByName("charCheck");
	test = document.getElementById("charExplainTxt");
	
	var foundCheck = false;
	for(check in checks){
		if(check.checked){
			foundCheck = true;
			break;
		}
	}
	if(!foundCheck){
		if(!foundError)test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	} else {
		if(test.value.search("[A-Za-z0-9]{5,}"==-1)){
			if(!foundError) test.focus();
			changeClass(count);
			foundError = true;
			errorCount++;
		}
	}
	count++;
	
	//validate descFriends
	test = document.getElementById("descFriends");
	
	if(test.value.search("[A-Za-z0-9]{2,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate whyJoin
	test = document.getElementById("whyJoin");
	
	if(test.value.search("[A-Za-z0-9]{25,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate toot
	test = document.getElementById("toot");
	
	if(test.value.search("[A-Za-z0-9]{25,}"==-1)){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate humor
	count++;
	
	//validate email
	test = document.getElementById("email");

	if(test.value.search("[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}")==-1){
		if(!foundError) test.focus();
		changeClass(count);
		foundError = true;
		errorCount++;
	}
	count++;
	
	//validate IM's
	count++;
	
	if(errorCount > 0){
		alert("There are "+errorCount+" errors in the application, please check the entries marked in red.");
	}else{
		document.getElementById("application").submit();
	}
}