function carrega_ufs(pais, campo, padrao, idm) {
	
    var html = $.ajax({
            url: "ajax_carrega_ufs.php?pais=" + pais + "&campo=" + campo + "&padrao=" + padrao + "&idm=" + idm,
            async: false
            }).responseText;
    
        	if (html!='')
        	{ 
        	    if (campo == "estado_vis") {
        	       $("#div_estado_emp").empty();
                   $("#div_estado_vis").empty();
        		   $("#div_estado_vis").append( html );   
        	    } else {
        	       $("#div_estado_emp").empty();
        	       $("#div_estado_emp").append( html );
        	    }  
        	}
    if (pais == '99999') {
        document.getElementById('div_op_emp').style.display = 'inline';
        document.getElementById('div_op_vis').style.display = 'inline';
        document.getElementById('div_ouf_emp').style.display = 'inline';
        document.getElementById('div_ouf_vis').style.display = 'inline';
        document.getElementById('div_oc_emp').style.display = 'inline';
        document.getElementById('div_oc_vis').style.display = 'inline';
        if (campo == 'estado_emp') {
            document.getElementById('estado_emp').value = '99'; 
            document.getElementById('cidade_emp').value = '99999999';   
        } else {
            document.getElementById('estado_vis').value = '99';  
            document.getElementById('cidade_vis').value = '99999999';     
        }
        
    } else {
        document.getElementById('div_op_emp').style.display  = 'none';
        document.getElementById('div_op_vis').style.display  = 'none'; 
        document.getElementById('div_ouf_emp').style.display = 'none';
        document.getElementById('div_ouf_vis').style.display = 'none'; 
        document.getElementById('div_oc_emp').style.display  = 'none';
        document.getElementById('div_oc_vis').style.display  = 'none'; 
        if (campo == 'estado_emp') {
            document.getElementById('estado_emp').value = padrao;    
        } else {
            document.getElementById('estado_vis').value = padrao;    
        }
    }
         
}

function carrega_mun(uf,campo,padrao,idm)
{
	
    var html = $.ajax({
            url: "ajax_carrega_cidades.php?uf=" + uf + "&campo=" + campo + "&padrao=" + padrao + "&idm=" + idm,
            async: false
            }).responseText;
            
        	if (html!='')
        	{ 
        	    if (campo == "cidade_vis") {
        	       $("#div_cidade_emp").empty();
                   $("#div_cidade_vis").empty();
        		   $("#div_cidade_vis").append( html );   
        	    } else {
        	       $("#div_cidade_emp").empty();
        	       $("#div_cidade_emp").append( html );
        	    }  
        	}
    if (uf == '99') {
        document.getElementById('div_ouf_emp').style.display = 'inline';
        document.getElementById('div_ouf_vis').style.display = 'inline';
        document.getElementById('div_oc_emp').style.display = 'inline';
        document.getElementById('div_oc_vis').style.display = 'inline';
        if (campo == 'cidade_emp') {
            document.getElementById('cidade_emp').value = '99999999';    
        } else {
            document.getElementById('cidade_vis').value = '99999999';    
        }
        
    } else {
        document.getElementById('div_ouf_emp').style.display = 'none';
        document.getElementById('div_ouf_vis').style.display = 'none'; 
        document.getElementById('div_oc_emp').style.display  = 'none';
        document.getElementById('div_oc_vis').style.display  = 'none'; 
        if (campo == 'cidade_emp') {
            document.getElementById('cidade_emp').value = padrao;    
        } else {
            document.getElementById('cidade_vis').value = padrao;    
        }
    }
         
}

