function isDate(strmonth, strday, stryear) 
{
  // Ensure valid month and set maximum days for that month...
  if( (strmonth == "1") || (strmonth == "3") || (strmonth == "5") || 
      (strmonth == "7") || (strmonth == "8") || (strmonth == "10") || 
      (strmonth == "12") ) { monthdays = 31 }
  else if( (strmonth == "4") || (strmonth == "6") || (strmonth == "9") ||
           (strmonth == "11") ) { monthdays = 30 }
  else if(strmonth == "2") { 
    monthdays = ((stryear % 4) == 0) ? 29 : 28; 
  }
  else {
    return false;
  }
  if(strday > monthdays) {
    return false;
  }
  return true;
}

function isValStateAndZip()
{
  if (document.PlayerForm.Country.value == 1)
  {
	document.PlayerForm.StateIsReq.value="*"
	document.PlayerForm.ZipIsReq.value="*"
  }
  else
  {
	document.PlayerForm.StateIsReq.value=" "
	document.PlayerForm.ZipIsReq.value=" "
  }
  return true;
}


function createPlayer() 
{

	var txtError = "";
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
		
	if (document.PlayerForm.Email.value == "" || !re_mail.test(document.PlayerForm.Email.value))
	{
		txtError = txtError + "Please enter a valid Email Address\n (example: yourname@somewhere.com).\n";	
	} 


	if (document.PlayerForm.Title.value == "")
	{
		txtError = txtError + "Please select a Title from the list.\n";
	}
	
	
	if (document.PlayerForm.FirstName.value == "")
	{
		txtError = txtError + "Please enter a First Name.\n";
	}
	
	
	if (document.PlayerForm.LastName.value == "")
	{
		txtError = txtError + "Please enter a Last Name.\n";
	}
	
	
	if (document.PlayerForm.Country.value == "")
	{
		txtError = txtError + "Please select a Country from the list.\n";
	}
	
	
	if (document.PlayerForm.Address1.value == "")
	{
		txtError = txtError + "Please enter an Address.\n";
	}
	
	
	if (document.PlayerForm.City.value == "")
	{
		txtError = txtError + "Please enter a City.\n";
	}


	// BAD: This relies on the fact that United States is value 1 in our SQL SERVER db.	
	if (document.PlayerForm.Country.value == 1)
	{
		if (document.PlayerForm.State.value == "")
		{
			txtError = txtError + "Please select a State from the list.\n";
		}
	
		if (document.PlayerForm.PostalCode.value == "")
		{
			txtError = txtError + "Please enter a Postal Code.\n";
		}
	}
	
	
	if (document.PlayerForm.BirthMonth.value == "")
	{
		txtError = txtError + "Please enter a valid Month for your Date Of Birth.\n";
	}
	
	
	if (document.PlayerForm.BirthDay.value == "")
	{
		txtError = txtError + "Please enter a valid Day for your Date Of Birth.\n";
	}
	
	
	if (document.PlayerForm.BirthYear.value == "")
	{
		txtError = txtError + "Please enter a valid Year for your Date Of Birth.\n";
	}
	
	
	// validate the date of birth that has been entered
	dobReturn = isDate(document.PlayerForm.BirthMonth.value,document.PlayerForm.BirthDay.value,document.PlayerForm.BirthYear.value);
	if (dobReturn == false)
	{
		txtError = txtError + "Please enter a valid Date Of Birth.\n";
	}
	else
		document.PlayerForm.DOB.value = document.PlayerForm.BirthMonth.value + "/" + document.PlayerForm.BirthDay.value + "/" + document.PlayerForm.BirthYear.value;

	birthday = new Date(document.PlayerForm.DOB.value);
	today = new Date();
	years = today.getFullYear() - birthday.getFullYear();
	birthday.setYear( today.getFullYear() );
	// If your birthday hasn't occurred yet this year, subtract 1.
	if(today < birthday)
	{
		years-- ;
	}
	
	
	if (years < 21)
	{
		txtError = txtError + "Must Be 21 Years Old To Sign-Up.\n";
	}
		

	if(txtError != ''){
		alert(txtError);
		return false;	
	}
	
}