/**
 * @author growin
 */

function Dados(valor) 
{
	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) 
	{
				
		if ((valor).length < 3)
		{
			alert("Digite ao menos 3 letras");		
			return false;
		}
     
		idOpcaoNome  			= document.getElementById("nome");
		idOpcaoDescricao  		= document.getElementById("descricao");
		idOpcaoLetra  			= document.getElementById("letra");
		idOpcaoLetraSignificado = document.getElementById("letraSignificado");

		document.getElementById("nome").style.background="#086994";
		document.getElementById("descricao").style.background="#F2F2F2";
		document.getElementById("letra").style.background="#086994";
		document.getElementById("letra").style.color="#FFFFFF";
		document.getElementById("letraSignificado").style.background="#F2F2F2";
		
		document.getElementById("busca").value = "";
	 
		ajax.open("POST", "busca_nome.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
		ajax.onreadystatechange = function() {

			if(ajax.readyState == 1) {
		   		idOpcaoNome.innerHTML = "Carregando...!";   
        	}

            if(ajax.readyState == 4 ) {
				if(ajax.responseXML) {
		      		processXML(ajax.responseXML);
		   		}
			   	else 
				{
					idOpcaoNome.innerHTML = "Busca não encontrada...";
			   	}
        	}
     	}

		var params = "busca=" + valor;
		ajax.send(params);
  	}
}
   
	function processXML(obj){
     
		var dataArray   = obj.getElementsByTagName("significados");
      
	 
		if(dataArray.length > 0) 
		{
			document.getElementById("resultadoBuscaNome").style.display = "";
			
			for(var i = 0 ; i < dataArray.length ; i++) 
			{
	            var item = dataArray[i];
	
				var nome    		 =  item.getElementsByTagName("nome")[0].firstChild.nodeValue;
				var letra			 =  item.getElementsByTagName("letra")[0].firstChild.nodeValue;
				var letraSignificado =  item.getElementsByTagName("letraSignificado")[0].firstChild.nodeValue;
				var arreio    		 =  item.getElementsByTagName("arreio")[0].firstChild.nodeValue;
				
				idOpcaoLetra.innerHTML 				= "<p>" + letra + "</p>";
				idOpcaoLetraSignificado.innerHTML 	= "<p>" + letraSignificado + "</p>";
			
				idOpcaoNome.innerHTML 	= "<p>" + nome + "</p>";
			
				idOpcaoDescricao.innerHTML 	= "";
			
				for (i = 0; i <= arreio; i++) 
				{
					var descricao 				= item.getElementsByTagName("descricao")[i].firstChild.nodeValue;
					descricao 					= descricao.replace("\n", "<br>");
					idOpcaoDescricao.innerHTML 	+= "<p>" + descricao + "</p>";				
				}
			
				
		 	}
	  	}
		else 
		{
			idOpcao.innerHTML = "Busca não encontrada...";
		}	  
	}
