


function isNewsEmail() {

	if (isEmail(document.frmNewsletter.Email.value) == false) {
	        alert("Please enter a valid email address.");
	        document.frmNewsletter.Email.focus();
	        return false;
	}

}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function frmMeetEntrySearch_onsubmit() {	
	
if (document.frmMeetEntrySearch.lbMeet.selectedIndex<1 && 
    document.frmMeetEntrySearch.lbCoach.selectedIndex<1 &&
    document.frmMeetEntrySearch.Swimmer.value=="" &&
	document.frmMeetEntrySearch.ussn.value=="" )
	{	
		alert('Please Enter at least 1 Search Criteria');
		document.frmMeetEntrySearch.lbMeet.focus();
		return false;
	}	

if (BadChar(document.frmMeetEntrySearch.Swimmer.value) != "") { 	
	alert('Swimmer Name Invalid Characters: '+BadChar(document.frmMeetEntrySearch.Swimmer.value));
		document.frmMeetEntrySearch.Swimmer.focus();
		return false;
	}
	
if (BadChar(document.frmMeetEntrySearch.ussn.value) != "") { 	
	alert('USSN Invalid Characters: '+ BadChar(document.frmMeetEntrySearch.ussn.value));
		document.frmMeetEntrySearch.ussn.focus();
		return false;
	}

	
}




function frmEntry_onsubmit() {	
	var iLoop=0;
	

	if (document.frmMeetEntry.lbMeet.selectedIndex<1)
	{	
		alert('Please Select Meet');
		document.frmMeetEntry.lbMeet.focus();
		return false;
	}


	if (document.frmMeetEntry.lbCoach.selectedIndex<1)
	{	
		alert('Please Select Coach');
		document.frmMeetEntry.lbCoach.focus();
		return false;
	}
	if (validate('Swimmer Name',document.frmMeetEntry.Swimmer) != true) { 	
		document.frmMeetEntry.Swimmer.focus();
		return false;
	}
	if (validate('USS Number',document.frmMeetEntry.ussn) != true) { 	
		document.frmMeetEntry.ussn.focus();
		return false;
	}
	if (validate('Telephone',document.frmMeetEntry.phone) != true) { 	
		document.frmMeetEntry.phone.focus();
		return false;
	}
	
	if (validate('Age',document.frmMeetEntry.age) != true) { 	
		alert("Please enter a valid Age.");
		document.frmMeetEntry.age.focus();
		return false;
	}

	if (isEmail(document.frmMeetEntry.email.value) == false) {
	        alert("Please enter a valid email address.");
	        document.frmMeetEntry.email.focus();
	        return false;
	}
	
	if (document.frmMeetEntry.gender[0].checked ==false && document.frmMeetEntry.gender[1].checked ==false ) { 	
		alert('Please Select Gender');	
		return false;
	}
	
	if (validate('Workout',document.frmMeetEntry.workout) != true) { 	
		document.frmMeetEntry.workout.focus();
		return false;
	}
	
		
	for (var i = 0; i < 10; i++) {	
	iLoop=i;

		if (document.frmMeetEntry.e[i].value.length>0) {	
	
			if (checkNumbers(document.frmMeetEntry.e[i].value) !="") {
			alert ('Event #'+iLoop+' Invalid Characters: ' + checkNumbers(document.frmMeetEntry.e[i].value));
			return false;	} 
		}
	}	
	
winopen('ENTRY','');
	
	
}

function frmLogin_onsubmit() {   	  
   var RetVal=true;   
	if (validate('Login',document.frmLogin.Login) != true) { 
		document.frmLogin.Login.focus();
		RetVal=false;
		return RetVal;
	}
	if (validate('Password',document.frmLogin.Password) != true) { 
		document.frmLogin.Password.focus();
		RetVal=false;
		return RetVal;
	}
   
}

function frmNewsletter_onsubmit() {   	  
	if (validate('Email Address',document.frmNewsletter.Email) != true) { 
		document.frmNewsletter.Email.focus();
		return false;
	}
}

function validate(label,field)
{
	if (field.value.length ==0 ){ 
	alert ("Please Enter " + label);
	
	return field.focus();
	} else {
		if (field.name=="email"){
			if (checkEmail(field.value)!="") {
			alert (checkEmail(field.value));			
			return field.focus();
			} else {
			return true;
			}
		} else if (	field.name=="phone" || field.name=="age"){
		
		if (checkNumbers(field.value)!="") {
			alert (label + " Invalid Characters: " + checkNumbers(field.value));			
			return field.focus();
			} else {
			return true;
			}	
		} else if (	field.name=="Comments"){
		
		if (BadCharComments(field.value)!="") {
			alert (label + " Invalid Characters: " + BadCharComments(field.value));			
			return field.focus();
			} else {
			return true;
			}		
	
		} else {
		 if (BadChar(field.value)!="") {
			alert (label + " Invalid Characters: " + BadChar(field.value));			
			return field.focus();
			} else {
			return true;
			}
		}
	}

}	



