﻿//===============================================
// This set of functions are general includes for validation
// The form event and the element event validation functions are designed in pairs
// The element event function will call the form function with the event source.
//===============================================

// Available Functions

//	---------------------------------- Form Validation

/*	General vlaidation Functions: */
//	frmValid.NonBlank(element)
//	frmValid.ItemSelected(element)
//	frmValid.LengthUpTo(element, int length)
//	frmValid.ExactLength(element, int length)

/*	Numberic Validation */
//	frmValid.ValidNumber(element, DisplayFlag, Format, 
//                       LowerLimit, UpperLimit, Exception1, Exception2)
//
//	DisplayFlag:	true, false, or null (false)
//	Format:			Numeric (1), Integer(2), Numeric with commas(3), 
//					Integer with commas (4), or null (Numeric)
//	LowerLimit:		Inclussive Lower Limit, null = -Infinity
//	UpperLimit:		Inclussive Upper Limit, null = +Infinity
//	Exception(s):	Must not equal this value.

/*	Date Valiation */
//	frmValid.ValidDate(element, DisplayFlag, Format, 
//                       LowerLimit, UpperLimit, Exception1, Exception2)
//
//	DisplayFlag:	true, false, or null (false)
//	Format:			
//					null (default) = 1
//					1) d/m/yyyy
//					2) m/d/yyyy
//
//	LowerLimit:		Inclussive Lower Limit, null = -Infinity
//	UpperLimit:		Inclussive Upper Limit, null = +Infinity
//	Exception(s):	Must not equal this value.

//	frmValid.ValidHours(element)
//	frmValid.ValidDateDmy(element)			/* in case of confusion, assumes dd/mm/yy */
//	frmValid.ValidDateMdy(element)			/* in case of confusion, assumes mm/dd/yy */
//	frmValid.ValidDateYmd(element)			/* in case of confusion, assumes yy/mm/dd */

/*	Other Validation */
//	frmValid.ValidZip(element)
//	frmValid.ValidSSNbr(element)
//	frmValid.ValidEmail(element)


//	---------------------------------- Elements Validations

/*	General vlaidation Functions: */
//	elemValid.NonBlank()
//	elemValid.ItemSelected()
//	elemValid.LengthUpTo(int length)
//	elemValid.ExactLength(element, int length)

/*	Numberic Validation */
//	elemValid.ValidNumber(DisplayFlag, Format, 
//                       LowerLimit, UpperLimit, Exception1, Exception2)
//
//	DisplayFlag:	true, false, or null (false)
//	Format:			Numeric (1), Integer(2), Numeric with commas(3), 
//					Integer with commas (4), or null (Numeric)
//	LowerLimit:		Inclussive Lower Limit, null = -Infinity
//	UpperLimit:		Inclussive Upper Limit, null = +Infinity
//	Exception(s):	Must not equal this value.



/*	Date Valiation */
//	elemValid.ValidDate(DisplayFlag, Format, 
//                       LowerLimit, UpperLimit, Exception1, Exception2)
//
//	DisplayFlag:	true, false, or null (false)
//	Format:			
//					null (default) = 1
//					1) d/m/yyyy
//					2) m/d/yyyy
//
//	LowerLimit:		Inclussive Lower Limit, null = -Infinity
//	UpperLimit:		Inclussive Upper Limit, null = +Infinity
//	Exception(s):	Must not equal this value.

//	elemValid.ValidHours()
//	elemValid.ValidDateDmy()			/* in case of confusion, assumes dd/mm/yy */
//	elemValid.ValidDateMdy()			/* in case of confusion, assumes mm/dd/yy */
//	elemValid.ValidDateYmd()			/* in case of confusion, assumes yy/mm/dd */

/*	Other Validation */
//	elemValid.ValidZip()
//	elemValid.ValidSSNbr()
//	elemValid.ValidEmail()

/*	Keyboads Events Validation */
//	elemValid.KpInteger()
//	elemValid.KpNumeric()
//	elemValid.KpCharacter()
//	elemValid.KpToUpper()
//	elemValid.KpToLower()



//===============================================
// return the display name of the document item
function display_name(item)
{
	var strDisplay = item.getAttribute("ValidationDisplayName");
	if (strDisplay==null || strDisplay=="")
	{
		strDisplay = item.getAttribute("name");
		if (strDisplay==null || strDisplay=="")
		{
			strDisplay = "Field";
		}
	}
	return strDisplay;
}

