//// Projeto : RANULFO ALVES PEREIRA - Active Company 
//// Email   : webmaster@activecompany.com.br                    

window.defaultStatus = "Active Company - Soluções Tecnologicas";

// bloqueia visualizacao do fonte
function verfonte() {
  if(event.button==2){
    window.alert('O código fonte deste site não pode ser exibido.\n\  Mas solicite você infrmação para o endereço:\n\         webmaster@activecompany.com.br\n\n\     Clique em Ok, para continuar navegando.');
  }
}

// abre janela poup-up de ajuda do sistema
function OpenUpAjuda(pagina,janela) {
   window.open(pagina,janela,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,width=520,height=400')
}

// funcao para impressao
function imprimir(){
   window.print();
}

//funcao voltar campos
function voltar(todoscampos,getoupost,tab){
  enviagenerico(todoscampos,document.getElementById("ultima").value,getoupost,tab)
}

function enviacomfoco(campo,todoscampos,idcampo,getoupost,tab){
  enviagenerico(todoscampos,idcampo,getoupost,tab);
}

// mover relogio
function moveRelogio(){
  momentoAtual = new Date()
  hora = momentoAtual.getHours()
  minuto = momentoAtual.getMinutes()
  segundo = momentoAtual.getSeconds()
  str_segundo = new String (segundo)
  if(str_segundo.length == 1)
    segundo = "0" + segundo
    str_minuto = new String (minuto)
    if(str_minuto.length == 1)
      minuto = "0" + minuto
    str_hora = new String (hora)
    if(str_hora.length == 1)
       hora = "0" + hora
	if(document.getElementById('campoteste2').value==""){
 	  document.getElementById('campoteste2').value=segundo;
	  var tempofinal=document.getElementById('campoteste2').value+3;
	}		
	document.getElementById('campoteste').value=tempofinal;
	if(document.getElementById('campoteste2').value==tempofinal){
	  document.getElementById('palav').value='00000';
	}
    setTimeout("moveRelogio()",1000)
}

// estracao de scrit de texo
function extraiScript(texto){
  //Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
  // inicializa o inicio ><
  var ini = 0;
  // loop enquanto achar um script
  while (ini!=-1){
    // procura uma tag de script
    ini = texto.indexOf('<script', ini);
    // se encontrar
    if(ini >=0){
      // define o inicio para depois do fechamento dessa tag
      ini = texto.indexOf('>', ini) + 1;
      // procura o final do script
      var fim = texto.indexOf('</script>', ini);
      // extrai apenas o script
      codigo = texto.substring(ini,fim);
      //  alert(codigo);
	  // executa o script
      // eval(codigo);	 
      novo = document.createElement("script")
	  // Define parâmetro language=javascript para o objeto de script
  	  novo.setAttribute('language', 'javascript');
      novo.text = codigo;
	  document.body.appendChild(novo);	 
    }
  }
}

// funcao envia formulario com id para validar/gravar/alterar (AJAX)
function enviaForm(frmNome, url, destino){
  var query='';
  // Captura o form
  f = document.getElementById(frmNome);
  for (i=0;i<f.elements.length;i++){
    // concatena a variavel na query
    if(f.elements[i].type=='radio'||f.elements[i].type=='checkbox'){
      if(f.elements[i].checked){
        query +=  '&'+f.elements[i].name + '=' + f.elements[i].value;
      }
    } else {
      query +=  '&'+f.elements[i].name + '=' + f.elements[i].value.replace("&","@@@@@@");
    }
  }
  // envia o formulario
  //alert(query);
  enviagenerico(query,url,'POST',destino);	
}

// funcao loading (aguarde)
function Loading(a,tab){
  if(a=='on'){
	document.getElementById(tab).innerHTML = "<img src='../images/aguarde.gif'><br>aguarde...";
  } else {
	document.getElementById(tab).innerHTML = "";
  }
}		

// funcao start do AJAX
function startAjax(){
  try { xmlhttp = new XMLHttpRequest(); } 
    catch(e) {
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
      catch(ee) {	
      try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} 
        catch(E){
        xmlhttp = false;
	  }
    }
  } 
  return xmlhttp;
}	
		
