function echeck(str) { //send a string here and it will check to make sure its an email address

	if (!str.match(/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z]{2,6}$/)) {
		alert("Invalid E-mail ID")
		return false;
	}
	return true;
/*
	var at="@"
	var dot="."
	var lat=str.indexOf(at) //gets the posotion of the @
	var lstr=str.length
	var ldot=str.indexOf(dot) //gets the posotion of the .
	
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	}

	 return true
	 */
}


function ValidateForm(){ //validate for application

	var appsnd=document.appfrm


	if ((appsnd.alias.value==null)||(appsnd.alias.value=="")){
		alert("Please enter your Super Hero alias.")
		appsnd.alias.focus()
		return false
	}

	if ((appsnd.name.value==null)||(appsnd.name.value=="")){
		alert("Please Enter your first name.")
		appsnd.name.focus()
		return false
	}

	if ((appsnd.lname.value==null)||(appsnd.lname.value=="")){
		alert("Please Enter your last name.")
		appsnd.lname.focus()
		return false
	}

	if ((appsnd.email.value==null)||(appsnd.email.value=="")){
		alert("Please Enter your email address.")
		appsnd.email.focus()
		return false
	}

	if (echeck(appsnd.email.value)==false){
		appsnd.email.focus() //the echeck function pops up the alert window for you
		return false
	}

	if (appsnd.email.value!=appsnd.email1.value){
		alert("Your email confirmation doesn't match.")
		appsnd.email.focus()
		return false
	}

	if ((appsnd.pword.value==null)||(appsnd.pword.value=="")){
		alert("Please enter your password.")
		appsnd.pword.focus()
		return false
	}

	if (appsnd.pword.value.length<8) {
		alert("You password is too short, 8 character minimun.")
		appsnd.pword.focus()
		return false
	}

	if (appsnd.pword.value!=appsnd.pword1.value){
		alert("Your password confirmation doesn't match.")
		appsnd.pword.focus()
		return false
	}


	//isNAN = is not a number function
	if ((appsnd.phone1.value.length<3)||(appsnd.phone2.value.length<3)||(appsnd.phone3.value.length<4)||isNaN(appsnd.phone1.value + appsnd.phone2.value + appsnd.phone3.value)) {
		alert("Please enter your phone number corectly.")
		appsnd.phone1.focus()
		return false
	}

	if ((appsnd.add.value==null)||(appsnd.add.value=="")){
		alert("Please enter your address so we can mail you your pay.")
		appsnd.add.focus()
		return false
	}

	if ((appsnd.exp.value==null)||(appsnd.exp.value=="")||isNaN(appsnd.exp.value)){
		alert("Please enter/fix your experience.")
		appsnd.exp.focus()
		return false
	}
/*	
	if ((appsnd.pay.value==null)||(appsnd.pay.value=="")||isNaN(appsnd.pay.value)){
		alert("Please enter/fix requested pay.")
		appsnd.pay.focus()
		return false
	}
*/	
	//NOTE: EMAIL CHECK ALLOWS "," IN AN EMAIL ADDY
	
	
	allunv=appsnd.unv.value + appsnd.unv0.value + appsnd.unv1.value + appsnd.unv2.value + appsnd.unv3.value
	if ((allunv==null)||(allunv=="")) {
		alert("Please enter a University in either 10 or 11.")
		appsnd.unv.focus()
		return false
	}//*/
	
	
	
	var isChecked = false;
	checklist = document.getElementsByName('ag[]')
	for (var i = 0; i < checklist.length; i++) {
	   if (checklist[i].checked) {
	      isChecked = true;
	   }
	}
	if (!isChecked){
		alert("Please select at least one age group you can tutor.")
		checklist[0].focus()
		return false
	}


	var isChecked = false;
	checklist = document.getElementsByName('crs[]')
	for (var i = 0; i < checklist.length; i++) {
	   if (checklist[i].checked) {
	      isChecked = true;
	   }
	}
	/*if (document.getElementsByName('bac[]') != null) {
		checklist = document.getElementsByName('bac[]')
		for (var i = 0; i < checklist.length; i++) {
		   if (checklist[i].checked) {
		      isChecked = true;
		   }
		}
	}*/
	if (!isChecked){
		alert("Please select at least one course you can tutor.")
		checklist[0].focus()
		return false
	}

	if ((appsnd.schedule.value==null)||(appsnd.schedule.value=="")){
		alert("Please enter your schedule.")
		appsnd.schedule.focus()
		return false
	}

	if ((appsnd.statement.value==null)||(appsnd.statement.value=="")){
		alert("Please enter a statement to your students.")
		appsnd.statement.focus()
		return false
	}



/*	if (!appsnd.terms.checked){
		alert("You must agree to the terms and conditions to apply.")
		appsnd.terms.focus()
		return false
	}		
*/



	return true
	
}





function ValidateContact(){ //validate for contact_us

	var emailsnd=document.emailfrm

	radiosel=null

	for (var i=0; i < emailsnd.youare.length; i++)
	   {
		if (emailsnd.youare[i].checked){ radiosel=i+1 }
	   }

	if ((radiosel==null)||(radiosel=="")){
		alert("Please Enter who you are.")
		emailsnd.youare[0].focus()
		return false
	}

	if ((emailsnd.fname.value==null)||(emailsnd.fname.value=="")){
		alert("Please Enter your first name.")
		emailsnd.fname.focus()
		return false
	}
	
	if ((emailsnd.lname.value==null)||(emailsnd.lname.value=="")){
		alert("Please Enter your last name.")
		emailsnd.lname.focus()
		return false
	}
	
	if ((emailsnd.emailbox.value==null)||(emailsnd.emailbox.value=="")){
		alert("Please Enter your Email ID")
		emailsnd.emailbox.focus()
		return false
	}
	if (echeck(emailsnd.emailbox.value)==false){
		emailsnd.emailbox.focus()
		return false
	}
	
	if ((emailsnd.msg.value==null)||(emailsnd.msg.value=="")){
		alert("Please Enter a message.")
		emailsnd.msg.focus()
		return false
	}
	
	if ((emailsnd.school.value == null)||(emailsnd.school.value=="")){
		alert("Please select a school.")
		emailsnd.thisstate.focus()
		return false
	}
	
	
	return true
 }
 
 
