function validateForm1(frm)
{
	//alert(frm.name)
	var isValid;
	var allBlank;
	var lastFive;
	var lastThree;
	var name;
	var i;

	isValid=true;
	allBlank=true;
	//check that no fields are blank
	i=0;
	while ((i<frm.length) && (allBlank == true))
	{
		
		if ((frm.elements[i].type=="text")||(frm.elements[i].type=="textarea")||(frm.elements[i].type=="select-one"))
			{
			if ((frm.txtFullName.value == '')||(frm.txtEmail.value == '')||(frm.txtStreet.value == '')||(frm.txtSuburb.value == '')||(frm.txtState.value == '')||(frm.txtPostCode.value == '')||(frm.txtCountry.value == ''))
			//if (frm.elements[i].value == '')
				{
				allBlank=false;
				isValid=false;
				}
			}
		i++;
	}
	if (!(isValid))
	{
		//isValid=false;
		alert ("To proceed you must enter values in the text fields marked * required.");
	}
	return (isValid);
}

function validateForm(frm,frmField1,frmField2,frmField3, frmField4)
{
	var isValid;
	var allBlank;
	var lastFive;
	var lastThree;
	var name;
	var i;

	isValid=true;
	allBlank=true;
	//check that no fields are blank
	i=0;
	//alert(frmField2)
	while ((i<frm.length)&&(isValid))
	{
		
		if ((frm.elements[i].name!=frmField1)&&(frm.elements[i].name!=frmField2)&&(frm.elements[i].name!=frmField3)&&(frm.elements[i].name!=frmField4))
			{
			if ((frm.elements[i].type=="text")||(frm.elements[i].type=="textarea")||(frm.elements[i].type=="select-one"))
			{
				//alert(frm.elements[i].name)
				name=frm.elements[i].name;
				lastFive="";
				lastThree="";
				if (name.length>=5)
					lastFive=name.substring(name.length-5,name.length).toLowerCase();
				if (name.length>=3)
					lastThree=name.substring(name.length-3,name.length).toLowerCase();
				
				if ((lastFive!="phone")&&(lastThree!="fax"))
				{
					//only check compulsory fields
					if (frm.elements[i].value=='')
					{
						isValid=false;
						
						alert ("Please complete the required fields.");
						frm.elements[i].focus();
					}
				}
				else
				{
					if (frm.elements[i].value!='')
					{
						allBlank=false;
					}
				}
			}
		}
		i++;
	}
	//if ((isValid)&&(allBlank))
	//{
		//isValid=false;
		//alert ("Please enter a phone or fax number.");
	//}
	return (isValid);
}

function validateIEForm(frm)
{
	//only works on IE forms!!
	//if id is I (ignore) does not validate the value at all
	//if id is T (text) checks that value is not blank
	//if id is N (numeric) checks that value is numeric
	//if id is C (currency) checks that value is currency
	
	var isValid;
	var name;
	var id;
	var i;

	isValid=true;
	//check that no compulsory fields are blank
	i=0;
	while ((i<frm.length)&&(isValid))
	{
		if ((frm.elements[i].type=="text")||(frm.elements[i].type=="textarea"))
		{
			name=frm.elements[i].name;
			id=frm.elements[i].id;
			//only check compulsory fields
			if (id!='I')
			{
				if (frm.elements[i].value=='')
				{
					isValid=false;
					alert ("Please enter a value for " + frm.elements[i].title + ".");
					frm.elements[i].focus();
				}
				else if (id=='N')
				{
					//if (frm.elements[i].value=='')
					//	frm.elements[i].value=0;
					if (!isNumber(frm.elements[i].value))
					{
						isValid=false;
						alert ("Please use only numeric values for " + frm.elements[i].title + ".");
						frm.elements[i].focus();
					}
				}
				else if (id=='C')
				{
					//if (frm.elements[i].value=='')
					//	frm.elements[i].value=0;
					if (!isFloat(frm.elements[i].value))
					{
						isValid=false;
						alert ("Please use only numeric values for " + frm.elements[i].title + ".");
						frm.elements[i].focus();
					}
				}
			}
		}
		
		i++;
	}
	return (isValid);
}

