// JavaScript Document
function objAjax() {
};
objAjax.prototype.iniciar = function() {

    try{
        this.xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                this.xmlhttp = false;
            }
        }
    }
    return true;
}
//===============================================================
objAjax.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}
//===============================================================
objAjax.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
        return true;
    }
}
//===============================================================
objAjax.prototype.enviar = function(url, metodo, modo,post) {
    if (!this.xmlhttp) {
        this.iniciar();
    }
    if (!this.ocupado()) {
        if(metodo == "GET") {
            this.xmlhttp.open("GET", url, modo);
            this.xmlhttp.send(null);
        } else {
            this.xmlhttp.open("POST", url, modo);
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
            this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
            this.xmlhttp.setRequestHeader("Pragma", "no-cache");
            this.xmlhttp.send(post);
        }

        if (this.processa) {
            return (this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}
//===============================================================
function montaForm(obj){
	var post=''
	var form=$(obj)
	for (i=0;i<form.length;i++){
	    if(((form[i].type=='checkbox'&&form[i].checked)||(form[i].type=='radio'&&form[i].checked))&&form[i].name!==''){
            	post+=form[i].name+'='+escape(form[i].value);
				if((i+1)!=form.length) post+='\n&';
		}
		else if(form[i].type!='checkbox'&&form[i].type!='radio'&&form[i].name!=='') {
				post+=form[i].name+'='+escape(form[i].value);
				if((i+1)!=form.length) post+='\n&';
		}
	}
	return post;
}
//===============================================================
function sendForm(obj)
{
	var post=montaForm(obj);
	var action=$(obj).action;
	var xmlhttp = new objAjax();
	return xmlhttp.enviar(action, 'POST', false, post);
}
//===============================================================
function sendInfo(url)
{
	var xmlhttp = new objAjax();
	return xmlhttp.enviar(url, 'GET', false);
}
