// BEGINNING OF FILE
// Copyright © McDonagh Brothers
// Script by: Peter S. Anderson

/*
**************************************************************
Function Index:
	winOpen(p,n,w,h,a)
	CheckUnCheck(iVal)
	isDate(dateStr)
	testEmail(email)

Revisions:
	Created:	06/02/2004	PSA
	
**************************************************************
*/

// Clears the Error Display for the form created by [InformeDesign.AccountForm.ascx]
function clearRegisterErrors(f)
{
	var txtFirstname = document.getElementById('MemberInfo1_txtFirstname');
	var txtLastname = document.getElementById('MemberInfo1_txtLastname');
	var txtEmail = document.getElementById('MemberInfo1_txtEmail');
	
	var drpOccupation = document.getElementById('drpOccupation');
	var txtOtherOccupation = document.getElementById('txtOtherOccupation');
	
	var chkActive = document.getElementById('chkActive');
	
	if (txtFirstname)
	{
		document.getElementById("divFirstNameStar").style.display = "none";
	}
	if (txtLastname)
	{
		document.getElementById("divLastNameStar").style.display = "none";
	}
	if (txtEmail)
	{
		document.getElementById("divEmailStar").style.display = "none";
	}
	if (chkActive)
	{
		document.getElementById("divActiveStar").style.display = "none";
	}
	if (f.tId)
	{
		document.getElementById("divTaxonomyStar").style.display = "none";
	}
}

