

//******************************************************
//Date Created : 09/25/01  Pallavi Sher
//Purpose:	Basic Validation functions
//
//Last Modified : 03/12/02 DR
//********************************************
//
//	This javascript library contains the following functions:
//
//	validate(field,strVerify)
//
//	TrimString2(string)								Trims the string(used in ALL the below functions)
//
//	disableEnterKey(event)							Disables any action - when the Enter Key is pressed.
//	isEmpty(field)									Returns true if empty
//	isNotEmpty(field)								Returns true if Not empty
//
//	isLesser(field,compare_value)					Returns true if lesser than compare value
//	isGreater(field,compare_value)					Returns true if greater than compare value
//	isEqual(field,compare_value)					Returns true if equal to compare value
//	isNotEqual(field,compare_value)					Returns true if not equal to compare value
//	isLesserOrEqual(field,compare_value)			Returns true if lesser than or equal to compare value
//	isGreaterOrEqual(field,compare_value)			Returns true if greater than or equal to compare value
//
//	isNumber(field)									Checks for valid number
//	isDecimal(field)								Checks for valid decimal
//	isInteger(field)								Checks for valid integer
//	isPositive(field)								Checks for valid positive number
//	isNegative(field)								Checks for valid negative number
//
//	isAlpha(namestr)								Checks for characters(a-z A-Z)
//	isAlphaNumeric(field)							Checks for characters(a-z A-Z) or numbers(0-9)
//
//
//	convert_date(field1,bEmptyAllowed)				Converts supplied dates to format - hh:mm:ss AM/PM.
//	convert_month()									Function to convert mmm month to mm month
//	invalid_date(inField)							Returns invalid time error Called by convert_time()
//	validate_date(month2, day2, year2)				Validates date output form convert_date()
//	validate_year(inYear)							Called by convert_date() before validate_date()	
//
//	convert_time(field1,bEmptyAllowed)				Converts supplied dates to format - hh:mm:ss AM/PM.
//	convert_hour()									Converts 24h to 12h Called by convert_time()
//	invalid_time(inField)							Returns invalid time error Called by convert_time()
//	validate_time(hour2, minute2, second2, ampm2)	Validates date output form convert_time()
//
//
//	formatCurrency(field)	(Use formatMoney(field))Converts the value in the field to a valid $ currency format
//	phoneCheck(field)							Checks for valid US Phone number
//	emailCheck(field)							Checks for valid email
//	zipCheck(zipstr)								Checks for valid US zip code
//	creditCheck(field)							Checks for valid US Phone number
//  ccCodeCheck(field)						checks for valid format of visa/master security code
//	DateCheck_MY(field)			validate a date entered as mm/yy or mm/yyyy


//	formatMoney(field)						Converts the value in the given field to a valid $ currency format
//
// snapToTextBox(field)						sets the focus to the given field
// LimitTextArea(field,maxlimit)			allows only maxlimit number of characters to be entered in the text area.

function LimitTextArea(field,maxlimit,nameinalert) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		//field.value = field.value.substring(0, maxlimit);
		
		//alert(field.value.length);
		alert("The maximum number of characters the " + nameinalert + " can hold is " + maxlimit + ".\nMessage too long.");
		
		field.focus();
		field.select();
		return false;
	}
	else  // otherwise, update 'characters left' counter
	{
		//countfield.value = maxlimit - field.value.length;
		return true;
	}
}



//sets the focus to the given field

function snapToTextBox(field)
{
		field.focus();
			
}

//formats to dollar value.USE THIS

function formatMoney(field)
{
	if(TrimString(field.value)!='')
	{
	field.value = formatCurrencyValue(field.value);
	}
	else
	{
	field.value = formatCurrencyValue("0");
	}
}


//Created on : 07/25/2002 - By Pallavi Sher
//disable enter key -works only with IE
//

function disableEnterKey(event)
{ 	 
	var code = 0;
	code = event.keyCode;
	
	if (code==13)
	{
		//if(confirm("Do you want to submit ??")==true)
		//{
		//	alert("chose to submit");
		//	event.returnValue = false;
		//	event.cancelBubble = true;
		//	btnOK_onclick();
		//}
		//else
		//{
			event.returnValue = false;
			event.cancelBubble = true;
			
		//}
		
	}
	else
	{
		return true;
	}
}
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
// This function returns a true if  the value in the control is empty.
//************************************************************************

function isEmpty(field)
{
	var val = field.value;
	
	if(TrimString2(val)=="")
	{
		return true
		
	}
	else
	{
		return false;
	}

}
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is Not empty.
//************************************************************************

function isNotEmpty(field)
{
	var val = field.value;
	
	//alert('val is - ' + val);
	if(TrimString2(val)!="")
	{
		return true;
		
	}
	else
	{
		alert('This field cannot be empty !Please enter data !');
		field.focus();
		field.select();
		return false;
	}

}
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is lesser than the compare value.
//************************************************************************

