// JavaScript Document

function _gebi(id){
//função que retorna o getElementById
//parâmetro
//id | char | o id
	return document.getElementById(id);
}

function ajax(url,param,tipo,pos){
	var xmlHttp;
	try{ // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch(e){
		try{ // Internet Explorer
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				alert("Browser não suporta AJAX.");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		/*State	Description
		0 = The request is not initialized
		1 = The request has been set up
		2 = The request has been sent
		3 = The request is in process
		4 = The request is complete*/
		
		if(xmlHttp.readyState==4 && xmlHttp.status==200){
			var res;
			if(tipo=='json')
				res=eval(unescape(xmlHttp.responseText));
			else
				res=eval(xmlHttp.responseText);
				
			eval(pos);
		}else if(xmlHttp.readyState==4){
			if(_gebi('erro'))
				_gebi('erro').innerHTML='status='+xmlHttp.status+'<br>'+xmlHttp.responseText;
			else
				alert('\nstatus='+xmlHttp.status+'\n'+xmlHttp.responseText);
		}
	}
	xmlHttp.open("POST",url,true); //get/post , url , assíncrono
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	xmlHttp.send(param);
}