// funcao enviar link  (AJAX)
function enviagenerico(todoscampos,enderecourl,getoupost,tab){
  var maiscampos=todoscampos;
  var ajax = startAjax();			
  if(ajax){
	Loading('on', tab);
	ajax.open(getoupost,enderecourl,true)
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function()
    {		
      if(ajax.readyState==4){
	    Loading('off', tab);
	    //var get = ajax.responseText.replace(/\+/g," ");
	    extraiScript(ajax.responseText);
	    //alert (ajax.responseText);
	    document.getElementById(tab).innerHTML = ajax.responseText;						
	  }
    }
    maiscampos=maiscampos+"&navegador="+document.getElementById('navegador').value;		
    ajax.send(maiscampos);
    /*
    if(document.getElementById("atual").value!=enderecourl){
	  document.getElementById("ultima").value=document.getElementById("atual").value;
	  document.getElementById("atual").value=enderecourl;
    }*/
  } 
}
		
// envia texto com fckeditor para um campo de edicao unico
function enviatexto(frmNome, url, destino){
  var query='';
  var not_conteudo = FCKeditorAPI.GetInstance('not_conteudo').GetXHTML(); 
  //aqui eu troco o & por @@@@@@
  not_conteudo=not_conteudo.replace(/&/g,"@@@@@@");
		
  FCKeditorAPI = null;
  __FCKeditorNS = null;

  // Captura o form
  f = document.getElementById(frmNome);

  for (i=0;i<f.elements.length;i++){
    // concatena a variavel na query
    if(f.elements[i].type=='radio'||f.elements[i].type=='checkbox'){
      if(f.elements[i].checked){
        query +=  '&'+f.elements[i].name + '=' + f.elements[i].value;
	  }
    } else {
      query +=  '&'+f.elements[i].name + '=' + f.elements[i].value.replace("&","@@@@@@");
    }
  }
  // envia o formulario
  //alert(query);

  query+="&not_conteudo="+not_conteudo;
  enviagenerico(query,url,'POST',destino);	
}

function enviatexto2cpo(frmNome, url, destino){
  var query='';
  var not_conteudo1 = FCKeditorAPI.GetInstance('not_conteudo1').GetXHTML();
  //aqui eu troco o & por @@@@@@
  not_conteudo1=not_conteudo1.replace(/&/g,"@@@@@@");
	
  var not_conteudo2 = FCKeditorAPI.GetInstance('not_conteudo2').GetXHTML();
  //aqui eu troco o & por @@@@@@
  not_conteudo2=not_conteudo2.replace(/&/g,"@@@@@@");

  FCKeditorAPI = null;
  __FCKeditorNS = null;

  // Captura o form
  f = document.getElementById(frmNome);

  for (i=0;i<f.elements.length;i++){
    // concatena a variavel na query
    if(f.elements[i].type=='radio'||f.elements[i].type=='checkbox'){
      if(f.elements[i].checked){
        query +=  '&'+f.elements[i].name + '=' + f.elements[i].value;
	  }
    } else {
      query +=  '&'+f.elements[i].name + '=' + f.elements[i].value.replace("&","@@@@@@");
    }
  }
  // envia o formulario
  //alert(query);

  query+="&not_conteudo1="+not_conteudo1+"&not_conteudo2="+not_conteudo2;
  enviagenerico(query,url,'POST',destino);	
}

