<!--

objForm = null;
isFirst = true;

/*
CLASS DECLARATIONS AND IMPLEMENTATIONS
*/

function IntegralType (min, max)
{
	this.Min = min;
	this.Max = max;
}

SQL_TINYINT  = new IntegralType (0, 255);
SQL_SMALLINT = new IntegralType (-32768, 32767);
SQL_INT      = new IntegralType (-2147483648, 2147483647);
SQL_BIGINT   = new IntegralType (-9223372036854775808, 9223372036854775807);


/*
FORM VALIDATION FUNCTIONS
*/


/*--------------------------------------- VACATION FORM ------------------------------------------------*/
function Verify_Vacation_Info (frm)
{	
	//set the global variable
	objForm = frm;
	fields = frm.elements;
	var out = "";

	out += CheckText       ("leave", "Date Leaving");
	out += CheckText       ("return", "Date Returning");
	
	out += CheckText       ("name", "Name");	
	out += CheckText       ("address", "Address");
	out += CheckText       ("phone", "Home Phone");
/*	out += CheckText       ("cell", "Cell Phone");     */
	out += CheckText       ("econtact", "Emergency Contact");
	out += CheckText       ("ephone", "Emergency Phone");
	
/*	out += CheckEmail      ("email");                  */

	if (out)
	{
		DisplayErrorWindow (out);
		return false;
	}

	//check for one of two files to be non blank
	if(!document.frm.FILENAME1.value&&!document.frm.FILENAME2.value)
	{
		window.alert("Please enter ONE or the OTHER")
		return false
	} 
    
	else
		return true;
}

/*---------------------------------------------------------------------------------------*/
function Verify_Event_Info (frm)
{	
	//set the global variable
	objForm = frm;
	fields = frm.elements;
	var out = "";
	
	out += CheckText       ("name", "Name");
	out += CheckText       ("phone", "Home Phone");
	out += CheckText       ("event", "Event Type");
/*	out += CheckEmail      ("email");	                */

	if (out)
	{
		DisplayErrorWindow (out);
		return false;
	}

	//check for one of two files to be non blank
	if(!document.frm.FILENAME1.value&&!document.frm.FILENAME2.value)
	{
		window.alert("Please enter ONE or the OTHER")
		return false
	} 
    
	else
		return true;
}

/*---------------------------------------------------------------------------------------*/
function Verify_TipLine_Info (frm)
{	
	//set the global variable
	objForm = frm;
	fields = frm.elements;
	var out = "";
	
/*	out += CheckText       ("name", "Name");            */
/*	out += CheckText       ("phone", "Home Phone");     */
	out += CheckText       ("comments", "Tip Information");
/*	out += CheckEmail      ("email");	                */

	if (out)
	{
		DisplayErrorWindow (out);
		return false;
	}

	//check for one of two files to be non blank
	if(!document.frm.FILENAME1.value&&!document.frm.FILENAME2.value)
	{
		window.alert("Please enter ONE or the OTHER")
		return false
	} 
    
	else
		return true;
}

/*---------------------------------------------------------------------------------------*/
function Verify_MailList_Info (frm)
{	
	//set the global variable
	objForm = frm;
	fields = frm.elements;
	var out = "";
	
	out += CheckText       ("name", "Name");
/*	out += CheckText       ("phone", "Home Phone");          */
	out += CheckEmail      ("email");

	if (out)
	{
		DisplayErrorWindow (out);
		return false;
	}

	//check for one of two files to be non blank
	if(!document.frm.FILENAME1.value&&!document.frm.FILENAME2.value)
	{
		window.alert("Please enter ONE or the OTHER")
		return false
	} 
    
	else
		return true;
}

/*---------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------*/


function CheckText (fieldName, msg)
{
	return (objForm.elements[fieldName].value == "") ? msg + "\n" : "";
}


function CheckSelectList (fieldName, msg)
{
	var myList = objForm.elements[fieldName];
	return (myList[myList.selectedIndex].value == "") ? msg + "\n" : "";
}


function CheckBoxSet (fieldName, msg)
{
	var i, isChecked, els;
	isChecked = false;
	els = objForm.elements;
	for (i=0; i < els.length && !isChecked; i++)
	{
		if (els[i].name == fieldName)
		{
			isChecked = els[i].checked;
		}
	}
	return (isChecked) ? "" : msg + "\n";
}

/* ------------------------------------------------------------------------- VALID PHONE NUMBER   (xxx) xxx-xxxx    */

/* ------------------------------------------------------------------------- QUESTIONABLE ROUTINE *
function CheckPhone(fieldName, msg) 
{
  phoneRegex = /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
 if( !phone.match( phoneRegex ) ) 
 {
  alert( ‘Please enter a valid phone number’ );
  return false;
 }
 return true;
}
/* -------------------------------------------------------------------------- */




function CheckRadioSet (fieldName, msg)
{
	var mySet = objForm.elements[fieldName], i, checked;
	for (i = 0; i < mySet.length; i++)
	{
		if (mySet[i].checked)
			return ("");
	}
	return (msg + "\n");
}


function CheckInteger (fieldName, intType, msg)
{
	var myField = objForm.elements[fieldName];
	var myValue = myField.value;
	
	if (isNaN (myValue) || myValue == "")
		return (msg + " requires a numeric value\n");
	if (myValue > intType.Max || myValue < intType.Min)
		return (msg + " must be between " + intType.Min + " and " + intType.Max + "\n");
	
	myField.value = parseInt (myField.value);
	return ("");
}

/* ------------------------------------------------------------------------------- CHECK EMAIL FORMAT */

function CheckEmail (fieldName)
{
	var emailStr = objForm.elements[fieldName].value;

	if (emailStr == "")
		return  ("Email Address\n")
		
	return CheckEmailFormat (fieldName);
}


function CheckEmailFormat (fieldName)
{
	var emailStr = objForm.elements[fieldName].value;
	
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
		return ("Email Address seems incorrect (check @ and .'s)\n")

	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null)
		return ("Email Address username does not seem to be valid\n")

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
				return ("Destination IP address is invalid\n")
		}
		return "";
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null)
		return ("Email Address domain name does not seem to be valid\n")

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		return ("Email Address must end in a three-letter domain, or two letter country\n")

	if (len<2)
		return ("This address is missing a hostname\n")
	
	return "";
}

/* ------------------------------------------------------------------------------ CHECK BOX VALIDATION */

function IsCheckBoxSet (fieldName, value)
{
	var i, isChecked, els;
	isChecked = false;
	els = objForm.elements;
	for (i=0; i < els.length && !isChecked; i++)
	{
		
		if (els[i].name == fieldName && els[i].value == value)
		{
			isChecked = els[i].checked;
		}
	}
	return isChecked;
}


/* ------------------------------------------------------------------------ DISPLAY ERROR WINDOW MESSAGE */


function DisplayErrorWindow (msg)
{
	alert ("The following information is required\nto submit this form:\n=======================\n" + msg);
}

//-->