function alerta(m) {
	if (confirm(m)) {
		return true;
	} else {
		return false;
	}
}

function validar(o) {
	if (o.noticiasTituloForm.value != "" && o.noticiasTextoForm.value != "") {
		return true;
	} else {
		getObj("alertatitulo").innerHTML = "<div class='erro'>Você deve informar um título e um texto.</div><br>";
		return false;
	}
}

function iniciaAjax() {
	var core;
	if (window.XMLHttpRequest) {
		core = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		core= new ActiveXObject("Msxml2.XMLHTTP");
		if (!core) {
			core = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else {
		alert("Seu Navegador não possui suporte a essa aplicação");
	}
	return core;
}

function getObj(obj) {
	if (typeof obj == "string") {
		if (null == (obj = document.getElementById(obj))) {
			throw new Error("Elemento HTML não encontrado. Não foi possível adicionar o evento.");
		}
	}
	return obj;
}

function visivel(id,o,t) {
	var url = "adm/ajax.php?funcao=visivel&id="+id+"&t="+t;
	ajax.open("GET",url,false);
	ajax.send(null);
	getObj(o.id).innerHTML = ajax.responseText;
	ajax.close;
	return false;
}

function titulo(o,id,t) {
	var url = "adm/ajax.php?funcao=titulo&id="+id+"&titulo="+btoa(o.value)+"&t="+t;
	ajax.open("GET",url,false);
	ajax.send(null);
	if (ajax.responseText != 0) {
		//getObj("alertatitulo").innerHTML = "<div class='erro'>O título digitado já existe.</div><br>";
		//getObj("submit").disabled = true;
		getObj("alertatitulo").innerHTML = "";
		getObj("submit").disabled = false;
	} else {
		getObj("alertatitulo").innerHTML = "";
		getObj("submit").disabled = false;
	}
	ajax.close;
}

function newsletter(o) {
	var email = o.news_email.value;
	var nome = o.news_nome.value;
	o.news_email.value = "";
	o.news_nome.value = "";
	var url = "ajax.php?funcao=newsletter&nome="+escape(nome)+"&email="+escape(email);
	ajax.open("GET",url,false);
	ajax.send(null);
	alert(ajax.responseText);
	ajax.close;
	return false;
}

var ajax = iniciaAjax();
