
//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_", "DESC. DE ");
	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_", "NOME DE ");
	nm_novo = nm_novo.replace("TMP", "");
	nm_novo = nm_novo.replace("_1_", "");
	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 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>'); }
// -->


