/**#############################################################################
#	JavaScrpt File / Anatex IT / Gary Crouch / Universal Haed / Jazz Factory
#	
#	Date: 9/7/2004
#
#	Description: 
#	
#	Form Valiadation Javascript function
#		
#	Contact: gc@anatex.net
#
#############################################################################**/

function AIT_UH_JF_validateThisForm(a,b){
	
	var DOC = document;
	var listOfFields = a.split(",");
	var listOfLabels = b.split(",");
	var listOfErrors = "";
	var emailError = 0;
	
	for (i=0; i < listOfFields.length; i++){
		
		if (DOC.getElementById(listOfFields[i]).value == ""){
			if (listOfErrors == ""){
				listOfErrors = listOfLabels[i];
			}else{
				listOfErrors = listOfErrors + "," + listOfLabels[i];
			}
		}
		if (listOfFields[i] == "email"){
			
			eTest = DOC.getElementById(listOfFields[i]).value;
			
		    if (eTest.indexOf("@") < 1) { //  must contain @, and it must not be the first character
		        emailError = 1;
		    } else if (eTest.lastIndexOf(".") < 1) {  // must contain ., and it must not be the first character
		        emailError = 1;
			} else if (eTest.lastIndexOf(".") <= eTest.indexOf("@")) {  // last dot must be after the @
		        emailError = 1;
		    } else if (eTest.indexOf("@") == eTest.length - 1) {  // @ must not be the last character
		        emailError = 1;
		    } else if (eTest.indexOf(".") == eTest.length - 1) {  // . must not be the last character
		        emailError = 1;
		    }
			
			if (emailError == 1) {
				if (listOfErrors == ""){
					listOfErrors = listOfLabels[i];
				}else{
					listOfErrors = listOfErrors + "," + listOfLabels[i];
				}
			}
		}
	}
	
	txtAlert = "You are required to complete the following fields:-\r\r";
	arrayOfErrors = listOfErrors.split(",");
	
	for (i=0; i < arrayOfErrors.length; i++){
		txtAlert = txtAlert + " - " + arrayOfErrors[i] + "\r";
	}
	
	if (DOC.getElementById('studentType_1') && DOC.getElementById('studentType_2')){
		if ( (!DOC.getElementById('studentType_1').checked & !DOC.getElementById('studentType_2').checked )
			 |
			 (DOC.getElementById('studentType_1').checked & DOC.getElementById('studentType_2').checked ) ){
			
			txtAlert = txtAlert + "\rAlso you are required to choose either:-\r\r - Current Jazz Factory student, or\r - New Student\r";
		}
	}

	if (DOC.getElementById('terms')){
		if ( !DOC.getElementById('terms').checked ){
			
			TCAlert = "\rYou are required to indicate your acceptance of our Terms and Conditions\r";
			txtAlert = txtAlert + TCAlert;
		}
	}
	
	txtAlert = txtAlert + "\rPlease click OK and finish competing the form.";
	
	if (emailError == 1){
		txtAlert = txtAlert + "\r\r NOTE: Email address must be correct.";
	}
	
	if (listOfErrors != ""){
		alert(txtAlert);		
		return false;
	}else if ( !DOC.getElementById('terms').checked ){
		alert(TCAlert);		
		return false;
	}else{
		return true;
	}
}
