//==========================================================================
// validateForm(): Validates the required elements in the form submitted  
//		have all been filled in.  
//
//		Input: none
//		Output: boolean (if false, an alert as well)
//==========================================================================
function validateForm(){
	var i;
	
	if ( !validateRadio(document.contact.retcoach,'Coach Status') ){
		return false;
	}
	else {
		if ( document.contact.retcoach[1].checked == true ) {
			if ( !validateText(document.contact.aim,'AIM Screen Name') ){
				return false;
			}
			else if ( !validateEmail(document.contact.email) ){
				return false;
			}
			/*else if ( !validateRadio(document.contact.prevexp,'Have you played in an organized league') ){
				return false;
			}
			else if ( !validateRadio(document.contact.hispeed,'High-speed internet') ){
				return false;
			}*/
			else if ( !validateText(document.contact.live,'Where do you live') ){
				return false;
			}
			else if ( !validateSelect(document.contact.tzid,'Timezone') ){
				return false;
			}
			else if ( !validateRadio(document.contact.syspref,'System') ){
				return false;
			}
		}
		if ( !validateText(document.contact.un,'Username') ){
			return false;
		}
		else if ( !validateTextLength(document.contact.un,'Username',2) ) {
			return false;
		}
		else if ( !validateText(document.contact.pwd,'Password') ){
			return false;
		}
		else if ( !validateTextLength(document.contact.pwd,'Password',4) ) {
			return false;
		}
		
		/*else if ( !validateRadio(document.contact.gamecount,'Preferred game count') ){
			return false;
		}*/
		
		if(!validateMultSelect(eval(document.contact.slg), 'League Level to join')){
			return false;
		}

		for (i=1; i <= 10; i++){
			if ( !validateSelect(eval('document.contact.team_' + i),'Team choice for #' + i + '. All ten choices must be made.') ) {
				return false;
			}
		}
		
		for (i=1; i <=10; i++) {
			team1 = eval('document.contact.team_' + i);
			for (j=i+1; j<=10; j++) {
				team2 = eval('document.contact.team_' + j);
				if (team1.value == team2.value) {
					notifyInvalid(team2,'You have entered the same team for #' + i + ' and #' + j + '. Please correct this before submitting.');
				}
			}
		}
	}
	/*
	var s = new String(document.contact.email.value);
	s = s.replace(/@/g," [at] ");
	var loc = s.indexOf(' [at] ');
	var ename = s.substring(0, loc+6);
	var ehost = s.substring(s.length, loc+6);
	ehost = ehost.replace(/\./g," [dot] ");
	
	document.contact.email.value = ename + ehost;
	*/
	
	return true;
}


//==========================================================================
// validatePhone(): Validates the phone number element in the form.
//==========================================================================
function validatePhone(objElement) {
	var strString = objElement.value;
	var strFilter  = /^([0-9])+([0-9])+([0-9])+\-([0-9])+([0-9])+([0-9])+\-([0-9])+([0-9])+([0-9])+([0-9])+$/;
	
	if ( strFilter.test(strString) ) {
		return true;
	}
	else {
		notifyInvalid(objElement,'You have entered an invalid phone number.\nPlease use the form ###-###-####');
		return false;
	}
}


//==========================================================================
// submitForm(): Validate the form and submits it if valid.
//==========================================================================
function submitForm() {
		
	if ( validateForm() ) {
		document.contact.submit();
		//return true;
	}
	else { return false; }
}


