<!--

/* This JavaScript file created in Microsoft Visual InterDev 6.0 */

/******************************************************************************

					JAVASCRIPT FORM VALIDATION FUNCTIONS
					====================================

This JavaScript file contains functions for client-side form validation.  The
'master' function, verify, is the function called from the onSubmit event
when the user submits the form.  All other functions in this file are called
by this function.

To standardize the layout of this file, please adhere to the following guide-
lines:

	1.	The verify function should always be the last function in this file.
		This then concludes that any function called by the verify function be
		located above the verify function.
	
	2.	Because this file may be modified by different people in the future,
		please list all functions in alphabetical order.  This will allow you
		to find a specific function much easier.
	
	3.	Please comment your code.  This will help others to understand what
		the purpose of your function is and how it works.  It will also help
		others when code needs to be tweaked or improved.  Following the
		formatting for code and comments will provide a more consistent and
		familiar layout for everyone.  A 'flowerbox' will precede each function
		containing the name of the function, a description of the arguments,
		and a description of the purpose of the function.  It would also be
		very helpful to future users who want to implement this form validation
		file in the future if you would include a sample of how to implement
		the function, or a syntax example.
	
There is, obviously, no way to enforce these guidelines.  So I implore you:
please, don't be a putz, and try to play nice...

To implement this JavaScript file in your HTML document, simply include the
following code in the document header:



where "path" is the path to this JavaScript file on the web server and
"filename" is the name of this JavaScript file (usually "validate.js").

	NOTE: Don't forget to follow it with a closing script tag.

By implementing this validation script this way, it is easily transferrable to
any HTML platform.

Also, I would ask that when you make any additions or modifications that you
send me a copy so that I can keep an up-to-date version that can be re-
distributed to anyone that wants it.  You can send it to me at
aporter@perficient.com.  Thanks.

******************************************************************************/

var specialMask = '&!/\\@-=#$%^()';


/******************************************************************************

FUNCTION:		checkDate

ARGUMENTS:		str - String

DESCRIPTION:	This function will determine if the string being received is
				in a valid date format (mm/dd/yy or mm/dd/yyyy).  If the string
				is a valid date, the function will return true, otherwise it
				will return false.

SYNTAX:			var str = "7/14/1999";
				if (!(checkDate(str))) {
					// show error message
				}

AUTHOR:			unknown

DATE:			14 July 1999

******************************************************************************/
function checkDate (str) {
	// check to see what delimiter the user included
	if (str.indexOf("-") != -1) {
		var aDate = str.split("-");
	} else if (str.indexOf("/") != -1) {
		var aDate = str.split("/");
	} else {
		var aDate = 0;
	}
	
	// split the string into an array containing month, day, year
	//var aDate = str.split("/");
	
	// if the array doesn't contain three elements return false
	if (aDate.length != 3) return false;
	
	// assign the month, day, and year to variables
	m = aDate[0];
	d = aDate[1];
	y = aDate[2];
	
	// check the month, day, and year for valid values
	if ((m < 1) || (m > 12)) return false;
	if ((d < 1) || (d > 31)) return false;
	if ((y < 0) || (y > 9999)) return false;
	
	//advanced error checking
	// months with 30 days
	if ((m == 4) || (m == 6) || (m == 9) || (m == 11)) {
		if (d == 31) return false;
	}
	
	// february, leap year
	if (m == 2) { // feb
		var leap = parseInt(y/4)
		if (isNaN(leap)) return false;
		if (d > 29) return false;
		if ((d == 29) && ((y / 4)!= parseInt(y/4))) return false;
    }
    return true;
}

