// JavaScript Document
<!--

function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
	{
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function trim(sInString) {
	sInString = sInString.replace( /^\s+/g, "" );// strip leading
	return sInString.replace( /\s+$/g, "" );// strip trailing
}

function checkTeams()
{
	var numStudents;
	
	current = document.registration
	
	if(current.numberTeams.value > 0)
	{
		numStudents = current.numberTeams.value * 4;
		
		if(current.numberStudents.value < numStudents)
		{
			alert('Number of students attending has to be at least ' + numStudents + ' for the corresponding selected number of teams. Please try again.');
			return false;
		}
		
	}
	
	if(trim(current.teamName1.value) != '')
	{
		if(current.numberTeams.value < 1)
		{
			alert('Please select correct number of teams.');	
			return false;
		}
		
		if(trim(current.teamName2.value) != '')
		{
			if(current.numberTeams.value < 2)
			{
				alert('Please select correct number of teams.');	
				return false;
			}
		}
	}
	
	if((trim(current.t1n1First.value) != '' || trim(current.t1n1Last.value) != '' ||
		trim(current.t1n2First.value) != '' || trim(current.t1n2Last.value) != '' ||	
		trim(current.t1n3First.value) != '' || trim(current.t1n3Last.value) != '' ||
		trim(current.t1n4First.value) != '' || trim(current.t1n4Last.value) != '') && (trim(current.teamName1.value) == ''))
	{
		alert('Please enter a team 1 name.');
		return false;
	}
	
	if((trim(current.t2n1First.value) != '' || trim(current.t2n1Last.value) != '' ||
		trim(current.t2n2First.value) != '' || trim(current.t2n2Last.value) != '' ||	
		trim(current.t2n3First.value) != '' || trim(current.t2n3Last.value) != '' ||
		trim(current.t2n4First.value) != '' || trim(current.t2n4Last.value) != '') && (trim(current.teamName2.value) == ''))
	{
		alert('Please enter a team 2 name.');
		return false;
	}

	return true;
}


function checkValidity(frm) /*A function used to check that all the required fields are entered*/
{
	/*current = document.registration*/
	
	if(!frm.schoolName.value || !frm.city.value || !frm.postCode.value || !frm.firstContact.value || !frm.lastContact.value || !frm.email.value || !frm.street.value || !frm.workPhone.value)
	
	{
		alert("Please fill in all the required fields!")
	
		return false
	
	}
	
	return true
}

function validate_char(field) /*A function called, used to validate that the right characters are entered in the field*/
{
	
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',. "
	
	var ok = "yes";
	
	var temp;
	
	for (var i=0; i<field.value.length; i++)
	
	{
	
		temp = "" + field.value.substring(i, i+1);
		
		if (valid.indexOf(temp) == "-1") ok = "no";
		
		}
		
		if (ok == "no")
		
		{
			alert("Only letters are accepted!\nPlease modify your entry.");
			
			field.focus();
			
			field.select();
		}

}



function validate_num(field) /*A function called, used to validate that only numerical characters are entered in the field*/
{
	var valid = "0123456789+()- "
	
	var ok = "yes";
	
	var temp;
	
	for (var i=0; i<field.value.length; i++)
	
	{
	
		temp = "" + field.value.substring(i, i+1);
		
		if (valid.indexOf(temp) == "-1") ok = "no";
		
	}
		
	if (ok == "no")
	{
	
		alert("Only numeric characters are accepted!\nPlease modify your entry.");
		
		field.focus();
		
		field.select();

	}
}

function checkTeam1() /*A function which checks that the MIT Team Name 1 field has been filled in*/
{
	current = document.registration
	
	if(!current.teamName1.value)
	
	{
	
		alert("You must enter in a name for Team 1")
	
		return false
	
	}

}

function updateParent(newURL)
{
	opener.document.location = newURL;
	window.close();
}

function checkTeam2() /*A function which checks that the MIT Team Name 2 field has been filled in*/
{
	current = document.registration
	
	if(!current.teamName2.value)
	{
	
		alert("You must enter in a name for Team 2")
	
		return false
	}
}



function validate_alphanum(field) /*A function which checks that only certain characters are entered in the field*/
{
	var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',./\# "
	
	var ok = "yes";
	
	var temp;
	
	for (var i=0; i<field.value.length; i++)
	{
	
		temp = "" + field.value.substring(i, i+1);
		
		if (valid.indexOf(temp) == "-1") ok = "no";
		
		}
		
		if (ok == "no")
		{
		
		alert("Only alpha-numeric characters are accepted!\nPlease modify your entry.");
		
		field.focus();
		
		field.select();
	
		}

}

function newWindow(page)
{
	pageWindow = window.open(page, "pageWin", "width=830,height=700,scrollbars=yes,resizable=yes,toolbar=yes,location=yes");
}
	
//-->
