// join_as_advertiser.js
function jsValidateFields(){
	try {
		var rc = true;
		var name = '';
		var email = '';
		var pass1 = '';
		var pass2 = '';
		var termsok = 0;
		var words = new Array('');
		var pat = /\s+/;
		var step = 0;
		var x = 0;
		var challenge1='';
		var challenge2='';
		
		// Analyze name field
		if ( rc ) {
			step = 1;
			name = Trim(tcGetVal('name'));
			tcSetVal('name', name);
			if ( rc && name.length < 5 ){
				alert('Please enter your valid full name in (First Last) format.');
				rc = false;
			}
			step = 2;
			pat = /\s+/;
			words = name.split(pat);
			if ( rc && words.length < 2 ) {
				alert('At least your first name and last name are required. Enter your first and last name separated by a space.');
				rc = false;
			}
			
			// Loop through and check all name parts.
			pat = /^[a-zA-Z]+$/;
			for ( x=0; x<words.length; x++){
				if ( rc && ( ! words[x].match(pat)) ) {
					alert('The name entered has invalid characters. Only use letters A thru Z.');
					rc = false;
					break;
				}
			}
		}
		
		// email field
		email = Trim(tcGetVal('email'));
		tcSetVal('email', email);
		if ( rc && ! tcValidateEmail(email)) {
			alert('E-mail address appears invalid. Please correct with valid e-mail address.');
			rc = false;
		}
		
		// passwords
		if ( rc ) {
			pass1 = Trim(tcGetVal('password1'));
			tcSetVal('password1', pass1);
			
			pass2 = Trim(tcGetVal('password2'));
			tcSetVal('password2', pass2);
			
			if ( rc && pass1.length < 6 ) {
				alert('Please enter a password of at least 6 characters long. Characters may be 0-9 A-Z _ - or ! (no commas or spaces allowed)');
				rc = false;
			}
			
			if ( rc ) {
				if ( pass1 != pass2 ) {
					alert('The passwords entered do not match. Please re-type them so they match and try again.');
					rc = false;
				}
			}
			
			if ( rc && ! tcValidatePasswordChars(pass1)) {
				alert('The password should only contain the following characters: 0-9 A-Z _ - or ! (no commas or spaces allowed)');
				rc = false;
			}
		}
		
		// challenge code
		if ( rc ) {
			challenge1 = Trim(tcGetVal('challenge1'));
			tcSetVal('challenge1', challenge1);
			
			challenge2 = Trim(tcGetVal('challenge2'));
			tcSetVal('challenge2', challenge2);
			
			if ( challenge1 != challenge2 ) {
				alert('Please re-enter the challenge code. It does not match the challenge shown. Thank you...');
				rc = false;
			}
		}
		
		// terms accepted
		if ( rc && ! tcIsChecked('termsok')){
			alert('You must check the checkbox to accept the site terms of use and other legal notices to continue.');
			rc = false;
		}
	
		return(rc);
	} catch(e) {
		alert('Error occurred in jadValidateFields(): step=' + step + ', error=' + e.message + '/' + e.name);	
		return(false);
	}
}
