function isValidEmail($str)
{
	filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
	if (filter.test($str)) {
		return true;
	}
	return false;
}

function ValidateConference(form)
{
	$cYear = form.cYear.value;
	$cFacSingleFee = form.cFacSingleFee.value;
	$cFacDoubleFee= form.cFacDoubleFee.value;
	$cStudSingleFee = form.cStudSingleFee.value;
	$cStudDoubleFee = form.cStudDoubleFee.value;
	$cEarlySchoolFee = form.cEarlySchoolFee.value;
	$cRegularSchoolFee = form.cRegularSchoolFee.value;
	$cLateSchoolFee = form.cLateSchoolFee.value;
	
	if (!$cYear)
	{
		alert("Please enter the conference Year.");
		form.cYear.focus();
		return false;
	}
	if (!$cFacSingleFee)
	{
		alert("Please enter the faculty single room Fee.");
		form.cFacSingleFee.focus();
		return false;
	}
	if (!$cFacDoubleFee)
	{
		alert("Please enter the faculty double room Fee.");
		form.cFacDoubleFee.focus();
		return false;
	}
	if (!$cStudSingleFee)
	{
		alert("Please enter the student single room Fee.");
		form.cStudSingleFee.focus();
		return false;
	}
	if (!$cStudDoubleFee)
	{
		alert("Please enter the student double room Fee.");
		form.cStudDoubleFee.focus();
		return false;
	}
	if (!$cEarlySchoolFee)
	{
		alert("Please enter the early registration Fee.");
		form.cEarlySchoolFee.focus();
		return false;
	}
	if (!$cRegularSchoolFee)
	{
		alert("Please enter the regular registration Fee.");
		form.cRegularSchoolFee.focus();
		return false;
	}
	if (!$cLateSchoolFee)
	{
		alert("Please enter the late registration Fee.");
		form.cLateSchoolFee.focus();
		return false;
	}
	return true;
}

function ValidateStaff(form)
{
	$sFName = form.sFName.value;
	$sLName = form.sLName.value;
	$sEmail = form.sEmail.value;
	$sPassword = form.sPassword.value;
	$sPassword2 = form.sPassword2.value;
	$sPosition = form.sPosition.value;
	
	if (!$sFName)
	{
		alert("Please enter the staff First Name.");
		form.sFName.focus();
		return false;
	}
	if (!$sLName)
	{
		alert("Please enter the staff Last Name.");
		form.sLName.focus();
		return false;
	}
	if (!$sEmail)
	{
		alert("Please enter the staff Email address.");
		form.sEmail.focus();
		return false;
	}
	if (!isValidEmail($sEmail))
	{
		alert("Please enter a valid Email address.");
		form.sEmail.select();
		return false;
	}
	if (!$sPassword)
	{
		alert("Please enter the staff Password.");
		form.sPassword.focus();
		return false;
	}
	if (!$sPassword2)
	{
		alert("Please confirm the staff Password.");
		form.sPassword2.focus();
		return false;
	}
	if ($sPassword != $sPassword2)
	{
		alert("The passwords do not match. Please confirm that you have entered the right password.");
		form.sPassword.select();
		return false;
	}
	if (!$sPosition)
	{
		alert("Please enter the staff Position.");
		form.sPosition.focus();
		return false;
	}
	return true;
}

function ValidateDelegate(form)
{
	$dFName = form.dFName.value;
	$dLName = form.dLName.value;
	$dPreference1 = form.dPreference1.value;
	$dPreference2 = form.dPreference2.value;
	$dPreference3 = form.dPreference3.value;
	
	if (!$dFName)
	{
		alert("Please enter the delegate's First Name.");
		form.dFName.focus();
		return false;
	}
	if (!$dLName)
	{
		alert("Please enter the delegate's Last Name.");
		form.dLName.focus();
		return false;
	}
	if (($dPreference1 == $dPreference2) || ($dPreference1 == $dPreference3) || (($dPreference2 == $dPreference3)))
	{
		alert("The delegate's three preferred programs must be different.");
		form.dPreference1.focus();
		return false;
	}
	return true;
}

function ValidateDelegation(form, $regr)
{
	$delName = form.delName.value;
	$delAddress = form.delAddress.value;
	$delNumDelegates = form.delNumDelegates.value;
	$aName = form.aName.value;
	$aEmail = form.aEmail.value;
	$aEmail2 = form.aEmail2.value;
	
	if ($regr)
	{
		$aPassword = form.aPassword.value;
		$aPassword2 = form.aPassword2.value;
	}
	
	if (!$delName)
	{
		alert("Please enter the School Name.");
		form.delName.focus();
		return false;
	}
	if (!$delAddress)
	{
		alert("Please enter the School Address.");
		form.delAddress.focus();
		return false;
	}
	if (!$delNumDelegates)
	{
		alert("Please enter the expected number of delegates.");
		form.delNumDelegates.focus();
		return false;
	}
	if (!$aName)
	{
		alert("Please enter the Faculty Advisor Name.");
		form.aName.focus();
		return false;
	}
	if (!$aEmail)
	{
		alert("Please enter the Faculty Advisor Email address.");
		form.aEmail.focus();
		return false;
	}
	if (!isValidEmail($aEmail))
	{
		alert("Please enter a valid Email address.");
		form.aEmail.select();
		return false;
	}
	if (!$aEmail2)
	{
		alert("Please enter the Confirm Faculty Advisor Email address.");
		form.aEmail2.focus();
		return false;
	}
	if (!isValidEmail($aEmail2))
	{
		alert("Please enter a valid Confirm Email address.");
		form.aEmail2.select();
		return false;
	}
	if ($aEmail != $aEmail2)
	{
		alert("The Emails do not match. Please confirm that you have entered the right Email.");
		form.aEmail.select();
		return false;
	}
	if ($regr)
	{
		if (!$aPassword)
		{
			alert("Please enter the Faculty Advisor Password.");
			form.aPassword.focus();
			return false;
		}
		if (!$aPassword2)
		{
			alert("Please confirm the Faculty Advisor Password.");
			form.aPassword2.focus();
			return false;
		}
		if ($aPassword != $aPassword2)
		{
			alert("The passwords do not match. Please confirm that you have entered the right password.");
			form.aPassword.select();
			return false;
		}
	}
	return true;
}