function enviatexto3cpo(frmNome, url, destino){
  var query='';
  var not_conteudo1 = FCKeditorAPI.GetInstance('not_conteudo1').GetXHTML();
  //aqui eu troco o & por @@@@@@
  not_conteudo1=not_conteudo1.replace(/&/g,"@@@@@@");
	
  var not_conteudo2 = FCKeditorAPI.GetInstance('not_conteudo2').GetXHTML();
  //aqui eu troco o & por @@@@@@
  not_conteudo2=not_conteudo2.replace(/&/g,"@@@@@@");

  var not_conteudo3 = FCKeditorAPI.GetInstance('not_conteudo3').GetXHTML();
  //aqui eu troco o & por @@@@@@
  not_conteudo3=not_conteudo3.replace(/&/g,"@@@@@@");	

  FCKeditorAPI = null;
  __FCKeditorNS = null;

  // Captura o form
  f = document.getElementById(frmNome);

  for (i=0;i<f.elements.length;i++){
    // concatena a variavel na query
    if(f.elements[i].type=='radio'||f.elements[i].type=='checkbox'){
      if(f.elements[i].checked){
        query +=  '&'+f.elements[i].name + '=' + f.elements[i].value;
	  }
    } else {
      query +=  '&'+f.elements[i].name + '=' + f.elements[i].value.replace("&","@@@@@@");
    }
  }
  // envia o formulario
  //alert(query);

  query+="&not_conteudo1="+not_conteudo1+"&not_conteudo2="+not_conteudo2+"&not_conteudo3="+not_conteudo3;
  enviagenerico(query,url,'POST',destino);	
}

// formata campos diversos
function formatar(mascara, documento){
  var i = documento.value.length;
  var saida = mascara.substring(0,1);
  var texto = mascara.substring(i)  
  if (texto.substring(0,1) != saida){
	documento.value += texto.substring(0,1);
  }
}

// formata campo de mes referencia
function mascara_referencia(nascimento,campoesp){ 
  var mynascimento = ''; 
  mynascimento = mynascimento + nascimento; 
  if(mynascimento.length == 2){ 
    mynascimento = mynascimento + '-'; 
    campoesp.value = mynascimento; 
  } 
  if(mynascimento.length == 7){ 
    verifica_referencia(campoesp); 
  } 
} 

// verifica mes referencia
function verifica_referencia (campoesp) { 
  mes = (campoesp.value.substring(0,2)); 
  ano = (campoesp.value.substring(3,7)); 
  situacao = ""; 
  // verifica se o mes e valido 
  if(mes < "01" || mes > "12" ) { 
    situacao = "falsa"; 
  } 
  // verifica se e ano bissexto 
  if(mes == "2" && ( dia < "01" || dia > "29" || ( dia > "28" && (parseInt(ano / 4) != ano / 4)))) { 
    situacao = "falsa"; 
  }     
  if(campoesp.value == "") { 
    situacao = "falsa"; 
  }     
  if(situacao == "falsa") { 
    alert("A Referencia "+campoesp.value+" é inválida!\nInsira uma referência correta!"); 
	campoesp.value=""; 
    campoesp.focus(); 
  } 
}		  

// formata campo data
function mascara_nascimento(nascimento,campoesp){ 
  var mynascimento = ''; 
  mynascimento = mynascimento + nascimento; 
  if(mynascimento.length == 2){ 
    mynascimento = mynascimento + '-'; 
    campoesp.value = mynascimento; 
  } 
  if(mynascimento.length == 5){ 
    mynascimento = mynascimento + '-'; 
    campoesp.value = mynascimento; 
  } 
  if(mynascimento.length == 10){ 
    verifica_nascimento(campoesp); 
  } 
} 

// verifica campo data
function verifica_nascimento (campoesp) { 
  dia = (campoesp.value.substring(0,2)); 
  mes = (campoesp.value.substring(3,5)); 
  ano = (campoesp.value.substring(6,10)); 
  situacao = ""; 
  // verifica o dia valido para cada mes 
  if((dia < "01")||(dia < "01" || dia > "30") && (  mes == "04" || mes == "06" || mes == "09" || mes == "11" ) || dia > "31") { 
    situacao = "falsa"; 
  } 
  // verifica se o mes e valido 
  if(mes < "01" || mes > "12" ) { 
    situacao = "falsa"; 
  } 
  // verifica se e ano bissexto 
  if(mes == "2" && ( dia < "01" || dia > "29" || ( dia > "28" && (parseInt(ano / 4) != ano / 4)))) { 
    situacao = "falsa"; 
  }     
  if(campoesp.value == "") { 
    situacao = "falsa"; 
  }     
  if(situacao == "falsa") { 
    alert("A Data "+campoesp.value+" é inválida!\nInsira uma data correta!"); 
	campoesp.value=""; 
    campoesp.focus(); 
  } 
} 

