function selectAjax(valor,selectname,arqPHP,primeiro,valorIni,ajx) {	
	 if (typeof valorIni == "undefined") {
		valorIni = "";
 	 }
	 
	 if (typeof ajx == "undefined") {
		ajx = "ajaxteste99";
 	 }



	  try {

         ajx = new ActiveXObject("Microsoft.XMLHTTP");

      } 

      catch(e) {

         try {

            ajx = new ActiveXObject("Msxml2.XMLHTTP");

         }

	     catch(ex) {

            try {

               ajx = new XMLHttpRequest();




            }

	        catch(exc) {

               alert("Esse browser não tem recursos para uso do Ajax");

               ajx = null;

            }

         }

      }

	  

	  



	  ajx.abort();

	  if(ajx) {


		 document.getElementById(selectname).options.length = 1;

	     


		 

	     ajx.open("POST", arqPHP, true);

		 

		 ajx.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 

		 ajx.onreadystatechange = function() {


			if(ajx.readyState == 1) {



				document.getElementById(selectname).remove(0);
				var novo = document.createElement("option");
			    novo.setAttribute("id", selectname);
			    novo.value = 0;
			    novo.text  = "Aguarde...";
				document.getElementById(selectname).options.add(novo);
			   

	        }


            if(ajx.readyState == 4 ) {

			     if(ajx.responseXML) {

			      processXML(ajx.responseXML,selectname,selectname,primeiro,valorIni);

			   

			   }

			   else {

				document.getElementById(selectname).remove(0);
				var val=primeiro.split("-");
				var novo = document.createElement("option");
			    novo.setAttribute("id", selectname);
				if(primeiro.indexOf("-")>0){
					var val=primeiro.split("-");
					novo.value = val[1];
					novo.text  = val[0];
				}else{
					novo.text  = primeiro;
					novo.value  = '';
				}	
				document.getElementById(selectname).options.add(novo);
							   

			   }

            }

         }


	     var params = "id="+valor;

         ajx.send(params);

      }

   }

   

   function processXML(obj,selectname,selectname,primeiro,valorIni){

      var dataArray   = obj.getElementsByTagName("it1");

      


	  document.getElementById(selectname).remove(0);

	  if(dataArray.length > 0) {



			if(primeiro){				
				var novo = document.createElement("option");
			    novo.setAttribute("id", selectname);
				if(primeiro.indexOf("-")>0){
					var val=primeiro.split("-");
					novo.value = val[1];
					novo.text  = val[0];
				}else{
					novo.text  = primeiro;
					novo.value  = '';
				}				
				document.getElementById(selectname).options.add(novo);
			}
		 
		 for(var i = 0 ; i < dataArray.length ; i++) {

            var item = dataArray[i];


			var codigo    =  item.getElementsByTagName("it2")[0].firstChild.nodeValue;

			var descricao =  item.getElementsByTagName("it3")[0].firstChild.nodeValue;

			


			

   

			


			var novo = document.createElement("option");


			    novo.setAttribute("id", selectname);

				if(codigo==valorIni)novo.setAttribute("selected", "selected");


			    novo.value = codigo;


			    novo.text  = descricao;


				document.getElementById(selectname).options.add(novo);

				



		 }

		 

	  }

	  else {


		/*var idOpcao.innerHTML = "Erro";*/

	  }	  

	 

}
