
function comunicacao(elemento,nomeid,tipo){
/* Tipo 1 - Mostrar valor na DIV */	/* Tipo 2 - Input */ /* Tipo 3 - Mostrar DIV : style="display:none" é visivel style="display:block" é invisivel */	
	
	try { 
		var comunicador = new  ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e1) { try { var comunicador = new  ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e2) { try { var comunicador = new  XMLHttpRequest(); }
		catch(e3) { alert("Este navegador nao oferece suporte ao uso do AJAX"); var comunicador = null; }}
		}    
	if (comunicador) { 
		var noPai, noFilho;
		comunicador.open("GET", elemento,false);
		comunicador.setRequestHeader('Content-Type','text/xml'); 
		comunicador.setRequestHeader('encoding','ISO-8859-1');
		comunicador.send(null); 
		if (comunicador.readyState == 4) { 
			noPai = document.getElementById(nomeid);
			if      (tipo==1)  noPai.innerHTML     = comunicador.responseText;
			else if (tipo==2)  noPai.value         = comunicador.responseText;
			else if (tipo==3)  noPai.style.display = comunicador.responseText;
            execJS(document.getElementById(nomeid));			
	  }
  }           
}

function enviardados(elemento,campos,idmsn){
	try { 
		comunicador = new  ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e1) { try { comunicador = new  ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e2) { try { comunicador = new  XMLHttpRequest(); }
		catch(e3) { alert("Este navegador nao oferece suporte ao uso do AJAX");  comunicador = null; }}
		}    
	if (comunicador) { 
		var noPai, noFilho;
		comunicador.open("POST", elemento,false);
		comunicador.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		comunicador.setRequestHeader('encoding','ISO-8859-1');
		comunicador.send(campos); 
		if (comunicador.readyState == 4) { 
			if (idmsn =="") idmsn = "mensagem";
			noPai = document.getElementById(idmsn);
		 	noPai.innerHTML = comunicador.responseText;
            execJS(document.getElementById(idmsn));			
	  }
	 
  }           
}

function carregadados(elemento) {
    var form    = document.forms[elemento];
	var tamanho = document.forms[elemento].length;

	var nomeid  = '';
	var campos  = '';
	
	for (i=0;i<tamanho;i++){
		nomeid  = form.elements[i].name;
		valorid = form.elements[i].value;
		if (i==0) {campos = nomeid+'='+valorid}
		else { campos = campos + '&' + nomeid + '=' + valorid;
		}
	}
	
	return campos;
}


function limpardados(elemento) {
    var form    = document.forms[elemento];
	var tamanho = document.forms[elemento].length;
	
	var nomeid  = '';
	var campos  = '';
	
	for (i=0;i<tamanho;i++){
        if (form.elements[i].type!='hidden') {
			if (form.elements[i].type == 'text' || form.elements[i].type == 'password' || form.elements[i].type == 'textarea' )  form.elements[i].value = '';
			else if (form.elements[i].type == 'select-one')  { 
				form.elements[i].options[0].selected = true;
			}
			else if (form.elements[i].type == 'checkbox' || form.elements[i].type == 'radio' ) {
					var arr, t, nome;
					nome = form.elements[i].name;
					arr = form.elements[i];
					t = arr.length;
			
					for(j=0; j<t;j++)
					{
						if (arr[j].checked)
						{
							arr[j].checked = false;
						}
				    }
			}
		}
	}
}


function abrirurl(categoria,pagina){
	var cat = "";
	var pag = "";
	if (categoria!= "" ) cat = "&tp="+categoria;
	if (pagina   >  "0") pag = "&num="+pagina;
	url = 'index.php?pg=2' + cat + pag;
	document.location.href = url;
}

function Carrega(nomecampo) {
	var campo = nomecampo;
     document.getElementById(campo).options.length = 1;
}


/**********************************************************/	
/* Funçao que alterna div  ********************************/
/**********************************************************/	
function alterna(tipo) {
    var tipo_vei =  tipo;
	if (tipo_vei ==0) {
		if (document.getElementById("codtpvei")!=null) {
			document.getElementById("codtpvei").value="";
			tipo_vei = 5;
		}
	}
	
	if (tipo_vei == 5 ) {
	    if (document.getElementById('tp_veiculo')!=null)   document.getElementById('tp_veiculo').style.display   ='block';
		if (document.getElementById('tp_categoria')!=null) document.getElementById('tp_categoria').style.display ='none';
	}
	else if (tipo_vei != 5 ) {
		if (document.getElementById('tp_veiculo')!=null)   document.getElementById('tp_veiculo').style.display   ='none';
		if (document.getElementById('tp_categoria')!=null) document.getElementById('tp_categoria').style.display ='block';
	}
}		 



function abrirpagina (url){
	if (url!=null) {
		url_abrir = url.replace('_','&');
		url_abrir = url_abrir.replace('_','&');
		url_abrir = url_abrir.replace('_','&');
		url_abrir = url_abrir.replace('_','&');
		
		document.location.href=url_abrir;
	}
}

function alterna_tipo(tipo,id1,id2,campoCpf,campoCnpj,CampoSenha) {
	document.getElementById(campoCnpj).value="";
	document.getElementById(campoCpf).value="";
	if (CampoSenha !="") document.getElementById(CampoSenha).value="";

	if (tipo =='F') {
		document.getElementById(id1).style.display='block';
		document.getElementById(id2).style.display='none';
		
	}
	else if (tipo=='J') {
		document.getElementById(id1).style.display='none';
		document.getElementById(id2).style.display='block';

	}
}


<!--Função Ajax que carrega um objeto option -->
function Dados(valor1,campo,desc_campo,nomelista,nomeparametro,nomeid) {
      <!--Verifica se o Browse Suporta Ajax-->
	  var nomecampo   = campo;
	  var tipo_navega = 1;
	  try { 
	  	ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
		tipo_navega = "IE";
	   } 
      catch(e) { 
	  	try {
        	ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
			tipo_navega = "IE";
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
			   tipo_navega = "FF";
            }
	        catch(exc) {
               alert("Esse browser nao tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  
	  if(ajax) {
		 //document.getElementById(nomecampo).options.length = 1;
		 var idOpcao  = document.getElementById(campo);
	     ajax.open("POST", nomelista , true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 ajax.onreadystatechange = function() {
			if(ajax.readyState == 1) {
			  //idOpcao.innerText = "Carregando...!";   
	        }
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML,nomeid,nomecampo,desc_campo,tipo_navega);
			   }
            }
         }
	     var params = nomeparametro+"="+valor1;
         ajax.send(params);
      }
   }

<!--Função processa Dados XML -->
function processXML(obj,nomeid,nomecampo,desc_campo,tipo_navega){ 
  var campo       = nomecampo;	
  var dataArray   = obj.getElementsByTagName(nomeid);
  document.getElementById(campo).options.length = 1;
  
  if(dataArray.length > 0) {

    <!--Só quando for Para o IE-->
	if (tipo_navega =="IE") {
		var novo = document.createElement("option");
			novo.setAttribute("id", "opcoes","selected");
			novo.value = "0";
			novo.text  = desc_campo;
			document.getElementById(campo).options.add(novo);
	}

	for(var i = 0 ; i < dataArray.length ; i++) {
		var item = dataArray[i];
		var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
		var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;

		var novo = document.createElement("option");
			novo.setAttribute("id", "opcoes","selected");
			novo.value = codigo;
			novo.text  = descricao;
			document.getElementById(campo).options.add(novo);
}
  }
}