// mascara para campo telefone
function mascara_telefone(fone,campo){ 
  var mytelefone = ''; 
  mytelefone = mytelefone + fone; 
  if(mytelefone.length == 2){ 
	 mytelefone = '('+mytelefone + ')'; 
	 campo.value = mytelefone; 
  } 
  if(mytelefone.length == 8){ 
	 mytelefone = mytelefone + '-'; 
	 campo.value = mytelefone; 
  } 
} 

// mascara para cep
function mascara_cep(cep,campo){ 
  var mycep = ''; 
  mycep = mycep + cep; 
  if(mycep.length == 5){ 
	 mycep = mycep + '-'; 
	 campo.value = mycep; 
  } 
}

// verifica CPF/CNPJ
function ver_cpf_cnpj(numcpf,campo){
  //Filtragem da entrada do CPF - Filtra caracteres ""-"" ou ""/"" ou "".""\
  var wcgccalc; var wsoma;
  cleancpf = "";
  tamcpf = numcpf.length;
  for(i = 0; i < tamcpf;i++){
    carac = numcpf.substring(i,i+1);
	if(carac != "1" && carac != "2" && carac != "3" && carac !="4" && carac != "5" && carac != "6" && carac != "7" && carac != "8" && carac!= "9" && carac != "0"){
	  carac = "";
	}
	cleancpf = cleancpf + carac;
  }
  numcpf = cleancpf;
  if(numcpf.length == 11){
	x=0; soma=0; dig1=0; dig2=0; texto=""; numcpf1="";
	len = numcpf.length; x = len -1;
	for(var i=0; i <= len - 3; i++){
	  y = numcpf.substring(i,i+1); soma = soma + ( y * x);
	  x = x - 1; texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if(dig1 == 10) dig1=0 ; 
	  if(dig1 == 11) dig1=0 ;
	    numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	    x = 11; soma=0;
		for(var i=0; i <= len - 2; i++){
		  soma = soma + (numcpf1.substring(i,i+1) * x); 
		  x = x - 1;
		}
		dig2= 11 - (soma % 11);
		if(dig2 == 10) dig2=0;
		if(dig2 == 11) dig2=0;
	    if((dig1 + "" + dig2) == numcpf.substring(len,len-2)){
		return true;
	  } else {
		alert("O cpf que digitou está incorreto");
		campo.focus();
		campo.value="";
		return false;
	  }
	} else {
	  if(numcpf.length == 14){  
		wcgccalc= (numcpf.substring(0,12));
		wsoma=0;
		for(var i=0; i<=3; i++){
		  wnum=parseInt(wcgccalc.substring(i,i+1));
		  wsoma= wsoma + wnum * (5-i);
		}
		for(var x=0; x<=7; x++){
		  wnum=parseInt(wcgccalc.substring(x+4,x+5));
		  wsoma=wsoma + wnum * (9-x);
		}
	    wcgcdigit= 11-(wsoma%11);
		if((wcgcdigit == 10) || (wcgcdigit == 11)){
		  wcgccalc= wcgccalc + '0';
		} else {
		  wcgccalc= wcgccalc + wcgcdigit;
		}	
		wsoma=0;
		for(var y=0; y<=4; y++){
		  wnum=parseInt(wcgccalc.substring(y,y+1));
		  wsoma= wsoma + wnum * (6-y);
		}
		for(var z=0; z<=7; z++){
		  wnum=parseInt(wcgccalc.substring(z+5,z+6));
		  wsoma=wsoma + wnum *(9-z);
		}
		wcgcdigit= 11 - (wsoma%11);
		if((wcgcdigit == 10)||(wcgcdigit == 11)){
	      wcgccalc= wcgccalc + '0';
		} else {
		  wcgccalc= wcgccalc + wcgcdigit;
		}
		if(numcpf==wcgccalc){
		  return true;
		} else {
		  alert("O Cnpj que digitou está incorreto");
		  campo.value="";
		  campo.focus();	
	      return false;
		}
      } else {
		alert("O Cnpj/Cnpj que digitou está incorreto");
		campo.value="";
		campo.focus();
		return false;
	  }
	}
}

// formata valores de moedas, percentuais
function FormataValor2(campo,tammax,casas){
  var vr=document.getElementById(campo).value
  // var vrss=document.getElementById(campo).value	
  while (vr.indexOf(".")>=0) {
	vr=vr.replace(".","");
  }
  while (vr.indexOf(",")>=0) {
	vr=vr.replace(",","");
  }	
  if(isNaN(vr)){
	alert ("Foi Digitado uma Letra. Este campo aceita só numeros com virgula ou ponto");
	document.getElementById(campo).value=vr.substring(0,vr.length-1); 
  } else {
    if(vr.length<tammax){	 	
	  if(vr.length>casas){
		vr=vr.substr(0,vr.length-casas)+","+vr.substr(vr.length-casas,vr.length);
		document.getElementById(campo).value=vr;
	  }
	  vrteste=vr.substr(0,vr.length-casas);
	  numero=vrteste.length;
	  if(numero>0){
		comparador=5;
		var numero=0;
		while (numero<=vrteste.length){
		  if(numero==comparador){
			var anterior=numero-1;
			vrteste=vrteste.substr(0,vrteste.length-anterior)+"."+vrteste.substr(vrteste.length-anterior,vr.length);
			comparador=comparador+4;
		  }
		  numero++;
		}
		vr=vrteste+vr.substr(vr.length-casas,vr.length);
	  }
	  document.getElementById(campo).value=vr.substr(0,tammax);
	}
  }
}

// abre janelas poup-u
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//saber qual browser é 
String.prototype.contains = function(){
 var resu = false;
 for(var i=0; i < arguments.length; i++){
  if(this.toLowerCase().indexOf(arguments[i].toLowerCase()) > -1){
   resu = i + 1;
   break;
  }
 }
 return resu;
}

var _ua = navigator.userAgent;
var _vd = navigator.vendor;
var _pd = navigator.product;
var _browser_rv = ( _ua.indexOf('rv:') > -1 );
var _browser_op = ( _ua.indexOf('Opera') > -1 );
var _browser_ie = ( _ua.indexOf('MSIE') > -1 );
var _browser_pd = ( _pd == 'Gecko' );
var _browser_ff = ( _vd == 'Firefox' || ( _browser_pd && _ua.contains('Firefox','BonEcho','Paradiso') && ! _ua.contains('Flock')));
var _browser_fk = ( _browser_pd && _ua.contains('Flock') && ! _browser_ff );
var _browser_ns = ( _vd == 'Netscape' );
 
function isMozilla(){ // Mozilla Suite Browser
  return ( _browser_pd && _browser_rv && ! _browser_ff && ! _browser_ns && ! _browser_fk);
}

function isFirefox(){ // Mozilla Firefox
  return ( _browser_pd && ( _browser_ff || ! _browser_rv ) && ! _browser_fk);
}

function isFlock(){
  return ( _browser_pd && _browser_fk);
}

function isNetscape(){ // Netscape 6 or higher
  return( _browser_pd && _browser_ns ) ;
}

function isIE(){ // Internet Explorer
  return( _browser_ie && ! _browser_pd && ! _browser_op);
}

function isOpera(){ // Opera browser
  return( ! _browser_pd && _browser_op);
}

function otherBrowsers(){
  return( !isMozilla() && !isFirefox() && !isFlock() && !isNetscape() && !isIE() && !isOpera());
}

function verificanav(){
  if(isFirefox()){
    document.getElementById('navegador').value="firefox"
  } else {
	document.getElementById('navegador').value="ie"	
  }
}

// validacao do formulario de cadastro de usuario
function usu_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('usus_nome').value==""){
	alert("Informe o nome do usuário.\n       Campo obrigatório.");
	document.getElementById('usus_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('usus_email').value==""){
	alert("Informe o e-mail do usuário.\n       Campo obrigatório.");
	document.getElementById('usus_email').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('usus_login').value==""){
	alert("   Informe o login.\nCampo obrigatório.");
	document.getElementById('usus_login').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('usus_senha').value==""){
	alert(" Informe a senha.\nCampo obrigatório.");
	document.getElementById('usus_senha').focus();
	erro="S";
	return false;
  }										
  if(document.getElementById('usus_tipo').value==""){
	alert("Informe tipo de usuário.\n    Campo obrigatório.");
	document.getElementById('usus_tipo').focus();
	erro="S";
	return false;
  }																																			  
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}


