// JavaScript Document
var dtCh= "/";
var minYear=1930;
var maxYear=1996;
var concMinAno = 1949;
var concMaxAno = 2010;

//var cor 	= '#e5694b';
//var cor 		= '#ffcc66';
var cor 		= '#ffffcc';
var menNome 	= "Por favor, preencha seu nome.";
var menData 	= "Por favor, preencha sua data de nascimento.";
var menEnde 	= "Por favor, preencha seu endereço.";
var menBair 	= "Por favor, preencha seu bairro.";
var menCida 	= "Por favor, preencha sua cidade.";
var menEsta 	= "Por favor, escolha seu estado.";
var menCep		= "Por favor, preencha seu CEP com 8 dígitos.";
var menMai1 	= "Por favor, preencha um endereço de e-mail válido."
var menMai2 	= "Os e-mails digitados estão diferentes.";
var menDdd  	= "Por favor, preencha seu DDD.";
var menTel  	= "Por favor, preencha seu telefone.";
var menDddc 	= "Por favor, preencha o DDD de seu celular.";
var menCel  	= "Por favor, preencha seu celular com 8 dígitos.";
var menIden 	= "Por favor, preencha sua identidade.";
var menOrga 	= "Por favor, preencha o orgão expedidor de sua identidade.";
var menIdEs 	= "Por favor, escolha o estado emissor de sua identidade.";
var menSexo 	= "Por favor, digite o sexo.";
var menSexoTxt 	= "Por favor, digite M ou F.";
var menEscola 	= "Por favor, preencha o nome da escola onde cursou o ensino médio.";
var menConc 	= "Por favor, preencha um ano válido para o campo: ANO DE CONCLUSÃO DO ENSINO MÉDIO.";
var menModa 	= "Por favor, escolha a modalidade de ensino médio.";
var menFisi 	= "Por favor, marque a opção do campo: Física.";
var menPorque 	= "Por favor, preencha o campo POR QUE VOCÊ QUER CURSAR O PRÉ-VESTIBULAR SOCIAL?";
var menPorqueTxt= "O campo POR QUE VOCÊ QUER CURSAR O PRÉ-VESTIBULAR SOCIAL? deve conter pelo menos 50 caracteres.";
var menQuim 	= "Por favor, marque a opção do campo: Química.";
var menPolo 	= "Por favor, escolha o PÓLO onde quer estudar.";
var menPolo_c 	= "Por favor, CONFIRME o PÓLO onde quer estudar.";
var menPolo_d 	= "O PÓLO escolhido e sua CONFIRMAÇÃO não conferem.";
var menPess 	= "Por favor, informe a quantidade de pessoas que moram na mesma casa que você.";
var menDias 	= "Por favor, preencha os dias e horários de estudo e/ou trabalho.";
var menSitu  	= "Por favor, escolha a situação da casa onde mora.";
var menEner  	= "Por favor, preencha o valor da conta de energia elétrica do último mês.";
var menEnZe  	= "Por favor, explique no campo observações o motivo da renda zero.";

var menDespAlug  		= "Por favor, preencha o campo: Aluguel / Prestação do imóvel.";
var menDespCondominio	= "Por favor, preencha o campo: Condomínio.";
var menDespIptu  		= "Por favor, preencha o campo: IPTU.";
var menDespTelefone		= "Por favor, preencha o campo: Telefone fixo.";
var menDespCelular		= "Por favor, preencha o campo: Celular.";
var menDespAgua  		= "Por favor, preencha o campo: Água.";
var menDespGas   		= "Por favor, preencha o campo: Gás.";
var menDespCurso		= "Por favor, preencha o campo: Curso / Colégio.";
var menDespPlano		= "Por favor, preencha o campo: Plano de saúde.";
var menDespInss			= "Por favor, preencha o campo: Carnê do INSS.";
var menDespCartao		= "Por favor, preencha o campo: Cartão de crédito.";
var menDespOutras		= "Por favor, preencha o campo: Outras despesas.";

