
function emailCheck (emailField,showalert) {
	var emailFld = document.getElementById(emailField);
	var emailStr = emailFld.value
	if (emailStr=="") {return true}
	if (showalert==null) {showalert=true}

/* 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. */
	if (showalert) {alert("The email address is invalid\rCheck the @ and .'s")}
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    if (showalert) {alert("The email address is invalid\rThe 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) {
	        if (showalert) {alert("The email address is invalid\rDestination IP address is invalid!")}
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	if (showalert) {alert("The email address is invalid\rThe domain name doesn't seem to be valid.")}
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   if (showalert) {alert("The email address is invalid\rThe address must end in a three-letter domain, or two letter country.")}
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="The email address is invalid\rThis address is missing a hostname!"
   if (showalert) {alert(errStr)}
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


//******************** END OF EMAIL VALIDATION CODE **********************



//***********************< DATE VALIDATION CODE >*************************
//																		//
//	The following date validation code was written by...				//
//	* AUTHOR:  Simon Kneafsey											//
//	* EMAIL:   simonkneafsey@hotmail.com								//
//	* WEBSITE: www.simonkneafsey.co.uk									//
//																		//
//************************************************************************
function convert_date(dateField, showalert)
{

	var field1 = document.getElementById(dateField);
	if (showalert==null) {showalert=true}

	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;	}

	// Deal with today or now
	//If the user types 'TODAY' or 'NOW' into the text box it is converted to today's date
	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();
		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,showalert);
		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, showalert);
		return false;   
	}

	// See if no dividers are present in the date string.
	if ( divider_holder[0] == 0 && divider_holder[1] == 0 ) 
	{ 
   		//continue processing
		if ( fLength == 6 ) 
		{	//ddmmyy
   			day1 = field1.value.substring(0,2);
     		month1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,6);
  			if ((year1 = validate_year(year1)) == false ) 
  			{
   				invalid_date(field1, showalert);
				return false; 
			}
		}
			
		else if ( fLength == 7 ) 
		{	//ddmmmy
   			day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,5);
  			year1 = field1.value.substring(5,7);
  			if ( (month1 = convert_month(month1)) == false ) 
  			{
   				invalid_date(field1, showalert);
				return false; 
			}
  			if ( (year1 = validate_year(year1)) == false ) 
  			{
   				invalid_date(field1, showalert);
				return false; 
			}
		}
		else if ( fLength == 8 ) 
		{	//ddmmyyyy
   			day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,8);
		}
		else if ( fLength == 9 ) 
		{	//ddmmmyyyy
   			day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,5);
  			year1 = field1.value.substring(5,9);
  			if ( (month1 = convert_month(month1)) == false ) 
  			{
   				invalid_date(field1,showalert);
				return false; 
			}
		}
		
		if ( (outdate1 = validate_date(day1,month1,year1)) == false ) 
		{
   			if (showalert) {
   				alert("The value " + field1.value + " is not a valid date.\n\r" +  
				"Please enter date in the format dd mmm yyyy (e.g. 01 Mar 2001)\n\r" +
				"or dd/mm/yyyy (e.g. 01/03/01)");
				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 ) 
	{ 	
  		day1 = field1.value.substring(0, divider_holder[0]);
  		month1 = 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, showalert);
		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, showalert);
			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, showalert);
   			return false;  
		}
	}

	// Date components are OK
	if ( (day1.length == 2 || month1.length == 2 || year1.length == 4) == false) 
	{
		invalid_date(field1, showalert);
		return false;
	}

	//Validate the date
	if ( (outdate1 = validate_date(day1, month1, year1)) == false ) 
	{
		if (showalert) {
			alert("The value " + field1.value + " is not a vaild date.\n\r" +  
		    "Please enter date in the format dd mmm yyyy (e.g. 01 Mar 2001)\n\r" +
			"or dd/mm/yyyy (e.g. 01/03/01)");
			field1.focus();
			field1.select();
			}
		return false;
	}

	// Redisplay the date in dd/mm/yyyy format
	field1.value = outdate1;
	return true;//All is well

	}

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 != 9 && i != 10 && i != 11 ) 
				{
   					monthIn = '0' + monthIn;
				}
				return monthIn;
			}
		}
	}

	else if ( monthIn.length == 4 && monthIn == 'SEPT') 
	{
		monthIn = '09';
		return monthIn;
	}

	else 
	{
		return false;
	} 
}

function invalid_date(inField, showalert) 
	{
	if (showalert) {
		alert("The value " + inField.value + " is not in a vaild date format.\n\r" + 
	    "Please enter date in the format dd mmm yyyy (e.g. 01 Mar 2001)\n\r" +
		"or dd/mm/yyyy (e.g. 01/03/01)");
		inField.focus();
		inField.select();
		}
	return true   
	}

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");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
	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 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
			{
				if (month2 == '01'){month2 = 'Jan'}
				if (month2 == '02'){month2 = 'Feb'}
				if (month2 == '03'){month2 = 'Mar'}
				if (month2 == '04'){month2 = 'Apr'}
				if (month2 == '05'){month2 = 'May'}
				if (month2 == '06'){month2 = 'Jun'}
				if (month2 == '07'){month2 = 'Jul'}
				if (month2 == '08'){month2 = 'Aug'}
				if (month2 == '09'){month2 = 'Sep'}
				if (month2 == '10'){month2 = 'Oct'}
				if (month2 == '11'){month2 = 'Nov'}
				if (month2 == '12'){month2 = 'Dec'}

				inpDate = day2 + ' ' + month2 + ' ' + year2;       
				return inpDate;
			}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
		else                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
			return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
   	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
}

