function frmEnviar(){
	ok = valFormLoop(document.forms[0]);
	if (!ok){
	alert ("Por Favor, preencha os campos obrigatórios!\n\n"+mensErro);
	document.forms[0].elements[qual].focus();
	return false;
	}
	
	if (VerificaExistencia("ckInteresse")){
		if (document.forms[0].ckInteresse[0].disabled == false){	
			if (!validarInteresse()){return false};
		}	
	}
	
	if (VerificaExistencia("valida")){
		document.forms[0].valida.value = "cadastrar";
	}	
	return true;
}


function frmEnviarUnico(f_valor){
	ok = valFormLoop(document.forms[f_valor]);
	if (!ok){
	alert ("Por Favor, preencha os campos obrigatórios!\n\n"+mensErro);
	document.forms[f_valor].elements[qual].focus();
	return false;
	}
	
	if (VerificaExistencia("ckInteresse")){
		if (document.forms[0].ckInteresse[0].disabled == false){	
			if (!validarInteresse()){return false};
		}	
	}
	
	if (VerificaExistencia("valida")){
		document.forms[0].valida.value = "cadastrar";
	}	
	return true;
}

function frmEnviarLogin(){
	if (document.frmLogin.xtxtLogin.value==''){
	mensErro = "O campo Login é obrigário"
	alert ("Por Favor, preencha os campos obrigatórios!\n\n"+mensErro);
	document.frmLogin.xtxtLogin.focus();
	return false;
	}
	
	if (document.frmLogin.xtxtSenha.value==''){
	mensErro = "O campo Senha é obrigário"
	alert ("Por Favor, preencha os campos obrigatórios!\n\n"+mensErro);
	document.frmLogin.xtxtSenha.focus();
	return false;
	}
	return true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function FotoView(sParam){
	window.open('foto_view.asp?imagem='+sParam,'Fotos','width=650,height=420,status=no,scrollbars=no')
}	

function preloadImage(){
	MM_preloadImages('imagens/menu_quem_on.gif','imagens/menu_inst_on.gif',
					'imagens/menu_edital_on.gif','imagens/menu_realiza_on.gif',
					'imagens/menu_agenda_on.gif','imagens/menu_fotos_on.gif',
					'imagens/menu_opiniao_on.gif','imagens/menu_links_on.gif',
					'imagens/menu_falecon_on.gif','imagens/barra_home_on.gif',
					'imagens/barra_estatuto_on.gif','imagens/barra_cadastro_on.gif',
					'imagens/barra_estatuto_on.gif','imagens/barra_cadastro_on.gif',
					'imagens/barra_mapa_on.gif','imagens/barra_perguntas_on.gif',
					'imagens/menu_quem_on.gif','imagens/menu_inst_ita_on.gif',
					'imagens/menu_edital_on.gif','imagens/menu_realiza_ita_on.gif',
					'imagens/menu_agenda_on.gif','imagens/menu_fotos_ita_on.gif',
					'imagens/menu_opiniao_on.gif','imagens/menu_links_ita_on.gif',
					'imagens/menu_falecon_on.gif','imagens/barra_home_on_ita.gif',
					'imagens/barra_estatuto_on.gif','imagens/barra_cadastro_on_ita.gif',
					'imagens/barra_estatuto_on.gif','imagens/barra_cadastro_on_ita.gif',
					'imagens/barra_mapa_on.gif','imagens/barra_perguntas_on_ita.gif');
}

function fCEP(){
	var sCampo="";
	sCampo = EliminarCaracter(document.forms[0].ytxtCep.value,".");
	sCampo = EliminarCaracter(sCampo,"-");	
	
    if ( (isNaN(sCampo)) || (TirarBrancoFinal(sCampo) == "") || (sCampo.length!=8) ) {
		alert ("Por favor, preencha os campos obrigatórios(com asteriscos) com valores válidos! :\n\nDigite um CEP válido!");
		document.forms[0].ytxtCep.focus();
		document.forms[0].ytxtCep.select();
		return false;  
	}
	frames['frameDados'].location.href = '/shared/buscaCep.asp?ytxtCep='+sCampo;
}

function fUF(){
	if (document.forms[0].zsltPais.value=='BR'){
		document.getElementById('idCep').className = 'tituloCadastro';
		document.getElementById('idEndereco').className = 'tituloCadastro';
		document.getElementById('idComplemento').className = 'tituloCadastro';
		document.getElementById('idBairro').className = 'tituloCadastro';
		document.getElementById('idEstado').className = 'tituloCadastro';
		document.getElementById('idCidade').className = 'tituloCadastro';
		DisablebCampo(1, document.forms[0].ytxtCep);
		DisablebCampo(1, document.forms[0].xtxtRua);
		DisablebCampo(1, document.forms[0].xtxtNumero);
		DisablebCampo(1, document.forms[0].txtComplemento);
		DisablebCampo(1, document.forms[0].xtxtBairro);
		DisablebCampo(1, document.forms[0].zsltEstado);
		DisablebCampo(1, document.forms[0].zsltCidade);
		frames['frameDados'].location.href = '/shared/buscaEstado.asp?pais='+document.forms[0].zsltPais.value;
	}else{
		document.getElementById('idCep').className = 'tituloCadastrooff';
		document.getElementById('idEndereco').className = 'tituloCadastrooff';
		document.getElementById('idComplemento').className = 'tituloCadastrooff';
		document.getElementById('idBairro').className = 'tituloCadastrooff';
		document.getElementById('idEstado').className = 'tituloCadastrooff';
		document.getElementById('idCidade').className = 'tituloCadastrooff';
		DisablebCampo(0, document.forms[0].ytxtCep);
		DisablebCampo(0, document.forms[0].xtxtRua);
		DisablebCampo(0, document.forms[0].xtxtNumero);
		DisablebCampo(0, document.forms[0].txtComplemento);
		DisablebCampo(0, document.forms[0].xtxtBairro);
		DisablebCampo(0, document.forms[0].zsltEstado);
		DisablebCampo(0, document.forms[0].zsltCidade);
	}
}

function fCidade(){
	if (document.forms[0].zsltPais.value !='' && document.forms[0].zsltEstado.value!=''){
		frames['frameDados'].location.href = '/shared/buscaCidade.asp?pais='+document.forms[0].zsltPais.value
		+'&zsltEstado='+document.forms[0].zsltEstado.value;
	}	
}

function fMantemUF(sPais, sEstado){
	frames['frameDados'].location.href = '/shared/buscaEstado.asp?pais='+sPais
	+'&zsltEstado='+sEstado;
}

function fMantemCidade(sPais, sEstado, sCidade){
	frames['frameDados2'].location.href = '/shared/buscaCidade.asp?pais='+sPais
		+'&zsltEstado='+sEstado+'&zsltCidade='+sCidade;
}

function DisablebCampo(v, c){
	if (v =='0')
		c.disabled = true;
	else
		c.disabled = false;
}

function VerificaExistencia(v){
	var campo = document.getElementsByName(v);
	if (campo.length > 0){
		return true;
	}else{
		return false;
	}
}

// elemento tipo checked
// se há não hover ticker indica que o usuario não escolheu nunhuma opcao 
function ck(nome,descnome){
var len = document.forms[0].elements.length
var pas = 0;
var dCampo = descnome;
var entrada = 0;
for (i = 0; i < len ; i++){
	if (document.forms[0].elements[i].name == nome && document.forms[0].elements[i].disabled==false){
		if (document.forms[0].elements[i].checked==true){
		pas = 1
		}
		entrada = 1;
	}
}
	
if (pas == 1){
	return true;
}else{
	return false;
}
}

function ckDisabled(nome,estado){
var len = document.forms[0].elements.length
var pas = 0;
for (i = 0; i < len ; i++){
	if (document.forms[0].elements[i].name == nome){
		document.forms[0].elements[i].disabled = estado;	
		document.forms[0].elements[i].checked = false;
	}	
}
}

function validarInteresse(){
	if (ck("ckInteresse","")==false){
	alert ("Por Favor, preencha os campos obrigatórios!\n\nInteresse inválido.");
	return false;
	}
	return true;
}

function OutroInteresse(){
	if (document.forms[0].ckInteresseOutro.checked){
		document.forms[0].xtxtOutrosInterresses.disabled = false;
		document.getElementById('idInteresse').className = 'tituloCadastrooff';
		document.getElementById('idInteresseOutro').className = 'tituloCadastro';
		ckDisabled('ckInteresse',true);
	}else{
		document.forms[0].xtxtOutrosInterresses.disabled = true;
		document.getElementById('idInteresse').className = 'tituloCadastro';
		document.getElementById('idInteresseOutro').className = 'tituloCadastrooff';
		ckDisabled('ckInteresse',false);
	}	
}

function OutroIndicao(){
	if (document.forms[0].ckIndica.checked){
		document.forms[0].xtxtOutrosIndicaSite.disabled = false;
		document.getElementById('idIndica').className = 'tituloCadastrooff';
		document.getElementById('idIndicaOutro').className = 'tituloCadastro';
		document.forms[0].zsltIndicaSite.options[0].selected = true;
		document.forms[0].zsltIndicaSite.disabled = true;
	}else{
		document.forms[0].xtxtOutrosIndicaSite.disabled = true;
		document.getElementById('idIndica').className = 'tituloCadastro';
		document.getElementById('idIndicaOutro').className = 'tituloCadastrooff';
		document.forms[0].zsltIndicaSite.disabled = false;
	}	
}

function Numero(e)
{
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla < 47 && tecla > 57)) event.returnValue = false;
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

