<!--
function Display() {
/*
	This function determines which section of the form is made availiable to the user based on
	their choice of gender and status.
	
	The system uses the inherent numbering of the forms elements by JavaScript, which is
	array-based.
*/
	var i;
	reset_form();	//Reset form to choose logic based on new selection
	
	if ( document.forms[ "Regis" ].Gender.selectedIndex != 0 ) {
		
		switch( document.forms[ "Regis" ].Status.selectedIndex ) {
			case 0:
				break;
			
			// For current students and alumni
			case 1 :
			case 2 :
				for ( i = 2; i < document.forms[ "Regis" ].length; i++ )
					document.forms[ "Regis" ].elements[ i ].disabled = false;
					
				break;
			
			// For faculty/staff
			case 3 :
				for ( i = 2; i < 22; i++ )
					document.forms[ "Regis" ].elements[ i ].disabled = false;
				
				for ( i = 29; i < document.forms[ "Regis" ].length; i++ )
					document.forms[ "Regis" ].elements[ i ].disabled = false;
				
				document.forms[ "Regis" ].elements[ "House" ].disabled = false;
				
				break;
			
			// For non-Compronians
			case 4 :
				document.forms[ "Regis" ].Email.disabled = false;
				
				for ( i = 10; i < 13; i++ )
					document.forms[ "Regis" ].elements[ i ].disabled = false;
				
				for ( i = 31; i < document.forms[ "Regis" ].length; i++ )
					document.forms[ "Regis" ].elements[ i ].disabled = false;
				
				document.forms[ "Regis" ].elements[ "LastName" ].disabled = false;
				document.forms[ "Regis" ].elements[ "FirstName" ].disabled = false;
				document.forms[ "Regis" ].elements[ "country" ].disabled = false;
				
				break;
		}
		
		if ( document.forms[ "Regis" ].Gender.selectedIndex != 2 )
			document.forms[ "Regis" ].MaidenName.disabled = true;
	}	
}

function Countries() {
	if ( document.forms[ "Regis" ].country.selectedIndex != 0 ) {
		switch ( document.forms[ "Regis" ].country.value ) {
			case "Nigeria":
				document.getElementById( "Nigeria" ).className = "black8";
				document.getElementById( "UnitedStates" ).className = "Invis";
				document.getElementById( "OtherCountry" ).className = "Invis";
				break;
			
			case "United States":
				document.getElementById( "Nigeria" ).className = "Invis";
				document.getElementById( "UnitedStates" ).className = "black8";
				document.getElementById( "OtherCountry" ).className = "Invis";				
				break;
			
			default:
				document.getElementById( "Nigeria" ).className = "Invis";
				document.getElementById( "UnitedStates" ).className = "Invis";
				document.getElementById( "OtherCountry" ).className = "black8";	
		}
	}
	else {
		document.getElementById( "Nigeria" ).className = "Invis";
		document.getElementById( "UnitedStates" ).className = "Invis";
		document.getElementById( "OtherCountry" ).className = "Invis";
	}
}

function window_onload() {
	//for ( i = 2; i < document.forms[ "Regis" ].length; i++ )
	//			document.forms[ "Regis" ].elements[ i ].disabled = true;
	
	//To release the form for those who need to correct something
	Display();
}

function reset_form() {
	for ( i = 2; i < document.forms[ "Regis" ].length; i++ )
				document.forms[ "Regis" ].elements[ i ].disabled = true;
	
	//To release the form for those who need to correct something
	//Display();
}

/*
function isURL( x ) {
	return REFindNoCase("^(((https?:|ftp:|gopher:)\/\/))[-[:alnum:]\?%,\.\/&##!@:=\+~_]+[A-Za-z0-9\/]$",x) NEQ 0;
}
*/

//Start

// REGULAR EXPRESSION DECLARATIONS
// Notes which apply to all the regexps below:
// (1) We want to only match strings exactly. In other words,
//     we only want to return true if the string being tested
//     matches the regular expression with no leading or trailing
//     unmatched characters. So, we begin each regexp with
//     the special character ^ (which matches beginning of input)
//     and end each regexp with the special character $ (which
//     matches end of input).
// (2) In the below comments we use these abbreviations:
//     BOI = Beginning Of Input
//     EOI = End Of Input
// (3) For explanations of the regexp special characters such as
//     ^ $ \s + [] \d * ! ? \ .
//     see http://developer.netscape.com/docs/manuals/communicator/jsguide/regexp.htm


// BOI, followed by one or more whitespace characters, followed by EOI.
var reWhitespace = /^\s+$/


// BOI, followed by one lower or uppercase English letter, followed by EOI.
var reLetter = /^[a-zA-Z]$/

// BOI, followed by one or more lower or uppercase English letters, 
// followed by EOI.
var reAlphabetic = /^[a-zA-Z]+$/


// BOI, followed by one or more lower or uppercase English letters
// or digits, followed by EOI.
var reAlphanumeric = /^[a-zA-Z0-9]+$/


