<!--

function SetHelp(txt) { help.innerText = txt ; }


function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.Form1[campo].value;
	if( tecla == 109 || tecla == 189 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.Form1[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	

	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				document.Form1[prox].focus() ;	}
}

function SaltaCampos (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.Form1[campo].value;
	if( tecla == 109 || tecla == 189 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.Form1[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	

	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				document.Form1[prox].focus() ;	}
}

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Form1[Campo].value;
	//alert(document.Form1[Campo].name);
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.Form1[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.Form1[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function FormataDatas(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Form1[Campo].value;
	//alert(document.Form1[Campo].name);
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.Form1[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.Form1[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function FormataHora(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Form1[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.Form1[Campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		if ( tam >= 5)
			document.Form1[Campo].value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 ) + ':' + vr.substr( 4, 4 ); }
}

function FormataMesAno(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Form1[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
		
			document.Form1[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			
	}		
		
}


function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.Form1[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.Form1[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.Form1[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.Form1[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.Form1[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.Form1[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.Form1[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}

//Função para validar datas
<!-- Begin
function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("Invalid date. Please, try again.");
datefield.focus();
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
var strDatestyle = "BR"; 
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;

strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) 
{

if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
return true;
}


function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}


function doDateCheck(from, to) 
{
if (Date.parse(from.value) <= Date.parse(to.value)) {
return true;
}
else {
if (from.value == "" || to.value == "") 
{
alert("As duas datas devem ser digitadas.");
return false;

}
else 
{
alert("A data final deve ser maior que a data de início.");
return false;

}
}
}




 
 function Compara_Datas(data_inicial, data_final)
 {
 	//Verifica se a data inicial é maior que a data final
 	//var data_inicial = document.Form1[data_inicial];
 	//var data_final   = document.Form1[data_final];
 	str_data_inicial = document.Form1[data_inicial].value;
 	str_data_final   = document.Form1[data_final].value;
 	dia_inicial      = document.Form1[data_inicial].value.substr(0,2);
 	dia_final        = document.Form1[data_final].value.substr(0,2);
 	mes_inicial      = document.Form1[data_inicial].value.substr(3,2);
 	mes_final        = document.Form1[data_final].value.substr(3,2);
 	ano_inicial      = document.Form1[data_inicial].value.substr(6,4);
 	ano_final        = document.Form1[data_final].value.substr(6,4);
 	if(ano_inicial > ano_final){
 		alert("A data de entrega deve ser menor que a data de recolha."); 
 		document.Form1[data_inicial].focus();
 		return false
 	}else{
  	if(ano_inicial == ano_final){
   	if(mes_inicial > mes_final){
    	alert("A data de entrega deve ser menor que a data de recolha.");
 				document.Form1[data_inicial].focus();
 				return false
 			}else{
 				if(mes_inicial == mes_final){
 					if(dia_inicial > dia_final){
 						alert("A data de entrega deve ser menor que a data de recolha.");
 						document.Form1[data_inicial].focus();
 						return false
 					}
 				}
 			}
 		}
 	}
 }
 


function numdias(mes,ano) 
{
   if((mes<8 && mes%2==1) || (mes>7 && mes%2==0)) return 31;
   if(mes!=2) return 30;
   if(ano%4==0) return 29;
   return 28;
}


function somadias(dia, meses, anos, dias) 
{

	
 if (dias != "")
 {	
	diafuturo=Number(parseInt(dia))+Number(dias);
	mes=parseInt(meses);
	ano=parseInt(anos);
	//alert(dias);
	while(diafuturo>numdias(mes,ano)) 
	{
	    diafuturo-=numdias(mes,ano);
	    mes++;
	    if(mes>12) {
	        mes=1;
	        ano++;
	    }
	}
	
	for (var i = 0; i < document.Form1.DiaReturnDate.length; i++) 
    {
		if (document.Form1.DiaReturnDate.options[i].value == diafuturo) 
        {
			document.Form1.DiaReturnDate.options[i].selected = true;
        }  
    }
    
    for (var i = 0; i < document.Form1.MesReturnDate.length; i++) 
    {
		if (document.Form1.MesReturnDate.options[i].value == mes) 
        {
			document.Form1.MesReturnDate.options[i].selected = true;
        }  
    }
    
    for (var i = 0; i < document.Form1.AnoReturnDate.length; i++) 
    {
		if (document.Form1.AnoReturnDate.options[i].value == ano) 
        {
			document.Form1.AnoReturnDate.options[i].selected = true;
        }  
    }
	
	
	
	Calcula_Dias(dia,meses,anos,diafuturo,mes,ano);
 }	
}

//Calcular dias
function Dia(Data_DDMMYYYY)
{
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1)
{
dia = string_data.substring(0,posicao_barra);
return dia;
}
else
{return false;}
}

function Mes(Data_DDMMYYYY)
{
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
	if (posicao_barra!= -1)
	{
		dia = string_data.substring(0,posicao_barra);
		string_mes = string_data.substring(posicao_barra+1,string_data.length);
		posicao_barra = string_mes.indexOf("/");
	if (posicao_barra!= -1)
	{
		mes = string_mes.substring(0,posicao_barra);
		mes = Math.floor(mes);return mes;
	}
	else
	{
		return false;
	}
}
else
{return false;}
} 

function Ano(Data_DDMMYYYY)
{
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1)
{
dia = string_data.substring(0,posicao_barra);
string_mes = string_data.substring(posicao_barra+1,string_data.length);
posicao_barra = string_mes.indexOf("/");
if (posicao_barra!= -1)
{
mes = string_mes.substring(0,posicao_barra);
mes = Math.floor(mes);
ano = string_mes.substring(posicao_barra+1,string_mes.length);
return ano;
}
else
{
return false;
}
}
else
{
return false;
}
}

function Calcula_Dias(Dia1,Mes1,Ano1,Dia2,Mes2,Ano2)
{
Var_Dia1=Dia1;
Var_Mes1=Math.floor(Mes1)-1;
Var_Ano1=Ano1;
var data1 = new Date(Var_Ano1,Var_Mes1,Var_Dia1);

Var_Dia2=Dia2;
Var_Mes2=Math.floor(Mes2)-1;
Var_Ano2=Ano2;
var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);

var diferenca = data1.getTime() - data2.getTime();
var diferenca = Math.abs(Math.floor(diferenca / (1000 * 60 * 60 * 24)));

Form1.a_NumDias.value=diferenca;
} 
 
 

//  End

//-->
