/*
   So this contains all the validation scripts for the registration.  They are
   rather large, so if you are looking for the athlete one, scroll down like 200
   lines of code.
*/

function validate_sponsor()
{
   var email_filter    = /^.+@.+\..{2,3}$/
   var i,str;
	if(document.sponsor_signup['offer_id'].value == "") {
      alert("Please Select a Package.");
      document.sponsor_signup['offer_id'].className = 'boxerror';
      document.sponsor_signup['offer_id'].focus();
      return false;
   }
   if(document.sponsor_signup['company_name'].value == "") {
      alert("Please enter a team name.");
      document.sponsor_signup['company_name'].className = 'boxerror';
      document.sponsor_signup['company_name'].focus();
      return false;
   }

   if(document.sponsor_signup['street'].value == "") {
      alert("Please enter a street");
      document.sponsor_signup['street'].className = 'boxerror';
      document.sponsor_signup['street'].focus();
      return false;
   }

   if(document.sponsor_signup['city'].value == "") {
      alert("Please enter a city");
      document.sponsor_signup['city'].className = 'boxerror';
      document.sponsor_signup['city'].focus();
      return false;
   }

   var stateIndex = document.sponsor_signup['state'].selectedIndex;
	if (document.sponsor_signup['state'].selectedIndex < 2 || document.sponsor_signup['state'].selectedIndex == 3) {
		alert("Please select a state.");
      document.sponsor_signup['state'].className = 'boxerror';
      document.sponsor_signup['state'].focus();
      return false;
	}
	if (stateIndex == 2 && document.sponsor_signup['state_other'].value == "") {
		alert("Please enter a state / province that is outside the United States.");
      document.sponsor_signup['state_other'].className = 'boxerror';
      document.sponsor_signup['state_other'].focus();
      return false;
	}

	if (document.sponsor_signup['country'].selectedIndex < 2) {
		alert("Please select a country.");
      document.sponsor_signup['country'].className = 'boxerror';
      document.sponsor_signup['country'].focus();
      return false;
	}

   if(document.sponsor_signup['postal_code'].value == "") {
      alert("Please enter a postal code");
      document.sponsor_signup['postal_code'].className = 'boxerror';
      document.sponsor_signup['postal_code'].focus();
      return false;
   }

	str = document.sponsor_signup.email.value;
   if (str != "") {
   	if (!email_filter.test(str)) {
   		alert("Please input a valid email address!");
   		document.sponsor_signup['email'].className = 'boxerror';
   		document.sponsor_signup['email'].focus();
   		return false;
   	}
   }
   else {
   	alert("Please input a valid email address!")
 		document.sponsor_signup['email'].className = 'boxerror';
   	document.sponsor_signup['email'].focus();
   	return false;
   }

   if(document.sponsor_signup['phone'].value == "") {
      alert("Please enter a phone number.");
      document.sponsor_signup['phone'].className = 'boxerror';
      document.sponsor_signup['phone'].focus();
      return false;
   }

	str = document.sponsor_signup.user_email.value;
   if (str != "") {
   	if (!email_filter.test(str)) {
   		alert("Please input a valid email address!");
   		document.sponsor_signup['user_email'].className = 'boxerror';
   		document.sponsor_signup['user_email'].focus();
   		return false;
   	}
   }
   else {
   	alert("Please input a valid email address!")
 		document.sponsor_signup['user_email'].className = 'boxerror';
   	document.sponsor_signup['user_email'].focus();
   	return false;
   }


   if(document.sponsor_signup['user_password'].value == "") {
      alert("Please enter a password.");
      document.sponsor_signup['user_password'].className = 'boxerror';
      document.sponsor_signup['user_password'].focus();
      return false;
   }

   n = document.sponsor_signup.user_password.value.length;
   for (i = 0;i < n;i++) {
      if (document.sponsor_signup.user_password.value.charAt(i) == " ") {
       alert("Spaces are not allowed in the password.");
       document.sponsor_signup.user_password.focus();
       document.sponsor_signup.user_password.className = 'boxerror';
       return false;
      }
   }
/* User this function to limit the password length

   if (document.sponsor_signup['user_password'].value.length < 6) {
      alert("Your password must be at least 6 characters long.");
      document.sponsor_signup['user_password'].focus();
      document.sponsor_signup['user_password'].className = 'boxerror';
      return false;
   } */
   str1 = document.sponsor_signup['user_password'].value;
   str2 = document.sponsor_signup['confirm_password'].value;
   if (str1 != str2)
   {
     alert("Your passwords must match.");
     document.sponsor_signup['user_password'].focus();
	  document.sponsor_signup['user_password'].className = 'boxerror';
     return false;
   }

   /*choice=document.sponsor_signup['sponsor_category'];
   count = 0;
   for (i=0;i<choice.length;++ i) {
      if (choice[i].checked) {
         count++;
      }
   }
   if ( count == 0 ) {
     alert("Your must select aproduct and services category.");
     return false;
   }*/

   if(document.sponsor_signup['user_subdomain'].value == "") {
      alert("Please enter a subdomain");
      document.sponsor_signup['user_subdomain'].className = 'boxerror';
      document.sponsor_signup['user_subdomain'].focus();
      return false;
   }

   return true;
}

