function FormataData(pForm, pCampo,pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 2 && wTam < 5 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '/' + wVr.substr( wTam - 2, wTam );
		if ( wTam >= 5 && wTam <= 10 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 4 ); 
	}			
}

function FormataDataDDMMAA(pForm, pCampo, pTeclaPres) 
{
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 )
	{
		if ( wTam > 2 && wTam < 5 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '/' + wVr.substr( wTam - 2, wTam );
		if ( wTam >= 5 && wTam <= 10 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 2 ); 
	}			
}

function FormataDataMMAA(pForm, pCampo,pTeclaPres) 
{
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 2 && wTam < 5 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '/' + wVr.substr( wTam - 2, wTam );
		if ( wTam > 2 && wTam <= 5 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 );
		if ( wTam > 5  )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 );
		
//		if ( wTam >= 5 && wTam <= 10 )
//			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 2 ); 
	}			
}
function ValidaPeriodo (DataInicial,DataFinal,EditData)
	{
		var DataAtual = EditData.value;
		var AnoInicial = DataInicial.substring(6,8);
		if (AnoInicial<70)
		{
			AnoInicial = "20"+AnoInicial;
		}
		else
		{
			AnoInicial = "19"+AnoInicial;
		}
		
		var AnoFinal = DataFinal.substring(6,8);
		if (AnoFinal<70)
		{
			AnoFinal = "20"+AnoFinal;
		}
		else
		{
			AnoFinal = "19"+AnoFinal;
		}
		var AnoAtual = DataAtual.substring(6,8);
		if (AnoAtual<70)
		{
			AnoAtual = "20"+AnoAtual;
		}
		else
		{
			AnoAtual = "19"+AnoAtual;
		}
		
		
		var MesInicial = DataInicial.substring(3,5);
		var MesFinal = DataFinal.substring(3,5);
		var MesAtual = DataAtual.substring(3,5);
		
		var DiaInicial = DataInicial.substring(0,2);
		var DiaFinal = DataFinal.substring(0,2);
		var DiaAtual = DataAtual.substring(0,2);
		
		var nDataAtual = new Date (AnoAtual,MesAtual,DiaAtual );
		var nDataFinal = new Date (AnoFinal,MesFinal,DiaFinal );
		var nDataInicial = new Date (AnoInicial,MesInicial,DiaInicial);
		if (nDataAtual < nDataInicial )
		{
			alert("A Data "+DataAtual+" é menor que o período inicial "+DataInicial);
			return false;
		}
		if (nDataAtual > nDataFinal  )
		{
			alert("A Data "+DataAtual+" é maior que o período final "+DataFinal);
			return false;
		}
		
		return true;
		
		
	}
	
	
	
