function aj() {
};
aj.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;
}

aj.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}

aj.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
        return true;
    }
}

aj.prototype.enviar = function(url, metodo, modo) {
    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=ISO-8859-1");
            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(url);
        }

        if (this.processa) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}

// Define variável global
var xmlhttp;

function buscafone1(cod){
    xmlhttp = new aj();
    document.getElementById("div_"+cod).innerHTML = "Carregando Telefones...";
    document.getElementById("div_"+cod).innerHTML = xmlhttp.enviar('dados.php?cod='+cod, 'POST', false);
}

function cadastraCategoria(varForm) {

    // Define variáveis
    var varNome;

    // Atribui valores as variáveis
    varNome  = escape(varForm.textNome.value);

    // Instancia o objeto, dependendo do navagador
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Seu navegador n&atilde;o suporta XMLHttpRequest.");
        return;
    }

    xmlhttp.open("POST", "CadCategoria.php", true);

    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
    xmlhttp.setRequestHeader("Pragma", "no-cache");

    xmlhttp.onreadystatechange = processReqChange;

    xmlhttp.send("textNome=" + varNome);
}

function cadastraCliente(varForm) {

    // Define variáveis
    var varNome;
    var varTelefone;
    var varEmail;
    var varSite;

    // Atribui valores as variáveis
    varNome  = escape(varForm.txtNome.value);
    varTelefone = escape(varForm.txtTelefone.value);
    varEmail        = escape(varForm.txtEmail.value);
    varSite  = escape(varForm.txtSite.value);

    // Instancia o objeto, dependendo do navagador
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Seu navegador n&atilde;o suporta XMLHttpRequest.");
        return;
    }

    xmlhttp.open("POST", "cadastro.php", true);

    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
    xmlhttp.setRequestHeader("Pragma", "no-cache");

    xmlhttp.onreadystatechange = processReqChange;

    xmlhttp.send("txtNome=" + varNome + "&txtTelefone=" + varTelefone + "&txtEmail=" + varEmail + "&txtSite=" + varSite);
}


/*
 * Edilson Hipolito da Silva
 * Ultima Alteracao = 08/12/2009 16:58
 */
function carregaCategoria() {
    //  xmlhttp = new aj();
    //    x = xmlhttp.enviar('../cadatendimentoaj.php?dt='+ dt +'&hora='+ hora +'&defeito='+ defeito +'&cliente='+ cliente +'&endereco='+ endereco +'&funcionario='+ funcionario +'&prioridade='+ prioridade +'&status='+ status +'&tipo='+ tipo, "POST", false); //manda adicionar
    xmlhttp = new aj();
    document.getElementById("div_categoria").innerHTML = "Carregando categorias...";
    document.getElementById("div_categoria").innerHTML = xmlhttp.enviar('CarregaCategoria.php', 'POST', false);

}


function processReqChange() {

    document.getElementById("resposta").innerHTML = "Processando dados...";
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            // xmlhttp.responseText, recebe o valor da variavel $msg de cadastro.php
            if(xmlhttp.responseText == 1) {
                //document.getElementById("resposta").innerHTML = "DADOS CADASTRADOS COM SUCESSO ! ! ! <br><br><br>";
                alert("DADOS CADASTRADOS COM SUCESSO !!!");
            //window.location.href = "http://www.wmonline.com.br";        // Redireciona para uma pagina....
            } else
                document.getElementById("resposta").innerHTML = xmlhttp.responseText;

        } else {
            alert("Problemas ao carregar o arquivo.");
        }
    }

}