// validacao do formulario de cadastro de Cliente
function cli_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('cli_nome').value==""){
	alert("Informe o nome do cliente.\n      Campo obrigatório.");
	document.getElementById('cli_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('cli_cpfcnpj').value==""){
	alert("Informe o CPF/CNPJ do cliente.\n          Campo obrigatório.");
	document.getElementById('cli_cpfcnpj').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('cli_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('cli_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade.\n      Campo obrigatório.");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('cli_tel').value==""){
	alert("Informe o número do telefone.\n          Campo obrigatório.");
	document.getElementById('cli_tel').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cli_email').value==""){
	alert("  Informe o e-mail.\nCampo obrigatório.");
	document.getElementById('cli_email').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cli_firma').value==""){
	alert("Informe o sistema.\n Campo obrigatório.");
	document.getElementById('cli_firma').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de cadastro de Fornecedores
function for_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('for_nome').value==""){
	alert("Informe o nome do fornecedor.\n      Campo obrigatório.");
	document.getElementById('for_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('for_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('for_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade.\n      Campo obrigatório.");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('for_tel').value==""){
	alert("Informe o número do telefone.\n          Campo obrigatório.");
	document.getElementById('for_tel').focus();
	erro="S";
	return false;
  }																																			
   if(document.getElementById('for_firma').value==""){
	alert("Informe a empresa do grupo.\n      Campo obrigatório.");
	document.getElementById('for_firma').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de cadastro de Funcionários
function fun_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('fun_nome').value==""){
	alert("Informe o nome do funcionário.\n         Campo obrigatório.");
	document.getElementById('fun_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fun_cpfcnpj').value==""){
	alert("Informe o CPF/CNPJ do funcionário.\n          Campo obrigatório.");
	document.getElementById('fun_cpfcnpj').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fun_endereco').value==""){
	alert("Informe o endereço do funcionário.\n          Campo obrigatório.");
	document.getElementById('fun_endereco').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fun_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('fun_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade.\n      Campo obrigatório.");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fun_tel').value==""){
	alert("Informe o número do telefone.\n          Campo obrigatório.");
	document.getElementById('fun_tel').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('fun_email').value==""){
	alert("  Informe o e-mail.\nCampo obrigatório.");
	document.getElementById('fun_email').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('fun_firma').value==""){
	alert("Informe a empresa do grupo.\n      Campo obrigatório.");
	document.getElementById('fun_firma').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de cadastro de empresa
function emp_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('emp_nome').value==""){
	alert("Informe o nome da Empresa.\n       Campo obrigatório");
	document.getElementById('emp_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('emp_cpfcnpj').value==""){
	alert("Informe o CNPJ da Empresa.\n       Campo obrigatório");
	document.getElementById('emp_cpfcnpj').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('emp_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('emp_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade da Empresa.\n          Campo obrigatório");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('emp_email').value==""){
	alert("  Informe o e-mail.\nCampo obrigatório.");
	document.getElementById('emp_email').focus();
	erro="S";
	return false;
  }																																			
  if (erro=="N"){enviaForm(frmNome, url, destino);}
}

// valida cadastro de contrato
function val_ctra(frmNome, url, destino ){
  var erro="N";
  if(document.getElementById('ctra_cliente').selectedIndex ==''){ 
	alert("Selecione um cliente");
	document.getElementById('ctra_cliente').focus(); 
	erro="S";	
	return false; 
  }  
  if(document.getElementById('ctra_situacao').selectedIndex ==''){ 
	alert("Selecione a situação"); 
	document.getElementById('ctra_situacao').focus(); 
	erro="S";
	return false; 
  }  
  if(document.getElementById('ctra_sistema').selectedIndex ==''){ 
	alert("Selecione o sistema"); 
	document.getElementById('ctra_sistema').focus(); 
	erro="S";	
	return false; 
  }  
  if(document.getElementById('ctra_numero').value==''){
    alert("Informe o número do contrato"); 
	document.getElementById('ctra_numero').focus(); 
	erro="S";
	return false; 
  }
  if(document.getElementById('ctra_dtcontrato').value==''){
    alert("Informe a data do contrato"); 
	document.getElementById('ctra_dtcontrato').focus(); 
	erro="S";	
	return false; 
  }
  if(document.getElementById('ctra_banco').selectedIndex ==''){ 
	alert("Selecione o banco de cobrança"); 
	document.getElementById('ctra_banco').focus(); 
	erro="S";	
	return false; 
  }  
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de cadastro de Fornecedores
function for_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('for_nome').value==""){
	alert("Informe o nome do fornecedor.\n      Campo obrigatório.");
	document.getElementById('for_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('for_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('for_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade.\n      Campo obrigatório.");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('for_tel').value==""){
	alert("Informe o número do telefone.\n          Campo obrigatório.");
	document.getElementById('for_tel').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// valida cadastro de contas
function validaconta(frmNome,url,destino ){
  var erro="N";
  if(document.getElementById('cta_conta').value==""){
    alert("Você precisa informar a conta"); 
	document.getElementById('cta_conta').focus(); 
	erro="S";
	return false;
  }
  if(document.getElementById('cta_descricao').value==""){
    alert("Você precisa informar o nome da conta"); 
	document.getElementById('cta_descricao').focus(); 
    erro="S";
	return false;
  }
  if(erro=="N"){enviaForm(frmNome,url,destino);}
}

// valida cadastro de banco
function validabancos(frmNome,url,destino){
  var pronto="S";
  if(document.getElementById('banc_favor').value.length < 3){
    alert("Você precisa informar o favorecido\n          Campo obrigatório"); 
	document.getElementById('banc_favor').focus(); 
	pronto="N"; return false; 
  }
  if(document.getElementById('banc_nome').value.length < 3){
    alert("Você precisa informar o nome do banco\n             Campo obrigatório"); 
	document.getElementById('banc_nome').focus(); 
	pronto="N"; return false; 
  }
  if(document.getElementById('banc_agen').value==''){
    alert("Você precisa informar a agência\n          Campo obrigatório"); 
	document.getElementById('banc_agen').focus(); 
	pronto="N"; return false;
  }
  if(document.getElementById('banc_conta').value==''){
    alert("Você precisa informar conta\n       Campo obrigatório"); 
	document.getElementById('banc_conta').focus(); 
	pronto="N"; return false;
  }
  if(document.getElementById('banc_dgct').value==''){
    alert("Você precisa informar o dígito da conta\n              Campo obrigatório"); 
	document.getElementById('banc_dgct').focus(); 
	pronto="N"; return false;
  }
  if(pronto=="S"){
    enviaForm(frmNome,url,destino);
  }
}

//valida indices
function valida_indice(frmNome,url,destino ){
  var erro="N";
  if(document.getElementById('indm_mesreferencia').value==""){
    alert("Você precisa informar o Mês de Referência"); 
	document.getElementById('indm_mesreferencia').focus(); 
	erro="S";
	return false;
  }
  if(erro=="N"){enviaForm(frmNome,url,destino);}
}

// validacao do movimentacao financeira
function fin_movimento(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('fin_data').value==""){
	alert("Informe uma data.\nCampo obrigatório");
	document.getElementById('fin_data').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fin_conta').value==""){
	alert("Selecione uma conta\n  Campo obrigatório");
	document.getElementById('fin_conta').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fin_historico').value==""){
	alert("Digite um histórico.\nCampo obrigatório");
	document.getElementById('fin_historico').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('fin_documento').value==""){
	alert("Informe o documento.\n   Campo obrigatório");
	document.getElementById('fin_documento').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('fin_total').value==""){
	alert("Informe o valor do lançamento.\n          Campo obrigatório");
	document.getElementById('fin_total').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de contato
function con_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('con_interesse').value==""){
	alert("Informe o interesse.\n Campo obrigatório.");
	document.getElementById('con_interesse').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('con_nome').value==""){
	alert("Informe o nome da Empresa.\n      Campo obrigatório.");
	document.getElementById('con_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('con_responsavel').value==""){
	alert("Informe o nome do Responsável.\n      Campo obrigatório.");
	document.getElementById('con_responsavel').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('con_cep').value==""){
	alert("   Informe o cep.\nCampo obrigatório.");
	document.getElementById('con_cep').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('cmbbx1_1').value==""){
	alert("Escolha a U.F. e a cidade.\n      Campo obrigatório.");
	document.getElementById('cmbbx1_1').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('con_tel').value==""){
	alert("Informe o número do telefone.\n          Campo obrigatório.");
	document.getElementById('con_tel').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('con_email').value==""){
	alert("  Informe o e-mail.\nCampo obrigatório.");
	document.getElementById('con_email').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('con_assunto').value==""){
	alert("Informe o interesse.\n Campo obrigatório.");
	document.getElementById('con_assunto').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// validacao do formulario de solicitacao
function sol_cadastro(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('sol_nome').value==""){
	alert("Informe o nome da Empresa.\n      Campo obrigatório.");
	document.getElementById('sol_nome').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('sol_responsavel').value==""){
	alert("Informe o nome do Responsável.\n      Campo obrigatório.");
	document.getElementById('sol_responsavel').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('sol_email').value==""){
	alert("  Informe o e-mail.\nCampo obrigatório.");
	document.getElementById('sol_email').focus();
	erro="S";
	return false;
  }																																			
  if(document.getElementById('sol_assunto').value==""){
	alert("Informe o assunto.\n Campo obrigatório.");
	document.getElementById('sol_assunto').focus();
	erro="S";
	return false;
  }																																			
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}

// envia texto com fckeditor para um campo de edicao unico
function enviatexto(frmNome, url, destino){
  var erro="N";
  if(document.getElementById('md_tit').value==""){
	alert("Informe o versão da atualização.\n          Campo obrigatório.");
	document.getElementById('md_tit').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('md_sof').value==""){
	alert("Informe o software.\n Campo obrigatório.");
	document.getElementById('md_sof').focus();
	erro="S";
	return false;
  }
  if(document.getElementById('md_dat').value==""){
	alert("Informe a data da atualização.\n         Campo obrigatório.");
	document.getElementById('md_dat').focus();
	erro="S";
	return false;
  }
  var query='';
  var not_conteudo = FCKeditorAPI.GetInstance('not_conteudo').GetXHTML(); 
  //aqui eu troco o & por @@@@@@
  not_conteudo=not_conteudo.replace(/&/g,"@@@@@@");
		
  FCKeditorAPI = null;
  __FCKeditorNS = null;

  // Captura o form
  f = document.getElementById(frmNome);

  for (i=0;i<f.elements.length;i++){
    // concatena a variavel na query
    if(f.elements[i].type=='radio'||f.elements[i].type=='checkbox'){
      if(f.elements[i].checked){
        query +=  '&'+f.elements[i].name + '=' + f.elements[i].value;
	  }
    } else {
      query +=  '&'+f.elements[i].name + '=' + f.elements[i].value.replace("&","@@@@@@");
    }
  }
  // envia o formulario
  //alert(query);

  query+="&not_conteudo="+not_conteudo;
  if(erro=="N"){enviagenerico(query,url,'POST',destino);}
}

// valida cadastro de contrato
function val_ctraasp(frmNome, url, destino ){
  var erro="N";
  if(document.getElementById('ctra_situacao').selectedIndex ==''){ 
	alert("Selecione a situação.\n Campo obrigatório."); 
	document.getElementById('ctra_situacao').focus(); 
	erro="S";
	return false; 
  }  
  if(document.getElementById('ctra_banco').selectedIndex ==''){ 
	alert("Selecione o banco de cobrança.\n          Campo obrigatório."); 
	document.getElementById('ctra_banco').focus(); 
	erro="S";	
	return false; 
  }  
  if(document.getElementById('ctra_boleto').value==''){ 
	alert("Indique a sequencia do boleto.\n          Campo obrigatório."); 
	document.getElementById('ctra_boleto').focus(); 
	erro="S";	
	return false; 
  }  
  if(erro=="N"){enviaForm(frmNome, url, destino);}
}
