/*
* Desenvolvido por Luciano Dexheimer Morais
* E-mail: lucianodmorais@gmail.com
* Website: http://www.lucianomorais.com.br
*/
function sendToPHP(email,id) {
	var expressao=new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(!(expressao.test(document.getElementById('sendemail_email'+id).value))) {
		alert("Digite um e-mail válido!");
	} else {
		AjaxRequest();
		if(!Ajax) {
			alert("Erro na chamada");
			return;
		}
		document.getElementById("sendemail"+id).innerHTML='Enviando e-mail para <b><u>'+email+'</u></b>...';
		Ajax.onreadystatechange = processaResultado;
		Ajax.open('GET', 'ajax/colunas/sendemail.php?ajaxON=1&email='+email+'&id='+id, true);
		Ajax.send(null);
	}
}
function processaResultado() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText.split('%%%%%');
			document.getElementById('sendemail'+respo[1]).innerHTML=respo[0];
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}
function sendToPHP3(id) {
	var expressao=new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(document.getElementById('comentando_nome'+id).value.length==0) {
		document.getElementById('comentando_nome'+id).style.border='solid 1px #ff0000';
		alert('Digite seu nome!');
		return;
	} else if(document.getElementById('comentando_email'+id).value.length==0) {
		document.getElementById('comentando_email'+id).style.border='solid 1px #ff0000';
		alert('Digite seu e-mail!');
		return;
	} else if(!(expressao.test(document.getElementById('comentando_email'+id).value))) {
		document.getElementById('comentando_email'+id).style.border='solid 1px #ff0000';
		alert("Digite um e-mail válido!");
	} else if(document.getElementById('comentando_texto'+id).value.length==0) {
		document.getElementById('comentando_texto'+id).style.border='solid 1px #ff0000';
		alert('Digite seu comentário!');
		return;
	} else {
		AjaxRequest();
		if(!Ajax) {
			alert("Erro na chamada");
			return;
		}
		var coluna = document.getElementById('id_coluna'+id).value;
		var nome = document.getElementById('comentando_nome'+id).value;
		var email = document.getElementById('comentando_email'+id).value;
		var texto = document.getElementById('comentando_texto'+id).value;
		document.getElementById("comentando"+id).innerHTML='<b>Registrando comentário...</b><br /><br />';
		document.getElementById('comentando_nome'+id).value=nome;
		document.getElementById('comentando_email'+id).value=email;
		document.getElementById('comentando_texto'+id).value=texto;
		var aux = "";
		for(var i = 0; i<=texto.length;i++) aux += texto.substring(i,(i+1)).charCodeAt()==10 ? "|%PL%|" : texto.substring(i,(i+1));
		texto = aux;
		Ajax.onreadystatechange = processaResultado3;
		Ajax.open('GET', 'ajax/colunas/comentando.php?ajaxON=1&coluna='+coluna+'&nome='+nome+'&email='+email+'&id='+id+'&texto='+texto, true);
		Ajax.send(null);
	}
}
function processaResultado3() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText.split('%');
			if(respo[0]==1) var resposta='Algum erro ocorreu durante o registro do seu comentário.<br />Tente novamente.';
			else {
				var resposta='Comentário adicionado com sucesso!';
				$("input[id^=comentando_]").val();
				atualizaComentarios(respo[1]);
			}
			document.getElementById('comentando'+respo[1]).innerHTML='<b>'+resposta+'</b><br /><br />';
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}
function atualizaComentarios(id) {
	AjaxRequest();
	if(!Ajax) {
		alert("Erro na chamada");
		return;
	}
	Ajax.onreadystatechange = atualizandoComentarios;
	document.getElementById('comentarios_'+id).innerHTML='<br /><br /><br /><br />Atualizando...<br /><br /><br /><br /><br /><br />';
	Ajax.open('GET', 'ajax/colunas/comentarios.php?id='+id+'&ajaxON=1', true);
	Ajax.send(null);
}
function atualizandoComentarios() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText.split('%%%%%%');
			document.getElementById('comentarios_'+respo[1]).innerHTML=respo[0];
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}
function alteraPaginacao(pag) {
	AjaxRequest();
	if(!Ajax) {
		alert("Erro na chamada");
		return;
	}
	Ajax.onreadystatechange = atualizaPaginacao;
	var aux = pag.split('=');
	document.getElementById('comentarios_'+aux[2]).innerHTML='<center><br /><br /><br /><br />Carregando...<br /><br /><br /><br /><br /><br /></center>';
	Ajax.open('GET', 'ajax/colunas/comentarios.php'+pag+'&ajaxON=1', true);
	Ajax.send(null);
}
function atualizaPaginacao() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText.split('%%%%%%');
			document.getElementById('comentarios_'+respo[1]).innerHTML=respo[0];
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}