function validate_athlete()
{
	//alert('allsport');

   var email_filter    = /^.+@.+\..{2,3}$/
   var i,str;


	if(document.athlete_signup['category_id'].value == "") {
      alert("Please select a Sport.");
      document.athlete_signup['category_id'].className = 'boxerror';
      document.athlete_signup['category_id'].focus();
      return false;
   }

   if(document.athlete_signup['firstname'].value == "") {
      alert("Please enter a first name.");
      document.athlete_signup['firstname'].className = 'boxerror';
      document.athlete_signup['firstname'].focus();
      return false;
   }

   if(document.athlete_signup['lastname'].value == "") {
      alert("Please enter a last name.");
      document.athlete_signup['lastname'].className = 'boxerror';
      document.athlete_signup['lastname'].focus();
      return false;
   }

   if(document.athlete_signup['street'].value == "") {
      alert("Please enter a street");
      document.athlete_signup['street'].className = 'boxerror';
      document.athlete_signup['street'].focus();
      return false;
   }

   if(document.athlete_signup['city'].value == "") {
      alert("Please enter a city");
      document.athlete_signup['city'].className = 'boxerror';
      document.athlete_signup['city'].focus();
      return false;
   }

   var stateIndex = document.athlete_signup['state'].selectedIndex;
	if (document.athlete_signup['state'].selectedIndex < 2 || document.athlete_signup['state'].selectedIndex == 3) {
		alert("Please select a state.");
      document.athlete_signup['state'].className = 'boxerror';
      document.athlete_signup['state'].focus();
      return false;
	}
	if (stateIndex == 2 && document.athlete_signup['state_other'].value == "") {
		alert("Please enter a state / province that is outside the United States.");
      document.athlete_signup['state_other'].className = 'boxerror';
      document.athlete_signup['state_other'].focus();
      return false;
	}

	if (document.athlete_signup['country'].selectedIndex < 2) {
		alert("Please select a country.");
      document.athlete_signup['country'].className = 'boxerror';
      document.athlete_signup['country'].focus();
      return false;
	}

   if(document.athlete_signup['postal_code'].value == "") {
      alert("Please enter a postal code");
      document.athlete_signup['postal_code'].className = 'boxerror';
      document.athlete_signup['postal_code'].focus();
      return false;
   }

   if(document.athlete_signup['rep_id'].selectedIndex < 1) {
      alert("You must select a rep code");
      document.athlete_signup['rep_id'].className = 'boxerror';
      document.athlete_signup['rep_id'].focus();
      return false;
   }

   if(document.athlete_signup['agree'].checked == false) {
      alert("You must check the box that you agree to the terms and conditions");
      document.athlete_signup['agree'].className = 'boxerror';
      document.athlete_signup['agree'].focus();
      return false;
   }

  if(document.athlete_signup['phone'].value == "") {
      alert("Please enter a phone number.");
      document.athlete_signup['phone'].className = 'boxerror';
      document.athlete_signup['phone'].focus();
      return false;
   }

	str = document.athlete_signup.email.value;
   if (str != "") {
   	if (!email_filter.test(str)) {
   		alert("Please input a valid email address!");
   		document.athlete_signup['email'].className = 'boxerror';
   		document.athlete_signup['email'].focus();
   		return false;
   	}
   }
   else {
   	alert("Please input a valid email address!")
 		document.athlete_signup['email'].className = 'boxerror';
   	document.athlete_signup['email'].focus();
   	return false;
   }

	str = document.athlete_signup.user_email.value;
   if (str != "") {
   	if (!email_filter.test(str)) {
   		alert("Please input a valid email address!");
   		document.athlete_signup['user_email'].className = 'boxerror';
   		document.athlete_signup['user_email'].focus();
   		return false;
   	}
   }
   else {
   	alert("Please input a valid email address!")
 		document.athlete_signup['user_email'].className = 'boxerror';
   	document.athlete_signup['user_email'].focus();
   	return false;
   }

   str1 = document.athlete_signup['user_email'].value;
   str2 = document.athlete_signup['confirm_user_email'].value;
   if (str1 != str2)
   {
     alert("Your emails must match.");
     document.athlete_signup['user_email'].focus();
	  document.athlete_signup['user_email'].className = 'boxerror';
     return false;
   }

   if(document.athlete_signup['user_password'].value == "") {
      alert("Please enter a password.");
      document.athlete_signup['user_password'].className = 'boxerror';
      document.athlete_signup['user_password'].focus();
      return false;
   }

   n = document.athlete_signup.user_password.value.length;
   for (i = 0;i < n;i++) {
      if (document.athlete_signup.user_password.value.charAt(i) == " ") {
       alert("Spaces are not allowed in the password.");
       document.athlete_signup.user_password.focus();
       document.athlete_signup.user_password.className = 'boxerror';
       return false;
      }
   }
/* User this function to limit the password length

   if (document.athlete_signup['user_password'].value.length < 6) {
      alert("Your password must be at least 6 characters long.");
      document.athlete_signup['user_password'].focus();
      document.athlete_signup['user_password'].className = 'boxerror';
      return false;
   } */
   str1 = document.athlete_signup['user_password'].value;
   str2 = document.athlete_signup['confirm_password'].value;
   if (str1 != str2)
   {
     alert("Your passwords must match.");
     document.athlete_signup['user_password'].focus();
	  document.athlete_signup['user_password'].className = 'boxerror';
     return false;
   }

   if(document.athlete_signup['user_subdomain'].value == "") {
      alert("Please enter a subdomain");
      document.athlete_signup['user_subdomain'].className = 'boxerror';
      document.athlete_signup['user_subdomain'].focus();
      return false;
   }
   return true;
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);

   if (i == -1) {
      return "";
   }
   else {
      if (buttonGroup[i]) {
      // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      }
      else {
      // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}

function isReady(form) {
	if (isFilled(form.name) == false) {
		alert('Please enter your name.');
		form.name.focus();
		return false;
	}
	if(isEmail(form.email) == false) {
		alert('Please enter your email address.');
		form.email.focus();
		return false;
	}
	if (isFilled(form.phone) == false) {
		alert('Please enter your phone number.');
		form.phone.focus();
		return false;
	}
	return true;
}

function isReadytoo(form) {
	if (isFilled(form.dates) == false) {
		alert("Please enter your Dates.");
		form.dates.focus();
		return false;
	}
	if (isFilled(form.theevent) == false) {
		alert("Please enter your Event.");
		form.theevent.focus();
		return false;
	}
	if (isFilled(form.venue) == false) {
		alert("Please enter your Venue.");
		form.venue.focus();
		return false;
	}
	if (isFilled(form.city) == false) {
		alert("Please enter your City.");
		form.city.focus();
		return false;
	}
	if (isFilled(form.state) == false) {
		alert("Please enter your State.");
		form.state.focus();
		return false;
	}
return true;
}

function isReadyAd(form) {
	if (isFilled(form.firstname) == false) {
		alert("Please enter your First Name.");
		form.firstname.focus();
		return false;
	}
	if (isFilled(form.lastname) == false) {
		alert("Please enter your Last Name.");
		form.lastname.focus();
		return false;
	}
	if (isFilled(form.company) == false) {
		alert("Please enter your Company.");
		form.company.focus();
		return false;
	}
	if (isFilled(form.url) == false) {
		alert("Please enter your Website URL.");
		form.url.focus();
		return false;
	}
	if (isFilled(form.email) == false) {
		alert("Please enter your Email.");
		form.email.focus();
		return false;
	}
	if (isFilled(form.phone) == false) {
		alert("Please enter your Phone.");
		form.phone.focus();
		return false;
	}
	if (isFilled(form.city) == false) {
		alert("Please enter your City.");
		form.city.focus();
		return false;
	}
	if (isFilled(form.state) == false) {
		alert("Please enter your State / Province.");
		form.state.focus();
		return false;
	}
	if (isFilled(form.country) == false) {
		alert("Please enter your Country.");
		form.country.focus();
		return false;
	}

return true;
}

function isReadyForgot(form) {
	if (isEmail(form.email) == false) {
		alert("Please enter a valid Username / Email Address.");
		form.country.focus();
		return false;
	}

return true;
}

function isEmail(elm) {
	if(elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value != " ") {
		return true;
	} else {
		return false;
	}
}

function isFilled(elm) {
	if (elm.value == "" || elm.value == null) {
		return false;
	} else {
		return true;
	}
}