function carrega_mun_pais(pais,campo,padrao,idm)
{
    if (idm == 'DSC_ING') {
        document.getElementById('div_ouf_emp').style.display = 'none';
        document.getElementById('div_ouf_vis').style.display = 'none'; 
        var html = $.ajax({
                url: "ajax_carrega_cidades_pais.php?pais=" + pais + "&campo=" + campo + "&padrao=" + padrao + "&idm=" + idm,
                async: false
                }).responseText;
                
            	if (html!='')
            	{ 
            	    if (campo == "cidade_vis") {
            	       $("#div_cidade_emp").empty();
                       $("#div_cidade_vis").empty();
            		   $("#div_cidade_vis").append( html );   
            	    } else {
            	       $("#div_cidade_emp").empty();
            	       $("#div_cidade_emp").append( html );
            	    }  
            	}
        if (pais == '99999') {
            document.getElementById('div_oc_emp').style.display = 'inline';
            document.getElementById('div_oc_vis').style.display = 'inline';
            if (campo == 'cidade_emp') {
                document.getElementById('cidade_emp').value = '99999999';    
            } else {
                document.getElementById('cidade_vis').value = '99999999';    
            }
            
        } else {
            document.getElementById('div_ouf_emp').style.display = 'none';
            document.getElementById('div_ouf_vis').style.display = 'none'; 
            document.getElementById('div_oc_emp').style.display  = 'none';
            document.getElementById('div_oc_vis').style.display  = 'none'; 
            if (campo == 'cidade_emp') {
                document.getElementById('cidade_emp').value = padrao;    
            } else {
                document.getElementById('cidade_vis').value = padrao;    
            }
        }
    }
}

function check_mun(mun, campo) {
    
    if (mun == '99999999') {
        document.getElementById('div_oc_emp').style.display = 'inline';
        document.getElementById('div_oc_vis').style.display = 'inline'; 
        if (campo == 'cidade_emp') {
            document.getElementById('cidade_emp').value = '99999999';    
        } else {
            document.getElementById('cidade_vis').value = '99999999';    
        }   
    } else {
        document.getElementById('div_oc_emp').style.display = 'none';
        document.getElementById('div_oc_vis').style.display = 'none';
    }
}

function check(valor) 
{
	if (valor=="consumidor")
	{
		/*
		document.getElementById('form_cliente').style.visibility = 'hidden';
		document.getElementById('mot_ocorr').style.visibility	 = 'visible';
		document.getElementById('form_cons').style.visibility	 = 'visible';
		*/

		document.getElementById('form_cliente').style.display = 'none';
		document.getElementById('mot_ocorr').style.display	  = 'inline';
		document.getElementById('form_cons').style.display	  = 'inline';
        document.getElementById('div_op_emp').style.display = 'none';
        document.getElementById('div_op_vis').style.display = 'none';
	}			
	
	if (valor=="cliente")
	{
		/*
		document.getElementById('form_cons').style.visibility	 = 'hidden';
		document.getElementById('mot_ocorr').style.visibility	 = 'visible';
		document.getElementById('form_cliente').style.visibility = 'visible';
		*/

		document.getElementById('form_cons').style.display	  = 'none';
		document.getElementById('mot_ocorr').style.display	  = 'inline';
		document.getElementById('form_cliente').style.display = 'inline';
        document.getElementById('div_op_emp').style.display = 'none';
        document.getElementById('div_op_vis').style.display = 'none';
	}
}

function no_changes(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;

	return false;
}

//Everson - Tarefa 65401 / Projeto 7312 - 23/09/2011
//	Implementar o conceito de multilinguagem no módulo HBtec-Falecom, para que seja possível trabalhar com outros idiomas
//	e sendo preparado para trabalhar nas versões português, inglês e espanhol da FGM

//limpar o formulário e guardar o idioma selecionado!

