function ajaxInit() 
{
	var xmlhttp;

	try 
	{
  		xmlhttp = new XMLHttpRequest();
	} 
	catch(ee) 
	{
    	try 
		{
	    	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   		} 
		catch(e) 
		{
	  		try 
			{
		 		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  		} 
			catch(E) 
			{
				xmlhttp = false;
	  		}
    	} //GP catch(e)
	} //GP catch(ee) 

	return xmlhttp;

} //GP function ajaxInit() 

//IIZ: Coloca conteudo de noticia e a sua paginacao
//nao terminada
function ConteudoNoticia ( pagina )
{
	//inicia AJAX
	ajax = ajaxInit();
	 
	if( ajax )
	{
		//Abre arquivo que retornará os dados
		ajax.open("GET", "/AjaxConteudoNoticia.php?" + pagina, true);
		
		ajax.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=iso-");   
		
		ajax.onreadystatechange = function(){
			
			//Estado 1: Enquanto carrega dados
			if(ajax.readyState == 1)
			{
				//document.getElementById("selectbox_extra").innerHTML = "Carregando...";	
			}
			   
			
			//Estado 4: Dados já carregados
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)
				{
					//recebe uma string com vários dados entre eles os requeridos  
					resposta =  ajax.responseText;
					document.getElementById("conteudo_noticia").innerHTML = resposta;
					
				}
				else
				{
					alert("Não foi possível realizar operação");
				}
			}
		}
ajax.send(null);
	}
}


//ANDZ: "adaptação" da função ConteudoNoticia para a pagina de busca
function ConteudoBusca (busca, pagina, flag)
{	
	var xmlhttp, path_relativo = "/dev";
	
	//inicia AJAX
	ajax = ajaxInit();

	if( ajax )
	{
		//Abre arquivo que retornará os dados
		ajax.open("GET", "/AjaxConteudoBusca.php?string_busca=" + url_encode (busca, true) +"&Pg=" + pagina +"&flag=" + flag, true);
		
		ajax.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=ISO-");   
		
		ajax.onreadystatechange = function()
		{
			//Estado 1: Enquanto carrega dados
			if(ajax.readyState == 1)
			{
				document.getElementById('alvo_ajax').innerHTML = '<img src=\"img/loading.gif\" align=\"center\">';
				document.getElementById('alvo_ajax').align = 'center';
			}
			   
			
			//Estado 4: Dados já carregados
			if(ajax.readyState == 4)
			{
				document.getElementById('alvo_ajax').align = '';
				
				if(ajax.status == 200)
				{
					//recebe uma string com vários dados entre eles os requeridos  
					resposta =  ajax.responseText;
					
					document.getElementById("alvo_ajax").innerHTML = resposta;
				}
				else
				{
					alert("Não foi possível realizar operação" + ajax.status);
				}
			}
		}
		ajax.send(null);
	}
}

// url_encode version 1.0 
function url_encode(str)
{ 
    var hex_chars = "0123456789ABCDEF"; 
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
    var n, strCode, hex1, hex2, strEncode = ""; 

    for(n = 0; n < str.length; n++) { 
        if (noEncode.test(str.charAt(n))) { 
            strEncode += str.charAt(n); 
        } else { 
            strCode = str.charCodeAt(n); 
            hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
            hex2 = hex_chars.charAt(strCode % 16); 
            strEncode += "%" + (hex1 + hex2); 
        } 
    } 
    return strEncode; 
} 

/*
// url_decode version 1.0 
function url_decode(str) { 
    var n, strCode, strDecode = ""; 

    for (n = 0; n < str.length; n++) { 
        if (str.charAt(n) == "%") { 
            strCode = str.charAt(n + 1) + str.charAt(n + 2); 
            strDecode += String.fromCharCode(parseInt(strCode, 16)); 
            n += 2; 
        } else { 
            strDecode += str.charAt(n); 
        } 
    } 
    return strDecode; 
}  
*/

//LIMA: Remove um Nó
function RemoveNo( No)
{

	//inicia AJAX
	ajax = ajaxInit();
	 
	if( ajax )
	{
		//Abre arquivo que retornará os dados
		ajax.open("GET", "menu_back.php?codigo=" + No, true);
		ajax.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=iso-");   
	
		ajax.onreadystatechange = function() {
			
			//Estado 1: Enquanto carrega dados
			if(ajax.readyState == 1)
			{
				//document.getElementById("selectbox_extra").innerHTML = "Carregando...";	
			}
			   
			
			//Estado 4: Dados já carregados
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)
				{
					//recebe uma string com vários dados entre eles os requeridos  
					resposta =  ajax.responseText;
						
					document.getElementById("Arvore").innerHTML = resposta;
			
				}
				else
				{
					alert("Não foi possível realizar operação");
				}
			}
		}
		ajax.send(null);
	}
}

//alert('Teste 2');
