/*function CheckRosterForm() {
	if (document.question.team.value == "") {
		alert("Please enter your team name.");
		document.question.team.focus();
		document.question.team.select();
		return false;
	}
	else if (document.question.password.value == "") {
		alert("Please enter your password.");
		document.question.password.focus();
		document.question.password.select();
		return false;
	}
	else {
		return true;
	}
}*/

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 9;

function isInteger(s) {   
	var i;

	if (s.length != 10) return false;
	
	for (i = 0; i < s.length; i++) {   
	  // Check that current character is number.
    var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
  }
  
	// All characters are numbers.
  return true;
}

function stripCharsInBag(s, bag) {   
	var i;
  var returnString = "";
  
	// Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++) {   
		// Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  
	return returnString;
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkForm () {
	if (document.contact_form.fullname.value == "") {
		alert("Please enter your name.");
		document.contact_form.fullname.focus();
		document.contact_form.fullname.select();
		return false;
	}
	if (document.contact_form.email.value == "") {
		alert ("Please enter an Email Address.");
		document.contact_form.email.focus();
		document.contact_form.email.select();
		return false;
	}
	if (!test(document.contact_form.email.value)) { 
		alert ("Please enter a valid Email Address.");
		document.contact_form.email.focus();
		document.contact_form.email.select();
		return false;
	}

	var Phone=document.contact_form.phone;

	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please enter a Phone Number.");
		Phone.focus();
		Phone.select();
		return false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid Phone Number.");
		Phone.value="";
		Phone.focus();
		Phone.select();
		return false;
	}
	if (!checkAlphanum(document.contact_form.comments.value)) {
		alert('Please enter only Alphanumeric and the following special characters: .,?!_()');
		document.contact_form.comments.focus();
		return false;

		function checkAlphanum(strObject) {
			/* Returns true if the field has all alphanumeric characters, false if not.
			You must pass in a input (text) object, not the value. */
			var re = /^[0-9A-Za-z\s.,!?_()]+$/;
			return re.test(strObject);
		}
	}

	return true;
}

function test(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(src);
}

function wipeText(el, name) {
	if (el.defaultValue == el.value) {
		el.value = "";

		el.className="input2";				

		if (el.name == "password") {
			document.getElementById("swapper").innerHTML="<input type=\"password\" name=\"password\" id=\"pass_box\" class=\"input2\" />" ;
			document.getElementById("pass_box").focus();
		}
	}
}

function CheckStates() {
	if (document.state_search.State_ID.value == "0") {
		alert("Must select a state.");
		document.state_search.State_ID.focus();
		return false;
	}
	else {
		return true;
	}
}

function CheckQuestion() {
	if (document.question.your_name.value == "" || document.question.your_name.defaultValue == document.question.your_name.value) {
		alert("Please enter your name.");
		document.question.your_name.focus();
		document.question.your_name.select();
		return false;
	}
	else if (document.question.email_phone.value == "" || document.question.email_phone.defaultValue == document.question.email_phone.value) {
		alert("Please enter your phone or email address.");
		document.question.email_phone.focus();
		document.question.email_phone.select();
		return false;
	}
	else {
		return true;
	}
}
		