function ajax() {
};
ajax.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;
}

ajax.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
        return true;
    }
}

ajax.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=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(url);
        }    

        if (this.processa) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}

function envia(url, metodo, modo, tipo, registroAtual){
	if (tipo == 'administradores') {
		var loginAdministradores = document.getElementById('sAdm_Login').value;
		if (loginAdministradores.toLowerCase() != registroAtual.toLowerCase() && loginAdministradores.toLowerCase() != "") {
			document.getElementById("alertaLoginAdministrador").innerHTML = 'Verificando <strong>Login</strong>, aguarde...';
			remoto  = new ajax();
			xmlhttp = remoto.enviar(url + "?sAdm_Login=" + loginAdministradores, metodo, modo);
			if(xmlhttp) {
				document.getElementById('_loginExiste').value = "0";
				document.getElementById("alertaLoginAdministrador").innerHTML = '<label class="error">O Login digitado j&aacute; est&aacute; cadastrado!</label>';
			} else {
				document.getElementById('_loginExiste').value = "00";
				document.getElementById("alertaLoginAdministrador").innerHTML = '';
			}
		} else {
			document.getElementById('_loginExiste').value = "00";
			document.getElementById("alertaLoginAdministrador").innerHTML = '';
		}
	}
	if (tipo == 'categoriasNovidades') {
		var categoriasNovidades = document.getElementById('sCatNov_Categoria').value;
		if (categoriasNovidades.toLowerCase() != registroAtual.toLowerCase() && categoriasNovidades.toLowerCase() != "") {
			document.getElementById("alertaCategoriasNovidades").innerHTML = 'Verificando <strong>Categoria</strong>, aguarde...';
			remoto  = new ajax();
			xmlhttp = remoto.enviar(url + "?sCatNov_Categoria=" + categoriasNovidades, metodo, modo);
			if(xmlhttp) {
				document.getElementById('_categoriaExiste').value = "0";
				document.getElementById("alertaCategoriasNovidades").innerHTML = '<label class="error">A Categoria digitada j&aacute; est&aacute; cadastrada!</label>';
			} else {
				document.getElementById('_categoriaExiste').value = "00";
				document.getElementById("alertaCategoriasNovidades").innerHTML = '';
			}
		} else {
			document.getElementById('_categoriaExiste').value = "00";
			document.getElementById("alertaCategoriasNovidades").innerHTML = '';
		}
	}
	if (tipo == 'emailNewsletter') {
		var emailNewsletter = document.getElementById('txtEmail').value;
		if (emailNewsletter.toLowerCase() != registroAtual.toLowerCase() && emailNewsletter.toLowerCase() != "") {
			document.getElementById("alertEmail").innerHTML = 'Verificando <strong>E-mail</strong>, aguarde...';
			remoto  = new ajax();
			xmlhttp = remoto.enviar(url + "?sNEWS_Email=" + emailNewsletter, metodo, modo);
			if(xmlhttp) {
				document.getElementById('txtEmailExiste').value = "0";
				document.getElementById("alertEmail").style.display = '';
				document.getElementById("alertEmail").innerHTML = '<label class="error">O E-mail digitado j&aacute; est&aacute; cadastrado!</label>';
			} else {
				document.getElementById('txtEmailExiste').value = "00";
				document.getElementById("alertEmail").innerHTML = '';
				document.getElementById("alertEmail").style.display = 'none';
			}
		} else {
			document.getElementById('txtEmailExiste').value = "00";
			document.getElementById("alertEmail").innerHTML = '';
			document.getElementById("alertEmail").style.display = 'none';
		}
	}
}