function ValidateAnnouncement(form)
{
	$aTitle = form.aTitle.value;
	$aText = form.aText.value;
	
	if (!$aTitle)
	{
		alert("Please the Announcement Title.");
		form.aTitle.focus();
		return false;
	}
	if (!$aText)
	{
		alert("Please the Announcement Text.");
		form.aText.focus();
		return false;
	}
	return true;
}

function ValidateLink(form)
{
	$lName = form.lName.value;
	$lURL = form.lURL.value;
	
	if (!$lName)
	{
		alert("Please enter the Link Name.");
		form.lName.focus();
		return false;
	}
	if (!$lURL)
	{
		alert("Please enter the Link URL.");
		form.lURL.focus();
		return false;
	}
	return true;
}

function ValidateSubscriber(form)
{
	$lsName = form.lsName.value;
	$lsEmail = form.lsEmail.value;
	
	if (!$lsName)
	{
		alert("Please enter the Name.");
		form.lsName.focus();
		return false;
	}
	if (!$lsEmail)
	{
		alert("Please enter the Email Address.");
		form.lsEmail.focus();
		return false;
	}
	if (!isValidEmail($lsEmail))
	{
		alert("Please enter a valid Email address.");
		form.lsEmail.select();
		return false;
	}
	return true;
}

function ValidateProgram(form)
{
	$pName = form.pName.value;
	$pDescription = form.pDescription.value;
	
	if (!$pName)
	{
		alert("Please enter the Program Name.");
		form.pName.focus();
		return false;
	}
	if (!$pDescription)
	{
		alert("Please enter the Program Description.");
		form.pDescription.focus();
		return false;
	}
	return true;
}

function ValidateRoom(form)
{
	
	$rArriveDate = form.rArriveDate.value;
	
	$rDepartDate = form.rDepartDate.value;
	
	if (!$rArriveDate)
	{
		alert("Please enter the Arrival Date.");
		form.rArriveDate.focus();
		return false;
	}
	
	if (!$rDepartDate)
	{
		alert("Please enter the Departure Date.");
		form.rDepartDate.focus();
		return false;
	}
	
	
	
	return true;
}

function ValidateMessage(form)
{
	$mTo = form.mTo.value;
	$mSubject = form.mSubject.value;
	$mBody = form.mBody.value;
	
	if (!$mTo)
	{
		alert("Please enter the message Recipients.");
		form.mTo.focus();
		return false;
	}
	if (!$mSubject)
	{
		alert("Please enter message Subject.");
		form.mSubject.focus();
		return false;
	}
	if (!$mBody)
	{
		alert("Please enter the message Text.");
		form.mBody.focus();
		return false;
	}
	return true;
}

function ValidateStaffLogin(form) 
{
	$sEmail = form.sEmail.value;
	$sPassword = form.sPassword.value;
	
	if (!$sEmail)
	{
		alert("Please enter your Username.");
		form.sEmail.focus();
		return false;
	}
	if (!$sPassword)
	{
		alert("Please enter your Password.");
		form.sPassword.focus();
		return false;
	}
	return true;
}

function ValidateAdvisorLogin(form) 
{
	$aEmail = form.aEmail.value;
	$aPassword = form.aPassword.value;
	
	if (!$aEmail)
	{
		alert("Please enter your Username.");
		form.aEmail.focus();
		return false;
	}
	if (!$aPassword)
	{
		alert("Please enter your Password.");
		form.aPassword.focus();
		return false;
	}
	return true;
}

function ValidateChangePassword(form) 
{
	$aPassword = form.aPassword.value;
	$aPassword1 = form.aPassword1.value;
	$aPassword2 = form.aPassword2.value;
	
	if (!$aPassword)
	{
		alert("Please enter your current Password.");
		form.aPassword.focus();
		return false;
	}
	if (!$aPassword1)
	{
		alert("Please enter your new Password.");
		form.aPassword1.focus();
		return false;
	}
	if (!$aPassword2)
	{
		alert("Please confirm your new Password.");
		form.aPassword2.focus();
		return false;
	}
	if ($aPassword1 != $aPassword2)
	{
		alert("Your passwords do not match. Please ensure that you have entered the correct password.");
		form.aPassword1.focus();
		return false;
	}
	return true;
}

function ValidateLoginForget(form) 
{
	$aEmail = form.aEmail.value;
	
	if (!$aEmail)
	{
		alert("Please enter your Email address.");
		form.aEmail.focus();
		return false;
	}
	if (!isValidEmail($aEmail))
	{
		alert("Please enter a valid Email address.");
		form.aEmail.focus();
		return false;
	}
	return true;
}
