<!--
//global variable for error flag
var errfound = false;

//function to validate by length
function ValidLength(item, len) {
  return (item.length >= len);
}

//function to validate max length
function ValidMaxLength(item, len) {
  return (item.length <= len);
}

//function to test for matching passwords
function PasswordMatch(item1, item2) {
  return (item1 == item2);
}

//test for valid email address (for now, just an @ symbol)
function ValidEmail(item) {
  for (var i = 0; i <= item.length - 1; i++) {
    if (item.charAt(i) == "@") {
	  return true;
	  }
	}
  return false;
}

//check for only numbers in phone and fax
function ValidNumber(item) {
   for (var i = 0; i <= item.length - 1; i++) {
      if (isNaN(item.charAt(i))) {
          return false
        }
    }
	return true;
}

// display an error alert
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.focus();
   errfound = true;
}



/********************************************
*  			FUNCTION validEditEvent			*
*  Function to validate input from 			*
*  EditEvent form.							*
*											*
********************************************/

function validEditEvent() {
   errfound = false;
   //test that all fields have values
   if (!ValidLength(document.EditEvent.Title.value,1))
      error(document.EditEvent.Title,"Please enter a title for your event!");
	  
  //test for maximum lengths in fields
   if (!ValidMaxLength(document.EditEvent.Title.value,200))
      error(document.EditEvent.Title,"The title of your event must be 200 characters or less. \n " +
			"Please enter an abbreviated title and try again.");
   if (!ValidMaxLength(document.EditEvent.Description.value,500))
      error(document.EditEvent.Description,"The description of your event must be 500 characters or less. \n " +
			"Please enter a shorter description and try again.");
   if (!ValidMaxLength(document.EditEvent.Abstract.value,500))
      error(document.EditEvent.Abstract,"The abstract must be 500 characters or less. \n " +
			"Please enter a shorter abstract and try again.");
   if (!ValidMaxLength(document.EditEvent.Speaker.value,300))
      error(document.EditEvent.Speaker,"The names of the speaker(s) must be 300 characters or less. \n " +
			"Please enter abbreviated names of the speaker(s) and try again.");
   if (!ValidMaxLength(document.EditEvent.Affiliation.value,300))
      error(document.EditEvent.affiliation,"The affiliation field must be 300 characters or less. \n " +
			"Please enter a shorter affiliation description and try again.");
   if (!ValidMaxLength(document.EditEvent.MoreInformationDescription.value,500))
      error(document.EditEvent.MoreInformationDescription,"The more information field must be 500 characters or less. \n " +
			"Please enter a shorter description for more information and try again.");
   if (!ValidMaxLength(document.EditEvent.URL.value,300))
      error(document.EditEvent.URL,"The web address field must be 300 characters or less. \n " +
			"Please enter a shorter web address for more information and try again.");
   if (!ValidMaxLength(document.EditEvent.Sponsor.value,500))
      error(document.EditEvent.Sponsor,"The sponsor description for your event must be 500 characters or less. \n " +
			"Please enter a shorter description of sponsorship and try again.");
   if (!ValidMaxLength(document.EditEvent.StaffNotes.value,1000))
      error(document.EditEvent.Sponsor,"Staff notes must be 1000 characters or less. \n " +
			"Please shorten this and try again.");
   
   return !errfound; /* true if there are no errors */
}


/********************************************
*  			FUNCTION validAddEvent			*
*  Function to validate input from AddEvent	*
*  form.									*
*											*
********************************************/