function checkNumbers(checkString)
{
	var sError="";         
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if (
        (ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") ||
        (ch == "`") || (ch == "!") || (ch == "~") || (ch == ":") ||
        (ch == "@") || (ch == '"') || (ch == "#") || (ch == "$") ||
        (ch == "%") || (ch == "^") || (ch == "&") || (ch == "*") ||
        (ch == "(") || (ch == ")") || (ch == "=") || (ch == "+") ||
        (ch == "{") || (ch == "}") || (ch == "[") || (ch == "]") || 
        (ch == "|") || (ch == "?") || (ch == "\\") ||(ch == ";") || 
		(ch == "/") || (ch == "<") || (ch == ">") || (ch == "@") || 
		(ch == "_") || (ch == "'")  
                
         ) {
        sError+=ch;
        }    
    }  	
	return sError;

}

function BadCharComments(checkString)
{            
	var sError="";         
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if (
        (ch == "`") || (ch == "~") || (ch == ":") ||
        (ch == '"') || (ch == "#") || (ch == "$") ||
        (ch == "%") || (ch == "^") || (ch == "&") || (ch=="@") ||
        (ch == "(") || (ch == ")") || (ch == "=") || (ch == "+") ||
        (ch == "{") || (ch == "}") || (ch == "[") || (ch == "]") ||
        (ch == "|") || (ch == "\\") || (ch == "_") ||
		(ch == "/") || (ch == "<") || (ch == ">")   
                
         ) {
        sError+=ch;
        }    
    }  	
	return sError;
}

function BadChar(checkString)
{            
	var sError="";         
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if (
        (ch == "`") || (ch == "!") || (ch == "~") || (ch == ":") ||
       (ch == '"') || (ch == "#") || (ch == "$") ||
        (ch == "%") || (ch == "^") || (ch == "&") || (ch=="@") ||
        (ch == "(") || (ch == ")") || (ch == "=") || (ch == "+") ||
        (ch == "{") || (ch == "}") || (ch == "[") || (ch == "]") ||
        (ch == "|") || (ch == "?") || (ch == "\\") || (ch == "_") ||
		(ch == "/") || (ch == "<") || (ch == ">") || (ch == ";")  
                
         ) {
        sError+=ch;
        }    
    }  	
	return sError;
}

function checkEmail(checkString)
        {
            var newstr = "";
            var sError = "";
            var at = false;
            var dot = false;

            // DO SOME PRELIMINARY CHECKS ON THE DATA

            // IF EMAIL ADDRESS HAS A '@' CHARACTER
            if (checkString.indexOf("@") != -1) {
              at = true;
           // IF EMAIL ADDRESS HAS A '.' CHARACTER
            } else if (checkString.indexOf(".") != -1) {
              dot = true;
            }
            // PARSE REMAINDER OF STRING
            for (var i = 0; i < checkString.length; i++) {
                ch = checkString.substring(i, i + 1)
                if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                        || (ch == "@") || (ch == ".") || (ch == "_")
                        || (ch == "-") || (ch >= "0" && ch <= "9")) {
                        newstr += ch;
                        if (ch == "@") {
                            at=true;
                        }
                        if (ch == ".") {
                            dot=true;
                        }
                }
                if (
                (ch == "`") || (ch == "~") || (ch == ":") ||
				(ch == "!") || (ch == "#") || (ch == "$") ||
				(ch == "%") || (ch == "^") || (ch == "&") || (ch == "*") ||
				(ch == "(") || (ch == ")") || (ch == "=") || (ch == "+") ||
				(ch == "{") || (ch == "}") || (ch == "[") || (ch == "]") ||
				(ch == "|") || (ch == "?") || (ch == " ") || (ch == "\\") ||
				(ch == "/") || (ch == "<") || (ch == ">") || (ch == ",") ||
				(ch == ";") || (ch == '"')
				){
					sError+=ch;
					}
            }

            if ((at == true) && (dot == true)) {
				if (sError !="") {
					return "Email Address Invalid Characters: "+sError;
				}
				else {             
					return sError;
				}            										
            }
            else {             
				return "Please Enter A Valid Email Address";
            }            
        }

	function ussNum(form){
	var padding = "***";
		mindex = form.themonth.selectedIndex
		thisMonth = form.themonth.options[mindex].value
		if (thisMonth == ""){
			alert("You must select a birth month")
		return false
		}

		dindex = form.theday.selectedIndex
		thisDay = form.theday.options[dindex].value
	
		if (thisDay == ""){
			alert("You must select a birth day")
			return false
		}

		yindex = form.theyear.selectedIndex
		thisYear = form.theyear.options[yindex].value
		if (thisYear == ""){
			alert("You must select a birth year")
			return false
		}

		name1 = form.firstname.value.substring(0,3)
	
		if (name1 == ""){
			alert("You must enter a first name")
			ussNumForm.firstname.focus()
			ussNumForm.firstname.select()
			return false
		}

		if (name1.length < 3){
			name1 = name1 + padding.substring(0,3 - name1.length)
		}
	
		name2 = form.midinitial.value

		if (name2.length > 1){
			alert("Your initial is more than one letter")
			ussNumForm.midinitial.focus()
			ussNumForm.midinitial.select()
			return false
		}

		if (name2 == ""){
		name2 = "*"
		}
	
		name3 = form.lastname.value.substring(0,4)
		if (name3 == ""){
			alert("You must enter a last name")
			ussNumForm.lastname.focus()
			ussNumForm.lastname.select()
			return false
		}

		if (name3.length < 4){
			name3 = name3 + padding.substring(0,4 - name3.length)
		}

		document.frmMeetEntry.ussn.value = thisMonth + thisDay + thisYear + name1 + name2 + name3
		document.frmMeetEntry.phone.focus()
		window.scroll(0)

		return false
	}