/******************************************************************************

FUNCTION:		checkEmail

ARGUMENTS:		str - String

DESCRIPTION:	This function will evaluate the string being passed in and
				determine if it is a valid e-mail address.
				
				NOTE: This function has been adapted from a script written by
				Chris Dorman in 1998 found on the Web Monkey web site.

SYNTAX:			var str = "name@domain.com";
				if (!(checkEmail(str))) {
					// show error message
				}

AUTHOR:			Andrew Porter
				Perficient

DATE:			30 September 1999

******************************************************************************/
function checkEmail (str) {
	var a = str.indexOf("@");
	var p = str.lastIndexOf(".");
	var s = str.indexOf(" ");
	var l = str.length - 1;
	
	if (a < 1) return false;		// @ cannot be in first position
	if (p <= a + 1) return false;	// must be atleast one valid character btwn @ and .
	if (p == l) return false;		// must be atleast one valid char after .
	if (s != -1) return false;		// no empty spaces permitted
	return true;
}

/******************************************************************************

FUNCTION:		checkURL

ARGUMENTS:		str - String

DESCRIPTION:	This function will evaluate the string being passed in and
				determine if it is a valid internet address.

SYNTAX:			var str = "http://www.solaris7.com";
				if (!(checkURL(str))) {
					// show error message
				}

AUTHOR:			George Blouin
				Solaris7.com

DATE:			19 December 2000

******************************************************************************/
function checkURL (str) {
	var mask = 'http://';
	var check = str.substring(0, 7);
	var l = str.length - 1;
	var PeriodLoc = str.indexOf(".");
	
	if (check != mask) return false;				// URL must start with http://
	if ((mask.length -1) == l) return false;		// URL must have characters after http://
	if (PeriodLoc == -1) return false;				// URL must have at least one period.
	return true;
}

/******************************************************************************

FUNCTION:		isEmpty

ARGUMENTS:		str - String

DESCRIPTION:	This function will determine if the string being received is
				blank or contains only whitespace (spaces, tabs, newline).  If
				this is the case, the function returns true, otherwise, it
				returns false.

SYNTAX:			var strText = " ";
				if (isEmpty(strText)) {
					// execute statement
				}

AUTHOR:			Andrew Porter
				Perficient

DATE:			13 July 1999

******************************************************************************/
function isEmpty (str) {
	if ((str != null) && (str != "")) {
		for (var i = 0; i < str.length; i++) {
			var temp = str.charAt(i);
			if ((temp != " ") && (temp != "\t") && (temp != "\n")) return false;
		}
	}
	return true;
}

/******************************************************************************

FUNCTION:		showError

ARGUMENTS:		obj - Form element
				str - Error message to display

DESCRIPTION:	This function will display an error message to the user and
				highlight/select the element in error.

SYNTAX:			return showError(form1.firstName, "Error!");

AUTHOR:			Andrew Porter
				Perficient

DATE:			13 July 1999

******************************************************************************/
function showError (obj, str) {
	if (obj.label != null) {
		str = obj.label + " " + str;
	} else {
		str = "This field " + str;
	}
	alert(str);
	if (obj.type != "select-one"){
		obj.select();
		obj.focus();
	}
	return false;
}

// ******************************************************
//function check(input) is added by Nancy K  
// This function will accept 0-9, dots and commas ie 9,000,000.00
// ******************************************************

function check(input) {
  var ok = true;

  for (var i = 0; i < input.length; i++) {
    var chr = input.charAt(i);
    var result = false;
	if ((chr >= '0' && chr <= '9') ||
		chr == ',' || chr == '.')
      result = true;
    
    if (!result) ok = false;
  }
 
  return ok;
}

function noSpecial(str) {
	alert(specialMask);
	alert(str);
	for(l=0; l<=(specialMask.length-1); l++) {
		for(j=0; j<=(str.length-1); j++) {
			if (str.charAt(j) == specialMask.charAt(l)) {									
				return false; 
			}
		}
	}
	return true;
}

