<!--

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 ) ;}
	}		
	
}



 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;
        }  
    }
	
	for (var i = 0; i < document.Form1.a_HoraReturn.length; i++) 
    {
		if (document.Form1.a_HoraReturn.options[i].value == document.Form1.a_HoraDelivery.value) 
        {
			document.Form1.a_HoraReturn.options[i].selected = true;
        }  
    }
    
	
	for (var i = 0; i < document.Form1.a_MinutoReturn.length; i++) 
    {
		if (document.Form1.a_MinutoReturn.options[i].value == document.Form1.a_MinutoDelivery.value) 
        {
			document.Form1.a_MinutoReturn.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);
//alert(data1.getTime());


Var_Dia2=Dia2;
Var_Mes2=Math.floor(Mes2)-1;
Var_Ano2=Ano2;
var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);
//alert(data2.getTime());


//var diferenca = data1.getTime() - data2.getTime();
var diferenca = data2.getTime() - data1.getTime();
//var diferenca = (Math.abs(Math.floor(diferenca / (1000 * 60 * 60 * 24))));
var diferenca = (Math.abs(Math.round(diferenca / (1000 * 60 * 60 * 24))));

//alert(Math.floor(diferenca / (1000 * 60 * 60 * 24)));
//if (diferenca > 2)
//	diferenca = diferenca - 1;
//alert(diferenca);

Form1.a_NumDias.value=diferenca;
} 
 
 
 
 
/*function somadiashoras(numdias,horarec,horaret) 
{

 if (numdias != "")
 {	
	var diferenca2 = Number(document.Form1.a_HoraReturn.value) - Number(document.Form1.a_HoraDelivery.value);
	
	if ( Number(diferenca2) > Number(4))	
	{
		Form1.a_NumDias.value = Number(Form1.a_NumDias.value)+Number(1);
	}
	else
	{
		Calcula_Dias(Form1.DiaDeliveryDate.value,Form1.MesDeliveryDate.value,Form1.AnoDeliveryDate.value,Form1.DiaReturnDate.value,Form1.MesReturnDate.value,Form1.AnoReturnDate.value);
	}	
	
	
 }	
} */
//-->