// JavaScript Document
function validatemyform(frmCheck, lstInputFields)
{

	var msgAlert = "";
	var i = 0;
	var arrInputFields;
	var totalFields;
	var fieldname;
	var fieldvalue;
	var field;
	var validform = true;
	
	if(testIsValidObject(frmCheck["chkEmailRequestor"]))
		checkEmailSelf(frmCheck);
	
	if (lstInputFields != null)
	{
		arrInputFields = lstInputFields.split(",");
		totalFields = arrInputFields.length;
		
		for (i=0; i<totalFields; i++)
		{
			fieldname = arrInputFields[i];
			f = frmCheck[fieldname];
			switch (f.type.toLowerCase())
			{
				case "text":
					fieldvalue = f.value;
					
					if (fieldvalue == "")
					{
						msgAlert = msgAlert + "\"" + fieldname.replace("_"," ") + "\" is required.\n";
						f.style.backgroundColor = "lightyellow";
						validform = false;		
					}
					else
						f.style.backgroundColor = "";
					break;
				case 'checkbox':
					if (!f.checked)
					{
						msgAlert = msgAlert + "\"" + fieldname.replace("_"," ") + "\" must be checked.\n";
						f.style.backgroundColor = "lightyellow";
						validform = false;		
					}
					else
						f.style.backgroundColor = "";
					break;
			}
				
		}
		
		if (!validform)
			alert(msgAlert);
	}
	
	return validform;
}

function checkEmailSelf(frmCheck)
{
	if(frmCheck["chkEmailRequestor"].checked == 1)
	{
		newEmailList = frmCheck["recipient"].value + ", " + frmCheck["email"].value;
		frmCheck["recipient"].value = newEmailList;
	}
	return;
}

function testIsValidObject(objToTest)
{
	if (null == objToTest)
		return false;
	if ("undefined" == typeof(objToTest) )
		return false;
	return true;
}

function CheckEmailSVSU(email)
{
	if(false == ValidateSVSUemail(email) || false == ValidateEmail(email) )
	{
		document.getElementById("svsu_email_notify").style.border = "1px solid #cba9a9";
		document.getElementById("svsu_email_notify").style.backgroundColor = "#fedcdc";
		document.getElementById("svsu_email_notify").style.width = "175px";
		document.getElementById("svsu_email_notify").style.display = "block";
		document.getElementById("svsu_email_notify").innerHTML = "<b>" + email + "</b><br />is not a valid SVSU e-mail address.";
	}
	else
	{
		document.getElementById("svsu_email_notify").style.border = "1px solid #a9a9cb";
		document.getElementById("svsu_email_notify").style.backgroundColor = "#dcdcfe";
		document.getElementById("svsu_email_notify").innerHTML = "<b>" + email + "</b><br />is a valid SVSU e-mail address.";
	}
}
function ValidateSVSUemail(email)
{
	splitemail = email.split("@");
	emailending = splitemail[1];
	
	if (emailending == "svsu.edu") 
		return true;
	else
		return false;		
}

function ValidateEmail(email)
{
	invalidChars = " /:,;"
	
	if (email == "")
		return false;
	
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1)
			return false;
	}
	
	atPos = email.indexOf("@",1)
	if (atPos == -1)
		return false;
	
	if (email.indexOf("@",atPos+1)!= -1)
		return false;
	
	periodPos = email.indexOf(".", atPos)
	if (periodPos == -1)
		return false;
	
	if (periodPos+3 > email.length)
		return false;
		
	return true;
}