var menCocs  	= "Por favor, marque a opção do campo: Possui computador em casa?.";
var menCout  	= "Por favor, escolha ao menos uma opção do campo: utiliza computador?";
var menCoIn  	= "Por favor, marque a opção do campo: Acessa a internet.";
var menCoSi  	= "Por favor, escolha ao menos uma opção do campo: Acessa regularmente sites.";
var menObs   	= "Por favor, preencha o campo: vida de estudante e planos.";
var menTerm  	= "Para enviar seu formulário é necessário concordar com o termo de compromisso.";
var menIdad		= "Por favor, preencha a idade.";
var menEsco		= "Por favor, preencha sua escolaridade.";
var menAtiv		= "Por favor, preencha sua atividade de trabalho atual.";
var menRegi		= "Por favor, preencha sua Regime de trabalho.";
var menRend		= "Por favor, preencha sua renda.";
var menLinha	= "Preencha TODOS os dados das pessoas que moram na mesma casa que você.\n Verifique a(s) linha(s):\n";
//var menRendaZero = "Você deve informar o motivo da renda zero no campo Outras informações";
//var menRendaZeroReq = "Informe o motivo dessa pessoa ter rendimento igual a zero no campo: OUTRAS INFORMAÇÕES SOBRE RENDIMENTOS.";
var menRendaZero = "Informe o motivo da pessoa ter rendimento igual a zero no campo: OUTRAS INFORMAÇÕES SOBRE RENDIMENTOS.";
var menEnergZero = "Informe o motivo da conta de energia igual a zero no campo: OUTRAS INFORMAÇÕES SOBRE ENERGIA ELÉTRICA.";
var menPare 	 = "Por favor informe as outras pessoas de sua casa que também estão solicitando uma vaga. Caso não se aplique, digite apenas: NÃO!";


function limpa() {
   document.autentica.cpfID.value="";
   document.autentica.cpfID.focus();
}
function validaCPF() {
	 cpf = document.autentica.cpfID.value;
	 erro = new String;
	 if (cpf.length < 11) erro += "Por favor digite os 11 digitos do CPF! \n\n";
	 var nonNumbers = /\D/;
	 if (nonNumbers.test(cpf)) erro += "Por favor digite apenas numeros! \n\n";
	 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			 erro += "Numero de CPF inválido!"
   }
   var a = [];
   var b = new Number;
   var c = 11;
   for (i=0; i<11; i++){
		   a[i] = cpf.charAt(i);
		   if (i < 9) b += (a[i] * --c);
   }
   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
   b = 0;
   c = 11;
   for (y=0; y<10; y++) b += (a[y] * c--);
   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		   erro +="CPF inválido!";
   }
   if (erro.length > 0){
		   alert(erro);
		   return false;
   }
   return true;
}
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	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}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	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)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

//	alert(pos2);

	if (pos1==-1 || pos2==-1 || pos1==1 || pos2==3 || pos2==4){
		alert("O formato da data deve ser: ddmmaaaa")
		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Por favor digite um mês válido!")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Por favor digite um dia válido para a data de nascimento!")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Por favor digite o ano, com 4 dígitos, entre "+minYear+" e "+maxYear)
		//alert("Por favor digite o ano de nascimento com 4 dígitos.")
		alert("Por favor digite um ano de nascimento válido e com 4 dígitos.")
		return false
	}
	if (year<minYear || year>maxYear){
		alert("Ano de nascimento inválido")		
		return false
	}
	
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Por favor digite uma data válida!")
		return false
	}
