var camposignora = new Array();
var camposobr = new Array();
var paginaatual = ''
diasmeses = new Array();
var keycodesnum = new Array(9,8,48,49,50,51,52,53,54,55,56,57);
var pgtemp = window.location.href.split("/")
var pagina = pgtemp[pgtemp.length - 1]
if (pagina.indexOf("?") != -1){
	pagina = pagina.substr(0,pagina.indexOf("?"))
}
var cpsmascara = new Array('cpf','cep');
var cpsnumericos = new Array();
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}
function tiramascara(campo){
	texto = campo;
	texto = campo.replace('-','');
	texto = texto.replace('(','');
	texto = texto.replace(')','');
	return texto;
}
function qtdechartexto(texto,caracter){
	var qtdecharacteres = 0;
	for(i=0;i<texto.length;i++){
		if (texto.substr(i,1) == caracter){
			qtdecharacteres += 1;	
		}
	}
	return qtdecharacteres;
}
function statusbotcepconfirmar(status){
	document.getElementById('cep').disabled = status;
	document.getElementById('botconfirmar').disabled = status;
}
function limpacamposendereco(){
	document.getElementById("ufstatus").innerHTML = "<font color='#999999' size='1' face='Verdana, Arial, Helvetica, sans-serif'>Não definido.</font>";
	document.getElementById("cidadestatus").innerHTML = "<font color='#999999' size='1' face='Verdana, Arial, Helvetica, sans-serif'>Não definido.</font>";
	document.getElementById("enderecostatus").innerHTML = "<font color=\"#999999\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Não definido.</font>";
	document.getElementById("bairrostatus").innerHTML = "<font color=\"#999999\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Não definido.</font>";
}
function buscaenderecocampo(){
	campocep = tiramascara(document.getElementById('cep').value);
	if (campocep.length == 8){
		if (document.getElementById('cep').value.indexOf('-') == 5 && qtdechartexto(document.getElementById('cep').value,'-') == 1){
			statusbotcepconfirmar(true);
			limpacamposendereco();
			xajax_pegacepinterno(campocep);
			if (document.getElementById('numeroend')){
				document.getElementById('numeroend').focus();
			}	
		}else{ 
			document.getElementById('enderecolabel').innerHTML='&nbsp;- Campo de cep inválido.';	
		}
	}
}
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 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{3})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
	var tamanho = v.substr(v.indexOf('-') + 1,v.length).length
	if (tamanho == 5){
		v=v.replace('-','');
		v=v.replace(/(\d{4})(\d)/,"$1-$2")
	}
    return v
}