/******************************************************************************

FUNCTION:		verify

ARGUMENTS:		f - Form object

DESCRIPTION:	Upon submit, this function will iterate through each element in
				the form.  Validation check functions are grouped and executed
				by element type and then by custom element properties.
				
				Custom element properties are declared before calling this form
				in the onSubmit event.  If no custom properties are set, they
				will inherit default values that will cause them to behave as
				regular form elements, or 'be ignored' by the validation
				script.
				
				Any form element value that does not comply with the custom
				properties set for that element will generate an error message.
				This message will be displayed to the user, and the form
				element in error will be highlighted and/or selected.  The user
				will then have to resubmit the form in order to continue.  This
				process will repeat until the entire form has been successfully
				evaluated.
				
				Below is an explanation of the custom properties currently
				available for each form element:
				
				Element		Property		Description
				-------		--------		--------------------------------
				button		N/A				N/A
				
				checkbox	N/A				N/A
				
				file		isRequired		Setting this property to 'true'
											will not allow the user to leave
											the field blank.
				
				password	isRequired		Setting this property to 'true'
											will not allow the user to leave
											the field blank.
				
							minLength		Setting this property to a number
											'n' will not allow the user to
											enter less than 'n' number of
											characters.
							
							noSpecial		Setting this property to 'true'
											will fire a check of the string
											against a mask of characters that
											are not to be allowed.
							
				radio		isRequired		Setting this property to 'true' on
											the first element of the radio group
											will fire a check to validate that a
											selection has been made.
				
				reset		N/A				N/A
				
				select-one	isRequired		Setting this property to 'true'
											will not allow the user to leave
											the field blank.
				
				select-many	N/A				N/A
				
				submit		N/A				N/A
				
				text		isDate			Setting this property to 'true'
											will require the user to enter a
											valid date string into the field.
							
							notPast			Setting this property to 'true'
											will require the user to enter a
											date that is not less then the
											current date.
											
							noSpecial		Setting this property to 'true'
											will fire a check of the string
											against a mask of characters that
											are not to be allowed.
	
							isEmail			Setting this property to 'true'
											with require the user to enter a
											valid e-mail address into the
											field.
							
							isURL			Setting this property to 'true'
											will require the user to enter a
											valid URL including the http://
											
							isNumeric		Setting this property to 'true'
											will require the user to enter a
											number into the field.
							
							isRequired		Setting this property to 'true'
											will not allow the user to leave
											the field blank.
							
							maxValue*		Setting this property to a number
											'n' will not allow the user to
											enter a numeric value greater than
											'n'.
							
							minLength		Setting this property to a number
											'n' will not allow the user to
											enter less than 'n' number of
											characters.
							
							minValue*		Setting this property to a number
											'n' will not allow the user to
											enter a numeric value less than
											'n'.
											
							* minValue and maxValue will only work if isNumeric
							is set to 'true'.
				
				textarea	isRequired		Setting this property to 'true'
											will not allow the user to leave
											the field blank.
							
							noSpecial		Setting this property to 'true'
											will fire a check of the string
											against a mask of characters that
											are not to be allowed.
											
							maxLength		Setting this property to a number
											'n' will not allow the user to
											enter more than 'n' number of
											characters.
				
							minLength		Setting this property to a number
											'n' will not allow the user to
											enter less than 'n' number of
											characters.
							
				NOTE: If you want all form elements to be required, simply set
				the form.all.isRequired property to true.  This way you won't
				have to set the isRequired attribute for all form elements
				individually.

SYNTAX:			<FORM action="" method="post" language="JavaScript" onSubmit="
					this.elementName.customProperty = value;
					this.elementName.customProperty = value;
					return verify(this);">

AUTHOR:			Andrew Porter
				Perficient
				George Blouin
				Escrow.com
				Viet La
				Escrow.com
				Nancy Khoan
				Escrow.com

DATE:			13	July	1999
				6	October	2000

******************************************************************************/

var submitIt = -1