function isValidEmail(str)
{
	var isValid;

	isValid=true;
	//check email is at least 7 chars in length
	if (str<7)
	{
		isValid=false;
	}
	//check email contains "@" and that it is at least 5 chars from the end
	//of the string
	if ((str.indexOf("@")<=0)
		||(str.indexOf("@")>(str.length-6)))
	{
		isValid=false;
	}
	return (isValid);
}
//----------------------------------------------------------------------------------
function validName(inField) 
//----------------------------------------------------------------------------------
{
	
var varName = inField.value;
var blnSet = true;

	invalidChars = " /:,;$%~!^*()+=|\}]{['?><#&"
	
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (varName.indexOf(badChar,0) > -1) {
			blnSet = false
		}
	}
	if (blnSet) {
		return true}
	else{
		invalid_Name(inField)}
}
//----------------------------------------------------------------------------------
function invalid_Name(inField) 
//----------------------------------------------------------------------------------
{
	var varName = inField.value;
	
	if (varName == "") {
		alert("Please enter a Name.")}
	else{
		alert("The value " + varName + " is not a valid Name.\n\r" ); 
	}
	
	inField.focus();
	inField.select();
	return true   
}
//----------------------------------------------------------------------------------
function validEmail(inField) 
//----------------------------------------------------------------------------------
{
	
var email = inField.value;
var blnSet = true;
var period2Pos
	
	
	invalidChars = " /:,;$%~!^*()+=-|\}]{['?><#&"

	
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			blnSet = false
			//invalid_email(inField)
		}
	}
	atPos = email.indexOf("@",1)
	
	if (atPos == -1) {
		blnSet = false
		//invalid_email(inField)
	}
	if (email.indexOf("@",atPos+1) > -1) {
		blnSet = false
		//invalid_email(inField)
	}
	periodPos = email.indexOf(".",atPos)
	//alert(periodPos)
	if (periodPos == -1) {
		blnSet = false
		//invalid_email(inField)
	}
	if (periodPos+3 > email.length)	{
		blnSet = false
		//invalid_email(inField)
	}
	period2Pos = email.indexOf(".",email.length-1)
	if (period2Pos != -1 ){
		blnSet = false
		//invalid_email(inField)
	}
	if (email == "") {
		
		blnSet = false
	}
	//alert (blnSet)
	//(blnSet) ? return true : invalid_email(inField)
	if (blnSet) {
		return true}
	else{
		invalid_email(inField)}
		
}
//----------------------------------------------------------------------------------
function invalid_email(inField) 
//----------------------------------------------------------------------------------
{
	var email = inField.value;
	
	if (email == "") {
		alert("Please enter a valid email address.")}
	else{
		alert("The value " + inField.value + " is not a valid email format.\n\r" + 
          "Please enter a correct email address");
	}
	
	inField.focus();
	inField.select();
	return true   
}
//----------------------------------------------------------------------------------
function containsValidChars(str,strValidChars)
{
	var isValid;
	var i;
	
	isValid=true;
	for (i=0;i<str.length;i++)
	{
		if (strValidChars.indexOf(str.charAt(i))==-1)
			isValid=false;
	}

	return isValid;
}

function isNumber(str)
{
//checks that str consists of digits only. Ignores any occurrences of commas. 
//(assumes commas are thousands/hundreds delimiters)
//returns true if valid

	return(containsValidChars(str, '0123456789,'));
	
}

function isNumeric(str)
{
//checks that str consists of digits only.
//returns true if valid
	//alert(str)
	return(containsValidChars(str, '0123456789'));
	
}

function isFloat(str)
{
//checks that str consists of digits only. 
//Ignores any occurrences of commas or decimal points. 
//(assumes commas are thousands/hundreds delimiters)
//returns true if valid

	return(containsValidChars(str, '0123456789,.'));
	
}

function isValidOption(frm,strOptName)
{
	var i;
	var boolSelected;

	boolSelected=false;
	i=0;
	while ((i<frm.elements[strOptName].length)&&(!boolSelected))
	{
		boolSelected=frm.elements[strOptName][i].checked;
		i++;
	}
	return boolSelected;
}


//-----------------------------------------------------------------------------
/*
   convert_date()
   
   Function to convert supplied dates to format - dd/mm/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)
{
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 ( 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);
	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
		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);
				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);
				return false; 
				}
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				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);
				return false; 
				}
			}
		
		if ( (outdate1 = validate_date(day1,month1,year1)) == false ) {
   		alert("The value " + field1.value + " is not a valid date.\n\r" +  
			"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 ) { 	
  	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);
	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 ( (day1.length == 2 || month1.length == 2 || year1.length == 4) == false) {
   invalid_date(field1);
   return false;
}

//Validate the date
if ( (outdate1 = validate_date(day1, month1, year1)) == false ) {
   alert("The value " + field1.value + " is not a valid date.\n\r" +  
	"Please enter a valid date in the format dd/mm/yyyy");
	field1.focus();
	field1.select();
	return false;
}

// 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 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!
*******************************************************************/
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 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
        {
        inpDate = day2 + '/' + month2 + '/' + 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;
	}   
}
//-----------------------------------------------------------------------------

function IsValidTime(timeStr,msg) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
//var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/;

var matchArray = timeStr.value.match(timePat);
	if (matchArray == null) 
		{
		alert("The " + msg + "Time is not in a valid format.");
		timeStr.focus();
		timeStr.select();
		return false;
		}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (minute=="") { minute = null }
	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 for military time)");
		alert("Hour must be between 0 and 23 ");
		timeStr.focus();
		timeStr.select();
		return false;
		}
	//if (hour <= 12 && ampm == null) 
		//{
		//if (confirm("Please indicate which time format you are using. OK = Standard Time, CANCEL = Military Time")) 
			//{
			//alert("You must specify AM or PM.");
			//return false;
			//}
		//}
	
	//if (hour > 12 && ampm != null) 
		//{
		//alert("You can't specify AM or PM for military time.");
		//return false;
		//}
	
	if (minute<0 || minute > 59) 
		{
		alert ("Minute must be between 0 and 59.");
		timeStr.focus();
		timeStr.select();
		return false;
		}
	
	if (second != null && (second < 0 || second > 59)) 
		{
		alert ("Second must be between 0 and 59.");
		timeStr.focus();
		timeStr.select();
		return false;
		}
	
	return false;
}

function format(expr, decplaces) 
	{
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) 
		{
		str = "0" + str
		}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
	}	