return true
}
function validateForm(frm_name) {
	if(frm_name=='autentica') {
		if (validaCPF()==false){
			document.getElementById('cpfID').focus();
			return false;
		}
		
		if (isDate(document.getElementById('data_nasc').value)==false){
			document.getElementById('data_nasc').focus();
			return false;
		}
	
		return true
	}
	
	if(frm_name=='autentica_check') {
		if (!document.getElementById('confirma').checked){
			alert("Você deve marcar que leu as instruções");
			document.getElementById('confirma').focus();
			return false;
		}
		
		if (validaCPF()==false){
			document.getElementById('cpfID').focus();
			return false;
		}		
	
		return true
	}
	
}
function validaConclusao(campo){
	if(document.getElementById(campo).value<concMinAno | document.getElementById(campo).value>concMaxAno){
		document.getElementById(campo).style.backgroundColor = cor;
		alert(menConc);
		wret = false;
		document.getElementById(campo).focus();
	}	
}
// MASCARAS DE FORMULÁRIO
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}
function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}
function soNumeros(v){
    return v.replace(/\D/g,"")
}
function soLetras(v){
    v=v.replace(/[^A-Za-z\sÀÌÒÙÈÁÍÓÚÉÃÏÕÜËÄÖÂÎÔÛÊàìòùèáíóúéãïõüëáöâîôûêÇç]/g,"")
	return v
}
function soAlfaNumerico(v){
    v=v.replace(/[^A-Za-z\sÀÌÒÙÈÁÍÓÚÉÃÏÕÜËÄÖÂÎÔÛÊàìòùèáíóúéãïõüëáöâîôûêÇç0123456789,-/:;]/g,"")
	return v
}
function soEmail(v){
    v=v.replace(/[^A-Za-z\s@._Çç0123456789-]/g,"")
	return v
}
function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}
function data(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca uma barra entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca uma barra entre o terceiro e o quarto dígitos
   
    return v
}
function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}
function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}
function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}
function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}
function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
function isValidEmail(str) {
	//alert(str.indexOf("."));
	//alert(str.length);
	return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}
function initSelects() {
	document.getElementById('estado').selectedIndex =0;
	document.getElementById('identidade_estado').selectedIndex =0;
	//document.getElementById('sexo').selectedIndex =0;
	document.getElementById('modalidade').selectedIndex =0;
	document.getElementById('polo').selectedIndex =0;
	document.getElementById('pessoas').selectedIndex =0;
	document.getElementById('idade_r').selectedIndex =0;
	document.getElementById('escolaridade_r').selectedIndex =0;
	document.getElementById('regime_trabalho_r').selectedIndex =0;
	document.getElementById('situacao_casa').selectedIndex =0;
	document.getElementById('comp_email').selectedIndex =0;
}
function initStyle(nome) {
	document.getElementById(nome).style.backgroundColor = '#ffffff';
}
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
function disableButton(disable) {
	var n = document.getElementsByName(disable).length;	
	var btn = document.getElementsByName(disable);

	for (var i=0; i<n-1; i++) {
        btn[i].checked = false;
    }
}
function disableOneButton(disable,ind) {
	document.getElementsByName(disable)[ind].checked = false;	
}
function validaEnergia(origem,interacao){
	if (	document.getElementById(origem).value == String(0) 
		&&  document.getElementById(interacao).value=="") {
				alert(menEnergZero);
				document.getElementById(interacao).style.backgroundColor = cor;
				document.getElementById(interacao).focus();
	}
}
function validaRenda(origem,interacao,mostra,campo){
	// digitando na ordem
	if (	document.getElementById(origem).value == 0
		//&& 	document.getElementById(interacao).value==""
		&&	document.getElementById(campo).value > 17) 
	{
		document.getElementById(interacao).value="";
		document.getElementById(mostra).style.display = "";
		alert(menRendaZero);
		document.getElementById(interacao).style.backgroundColor = cor;
		document.getElementById(interacao).focus();
	} else {
		document.getElementById(interacao).value="";
		document.getElementById(mostra).style.display = "none";
	}
}
function povoaPrimeiroNome(de,para){
var str=document.getElementById(de).value;
var priNome = String(str.split(" ",1));
document.getElementById(para).value=priNome.toUpperCase();	
}