function verify(f) {
	for (var i = 0; i < f.length; i++) {
		// create a variable containing the form element object
		var e = f.elements[i]
		// check for element type and then perform the necessary checks for
		// that type
		// also, check to see if the form.all.isRequired property
		// has been set
		switch (e.type) {
			case "button" :
				// don't do anything
				break;
			case "checkbox" :
				// don't do anything
				break;
			case "file" :
				// check if the element is empty
				if (isEmpty(e.value)) {
					// if the field is required, show error message and select field
					if (e.isRequired) {
						return showError(e, "is a required field.");
					}
				}
				break;
			case "password" :
				// check if the element is empty
				if (isEmpty(e.value)) {
					// if the field is required, show error message and select field
					if (e.isRequired) {
						return showError(e, "is a required field.");
					}
				}
				
				// if the text box is required, or not empty, then check for
				// custom field values...
				if ((e.isRequired) || !(isEmpty(e.value))) {
					// check for a minimum field length property
					if (e.minLength != null) {
						if (e.value.length < e.minLength) {
							return showError(e, "contains less than " + e.minLength + " characters.");
						}
					}
					
					// check for special characters
					if (e.noSpecial) {
						if (!noSpecial(e.value)) {
							return showError(e, 'can not contain the following special character(s): ' + specialMask + '.');
						}
					}
					
					// check for matching values
					if (e.Match) {
						if (e.value != e.MatchValue) {
							return showError(e, 'must be the same.');
						}
					}
				}
				break;
			case "radio" :
				// *** TO GET RADIO GROUPS TO WORK YOU MUST ADD isRequired TO THE FIRST ELEMENT OF THE RADIO IE. this.Radio_Name[0].isRequired
				// *** SAME GOES FOR THE LABEL this.Radio_Name[0].label = 'Label';
				// if the radio group is required then check for selection
				if (e.isRequired) {
					var isChecked = false;
					for (j=0; j < f.length; j++) {
						if (f.elements[j].name == e.name && f.elements[j].type == "radio") {
							if (f.elements[j].checked) {
								isChecked = true;
							}
						}
					}
					if (!isChecked) {
						return showError(e, "is a required field.");
					}
				}
				break;
			case "reset" :
				// don't do anything
				break;
			case "select-one" :
				if (e.isRequired) {
					//Check the selected index to see if it is empty
					if ((e.options[e.selectedIndex].value == "") || (e.options[e.selectedIndex].text == ""))
						return showError(e, "is a required field.");
				}
				// don't do anything
				break;
			case "select-many" :
				// don't do anything
				break;
			case "submit" :
				if (e.submitform){
						if (submitIt < 0) {
							submitIt = submitIt + 1;
							return true; 
						} else { 
							return false;
						}
				}	
				// don't do anything
				break;
			case "text" :
				// check if the element is empty
				if (isEmpty(e.value)) {
					// if the field is required, show error message and select field
					if (e.isRequired) {
						return showError(e, "is a required field.");
					}
				}
				
				// if the text box is required, or not empty, then check for
				// custom field values...
				if ((e.isRequired) || !(isEmpty(e.value))) {
					
					// check for Formatting
					if (e.isFormatted) {
						if (!checkFormat(e.value, e.Format)) {
							return showError(e, "does not match the required format.");
						}
					}
				
					// check for URL
					if (e.isURL) {
						if (!checkURL(e.value)) {
							return showError(e, "contains an invalid URL.");
						}
					}
						
					// check for a minimum field length property
					if (e.minLength != null) {
						if (e.value.length < e.minLength) {
							return showError(e, "contains less than " + e.minLength + " characters.");
						}
					}
				
					// check for special characters that cannot be in the field
					if (e.noSpecial) {
						if (!noSpecial(e.value)) {
							return showError(e, 'can not contain the following special character(s): ' + specialMask + '.');
						}
					}
	
					// check if the field should be a date
					if (e.isDate) {
						if (!(checkDate(e.value))) {
							return showError(e, "contains an invalid date.");
						} else {
							if (e.notPast) {
								if (!(verifyDate(e.value))) {
									return showError(e, "contains a past date.");
								}
							}
						}
					}
					
					// check if the field should be an e-mail address
					if (e.isEmail) {
						if (!(checkEmail(e.value))) {
							return showError(e, "contains an invalid e-mail address.");
						}
					}
					// will accept only 0-9, dots and commas (Nancy adds)
					if (e.isNumber) {
						if (!(check(e.value))) {
						return showError(e, "contains invalid number.");
						}
					}	
					// check if the field should be numeric.  Not accept dots and commas
					if (e.isNumeric) {
						// check if the field value is not a number
						if (isNaN(e.value)) {
							return showError(e, "can only contain a numeric value.");
						}
						// check if the field has a mimum value limit
						if (e.minValue != null) {
							if (parseFloat(e.value) < parseFloat(e.minValue)) {
								return showError(e, "must be greater than " + e.minValue + ".");
							}
						}
						// check if the field has a maximum value limit
						if (e.maxValue != null) {
							if (parseFloat(e.value) > parseFloat(e.maxValue)) {
								return showError(e, "is greater than " + e.maxValue + ".");
							}
						}
					}
					
					// check for matching values
					if (e.Match) {
						if (e.value != e.MatchValue) {
							return showError(e, 'must be the same.');
						}
					}
				}
				break;
			case "textarea" :
				// check if the element is empty
				if (isEmpty(e.value)) {
					// if the field is required, show error message and select field
					if (e.isRequired) {
						return showError(e, "is a required field.");
					}
				}
				
				// if the field is required or not empty...
				if ((e.isRequired) || !(isEmpty(e.value))) {
					// check for a minimum field length property
					if (e.minLength != null) {
						if (e.value.length < e.minLength) {
							return showError(e, "contains less than " + e.minLength + " characters.");
						}
					}
					
					// check for special characters that cannot be in the field
					if (e.noSpecial) {
						if (!noSpecial(e.value)) {
							return showError(e, 'can not contain the following special character(s): ' + specialMask + '.');
						}
					}
					
					// check for a maximum field length property
					if (e.maxLength != null) {
						// check to see if it is too long
						if (e.value.length > e.maxLength) {
							// the user should be given the option to edit the field
							// or have the extra characters removed
							eMsg = "contains more than " + e.maxLength + " characters.\n\n"
							eMsg += "Click OK to truncate or CANCEL to edit, then resubmit."
							// if there is a label for this field, display it in the message
							if (e.label != null) {
								eMsg = e.label + ": " + eMsg;
							}
							// if the user clicked OK, then truncate the string value
							if (confirm(eMsg)) {
								e.value = e.value.substr(0, e.maxLength);
							}
							e.select();
							e.focus();
							return false;
						}
					}
				}
				break;
		} // end switch
	}
} // end verify

