
//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("DEP", "");
	nm_novo = nm_novo.replace(/_/g, " ");
	
	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, imagem_ok){
	var foto = 'img_' + campo
	document.form_incluir[campo].value = imagem;
	document.form_incluir[foto].src = imagem_ok;
}


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 atualiza_data_completa(obj_dia, obj_mes, obj_ano, obj_hora, obj_minuto, obj_final) {
	dia = obj_dia.value;
	mes = obj_mes.value;
	ano = obj_ano.value;
	hora = obj_hora.value;
	minuto = obj_minuto.value;
	obj_final.value = dia+"/"+mes+"/"+ano+ " "+hora+":"+minuto;

}

function exibir_painel(item){

	if (item.style.display=='none'){
		item.style.display='';
	}
	else{
		item.style.display='none'
	}
}



function recebe_valor(campo_func,valor_func){
	document.form_incluir[campo_func].value = valor_func;
}


function horario_maximo(hora_func, minuto_func) {

	if (hora_func.value==24) { 
		minuto_func.value="00";
		minuto_func.disabled=1;
	}else{
		minuto_func.disabled=0;
	}	

}

var Aberto = ""
var Fechado = ""

function preload(){
	if(document.images){
		Aberto = new Image(16,13) 
		Fechado = new Image(16,13)
		Aberto.src = "../img_sistema/pasta_menos.jpg"
		Fechado.src = "../img_sistema/pasta_mais.jpg"
	}
}

function mostra(item,item2){

	if (item.style.display=='none'){
		item.style.display='';
		item2.src=Aberto.src
	}
	else{
		item.style.display='none'
		item2.src=Fechado.src
	}
}
preload();

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_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function selecionar_tudo(){ 
   for (i=0;i<document.f1.elements.length;i++) 
      if(document.f1.elements[i].type == "checkbox") 
         document.f1.elements[i].checked=1 
} 
function deselecionar_tudo(){ 
   for (i=0;i<document.f1.elements.length;i++) 
      if(document.f1.elements[i].type == "checkbox") 
         document.f1.elements[i].checked=0 
} 

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 selecionar_tudo(secao_escolhida){
		
	for (i=0;i<document.form_incluir.elements.length;i++){
		
		var tamanho_secao = secao_escolhida.length;
		var secao_final = secao_escolhida.substring(10, tamanho_secao)
		var secao_final = secao_final + "_";
		
		
		var tamanho_secao_final = secao_final.length;
		
		
		var nom_item_tmp = document.form_incluir.elements[i].name;
		var nom_item = nom_item_tmp.substring(0, tamanho_secao_final)
		
		
		
		if(document.form_incluir.elements[i].type == "checkbox"){
		
			
			if(document.form_incluir.elements[i].checked == 0){
				if(nom_item_tmp == secao_escolhida){
					var selecionado = false;
				}
			}
			if(document.form_incluir.elements[i].checked == 1){
				if(nom_item_tmp == secao_escolhida){
					var selecionado = true;
				}
			}
			
			
			if (selecionado == false){
				if(nom_item == secao_final){
					document.form_incluir.elements[i].checked=0;
					document.form_incluir.elements[i].disabled=true;
				}
			}
			if (selecionado == true){
				if(nom_item == secao_final){
					document.form_incluir.elements[i].checked=1;
					document.form_incluir.elements[i].disabled=false;
				}
			}
		}
	}
}