//===============================================
function default_value(item)
{
	var strDefault = item.ValidationDefaultValue;
	if (strDefault==null || strDefault=="")
	{
		strDefault = "";
	}
	return strDefault;
}

//===============================================
function trim_string()
{
	var ichar, icount;
	var strValue = this;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar) == ' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.lenght-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar, strValue.length);
	return strValue;
}

//===============================================
function date_toSimpleForm()
{
	var toSimpleForm = new String;
	toSimpleForm = this.toLocaleString();
	toSimpleForm = toSimpleForm.substring(0, toSimpleForm, indexOf(' '));
	return toSimpleForm;
}


//===============================================
function es_non_blank()
{
	var item = event.srcElement;
	event.returnValue = vs_non_blank(item);
}

function vs_non_blank(item)
{
	var strErrorMsg = display_name(item) + " يجب ان لا تكون خالية";
	item.value = item.value.Trim();
	if (item.value.length==0)
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
function es_valid_number1(lower, upper)
{
	alert ("es_valid_number1(lower, upper): "+lower+" "+upper);
	if (upper == null)
	{
		alert ("Upper is null");
	}
	if (lower == null)
	{
		alert ("Lower is null");
	}
}


//===============================================
function es_valid_number(DisplayFlag, Format, 
                         LowerLimit, UpperLimit, Exception1, Exception2)
{
	var item = event.srcElement;
	event.returnValue = vs_valid_number(item, DisplayFlag, Format, 
                        LowerLimit, UpperLimit, Exception1, Exception2);
}


function vs_valid_number(item, DisplayFlag, Format, 
                       LowerLimit, UpperLimit, Exception1, Exception2)
{
	var value = item.value.Trim();
	if (item.value.Trim().length==0)
	{
		return(true);			// Blank is always valid!
	}


	LowerLimit = "" + LowerLimit;
	UpperLimit = "" + UpperLimit;
	Exception1 = "" + Exception1;
	Exception2 = "" + Exception2;
/*	alert ("valid_number:\nitem = "+value+"\nDisplayFlag = "+DisplayFlag+
		    "\nFormat = "+Format+"\nLowerLimit = "+LowerLimit+
		    "\nUpperLimit = "+UpperLimit+"\nException1 = "+Exception1+
		    "\nException2 = "+Exception2);
*/
	var	ErrorValue = do_vs_valid_number(value, Format, 
                       LowerLimit, UpperLimit, Exception1, Exception2);

	if (!ErrorValue)		// No Error
	{
		if (DisplayFlag == true) {		// For testing only
	 		// alert ("Valid");
	 	}
		return (true);
	}
	else if ( (DisplayFlag == false) || (DisplayFlag == null))
	{
		return (false);
	}
	else
	{
		item.focus();
		switch (ErrorValue)
		{
			case 1:			// Wrong format
				alert(display_name(item) + " يجب ان تكون لها صيغة صحيحة");
				break;
			case 2:			// Wrong value
				alert(display_name(item) + " must have a valid value");
				break;
			case 3:			// Invalid parameters
				alert(display_name(item) + " Check called with Invalid Parameters");
				break;
			default:
				alert ("Error!");
				break;
		}
		return (false);
	}
}

function do_vs_valid_number(value, Format, 
                       LowerLimit, UpperLimit, Exception1, Exception2)
// returns (0) if valid
// Otherwise returns the error code
// 1 = Invalid Format
// 2 = Invalid value
// 3 = Invalid Limits
{
	if (!do_vs_valid_number_format(value, Format))
	{
		return (1);				// Invalid Format
	}
	value = StandardNumericFormat(value, Format);
	if ( (LowerLimit != "undefined") && (LowerLimit != "null") && (LowerLimit.Trim() != "") )
	{
		if  (!do_vs_valid_number_format(LowerLimit, Format))
		{
			return (3);				// Invalid Limits Format
		}
		LowerLimit = StandardNumericFormat(LowerLimit, Format);
		if (value < LowerLimit)
		{
			return (2);				// Invalid value
		}
	}
	if ( (UpperLimit != "undefined") && (UpperLimit != "null") && (UpperLimit.Trim() != "") )
	{
		if  (!do_vs_valid_number_format(UpperLimit, Format))
		{
			return (3);				// Invalid Limits Format
		}
		UpperLimit = StandardNumericFormat(UpperLimit, Format);
		if (value > UpperLimit)
		{
			return (2);				// Invalid value
		}
	}
	if ( (Exception1 != "undefined") && (Exception1 != "null") && (Exception1.Trim() != "") )
	{
		if  (!do_vs_valid_number_format(Exception1, Format))
		{
			return (3);				// Invalid Limits Format
		}
		Exception1 = StandardNumericFormat(Exception1, Format);
		if (value == Exception1)
		{
			return (2);				// Invalid value
		}
	}
	if ( (Exception2 != "undefined") && (Exception2 != "null") && (Exception2.Trim() != "") )
	{
		if  (!do_vs_valid_number_format(Exception2, Format))
		{
			return (3);				// Invalid Limits Format
		}
		Exception2 = StandardNumericFormat(Exception2, Format);
		if (value == Exception2)
		{
			return (2);				// Invalid value
		}
	}
	return(0);
}


function StandardNumericFormat(value, Format)		// Assumes a valid format already been checked
{
var s;
var i;
var StValue;
var Commas = new RegExp(",");

	StValue = "" + value;
	switch (Format)
	{
		case null:				// Default Numeric
		case 1:					// Numeric
			value = parseFloat(value);
			return (value);
			break;
		case 2:					// Integer
			value = parseInt(value);
			return (value);
			break;
		case 3:					// Numeric With Commas
			s = StValue.split(Commas);
			StValue = "";
			for (i=0; (s[i] != null); i++)
			{
				StValue += s[i];
			}
			value = parseFloat(StValue);
			return (value);
			break;
		case 4:					// Integer With Commas
			s = StValue.split(Commas);
			StValue = "";
			for (i=0; (s[i] != null); i++)
			{
				StValue += s[i];
			}
			value = parseInt(StValue);
			return (value);
			break;
		default:				// Default Numeric
			return (value);
			break;
	}
}

function do_vs_valid_number_format(value, Format)
{
	var StValue=value;

	if (typeof(value) == "number")
	{
		StValue = "" + value;
	}

	if (typeof(value) != "string")
	{
		return (false);			// Wrong Format
	}

	if (StValue.length == 0)
		return (true);			// Valid Field

	var ValidChars;
	switch (Format)
	{
		case null:				// Default Numeric
		case 1:					// Numeric
			ValidChars = "-.0123456789Ee";
			break;
		case 2:					// Integer
			ValidChars = "-0123456789Ee";
			break;
		case 3:					// Numeric With Commas
			ValidChars = "-,.0123456789Ee";
			break;
		case 4:					// Integer With Commas
			ValidChars = "-,0123456789Ee";
			break;
		default:				// Default Numeric
			ValidChars = "-.0123456789Ee";
			break;
	}
	for (var intLoop = 0; intLoop < StValue.length; intLoop++)
	{
		if (ValidChars.indexOf(StValue.charAt(intLoop)) == -1)
		{
			return (false);			// Wrong Format
		}
	}
	if (StValue.indexOf(".")!=StValue.lastIndexOf("."))
	{
		return (false);			// Wrong Format
	}
	if (StValue.indexOf("E")!=StValue.lastIndexOf("E"))
	{
		return (false);			// Wrong Format
	}
	if (StValue.indexOf("e")!=StValue.lastIndexOf("e"))
	{
		return (false);			// Wrong Format
	}
	if ( (StValue.indexOf("e")!= -1) && (StValue.lastIndexOf("E") != -1) )
	{
		return (false);			// Wrong Format
	}
	if ( (StValue.indexOf("e") == 0) || (StValue.lastIndexOf("E") == 0) )
	{
		return (false);			// Wrong Format
	}
	if ( (StValue.indexOf("e") == StValue.length) || (StValue.lastIndexOf("E") == StValue.length) )
	{
		return (false);			// Wrong Format
	}
	if ( (StValue.indexOf("-")!= -1) )
	{
		if ( (StValue.indexOf("-")!=StValue.lastIndexOf("-")) ||
			 (StValue.indexOf("-")!= 0) )
		{
			return (false);			// Wrong Format
		}
	}
	return (true);
}

//===============================================

//===============================================
function es_valid_hours()
{
	var item = event.srcElement;
	event.returnValue = vs_valid_hours(item);
}

function vs_valid_hours()
{
	var strErrorMsg = display_name(item);
	if (!vs_valid_number(item))
		return false;
	var itemValue = new Number(item.value);
	if (itemValue < 0 || itemValue > 80)
	{
		item.focus();
		alert(strErrorMsg + " must have a value from 0 to 80 hours");
		return false;
	}
	itemValue *= 4;
	if (itemValue != Math.ceil(itemValue))
	{
		item.focus();
		alert(strErrorMsg + " must be a valid quartely increment");
		return false;
	}
	return true;
}
//===============================================
function es_valid_date(DisplayFlag, Format, 
                         LowerLimit, UpperLimit, Exception1, Exception2)
{
	var item = event.srcElement;
	event.returnValue = vs_valid_date(item, DisplayFlag, Format, 
                         LowerLimit, UpperLimit, Exception1, Exception2);
}


function vs_valid_date(item, DisplayFlag, Format, 
                         LowerLimit, UpperLimit, Exception1, Exception2)
{
	var value = item.value.Trim();
	if (item.value.Trim().length==0)
	{
		return(true);			// Blank is always valid!
	}

	LowerLimit = "" + LowerLimit;
	UpperLimit = "" + UpperLimit;
	Exception1 = "" + Exception1;
	Exception2 = "" + Exception2;
/*
	alert ("valid_date:\nitem = "+value+"\nDisplayFlag = "+DisplayFlag+
		    "\nFormat = "+Format+"\nLowerLimit = "+LowerLimit+
		    "\nUpperLimit = "+UpperLimit+"\nException1 = "+Exception1+
		    "\nException2 = "+Exception2);
*/
	var	ErrorValue = do_vs_valid_date(value, Format, 
                       LowerLimit, UpperLimit, Exception1, Exception2);

	if (!ErrorValue)		// No Error
	{
		if (DisplayFlag == true) {		// For testing only
//	 		alert ("Valid");
	 	}
		return (true);
	}
	else if ( (DisplayFlag == false) || (DisplayFlag == null))
	{
		return (false);
	}
	else
	{
		item.focus();
		switch (ErrorValue)
		{
			case 1:			// Wrong format
				alert(display_name(item) + " must be a valid Format");
				break;
			case 2:			// Wrong value
				alert(display_name(item) + " must have a valid value");
				break;
			case 3:			// Invalid parameters
				alert(display_name(item) + " Check called with Invalid Parameters");
				break;
			default:
				alert ("Error!");
				break;
		}
		return (false);
	}
}
function do_vs_valid_date(value, Format, 
                       LowerLimit, UpperLimit, Exception1, Exception2)
// returns (0) if valid
// Otherwise returns the error code
// 1 = Invalid Format
// 2 = Invalid value
// 3 = Invalid Limits
{
	if (!do_vs_valid_date_format(value, Format))
	{
		return (1);				// Invalid Format
	}
	value = StandardDateFormat(value, Format);

	if ( (LowerLimit != "undefined") && (LowerLimit != "null") && (LowerLimit.Trim() != "") )
	{
		if  (!do_vs_valid_date_format(LowerLimit, Format))
		{
			return (3);				// Invalid Limits Format
		}
		LowerLimit = StandardDateFormat(LowerLimit, Format);
		if (Date.parse(value) < Date.parse(LowerLimit))
		{
			return (2);				// Invalid value
		}
	}
	if ( (UpperLimit != "undefined") && (UpperLimit != "null") && (UpperLimit.Trim() != "") )
	{
		if  (!do_vs_valid_date_format(UpperLimit, Format))
		{
			return (3);				// Invalid Limits Format
		}
		UpperLimit = StandardDateFormat(UpperLimit, Format);
		if (Date.parse(value) > Date.parse(UpperLimit))
		{
			return (2);				// Invalid value
		}
	}
	if ( (Exception1 != "undefined") && (Exception1 != "null") && (Exception1.Trim() != "") )
	{
		if  (!do_vs_valid_date_format(Exception1, Format))
		{
			return (3);				// Invalid Limits Format
		}
		Exception1 = StandardDateFormat(Exception1, Format);
		if (Date.parse(value) == Date.parse(Exception1))
		{
			return (2);				// Invalid value
		}
	}
	if ( (Exception2 != "undefined") && (Exception2 != "null") && (Exception2.Trim() != "") )
	{
		if  (!do_vs_valid_date_format(Exception2, Format))
		{
			return (3);				// Invalid Limits Format
		}
		Exception2 = StandardDateFormat(Exception2, Format);
		if (Date.parse(value) == Date.parse(Exception2))
		{
			return (2);				// Invalid value
		}
	}
	return(0);
}

function StandardDateFormat(value, Format)		/* To Be Done */
{
// Assumes a valid date...
	switch (Format)
	{
		case null:				// Default date
		case 1:					// m/d/yyyy
			var	s, temp;
			var DateSeparators = new RegExp("[-\/]");
			s = value.split(DateSeparators);
			var NewValue = new Date(parseInt(s[2]), parseInt(s[1])-1, parseInt(s[0]));
			return (NewValue);
			break;
		case 2:					// d/y/yyyy
			var	s, temp;
			var DateSeparators = new RegExp("[-\/]");
			s = value.split(DateSeparators);
			var NewValue = new Date(parseInt(s[2]), parseInt(s[0])-1, parseInt(s[1]));
			return (NewValue);
			break;
		default:				// Default Date
			return (value);
			break;
	}
}

function do_vs_valid_date_format(value, Format)
{
	switch (Format)
	{
		case	null:
		case	1:
			return (do_vs_valid_date_format__d_m_yyyy(value));
			break;
		case	2:
			return (do_vs_valid_date_format__m_d_yyyy(value));
			break;
		default:
			return (false);
			break;
	}
}

function do_vs_valid_date_format__m_d_yyyy(value)
{
	var DateSeparators = new RegExp("[-\/]");
	var i=0;
	var day, month, year;
	var	s;

	s = value.split(DateSeparators);
	for (i=0; (s[i] != null); i++)
		if (isNaN(s[i]) || i>2)
			return (false);

	if (typeof (s[2]) == "undefined")
	{
		return flase;
	}
	if (s[0].length > 2 || s[1].length > 2 || s[2].length != 4)
	{
		return(false);
	}
	day = parseInt(s[1]);
	month = parseInt(s[0]);
	year = parseInt(s[2]);

	if (year < 1000 || year > 9999)
	{
		return(false);
	}

	return (ckeck_vs_valid_date(year, month, day));
}

function do_vs_valid_date_format__d_m_yyyy(value)
{
	var DateSeparators = new RegExp("[-\/]");
	var i=0;
	var day, month, year;
	var	s;

	s = value.split(DateSeparators);
	for (i=0; (s[i] != null); i++)
		if (isNaN(s[i]) || i>2)
			return (false);

	if (typeof(s[2]) == "undefined")
	{
		return false;
	}
	if (s[0].length > 2 || s[1].length > 2 || s[2].length != 4)
	{
		return(false);
	}
	day = parseInt(s[0]);
	month = parseInt(s[1]);
	year = parseInt(s[2]);

	if (year < 1000 || year > 9999)
	{
		return(false);
	}

	return (ckeck_vs_valid_date(year, month, day));
}

function ckeck_vs_valid_date(year, month, day)
{
	if ( (year <= 0) || (month <= 0) || (month > 12) || (day <= 0) || (day > 31) )
	{
		return(false);
	}
	if (day == 31)
	{
		if (month == 2 || month == 4 || month == 6 | month == 9 || month == 11)
		{
			return false;
		}
	}
	else if (day == 30 && month == 2)
	{
		return false;
	}
	else if (day == 29 && month == 2)
	{
		if ((year % 400) == 0)
		{
		}
		else if ( ((year % 100) == 0) || ((year % 4) != 0))
		{
			return false;
		}
	}
	return true;
}

//===============================================
//function definition for use with the item change event
function es_item_selected()
{
		// alert("es_item_selected");
	var item = event.srcElement;
	event.returnValue = vs_item_selected(item);
}

//===============================================

// function definition to perform the item selected validation
function vs_item_selected(item)
{
		// alert("vs_item_selected");
	var strErrorMsg = display_name(item) + " must be a valid selection";
	// ensure the first item is not selected
	if (item.selectedIndex == 0)
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}


//===============================================
function es_valid_zip()
{
	var item = event.srcElement;
	event.returnValue = vs_valid_zip(item);
}

function vs_valid_zip(item)
{
	var strErrorMsg = display_name(item) + " must be of the form 99999-9999";
	item.value = item.value.Trim();
	if (!(/^\d{5}$/.test(item.value) || /^\d{5}-\d{4}$/.test(item.value)))
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
function es_valid_ssnbr()
{
	var item = event.srcElement;
	event.returnValue = vs_valid_ssnbr(item);
}

function vs_valid_ssnbr(item)
{
	var strErrorMsg = display_name(item) + " must be of the form 999-99-9999";
	item.value = item.value.Trim();
	if (!(/^\d{3}-\d{2}-\d{4}$/.test(item.value)))
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
function es_valid_email()
{
	var item = event.srcElement;
	event.returnValue = vs_valid_email(item);
}

function vs_valid_email(item)
{
	//var strErrorMsg = display_name(item) + " is not a valid Email";
	var strErrorMsg =  "'" + item.value + "'" + " : بريد الكترونى غير صحيح";
	item.value = item.value.Trim();
	if (!(/^[\w\.]+@[a-z\.]+$/.test(item.value)))
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
function es_length_up_to(length)
{
	var item = event.srcElement;
	event.returnValue = vs_length_up_to(item, length);
}

function vs_length_up_to(item, length)
{
	var strErrorMsg = " طول " + display_name(item) + "  لايجب ان تزيد عن  " + length + " حرف ";
	if (item.value.length > length)
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
function es_exact_length(length)
{
	var item = event.srcElement;
	event.returnValue = vs_exact_length(item, length);
}

function vs_exact_length(item, length)
{
	var strErrorMsg = display_name(item) + "  does not have valid length";
	if (item.value.length != length)
	{
		item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}

//===============================================
// This set of functions are for processing the key press event
// Used to restrict input on numerics and pure textual fields

//===============================================
function kp_integer()
{
	if ((event.keyCode < 48 || event.keyCode > 57))
		event.returnValue = false;
}

//===============================================
function kp_numeric()
{
	if ((event.keyCode != 46) && (event.keyCode < 48 || event.keyCode > 57))
		event.returnValue = false;
	if (event.keyCode == 46)
	{
		if (event.srcElement.value.indexOf(".") > -1)
			event.returnValue = false;			
	}
}

//===============================================
function kp_character()
{
	if ((event.keyCode < 65 || event.keyCode > 90) && 
	    (event.keyCode < 97 || event.keyCode > 122))
		event.returnValue = false;
}

//===============================================
function kp_convert_upper()
{
	if ((event.keyCode >= 97 && event.keyCode <= 122))
		event.keyCode -= 32;
}

//===============================================
function kp_convert_lower()
{
	if ((event.keyCode >= 65 && event.keyCode <= 90))
		event.keyCode += 32;
}

//===============================================
function vs_version()
{
	return(frmValid.VersionNumber);
}


//===============================================
//build the validation object
function elem_valid_setup()
{
	elemValid.NonBlank = es_non_blank;

	elemValid.ValidNumber = es_valid_number;

	elemValid.ValidHours = es_valid_hours;

	elemValid.ValidDate = es_valid_date;
	
	//elemValid.ValidDateDmy = es_valid_date_dmy;

	//elemValid.ValidDateMdy = es_valid_date_mdy;

	//elemValid.ValidDateYmd = es_valid_date_ymd;

	elemValid.ItemSelected = es_item_selected;

	elemValid.ValidZip = es_valid_zip;

	elemValid.ValidSSNbr = es_valid_ssnbr;

	elemValid.ValidEmail = es_valid_email;

	elemValid.LengthUpTo = es_length_up_to;

	elemValid.ExactLength = es_exact_length;

//build the keyPressInput object
	elemValid.KpInteger = kp_integer;
	elemValid.KpNumeric = kp_numeric;
	elemValid.KpCharacter = kp_character;
	elemValid.KpToUpper = kp_convert_upper;
	elemValid.KpToLower = kp_convert_lower;
}

function frm_valid_setup()
{
	frmValid.DefaultDateFormat = 1;			//dmy

	frmValid.NonBlank = vs_non_blank;

	frmValid.ValidNumber = vs_valid_number;

	frmValid.ValidHours = vs_valid_hours;

	frmValid.ValidDate = vs_valid_date;
	
	//frmValid.ValidDateDmy = vs_valid_date_dmy;

	//frmValid.ValidDateMdy = vs_valid_date_mdy;

	//frmValid.ValidDateYmd = vs_valid_date_ymd;

	frmValid.ItemSelected = vs_item_selected;

	frmValid.ValidZip = vs_valid_zip;

	frmValid.ValidSSNbr = vs_valid_ssnbr;

	frmValid.ValidEmail = vs_valid_email;

	frmValid.LengthUpTo = vs_length_up_to;

	frmValid.ExactLength = vs_exact_length;

	frmValid.Version = vs_version;
	
	frmValid.VersionNumber = "Version " + "1.0" + " Last updated on: 6 May 1999";

// Functions to test the key pressed
//	frmValid.element = es_;
//	frmValid. = vs_;
}



//===============================================
// Extend the string object to include a trim function
String.prototype.Trim = trim_string;

// Extend the date object to include a simple form string conversion
Date.prototype.toSimpleForm = date_toSimpleForm;

// Construct the validation object
// Construct the validation object
var frmValid = new Object;
frm_valid_setup();

var elemValid = new Object;
elem_valid_setup();

