function testAjax()
{
	try {
	 return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				return new XMLHttpRequest();
			}
			catch(exc) {
			   alert("Esse browser não tem recursos para uso do Ajax");
			   return null;
			}
		}
	}
}


function lista(exotico) {
	
	if(exotico == 1){
		div = document.getElementById("bichinhos-exoticos-lista");
		comp = "-exoticos";
		}else{
		div = document.getElementById("bichinhos-lista");
		comp = "";
		
	}
	
	
	if(div.className == "display-ativado"){
		div.className = "display-desativado";
		
	}else{
		
		if(ajax = testAjax()) {
			   
			ajax.open("POST", "../../modulos/bichinhos/bichinho.php", true);
			 
			listaBichinhos 	= document.getElementById("bichinhos"+comp+"-lista");
			 
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			 
			ajax.onreadystatechange = function() {
				 
				if(ajax.readyState == 1) {
					listaBichinhos.innerHTML = "Carregando...";
				}
				 
				if(ajax.readyState == 4 ) {
					if(ajax.responseText != "nada") {
						div.className = "display-ativado";
						listaBichinhos.innerHTML = unescape(ajax.responseText.replace(/\+/g," "));
					}else
						listaBichinhos.innerHTML = "Sem Bichinhos!";
				}
				
			}
			
			if(exotico == 1)
				comp = "&exotico=1";
			else
				comp = "&exotico=0";
			
			var params = "listar=1"+comp;
			ajax.send(params);
				 
		}
	}
}



//ao apertar enter (13) ou tab(9)

function onenter(evt, exotico){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode == 13 || charCode == 9){
		
		if(exotico == 1){
			div = document.getElementById("bichinhosexoticos");
		}else{
			div = document.getElementById("bichinhos");
		}
	 	div.className = "display-desativado";
	}
}