/******************************************************************************

FUNCTION:		trim

ARGUMENTS:		str - String

DESCRIPTION:	This function will trim the leading and trailing spaces off of
				the string passed to it.

SYNTAX:			newstring = trim(oldstring);

AUTHOR:			Viet La
				Escrow.com

DATE:			4 April 2000

******************************************************************************/
function trim(str)
{
	var newstr;
	var intlen;
	var s
	newstr	= "";
	intlen	= str.length;
	for (i = 0; i <= intlen; i++) 
	{      
		s = str.substr(i,1);
		if (s != " ") 
		{
			beginpos = i;
			break;
		}
	}
	for (i = intlen; i >= 0; i--) 
	{      
		s = str.substr((i-1),1);
		if (s != " ") 
		{
			endpos = i;
			break;
		}
	}
	newstr = str.substr(beginpos,endpos);
	return newstr;
}

/******************************************************************************

FUNCTION:		verifyDate

ARGUMENTS:		ExpectedDate - Fulfillment Date given by participant

DESCRIPTION:	This function will convert the current date and the date given
				by the Participant into a Julian Date and compare.  If the date
				given is before the current date it returns false, else it will
				return true.

SYNTAX:			verifyDate(this.ExpectedTransfer.value);

AUTHOR:			Aaron Strasburg

DATE:			13 June 2000

******************************************************************************/
function verifyDate(ExpectedDate)
{
	//ENTERED DATE MUST BE PARSED FOR EACH PART
	if (ExpectedDate.indexOf("/") != -1) {
		userDate = ExpectedDate.split("/");
	} else {
		if (ExpectedDate.indexOf("-") != -1) {
			userDate = ExpectedDate.split("-");
		} else {
			//THE DATE WAS NOT IN THE CORRECT FORMAT
			return false;
		}
	}
	
	//STORE THE SEPERATE PARTS OF THE DATE
	if (userDate.length == 3) {
		userMonth = userDate[0];
		userDay = userDate[1];
		userYear = userDate[2];
	} else {
		//THE DATE WAS NOT IN THE CORRECT FORMAT
		return false;
	}
	
	//RETRIEVE THE CURRENT DATES PARTS
	today = new Date();
	curMonth = today.getMonth() + 1;
	curDay = today.getDate();
	curYear = today.getYear();
	
	//CHECK THE YEAR FORMAT
	if (parseInt(userYear) < 50) {
		userYear = parseInt(userYear) + 2000;
	} else {
		userYear = parseInt(userYear) + 1900;
	}

	//CHECK CURRENT DATE AGAINST ENTERED DATE
	if (userYear < curYear) {
		return false;
	} else {
		if (userYear == curYear) {
			//CHECK THE MONTH
			if (userMonth < curMonth) {
				return false;
			} else {
				if (userMonth == curMonth) {
					//CHECK THE DAY
					if (userDay < curDay) {
						return false;
					}
				}
			}
		}
	}
	return true;
}