function validAddEvent() {
   errfound = false;

   //test that all fields have values
   if (!ValidLength(document.AddEvent.Title.value,1)&&!ValidLength(document.AddEvent.EventID.value, 1))
      error(document.AddEvent.Title,"Please enter a new title for your event or select an existing title!");
	  
  //test for maximum lengths in fields
   if (!ValidMaxLength(document.AddEvent.Title.value,200))
      error(document.AddEvent.Title,"The title of your event must be 200 characters or less. \n " +
			"Please enter an abbreviated title and try again.");
   if (!ValidMaxLength(document.AddEvent.Description.value,500))
      error(document.AddEvent.Description,"The description of your event must be 500 characters or less. \n " +
			"Please enter a shorter description and try again.");
   if (!ValidMaxLength(document.AddEvent.Abstract.value,500))
      error(document.AddEvent.Abstract,"The abstract must be 500 characters or less. \n " +
			"Please enter a shorter abstract and try again.");
   if (document.AddEvent.Abstract.value == '' && document.AddEvent.adm.value != 1)
      error(document.AddEvent.Abstract,"You must enter an abstract or description for your event.");
   if (!ValidMaxLength(document.AddEvent.Speaker.value,300))
      error(document.AddEvent.Speaker,"The names of the speaker(s) must be 300 characters or less. \n " +
			"Please enter abbreviated names of the speaker(s) and try again.");
   if (!ValidMaxLength(document.AddEvent.Affiliation.value,300))
      error(document.AddEvent.affiliation,"The affiliation field must be 300 characters or less. \n " +
			"Please enter a shorter affiliation description and try again.");
   if (!ValidMaxLength(document.AddEvent.MoreInformationDescription.value,500))
      error(document.AddEvent.MoreInformationDescription,"The For More Information field must be 500 characters or less.");
   if (document.AddEvent.MoreInformationDescription.value == '')
      error(document.AddEvent.MoreInformationDescription,"You must enter a contact for information about your event.");
   if (!ValidMaxLength(document.AddEvent.URL.value,300))
      error(document.AddEvent.URL,"The web address field must be 300 characters or less. \n " +
			"Please enter a shorter web address for more information and try again.");
   if (!ValidMaxLength(document.AddEvent.Sponsor.value,500))
      error(document.AddEvent.Sponsor,"The sponsor description for your event must be 500 characters or less. \n " +
			"Please enter a shorter description of sponsorship and try again.");
   if (document.AddEvent.LocationID && document.AddEvent.LocationID.length == 0)
   	  error(document.AddEvent.LocationID,"You have no locations available. Either: \nClick the User Information link to set up a custom location outside of UWBC; or " +
			"\nProvide your billing information if you want to schedule a UWBC location.");

	return !errfound; /* true if there are no errors */
}


function validAddEventPage2() {
   errfound = false;

   if (!ValidMaxLength(document.AddEvent.StaffNotes.value,1000))
      error(document.AddEvent.Sponsor,"Staff notes must be 1000 characters or less. \n " +
			"Please shorten this and try again.");

	return !errfound; /* true if there are no errors */
}



/*********************************************
*  			FUNCTION validDelete....		 *
*  Functions to ask "are you sure?" 	 	 *
*											 *
*********************************************/

function validDeleteEvent() {
  if(confirm("Are you sure you want to delete this event?"))
    document.AddEvent.submit;
  else
    return false;
}

function validDeleteAllEvents() {
  if(confirm("Are you sure you want to delete all occurences of this event?"))
    document.AddEvent.submit;
  else
    return false;
}


/*********************************************
*  			FUNCTIONs GoBack...				 *
*  Functions to drive "go back" buttons on 	 *
*  forms									 *
*											 *
*********************************************/

function GoBackAdd1() {
  document.AddEvent.action = "calendar.asp?page=add1";
  document.AddEvent.submit;
}

function GoBackAdd2() {
  document.AddEvent.action = "calendar.asp?page=add2";
  document.AddEvent.submit;
}

function GoBackEdit1() {
  document.EditEvent.action = "calendar.asp?page=edit1";
  document.EditEvent.submit;
}

function GoBackEdit2() {
  document.EditEvent.action = "calendar.asp?page=edit2";
  document.EditEvent.submit;
}


/*********************************************
*  			FUNCTION validRegisterPart1		 *
*  Takes input from registration form		 *
*  Tests:									 *
*											 *
*********************************************/