// Submits and Validates the form created by [InformeDesign.AccountForm.ascx]
// Code also referenced in [InformeDesign.Controls.TaxonomyCheckboxList.cs]
function submitRegisterForm(f)
{
	clearRegisterErrors(f);
	var status = true;
	var sError = "<UL>";
	
	var txtFirstname = document.getElementById('MemberInfo1_txtFirstname');
	var txtLastname = document.getElementById('MemberInfo1_txtLastname');
	var txtEmail = document.getElementById('MemberInfo1_txtEmail');
	
	var drpOccupation = document.getElementById('drpOccupation');
	var txtOtherOccupation = document.getElementById('txtOtherOccupation');
	
	var chkActive = document.getElementById('chkActive');
	
	if (txtFirstname)
	{
		if (txtFirstname.value == "")
		{
			sError += "<LI>[First Name] is required</LI>";
			document.getElementById("divFirstNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtLastname)
	{
		if (txtLastname.value == "")
		{
			sError += "<LI>[Last Name] is required</LI>";
			document.getElementById("divLastNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtEmail)
	{
		if (txtEmail.value == "")
		{
			sError += "<LI>[Email Address] is required</LI>";
			document.getElementById("divEmailStar").style.display = "block";
			status = false;
		}
		else
		{
			if (!testEmail(txtEmail.value))
			{
				sError += "<LI>[Email Address] is not a valid email address</LI>";
				document.getElementById("divEmailStar").style.display = "block";
				status = false;
			}
		}
	}
	// drpOccupation is not required
	if (drpOccupation)
	{
		if (drpOccupation.value == "-1")
		{
			if (txtOtherOccupation)
			{
				if (drpOccupation.value == "")
				{
					sError += "<LI>Please write in an Occupation if you chose \"Other\" from the list.</LI>";
					document.getElementById("divOccupationStar").style.display = "block";
					status = false;
				}
			}
		}
	}
	// txtOtherOccupation is not required
	// drpYearsOfExperience is not required
	// cblAffiliations is not required
	if (chkActive)
	{
		if (!chkActive.checked)
		{
			sError += "<LI>Please check \"Yes\" to agree with our terms and conditions of use.</LI>";
			document.getElementById("divActiveStar").style.display = "block";
			status = false;
		}
	}
	if (f.tId)
	{
		if (f.tId.value == "")
		{
			sError += "<LI>Please choose at least one topic of interest</LI>";
			document.getElementById("divTaxonomyStar").style.display = "block";
			status = false;
		}
	}
	
	sError += "</UL>";
	if (!status)
	{
		document.getElementById('divErrorSummary').innerHTML = sError;
		document.getElementById('divErrorSummary').style.display = "block";
	}
	return status;
}


// Clears the Error Display for the form created by [InformeDesign.Email.aspx]
function clearEmailErrors(f)
{
	var txtRecipientName = document.getElementById('txtRecipientName');
	var txtRecipientEmail = document.getElementById('txtRecipientEmail');
	var txtSenderName = document.getElementById('txtSenderName');
	var txtSenderEmail = document.getElementById('txtSenderEmail');
	var txtMessage = document.getElementById('txtMessage');
	
	if (txtRecipientName)
	{
		document.getElementById("divRecipientNameStar").style.display = "none";
	}
	if (txtRecipientEmail)
	{
		document.getElementById("divRecipientEmailStar").style.display = "none";
	}
	if (txtSenderName)
	{
		document.getElementById("divSenderNameStar").style.display = "none";
	}
	if (txtSenderEmail)
	{
		document.getElementById("divSenderEmailStar").style.display = "none";
	}
	if (txtMessage)
	{
		document.getElementById("divMessageStar").style.display = "none";
	}
}

// Submits and Validates the form created by [InformeDesign.AccountForm.ascx]
// Code also referenced in [InformeDesign.Controls.TaxonomyCheckboxList.cs]
function submitEmailForm(f)
{
	clearEmailErrors(f);
	var status = true;
	var sError = "<UL>";

	var txtRecipientName = document.getElementById('txtRecipientName');
	var txtRecipientEmail = document.getElementById('txtRecipientEmail');
	var txtSenderName = document.getElementById('txtSenderName');
	var txtSenderEmail = document.getElementById('txtSenderEmail');
	var txtMessage = document.getElementById('txtMessage');
	
	if (txtRecipientName)
	{
		if (txtRecipientName.value == "")
		{
			sError += "<LI>[Recipient Name] is required</LI>";
			document.getElementById("divRecipientNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtRecipientEmail)
	{
		if (txtRecipientEmail.value == "")
		{
			sError += "<LI>[Recipient E-mail] is required</LI>";
			document.getElementById("divRecipientEmailStar").style.display = "block";
			status = false;
		}
		else
		{
			if (!testEmail(txtRecipientEmail.value))
			{
				sError += "<LI>[Recipient E-mail] is not a valid email address</LI>";
				document.getElementById("divRecipientEmailStar").style.display = "block";
				status = false;
			}
		}
	}
	if (txtSenderName)
	{
		if (txtSenderName.value == "")
		{
			sError += "<LI>[Your Name] is required</LI>";
			document.getElementById("divSenderNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtSenderEmail)
	{
		if (txtSenderEmail.value == "")
		{
			sError += "<LI>[Your E-mail Address] is required</LI>";
			document.getElementById("divSenderEmailStar").style.display = "block";
			status = false;
		}
		else
		{
			if (!testEmail(txtSenderEmail.value))
			{
				sError += "<LI>[Your E-mail Address] is not a valid email address</LI>";
				document.getElementById("divSenderEmailStar").style.display = "block";
				status = false;
			}
		}
	}
	if (txtMessage)
	{
		if (txtMessage.value == "")
		{
			sError += "<LI>[Message] is required</LI>";
			document.getElementById("divMessageStar").style.display = "block";
			status = false;
		}
	}
	
	sError += "</UL>";
	if (!status)
	{
		document.getElementById('divErrorSummary').innerHTML = sError;
		document.getElementById('divErrorSummary').style.display = "block";
	}
	return status;
}

// Checks passed value for proper Email address format
function testEmail(email) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(email);
}

// Clears the Error Display for the form created by [InformeDesign.PasswordChange.aspx]
function clearPasswordChangeErrors(f)
{
	var txtOldPassword = document.getElementById('txtOldPassword');
	var txtPassword = document.getElementById('txtPassword');
	var txtNewPassword = document.getElementById('txtNewPassword');
	var txtNewPasswordConfirm = document.getElementById('txtNewPasswordConfirm');
	
	if (txtPassword)
	{
		document.getElementById("divPasswordStar").style.display = "none";
	}
	if (txtNewPassword)
	{
		document.getElementById("divNewPasswordStar").style.display = "none";
	}
	if (txtNewPasswordConfirm)
	{
		document.getElementById("divNewPasswordConfirmStar").style.display = "none";
	}
}

// Submits and Validates the form created by [InformeDesign.AccountForm.ascx]
// Code also referenced in [InformeDesign.Controls.TaxonomyCheckboxList.cs]
function submitPasswordChangeForm(f)
{
	clearPasswordChangeErrors(f);
	var status = true;
	var sError = "<UL>";
	
	var txtOldPassword = document.getElementById('txtOldPassword');
	var txtPassword = document.getElementById('txtPassword');
	var txtNewPassword = document.getElementById('txtNewPassword');
	var txtNewPasswordConfirm = document.getElementById('txtNewPasswordConfirm');
	
	if (txtPassword)
	{
		if (txtPassword.value == "")
		{
			sError += "<LI>[Password] is required</LI>";
			document.getElementById("divPasswordStar").style.display = "block";
			status = false;
		}
		else
		{
			if (txtOldPassword)
			{
				if (txtPassword.value != txtOldPassword.value)
				{
					sError += "<LI>[Password] entered is incorrect</LI>";
					document.getElementById("divPasswordStar").style.display = "block";
					status = false;
				}
			}
		}
	}
	if (txtNewPassword)
	{
		if (txtNewPassword.value == "")
		{
			sError += "<LI>[New Password] is required</LI>";
			document.getElementById("divNewPasswordStar").style.display = "block";
			status = false;
		}
	}
	if (txtNewPasswordConfirm)
	{
		if (txtNewPasswordConfirm.value == "")
		{
			sError += "<LI>[Confirm New Password] is required</LI>";
			document.getElementById("divNewPasswordConfirmStar").style.display = "block";
			status = false;
		}
		else
		{
			if (txtNewPassword.value != txtNewPasswordConfirm.value)
			{
				sError += "<LI>[New Password] and [Confirm New Password] must be identical</LI>";
				document.getElementById("divNewPasswordConfirmStar").style.display = "block";
				status = false;
			}
		}
	}
	
	sError += "</UL>";
	if (!status)
	{
		document.getElementById('divErrorSummary').innerHTML = sError;
		document.getElementById('divErrorSummary').style.display = "block";
	}
	return status;
}

function clearStudentFormErrors(f)
{
	var txtFullName = document.getElementById('txtFullName');
	var txtCollege = document.getElementById('txtCollege');
	var txtEmail = document.getElementById('txtEmail');
	var txtMajor = document.getElementById('txtMajor');
	var txtGradDate = document.getElementById('txtGradDate');
	
	if (txtFullName)
	{
		document.getElementById("divFullNameStar").style.display = "none";
	}
	if (txtCollege)
	{
		document.getElementById("divCollegeStar").style.display = "none";
	}
	if (txtEmail)
	{
		document.getElementById("divEmailStar").style.display = "none";
	}
	if (txtMajor)
	{
		document.getElementById("divMajorStar").style.display = "none";
	}
	if (txtGradDate)
	{
		document.getElementById("divGradDateStar").style.display = "none";
	}
}

function submitStudentForm(f)
{
	clearStudentFormErrors(f);
	var status = true;
	var sError = "<UL>";
	
	var txtFullName = document.getElementById('txtFullName');
	var txtCollege = document.getElementById('txtCollege');
	var txtEmail = document.getElementById('txtEmail');
	var txtMajor = document.getElementById('txtMajor');
	var txtGradDate = document.getElementById('txtGradDate');
	
	if (txtFullName)
	{
		if (txtFullName.value == "")
		{
			sError += "<LI>[Full Legal Name] is required</LI>";
			document.getElementById("divFullNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtCollege)
	{
		if (txtCollege.value == "")
		{
			sError += "<LI>[University/College] is required</LI>";
			document.getElementById("divCollegeStar").style.display = "block";
			status = false;
		}
	}
	if (txtEmail)
	{
		if (txtEmail.value == "")
		{
			sError += "<LI>[Student Email Address] is required</LI>";
			document.getElementById("divEmailStar").style.display = "block";
			status = false;
		}
		else
		{
			if (!testEmail(txtEmail.value))
			{
				sError += "<LI>[Student Email Address] is not a valid email address</LI>";
				document.getElementById("divEmailStar").style.display = "block";
				status = false;
			}
		}
	}
	if (txtMajor)
	{
		if (txtMajor.value == "")
		{
			sError += "<LI>[Major] is required</LI>";
			document.getElementById("divMajorStar").style.display = "block";
			status = false;
		}
	}
	if (txtGradDate)
	{
		if (txtGradDate.value == "")
		{
			sError += "<LI>[Estimated date of graduation] is required</LI>";
			document.getElementById("divGradDateStar").style.display = "block";
			status = false;
		}
	}
	
	sError += "</UL>";
	if (!status)
	{
		document.getElementById('divErrorSummary').innerHTML = sError;
		document.getElementById('divErrorSummary').style.display = "block";
	}
	return status;
}

function clearUofMFormErrors(f)
{
	var txtFullName = document.getElementById('txtFullName');
	var txtCollege = document.getElementById('txtCollege');
	var txtEmail = document.getElementById('txtEmail');
	
	if (txtFullName)
	{
		document.getElementById("divFullNameStar").style.display = "none";
	}
	if (txtCollege)
	{
		document.getElementById("divCollegeStar").style.display = "none";
	}
	if (txtEmail)
	{
		document.getElementById("divEmailStar").style.display = "none";
	}
}

function submitUofMForm(f)
{
	clearUofMFormErrors(f);
	var status = true;
	var sError = "<UL>";
	
	var txtFullName = document.getElementById('txtFullName');
	var txtCollege = document.getElementById('txtCollege');
	var txtEmail = document.getElementById('txtEmail');
	
	if (txtFullName)
	{
		if (txtFullName.value == "")
		{
			sError += "<LI>[Full Legal Name] is required</LI>";
			document.getElementById("divFullNameStar").style.display = "block";
			status = false;
		}
	}
	if (txtCollege)
	{
		if (txtCollege.value == "")
		{
			sError += "<LI>[University/College] is required</LI>";
			document.getElementById("divCollegeStar").style.display = "block";
			status = false;
		}
	}
	if (txtEmail)
	{
		if (txtEmail.value == "")
		{
			sError += "<LI>[Student Email Address] is required</LI>";
			document.getElementById("divEmailStar").style.display = "block";
			status = false;
		}
		else
		{
			if (!testEmail(txtEmail.value))
			{
				sError += "<LI>[Student Email Address] is not a valid email address</LI>";
				document.getElementById("divEmailStar").style.display = "block";
				status = false;
			}
		}
	}
	
	sError += "</UL>";
	if (!status)
	{
		document.getElementById('divErrorSummary').innerHTML = sError;
		document.getElementById('divErrorSummary').style.display = "block";
	}
	return status;
}

function IsOkToMarkSch()
{
	var obj = document.frmSearch.txtHidMarked;
	var obj2 = document.frmSearch.chkShowMe;
	if (obj && obj2)
	{
		var val = obj.value;
		var len = val.length;
		var max = obj2.length;
		var msg = "";
		var boo = false;
		//alert("val = " + val + "\n len = " + len + "\n max = " + max + "\n");
		if (len == 0) // There's nothing in the box, but did they check something?
		{
			if (max > 1)
			{
				for (var i = 0; i < max; i++)
				{
					if (eval("document.frmSearch.chkShowMe[" + i + "].checked") == true)
					{
						boo = true;
					}
				}
				if (!boo)
				{
					msg = "Please choose at least one Research Summary to mark before clicking 'View Marked'";
				}
			}
			else
			{
				if (document.frmSearch.chkShowMe.checked)
				{
					boo = true;
				}
				else
				{
					msg = "Please choose at least one Research Summary to mark before clicking 'View Marked'";
				}
			}
			
		}
		else // There's something in the box... move along.
		{
			boo = true;
		}
		if (!boo)
		{
			alert(msg);
		}
		return boo;
	}
}

function IsOkToMark()
{
	var obj = document.frmRs.txtHidMarked;
	var obj2 = document.frmRs.chkShowMe;
	if (obj && obj2)
	{
		var val = obj.value;
		var len = val.length;
		var max = obj2.length;
		var msg = "";
		var boo = false;
		//alert("val = " + val + "\n len = " + len + "\n max = " + max + "\n");
		if (len == 0) // There's nothing in the box, but did they check something?
		{
			if (max > 1)
			{
				for (var i = 0; i < max; i++)
				{
					if (eval("document.frmRs.chkShowMe[" + i + "].checked") == true)
					{
						boo = true;
					}
				}
				if (!boo)
				{
					msg = "Please choose at least one Research Summary to mark before clicking 'View Marked'";
				}
			}
			else
			{
				if (document.frmRs.chkShowMe.checked)
				{
					boo = true;
				}
				else
				{
					msg = "Please choose at least one Research Summary to mark before clicking 'View Marked'";
				}
			}
			
		}
		else // There's something in the box... move along.
		{
			boo = true;
		}
		if (!boo)
		{
			alert(msg);
		}
		return boo;
	}
}