// BOI, followed by one digit, followed by EOI.
var reDigit = /^\d/

// BOI, followed by one lower or uppercase English letter
// or digit, followed by EOI.
var reLetterOrDigit = /^([a-zA-Z]|\d)$/


// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/


// BOI, followed by an optional + or -, followed by one or more digits, 
// followed by EOI.
//var reSignedInteger = /^(+|-)?\d+$/


// BOI, followed by one of these two patterns:
// (a) one or more digits, followed by ., followed by zero or more digits
// (b) zero or more digits, followed by ., followed by one or more digits
// ... followed by EOI.
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

// BOI, followed by an optional + or -, followed by one of these two patterns:
// (a) one or more digits, followed by ., followed by zero or more digits
// (b) zero or more digits, followed by ., followed by one or more digits
// ... followed by EOI.
//var reSignedFloat = /^(((+|-)?\d+(\.\d*)?)|((+|-)?(\d*\.)?\d+))$/

// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by ., 
// followed by one or more characters, followed by EOI.
var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

//Illegal characters for email
var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/

// VARIABLE DECLARATIONS

var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// whitespace characters as defined by this sample code
var whitespace = " \t\n\r";

//End

function Regis_onsubmit() {

	switch ( document.forms[ "Regis" ].Status.value ) {
			case "Alumni":
			case "Current Student":
				var Required = new Array( "Gender", "Status", "LastName", "FirstName", "Email", "Username", "Password", "Password_2", "country", "YearofGraduation", "JSS", "SSS", "House", "Prefect", "Career" );
				var RequiredDescription = Array("your Gender", "your Current Status", "your Last Name/Surname", "your First Name", "your Email", "your User Name", "your Password", "confirm your Password", "your country of residence", "your year of Graduation", "your JSS Arm", "your SSS Arm", "your House", "whether you were a Prefect", "your Present Career Field" );
				break;
			
			case "Faculty/Staff":
				var Required = new Array( "Gender", "Status", "LastName", "FirstName", "Email", "Username", "Password", "Password_2", "country", "House", "Career" );
				var RequiredDescription = Array("your Gender", "your Current Status", "your Last Name/Surname", "your First Name", "your Email", "your User Name", "your Password", "confirm your Password", "your country of residence", "your House", "your Present Career Field" );
				break;
			
			case "Non-Compronian":
				var Required = new Array( "Gender", "Status", "LastName", "FirstName", "Email", "Username", "Password", "Password_2", "country" );
				var RequiredDescription = Array("your Gender", "your Current Status", "your Last Name/Surname", "your First Name", "your Email", "your User Name", "your Password", "confirm your Password", "your country of residence" );
		}
		
	for ( i_1 = 0; i_1 < Required.length ; i_1++ ) {
		//if ( Required[ i_1 ] == 9 || Required[ i_1 ] == 18 )
		//	document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value = document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value.replace( " ", "_");
			
		if ( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value == "" ) {
			alert("You need to indicate " + RequiredDescription[ i_1 ] + "!");
			document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
			return false;
		}
	}
	
	for ( i_1 = 0; i_1 < Required.length ; i_1++ ) {
		
		switch ( Required[ i_1 ] ) {
			case "LastName":
			case "FirstName":
				if ( !reAlphanumeric.test( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value ) ) {
					alert( "Only English alphanumeric characters are allowed for " + RequiredDescription[ i_1 ] + " field!\nSpaces, tabs, commas, etc are not allowed." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}					 
				break;
			
			case "Email":
				//check email format
				if ( !reEmail.test( Trim( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value ) ) ) {
					alert( "Your email address is not valid!\n\nYour email need not only be valid but functional to use this site.\nA confirmatory email will be sent to the email address used in this form." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}
				
				//disallow illegal characters					
				if ( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value.match( illegalChars ) ) {
					alert( "The email address contains illegal characters." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}					 
				break;
				
			case "Username":
				var strng = document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value;
				
				var illegalCharsU = /\W/; // allow letters, numbers, and underscores
				if ( ( strng.length < 4 ) || ( strng.length > 20 ) ) {
					alert( "Username length inappropriate!\nMust be between 4 and 20 characters." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}
				
				if ( illegalCharsU.test( strng ) ) {
					alert( "The username contains illegal characters.\n" );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;				
				}
				break;
			
			case "Password":
				var illegalCharsP = /[\W_]/; // allow only letters and numbers
				var strng = document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value;
    
				if ( ( strng.length < 4 ) || ( strng.length > 20 ) ) {
				   alert( "The password is the wrong length.\nIt must be 4-20 characters long." );
				   document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
				   return false;
				}
				
				if ( illegalCharsP.test( strng ) ) {
				  alert( "The password contains illegal characters.\n" );
				  document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
				  return false;
				}
				
				if ( strng != document.forms[ "Regis" ].elements[ "Password_2" ].value ) {
					alert( "Your passwords do not match!\nTry again." );
					document.forms[ "Regis" ].elements[ "Password_2" ].focus();
					return false;
				}								
				break;			
			
			case "country":
				if ( document.forms[ "Regis" ].elements[ "Status" ].value != "Non-Compronian" ) {
					var strng = document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value;
				
					switch ( strng ) {
						case "Nigeria":
							if ( document.forms[ "Regis" ].elements[ "Nig_City" ].value == "" ) {
								alert( "Indicate the Local Goverment Area you know live in for the city.\n\nFor example, if you live in Surulere of Lagos State, you should enter \"Surulere\"" );
								document.forms[ "Regis" ].elements[ "Nig_City" ].focus();
								return false;
							}
							
							if ( document.forms[ "Regis" ].elements[ "Nig_State" ].value == "" ) {
								alert( "Indicate the state you now live in.\n\nPlease note that this is not necessarily the same as your state of orgin.\nYour parents might hail from Kano but you now live in Cross Rivers.  In that case, you should select \"Cross Rivers\"" );
								document.forms[ "Regis" ].elements[ "Nig_State" ].focus();
								return false;
							}
							break;
						
						case "United States":
							if ( document.forms[ "Regis" ].elements[ "US_City" ].value == "" ) {
								alert( "Indicate city you now live in!" );
								document.forms[ "Regis" ].elements[ "US_City" ].focus();
								return false;
							}
							
							if ( document.forms[ "Regis" ].elements[ "US_State" ].value == "" ) {
								alert( "Indicate the state you now live in!" );
								document.forms[ "Regis" ].elements[ "US_State" ].focus();
								return false;
							}
							break;
						
						default:
							if ( document.forms[ "Regis" ].elements[ "Other_City" ].value == "" ) {
								alert( "Indicate city you now live in!" );
								document.forms[ "Regis" ].elements[ "Other_City" ].focus();
								return false;
							}
							
							if ( document.forms[ "Regis" ].elements[ "Other_State" ].value == "" ) {
								alert( "Indicate the state you now live in!" );
								document.forms[ "Regis" ].elements[ "Other_State" ].focus();
								return false;
							}
							break;
					}
				}	
				break;
			
			case "YearofGraduation":
				if ( !reInteger.test( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value ) ) {
					alert( "Only digits in " + RequiredDescription[ i_1 ] + " field!\nSpaces, tabs, commas, etc are not acceptable." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}
				
				if ( document.forms[ "Regis" ].elements[ Required[ i_1 ] ].value < 1963 ) {
					alert( "Your graduation date is impossible!\nTry again." );
					document.forms[ "Regis" ].elements[ Required[ i_1 ] ].focus();
					return false;
				}					 
				break;
			
			case "Prefect":
				if ( document.forms[ "Regis" ].elements[ "Prefect" ].value != "No" ) {
				
					if ( document.forms[ "Regis" ].elements[ "OfficeTitle" ].value == "" ) {
						alert( "Indicate your official title!" );
						document.forms[ "Regis" ].elements[ "OfficeTitle" ].focus();
						return false;
					}
				}	
				break;
		}
	}
	
	//alert( "I'm in!" );
	
	if ( document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex != 0 && document.forms[ "Regis" ].elements[ "birthDay" ].selectedIndex == 0 ) {
		alert( "Your birth day can't be left blank.  Please make a selection!" );
		document.forms[ "Regis" ].elements[ "birthDay" ].focus();
		return false;
	}
				
	if ( document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 0 && document.forms[ "Regis" ].elements[ "birthDay" ].selectedIndex != 0 ) {
		alert( "Your birth month can't be left blank.  Please make a selection!" );
		document.forms[ "Regis" ].elements[ "birthMonth" ].focus();
		return false;
	}
	
	if ( document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex != 0 && document.forms[ "Regis" ].elements[ "birthDay" ].selectedIndex != 0 ) {
		if ( document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 2 && document.forms[ "Regis" ].elements[ "birthDay" ].selectedIndex > 29 ) {
			alert( "There are only 29 days in Feb.  Please make another selection!" );
			document.forms[ "Regis" ].elements[ "birthDay" ].focus();
			return false;
		}
		if ( document.forms[ "Regis" ].elements[ "birthDay" ].selectedIndex > 30 &&
				(
					document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 9 ||
					document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 4 ||
					document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 6 ||
					document.forms[ "Regis" ].elements[ "birthMonth" ].selectedIndex == 11
				)
			)
				{
					alert( "There are only 30 days in your birth-month  Please make another selection!" );
					document.forms[ "Regis" ].elements[ "birthDay" ].focus();
					return false;
		}
	}
/*	
	if ( Trim( document.forms[ "Regis" ].elements[ "Website" ].value != "" ) ) {
		if ( !isURL( Trim( document.forms[ "Regis" ].elements[ "Website" ].value != "" ) ) {
			alert( "Your web address doesn't seem valid!" );
			document.forms[ "Regis" ].elements[ "Website" ].focus();
			return false;
		}
	}
*/
		
	return true;
}