/******************************************************************************

FUNCTION:		getFullYear

ARGUMENTS:		year - The year part

DESCRIPTION:	This function will convert the given year into it's full form.

SYNTAX:			getFullYear(this.ExpectedTransfer.value);

AUTHOR:			George Blouin

DATE:			28 August 2000

******************************************************************************/
function getFullYear(year)
{
	var y = year
	if (y < 1000) y +=2000;
	return y;
}

/******************************************************************************

FUNCTION:		checkFormat

ARGUMENTS:		theString - The string entered by the user that will be checked.
				theFormat - The format that the string should match.

DESCRIPTION:	This function checks the user string to validate that it meets
				an expected format.

SYNTAX:			checkFormat(this.CostCenter.value, this.CostCenter.Format);

AUTHOR:			George Blouin

DATE:			12 June 2001

******************************************************************************/
function checkFormat(theString, theFormat) {
	var alphaMask = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var numericMask = "0123456789";
	
	if (theString.length > 0 && theFormat.length > 0) {
		for(i=0; i <= theString.length-1; i++) {
			switch (theFormat.charAt(i)) {
				case 'A' :
					if (!CharinMask(theString.charAt(i), alphaMask)) return false;
					break;
				case '#' :
					if (!CharinMask(theString.charAt(i), numericMask)) return false;
					break;
				case '%' :
					break;
			}
		}
		return true;
	}
	return false;
}

/******************************************************************************

FUNCTION:		CharinMask

ARGUMENTS:		theCharacter - The current character to check.
				theMask - A mask that theCharacter might be included within.

DESCRIPTION:	This function checks whether or not the character is included
				in the given mask and returns a boolean.

SYNTAX:			CharinMask(theString.charAt(i), alphaMask);

AUTHOR:			George Blouin

DATE:			12 June 2001

******************************************************************************/
function CharinMask(theCharacter, theMask) {
	for (l=0; l <= theMask.length-1; l++) {
		if (theMask.charAt(l) == theCharacter) {
			return true;
		}
	}
	return false;
}

function varPopUp(url, height, width, options) {
    varremote = window.open(url, "VarRemote", options + ",width=" + width + ",height=" + height);
    window.varremote.focus();
}

/******************************************************************************
		END OF JAVASCRIPT FORM VALIDATION SCRIPTS
******************************************************************************/
//-->
