function mandarOrkut(){
	a=document.getElementById('mandarOrkut');
	document.getElementById('mandarEmail').style.display="none";

	if(a.style.display=="none")	{
		a.style.display="block";
	}else{
		a.style.display="none";
	}
}

function mandarEmail(){
	a=document.getElementById('mandarEmail');
	document.getElementById('mandarOrkut').style.display="none";

	if(a.style.display=="none")	{
		a.style.display="block";
	}else{
		a.style.display="none";
	}
}

function Comentario(){
	a=document.getElementById('Comentario');

	if(a.style.display=="none")	{
		a.style.display="block";
	}else{
		a.style.display="none";
	}
}

function validar(){
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (document.enviamensagem.seunome.value == "" || document.enviamensagem.seunome.value == "Seu nome")	{
		window.alert("Erro ! Digite seu Nome");
		enviamensagem.seunome.focus();
		return false;
	}
	if (document.enviamensagem.seuemail.value == "" || document.enviamensagem.seuemail.value == "Seu email")	{
		window.alert("Erro ! Digite seu E-mail");
		enviamensagem.seuemail.focus();
		return false;
	}

	if(reEmail.test(document.enviamensagem.seuemail.value)){}
	else{
		window.alert("Erro ! E-mail INVÁLIDO");
		enviamensagem.seuemail.focus();
		return false;
	}
	if(document.enviamensagem.amigonome.value == "" || document.enviamensagem.amigonome.value == "Nome amigo"){
		window.alert("Erro ! Digite Nome do Amigo");
		enviamensagem.amigonome.focus();
		return false;
	}
	if (document.enviamensagem.amigoemail.value == "" || document.enviamensagem.amigoemail.value == "Email amigo"){
		window.alert("Erro ! Digite E-mail do Amigo");
		enviamensagem.amigoemail.focus();
		return false;
	}
	if(reEmail.test(document.enviamensagem.amigoemail.value)){}
	else{
		window.alert("Erro ! E-mail INVÁLIDO");
		enviamensagem.amigoemail.focus();
		return false;
	}
}

function validarComment(){
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (document.enviacomentario.nomeComment.value == "" || document.enviacomentario.nomeComment.value == "Seu nome")	{
		window.alert("Erro ! Digite seu Nome");
		enviacomentario.nomeComment.focus();
		return false;
	}
	if (document.enviacomentario.emailComment.value == "" || document.enviacomentario.emailComment.value == "Seu email")	{
		window.alert("Erro ! Digite seu E-mail");
		enviacomentario.emailComment.focus();
		return false;
	}

	if(reEmail.test(document.enviacomentario.emailComment.value)){}
	else{
		window.alert("Erro ! E-mail INVÁLIDO");
		enviacomentario.emailComment.focus();
		return false;
	}

	if (document.enviacomentario.comentarioComment.value == ""){
		window.alert("Erro ! Digite o Comentário");
		enviacomentario.comentarioComment.focus();
		return false;
	}
}

function EmailMensagem(seunome,seuemail,amigonome,amigoemail,mensagem,url){
	var ajax = openAjax();
	if(ajax){
		spanenvia = document.getElementById('emailmensagem');
		spanamigonome = document.getElementById('spanamigonome');
		spanamigoemail = document.getElementById('spanamigoemail');
		spanmsg = document.getElementById('spanmsg');

		ajax.open("POST", "/poemas_poesias/envia.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		ajax.onreadystatechange = function(){
			if(ajax.readyState == 1){
				spanenvia.innerHTML = "<img src='/poemas_poesias/barraEnviando.gif'>";   
			}
			if(ajax.readyState == 4 ){
				var resultado = ajax.resposeText;
				resultado="<img src='/poemas_poesias/check.gif'>";
				spanenvia.innerHTML = resultado;
				spanamigonome.value='';
				spanamigoemail.value='';
				spanmsg.value='';
			}
		}

		var params = "url="+url+"&seunome="+escape(seunome)+"&seuemail="+seuemail+"&amigonome="+escape(amigonome)+"&amigoemail="+amigoemail+"&msg="+escape(mensagem);
		//prompt('',params);
		ajax.send(params);		
	}
}


function EnviaComment(nome, email, comentario, ip, idsonho){
	var ajax = openAjax();
	if(ajax){
		retornocomentario = document.getElementById('retornocomentario');
		nomeComment       = document.getElementById('nomeComment');
		emailComment      = document.getElementById('emailComment');
		comentarioComment = document.getElementById('comentarioComment');

		ajax.open("POST", "/poemas_poesias/enviaComment.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		ajax.onreadystatechange = function(){
			if(ajax.readyState == 1){
				spanenvia.innerHTML = "<img src='/poemas_poesias/barraEnviando.gif'>";   
			}
			if(ajax.readyState == 4 ){
				var resultado = ajax.resposeText;
				resultado="<img src='/poemas_poesias/check.gif'>";
				retornocomentario.innerHTML = resultado;

				nomeComment.value       ='';
				emailComment.value      ='';
				comentarioComment.value ='';
			}
		}

		var params = "nome="+escape(nome)+"&email="+email+"&comentario="+escape(comentario)+"&ip="+ip+"&idsonho="+idsonho;
		//prompt('',params);
		ajax.send(params);		
	}
}


function openAjax(){
	var ajax;
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex){
			try	{
				ajax = new XMLHttpRequest();
			}
			catch(exc){
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = false;
			}
		}
	}
	return ajax;
}
