var xmlHttp;

function ajax(metodo,alvo,url) {
	try	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();  
	} catch (e) {
		// Internet Explorer
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	  
			} catch (e) {
				alert("Seu navegador de internet n�o suporta AJAX!");
				return false;
			}
		}
	}
  
	switch(metodo) {
		case 'procedimento' :
				ajaxFaz(url);
			break;
		case 'funcao' :
				ajaxRetorna(url,alvo);
			break;
		case 'inner' :
				ajaxInner(url,alvo);
			break;
	}	
}

function ajaxFaz(url) {
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if(document.getElementById('alvo_imagem')!='undefined') {
                /*prop = new Array('src');
                val = new Array('../php/geraGrafico.php');
                criaElemento('img','alvo',prop,val,'');
                */
               document.getElementById('alvo_imagem').src = url;
               montaLista();
            }
		}
	}
}

function ajaxInner(url,alvo) {
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if(document.getElementById('alvo_imagem')!='undefined') {
                /*prop = new Array('src');
                val = new Array('../php/geraGrafico.php');
                criaElemento('img','alvo',prop,val,'');
                */
               document.getElementById(alvo).innerHTML = xmlHttp.responseText;
               montaLista();
            }
		}
	}
}

function ajaxRetorna(url,alvo) {
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if(alvo=='null') { 
                alert(xmlHttp.responseText); //alert(xmlHttp.responseText.substring(0,77));
            } else if (alvo=='alvo_imagem') {
                document.getElementById(alvo).src = xmlHttp.responseText;
            } else {
                document.getElementById(alvo).innerHTML = xmlHttp.responseText;
            }
		}
	}
}

function chamaAjax(action,url,alvo) {
	xmlHttp.open(action,url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			if (alvo!='null') document.getElementById(alvo).innerHTML = xmlHttp.responseText;
				else alert(xmlHttp.responseText.substring(0,77));
		}
	}
}