<!--

function auto_date(field1)
{
	if (field1.value.length==0){
		field1.value='now';
		field1.blur();
	}
}

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' || field1.value.toUpperCase() == 'HOJE' || field1.value.toUpperCase() == 'JA' || field1.value.toUpperCase() == 'AGORA') { 
   
	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("O valor " + field1.value + " não é válido.\n\r" + "Por favor introduza a data no seguinte formato: dd/mm/aaaa");
			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("O valor " + field1.value + " não é válido.\n\r" + "Por favor introduza a data no seguinte formato: dd/mm/aaaa");
	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","FEV","MAR","ABR","MAI","JUN","JUL","AGO","SET","OUT","NOV","DEZ");

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 && i != 12 ) // acrescentei i!=9
				{ 
   			monthIn = '0' + monthIn;
				}
			return monthIn;
			}
		}
	}


	
else {
	return false;
	} 
}

function invalid_date(inField) 
{
alert("O valor " + inField.value + " não é válido.\n\r" + "Por favor introduza a data no seguinte formato: dd/mm/aaaa");
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 )  
     { 
     inpDate = day2 + '-' + convertNumToName(month2) + '-' + year2;   
     return inpDate; 
     }   
      else  
     {  
     return false;  
     }   
   	} 
   }  
}

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 convertNumToName(mesIn){
	var meses2= new makeArray0('Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez');
	return meses2[mesIn-1];
}

function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
    this[i] = makeArray0.arguments[i];
}

//----------------------------------------------------------------------------------------
function auto_hour(field1, formatIn)
{
	var newDate1 = new Date();
  	var myHour1 = newDate1.getHours();
  	var myMinute1 = newDate1.getMinutes();
  	var mySecond1 = newDate1.getSeconds();
  	var myMilisecond1 = newDate1.getMilliseconds();
	if (field1.value.length==0){
		if (formatIn==1){
			field1.value=myHour1 + ':' + myMinute1;
		}else if (formatIn==2){
			field1.value=myHour1+ ':' +myMinute1+ ':' +mySecond1;
		}else{
			field1.value=myHour1+ ':' +myMinute1+ ':' +mySecond1+ '.' +myMilisecond1;
		}
	}
}


function convert_time(field1, FormatIN)
{
var fieldlength = field1.value.length
var divider_values = new Array ('-','.','/',' ',':','_',','); 
var hour1 = new String(null);
var minute1 = new String(null);
var second1 = new String(null);
var milisecond1 = new String(null);


}

function chech_hour(hourIn)
{
if ( hourIn == 24 )
	{ 
   hourIn = "00";
   return hourIn;
	}
else if ( hourIn >= 0 && hourIn <= 9)
	{ 
   hourIn = "0" + hourIn; 
   return hourIn;
	}
else if ( hourIn >= 10 && hourIn <= 23)
	{
	return hourIn; 
	}   
else
	{
	return false;
	}
}

function chech_minute(minuteIn)
{
if ( minuteIn >= 0 && minuteIn <= 9)
	{ 
   minuteIn = "0" + minuteIn; 
   return minuteIn;
	}
else if ( minuteIn >= 10 && minuteIn <= 59)
	{ 
   return minuteIn;
	}
else
	{
	return false;
	}
}

function chech_second(secondIn)
{
if ( secondIn >= 0 && secondIn <= 9)
	{ 
   secondIn = "0" + secondIn; 
   return secondIn;
	}
else if ( secondIn >= 10 && secondIn <= 59)
	{ 
   return secondIn;
	}
else
	{
	return false;
	}
}

function chech_milisecond(milisecondIn)
{
if ( milisecondIn >= 0 && milisecondIn <= 9)
	{
   return milisecondIn;
	}
else
	{
	return false;
	}
}

function invalid_time(inField, inFormat)
{
if (inFormat==1){
	alert("O valor " + inField.value + " não é válido.\n\r" + "Por favor introduza a tempo no seguinte formato: hh/mm");
}
if (inFormat==2){
	alert("O valor " + inField.value + " não é válido.\n\r" + "Por favor introduza a tempo no seguinte formato: hh/mm/ss");
}
if (inFormat==3){
	alert("O valor " + inField.value + " não é válido.\n\r" + "Por favor introduza a tempo no seguinte formato: hh/mm/ss/d");
}
inField.focus();
inField.select();
return true   
}
-->