function validate_year(inYear) 
{
	// converts yy years to yyyy
	// Uses a hinge date of 10
    // <  10 = 20yy 
    // => 10 = 19yy.
    
	if ( inYear < 10 ) 
	{
		inYear = "20" + inYear;
		return inYear;
	}
	else if ( inYear >= 10 )
	{
		inYear = "19" + inYear;
		return inYear;
	}
	else 
	{
		return false;
	}   
}
//******************** END OF DATE VALIDATION CODE **********************



//************** Time Validation Code ***************//


//-- Original:  Sandeep Tamhankar (stamhankar@hotmail.com) --//
//-- Web Site:  http://207.20.242.93                       --//                       

//-- This script and many more are available free online at --//
//-- The JavaScript Source!! http://javascript.internet.com --//

function IsValidTime24(timeFld){
	var timefield = document.getElementById(timeFld);
	timeStr = trim(timefield.value);
	if(timeStr == '' || timeStr == null || timeStr.length == 0)
		return true;
	if((timeStr.length < 2 || timeStr.substring(0,2) != '0:') && timeStr.substring(0,1) == '0')
		timeStr = timeStr.substring(1,timeStr.length);
	if(timeStr == '')
		timeStr = '0:00'
	if(parseInt(timeStr) > 0 && parseInt(timeStr).toString().length==timeStr.length){
		if(timeStr.length < 3)
			timeStr += ':00';
		else if(timeStr.length == 3)
			timeStr = '0' + timeStr.substring(0,1) + ':' + timeStr.substring(1,timeStr.length);
		else
			timeStr = timeStr.substring(0,2) + ':' + timeStr.substring(2,timeStr.length);
	}
	var timePat = /^(\d{1,2}):(\d{2})/;
	var timePat2 = /^(\d{1,2}).(\d{2})/;
	var timePat3 = /^(\d{1,2})\s(\d{2})/;
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {matchArray = timeStr.match(timePat2);}
	if (matchArray == null) {matchArray = timeStr.match(timePat3);}
	if (matchArray == null) {
	  alert('Time \''+timeStr+'\' is not in a valid 24 hour format.\neg. \'12:45\'.');
	  timefield.focus;
	  return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	if(minute == null)
		minute = '00'
	if (hour < 0  || hour > 23){
		alert('Time \''+timeStr+'\' is not in a valid 24 hour format.\nHour must be between 1 and 23.\neg. \'12:45\'.');
		timefield.focus;
		return false;
	}
	if (minute < 0 || minute > 59) {
		alert('Time \''+timeStr+'\' is not in a valid 24 hour format.\nMinutes must be between 1 and 59.\neg. \'12:45\'.');
		timefield.focus;
		return false;
	}
	var ret = hour + ':' + minute;
	if(ret.length==3)
		ret = '0' + ret;
	timefield.value = ret;
	return true;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,'');
}

function IsValidTime(timeFld,defaultAMPM) {

	var timefield = document.getElementById(timeFld);
	var timefieldAMPM = document.getElementById(timeFld + 'AMPM');
	timeStr = timefield.value;

	if (timeStr == "" || timeStr == null) {return true}
	
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.
		
	if(parseInt(timeStr).toString().length==timeStr.length){
		timeStr += ':00';
	}

	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var timePat2 = /^(\d{1,2}).(\d{2})(.(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var timePat3 = /^(\d{1,2})\s(\d{2})(\s(\d{2}))?(\s?(AM|am|PM|pm))?$/;

	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {matchArray = timeStr.match(timePat2);}
	if (matchArray == null) {matchArray = timeStr.match(timePat3);}
	if (matchArray == null) {
	  alert("Time is not in a valid format.");
	  timefield.focus;
	  return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }

	if (hour < 0  || hour > 23) {
	  alert("Hour must be between 1 and 12. (or 0 and 23)");
	  timefield.focus;
	  return false;
	}
	if (hour <= 12 && ampm == null) {
		if(!defaultAMPM||defaultAMPM==null){
	  	//defaultAMPM = "AM";
	  }
	  ampm = defaultAMPM;
	}
	if  (hour > 12) {
		hour = hour-12;
		timefieldAMPM.childNodes[1].selected='true';
		//ampm = "PM";
	}
	if (minute<0 || minute > 59) {
	  alert ("Minute must be between 0 and 59.");
	  return false;
	}
	if (second != null && (second < 0 || second > 59)) {
	  alert ("Second must be between 0 and 59.");
	  timefield.focus;
	  return false;
	}
	if (second != null) {
		timefield.value = hour + ":" + minute + ":" + second; // + " " + ampm;
	} else {
		timefield.value = hour + ":" + minute; // + " " + ampm;
	}
	return true;
}

// *********************** End Time Validation **************//