function validRegisterPart1() {
   errfound = false;
   //test that all fields have values
   if (!ValidLength(document.RegisterForm.FirstName.value,1))
      error(document.RegisterForm.FirstName,"Please enter your first name!");
   if (!ValidLength(document.RegisterForm.LastName.value,1))
      error(document.RegisterForm.LastName,"Please enter your last name!");
   if (!ValidLength(document.RegisterForm.EmailAddress.value,1))
      error(document.RegisterForm.EmailAddress,"Please enter your email address!");
   if (!ValidLength(document.RegisterForm.Password.value,1))
      error(document.RegisterForm.Password,"Please enter a password!");
   if (!ValidLength(document.RegisterForm.ConfirmPassword.value,1))
      error(document.RegisterForm.ConfirmPassword,"Please confirm your password!");
	  
  //test for maximum lengths in fields
   if (!ValidMaxLength(document.RegisterForm.FirstName.value,50))
      error(document.RegisterForm.FirstName,"Name fields are limited to no more than 50 characters. \n " +
			"Please enter an abbreviated first name and try again.");
  if (!ValidMaxLength(document.RegisterForm.LastName.value,50))
      error(document.RegisterForm.LastName,"Name fields are limited to no more than 50 characters. \n " +
			"Please enter an abbreviated last name and try again.");
  if (!ValidMaxLength(document.RegisterForm.EmailAddress.value,100))
      error(document.RegisterForm.EmailAddress,"Email addresses are limited to no more than 100 characters. \n " +
			"Please enter a shorter email address and try again.");
  if (!ValidMaxLength(document.RegisterForm.Password.value,20))
      error(document.RegisterForm.Password,"Name fields are limited to no more than 255 characters. \n " +
			"Please enter an abbreviated last name and try again.");

  //test for password matching confirmed password
  if (!PasswordMatch(document.RegisterForm.Password.value,document.RegisterForm.ConfirmPassword.value))
      error(document.RegisterForm.ConfirmPassword,"Your passwords do not match. " +
			"Please verify that the passwords you entered match and try again.");

  //test for valid email address
  if (!ValidEmail(document.RegisterForm.EmailAddress.value))
      error(document.RegisterForm.EmailAddress,"The email address you entered does not appear to be valid. \n " +
			"Please re-enter your email address and try again.");

   return !errfound; /* true if there are no errors */
}


/*********************************************
*  			FUNCTION validRegisterPart2		 *
*  Takes input from registration form		 *
*  Tests:									 *
*											 *
*********************************************/