function limpar()
{
    var num_pesquisa = document.frm1.num_pesquisa.value,
        num_cpf_cgc  = document.frm1.cpf.value,
		idioma = document.getElementById('idioma').value;//Implementado o idioma;
        
	block();
    if (num_pesquisa != '') 
	{
        window.location='http://vmphp5.hbtec.local/afv_sac/sys/pesquisa_fgm/aplicacao_pesquisa.php?num_pesquisa=' + num_pesquisa + '&num_cpf_cgc=' + num_cpf_cgc;       
    } 
	else 
	{
		if(idioma != '')
		{
			window.location='contato.php?cod_emp=' + document.frm1.cod_emp.value + '&IDM=' + idioma; //Implementado o 'IDM'
		}
		else
		{
			window.location='contato.php?cod_emp=' + document.frm1.cod_emp.value;	
		}	
    }
	
}

//--------------------------------------------------------------------------------------------------------------
//												FIM TAREFA
//--------------------------------------------------------------------------------------------------------------

function no_update(tipo)
{
    
  if (tipo == 'emp')
	{
		document.frm1.cnpj.readOnly			= true;
		document.frm1.raz_soc.readOnly		= true;
		document.frm1.email_emp.readOnly	= true;
		document.frm1.endereco_emp.readOnly	= true;
		document.frm1.bairro_emp.readOnly	= true;
		document.frm1.cep_emp.readOnly      = true;
		document.frm1.telefone_emp.disabled	= true;
        document.getElementById('pais_emp').disabled	= true;
		document.getElementById('estado_emp').disabled	= true;
		document.getElementById('cidade_emp').disabled	= true;
        
	}

	if (tipo == 'cli')
	{
		document.frm1.cpf.readOnly			= true;
		document.frm1.nome.readOnly			= true;
		document.frm1.nascimento.readOnly	= true;
		document.frm1.email_vis.readOnly	= true;
		document.frm1.endereco_vis.readOnly	= true;
		document.frm1.bairro_vis.readOnly	= true;
		document.frm1.cep_vis.readOnly		= true;
		document.frm1.telefone_vis.readOnly	= true;
		document.frm1.celular.readOnly		= true;
        document.getElementById('pais_vis').disabled	    = true;
		document.getElementById('estado_vis').disabled	= true;
		document.getElementById('cidade_vis').disabled	= true;
        
	}
}

function isValidDate(tObject, dt_fmt)
{
	var dt_format = 'DD\/MM\/YYYY';
	
	if( dt_fmt != undefined ) 
	{ 
		dt_format = dt_fmt;  
	}

	if( dt_format.indexOf('-') >=0 )
	        div = '-';
	else
	        div = '/';
	
	tObject.value = clean(tObject.value);
	dt_fmt        = clean(dt_format);
	
	if(isValidNumber(tObject.value)) 
	{
		if((tObject.value.length == 0)||(tObject.value == '')){ return false; }
		var old_data = tObject.value;
		var erro  = false;
		var erro1 = false;
		var meses = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		if(tObject.value.length == 8)
		{
			  var dia;
			  var mes;
			  var ano;
			  var nova_data;
			  
			  var pD = dt_fmt.indexOf('D');
			  var pM = dt_fmt.indexOf('M');
			  var pY = dt_fmt.indexOf('Y');
			  
			  dia = tObject.value.substring(pD,pD+2);
			  mes = tObject.value.substring(pM,pM+2);
			  ano = tObject.value.substring(pY,pY+4);
			  
			  if(mes > 12  ){ erro1 = true; }
			  if(ano < 1800){ erro1 = true; }
	
			  if(mes==02)
				 if((ano%4)==0) meses[1] = 29;
	
			  if(dia > meses[mes-1] ) { erro1 = true; }
			  
			  nova_data = '';
			  if( ( pD < pM ) && ( pD < pY ) )
			  {
			  	nova_data += dia + div;
			  	
			  	if( pM < pY )
			  		nova_data += mes + div + ano;
			  	else
			  		nova_data += ano + div + mes;
			  }
			  else
			  {
			  	if( pM < pY )
			  		nova_data = mes + div + dia + div + ano;
			  	else
			  		nova_data = ano + div + mes + div + dia;
			  }
			  //nova_data     = dia + div + mes + div + ano;
			  tObject.value = nova_data;
		 } 
		 else { erro = true; }
	} 
	else 
	{
		erro = true;
	}
	 if(erro || erro1){
	   if(erro1)
		   window.alert('Data inválida!');
	   else 
		   window.alert('Campo é do tipo data!');
	   tObject.focus();
	   tObject.value = '';
	 } else {
	   tObject.value = nova_data;
	 }   
}

