function ajax_categorias(valor) {

var ajax = null;

if (window.XMLHttpRequest){
    // If IE7, Mozilla, Safari, etc: Use native object
    ajax = new XMLHttpRequest()
}
else
{
    if (window.ActiveXObject){
    // ...otherwise, use the ActiveX control for IE5.x and IE6
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
    }
}


  //verifica se o browser tem suporte a ajax
//	  try {
//         ajax = new ActiveXObject("Microsoft.XMLHTTP");
//      }
//      catch(e) {
//         try {
//            ajax = new ActiveXObject("Msxml2.XMLHTTP");
//         }
//	     catch(ex) {
//            try {
//               ajax = new XMLHttpRequest();
//            }
//	        catch(exc) {
//               alert("Esse browser não tem recursos para uso do Ajax");
//               ajax = null;
//            }
//         }
//      }

	  if(ajax) {

		 //document.forms[0].categorias.options.length = 2;
                 var combo = document.getElementById('selcat');
                 combo.disabled = false;
                 combo.options.length = 2;

		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "/ajax/xml_categorias.php", true);
         //ajax.open("POST", "http://192.168.1.101/mix09/web/xml_categorias.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...";   
	        }
			//apos ser processado - chama funcao processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso no seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "Erro XML";
			   }
            }
         }
		 //passa o cdigo do estado escolhido
	     var params = "CdCidade="+valor;
		 //alert(params);
         ajax.send(params);
      }
   }
   
   function processXML(obj){
      //pega o xml
      var dataArray   = obj.getElementsByTagName("categorias");
      
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//conteudo dos campos no arquivo XML
			var id_bairro    =  item.getElementsByTagName("cd_categoria")[0].firstChild.nodeValue;
			var nome =  item.getElementsByTagName("nome_categoria")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "Selecione";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = id_bairro;
				//atribui um texto
			    novo.text  = nome;
				//finalmente adiciona o novo elemento
				//document.forms[0].categorias.options.add(novo);
                                var combo = document.getElementById('selcat');
                                combo.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Sem cidades cadastradas!";
	  }	  
   }


