/**
*	@description: Efetua operação no modelo XMLHTTP "Ajax" via POST
*	@author: Pablo Diego - pablodc@gmail.com
*	@date: 09/03/2006
*
*	@called: loadAjax('url_desejada.php','id_resultado',ObjForm)
*/

function loadAjax(url,id,objForm){
	objAjax = Ajax();
	if(objAjax){
		parametros = montaParametros(objForm);
		//alert(parametros);
		objAjax.open("POST",url, true);
		objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
		objAjax.onreadystatechange = function(){
			if(objAjax.readyState == 1){
				echo(id,"<center><img src='js/loading.gif'></center>");
			}
			if(objAjax.readyState == 2){
				echo(id,"<center><img src='js/loading.gif'></center>");
			}
			if(objAjax.readyState == 4){
				if(objAjax.status == 200){
					echo(id,objAjax.responseText);
				}else{
					echo(id,"Error: " + objAjax.statusText);
				}
			}
		}
		//alert(montaParametros(objForm));
		objAjax.send(parametros);
	}
}

function Ajax(){
	var ajax;
	try{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex){
			try{
				ajax = new XMLHttpRequest();
			}catch(exc){
				alert("Este browser não tem recursos para uso do XMLHTTP");
				ajax = null;
			}
		}
	}
	return ajax;
}

function montaParametros(objForm){
	var saida = "";
	if(objForm){
		var y = objForm.length-1;
		for(x = 0; x < objForm.length; x++){
			if(objForm[x].disabled != true && objForm[x].style.display != "none" && objForm[x].type != "button" && objForm[x].type != "reset" && objForm[x].type != "submit"){
				//alert(objForm[x].name);
				saida = saida + objForm[x].name + "=" + objForm[x].value;
				//if(x < (y-1)){
					saida = saida + "&";
				//}
			}else{
				y = y-1;
			}
		}
	}
	return saida;
}

function echo(id,texto){
	document.getElementById(id).innerHTML = texto;
}