function validaFormulario(frm_name) {
	var wret = true;

	if (wret) {
		if (document.getElementById('nome').value == "") {
			document.getElementById('nome').style.backgroundColor = cor;
			alert(menNome);
			wret = false;
			document.getElementById('nome').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('data_nascimento').value == "" | document.getElementById('data_nascimento').value == "ddmmaaaa") {
			document.getElementById('data_nascimento').style.backgroundColor = cor;
			alert(menData);
			wret = false;
			document.getElementById('data_nascimento').focus();
		} 
	}
	
	if (wret) {
		if (isDate(document.getElementById('data_nascimento').value)==false){
			document.getElementById('data_nascimento').style.backgroundColor = cor;
			document.getElementById('data_nascimento').focus();
			return false;
		}
	}
	
	if (wret) {
		if (document.getElementById('endereco').value == "") {
			document.getElementById('endereco').style.backgroundColor = cor;
			alert(menEnde);
			wret = false;
			document.getElementById('endereco').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('bairro').value == "") {
			document.getElementById('bairro').style.backgroundColor = cor;
			alert(menBair);
			wret = false;
			document.getElementById('bairro').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('cidade').value == "") {
			document.getElementById('cidade').style.backgroundColor = cor;
			alert(menCida);
			wret = false;
			document.getElementById('cidade').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('estado').selectedIndex == 0) {
			document.getElementById('estado').style.backgroundColor = cor;
			alert(menEsta);
			wret = false;
			document.getElementById('estado').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('cep').value.length <8) {
			document.getElementById('cep').style.backgroundColor = cor;
			alert(menCep);
			wret = false;
			document.getElementById('cep').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('email_a').value != "") {

			if (!isValidEmail(document.getElementById('email_a').value)){
				document.getElementById('email_a').style.backgroundColor = cor;
				alert(menMai1);
				wret = false;
				document.getElementById('email_a').focus();
			}
			
		}
	}
	
	if (wret) {
		if (document.getElementById('email_a').value != "") {
			
			if(document.getElementById('email_a').value != document.getElementById('email_b').value){
				document.getElementById('email_b').style.backgroundColor = cor;
				alert(menMai2);
				wret = false;
				document.getElementById('email_b').focus();
			}

		}
	}

	if (wret) {
		if (document.getElementById('tel_ddd').value.length <2) {
			document.getElementById('tel_ddd').style.backgroundColor = cor;
			alert(menDdd);
			wret = false;
			document.getElementById('tel_ddd').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('telefone').value.length <8) {
			document.getElementById('telefone').style.backgroundColor = cor;
			alert(menTel);
			wret = false;
			document.getElementById('telefone').focus();
		} 
	}

	if (document.getElementById('cel_ddd').value!="" | document.getElementById('celular').value!="") {
		if (wret) {
				if (document.getElementById('cel_ddd').value.length <2) {
					document.getElementById('cel_ddd').style.backgroundColor = cor;
					alert(menDddc);
					wret = false;
					document.getElementById('cel_ddd').focus();
				}
		}
		if (wret) {
				if (document.getElementById('celular').value.length <8) {
					document.getElementById('celular').style.backgroundColor = cor;
					alert(menCel);
					wret = false;
					document.getElementById('celular').focus();
				}
		}
	}

	if (wret) {
		if (document.getElementById('identidade').value == "") {
			document.getElementById('identidade').style.backgroundColor = cor;
			alert(menIden);
			wret = false;
			document.getElementById('identidade').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('identidade_orgao').value == "") {
			document.getElementById('identidade_orgao').style.backgroundColor = cor;
			alert(menOrga);
			wret = false;
			document.getElementById('identidade_orgao').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('identidade_estado').selectedIndex == 0) {
			document.getElementById('identidade_estado').style.backgroundColor = cor;
			alert(menIdEs);
			wret = false;
			document.getElementById('identidade_estado').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('sexo').value == "") {
			document.getElementById('sexo').style.backgroundColor = cor;
			alert(menSexo);
			wret = false;
			document.getElementById('sexo').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('sexo').value.toUpperCase() != "M" &  document.getElementById('sexo').value.toUpperCase() != "F") {
			document.getElementById('sexo').style.backgroundColor = cor;
			alert(menSexoTxt);
			wret = false;
			document.getElementById('sexo').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('escola').value == "") {
			document.getElementById('escola').style.backgroundColor = cor;
			alert(menEscola);
			wret = false;
			document.getElementById('escola').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('conclusao').value == "" | document.getElementById('conclusao').value<concMinAno | document.getElementById('conclusao').value>concMaxAno) {
			document.getElementById('conclusao').style.backgroundColor = cor;
			alert(menConc);
			wret = false;
			document.getElementById('conclusao').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('modalidade').selectedIndex == 0) {
			document.getElementById('modalidade').style.backgroundColor = cor;
			alert(menModa);
			wret = false;
			document.getElementById('modalidade').focus();
		} 
	}
			
	if (wret) {
		if (document.getElementById('porque').value == "") {
			document.getElementById('porque').style.backgroundColor = cor;
			alert(menPorque);
			wret = false;
			document.getElementById('porque').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('porque').value.length<50) {
			document.getElementById('porque').style.backgroundColor = cor;
			alert(menPorqueTxt);
			wret = false;
			document.getElementById('porque').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('polo').selectedIndex == 0) {
			document.getElementById('polo').style.backgroundColor = cor;
			alert(menPolo);
			wret = false;
			document.getElementById('polo').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('polo_conf').selectedIndex == 0) {
			document.getElementById('polo_conf').style.backgroundColor = cor;
			alert(menPolo_c);
			wret = false;
			document.getElementById('polo_conf').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('polo_conf').value != document.getElementById('polo').value) {
			document.getElementById('polo_conf').style.backgroundColor = cor;
			alert(menPolo_d);
			wret = false;
			document.getElementById('polo_conf').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('pessoas').selectedIndex == 0) {
			document.getElementById('pessoas').style.backgroundColor = cor;
			alert(menPess);
			wret = false;
			document.getElementById('pessoas').focus();
		} 
	}
	// REQUERENTE
	if (wret) {
		if (document.getElementById('idade_r').selectedIndex == 0) {
			document.getElementById('idade_r').style.backgroundColor = cor;
			alert(menIdad);
			wret = false;
			document.getElementById('idade_r').focus();
		} 
	}
	if (wret) {
		if (document.getElementById('escolaridade_r').value=="") {
			document.getElementById('escolaridade_r').style.backgroundColor = cor;
			alert(menEsco);
			wret = false;
			document.getElementById('escolaridade_r').focus();
		} 
	}
	if (wret) {
		if (document.getElementById('atividade_r').value=="") {
			document.getElementById('atividade_r').style.backgroundColor = cor;
			alert(menAtiv);
			wret = false;
			document.getElementById('atividade_r').focus();
		} 
	}
	if (wret) {
		if (document.getElementById('regime_trabalho_r').selectedIndex == 0) {
			document.getElementById('regime_trabalho_r').style.backgroundColor = cor;
			alert(menRegi);
			wret = false;
			document.getElementById('regime_trabalho_r').focus();
		} 
	}
	if (wret) {
		if (document.getElementById('renda_r').value=="") {
			document.getElementById('renda_r').style.backgroundColor = cor;
			alert(menRend);
			wret = false;
			document.getElementById('renda_r').focus();
		} 
	}
	if (wret) {
		if (	document.getElementById('renda_r').value==0 
			&& 	document.getElementById('idade_r').value>17							
			&& 	document.getElementById('obs_renda_r').value==""	) {
					document.getElementById('td_obs_renda_r').style.display = "";
					document.getElementById('obs_renda_r').style.backgroundColor = cor;
					alert(menRendaZero);
					wret = false;
					document.getElementById('obs_renda_r').focus();
		} 
	}
	
	// LINHAS EXTRAS

	var index = Number(document.getElementById('pessoas').value) - 1;
	
	if (wret) {
		var mens = menLinha;
		var obj = "";
		var maiorComRendaZero = "";

		for (var i=1; i <= index; i++) {
			// Verificando as linhas que não estão preenchidas
			if(	document.getElementById('primeiro_nome_'+i).value 			=="" 	|
				document.getElementById('parentesco_'+i).value 				=="" 	|
				document.getElementById('parentesco_'+i).value.toLowerCase() =="requerente" 	|
				
				
				document.getElementById('idade_'+i).selectedIndex 			== 0 	|
				document.getElementById('escolaridade_'+i).value 			=="" 	|
				document.getElementById('atividade_'+i).value 				=="" 	|
				document.getElementById('regime_trabalho_'+i).selectedIndex == 0 	|
				document.getElementById('renda_'+i).value 					=="" 	|
				(		document.getElementById('renda_'+i).value==0 
					&& 	document.getElementById('idade_'+i).value>17
					&&	document.getElementById('obs_renda_'+i).value==""	)		){
				//montando a mensagem
				mens += i +'° Morador;\n';
				
				if(		document.getElementById('renda_'+i).value==0 
					&& 	document.getElementById('idade_'+i).value>17
					&&	document.getElementById('obs_renda_'+i).value==""	){
					// concatenando a mensagem para renda zero
					mens += menRendaZero +'\n\n';
				}
				
				wret = false;
			}
			
			// Montando as interações
			if(document.getElementById('primeiro_nome_'+i).value ==""){
				document.getElementById('primeiro_nome_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'primeiro_nome_'+i;
				}
			}
			if(document.getElementById('parentesco_'+i).value =="" || document.getElementById('parentesco_'+i).value.toLowerCase() == "requerente"){
				document.getElementById('parentesco_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'parentesco_'+i;
				}
			}
			if(document.getElementById('idade_'+i).selectedIndex==0){
				document.getElementById('idade_'+i).style.backgroundColor = cor;
				if(!obj){	
					obj = 'idade_'+i;
				}
			}
			if(document.getElementById('escolaridade_'+i).value==""){
				document.getElementById('escolaridade_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'escolaridade_'+i;
				}
			}
			if(document.getElementById('atividade_'+i).value==""){
				document.getElementById('atividade_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'atividade_'+i;
				}
			}
			if(document.getElementById('regime_trabalho_'+i).selectedIndex==0){
				document.getElementById('regime_trabalho_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'regime_trabalho_'+i;
				}
			}
			if(document.getElementById('renda_'+i).value==""){
				document.getElementById('renda_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'renda_'+i;
				}
			}
			// Checando se tem maior com renda zero
			if(		document.getElementById('renda_'+i).value==0 
				&& 	document.getElementById('idade_'+i).value>17
				&&	document.getElementById('obs_renda_'+i).value==""){
				document.getElementById('obs_renda_'+i).style.backgroundColor = cor;
				if(!obj){
					obj = 'obs_renda_'+i;
				}
				document.getElementById('td_obs_renda_'+i).style.display = "";
			}

		} // end FOR
		//alert(wret);
		//alert(obj);
		if(wret==false){
			alert(mens);
			document.getElementById(obj).style.backgroundColor = cor;
			document.getElementById(obj).focus();
		}
	}

	// FIM LINHAS EXTRAS

	if (wret) {
		if (document.getElementById('dias_horarios').value == "") {
			document.getElementById('dias_horarios').style.backgroundColor = cor;
			alert(menDias);
			wret = false;
			document.getElementById('dias_horarios').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('situacao_casa').selectedIndex == 0) {
			document.getElementById('situacao_casa').style.backgroundColor = cor;
			alert(menSitu);
			wret = false;
			document.getElementById('situacao_casa').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_aluguel').value == "") {
			document.getElementById('desp_aluguel').style.backgroundColor = cor;
			alert(menDespAlug);
			wret = false;
			document.getElementById('desp_aluguel').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_condominio').value == "") {
			document.getElementById('desp_condominio').style.backgroundColor = cor;
			alert(menDespCondominio);
			wret = false;
			document.getElementById('desp_condominio').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_iptu').value == "") {
			document.getElementById('desp_iptu').style.backgroundColor = cor;
			alert(menDespIptu);
			wret = false;
			document.getElementById('desp_iptu').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_telefone').value == "") {
			document.getElementById('desp_telefone').style.backgroundColor = cor;
			alert(menDespTelefone);
			wret = false;
			document.getElementById('desp_telefone').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_celular').value == "") {
			document.getElementById('desp_celular').style.backgroundColor = cor;
			alert(menDespCelular);
			wret = false;
			document.getElementById('desp_celular').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_agua').value == "") {
			document.getElementById('desp_agua').style.backgroundColor = cor;
			alert(menDespAgua);
			wret = false;
			document.getElementById('desp_agua').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_gas').value == "") {
			document.getElementById('desp_gas').style.backgroundColor = cor;
			alert(menDespGas);
			wret = false;
			document.getElementById('desp_gas').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_curso').value == "") {
			document.getElementById('desp_curso').style.backgroundColor = cor;
			alert(menDespCurso);
			wret = false;
			document.getElementById('desp_curso').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_plano').value == "") {
			document.getElementById('desp_plano').style.backgroundColor = cor;
			alert(menDespPlano);
			wret = false;
			document.getElementById('desp_plano').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_inss').value == "") {
			document.getElementById('desp_inss').style.backgroundColor = cor;
			alert(menDespInss);
			wret = false;
			document.getElementById('desp_inss').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_cartao').value == "") {
			document.getElementById('desp_cartao').style.backgroundColor = cor;
			alert(menDespCartao);
			wret = false;
			document.getElementById('desp_cartao').focus();
		} 
	}
	
	if (wret) {
		if (document.getElementById('desp_outras').value == "") {
			document.getElementById('desp_outras').style.backgroundColor = cor;
			alert(menDespOutras);
			wret = false;
			document.getElementById('desp_outras').focus();
		} 
	}

	if (wret) {
		if (document.getElementById('energia').value == "") {
			document.getElementById('energia').style.backgroundColor = cor;
			alert(menEner);
			wret = false;
			document.getElementById('energia').focus();
		} 
	}
	
	if (wret) {
		if (	document.getElementById('energia').value == 0 
			&& 	document.getElementById('obs_energia').value == "") {
			document.getElementById('obs_energia').style.backgroundColor = cor;
			alert(menEnergZero);
			wret = false;
			document.getElementById('obs_energia').focus();
		} 
	}

	if (wret) {
		if (!valButton(document.getElementsByName('comp_possui'))) {
			document.getElementById('comp_possui_fundo').style.backgroundColor = cor;
			alert(menCocs);
			wret = false;
			document.getElementById('comp_possui').focus();
		}
	}
	
	if (wret) {
		if (!valButton(document.getElementsByName('comp_utiliza[]'))) {
			document.getElementById('comp_utiliza_fundo').style.backgroundColor = cor;
			alert(menCout);
			wret = false;
			document.getElementById('comp_utiliza[]').focus();
		}
	}
	
	if (wret) {
		if (document.getElementById('parentes_insc').value=="") {
			document.getElementById('parentes_insc').style.backgroundColor = cor;
			alert(menPare);
			wret = false;
			document.getElementById('parentes_insc').focus();
		} 
	}
	
	if (wret) {
		if (!document.getElementById('termo_compromisso').checked) {
			document.getElementById('termo_compromisso').style.backgroundColor = cor;
			alert(menTerm);
			wret = false;
			document.getElementById('termo_compromisso').focus();
		} 
	}
	
	if (wret){
	//	alert("OK")
		document.getElementById(frm_name).submit();
	}
}