function cpfin(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 cepin(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 newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar;
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}
function getbrowserwidth()


    {
    	if (navigator.userAgent.indexOf("MSIE") > 0)


        	{
        		return(document.body.clientWidth);
        	}
        else


            {
            		return window.outerWidth;
            	}
        }
        function getbrowserheight()


            {
            	if (navigator.userAgent.indexOf("MSIE") > 0)


                	{
                		return(document.body.clientHeight);
                	} 
                else


                    {
                    		return(window.outerHeight);
                    	}
                }
                var popup = new Object()
                function CenterPopup(URL, width, height)


                    {
                    	// get center of browser window
                    	var X = getbrowserwidth() / 2
                    	var Y = getbrowserheight() / 2
                    	
                    	popup = window.open(URL, 'PopUp', 
                    		'scrollbars=yes ' +
                    		'width=' + width + ' ' +
                    		'height=' + height + ' ' +
                    		'top=' + (window.screenTop + (Y - (height/2))) + ' ' +
                    		'left=' + (window.screenLeft + (X - (width/2))) 
                    		)
                    	
                    	popup.focus()
                }


function preparavarsjava(cpsignora,pgatual,cpsobr){
	camposjs = cpsignora.split(',');
	camposob = cpsobr.split(',');
	for (i=0;i<camposjs.length;i++){
		camposignora[i] = camposjs[i];	
	}
	for (i=0;i<camposob.length;i++){
		camposobr[i] = camposob[i];	
	}
	paginaatual = pgatual;
}
function in_array(arraydin,valor){
	valorretorno = false;
	for (i in arraydin) {	
		if (valor.toString() == arraydin[i].toString()){
			valorretorno = true;
		}
	}
	return valorretorno;
}
function trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function validavalor(val,nomecampo){
	if (val != ''){		
		if (!IsNumeric(val)) { 
			return alertafocacampo(nomecampo,'Campo "' + traduznomecampo(nomecampo) + '" inválido.');
		}else{
			return true;
		}
	}else if (val == '0'){
			return true;
	}else{
		return alertafocacampo(nomecampo,'');
	}
}
function checa_email(nomecampo){
	var email_string = document.all(nomecampo).value;
	if (campovazio(email_string)){
		return alertafocacampo(nomecampo,'');
	}else{
		if (email_string.indexOf("@") == -1){
			return alertafocacampo(nomecampo,'@ não encontrado.');
		}else if (email_string.indexOf("@") < 1){
			return alertafocacampo(nomecampo,'Favor digitar um valor antes do @.');
		}else{
			if (email_string.substring(email_string.indexOf("@") + 1,email_string.length) != 0){
				if (email_string.substring(email_string.indexOf("@") + 2,email_string.length) == 0){
					return alertafocacampo(nomecampo,'Favor completar o endereço de email.');
				}else if (email_string.substring(email_string.indexOf("@") + 1,email_string.indexOf("@") + 2) == "."){
					return alertafocacampo(nomecampo,'O ponto não pode estar depois do arroba.');
				}else if (email_string.indexOf(".") == -1){
					return alertafocacampo(nomecampo,'Favor colocar um ponto.');
				}else if (email_string.indexOf(".") == email_string.length -1){
					return alertafocacampo(nomecampo,'Favor completar o email.');
				}else if (email_string.indexOf("..") != -1){
					return alertafocacampo(nomecampo,'Email inválido.');
				}else{
					return true;
				}
			}else{
					return alertafocacampo(nomecampo,'Favor completar o e-mail.');
			}
		}
	}
}
function campovazio(valor) {
	valconv = trim(valor);
	if (valconv == "" || valconv == null || valconv.length == 0 || valconv == '0') {
		return true;
	} else {
   		return false;
	}
}
function nomeproprio(variavel){
	varconv = variavel.substring(0,1).toUpperCase() + variavel.substring(1,variavel.length).toLowerCase();
	return varconv;
}
function traduznomecampo(nomecampo){
	nomecampoval = nomecampo.toLowerCase();
	switch(nomecampoval){
	case 'endereco':
	  return 'Endereço';
	  break;
	case 'usuario':
	  return 'Usuário';
	  break;
	case 'textobilhete':
	  return 'Texto Bilhete';
	  break;
	case 'textoemailcobr':
	  return 'Texto de email de Cobrança';
	  break;
	case 'demailcobr':
	  return 'Dias email cobrança';
	  break; 
	case 'dpagamento':
	  return 'Dia de Pagamento';
	  break;
	case 'dbloqueio':
	  return 'Dias Bloqueio';
	  break;
	case 'descricao':
	case 'linhatexto':
	  return 'Descrição';
	  break; 
	case 'obs':
	  return 'Observação';
	  break; 
	case 'razaosocial':
	  return 'Razão Social';
	  break; 
	case 'mes':
	  return 'Mês';
	  break;	 
	case 'marqueetextocab':
	  return 'Texto marquee';
	  break;	  
	case 'confere_senha':
	  return 'Confere Senha';
	  break;	  
	case 'uf':
	  return 'Estado';
	  break;	  
	case 'senhaatual':
	  return 'Senha Atual';
	  break;	  	  
	case 'idatividades':
	  return 'Atividade';
	  break;	  
	case 'emailadmin':
	  return 'E-mail do Admin';
	  break;	 
	case 'novasenha':
	  return 'Nova Senha';
	  break;	 	 
	case 'loginesquecisenha':
	  return 'Login';
	  break;	 	   	  
	default:
	  return nomeproprio(nomecampoval);
	} 
}
function alertafocacampo(nomecampo,mensagem){
	var campo = document.getElementById(nomecampo);
	if(mensagem == ''){
		alert('Favor preencher o campo "' + traduznomecampo(nomecampo) + '".');
	}else{
		alert(mensagem);
	}
	if (campo.type != 'select-one' && campo.id != '0to9'){
		campo.value = "";
	}
	document.getElementById(nomecampo).focus();
	return false;
}
function pegacamposform(){
valores = new Array();
valores['nome'] = new Array();
valores['tipo'] = new Array();
valores['valorcampo'] = new Array;
valores['id'] = new Array;
a = 0;
for (c=0;c<document.forms[0].length;c++){
	campo = document.forms[0].elements[c];
	valorcampo = campo.value;
	nome = campo.name;
	if (!in_array(camposignora,nome) && in_array(camposobr,nome)){
		valores['nome'][a] = campo.name;
		valores['tipo'][a] = campo.type;
		valores['valorcampo'][a] = campo.value;
		a += 1;
	}
}
	return valores;
}
function validacaoform(){
	campos = pegacamposform();
	for (c=0;c<campos['nome'].length;c++){
		valorcampo 	= campos['valorcampo'][c];
		nome 			= campos['nome'][c];
		tipo 				= campos['tipo'][c];
		switch(nome.toLowerCase()){
		case 'email':
		case 'emailadmin':
			if (!checa_email(nome)){
				return false;
			}
		break;
		default:
			if (campovazio(valorcampo)){
				return alertafocacampo(nome,'');
			}
		}
	}
}
function checaformulario(){
	var pedacopagina = window.location.href.toLowerCase().split('/');
	var pgatual = pedacopagina[pedacopagina.length - 1];
	pgatual = pgatual.replace(".php","")
	pgstelefones = new Array('cadastroclientes');
	if (in_array(pgstelefones,pgatual)){;
		if (checatel('tel1') && checatel('tel2') && checatel('celular') && checatel('fax')){
			return validacaoform();	
		}else{
			return false;
		}
	}else{
		return validacaoform();	
	}	
}
function preparaform(){
	document.forms[0].onsubmit = new Function('return checaformulario();');
	document.forms[0].method="post";
	if (paginaatual == 'lancamentos'){
		if (document.all('catradio')){
			if (document.all('catradio')[0].checked){
				document.all('catradio')[0].disabled = true;
				document.all('catradio')[1].disabled = false;	
			}else{
				document.all('catradio')[1].disabled = true;
				document.all('catradio')[0].disabled = false;		
			}
		}	
	}
	for (c=0;c<document.forms[0].length;c++){
		campo = document.forms[0].elements[c];
		valorcampo = campo.value;
		nome = campo.name;
		if(campo.type == 'text' || campo.type =='password'){
			campo.className = 'camposnormal';
			campo.onblur = new Function('mudacorcampo("normal",this)');
			campo.onfocus = new Function('mudacorcampo("foco",this)');
		}
	}
}
function mudacorcampo(estado,campo){
	nomeclasse = "camposfocus";
if (estado == 'normal'){
	nomeclasse = "camposnormal";
}
campo.className=nomeclasse;
}

function checkCR2(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	tipobrowser = navigator.appName.toLowerCase();
	var codigochave = evt.keyCode;
	if (document.getElementById('loadingMessage')){
		if (document.getElementById('loadingMessage').style.display == 'block'){
			if (codigochave == 40 || codigochave == 38){
				return false;
			}
		}
	}
	if (node){
		if (in_array(cpsmascara,node.id) && codigochave == 46){
			return false;
		}
		if (node.type == 'file' && codigochave == 8){
			return false;
		}
	}
}

function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
tipobrowser = navigator.appName.toLowerCase();
var codigochave = evt.keyCode;
var kcodestrava 					= new Array(34,39,60,62);
if (node){
	if (node.type == 'file' && codigochave == 8){
		return false;
	}
	if ((tipobrowser != 'microsoft internet explorer') && (codigochave != 8)){
		codigochave = evt.charCode;
	}
	if (codigochave != 8){
		var valorcampo = node.value		
		if (in_array(kcodestrava,codigochave)){
			return false;
		}else{
			if ((codigochave == 13) && (node.id == 'loginesquecisenha')){
				checaesquecisenha();
				return false;
			}else if ((codigochave == 13) && (node.id == 'cpbusca')){
				buscaclassificados();
				return false;
			}else if ((codigochave == 13) && (node.id == 'buscaguia')){
				buscar();
				return false;							
			}else if (in_array(cpsnumericos,node.id)){
				keycodesnum.unshift(44);
				keycodesnum.unshift(46);
				if (!in_array(keycodesnum,codigochave)){
					return false;
				}
			}else if(node.id == 'email'){
				if (codigochave == 32){
					return false;
				}
			}else if (node.id == 'userfile'){
				return false;
			}
		}
	}
}
}
function delregistro(id,tabela){
input_box=confirm("Tem certeza de que deseja excluir este registro?.");
	if (input_box){
		window.location.href = 'redirect.php?acao=deletar&tabela=' + tabela + '&id=' + id;
	}	
}
function acao(id,acaobot){
	if (document.all('meses' + id).value){
		valorcombo = document.all('meses' + id).value.split("|");
	}else{
		valorcombo='1';
	}	
	mes = valorcombo[0];
	ano = valorcombo[1];
	if (valorcombo == '0'){
		alert("Favor selecionar um mês");
		document.all('meses' + id).focus();
	}else{
		window.location.href = 'redirect.php?acao=' + acaobot + '&mes=' + mes + '&ano=' + ano + '&id=' + id + '&frame=true';
	}
}
function abreimpr(pagina,mesatual){
	alert("Se a janela não abrir, verifique se o seu navegador possui um Anti-Popup ativado.");
	CenterPopup('impressoes/' + pagina + '.php?mesatual=' + mesatual,650,400)
}
function mudaimpr(cat,mesatual){
	top.imprcab.location.href=cat.toLowerCase() + '.php?mesatual=' + mesatual;
	top.document.all('titulo').innerHTML = cat.toUpperCase() + ' - Impressão';
}

