/*
  12-Jan-2010 (A.Ianovski) - added optional confirmation prompt into validateRegistration() (issue#222).
  20090324 AI - name validation changed to isValidUserName().
  20090323 LH - Permit email addresses to be shared
*/

   function isEmpty( str )
   {
        var strRE = /^[\s ]*$/gi;
        return strRE.test(str);
    }



function validateRegistration(show_prompt)
{
   var  teamname  = document.getElementById('teamname');
   var  eventname =  document.getElementById('ddlevent');
   var  username = document.getElementById('txtusername');
   var  passwd = document.getElementById('passwd');
   var  retypepasswd = document.getElementById('retypepasswd');
   var  emailId = document.getElementById('emailId');
   var  fname = document.getElementById('fname');
   var  lname = document.getElementById('lname');
   var  DOB_day = document.getElementById('DOB_day');
   var  DOB_Month = document.getElementById('DOB_Month');
   var  DOB_Year = document.getElementById('DOB_Year');
   var  location = document.getElementById('locationofuser');
   var  postal_code = document.getElementById('postal_code');
   var  invalid = " ";

   var dt= DOB_Month.value + '/'+ DOB_day.value+'/'+DOB_Year.value;

//dd
  if(isValidUserName(fname.value) !=true)
  {
	 alert('First Name contains invalid symbols');
	 fname.focus();
	 return false;
  }

   if(trim(teamname.value)=="")
   {
	   alert('Please Enter Team Name');
	   teamname.focus();
	   return false;
	}
  if(eventname.value == "0")
  {
     alert('Select An Event');
	 eventname.focus();
	 return false;

  }

  if(trim(username.value)=="")
  {
	  alert('Enter Username');
	  username.focus();
	  return false;
  }
  else if(isAlphanumeric(username.value) !=true)
  {
	  alert('Username must be lettters or numbers only,special characters or blank space not allowed');
	  username.focus();
	  return false;
  }
  if(passwd.value=="")
  {
     alert('Enter Password');
	 passwd.focus();
	 return false;
  }

  if(passwd.value.indexOf(invalid) > -1)
  {
	 alert('Password does not allow any blank space');
	 passwd.focus();
	 return false;
  }
  else if(passwd.value.length <6)
  {
	 alert('Password must be atleast 6 characters length');
	 passwd.focus();
	 return false;
  }
  if(retypepasswd.value=="")
  {
	 alert('Enter Re Type Password');
	 retypepasswd.focus();
	 return false;
  }
  else if(passwd.value != retypepasswd.value)
  {
	 alert('Password and Re Type Password not matched');
	 retypepasswd.focus();
	 return false;
  }
  if(trim(emailId.value) == "")
  {
   //alert('Enter E-mail Address');
   alert('Please enter an email address: if necessary you can share an address with a team or family member');
	 emailId.focus();
	 return false;
  }
  else if(checkEmail(emailId.value) !=true)
  {
	 alert('Please enter a valid email address');
	 emailId.focus();
	 return false;
  }
  if(trim(fname.value) == "")
  {
	 alert('Enter First Name');
	 fname.focus();
	 return false;
  }
  else if(isValidUserName(fname.value) !=true)
  {
	 alert('First Name contains invalid symbols');
	 fname.focus();
	 return false;
  }

  if(trim(lname.value) =="")
  {
	alert('Enter Last Name');
	 lname.focus();
	 return false;
  }
 if (isDate(dt)==false)
	{
		DOB_day.focus();
		return false;
	}
	if(location.value == "0")
    {
     alert('Select location');
	 location.focus();
	 return false;
   }
   if(trim(postal_code.value) !="")
   {
	 if(isNumeric(postal_code.value) != true)
	 {
	   alert('Enter Numeric value for Postal Code/Zip');
	   postal_code.focus();
	   return false;
	 }
	 if(postal_code.value.value.length <5)
	 {
		alert('Postal code atleast 5 digit,invalid postal code/zip');
	    postal_code.focus();
	    return false;

	 }
  }

  if(show_prompt == true)
  {
    var  reg_amount = document.getElementById('reg_amount');
    return confirm('Are you sure you want to register team "' + teamname.value + '" in event "' + eventname.options[eventname.selectedIndex].text + '" for $' + reg_amount.value + ' ?');
  }
}

function chk_donation_amt()
{
	var Email = document.getElementById('DonationAdditionalEmail');
	var DonationAmount = document.getElementById('DonationAmount');
	var EventName = document.getElementById('DonationEventID');
	var TeamName = document.getElementById('DonationTeamID');

	if(Email.value =="")
    {
	 alert('Enter E-mail Address');
	 Email.focus();
	 return false;
    }
	else if(!checkEmail(Email.value))
	{
		 alert('Enter valid E-mail Address');
		 Email.focus();
		 return false;
	}

	if(DonationAmount.value=="")
	{
	alert("Please enter Amount");
	DonationAmount.focus();
	return false;
	}
	else if(!isNumber(DonationAmount.value))
	{
		alert("Please enter valid Amount");
		DonationAmount.focus();
		return false;
	}


	if(EventName.value == "")
	{
		alert('Select Event Name');
		EventName.focus();
		return false;
	}

	if(TeamName.value == "")
	{
		alert('Select Team Name');
		TeamName.focus();
		return false;
	}
}