
//Highlight campos

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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 tratar_campo(nm) {

	var nm, nm_novo;
	
	nm_novo = nm.toUpperCase();
	
	nm_novo = nm_novo.replace("DES_EMAIL", "E-MAIL");
	nm_novo = nm_novo.replace("DES_MSN", "MSN");
	nm_novo = nm_novo.replace("DES_CIDADE", "CIDADE");
	nm_novo = nm_novo.replace("DES_", "");
	nm_novo = nm_novo.replace("CLIFOR", "NOME");
	nm_novo = nm_novo.replace("NUM_", "");
	nm_novo = nm_novo.replace("DAT_", "DATA DE ");
	nm_novo = nm_novo.replace("COD_", "CÓDIGO ");
	nm_novo = nm_novo.replace("VLR_", "VALOR DE ");
	nm_novo = nm_novo.replace("HOR_", "HORAS ");
	nm_novo = nm_novo.replace("NOM_", "");
	nm_novo = nm_novo.replace("PESS", "PESSOA DE");
	nm_novo = nm_novo.replace("TMP", "");
	nm_novo = nm_novo.replace("CONT", "");
	nm_novo = nm_novo.replace("ATO", "CONTATO");
	nm_novo = nm_novo.replace("TIT", "");
	nm_novo = nm_novo.replace("TXT", "");
	nm_novo = nm_novo.replace("MSG", "MENSAGEM");
	nm_novo = nm_novo.replace("_", " ");
	
	return nm_novo ;
	
}


function tratar_cpf(nm) {

	var nm, nm_novo;
	
	nm_novo = nm.toUpperCase();
	nm_novo = nm_novo.replace(".", "");
	nm_novo = nm_novo.replace(".", "");
	nm_novo = nm_novo.replace(".", "");
	nm_novo = nm_novo.replace(",", "");
	nm_novo = nm_novo.replace(" ", "");
	nm_novo = nm_novo.replace(" ", "");
	nm_novo = nm_novo.replace(" ", "");
	nm_novo = nm_novo.replace("-", "");
	nm_novo = nm_novo.replace("-", "");
	nm_novo = nm_novo.replace("-", "");
	nm_novo = nm_novo.replace("-", "");
	
	return nm_novo ;
	
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+tratar_campo(nm)+' deve ser um endereço de e-mail válido.\n';
        } else if (test!='R') { num = parseFloat(val);
		  
		  if (nm=='num_cpf')  { 
		  	val = tratar_cpf(val);
		  } 
		  
          if (isNaN(val)) errors+='- '+tratar_campo(nm)+' deve ser numérico.\n';
          
		  if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+tratar_campo(nm)+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+tratar_campo(nm)+' deve ser preenchido.\n'; }




	  if (nm == 'num_cpf_tmp') {
	  	var CPF;
		CPF = tratar_cpf(val);
		var mensagem = "erro"
		var msg = "";
		if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		  CPF == "88888888888" || CPF == "99999999999")
		msg = mensagem;
		soma = 0;
		for (y=0; y < 9; y ++)
		soma += parseInt(CPF.charAt(y)) * (10 - y);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)resto = 0;
		if (resto != parseInt(CPF.charAt(9)))
		  msg = mensagem; soma = 0;
		for (y = 0; y < 10; y ++)
		  soma += parseInt(CPF.charAt(y)) * (11 - y);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11) resto = 0;
		if (resto != parseInt(CPF.charAt(10)))
		msg = mensagem;
		if (msg!='') {
		errors += '- CPF deve ser preenchido corretamente.\n';
		}

	  }

		if (nm == 'num_cnpj_tmp') {
			
			var CNPJ;
			CNPJ = val;
			var mensagem = "informe corretamente o número do CNPJ"
			var msg = "";
			var y;
			var c = CNPJ.substr(0,12);
			var dv = CNPJ.substr(12,2);
			var d1 = 0;
			for (y = 0; y < 12; y++)
			{
			d1 += c.charAt(11-y)*(2+(y % 8));
			}
			if (d1 == 0) msg = mensagem;
			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;
			if (dv.charAt(0) != d1)msg = mensagem;
			d1 *= 2;
			for (y = 0; y < 12; y++)
			{
			d1 += c.charAt(11-y)*(2+((y+1) % 8));
			}
			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;
			if (dv.charAt(1) != d1) msg = mensagem;
			
			if (msg!='') {
			errors += '- CNPJ deve ser preenchido corretamente.\n';
			}
		
	  }

	  
	  
	  
	  
	  
    } 
	
	if (errors) alert('Atenção:\n'+errors);
    document.MM_returnValue = (errors == '');
} }