/**
* Tarefa 7246/62799 - Alex - 16/06/2011
* Descrição.: formata um campo do formulário de  
* acordo com a máscara informada...  
* Parâmetros: - objForm (o Objeto Form)  
* - strField (string contendo o nome  
* do textbox)  
* - sMask (mascara que define o  
* formato que o dado será apresentado,  
* usando o algorismo "9" para  
* definir números e o símbolo "!" para  
* qualquer caracter...  
* - evtKeyPress (evento)  
* Uso.......: <input type="textbox"  
* name="xxx".....  
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">  
* Observação: As máscaras podem ser representadas como os exemplos abaixo:  
* CEP -> 99.999-999  
* CPF -> 999.999.999-99  
* CNPJ -> 99.999.999/9999-99  
* Data -> 99/99/9999  
* Tel Resid -> (99) 999-9999  
* Tel Cel -> (99) 9999-9999  
* Processo -> 99.999999999/999-99  
* C/C -> 999999-!  
* E por aí vai...  
***/ 
function txtBoxFormat(objForm, strField, sMask, evtKeyPress, campo) { 
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla, tipo, tamanho; 
    var tp_jur, tp_fis, idioma;
    
    tamanho = sMask.length - 3;
    idioma = document.getElementById('idioma').value;
    tp_jur = document.getElementById('tipo_pessoa_0');
    
    //tipo = document.getElementById('flag_tipo_pessoa').value;
    if (tp_jur.checked == 'checked' && campo == 'cnpj') {
       sMask = '99.999.999/9999-99';
       tamanho = 15;       
    }
    
    if (idioma != '' && (campo == 'telefone_emp' || campo == 'telefone_vis' || campo == 'celular')) {
       sMask = '999999999999999';
       tamanho = 15;      
    }
    
    
    tamanho = sMask.length - 3;
    
    /*if (tipo == '2') {
        sMask = '99.999.999/9999-99';
        tamanho = 15;
    }*/
    if(document.all) { // Internet Explorer 
        nTecla = evtKeyPress.keyCode; } 
    else if(document.layers) { // Nestcape 
        nTecla = evtKeyPress.which; 
    } 
 
    sValue = strField; 
 
    // Limpa todos os caracteres de formatação que 
    // já estiverem no campo. 
    sValue = sValue.toString().replace( "-", "" ); 
    sValue = sValue.toString().replace( "-", "" ); 
    sValue = sValue.toString().replace( ".", "" ); 
    sValue = sValue.toString().replace( ".", "" ); 
    sValue = sValue.toString().replace( "/", "" ); 
    sValue = sValue.toString().replace( "/", "" ); 
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( "+", "" );
    sValue = sValue.toString().replace( ",", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;
    mskLen1 = sMask.length;
 
    i = 0; 
    nCount = 0; 
    sCod = ""; 
    mskLen = fldLen;
     
    while (i <= mskLen) { 
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/")) 
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ")) 
        
        if (bolMask)
        { 
          sCod += sMask.charAt(i); 
          
          if (mskLen <= tamanho){
            mskLen++;
          }
            
        } else { 
          sCod += sValue.charAt(nCount); 
          nCount++; 
        } 
        i++; 
    } 

    document.getElementById(campo).value = sCod;
 
    if (nTecla != 8) { // backspace 
        if (sMask.charAt(i-1) == "9") // apenas números... 
        { 
          return ((nTecla > 47) && (nTecla < 58)); // números de 0 a 9 
        } else { // qualquer caracter... 
            return true; 
        }
    } else { 
        return true; 
    } 
} 