function ValidateBuy() { //validate for purchasing hours
	
	var buysnd=document.payfrm
	
	if ((buysnd.school.value==null)||(buysnd.school.value=="")){
		alert("Please select a school")
		buysnd.thisstate.focus()
		return false
	}

	var isChecked = 0;
	checklist = document.getElementsByName('crs[]')
	for (var i = 0; i < checklist.length; i++) {
	   if (checklist[i].checked) {
	      isChecked++;
	   }
	}
	if (!isChecked){
		alert("Please select at least one class you need tutoring in.")
		//buysnd.second.focus()
		//checklist[0].focus()
		location.href="#second";
		return false
	}

	if (buysnd.level.selectedIndex == 0){
		alert("Please select a level.");
		//buysnd.third.focus()
		temp=document.getElementById('step3')
		temp.style.display = "block";
		location.href="#third";
		return false;
	}
	
	if (buysnd.hours.selectedIndex == 0){
		alert("Please select hours.");
		//buysnd.third.focus()
		temp=document.getElementById('step3')
		temp.style.display = "block";
		location.href="#third";
		return false;
	}

	return true;
 }


function ValidateCustInfo() { //validate for purchasing hours
	
	var infosnd=document.userinfo;

	if ((infosnd.fname.value==null)||(infosnd.fname.value=="")){
		alert("Please Enter your first name.")
		infosnd.fname.focus()
		return false
	}
	
	if ((infosnd.lname.value==null)||(infosnd.lname.value=="")){
		alert("Please Enter your last name.")
		infosnd.lname.focus()
		return false
	}

	if ((infosnd.phone1.value.length<3)||(infosnd.phone2.value.length<3)||(infosnd.phone3.value.length<4)||isNaN(infosnd.phone1.value + infosnd.phone2.value + infosnd.phone3.value)) {
		alert("Please enter your phone number corectly.")
		infosnd.phone1.focus()
		return false
	}

	if ((infosnd.add.value==null)||(infosnd.add.value=="")){
		alert("Please enter your address.")
		infosnd.add.focus()
		return false
	}
	
	if ((infosnd.email.value==null)||(infosnd.email.value=="")){
		alert("Please Enter your email address.")
		infosnd.email.focus()
		return false
	}

	if (echeck(infosnd.email.value)==false){
		infosnd.email.focus() //the echeck function pops up the alert window for you
		return false
	}

	if (infosnd.email.value!=infosnd.email1.value){
		alert("Your email confirmation doesn't match.")
		infosnd.email.focus()
		return false
	}

	if ((infosnd.pword.value==null)||(infosnd.pword.value=="")){
		alert("Please enter your password.")
		infosnd.pword.focus()
		return false
	}

	if (infosnd.pword.value.length<8) {
		alert("You password is too short, 8 character minimun.")
		infosnd.pword.focus()
		return false
	}

	if (infosnd.pword.value!=infosnd.pword1.value){
		alert("Your password confirmation doesn't match.")
		infosnd.pword.focus()
		return false
	}

	if ((infosnd.comments.value==null)||(infosnd.comments.value=="")){
		alert("Please enter days/times when you're free to be tutored.")
		infosnd.comments.focus()
		return false
	}

	
	return true

 }



function ValidateUsrForm() { //validate for new user acct
	
	var userinfo=document.newusrfrm;

	if ((userinfo.username.value==null)||(userinfo.username.value=="")){
		alert("Please Enter your username.")
		userinfo.username.focus()
		return false
	}

	if (!userinfo.username.value.match(/^[a-zA-Z]([a-zA-Z0-9_-]+)*$/)) {
		alert("The username must begin with a letter and may only contain letters, numbers, '_' and '-' .");
		userinfo.username.focus()
		return false
	}

	if (userinfo.username.value.length<4) {
		alert("You username is too short, 4 character minimun.")
		userinfo.username.focus()
		return false
	}

	if ((userinfo.email.value==null)||(userinfo.email.value=="")){
		alert("Please Enter your email address.")
		userinfo.email.focus()
	
		return false
	}
	
	if (echeck(userinfo.email.value)==false){
		userinfo.email.focus() //the echeck function pops up the alert window for you
		return false
	}
	
	if (userinfo.email.value!=userinfo.email1.value){
		alert("Your email confirmation doesn't match.")
		userinfo.email.focus()
		return false
	}

	if ((userinfo.fname.value==null)||(userinfo.fname.value=="")){
		alert("Please Enter your first name.")
		userinfo.fname.focus()
		return false
	}
	
	if ((userinfo.lname.value==null)||(userinfo.lname.value=="")){
		alert("Please Enter your last name.")
		userinfo.lname.focus()
		return false
	}

	if ((userinfo.password.value==null)||(userinfo.password.value=="")){
		alert("Please enter your password.")
		userinfo.password.focus()
		return false
	}

	if (userinfo.password.value.length<8) {
		alert("You password is too short, 8 character minimun.")
		userinfo.password.focus()
		return false
	}

	if (userinfo.password.value!=userinfo.password1.value){
		alert("Your password confirmation doesn't match.")
		userinfo.password.focus()
		return false
	}
	return true
 }
