<!-- saved from url=(0022)http://internet.e-mail -->
//*************************************************************************<br>
//Author:       Jay Mendiola <br>
//Date Written: October 98   <br>
//Purpose:      Reusable client-side Javascript validation functions <br>
//<B>Do not modify in design view. Switch to source view.</B><BR>
//Modified by:	Nick Lee, N5R.com
//*************************************************************************<br>
// <SCRIPT language="JavaScript">
<!--
function isEmpty(obj)
{
	if ((obj.value.length <= 0) || (obj.value == null) || (obj.value.charAt(0) == " "))
	{
		return true;
	}
	return false;
}

function isAtLeastOneSelected(obj) {	// require at least one radio option to be selected
	var atLeastOneSelected = false;
	for (i=0; i<obj.length; i++) {
		if (obj[i].checked) return true;
	}
	return false;
}

function isValidCode(obj, mask)
{
	var str = obj.value;

	if (str.length != mask.length)
		return false;
	else
	{
		for (i=0; i<mask.length; i++)
		{
			if (mask.charAt(i) == "9")
			{
				if ((str.charAt(i) < "0") || (str.charAt(i) > "9"))
					return false;
			}
			else if (mask.charAt(i) == "A")
			{
				if ((str.charAt(i) < "A") || (str.charAt(i) > "Z"))
					return false;
			}
			else
			{
				if (str.charAt(i) != mask.charAt(i))
					return false;
			}
		}
	}
	return true;
}

function isValidCode2(str, mask)
{
	if (str.length != mask.length)
		return false;
	else
	{
		for (i=0; i<mask.length; i++)
		{
			if (mask.charAt(i) == "9")
			{
				if ((str.charAt(i) < "0") || (str.charAt(i) > "9"))
					return false;
			}
			else if (mask.charAt(i) == "A")
			{
				if ((str.charAt(i) < "A") || (str.charAt(i) > "Z"))
					return false;
			}
			else
			{
				if (str.charAt(i) != mask.charAt(i))
					return false;
			}
		}
	}
	return true;
}

function isNumeric(obj)
{
	var str = obj.value;

	if (str.length <= 0)
		return false;

	for (i=0; i<str.length; i++)
	{
		if ((str.charAt(i) < "0") || (str.charAt(i) > "9"))
			return false;
	}
	return true;
}

function isGoodEmail(obj)
{
  var em = obj.value;

  if (em == "") return false;

  if (em.indexOf(">") != -1 ||
      em.indexOf(",") != -1 ||
      em.indexOf("<") != -1 ||
      em.indexOf(":") != -1 ||
      em.indexOf(";") != -1 ||
      //em.indexOf("'") != -1 ||
      em.indexOf('"') != -1 ||
      em.indexOf("/") != -1 ||
      em.indexOf("?") != -1) {
    return false;
  }

  var arr = obj.value.split("@");
  if (arr.length != 2 || arr[0].length == 0) {
    return false;
  }

  arr = arr[1].split(".");
  if (arr.length < 2) {
    return false;
  }

  var index = 0;
  for (; index<arr.length-1; index++) {
    if (arr[index].length == 0) {
      return false;
    }
  }

  if (arr[index].length < 2 || arr[index].length > 4) {
    return false;
  }

  return true;
}


function isMDY2(theMonth, theDay, theYear) {
	var str = theMonth + '/' + theDay + '/' + theYear;

	if (isNaN(theMonth) || isNaN(theDay) || isNaN(theYear)) {
		return false;
	}

//	var month = parseInt(theMonth);
//	var day = parseInt(theDay);
//	var year = parseInt(theYear);
	var day = theDay.charAt(0) == "0" ? parseInt(theDay.substring(1, 2)) : parseInt(theDay.substring(0, 2));
	var month = theMonth.charAt(0) == "0" ? parseInt(theMonth.substring(1, 2)) : parseInt(theMonth.substring(0, 2));
	var year = theYear.charAt(0) == "0" ? parseInt(theYear.substring(1, 2)) : parseInt(theYear.substring(0, 2));



	if (day == 0)
		return false;

	if (month == 0 || month > 12)
		return false;

	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||month == 10 || month == 12) {
		if (day > 31)
			return false;
	}
    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
		if (day > 30)
			return false;
	}
	else if (year % 4 == 0)
	{
		if (day > 29)
			return false;
	}
	else if (day > 28)
		return false;

    return true;
}

