function formataDatas( whichForm ) {
	var data, nova_data;
	var dia, mes, ano;

	for(var i=0; i < whichForm.elements.length; i++) {
		// Se achou _dat_ no nome do campo
		if(whichForm.elements[i].name.indexOf("_dat_")>=0) {
		 	data = whichForm.elements[i].value;
			dia = data.substr(0,2);
			if(dia.substr(1,1)=="/") {
				dia = "0" + dia.substr(0,1);
			}
			mes = data.substr(data.indexOf("/")+1,2);
			if(mes.substr(1,1)=="/") {
				mes = "0" + mes.substr(0,1);
			}
			ano = data.substr(data.lastIndexOf("/")+1,4);
			nova_data = dia + "/" + mes + "/" + ano;
			whichForm.elements[i].value = nova_data;
		}
	}
	
}


function contaQtos( onde, valor ) {
	var retVal = 0;
	
	for(var i=0; i < onde.length; i++) {
		if(onde.charAt(i)==valor) {
			retVal++;
		}
	}
	
	return retVal;
}

//Funções relacionadas a Data
hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getYear()
ano += (ano < 1900) ? 1900 : 0
if (dia < 10)
dia = "0" + dia
if (ano < 2000)
ano = "19" + ano
function CriaArray (n) {
this.length = n }
NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Terça-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "Sábado"
//
NomeMes = new CriaArray(12)
NomeMes[0] = "Janeiro"
NomeMes[1] = "Fevereiro"
NomeMes[2] = "Março"
NomeMes[3] = "Abril"
NomeMes[4] = "Maio"
NomeMes[5] = "Junho"
NomeMes[6] = "Julho"
NomeMes[7] = "Agosto"
NomeMes[8] = "Setembro"
NomeMes[9] = "Outubro"
NomeMes[10] = "Novembro"
NomeMes[11] = "Dezembro"
function WriteDate() {
}

day = new Date()
d = day.getDate()
m = day.getMonth()
hr = day.getHours()
mi = day.getMinutes()
se = day.getSeconds()

// A validaçao abaixo diz respeito aos campos de data das paginas. As funçoes sao usadas p/ validaçao das entradas do usuario
nome_mes = new Array();
nome_mes[1]="Jan";
nome_mes[2]="Feb";
nome_mes[3]="Mar";
nome_mes[4]="Apr";
nome_mes[5]="May";
nome_mes[6]="Jun";
nome_mes[7]="Jul";
nome_mes[8]="Aug";
nome_mes[9]="Sep";
nome_mes[10]="Oct";
nome_mes[11]="Nov";
nome_mes[12]="Dec";

function checkDate( whichfield ) {
	if (whichfield != '') {
		if( !checkField( whichfield, "<|>@#$%&*!+- ()?[]{}~^´`,.\"_=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóúãõàüäëöïñçÁÉÍÓÚÃÕÀÜÄËÖÏÑÇ\\" ) ) {
			return false;
		}
		if (whichfield.length != 10) {
			return false;
		}
		if (whichfield == '1111111111') {
			return false;
		}
	 
		var myDayStr = whichfield.substr(0,2);
		var myMonthStr = nome_mes[Math.abs(whichfield.substr(3,2))];
		var myYearStr = whichfield.substr(6,4);
		var myDateStr = myDayStr + " " + myMonthStr + " " + myYearStr;
		var myDate = new Date( myDateStr );
		var myDate_string = myDate.toUTCString();
		var myDate_array = myDate_string.split(" ");
	
		if( ( myDate_array[2] != myMonthStr ) || ( Math.abs(whichfield.substr(3,2) ) < 1 || Math.abs(whichfield.substr(3,2) ) > 12) ) {
			return false;
		} else {
			return true;
		}
	}
	return true;
}


//Função checkField
function checkField( sStr, sChars ) {
	var j=0;
	var bRetVal = true;
	while( j < sChars.length ) {
		if( sStr.indexOf( sChars.substr(j,1) ) >= 0 ) {
			bRetVal = false;
			break;
		}
		j++
	}
	return bRetVal;
}

