/*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;
//check for white space
var reWhiteSpace = new RegExp(/^\s+$/);

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.first_name.value == "" || reWhiteSpace.test(document.contact_form.first_name.value)) {
		alert("Please enter your First Name.");
		document.contact_form.first_name.focus();
		document.contact_form.first_name.select();
		return false;
	}
	if (document.contact_form.last_name.value == "" || reWhiteSpace.test(document.contact_form.last_name.value)) {
		alert("Please enter your Last Name.");
		document.contact_form.last_name.focus();
		document.contact_form.last_name.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.select();
		return false;
	}
	if (document.contact_form.company.value == "" || reWhiteSpace.test(document.contact_form.company.value)) {
		alert ("Please enter your Company.");
		document.contact_form.company.focus();
		document.contact_form.company.select();
		return false;
	}

	if (document.contact_form.state.value == "" || reWhiteSpace.test(document.contact_form.state.value)) {
		alert ("Please enter your State.");
		document.contact_form.state.focus();
		document.contact_form.state.select();
		return false;
	}
	if (document.contact_form.country.value == "" || reWhiteSpace.test(document.contact_form.country.value)) {
		alert ("Please enter your Country.");
		document.contact_form.country.focus();
		document.contact_form.country.select();
		return false;
	}
	if (!checkAlphanum(document.contact_form.comments.value) || reWhiteSpace.test(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 CheckEmail() {
	if (document.eamil.email_value.value == "" || document.eamil.email_value.defaultValue == document.eamil.email_value.value) {
		alert ("Please enter an Email Address.");
		document.eamil.email_value.focus();
		document.eamil.email_value.select();
		return false;
	}
	if (!test(document.eamil.email_value.value)) { 
		alert ("Please enter a valid Email Address.");
		document.eamil.email_value.focus();
		document.eamil.email_value.select();
		return false;
	}
}

function wipeText(el, name) {
	if (el.defaultValue == el.value) {
		el.value = "";

		if (el.name == "comments") el.className="input4";
		else if (el.name == "search_value" || el.name == "email_value") el.className="input6";
		else if (el.name == "first_name" || el.name == "last_name" || el.name == "state" || el.name == "country") el.className="input8";
		else 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.first_name.value == "" || document.question.first_name.defaultValue == document.question.first_name.value || reWhiteSpace.test(document.question.first_name.value)) {
		alert("Please enter your First Name.");
		document.question.first_name.select();
		document.question.first_name.focus();
		return false;
	}
	if (document.question.last_name.value == "" || document.question.last_name.defaultValue == document.question.last_name.value || reWhiteSpace.test(document.question.last_name.value)) {
		alert("Please enter your Last Name.");
		document.question.last_name.select();
		document.question.last_name.focus();
		return false;
	}
	if (document.question.email.value == "") {
		alert ("Please enter an Email Address.");
		document.question.email.focus();
		document.question.email.select();
		return false;
	}
	if (!test(document.question.email.value)) { 
		alert ("Please enter a valid Email Address.");
		document.question.email.focus();
		document.question.email.select();
		return false;
	}

	var Phone=document.question.phone;

	if ((Phone.value==null)||(Phone.value=="") || document.question.phone.defaultValue == Phone.value){
		alert("Please enter a Phone Number.");
		document.question.phone.focus();
		document.question.phone.select();
		return false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid Phone Number.");
		Phone.value="";
		document.question.phone.select();
		return false;
	}
	if (document.question.company.value == "" || document.question.company.defaultValue == document.question.company.value || reWhiteSpace.test(document.question.company.value)) {
		alert("Please enter your Company.");
		document.question.company.focus();
		document.question.company.select();
		return false;
	}
	if (document.question.state.value == "" || document.question.state.defaultValue == document.question.state.value || reWhiteSpace.test(document.question.state.value)) {
		alert("Please enter your State/Prov.");
		document.question.state.focus();
		document.question.state.select();
		return false;
	}
	if (document.question.country.value == "" || document.question.country.defaultValue == document.question.country.value || reWhiteSpace.test(document.question.country.value)) {
		alert("Please enter your Country.");
		document.question.country.focus();
		document.question.country.select();
		return false;
	}
	if (document.question.comments.value == "" || document.question.comments.defaultValue == document.question.comments.value) {
		alert("Please enter a Comment or Question.");
		document.question.comments.focus();
		document.question.comments.select();
		return false;
	}
	if (!checkAlphanum(document.question.comment.value) || reWhiteSpace.test(document.question.comment.value)) {
		alert('Please enter only Alphanumeric and the following special characters: .,?!_()');
		document.question.comment.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 Show_EW() {
	var pgm = "documents/user_assets/news/" + document.news.News_Story_ID.value;

	newwindow=window.open (pgm,"mywindow","location=1,status=1,scrollbars=1,resizable=1,width=700,height=800"); 
	if (window.focus) {newwindow.focus()}
	return false;
}

function checkCreateForm () {
	if (document.create_form.First_Name.value == "") {
		alert("Please enter your First Name.");
		document.create_form.First_Name.focus();
		document.create_form.First_Name.select();
		return false;
	}
	if (document.create_form.Last_Name.value == "") {
		alert("Please enter your Last Name.");
		document.create_form.Last_Name.focus();
		document.create_form.Last_Name.select();
		return false;
	}
	if (document.create_form.Email_Address.value == "") {
		alert ("Please enter an Email Address.");
		document.create_form.Email_Address.focus();
		document.create_form.Email_Address.select();
		return false;
	}
	if (!test(document.create_form.Email_Address.value)) { 
		alert ("Please enter a valid Email Address.");
		document.create_form.Email_Address.focus();
		document.create_form.Email_Address.select();
		return false;
	}
	if (document.create_form.Company.value == "") {
		alert ("Please enter your Company/CO-OP Name.");
		document.create_form.Company.focus();
		document.create_form.Company.select();
		return false;
	}
	if (document.create_form.User_Name.value == "") {
		alert ("Please enter an User Name.");
		document.create_form.User_Name.focus();
		document.create_form.User_Name.select();
		return false;
	}
	if (document.create_form.Password.value == "") {
		alert ("Please enter an Password.");
		document.create_form.Password.focus();
		document.create_form.Password.select();
		return false;
	}

return true;
}


		