function alteradata(tabela,campo){
         var X = getbrowserwidth() / 2
         var Y = getbrowserheight() / 2
                    	width = 250;
						height = 100;	
                    	window.open('editardata.php?tabela=' + tabela + '&campo=' + campo, 'PopUp', 
                    		'scrollbars=no ' +
                    		'width=' + width + ' ' +
                    		'height=' + height + ' ' +
                    		'top=' + (window.screenTop + (Y - (height/2))) + ' ' +
                    		'left=' + (window.screenLeft + (X - (width/2))) 
                    		)
}

function abrerelatorio(){
         var X = getbrowserwidth() / 2
         var Y = getbrowserheight() / 2
                    	width = 200;
						height = 150;
                    	window.open('relatoriomes.php', 'PopUp', 
                    		'scrollbars=no ' +
                    		'width=' + width + ' ' +
                    		'height=' + height + ' ' +
                    		'top=' + (window.screenTop + (Y - (height/2))) + ' ' +
                    		'left=' + (window.screenLeft + (X - (width/2))) 
                    		)
}
function abreservadd(){
         var X = getbrowserwidth() / 2
         var Y = getbrowserheight() / 2
                    	width = 400;
						height = 70;
                    	window.open('servicosadicionais.php', 'PopUp', 
                    		'scrollbars=no ' +
                    		'width=' + width + ' ' +
                    		'height=' + height + ' ' +
                    		'top=' + (window.screenTop + (Y - (height/2))) + ' ' +
                    		'left=' + (window.screenLeft + (X - (width/2))) 
                    		)
}

