	function soNumeros(campo) {
		var txt = campo.value;
		var s = "";

		for (var i = 0 ; i < txt.length ; i++) {
			if (txt.charAt(i) >= '0' && txt.charAt(i) <= '9') {
				s += txt.charAt(i);
			}
		}

		if (txt.length != s) {campo.value = s;}
	}

	function completaZeros(fld,q) {
		while (fld.value.length < q) {
			fld.value = '0' + fld.value;
		}
	}


	function validaCPF(s){ 
		var d1 = 0; var d2 = 0;

		for (var i = 0; i < 9; i++) {
			d1 += s.charAt(i)*(10-i); d2 += s.charAt(i)*(11-i);}

		if ((d1 == 0)||(s.length != 11)){return false;}

		d1 = 11 - (d1        % 11); if (d1 > 9) d1 = 0; 
		d2 = 11 - ((d2+d1*2) % 11); if (d2 > 9) d2 = 0; 

		return (s.charAt(9) == d1) && (s.charAt(10) == d2);
	}


	function validaEmail_possuiCarateresInvalidos(string){

		var exChar="*"+unescape("%7E%5E%B4%60%27%22%21%24%25%23%26%28%29%3C%3E%2C%3B%3A%3F%5C%5D%5B%7B%7D ");
		var c;
		for(var i=0; i<exChar.length; i++){
			c=exChar.charAt(i);
			if(!(string.indexOf(c)==-1))
				return true;
		}
		return false;
	}


	function validaEmail (email){
		if(validaEmail_possuiCarateresInvalidos(email)) // verificar caracteres nao validos
			return false;

		var i=email.indexOf("@");                   // posicao de @ no email fornecido
		var sLength=email.length - 1;               // comprimento do valor do campo
		if((i>0)&&(i<sLength)){                     // se i<0 ou i==sLengt=> ERRO!
			email=email.substring(i+1, sLength+1);  // substring depois de @
			i=email.indexOf(".");                   // posicao do . na substring
			sLength=email.length - 1;
			if((!(email.charAt(sLength)=="."))&&(email.indexOf("@")==-1))
			if(i>0 && i<sLength)                    // se i>0 e i<Length=> OK!
				return true;
		}
		return false;
	}

	
	function DaysArray(n,year) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
		}
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		this[2] = (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

		return this
	}


	function isDate(dtStr){
		var dtCh= "/";
		var minYear=1900;
		var maxYear=2100;

		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)

		if (eval(strMonth) < 1 || eval(strMonth) > 12){
			return false
		}
		if (eval(strDay)<1 || eval(strDay) > DaysArray(12,eval(strYear))[eval(strMonth)]){
			return false
		}
		if (eval(strYear)<minYear || eval(strYear)>maxYear){
			return false
		}
	return true
	}


	/******************************************************************************
	 * Autor : Leandro Ferreira
	 * Última modificação :	29/08/2007
	 *
	 * Verifica a validade da data enquanto é digitada, insere as barras 
	 * automaticamente e, se for o caso, passa para o próximo campo quando de uma
	 * data válida completamente preenchida
	 *
	 * Parâmetros :
	 *      evento: evento, para se obter a tecla pressionada (sempre event)
	 *      obj:    campo a ser formatado (sempre this)
	 *      prox:   caso deseje um "autotab", indica o próximo campo. Caso
	 *              contrário, passar null
	 *
	 * Exemplo : OnKeyUp="verificaData(event,this,document.financas.vardatafinal);"
	 ******************************************************************************/
	function verificaData (evento,obj,prox)
	{
		var c, res='';

		//Remove caracteres não numéricos e não barra
		//Verifica o tamanho da string
		//Verifica o posicionamento das barras
		for (var i=0; i < obj.value.length; i++) {
			c = obj.value.charCodeAt(i);
			if ((c >= 48 && c <= 57) || (c == 47)) {
				if (!((c == 47) && ((i != 2) && (i != 5))) &&
					!((c != 47) && ((i == 2) || (i == 5)))) {

						if (res.length < 10) {
							res += String.fromCharCode(c);
						}
				}
			}
		}
		obj.value = res;

		//Insere as barras automaticamente
		if ((obj.value.length == 2 || obj.value.length == 5) && evento.keyCode != 8) {
			obj.value += '/';
		}

		//Verifica a validade da data...
		if (obj.value.length == 10) {
			if (isDate (obj.value)) {
				//...e, se for o caso, automaticamente
				//   vai para o próximo campo
				if (prox) {
					prox.focus();
				}
			} else {
				//Senão, informa que a data está errada
				alert ('Data Inválida');
				obj.select();
			}
		}
	}


	function mudaCep() {
		var cep = document.frmCad.cepUs.value;
		var s = "";

		for (var i = 0 ; i < cep.length ; i++) {
			if (cep.charAt(i) >= '0' && cep.charAt(i) <= '9' && s.length < 8) {
				s += cep.charAt(i);
			}
		}

		if (cep.length != s) {document.frmCad.cepUs.value = s;}

		if (cep.length == 8) {
			document.frmCad.endUs.value = 'Aguarde...';document.frmCad.endUs.style.background='#D0D0D0';document.frmCad.endUs.style.color='#808080';
			document.frmCad.baiUs.value = 'Aguarde...';document.frmCad.baiUs.style.background='#D0D0D0';document.frmCad.baiUs.style.color='#808080';
			document.frmCad.cidUs.value = 'Aguarde...';document.frmCad.cidUs.style.background='#D0D0D0';document.frmCad.cidUs.style.color='#808080';
			document.frmCad.estUs.value = 'Aguarde...';document.frmCad.estUs.style.background='#D0D0D0';document.frmCad.estUs.style.color='#808080';

			document.getElementById('Posts').src="posts.asp?act=mudaCEP&cep=" + cep;
		}

	}


	function mudaUnidade() {
		var unid = document.frmCad.uniRs.value;

		document.frmCad.nomeResp.disabled = (unid != 'OUTROS');
		document.frmCad.ramResp.disabled =  (unid != 'OUTROS');
		document.frmCad.carResp.disabled =  (unid != 'OUTROS');

		document.frmCad.nomeResp.style.backgroundColor = '#F0F0F0';
		document.frmCad.ramResp.style.backgroundColor = '#F0F0F0';
		document.frmCad.carResp.style.backgroundColor = '#F0F0F0';



		if (unid != 0 && unid != 'OUTROS') {
			document.Posts.location.href="posts.asp?act=mudaUnidade&codUnidade=" + unid;
		} else {
			document.frmCad.nomeResp.value = "";
			document.frmCad.ramResp.value  = "";
			document.frmCad.carResp.value  = "";

			if (unid == 'OUTROS') {
				document.frmCad.nomeResp.style.backgroundColor = '#FFFFFF';
				document.frmCad.ramResp.style.backgroundColor = '#FFFFFF';
				document.frmCad.carResp.style.backgroundColor = '#FFFFFF';

				document.frmCad.nomeResp.focus();
			}
		}
	}


	function validaForm(n) {
		var nomeCampo = "", idCampo = ""

		if (n == 1) {

				 if (document.frmCad.matUs.value.length == 0) {nomeCampo = "Matricula"; idCampo = "matUs"}
			else if (document.frmCad.nascUs.value.length != 10 || !isDate(document.frmCad.nascUs.value)) {nomeCampo = "Data de nascimento"; idCampo = "nascUs"}

		} else if (n == 2) {

			/*	 if (document.frmCad.matUs.value.length == 0) {nomeCampo = "Matricula"; idCampo = "matUs"}
			else*/ if (document.frmCad.nomeUs.value.length == 0) {nomeCampo = "Nome completo"; idCampo = "nomeUs"}
			else if (document.frmCad.nascUs.value.length != 10 || !isDate(document.frmCad.nascUs.value)) {nomeCampo = "Date de nascimento"; idCampo = "nascUs"}
			else if (document.frmCad.colUs && document.frmCad.colUs.value.length == 0) {nomeCampo = "Colégio de origem"; idCampo = "colUs"}
			else if (document.frmCad.cepUs.value.length < 8) {nomeCampo = "CEP"; idCampo = "cepUs"}
			else if (document.frmCad.endUs.value.length == 0) {nomeCampo = "Endereço"; idCampo = "endUs"}
			else if (document.frmCad.numUs.value.length == 0) {nomeCampo = "Número/Complemento"; idCampo = "numUs"}
			else if (document.frmCad.baiUs.value.length == 0) {nomeCampo = "Bairro"; idCampo = "baiUs"}
			else if (document.frmCad.cidUs.value.length == 0) {nomeCampo = "Cidade"; idCampo = "cidUs"}

			else if (document.frmCad.fonUs.value.length == 0) {nomeCampo = "Fone residencial"; idCampo = "fonUs"}
			else if (document.frmCad.celUs.value.length == 0) {nomeCampo = "Fone celular"; idCampo = "celUs"}
			else if (document.frmCad.emaUs.value.length == 0 || !validaEmail(document.frmCad.emaUs.value)) {nomeCampo = "Email"; idCampo = "emaUs"}

			else if (document.frmCad.cursoUs && document.frmCad.cursoUs.value == 0) {nomeCampo = "Curso"; idCampo = "cursoUs"}
			else if (document.frmCad.linguaSu && document.frmCad.linguaUs.value == 0) {nomeCampo = "Língua Estrangeira"; idCampo = "linguaUs"}
			else if (document.frmCad.sh1Us.value != document.frmCad.sh2Us.value || document.frmCad.sh1Us.value.length == 0) {nomeCampo = "Senha"; idCampo = "sh1Us"}

		} else if (n == 3) {

		} else if (n == 4) {
				 if (document.frmCad.matUs.value.length == 0) {nomeCampo = "Matricula"; idCampo = "matUs"}
			else if (document.frmCad.passUs.value.length == 0) {nomeCampo = "Senha"; idCampo = "passUs"}
		} else if (n == 5) {
				 if (document.frmCad.codCurso.value == 0) {nomeCampo = "Curso"; idCampo = "codCurso"}
			else if (document.frmCad.lingua.value == 0) {nomeCampo = "Língua estrangeira"; idCampo = "lingua"}
		} else if (n == 6) {
				 if (document.frmCad.emaUs.value.length == 0 || !validaEmail(document.frmCad.emaUs.value)) {nomeCampo = "Email"; idCampo = "emaUs"}
		}

		if (nomeCampo != '') {
			alert ('Erro ao preencher ' + nomeCampo);
			eval ('document.frmCad.' + idCampo + '.focus()');
			return false;
		} else {
			document.frmCad.submit();
		}
	}

	function verMatricula(mat) {

		document.Posts.location.href="posts.asp?act=verMatr&matr=" + mat;

	}