function isMDY(obj)
{
	var str = obj.value;

	if  (isValidCode(obj, "99999999"))
		obj.value = str.substring(0, 2) + "/" + str.substring(2, 4) + "/" + str.substring(4, 8);
	else if (isValidCode(obj, "9/9/9999"))
		obj.value = "0" + str.substring(0, 2) + "0" + str.substring(2, 8);
	else if (isValidCode(obj, "9/99/9999"))
		obj.value = "0" + str.substring(0, 9);
	else if (isValidCode(obj, "99/9/9999"))
		obj.value = str.substring(0, 3) + "0" + str.substring(3, 9);

	if (!isValidCode(obj, "99/99/9999"))
		return false;

	str = obj.value
	var month = str.charAt(0) == "0" ? parseInt(str.substring(1, 2)) : 
parseInt(str.substring(0, 2));
	var day = str.charAt(3) == "0" ? parseInt(str.substring(4, 5)) : 
parseInt(str.substring(3, 5));
	var year = str.charAt(8) == "0" ? parseInt(str.substring(9, 10)) : 
parseInt(str.substring(8, 10));
	var cent = str.charAt(6) == "0" ? parseInt(str.substring(7, 8)) : 
parseInt(str.substring(6, 8));

	if (day == 0)
		return false;

	if (month == 0 || month > 12)
		return false;

	if (cent != 19 && cent != 20)
		return false;

	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || 
month == 10 || month == 12)
	{
		if (day > 31)
			return false;
	}
    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
		if (day > 30)
			return false;
	}
	else if (year % 4 == 0)
	{
		if (day > 29)
			return false;
	}
	else if (day > 28)
		return false;

    return true;
}
function isMoney(obj)
{
	var str = obj.value;

	if (str.length <= 0)
		return false;

	i = 0;
	for (j=0; j<str.length; j++)
	{
		if ((str.charAt(j) != ".") && (str.charAt(j) != ",") && ((str.charAt(j) < "0") || (str.charAt(j) > "9")))
			return false;
		if (str.charAt(j) == ".")
		{
			i += 1;
			if (i > 1)
				return false;
			else if ((str.length - j) > 3)
				return false;
		}
	}
	return true;
}
function isPostalCode(obj)
{
	obj.value = obj.value.toUpperCase();
	if (isValidCode(obj, "A9A9A9"))
	{
		str = obj.value;
		obj.value = str.substring(0, 3) + " " + str.substring(3, 6);
		return true;
	}
	else if (isValidCode(obj, "A9A 9A9"))
		return true;

	return false;
}
function isPostalCodeA(obj) {
	obj.value = obj.value.toUpperCase();
	if (isValidCode(obj, "A9A"))
		return true;
	return false;
}

function isPostalCodeB(obj) {
	obj.value = obj.value.toUpperCase();
	if (isValidCode(obj, "9A9"))
		return true;
	return false;
}

function isPhone(obj)
{
	if (obj.value.length < 10)
	{
		errorMsg = "Please include area code.";
		return false;
	}

	if (isValidCode(obj, "9999999999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(3, 6) + "-" + 
str.substring(6, 10);
		return true;
	}
	else if (isValidCode(obj, "999 9999999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(4, 7) + "-" + 
str.substring(7, 11);
		return true;
	}
	else if (isValidCode(obj, "999 999 9999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(4, 7) + "-" + 
str.substring(8, 12);
		return true;
	}
	else if (isValidCode(obj, "999 999-9999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(4, 12);
		return true;
	}
	else if (isValidCode(obj, "999999-9999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(3, 11);
		return true;
	}
	else if (isValidCode(obj, "999-999-9999"))
	{
		str = obj.value;
		obj.value = "(" + str.substring(0, 3) + ") " + str.substring(4, 12);
		return true;
	}
	else if (isValidCode(obj, "(999)999-9999"))
	{
		str = obj.value;
		obj.value = str.substring(0, 5) + " " + str.substring(5, 13);
		return true;
	}
	else if (isValidCode(obj, "(999)9999999"))
	{
		str = obj.value;
		obj.value = str.substring(0, 5) + " " + str.substring(5, 8) + "-" + 
str.substring(8, 12);
		return true;
	}
	else if (isValidCode(obj, "(999) 9999999"))
	{
		str = obj.value;
		obj.value = str.substring(0, 6) + str.substring(6, 9) + "-" + 
str.substring(9, 13);
		return true;
	}
	else if (isValidCode(obj, "(999)999 9999"))
	{
		str = obj.value;
		obj.value = str.substring(0, 5) + " " + str.substring(5, 8) + "-" + 
str.substring(9, 13);
		return true;
	}
	else if (isValidCode(obj, "(999) 999 9999"))
	{
		str = obj.value;
		obj.value = str.substring(0, 6) + str.substring(6, 9) + "-" + 
str.substring(10, 14);
		return true;
	}
	else if (isValidCode(obj, "(999) 999-9999"))
		return true;

	return false;
}
//-->