function desativabotcima2(botao){
quadro = top.conteudo.conteudologin.cabuser
if (quadro){
	for (i=0;i<quadro.document.all.length;i++){
		bt = quadro.document.all[i]
		if (bt.type == 'button'){
			if (bt.name.toLowerCase() == botao){
				bt.disabled = true
			}else{
				bt.disabled = false;
			}
		}
	}
}
}
if (navigator.userAgent.indexOf("MSIE") > 0){
	document.oncontextmenu = function(){return false} 
	if(document.layers) { 
		window.captureEvents(Event.MOUSEDOWN); 
		window.onmousedown = function(e){ 
		if(e.target==document)
			return false; 
		} 
	}else{ 
		document.onmousedown = function(){return false} 
	} 
}
function rodaflash(flash,largura,altura,corfundo,transparente)
{
   document.write('<object classid="clsid:D27CDB6E..." width="' + largura + '" height="' + altura + '">\n');
   if (corfundo != ''){
   		document.write('<param name="BGCOLOR" value="' + corfundo + '">');
		bgcolor = 'bgcolor="' + corfundo + '"';
   }else{
   		bgcolor = "";
   }
	if (transparente){
		document.write('<param name="wmode" value="transparent">\n');
		textotransp = 'wmode="transparent"';
	}else{
		textotransp = "";
	}
   document.write('<param name="movie" value="' + flash + '" />\n');
   document.write('<param name="quality" value="high" />\n');
   document.write('<embed src="' + flash + '" width="' + largura + '" height="' + altura + '" ' + textotransp + ' ' + bgcolor + '></embed>');
   document.write('</object>');
}
function delregistro(id,tabela){
	input_box=confirm("Tem certeza de que deseja excluir este registro?.");
		if (input_box){
			window.location.href = '../redirect.php?acao=deletar&tabela=' + tabela + '&id=' + id;
		}	
}

