//writed by Marcio Vinicius Brandao
//feb, 17 2009


function byMail(id, tipo){
		
		
		var myform = document.getElementById("send-news");
		var myname = myform.nome.value;
		var mydestin = myform.destinatario.value;
		var myemail = myform.email.value;
		var resposta = document.getElementById("resposta");
		


			//xmlHttp
			var xmlHttp = new http_request();
			var url = "libs/php/ajax.php?cmd=bymail&nome="+myname+"&destinatario="+mydestin+"&email="+myemail+"&id="+id+"&t="+tipo;
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		
			xmlHttp.onreadystatechange = function(){


				if(xmlHttp.readyState == 4){
						
							if(xmlHttp.status == 200){
								
								resultados = xmlHttp.responseText;
								
								if(resultados==1){
									
								ok(myname+',<br/>a not&iacute;cia foi enviada para '+mydestin+'<br/> com sucesso!');
								
								}else{
									
									ok('Falha no servidor smtp!!!');
								}
							}else{
								
								//resposta.innerHTML = "Erro 404! P&aacute;gina no encontrada ...";


						}


					
		}

	}

		return(false);
	
}




function cadastrar(){


		var logform = document.getElementById("form-coment");
		var lognome = logform.nome;
		var logpass = logform.mensagem.value;

		var resposta = document.getElementById("resposta-cad");		
		var myform = document.getElementById("form-cadastrar");
		var myname = myform.nome.value;
		var myemail = myform.email.value;
		var mypass = myform.senha.value;
		var mycpass = myform.csenha.value;

		if(myname==""){
			
			myform.nome.style.border="1px solid #cc0000";
			return(false);
		}else{
			myform.nome.style.border="1px solid #00cc00";
			
		}
	
	
		if(myemail==""){
			
			myform.email.style.border="1px solid #cc0000";
			return(false);
		}else{
			myform.email.style.border="1px solid #00cc00";
			
		}
	

	
		if(mypass==""){
			
			myform.senha.style.border="1px solid #cc0000";
			return(false);
		}else{
			myform.senha.style.border="1px solid #00cc00";
			
		}
	

	
		if(mycpass==""){
			
			myform.csenha.style.border="1px solid #cc0000";
			return(false);
		}else{
			myform.csenha.style.border="1px solid #00cc00";
			
		}
		
		if(mypass != mycpass){
			myform.csenha.style.border="1px solid #cc0000";
			myform.senha.style.border="1px solid #cc0000";
			return(false);
		}else{
			myform.csenha.style.border="1px solid #00cc00";
			myform.senha.style.border="1px solid #00cc00";
			
		}
	
			//xmlHttp
			var xmlHttp = new http_request();
			var url = "libs/php/ajax.php?cmd=cadastrar&nome="+myname+"&email="+myemail+"&senha="+mypass;
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		
			xmlHttp.onreadystatechange = function(){


				if(xmlHttp.readyState == 4){
						
							if(xmlHttp.status == 200){
								
								resultados = xmlHttp.responseText;
								
								if(resultados==1){
									
									$(document).ready(function(){ 
									
										$("#cadastro").slideUp("fast");  $("#comentario").slideDown("fast"); $("#tools").fadeOut("fast");
										lognome.value = myname;	
									
									}); 
								
								}else if (resultados == 3){

										resposta.innerHTML = "<br/>O e-mail informado j&aacute; est&aacute; cadastrado! Eu enviei pra voc&ecirc; um e-mail lembrado sua senha.";
										
								}else{
								
										resposta.innerHTML = "<br/>Houve uma falha na tentativa do seu cadastro!.<br/> Tente mais tarde!"; 								
								}
								
							}else{
								
								//resposta.innerHTML = "Erro 404! P&aacute;gina no encontrada ...";


						}


					
		}

	}

		return(false);
	
}






function logar(){
		
		
		var logform = document.getElementById("form-coment");
		var lognome = logform.nome;
		var logpass = logform.mensagem.value;
		

		var myform = document.getElementById("form-log");
		var myemail = myform.email.value;
		var mypass = myform.senha.value;
		var resposta = document.getElementById("resposta-log");

			//xmlHttp
			var xmlHttp = new http_request();
			var url = "libs/php/ajax.php?cmd=login&email="+myemail+"&senha="+mypass;
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		
			xmlHttp.onreadystatechange = function(){


				if(xmlHttp.readyState == 4){
						
							if(xmlHttp.status == 200){
								
								resultados = xmlHttp.responseText;
								//resposta.innerHTML =  resultados;
								
								if(resultados!=2){
									
									$(document).ready(function(){
															   
											$("#login").slideUp("fast"); 
											$("#comentario").slideDown("fast"); 
											$("#tools").fadeOut("fast");
									
									});
									
									lognome.value = resultados;
								
								}else{
									
									resposta.innerHTML = "Login Incorreto!!"
									myform.email.style.border = "1px solid #cc0000";
									myform.senha.style.border = "1px solid #cc0000";

								}
								
							}else{
								
								//resposta.innerHTML = "Erro 404! P&aacute;gina no encontrada ...";


						}


					
		}

	}

		return(false);
	
}





function comentar(id,tipo){
		
		var resposta = document.getElementById("resposta-com");
		var comentario; 
		var logform = document.getElementById("form-coment");
		var lognome = logform.nome.value;
		var logmensagem = logform.mensagem.value;
		
		
		if(lognome==""){
			
			logform.nome.style.border="1px solid #cc0000";
			return(false);
		}else{
			logform.nome.style.border="1px solid #00cc00";
			
		}
	
	
		if(logmensagem==""){
			logform.mensagem.style.border="1px solid #cc0000";
			return(false);
		}else{
			logform.mensagem.style.border="1px solid #00cc00";
		}
	
	
			//xmlHttp
			var xmlHttp = new http_request();
			var url = "libs/php/ajax.php?cmd=comentar&nome="+lognome+"&comentario="+logmensagem+"&id="+id+"&tipo="+tipo;
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		
			xmlHttp.onreadystatechange = function(){


				if(xmlHttp.readyState == 4){
						
							if(xmlHttp.status == 200){
								
								resultados = xmlHttp.responseText;
								//resposta.innerHTML =  resultados;
								
								if(resultados=="1"){
										
								comentatario ='<p>';
								comentatario +='<span style="color:#959595; font-size:10px; margin-bottom:5px;"><strong>1 min atrás</strong> - Por: <strong>'+lognome+'</strong></span><br />';
								comentatario += logmensagem;
								comentatario +='<p style="background:#ffcccc; text-align:center;">Seu coment&aacute;rio ser&aacute; aprovado antes de ser publicado!</p>';
								comentatario +='</p>';
	
								
									 $(document).ready(function(){ 
																
										$("#seecoments").html(comentatario).effect("highlight", {}, 1000);
										$("#nocoments").fadeOut("fast");
										$("#comentario").slideUp("fast");
										
									 });
								
								}else if(resultados=="3"){
								
									 resposta.innerHTML = "Essa mesma mensagem ja foi enviada por voc&ecirc;. Spans não serão bem sucedidos neste site!";
									 
								}else{
								
									 resposta.innerHTML = "Falha ao inserir coment&aacute;rio. Tente mais tarde!";
								
								}
							}else{
								
								//resposta.innerHTML = "Erro 404! P&aacute;gina no encontrada ...";


						}


					
		}

	}

		return(false);
	
}


