// AUTHOR:				Jason Noftall
// DATE:				Oct. 16, 2001
// DESCRIPTION:				Validates a string for a valid e-mail address.
// PARAMETERS:				1. strIn = e-mail address to be validated
// RETURNS:				bool, true for valid address...false if otherwise.
function ValidEmail(strIn)
{
	var strEmail = trimString(strIn);			// Trim the e-mail address
	var intLen = strEmail.length;				// Get the length of e-mail
	var intAtCount = countChars(strEmail, "@");		// Count occurences of "@"
	var intAtLoc = strEmail.indexOf("@");			// Find a "@"
	var intDotLoc = strEmail.lastIndexOf(".");		// Find the last "."
	var blnReturn = true;					// Return value
	
	if (intLen == 0)
		// No e-mail address specified...
		blnReturn = false;
	else if (intAtLoc == 0)
		// Ensure the "@" is not the first character in the string...
		blnReturn = false;
	else if (intAtCount > 1)
		// More than 1 "@" symbol found...
		blnReturn = false;
	else if (intDotLoc < intAtLoc)
		// Ensure the last "." is located after the "@"...
		blnReturn = false;

	return blnReturn;
}

// AUTHOR:		Jason Noftall
// DATE:		Oct. 16, 2001
// DESCRIPTION:		Trims any leading/trailing spaces from the incoming string.
// PARAMETERS:		strIn = string that needs to be trimmed
// RETURNS:		String, input string less any leading/trailing spaces.
function trimString(strIn)
{
	var strOut = new String(strIn);						// Return value

	// If there are trailing spaces, instantiate a new
	// String object with the original string less the spaces...
	while (strOut.charAt(strOut.length - 1) == ' ')
	{
		strOut = new String(strOut.substring(0, strOut.length - 1));
	}

	// If there are leading spaces, instantiate a new
	// String object with the original string less the spaces...
	while (strOut.charAt(0) == ' ')
	{
		strOut = new String(strOut.substring(1, strOut.length));
	}

	return strOut;
}

function popWin(page,name,dX,dY) 
{
	//Pop up dynamic sized window
	var ewwin = window.open(page,name,"width="+dX+",height="+dY+",scrollbars=yes,status=no,toolbar=no");
	ewwin.window.focus();
}


function popWinNoScroll(page,name,dX,dY) 
{
	//Pop up dynamic sized window without scrollbars
	var ewwin = window.open(page,name,"width="+dX+",height="+dY+",scrollbars=no,status=no,toolbar=no,border=0");
	ewwin.window.focus();
}


// AUTHOR:		Jason Noftall
// DATE:		Nov. 1, 2001
// DESCRIPTION:		Validates strings to check for certain numeric attributes.
// PARAMETERS:		strIn = string that needs numeric validation
//			intFormat = numeric value indicating the type of
//			validation to perform.
// 			1 = Whole numbers, positive only
// 			2 = Whole numbers, positive and negative
// 			3 = Decimal numbers, positive only
// 			4 = Decimal numbers, positive and negative
// RETURNS:		Boolean, True if valid...False if otherwise.
function ensureNumeric(strIn,intFormat)
{
	blnReturn = false;					// Return value
	strNew = trimString(strIn);				// Trim spaces from input string
	var strChar;						// Get 1 char at a time
	var intDecCount = 0;					// Decimal count

	// intFormat
	// ---------
	// 1 = Whole numbers, positive only
	// 2 = Whole numbers, positive and negative
	// 3 = Decimal numbers, positive only
	// 4 = Decimal numbers, positive and negative

	for (var i=0; i < strNew.length; i++)
	{
		// Get 1 char at a time...
		strChar = strNew.substring(i,i+1);

		switch (intFormat)
		{
			case 1:
			{
				// whole positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 1:

			case 2:
			{
				// whole positive or negative numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case "-":
						if (i == 0)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 2:

			case 3:
			{
				// decimal positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case ".":
						intDecCount++;
						if (intDecCount == 1)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 3:

			case 4:
			{
				// decimal positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case "-":
						if (i == 0)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}

					case ".":
						intDecCount++;
						if (intDecCount == 1)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 4:

		} // switch (intFormat)
	} // (var i=0; i < strNew.length; i++)

	return blnReturn;
}