function checa_senha2(){
	if(campovazio(usuario)){
		return alertafocacampo('usuario','');
	}else{
		if (campovazio(novasenha)){
			return alertafocacampo('novasenha','');
		}else{
			if (campovazio(confere_senha)){
				return alertafocacampo('confere_senha','');
			}else{
				if (novasenha != confere_senha){
					return alertafocacampo('confere_senha','A senha não confere. Favor redigitá-la.')
					document.all("confere_senha").value = '';
				}else{
					return true
				}
			}
		}	
	}
}
function checa_senha(idtemp,tipousuario){
	novasenha = trim(document.getElementById('novasenha').value)
	confere_senha = trim(document.getElementById('confere_senha').value)
	if (!idtemp || tipousuario == 'USER'){
		senhaatual = trim(document.getElementById('senhaatual').value)
		if (!campovazio(senhaatual)){
			checa_senha2();	
		}else{
			alertafocacampo('senhaatual','');	
		}
	}else{
		if (!campovazio(novasenha)){
			checa_senha2();	
		}else{
			alertafocacampo('novasenha','');	
		}
	}
	
}
function checa_senha2(){
	if (campovazio(novasenha)){
		alertafocacampo('novasenha','');
	}else{
		if (campovazio(confere_senha)){
			alertafocacampo('confere_senha','');
		}else{
			if (novasenha != confere_senha){
				alertafocacampo('confere_senha','A senha não confere. Favor redigitá-la.')
				document.getElementById("confere_senha").value = '';
			}else{
				xajax_alterasenha(xajax.getFormValues('formdinamico'));
			}
		}
	}	
}
function mostracontsimples(pagina){
	top.conteudo.location.href = 'frame_conteudossimples.php?pagina=' + pagina
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function ampliafoto(id,caminhoabsoluto){
	newWindow(caminhoabsoluto + 'fotoclgrande.php?id=' + id, 'Imagem', 320, 240, 0, 0, 0, 0, 0, 0); 	
}
function mudaestadocampos(indice,numerocampos){
	if (document.getElementById('atividade' + (indice + 1))){
		if (document.getElementById('atividade' + indice).selectedIndex == 0){
			for (i=(indice + 1);i<(numerocampos + 1);i++){
				document.getElementById('atividade' + i).disabled = true;
				document.getElementById('atividade' + i).selectedIndex = 0;
			}
		}else{
			document.getElementById('atividade' + (indice+1)).disabled = false
			document.getElementById('atividade' + (indice+1)).focus();
		}
	}
}
function validaatividades(totalindice,tipousuario){
	var envia = false;
	var envia2 = false;
	var idsatividades = '';
	var tipopessoa = '';
	if (tipousuario == ''){
		envia2 = checaconcordatermos();
	}else{
		envia2 = true;
	}
	if (envia2){
		if (!document.all.tipopessoa[0].checked && !document.all.tipopessoa[1].checked){
			alert("Favor selecionar um tipo de pessoa.")
		}else if (campovazio(document.getElementById('categoria').value)){
			alertafocacampo("categoria","");
		}else{
			if (document.all.tipopessoa[0].checked){
				tipopessoa = document.all.tipopessoa[0].value;
			}else{
				tipopessoa = document.all.tipopessoa[1].value;
			}
			for (i=1;i<(totalindice + 1);i++){
				campoatual = document.getElementById('atividade' + i).value;
				if (campoatual != '0'){
					envia = true;
					idsatividades = idsatividades + campoatual + ',';
				}
			}
			if (!envia){
				alertafocacampo('atividade1',"Favor selecionar no mínimo uma atividade.");
			}else{
				idsatividades = idsatividades.substr(0,idsatividades.length-1);
				xajax_alteraatividade(idsatividades,tipopessoa);
			}
		}
	}
}
function editorhtmlvazio(nomecampo){
	valorcampotexto = removeHTMLTags(getEditorValue('valortexto'));
	if (campovazio(valorcampotexto)){
		var oEditor = FCKeditorAPI.GetInstance('valortexto');
		oEditor.Focus();
		alert("Campo Obrigatório: " + nomecampo + ".");
		return false;
	}else{
		return true;
	}
}
function removeHTMLTags(texto){
	var strInputCode = texto;
 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 	return (p1 == "lt")? "<" : ">";
	});
	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
	return strTagStrippedText;
}
function getEditorValue(instanceName){
	var oEditor = FCKeditorAPI.GetInstance(instanceName);
	return oEditor.GetXHTML(false);
}
function deletaclassificado(id,idusuario){
	xajax_deletaclassificado(id,idusuario);
}
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
function checaconcordatermos(){
	if (!document.all.termosuso[0].checked){
		alert("Para cadastrar-se, é preciso ler os termos de uso acima.")
		return false;
	}else{
		document.getElementById('termosusotexto').disabled = true;
		document.getElementById('lbconcordo').disabled = true;
		document.getElementById('lbdiscordo').disabled = true;
		document.all.termosuso[0].disabled = true;
		document.all.termosuso[1].disabled = true;
		return true;
	}
}
function mostraadmin(tipousuario){
	top.location.href = tipousuario.toLowerCase() + '/index_' + tipousuario.toLowerCase() + '.php';
}
function ordemgrade(coluna){
	xajax_ordemgrade(coluna);
}
function remove_items_listbox(nome_campo){
	var x=document.getElementById(nome_campo);
	while (x.options.length > 0) {
		x.options[0] = null;
	}
}
function cria_option(nome_objeto,label,valor){
	var optionObject = new Option(label,valor);
	var optionRank = document.getElementById(nome_objeto).options.length;
	document.getElementById(nome_objeto).options[optionRank]=optionObject;
}
function trocadias(campo,categoria,dias){
	dias = dias.split(',');
	atualizadiasmeses(dias);
	diaatual = document.getElementById('dia_' + categoria).value;
	remove_items_listbox('dia_' + categoria);
	for (i=1;i<parseInt(diasmeses[campo.value  - 1]) + 1;i++){
		valordia = i;
		if (valordia < 10){
			valordia = '0' + i;
		}
	cria_option('dia_' + categoria,i,valordia);
	}
	if (parseInt(diaatual) < parseInt(diasmeses[campo.value  - 1])){
		document.getElementById('dia_' + categoria).value = diaatual;
	}
}
function atualizadiasmeses(dias){
	diasmeses = dias;
}
function desativateclaenter(evt){
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	tipobrowser = navigator.appName.toLowerCase();
	var codigochave = evt.keyCode;
	if ((tipobrowser != 'microsoft internet explorer') && (codigochave != 8)){
		codigochave = evt.charCode;
	}
	if (codigochave == 0){
		codigochave = evt.charCode;
	}
	if (codigochave == 13){
		return false;
	}
}
function FormataValor(campo,tammax,teclapres) 
 {
 	//uso:
	//<input type="Text" name="fat_vr_bruto" maxlength="17" onKeyDown="FormataValor(this,17,event)">

	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}			
}
function imprimiriframe(ptarget) 
{ 
ptarget.focus();
ptarget.print(); 
} 
document.onkeydown = checkCR2
document.onkeypress = checkCR;