function isLesser(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if(val < comp_val)
			{
				return true;
			}
			else
			{
				alert('The value entered should be lesser than : ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			//alert('The value is empty ! Cannot Validate !');
			/*
			alert('The value entered should be lesser than : ' + comp_val );
			field.focus();
			field.select();
			return false;			
			*/
			return true;
			
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate2 !');
		field.focus();
		field.select();
		return false;
			
	}
	
}
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is greater than the compare value.
//************************************************************************

function isGreater(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if(val > comp_val)
			{
				return true;
			}
			else
			{
				alert('The value entered should be greater than : ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			//alert('The value is empty ! Cannot Validate !');
			/*
			alert('The value entered should be greater than : ' + comp_val );
			field.focus();
			field.select();
			return false;			
			*/
			return true;
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate1 !');
		field.focus();
		field.select();
		return false;
			
	}
	
}

//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is equal to the compare value.
//********************************

function isEqual(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if(val == comp_val)
			{
				return true;
			}
			else
			{
				alert('The value entered should be equal to : ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			
			//alert('The value is empty ! Cannot Validate !');
			
			/*
			alert('The value entered should be equal to : ' + comp_val );
			field.focus();
			field.select();
			return false;
			*/
			return true;			
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate !');
		field.focus();
		field.select();
		return false;
			
	}
	
}


//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
// This function returns a true if  the value in the control is not equal to the compare value.
//********************************

function isNotEqual(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if(val != comp_val)
			{
				return true;
			}
			else
			{
				alert('The value entered should not be equal to : ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			
			//alert('The value is empty ! Cannot Validate !');
			
			/*
			alert('The value entered should not be equal to : ' + comp_val );
			field.focus();
			field.select();
			return false;
			*/
			return true;			
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate !');
		field.focus();
		field.select();
		return false;
			
	}
	
}


//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is lesser than or equal to the compare value.
//************************************************************************

function isLesserOrEqual(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if((val < comp_val)||(val == comp_val))
			{
				return true;
			}
			else
			{
				alert('The value entered should be lesser than OR equal to : ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			//alert('The value is empty ! Cannot Validate !');
			/*
			alert('The value entered should be lesser than OR equal to : ' + comp_val );
			field.focus();
			field.select();
			return false;			
			*/
			return true;
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate2 !');
		field.focus();
		field.select();
		return false;
			
	}
	
}

//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
// 
// This function returns a true if  the value in the control is greater than or equal to the compare value.
//************************************************************************

function isGreaterOrEqual(field,compare_value)
{
	var val = parseFloat(TrimString2(field.value));
	var comp_val = compare_value;
	
	//alert(val);
	//alert(comp_val);
	if(comp_val !="")
	{
		if(isFinite(val)==true)
		{
			if((val > comp_val)||(val == comp_val))
			{
				return true;
			}
			else
			{
				alert('The value entered should be greater than OR equal to: ' + comp_val );
				field.focus();
				field.select();
				return false;
			}
		
		}
		else
		{
			//alert('The value is empty ! Cannot Validate !');
			/*
			alert('The value entered should be greater than OR equal to: ' + comp_val );
			field.focus();
			field.select();
			return false;			
			*/
			return true;
		}
			
	}
	else
	{
		alert('The compare value is empty ! Cannot Validate1 !');
		field.focus();
		field.select();
		return false;
			
	}
	
}

//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
//  
//********************************
function isNumber(field) {
	var valid = "0123456789-."
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		alert("Sorry.  This field can only accept numbers.");
		field.focus();
		field.select();
		return false;
	}
	else
	{
		return true;
	}
 }

//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
//********************************
function isInteger(field) {
	var valid = "0123456789-"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		alert("Sorry. This field can only accept whole numbers.");
		field.focus();
		field.select();
		return false;
	}
	else
	{
		return true;
	}
 }

//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
//********************************
function isDecimal(field) {
	
	var val = field.value;
	
	if(isFinite(val)==true)
	{
		if(val.indexOf(".") != -1) 
		{
			return true;
		}
		else
		{
			//alert("Sorry. This field can only accept decimal numbers.");
			//field.focus();
			//field.select();
			//return false;
			//field.value=parseFloat(val);
			return true;
		}
	}
	else
	{
		alert("Invalid entry!  Only Numbers are accepted!");
		field.focus();
		field.select();
		return false;
	
	}
	
	/*
	var valid = "0123456789-."
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid entry!  Only numbers are accepted!");
		field.focus();
		field.select();
		return false;
	}
	else
	{
		return true;
	}*/
	
 }
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
//********************************
function isNegative(field) {
	
	var val = field.value;
	
	if(isFinite(val)==true)
	{
		if(val < 0) 
		{
			return true;
		}
		else
		{
			alert("Invalid entry!  Only Negative Integers are accepted!");
			field.focus();
			field.select();
			return false;
		}
	}
	else
	{
		alert("Invalid entry!  Only Integers are accepted!");
		field.focus();
		field.select();
		return false;
	
	}
	
 }
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/05/2002
// 
//********************************
function isPositive(field) {
	
	var val = field.value;
	
	if(isFinite(val)==true)
	{
		if(val >= 0) 
		{
			return true;
		}
		else
		{
			alert("Invalid entry!  Only Positive Integers are accepted!");
			field.focus();
			field.select();
			return false;
		}
	}
	else
	{
		alert("Invalid entry!  Only Integers are accepted!");
		field.focus();
		field.select();
		return false;
	
	}
	
 }
 
//********************************************
//******************
//Pallavi Sher
//  Date : 03/05/2002
//
//isAlpha(field) checks for characters(a-z A-Z) 
//*********************
function isAlpha(field) {
	var namestr = TrimString2(field.value);
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ."
	var ok = "yes";
	var temp;
	
	for (var i=0; i<namestr.length; i++) 
	{
		temp = "" + namestr.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") 
	{
		alert("Invalid entry!Data can have only characters(a-z and A-z)!");
		field.focus();
		field.select();
		return false;
	}
	
}

//********************************************
//******************
//Pallavi Sher
//  Date : 03/05/2002
// 
//
//isAlphaNumeric(field) checks for characters(a-z A-Z) and Numbers(0-9)
//*********************
function isAlphaNumeric(field) {
	var str = TrimString2(field.value);
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .0123456789"
	var ok = "yes";
	var temp;
	
	for (var i=0; i<str.length; i++) 
	{
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (ok == "no") 
	{
		alert("Invalid entry!Data can have only characters(a-z and A-z) and Numbers (0-9)!");
		field.focus();
		field.select();
		return false;
	}
	
}

/******************************************************************
   convert_date()
   DR 04/20/2001
   Modified to:
   Function to convert supplied dates to format - mm/dd/yyyy.
	Valid input dates = 
		mmddyy, mmmddyy, mmddyyyy, mmmddyyyy,
		m/d/yy, m/dd/yy, mm/d/yy, mm/dd/yy, mmm/d/yy, mmm/dd/yy,
		m/d/yyyy, m/dd/yyyy, mm/d/yyyy, mm/dd/yyyy, mmm/d/yyyy, mmm/dd/yyyy
	Valid date seperators =
		'-','.','/',' ',':','_',','
	
   
*******************************************************************/   
/******************************************************************   
   Function to convert supplied dates to format - mm/dd/yyyy.
	Valid input dates = 
		ddmmyy, ddmmmyy, ddmmyyyy, ddmmmyyyy,
		d/m/yy, dd/m/yy, d/mm/yy, dd/mm/yy, d/mmm/yy, dd/mmm/yy,
		d/m/yyyy, dd/m/yyyy, d/mm/yyyy, dd/mm/yyyy, d/mmm/yyyy, dd/mmm/yyyy
	Valid date seperators =
		'-','.','/',' ',':','_',','
		
	Calls convert_month()
			invalid_date()
			validate_date()
			validate_year()
     
   Author: Simon Kneafsey 
   Email: simonkneafsey@hotmail.com
   WebSite: www.simonkneafsey.co.uk
   Date Created: 4/9/00
   
   Notes: Please feel free to use/edit this script.  If you do please keep my comments and details 
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
//function convert_date(field1)
function convert_date(field1,bEmptyAllowed)
{
var fLength = field1.value.length; // Length of supplied field in characters.
var divider_values = new Array ('-','.','/',' ',':','_',','); // Array to hold permitted date seperators.  Add in '\' value
var array_elements = 7; // Number of elements in the array - divider_values.
var day1 = new String(null); // day value holder
var month1 = new String(null); // month value holder
var year1 = new String(null); // year value holder
var divider1 = null; // divider holder
var outdate1 = null; // formatted date to send back to calling field holder
var counter1 = 0; // counter for divider looping 
var divider_holder = new Array ('0','0','0'); // array to hold positions of dividers in dates
var s = String(field1.value); // supplied date value variable

////If field is empty do nothing
//if ( fLength == 0 ) {
//	return true;
//}

// DR 04/20/2001
if ( fLength == 0 ) {
	if (( bEmptyAllowed == 'true' )||( bEmptyAllowed == "true" )||(bEmptyAllowed==1)) {
		return true;
	}
	else {
		alert("This field may not be empty.");  
		
		var newDate1 = new Date();
	
		if (navigator.appName == "Netscape") {
    		var myYear1 = newDate1.getYear() + 1900;
  		}
  		else {
  			var myYear1 =newDate1.getYear();
  		}
  
		var myMonth1 = newDate1.getMonth()+1;  
		var myDay1 = newDate1.getDate();
	
		field1.value = myMonth1 + "/" + myDay1 + "/" + myYear1;		
		fLength = field1.value.length;//re-evaluate string length.
		s = String(field1.value)//re-evaluate the string value.
	}
}


// Deal with today or now
if ( field1.value.toUpperCase() == 'NOW' || field1.value.toUpperCase() == 'TODAY' ) {
   
	var newDate1 = new Date();
	
  		if (navigator.appName == "Netscape") {
    		var myYear1 = newDate1.getYear() + 1900;
  		}
  		else {
  			var myYear1 =newDate1.getYear();
  		}
  
	var myMonth1 = newDate1.getMonth()+1;  
	var myDay1 = newDate1.getDate();
	// DR 04/20/2001:
	field1.value = myMonth1 + "/" + myDay1 + "/" + myYear1;		
	//field1.value = myDay1 + "/" + myMonth1 + "/" + myYear1;
	fLength = field1.value.length;//re-evaluate string length.
	s = String(field1.value)//re-evaluate the string value.
}

//Check the date is the required length
if ( fLength != 0 && (fLength < 6 || fLength > 11) ) {
	invalid_date(field1);
	return false;   
	}

// Find position and type of divider in the date
for ( var i=0; i<3; i++ ) {
	for ( var x=0; x<array_elements; x++ ) {
		if ( s.indexOf(divider_values[x], counter1) != -1 ) {
			divider1 = divider_values[x];
			divider_holder[i] = s.indexOf(divider_values[x], counter1);
		   //alert(i + " divider1 = " + divider_holder[i]);
			counter1 = divider_holder[i] + 1;
			//alert(i + " counter1 = " + counter1);
			break;
		}
 	}
 }

// if element 2 is not 0 then more than 2 dividers have been found so date is invalid.
if ( divider_holder[2] != 0 ) {
   invalid_date(field1);
	return false;   
}

// See if no dividers are present in the date string.
if ( divider_holder[0] == 0 && divider_holder[1] == 0 ) { 
   
		//continue processing
		// DR 04/20/2001:
		//if ( fLength == 6 ) {//ddmmyy
		//day1 = field1.value.substring(0,2);
		//	month1 = field1.value.substring(2,4);
		if ( fLength == 6 ) {//mmddyy
		month1 = field1.value.substring(0,2);
   			day1 = field1.value.substring(2,4);
     		year1 = field1.value.substring(4,6);
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
		// DR 04/20/2001:	
		//else if ( fLength == 7 ) {//ddmmmy [sic]
   		//day1 = field1.value.substring(0,2);
  		//	month1 = field1.value.substring(2,5);
  		else if ( fLength == 7 ) {//mmmddyy
   		month1 = field1.value.substring(0,3);
  			day1 = field1.value.substring(3,5);
  			year1 = field1.value.substring(5,7);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
		// DR 04/20/2001:
		//else if ( fLength == 8 ) {//ddmmyyyy
   		//day1 = field1.value.substring(0,2);
  		//	month1 = field1.value.substring(2,4);
  		else if ( fLength == 8 ) {//mmddyyyy
   		month1 = field1.value.substring(0,2);
  			day1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,8);
			}
		// DR 04/20/2001:
		//else if ( fLength == 9 ) {//ddmmmyyyy
   		//day1 = field1.value.substring(0,2);
  		//	month1 = field1.value.substring(2,5);
  		else if ( fLength == 9 ) {//mmmddyyyy
   		month1 = field1.value.substring(0,3);
  			day1 = field1.value.substring(3,5);
  			year1 = field1.value.substring(5,9);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
		
		// DR 04/20/2001:
		if ( (outdate1 = validate_date(month1,day1,year1)) == false ) {
		//if ( (outdate1 = validate_date(day1,month1,year1)) == false ) {
   		alert("The value " + field1.value + " is not a vaild date.\n\r" +  
			"Please enter a valid date in the format mm/dd/yyyy");	
			//"Please enter a valid date in the format dd/mm/yyyy");	
			field1.focus();
			field1.select();
			return false;
			}

		field1.value = outdate1;
		return true;// All OK
		}
		
// 2 dividers are present so continue to process	
if ( divider_holder[0] != 0 && divider_holder[1] != 0 ) { 	
	// DR 04/20/2001:
  	//day1 = field1.value.substring(0, divider_holder[0]);
  	//month1 = field1.value.substring(divider_holder[0] + 1, divider_holder[1]);
  	month1 = field1.value.substring(0, divider_holder[0]);
  	day1 = field1.value.substring(divider_holder[0] + 1, divider_holder[1]);
  	//alert(month1);
  	year1 = field1.value.substring(divider_holder[1] + 1, field1.value.length);
	}

if ( isNaN(day1) && isNaN(year1) ) { // Check day and year are numeric
	invalid_date(field1);
	return false;  
   }

if ( day1.length == 1 ) { //Make d day dd
   day1 = '0' + day1;  
}

if ( month1.length == 1 ) {//Make m month mm
	month1 = '0' + month1;   
}

if ( year1.length == 2 ) {//Make yy year yyyy
   if ( (year1 = validate_year(year1)) == false ) {
   	invalid_date(field1);
		return false;  
		}
}

if ( month1.length == 3 || month1.length == 4 ) {//Make mmm month mm
   if ( (month1 = convert_month(month1)) == false) {
   	alert("month1" + month1);
   	invalid_date(field1);
   	return false;  
   }
}

// Date components are OK
if ( (month1.length == 2 || day1.length == 2 || year1.length == 4) == false) {
   invalid_date(field1);
   return false;
}

//Validate the date
// DR 04/20/2001:
if ( (outdate1 = validate_date(month1, day1, year1)) == false ) {
//if ( (outdate1 = validate_date(day1, month1, year1)) == false ) {
   alert("The value " + field1.value + " is not a vaild date.\n\r" +  
	"Please enter a valid date in the format mm/dd/yyyy");
	//"Please enter a valid date in the format dd/mm/yyyy");
	field1.focus();
	field1.select();
	return false;
}

// DR 04/20/2001
// Redisplay the date in mm/dd/yyyy format
// Redisplay the date in dd/mm/yyyy format
field1.value = outdate1;
return true;//All is well

}
/******************************************************************
   convert_month()
   
   Function to convert mmm month to mm month 
   
   Called by convert_date()    
   
   Author: Simon Kneafsey 
   Date Created: 4/9/00
   Email: simonkneafsey@hotmail.com
   WebSite: www.simonkneafsey.co.uk
   
   Notes:P lease feel free to use/edit this script.  If you do please keep my comments and details 
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
function convert_month(monthIn) {

var month_values = new Array ("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");

monthIn = monthIn.toUpperCase(); 

if ( monthIn.length == 3 ) {
	for ( var i=0; i<12; i++ ) 
		{
   	if ( monthIn == month_values[i] ) 
   		{
			monthIn = i + 1;
			if ( i != 10 && i != 11 && i != 12 ) 
				{
   			monthIn = '0' + monthIn;
				}
			return monthIn;
			}
		}
	}

else if ( monthIn.length == 4 && monthIn == 'SEPT') {
   monthIn = '09';
   return monthIn;
	}
	
else {
	return false;
	} 
}
/******************************************************************
   invalid_date()
   
   If an entered date is deemed to be invalid, invali
   d_date() is called to display a warning message to
   the user.  Also returns focus to the date  in que
   stion and selects the date for edit.
        
   Called by convert_date()
   
   Author: Simon Kneafsey
   Date Created: 4/9/00
   Email: simonkneafsey@hotmail.com
   WebSite: www.simonkneafsey.co.uk
   
   Notes: Please feel free to use/edit this script.  If you do please keep my comments and details 
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
function invalid_date(inField) 
{
alert("The value " + inField.value + " is not in a valid date format.\n\r" + 
        "Please enter date in the format mm/dd/yyyy");
        // DR 04/20/2001
        //"Please enter date in the format dd/mm/yyyy");
inField.focus();
inField.select();
return true   
}
/******************************************************************
   validate_date()
   
   Validates date output from convert_date().  Checks
   day is valid for month, leap years, month !> 12,.
   
   Author: Simon Kneafsey
   Date Created: 4/9/00
   Email: simonkneafsey@hotmail.com
   WebSite: www.simonkneafsey.co.uk
   
   Notes: Please feel free to use/edit this script.  If you do please keep my comments and details 
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
// DR 04/20/2001
function validate_date(month2, day2, year2)
//function validate_date(day2, month2, year2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
// DR 04/20/2001:
var inpDate = month2 + day2 + year2;
//var inpDate = day2 + month2 + year2;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

//Check ddmmyyyy date supplied
if (! filter.test(inpDate))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
/* Check Valid Month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
if (! filter.test(month2))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
/* Check For Leap Year */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
var N = Number(year2);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
   DayArray[1]=29;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
  	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
/* Check for valid days for month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
for(var ctr=0; ctr<=11; ctr++)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
   if (MonthArray[ctr]==month2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
   	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
      if (day2<= DayArray[ctr] && day2 >0 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
        {
        // DR 04/20/2001
        //inpDate = day2 + '/' + month2 + '/' + year2;
        inpDate = month2 + '/' + day2 + '/' + year2;              
        return inpDate;
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
      else                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
        return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
   	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
   }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
}
/******************************************************************
   validate_year()
   
   converts yy years to yyyy
   Uses a hinge date of 10
        < 10 = 20yy 
        => 10 = 19yy.
         
   Called by convert_date() before validate_date().
      
   Author: Simon Kneafsey 
   Date Created: 4/9/00
   Email: simonkneafsey@hotmail.com
   WebSite: www.simonkneafsey.co.uk
   
   Notes: Please feel free to use/edit this script.  If you do please keep my comments and details 
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
function validate_year(inYear) 
{
if ( inYear < 10 ) 
	{
   inYear = "20" + inYear;
   return inYear;
	}
else if ( inYear >= 10 )
	{
   inYear = "19" + inYear;
   return inYear;
	}
else 
	{
	return false;
	}   
}

//********************************************




/******************************************************************
   convert_time()
   DR 06/11/2001
   Modified to:
   Function to convert supplied dates to format - hh:mm:ss AM/PM.
	Valid input times = 
		hhmmss, hhmm, hmmss, hmm, 
		hhmmssA, hhmmA, hmmssA, hmmA, 
		hh:mm:ss, hh:mm, h:mm:ss, h:m:ss, h:m:s, h:m,
		hh:mm:ssA, hh:mmA, h:mm:ssA, h:m:ssA, h:m:sA, h:mA //,
		// not these (for now) hh:mm:ss A, hh:mm A, h:mm:ss A, h:m:ss A, h:m:s A, h:m A    
	Valid AM/PM designators =
		'A', 'a', 'p', 'P'
	Valid time seperators =
		'-', '.', '/', ' ', ':', '_', ','
	
	Calls 	convert_ampm()
			convert_hour()
			invalid_time()
			validate_time()
   
   Author: David Roberts
   Date Created: 6/11/01
   
   Notes: Please feel free to use/edit this script.  If you do please update comments.
*******************************************************************/
function convert_time(field1,bEmptyAllowed)
{
var temp_holder=0;
var fLength = field1.value.length; // Length of supplied field in characters.
var fValue = field1.value; // Value of supplied field in characters.
var divider_values = new Array ('-', '.', '/', ' ', ':' ,'_' , ','); // Array to hold permitted time seperators.  Add in '\' value
var array_elements = 7; // Number of elements in the array - divider_values.
var designator_values = new Array ('A','P'); // Array to hold permitted am/pm designators.
var array_elementsd = 2; // Number of elements in the array - divider_values.
var hour1 = new String(null); // hour value holder
var minute1 = new String(null); // minute value holder
var second1 = new String(null); // second value holder
var ampm1 = new String(null); // designator value holder
var outtime1 = null; // formatted time to send back to calling field holder
var counter1 = 0; // counter for divider looping 
var divider_holder = new Array ('0','0','0','0'); // array to hold positions of dividers in times
var s = String(field1.value); // supplied time value variable
var ts = new String(null); //temporary string for various purposes
var nfilter=/^[0-9]{1}$/; //numeric filter regular expression

if ( fLength == 0 ) {
	if (( bEmptyAllowed == 'true' )||( bEmptyAllowed == "true" )||( bEmptyAllowed == 1 )) {
		
		return true;
	}
	else {
		alert("This field may not be empty.");  
		
		var newDate1, myHour1, myMinute1, mySecond1, myAmpm1
		
		newDate1 = new Date();
		myHour1 = newDate1.getHours();
		myMinute1 = newDate1.getMinutes();
		mySecond1 = newDate1.getSeconds();
		if (myHour1 > 11){
			myAmpm1 = 'PM';
			}
			else{
			myAmpm1 = 'AM';
		}
		myHour1 = convert_hour(myHour1);
		field1.value = myHour1 + ":" + myMinute1 + ":" + mySecond1 + " " + myAmpm1;		
		fLength = field1.value.length;//re-evaluate string length.
		s = String(field1.value)//re-evaluate the string value.
		//return true;
	}
}
// Deal with today or now
if ( field1.value.toUpperCase() == 'NOW' || field1.value.toUpperCase() == 'TODAY' ) {
   
	var newDate1 = new Date();
	
	var myHour1 =newDate1.getHours();
	var myMinute1 = newDate1.getMinutes();  
	var mySecond1 = newDate1.getSeconds();
	
	if (myHour1 > 11){
		myAmpm1 = 'PM';
		}
		else{
		myAmpm1 = 'AM';
	}
	myHour1 = convert_hour(myHour1);
	
	
	field1.value = myHour1 + ":" + myMinute1 + ":" + mySecond1 + " " + myAmpm1;
	fLength = field1.value.length;//re-evaluate string length.
	s = String(field1.value)//re-evaluate the string value.
	//return true;
}

// Deal with noon
if ( field1.value.toUpperCase() == 'NOON' ) {
   	field1.value = "12:00:00 PM";
	fLength = field1.value.length;//re-evaluate string length.
	s = String(field1.value)//re-evaluate the string value.
	//return true;
}

//Check the date is the required length [(hmm)..(hh:mm:ss AM)]
if ( fLength != 0 && (fLength < 3 || fLength > 11) ) {
//alert("Calling invalid_time...dr1164-1");
	invalid_time(field1);
	return false;   
	}

// Find position(s) of divider(s) in the time upto 4 dividers
counter1=0;
temp_holder=0;
for ( var i=0; i<4; i++ ) {
	for ( var counter2=0; counter2<fLength; counter2++) {
		for ( var x=counter1; x<array_elements; x++ ) {
			if ( s.substring(counter2, counter2 +1) == divider_values[x] ) {
				divider_holder[i] = counter2;
				i++;
				counter2++;
			}
		}
 	}
 }
		
//now sort array
divider_holder=divider_holder.sort();
temp_holder = divider_holder[0];
for (var i=0; i<3; i++) {
	divider_holder[i] = divider_holder[i+1];
}
divider_holder[3] = temp_holder;

// if element 3 is not 0 then more than 3 dividers have been found so date is invalid.
if ( divider_holder[3] != 0 ) {
//alert("Calling invalid_time...dr1164-2");
   invalid_date(field1);
	return false;   
}

// See if no dividers are present in the date string.
if ( divider_holder[0] == 0 && divider_holder[1] == 0 && divider_holder[2] == 0 ) { 
   
		//continue processing
		
		if ( fLength == 3 ) {//hmm
			//alert("fLength == 3");
			hour1 = field1.value.substring(0,1);
   			minute1 = field1.value.substring(1,3);
     		second1 = "00";
     		ampm1 = "";
  			
			}
			
		else if ( fLength == 4 ) {//hhmm or hmmA
		
			if (!nfilter.test(field1.value.substring(3,4))){//hmmA
				//alert("//hmmA");
				hour1 = field1.value.substring(0,1);
   				minute1 = field1.value.substring(1,3);
     			second1 = "00";
     			ampm1 = field1.value.substring(3,4).toUpperCase() + "M";
     			
     			}
     		else {//hhmm
     			//alert("//hhmm");
     			hour1 = field1.value.substring(0,2);
   				minute1 = field1.value.substring(2,4);
     			second1 = "00";
     			ampm1 = "";
     			
     			}
     		
  			
			}

		else if ( fLength == 5 ) {//hmmss or hhmmA
			//alert("fLength == 5");
			if (!nfilter.test(field1.value.substring(4,5))){//hhmmA
				hour1 = field1.value.substring(0,2);
   				minute1 = field1.value.substring(2,4);
     			second1 = "00";
     			ampm1 = field1.value.substring(4,5).toUpperCase() + "M";
     			}
     		else {//hmmss
     			hour1 = field1.value.substring(0,1);
   				minute1 = field1.value.substring(1,3);
     			second1 = field1.value.substring(3,5);
     			ampm1 = "";
     			}
     		
  			
			}

		else if ( fLength == 6 ) {//hhmmss or hmmssA
			//alert("fLength == 6");
			if (!nfilter.test(field1.value.substring(5,6))){//hmmssA
				hour1 = field1.value.substring(0,1);
   				minute1 = field1.value.substring(1,3);
     			second1 = field1.value.substring(3,5);
     			ampm1 = field1.value.substring(5,6).toUpperCase() + "M";
     			}
     		else {//hhmmss
     			hour1 = field1.value.substring(0,2);
   				minute1 = field1.value.substring(2,4);
     			second1 = field1.value.substring(4,6);
     			ampm1 = "";
     			}
     		
  		
			}
			
		else if ( fLength == 7 ) {//hhmmssA
			//alert("fLength == 7");
			hour1 = field1.value.substring(0,2);
   			minute1 = field1.value.substring(2,4);
     		second1 = field1.value.substring(4,6);
     		ampm1 = field1.value.substring(6,7).toUpperCase() + "M";
     		
     		
  		
			}
		
		//else if ( fLength == 8 ) {//hhmmssAM
		//	alert("fLength == 8");
		//	hour1 = field1.value.substring(0,2);
   		//	minute1 = field1.value.substring(2,2);
     	//	second1 = field1.value.substring(4,2);
     	//	//ampm1 = field1.value.substring(6,2).toUpperCase();
     	//	ampm1 = field1.value.substring(6,2);
     	//	
     	//
		//	}
		
//		alert("Just before if statement...hour1=" + hour1 + "; minute1=" + minute1 +"; second1=" + second1 + ";ampm1=" + ampm1);
		
		if ( (outtime1 = validate_time(hour1,minute1,second1,ampm1)) == false ) {
		alert("The value " + field1.value + " is not a valid time.\n\r" +  
			"Please enter a valid time in the format hh:mm:ss AM/PM\n\r"); //+
			//"Only a single 'A' or 'P' is allowed for AM/PM designation.");	
			field1.focus();
			field1.select();
			return false;
			}

		field1.value = outtime1;
		return true;// All OK
		}
		
// 3 dividers are present so continue to process	
if ( divider_holder[0] != 0 && divider_holder[1] != 0 && divider_holder[2] != 0) { 	
	// DR 04/20/2001:
  	hour1 = field1.value.substring(0, divider_holder[0]);
  	minute1 = field1.value.substring(divider_holder[0] + 1, divider_holder[1]);
  	second1 = field1.value.substring(divider_holder[1] + 1, divider_holder[2]);
  	ampm1 = field1.value.substring(divider_holder[2] + 1, field1.value.length);
	}

if ( hour1.length == 1 ) { //Make h hour hh
   hour1 = '0' + hour1;
}

if ( minute1.length == 1 ) {//Make m minute mm
	minute1 = '0' + minute1;
}

if ( second1.length == 1 ) {//Make s second ss
	second1 = '0' + second1;
}

// Check for AM/PM info
if ( second1.length == 3 || second1.length == 4 ) {//Make ssA or ssAM second ss AM second ampm
	ampm1 = second1.substring(2,(second1.length-2))
	ampm1 = ampm1.toUpperCase()
	second1 = second1.substring(0,2)
	}
else if ( second1.lenght == 2) {//Make ampm1 AM (default)
	ampm1 = 'AM'
	}

if ( ampm1.length == 1 ) {//Make s second ss
	ampm1 = ampm1.toUpperCase() + 'M';
}


// Time components are OK
if ( (hour1.length == 2 || minute1.length == 2 || second1.length == 2 || ampm1.lenght == 2) == false) {
//alert("Calling invalid_time...dr1164-4");
   invalid_time(field1);
   return false;
}

//Validate the time
if ( (outtime1 = validate_time(hour1, minute1, second1, ampm1)) == false ) {
   alert("The value " + field1.value + " is not a valid time.\n\r" +  
	"Please enter a valid time in the format hh:mm:ss AM/PM");
	field1.focus();
	field1.select();
	return false;
}

// Redisplay the date in hh:mm:ss AM/PM format
field1.value = outtime1;
return true;//All is well

}

/******************************************************************
   convert_hour()
   
   Function to convert 24h to 12h
   
   Called by convert_time()    
*******************************************************************/
function convert_hour(hourIn) {

var hour_values = new Array ("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","00");

hourIn = hourIn.toString(); 
if ( hourIn.length == 2 ) {
	for ( var i=0; i<12; i++ ) 
		{
   	if ( hourIn == hour_values[i] ) 
   		{
			hourIn = i + 1;
			if ( i != 9 && i != 10 && i != 11 ) 
				{
   			hourIn = '0' + hourIn;
				}
			return hourIn;
			}
		}
	for ( var i=0; i<12; i++ ) 
		{
   	if ( hourIn == hour_values[i+12] ) 
   		{
			hourIn = i + 1;
			if ( i != 9 && i != 10 && i != 11 ) 
				{
   			hourIn = '0' + hourIn;
				}
			return hourIn;
			}
		}
	}

else if ( hourIn.length == 2 && hourIn == '12') {
   hourIn = '12';
   return hourIn;
	}

else if ( hourIn.length == 2 && hourIn == '11') {
   hourIn = '11';
   return hourIn;
	}

else if ( hourIn.length == 2 && hourIn == '10') {
   hourIn = '10';
   return hourIn;
	}

else if ( hourIn.length == 1 && hourIn == '0') {
   hourIn = '12';
   return hourIn;
	}

else if ( hourIn.length == 1 ) {
   hourIn = '0' + hourIn;
   return hourIn;
	}

	
else {
	return false;
	} 
}

/******************************************************************
   invalid_time()
******************************************************************/
function invalid_time(inField) 
{
alert("The value " + inField.value + " is not in a valid time format.\n\r" + 
        "Please enter date in the format hh:mm:ss AM/PM");
        
inField.focus();
inField.select();
return true;
}

/******************************************************************
   validate_time()
   
   Validates date output from convert_time().
*******************************************************************/
function validate_time(hour2, minute2, second2, ampm2)
{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

if (hour2 > 11 && hour2 < 24){
	if ( ampm2.length == 0 ) {//Make it PM
	ampm2 = 'PM';
	}
}

if ( ampm2.length == 0 ) {//Make s second ss
	ampm2 = ampm2 + 'AM';
}

if ( ampm2.length == 1 ) {//Make s second ss
	ampm2 = ampm2 + 'M';
}

ampm2 = ampm2.toUpperCase()

hour2=convert_hour(hour2);
minute2 = minute2 * 1 + 0; // convert string to number
second2 = second2 * 1 + 0; // convert string to number

if (minute2 > 59) {
	minute2 = minute2 - 60;
}

if (minute2 < 10) {
	minute2 = '0' + minute2.toString();
}

if ((second2 * 1) > 59) {
	second2 = second2 - 60;
}

if (second2 < 10) {
	second2 = '0' + second2.toString();
}
	minute2 = minute2.toString(); //back to string
	second2 = second2.toString(); //back to string
	
if ( minute2.length == 1 ) {//Make m minute mm
	minute2 = '0' + minute2;
}

if ( second2.length == 1 ) {//Make s second ss
	second2 = '0' + second2;
}

var inpDate = hour2 + minute2 + second2;
var filter=/^[0-9]{2}[0-9]{2}[0-9]{2}$/;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

//Check hhmmss time supplied
if (! filter.test(inpDate))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  { 
  //alert("filter test failed")                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
/* Check Valid AM/PM */
else if (!(ampm2 == 'AM' || ampm2 == 'PM'))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  {
  //alert("AM/PM test failed")                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  } 
else {
	inpDate = hour2 + ':' + minute2 + ':' + second2 + ' ' + ampm2;
    return inpDate;
  }
}

//************************************************************************
// Added on 02/07/2002 : Pallavi Sher
// 
//********************************
function formatCurrency(field) {
	
	var num=TrimString2(field.value);
	
	if((num!='') && (num!=0))
	{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	
	
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
		field.value= (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	return true
}

//********************************************
//************
//Pallavi Sher - 09/26/01
//phoneCheck(field) checks for valid US phone number
//
//**********
function phoneCheck(field) {
  var phonestr=TrimString2(field.value);
     // 5135330838 format
   
  str = phonestr;
  if ((str.length ==10)==false) 
  { 
    alert("Phone number must be in the format ##########.Cannot be more than 10 digits long.[like 5135330838]");
    return false;
  }
  
  len = str.length;
  for (i = 0; i < len; i++) 
  {
   c = str.charAt(i);
		/*if (i == 3) 
		{
				if (c != "-") 
				{ 
				    alert("Phone number must be in the format ###-###-#### .[like 513-533-0838]");
				    return false; 
				}
		} 
		if(i == 7)
		{
				
				if (c != "-") 
				{ 
					alert("Phone number must be in the format ###-###-#### .[like 513-533-0838]");
				    return false;
				}		
		}
   
		if(i!=3 && i!=7)
		{
		*/
	if((c < "0") || (c > "9"))
	{
			alert("Phone number must be in the format ########## .[like 5135330838]");
	    return false;
	}
		 //}
   
  }
  return true;
}

//********************************************
//************
//Pallavi Sher - 05/02/2003
//creditCheck(field) checks for valid credit card number
//
//**********
function creditCheck(field) {
  var str=TrimString2(field.value);
  // 1234123412341234 format
      
  if ((str.length ==16)==false) 
  { 
    alert("Credit Card Number must be in the format ################ .[like 4234123412341234]");
    return false;
  }
  
  len = str.length;
  for (i = 0; i < len; i++) 
  {
   c = str.charAt(i);
   /*if (i == 4) 
   {
		if (c != "-") 
		{ 
		    alert("Credit Card Number must be in the format ####-####-####-#### .[like 4234-1234-1234-1234]");
		    return false; 
		}
   } 
   if(i == 9)
   {
		
		if (c != "-") 
		{ 
			alert("Credit Card Number must be in the format ####-####-####-#### .[like 4234-1234-1234-1234]");
		    return false;
		}		
   }
   if(i == 14)
   {
		
		if (c != "-") 
		{ 
			alert("Credit Card Number must be in the format ####-####-####-#### .[like 4234-1234-1234-1234]");
		    return false;
		}		
   }
   
   if(i!=4 && i!=9 && i!=14)
   {
   */
		if((c < "0") || (c > "9"))
		{
			alert("Invalid character in Credit Card Number.\nCredit Card Number must be in the format ################ .[like 4234123412341234]");
		    return false;
		}
		
		if(i==0)
		{
			if (c != "4" && c !="5") 
			{ 
			    alert("Please enter a valid Visa/Master credit card number .[like 4234123412341234]");
			    return false; 
			}
		
		}
		
   //}
   
  }
  return true;
}
//********************************************
//************
//Pallavi Sher - 05/20/2003
//ccCodeCheck(field) checks for valid visa/master security code
//
//**********
function ccCodeCheck(field)
{
	var str=TrimString2(field.value);
  // 123 format
      
  if ((str.length ==3)==false) 
  { 
    alert("Credit Card Security Code must be in the format ### [like 123]");
    return false;
  }
  
  len = str.length;
  for (i = 0; i < len; i++) 
  {
   c = str.charAt(i);
	
	if((c < "0") || (c > "9"))
	{
		alert("Invalid character in Credit Card Security Code.\nCredit Card Security Code must be in the format ### [like 123]");
		return false;
	}

   
  }
  return true;

}
//********************************************
//************
//Pallavi Sher - 05/20/2003
//ccDateCheck(field) checks for valid credit card expiry date
//
//**********

function ccDateCheck(field)
{

	var str=TrimString2(field.value);
	var c;
	var i;
	var len;
	var x;
	var final_date;

	//Get left 2 digits of yr so that 2 digit yrs can be processed like 4 digit yrs.
	var centurydate = new Date();
	var centurystr = '';
	centurystr += centurydate.getYear();

	
			
  // mm/yyyy format
  if(str!='')
  {    
	if(str.length == 4)
	{
		field.value = str.substr(0,2) + '/' + str.substr(2,4);
		str = TrimString2(field.value);
	}
	if(str.length == 5)
	{
		//field.value = str.substr(0,3) + centurystr.substr(1,3) + str.substr(3,5);
		str = TrimString2(str.substr(0,3) + centurystr.substr(0,2) + str.substr(3,5));
	}
	if(str.length == 6)
	{
		field.value = str.substr(0,2) + '/' + str.substr(2,4);	
		str = TrimString2(field.value);
	}
	else
	{  
		if ((str.length ==7)==false) 
		{ 
			//alert("Length must be 7 characters.\nCredit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
			alert("Credit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
			field.focus();
			field.select();
			return false;
		}
	}
  
	var datestr = str;
  
	len = str.length;
	for (i = 0; i < len; i++) 
	{
	 c = str.charAt(i);
		if(i == 0)
		{
			if((c < "0") || (c > "1"))
			{
				alert("Invalid month.\nCredit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}
			else
			{
				x = c;
			}		
		}
		if(i==1)
		{
			if(x=="1")
			{
				if((c < "0") || (c > "2"))
				{
					alert("Invalid month.\nCredit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
					field.focus();
					field.select();
					return false;
				}
			}
			else
			{
				if((c < "1") || (c > "9"))
				{
					alert("Invalid month.\nCredit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
					field.focus();
					field.select();
					return false;
				}
				
			}
	
		}
		if(i == 2)
		{
			if (c != "/") 
			{ 
				//alert("Third character must be a / .\nCredit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
				alert("Credit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}		
		}
	
		if(i!=2)
		{
			if((c < "0") || (c > "9"))
			{
				alert("Credit Card Expiration Date must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}
		}

	}
  
	var today = new Date();
  
	var thisyear = parseInt(today.getFullYear());
	var expyear = parseInt(datestr.substr(3,4));
  
	//if numbers provided to parseint are in 0x format  they are considered as octal numbers  to avoid this,
	//put the radix (base) = 10 so that these month values are always considered as decimals.
	//--PALLAVI 05/23/2003
  
	var thismonth = parseInt(today.getMonth(),10) + 1;
	var expmonth = parseInt(datestr.substr(0,2),10);
  
  
	if(expyear <= thisyear)
	{
		if(expyear < thisyear)
		{
			alert("Credit Card Expiration date must be in the future.");
			field.focus();
			field.select();
			return false;
		}
		else
		{
			if(expmonth <= thismonth)
			{
				alert("Credit Card Expiration date must be in the future.");
			alert("ha.");
				field.focus();
				field.select();
				return false;
			}	
		}
		  
	}
  }  
  return true;

}


//********************************************
//************
//Greg Free 5/25/2004 Modified from ccDateCheck - generic date check routine.
//DateCheck_MY(field) checks for valid date
//
//**********

function DateCheck_MY(field)
{
	var str=TrimString2(field.value);
	var c;
	var i;
	var len;
	var x;
	var final_date;

	//Get left 2 digits of yr so that 2 digit yrs can be processed like 4 digit yrs.
	var centurydate = new Date();
	var centurystr = '';
	centurystr += centurydate.getYear();

	
			
  // mm/yyyy format
  if(str!='')
  {    
	if(str.length == 4)
	{
		field.value = str.substr(0,2) + '/' + str.substr(2,4);
		str = TrimString2(field.value);
	}
	if(str.length == 5)
	{
		//field.value = str.substr(0,3) + centurystr.substr(1,3) + str.substr(3,5);
		str = TrimString2(str.substr(0,3) + centurystr.substr(0,2) + str.substr(3,5));
	}
	if(str.length == 6)
	{
		field.value = str.substr(0,2) + '/' + str.substr(2,4);	
		str = TrimString2(field.value);
	}
	else
	{  
		if ((str.length ==7)==false) 
		{ 
			//alert("Length must be 7 characters.\nDate must be in the format mm/yyyy [like 01/2003]");
			alert("Date must be in the format mm/yyyy [like 01/2003]");
			field.focus();
			field.select();
			return false;
		}
	}
  
	var datestr = str;
  
	len = str.length;
	for (i = 0; i < len; i++) 
	{
	 c = str.charAt(i);
		if(i == 0)
		{
			if((c < "0") || (c > "1"))
			{
				alert("Invalid month.\nDate must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}
			else
			{
				x = c;
			}		
		}
		if(i==1)
		{
			if(x=="1")
			{
				if((c < "0") || (c > "2"))
				{
					alert("Invalid month.\nDate must be in the format mm/yyyy [like 01/2003]");
					field.focus();
					field.select();
					return false;
				}
			}
			else
			{
				if((c < "1") || (c > "9"))
				{
					alert("Invalid month.\nDate must be in the format mm/yyyy [like 01/2003]");
					field.focus();
					field.select();
					return false;
				}
				
			}
	
		}
		if(i == 2)
		{
			if (c != "/") 
			{ 
				//alert("Third character must be a / .\nDate must be in the format mm/yyyy [like 01/2003]");
				alert("Date must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}		
		}
	
		if(i!=2)
		{
			if((c < "0") || (c > "9"))
			{
				alert("Date must be in the format mm/yyyy [like 01/2003]");
				field.focus();
				field.select();
				return false;
			}
		}

	}
  
  }  
  return true;

}




//************************************************************************
// modified : Pallavi Sher
//********************************

function emailCheck(field) {
	
	var emailStr = TrimString2(field.value);
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	//allow empty
	if (emailStr == '') return true;

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Email address seems incorrect (check @ and .'s)");
	field.focus();
	field.select();
	return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];

	//added by pallavi to fix the invalidation of domains in caps issue.-12/03/2003
	domain = domain.toLowerCase();
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			alert("This username contains invalid characters.");
			field.focus();
			field.select();
			return false;
		}
	}

	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
		alert("This domain name contains invalid characters.");
		field.focus();
		field.select();
		return false;
		}
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("The username doesn't seem to be valid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) 
	{
		if (IPArray[i]>255) 
		{
			alert("Destination IP address is invalid!");
			field.focus();
			field.select();
			return false;
		}
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	field.focus();
	field.select();
	return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	field.focus();
	field.select();
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	alert("This address is missing a hostname!");
	field.focus();
	field.select();
	return false;
	}

	// If we've gotten this far, everything's valid!
	
	return true;
}
//********************************************
//************
//Pallavi Sher - 09/25/01
//zipCheck(field) checks for valid US zip code
//
//**********

function zipCheck(field) {
	var zipstr = TrimString2(field.value);
	var valid = "0123456789-";
	var count = 0;

	if (zipstr.length!=5 && zipstr.length!=10)
	{
		alert("Please enter the 5 digit  or 9 digit zip code (like '12345-6789')!!");
		return false;
	}
	
	for (var i=0; i < zipstr.length; i++)
	{
		temp = "" + zipstr.substring(i, i+1);
		if (temp == "-") count++;
		
		if (valid.indexOf(temp) == "-1") 
		{
			alert("Invalid characters in the zip code.  Please try again !!");
			field.focus();
			field.select();
			return false;
		}
		
		if ((count > 1) || ((zipstr.length==10) && ""+zipstr.charAt(5)!="-")) 
		{
			alert("The '-' character should be used with a properly formatted 9 digit zip code, like '12345-6789'.   Please try again !!");
			field.focus();
			field.select();
			return false;
		}
	}
	
	return true;
}

//************************************************************************
//  Date : 03/04/2002
//
//************************************************************************
function TrimString2(stringS)
{
	var stringD = ""
	var i, j
	
	// Check if stringS is already empty
	if (stringS.length == 0)
		return stringD
		
	// Trim the leading spaces.
	// i = first non-space char or EOF
	i = 0
	while (i<stringS.length)
	{
		if (stringS.charAt(i) != " ")
			break
		
		i++		
	}
	
	// Trim the ending spaces
	// j = last non-space char or 
	j = stringS.length-1
	while (j >= i)
	{
		if (stringS.charAt(j) != " ")
			break

		j--
	}

	// Copy non-space chars from stringS to stringD
	while (i <= j)
	{
		stringD += stringS.charAt(i)
		i++
	}
	
	return stringD
}
//************************************************************************
// Created : Pallavi Sher
//  Date : 03/04/2002
/*
Given the minimum value and the maximum value this function checks if the value in the control is  
in the range of the minVal & the maxVal
*/
//************************************************************************

function isInRange(field,minVal,maxVal)
{
	var val = field.value;
	
	if(TrimString2(minVal)!="")
	{
		if(TrimString2(maxVal)!="")
		{
			if(TrimString2(val) != "") 
			{
				if(minVal < val && maxVal > val)
				{
					return true;			
				}
				else
				{
					alert('The value entered should be in the range : (' + minVal + ' - ' + maxVal + ')');
					field.focus();
					field.select();
					return false;
				}
	
			}
			else
			{
				//alert('The value entered is empty');
				alert('The value entered should be in the range : (' + minVal + ' - ' + maxVal + ')');
				field.focus();
				field.select();
				return false;
			}
			
		}
		else
		{
			alert('The max value is not available ! Cannot Validate Range !');
			field.focus();
			field.select();
			return false;
		}
	}
	else
	{
		alert('The min value is not available ! Cannot Validate Range !');
		field.focus();
		field.select();
		return false;
	}
		
}


//************************************************************************
// Added on 03/12/2002 : Pallavi Sher
// 
//********************************
function formatCurrencyValue(val) {
	
	var num=val;
	
	//alert(num);
	if((num=='') && (num==0))
	{
		num = "0";
	}
	
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = 0;
		
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
		num	= (((sign)?'':'-') + '$' + num + '.' + cents);
		
	
	return num
}
//************************************************************************
// Added on 07/02/2004 : Pallavi Sher
// 
//Checks if strNum appears in the comma delimited string strallNums 
//********************************
function isUniqueStr(strNum,strallNums)
{
	var givenNum = strNum;
	var flagVal = true;
	
	givenNum = givenNum.toUpperCase();
	givenNum = TrimString(givenNum);
	
	var allNums = strallNums;
	
	allNums = allNums.toUpperCase();
	
	
	var numsArr = allNums.split(",");
	var i;
	var strToken;
	var maxlen = numsArr.length;
	
	//alert(allNums);
	
	for(i=0;i<maxlen;i++)
	{
		strToken = numsArr[i];
		//alert(strToken);
		
		if(givenNum == strToken)
		{
			flagVal = false;
			break;
		}
		else
		{
			continue;
		}
	}
	
	return flagVal;
	
}


// added by dave 20050406
// checks for 2 characters or 4 characters
// checks for integer-ness
// converts 2 character year to 4 character year
function checkYear(field){
	if (field.value.length != 2 && field.value.length != 4){
		alert("The year value you entered is invalid.  Please try again.")
		field.focus();
		field.select();
		return false;
	}

	var whatever = isInteger(field)

	if (field.value.length == 2){
		if (field.value == "--"){field.value = "----"}
		else {
			var dateNow = new Date;
			var centNow = dateNow.toString().substr(dateNow.toString().length-4,2);
			var year4 = centNow + field.value;
			if (year4 > dateNow.getFullYear() + 30){
				year4 = year4 - 100;
			}
			field.value = year4;
		}
	}
}

// added by dave 20050406
// fills in empty year box when user goes there
function fillYear(field){
	if (field.value == "----"){
		var dateNow = new Date;
		field.value = dateNow.getFullYear();
		field.select();
	}
}