function abre_janela(width, height, nome) {
	var top; var left;
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	window.open('',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function recebe_imagem(campo, imagem){
	var foto = 'img_' + campo
	document.form_incluir[campo].value = imagem;
	document.form_incluir[foto].src = imagem;
}


function desabilita_cor(campo) {
	campo.className='campos_formulario'
}

function mascara_numero(numero){ 
var mynumero = ''; 
mynumero = mynumero + numero; 
mynumero = mynumero.replace(",","");
mynumero = mynumero.replace(".","");
lenTotal = mynumero.length;
casaCentavos = lenTotal-2;
centavos = (mynumero.substring(lenTotal,casaCentavos));
resto = (mynumero.substring(0,casaCentavos));

	if (mynumero.length > 2){ 
		mynumero =  resto + ","+ centavos; 
	} 

return mynumero; 
} 


function checa_cnpj(s) {
	var mensagem = "informe corretamente o número do CNPJ"
	var msg = "";
	var y;
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (y = 0; y < 12; y++)
	{
	d1 += c.charAt(11-y)*(2+(y % 8));
	}
	if (d1 == 0) msg = mensagem;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)msg = mensagem;
	d1 *= 2;
	for (y = 0; y < 12; y++)
	{
	d1 += c.charAt(11-y)*(2+((y+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) msg = mensagem;
	return msg;
}




function mascara_data(data){ 
	var mydata = ''; 
	mydata = mydata + data; 
	if (mydata.length == 2){ 
	mydata = mydata + '/'; 
	} 
	if (mydata.length == 5){ 
	mydata = mydata + '/'; 
	} 
	return mydata; 
	} 
	function verifica_data(data) { 
	if (data.value != "") {
	dia = (data.value.substring(0,2));
	mes = (data.value.substring(3,5)); 
	ano = (data.value.substring(6,10)); 
	situacao = ""; 
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
	situacao = "falsa"; 
	} 
	if (mes < 01 || mes > 12 ) { 
	situacao = "falsa"; 
	}
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
	situacao = "falsa"; 
	} 
	if (situacao == "falsa") { 
	data.focus();
	data.select();
	alert("Data inválida!"); 
	}
	} 
}


<!-- // load htmlarea
_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }

if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="../inc/editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// -->

function limitar_caracteres(nome_obj, limite_caracteres, campo_aviso) {
 
	num_caracteres = nome_obj.value.length+1;
	campo_aviso.value = num_caracteres + " de " + limite_caracteres + " caracteres permitidos";
	
	if (num_caracteres >= limite_caracteres) {
	//	window.alert("Limite de caracteres excedido!");
		nome_obj.value = nome_obj.value.substring(0, limite_caracteres-1);
		campo_aviso.style.color = '#FF0000';
		return false;
	}
 
}

function atualiza_data(obj_dia, obj_mes, obj_ano, obj_final) {
	dia = obj_dia.value;
	mes = obj_mes.value;
	ano = obj_ano.value;
	obj_final.value = dia+"/"+mes+"/"+ano;

}

function exibir_painel(item){

	if (item.style.display=='none'){
		item.style.display='';
	}
	else{
		item.style.display='none'
	}
}


function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function limitar_caracteres(nome_obj, limite_caracteres, campo_aviso) {

	num_caracteres = nome_obj.value.length+1;
	if (nome_obj.value=="") { 
		num_caracteres =0;
	}
	
	campo_aviso.value = "("+ num_caracteres + " de " + limite_caracteres + " caracteres permitidos)";
	
	if (num_caracteres >= limite_caracteres) {
		window.alert("Limite de caracteres excedido!");
		nome_obj.value = nome_obj.value.substring(0, limite_caracteres-1);
		campo_aviso.style.color = '#FF0000';
		return false;
	} else {
		campo_aviso.style.color = '#000000';
	}
	

}


function informar_url_simples($url_imagem_func, $des_campo_func){
	var campo = eval('window.opener.'+$des_campo_func);
	campo.value = $url_imagem_func;
	
	var imagem = eval('window.opener.IMG_'+$des_campo_func);
	imagem.innerHTML = "<img src='../img/arquivo_ok.jpg' alt='' width='111' name='img_img01' border='1'>";
	//window.opener.img_artista_01.value = $url_imagem_func;
}

/* Vários tipos de máscaras 
chamadas:

Somente numeros:
onkeydown="Mascara(this,Integer);" onkeypress="Mascara(this,Integer);"

Telefone:
onkeydown="Mascara(this,Telefone);" onkeypress="Mascara(this,Telefone);" onkeyup="Mascara(this,Telefone);"

CPF:
onkeydown="Mascara(this,Cpf);" onkeypress="Mascara(this,Cpf);" onkeyup="Mascara(this,Cpf)

CEP:
onkeydown="Mascara(this,Cep);" onkeypress="Mascara(this,Cep);" onkeyup="Mascara(this,Cep);

CNPJ:
onkeydown="Mascara(this,Cnpj);" onkeypress="Mascara(this,Cnpj);" onkeyup="Mascara(this,Cnpj);

Romanos:
onkeydown="Mascara(this,Romanos);" onkeypress="Mascara(this,Romanos);" onkeyup="Mascara(this,Romanos)

Site:
onkeydown="Mascara(this,Site);" onkeypress="Mascara(this,Site);" onkeyup="Mascara(this,Site)

Data:
onkeydown="Mascara(this,Data);" onkeypress="Mascara(this,Data);" onkeyup="Mascara(this,Data)

Area:
onkeydown="Mascara(this,Area);" onkeypress="Mascara(this,Area);" onkeyup="Mascara(this,Area)


 */
 /*Função Pai de Mascaras*/
        function Mascara(o,f){
                v_obj=o
                v_fun=f
                setTimeout("execmascara()",1)
        }
        
        /*Função que Executa os objetos*/
        function execmascara(){
                v_obj.value=v_fun(v_obj.value)
        }
        
        /*Função que Determina as expressões regulares dos objetos*/
        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
        }
        
        /*Função que permite apenas numeros*/
        function Integer(v){
                return v.replace(/\D/g,"")
        }
        
        /*Função que padroniza telefone (11) 4184-1241*/
        function Telefone(v){
                v=v.replace(/\D/g,"")                            
                v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
                v=v.replace(/(\d{4})(\d)/,"$1-$2")      
                return v
        }
		
		/*Função que padroniza telefone (11) 41841241*/
        function TelefoneCall(v){
                v=v.replace(/\D/g,"")                            
                v=v.replace(/^(\d\d)(\d)/g,"($1) $2")   
                return v
        }
		
		/*Função que padroniza CPF*/
        function Cpf(v){
                v=v.replace(/\D/g,"")                                   
                v=v.replace(/(\d{3})(\d)/,"$1.$2")         
                v=v.replace(/(\d{3})(\d)/,"$1.$2")         
                                                                                                 
                v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2")
 
                return v
        }
		
		/*Função que padroniza CEP*/
        function Cep(v){
                v=v.replace(/D/g,"")                            
                v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
                return v
        }
		
		/*Função que padroniza CNPJ*/
        function Cnpj(v){
                v=v.replace(/\D/g,"")                              
                v=v.replace(/^(\d{2})(\d)/,"$1.$2")      
                v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
                v=v.replace(/\.(\d{3})(\d)/,".$1/$2")              
                v=v.replace(/(\d{4})(\d)/,"$1-$2")                        
                return v
        }
		
		/*Função que permite apenas numeros Romanos*/
        function Romanos(v){
                v=v.toUpperCase()                        
                v=v.replace(/[^IVXLCDM]/g,"") 
                
                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
        }
		
		/*Função que padroniza o Site*/
        function Site(v){
                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
        }
		
		 /*Função que padroniza DATA*/
        function Data(v){
                v=v.replace(/\D/g,"") 
                v=v.replace(/(\d{2})(\d)/,"$1/$2") 
                v=v.replace(/(\d{2})(\d)/,"$1/$2") 
                return v
        }
		
		 /*Função que padroniza valor monétario*/
        function Valor(v){
                v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
                v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
                //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
                v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
                return v
        }
		
		 /*Função que padroniza Area*/
        function Area(v){
                v=v.replace(/\D/g,"") 
                v=v.replace(/(\d)(\d{2})$/,"$1.$2") 
                return v
                
        }