function validRegisterPart2() {
   errfound = false;
   
   //test for valid phone and fax (only numbers)
  if (!ValidNumber(document.RegisterForm.Phone1.value))
      error(document.RegisterForm.Phone1,"Plesae enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");
  if (!ValidNumber(document.RegisterForm.Phone2.value))
      error(document.RegisterForm.Phone2,"Plesae enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");
  if (!ValidNumber(document.RegisterForm.Fax.value))
      error(document.RegisterForm.Fax,"Plesae enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");

  //test for valid max lengths
   if (!ValidMaxLength(document.RegisterForm.DepartmentName.value,255))
      error(document.RegisterForm.DepartmentName,"The department name field is limited to 255 characters. \n " +
			"Please enter an abbreviated department name and try again.");

  //magic number used for intExternalUserTypeID, 3

   //test for company name entered
   if (!ValidLength(document.RegisterForm.CompanyName.value,1))
      error(document.RegisterForm.CompanyName,"Please enter a company name!");
  if (document.RegisterForm.UserTypeID.value == 3) {
    if (!ValidMaxLength(document.RegisterForm.CompanyName.value,255))
       error(document.RegisterForm.CompanyName,"The company name field is limited to 255 characters. \n " +
	 		"Please enter an abbreviated company name and try again.");

    if (!ValidMaxLength(document.RegisterForm.CompanyURL.value,255))
       error(document.RegisterForm.CompanyURL,"The company URL field is limited to 255 characters. \n " +
	 		"Please enter an abbreviated company URL and try again.");
	}

  //magic number used for intInternalPIsUserTypeID, 1
  if (document.RegisterForm.UserTypeID.value == 1) {
    if (!ValidMaxLength(document.RegisterForm.DepartmentURL.value,255))
       error(document.RegisterForm.DepartmentURL,"The department URL field is limited to 255 characters.");
	}

   if (!ValidMaxLength(document.RegisterForm.Address1.value,255))
      error(document.RegisterForm.Address1,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated address and try again.");
   if (!ValidMaxLength(document.RegisterForm.Address2.value,255))
      error(document.RegisterForm.Address2,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated address and try again.");
   if (!ValidMaxLength(document.RegisterForm.City.value,255))
      error(document.RegisterForm.City,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated city name and try again.");
   if (!ValidMaxLength(document.RegisterForm.State.value,2))
      error(document.RegisterForm.State,"The state field must be entered as a two character abbreviation.");
   if (!ValidMaxLength(document.RegisterForm.ZipCode.value,10))
      error(document.RegisterForm.ZipCode,"The zip code field is limited to 10 characters or less.");
 
   return !errfound; /* true if there are no errors */
}


/*********************************************
*  			FUNCTION validLogon				 *
*  Takes input from logon form				 *
*  Tests:									 *
*  	> 0 characters in email address/password *
*	@ character in email address			 *
*											 *
*********************************************/

//test for valid data in logon
function validLogon() {
  errfound = false;

  //you did actually enter an email address and password, didn't you?
  if (!ValidLength(document.LogonForm.EmailAddressLogon.value,1))
    error(document.LogonForm.EmailAddressLogon,"Please enter your email address!");
  if (!ValidLength(document.LogonForm.PasswordLogon.value,1))
    error(document.LogonForm.PasswordLogon,"Please enter a password!");

  //test for valid email address
  if (!ValidEmail(document.LogonForm.EmailAddressLogon.value))
    error(document.LogonForm.EmailAddressLogon,"The email address you entered does not appear to be valid. \n " +
		"Please re-enter your email address and try again.");

  return !errfound; /* true if there are no errors */

}





/*********************************************
*  			FUNCTION validUserDetails		 *
*  Validate user details					 *
*											 *
*********************************************/

function validUserDetails() {
   errfound = false;

   if (!ValidLength(document.UpdateUserDetails.FirstName.value,1))
      error(document.UpdateUserDetails.FirstName,"Please enter your first name!");
   if (!ValidLength(document.UpdateUserDetails.LastName.value,1))
      error(document.UpdateUserDetails.LastName,"Please enter your last name!");
   if (!ValidLength(document.UpdateUserDetails.EmailAddress.value,1))
      error(document.UpdateUserDetails.EmailAddress,"Please enter your email address!");

   if (!ValidMaxLength(document.UpdateUserDetails.FirstName.value,50))
      error(document.UpdateUserDetails.FirstName,"Name fields are limited to no more than 50 characters. \n " +
			"Please enter an abbreviated first name and try again.");
  if (!ValidMaxLength(document.UpdateUserDetails.LastName.value,50))
      error(document.UpdateUserDetails.LastName,"Name fields are limited to no more than 50 characters. \n " +
			"Please enter an abbreviated last name and try again.");
  if (!ValidMaxLength(document.UpdateUserDetails.EmailAddress.value,100))
      error(document.UpdateUserDetails.EmailAddress,"Email addresses are limited to no more than 100 characters. \n " +
			"Please enter a shorter email address and try again.");

  //test for password matching confirmed password
  if (!PasswordMatch(document.UpdateUserDetails.Password.value,document.UpdateUserDetails.ConfirmPassword.value))
      error(document.UpdateUserDetails.ConfirmPassword,"Your passwords do not match. " +
			"Please verify that the passwords you entered match and try again.");

  //test for valid email address
  if (!ValidEmail(document.UpdateUserDetails.EmailAddress.value))
      error(document.UpdateUserDetails.EmailAddress,"The email address you entered does not appear to be valid. \n " +
			"Please re-enter your email address and try again.");

  //test for valid phone and fax (only numbers)
  if (!ValidNumber(document.UpdateUserDetails.Phone1.value))
      error(document.UpdateUserDetails.Phone1,"Please enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");
  if (!ValidNumber(document.UpdateUserDetails.Phone2.value))
      error(document.UpdateUserDetails.Phone2,"Please enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");
  if (!ValidNumber(document.UpdateUserDetails.Fax.value))
      error(document.UpdateUserDetails.Fax,"Please enter only numbers in the phone and fax fields. \n" +
	  			"Do not enter dashes or other punctuation.");

  //magic number used for intExternalUserTypeID, 3
  if (document.UpdateUserDetails.UserTypeID.value == 3) {
    //test for company name entered
    if (!ValidLength(document.UpdateUserDetails.CompanyName.value,1))
      error(document.UpdateUserDetails.CompanyName,"Please enter a company name!");

    if (!ValidMaxLength(document.UpdateUserDetails.CompanyName.value,255))
       error(document.UpdateUserDetails.CompanyName,"The company name field is limited to 255 characters. \n " +
	 		"Please enter an abbreviated company name and try again.");

    if (!ValidMaxLength(document.UpdateUserDetails.CompanyURL.value,255))
       error(document.UpdateUserDetails.CompanyURL,"The company URL field is limited to 255 characters. \n " +
	 		"Please enter an abbreviated company URL and try again.");
	}

  //magic number used for intInternalPIsUserTypeID, 1
  if (document.UpdateUserDetails.UserTypeID.value == 1) {
    if (!ValidMaxLength(document.UpdateUserDetails.DepartmentURL.value,255))
       error(document.UpdateUserDetails.DepartmentURL,"The department URL field is limited to 255 characters.");
	}

   if (!ValidMaxLength(document.UpdateUserDetails.Address1.value,255))
      error(document.UpdateUserDetails.Address1,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated address and try again.");
   if (!ValidMaxLength(document.UpdateUserDetails.Address2.value,255))
      error(document.UpdateUserDetails.Address2,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated address and try again.");
   if (!ValidMaxLength(document.UpdateUserDetails.City.value,255))
      error(document.UpdateUserDetails.City,"Address fields are limited to 255 characters. \n " +
			"Please enter an abbreviated city name and try again.");
   if (!ValidMaxLength(document.UpdateUserDetails.State.value,2))
      error(document.UpdateUserDetails.State,"The state field must be entered as a two character abbreviation.");
   if (!ValidMaxLength(document.UpdateUserDetails.ZipCode.value,10))
      error(document.UpdateUserDetails.ZipCode,"The zip code field is limited to 10 characters or less.");
 
   return !errfound; /* true if there are no errors */
}


/********************************************
*  			FUNCTION validAddLocation		*
*  Function to validate input from 			*
*  AddLocation form.						*
*											*
********************************************/

function validAddLocation() {
   errfound = false;

   //test that all fields have values
   if (!ValidLength(document.AddLocation.LocationName.value,1))
      error(document.AddLocation.LocationName,"Please enter a name for this location!");

   return !errfound; /* true if there are no errors */
}

/********************************************
*			FUNCTION hideAddFields			*
*	Function to hide fields in the Add		*
*	Event form if another user has been 	*
*	selected using "Add Event As".			*
*											*
********************************************/

function hideAddFields() {
//  document.AddEvent.Title.style.visibility = "collapse";
//  document.getElementById("tdFormHeader").style.visibility = "collapse";
}

function showStreamIfAud(referer) {
	var obj = document.getElementById("stream")
	if (referer.value == '1-True') {
		obj.style.visibility = "visible"
		obj.style.height = "auto"
	} else {
		obj.style.visibility = "hidden"
		obj.style.height = "0"
	}
}

//-->