
function tryAjax () {
	
	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;
            }
         }
      }
      
      return ajax;
	
	
}

function alturaDiv (num) {
	
	
	return num * 23;
	
}



function ajaxBuscaSetores(empresaID) {
	
	/// FAZ UMA BUSCA DOS DADOS POR AJAX E CHAMA A FUNÇÃO QUE MONTA O SELECT

  var ajax = tryAjax();
  var div  = document.getElementById('setor_select');
  var php = 'mods/ajaxSetores.php';

  if(ajax) {
  	
  ajax.open("POST", php, true); // TRUE PARA NÃO SER SÍNCRONO
  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
  ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
	  		if (ajax.status == 200) {
	            	//alert(divId + "\n" + classe + "\n" + php + "\n" + where);
					//montaSelect (selectId, divId, classe, ajax.responseText,'onChange=\"buscaSelect(' + selectId + ',' + divId + ',' + classe + ',' + php + ',' + where + ');\"');
	            //alert(ajax.responseText);
	            var ajaxText = ajax.responseText;
	            dados = ajaxText.split("#");
	            resultados = dados[0];
	            texto = dados[1];
	            div.style.height = alturaDiv(resultados);
				div.innerHTML =  texto;
	  		} 
	  		else 
	  		{
	  			alert('ERRO: '+ajax.statusText);
	  		}

    	}


   	}
	//passa o código do estado escolhido
	//var params = where;
	//ajax.send(empresaId);

	var select = "empresaID="+empresaID;
	ajax.send(select);  
	     
   return true;
   }
	  
}


