// JavaScript Document 

function getId(id)
{
	return document.getElementById(id);
}

function mostraId(id)
{
	$("#"+id).show("fast");
}

function escondeId(id)
{
	$("#"+id).hide("fast");
}

function mostraEscondeId(id)
{
	if(getId(id).style.display=='none')
	{
		$("#"+id).show("fast");
	}
	else
	{
		$("#"+id).hide("fast");
	}
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
			if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){
									return true;
							}
	}else{
			return false;
			}
}

function enviaContato()
{
	var nome = document.getElementById('nome');
	var email = document.getElementById('email');
	//var telefone = document.getElementById('telefone');
	var cidade = document.getElementById('cidade');
	//var assunto = document.getElementById('assunto');
	var mensagem = document.getElementById('mensagem');
	
	if(nome.value=='')
	{
		alert("Verifique o campo 'Nome'.");
		nome.focus();
		return false;
	}
	if(!checkMail(email.value))
	{
		alert("Verifique seu 'Email'.");
		email.focus();
		return false;
	}
	/*if(telefone.value == ''){
		alert("Preencha seu telefone");
		telefone.focus();
		return false;
	}*/
	if(cidade.value==''){
		alert("Preencha sua cidade");
		cidade.focus();
		return false;
	}
	/*if(assunto.value=='')
	{
		alert("Preencha o campo 'Assunto'.");
		assunto.focus();
		return false;
	}*/
	if(mensagem.value=='')
	{
		alert("Preencha o campo com sua mensagem.");
		mensagem.focus();
		return false;
	}
	
	mostraId('enviando');
	xajax_enviaContato(nome.value, email.value, '', cidade.value, '', mensagem.value);
	//xajax_enviaContato(nome.value, email.value, telefone.value, '', assunto.value, mensagem.value);
}

function limpaCampoContato()
{
	document.getElementById('nome').value='';
	document.getElementById('email').value='';
	//document.getElementById('telefone').value='';
	document.getElementById('cidade').value='';
	//document.getElementById('assunto').value='';
	document.getElementById('mensagem').value='';
	
	setTimeout("escondeId('enviando');", 3000);
	mostraId('sucesso');
	setTimeout("escondeId('sucesso');", 3000);
}

function resete(){
	setTimeout(function(){
		document.getElementById('newMsg').innerHTML = 'Receba not&iacute;cias e novidades';
		document.getElementById('newMsg').style.color = '#000';
	}, 3000);
}

function txtNews(texto, cor, limpa){
		var txt = document.getElementById('newMsg');
		var email = document.getElementById('emailNews');
		txt.style.color = cor;
		txt.innerHTML = texto;
		if(limpa){
			email.value='Digite seu e-mail';
		}
}

function cadastraEmail(){
	var email = document.getElementById('emailNews');
	if(!checkMail(email.value)){
		txtNews("Verifique seu e-mail.", "#F00");
	}else{
		xajax_cadastraNewsletter(email.value);
	}
	resete();
}

function verificaEmail(email){
	xajax_verificaEmail(email.value);
}

function cadastroUsuarios(){
	var i=0;
	$('.erroCampo').removeClass('erroCampo');
	if($('#nome').val()==''){
		$('#nome').addClass('erroCampo');
		i=1;
	}
	if(!checkMail($('#email').val())){
		$('#email').addClass('erroCampo');
		i=1;
	}
	if($('#senha').val()==''){
		$('#senha').addClass('erroCampo');
		i=1;
	}
	if($('#repsenha').val()==''){
		$('#repsenha').addClass('erroCampo');
		i=1;
	}
	if( $('#repsenha').val() != $('#senha').val() ){
		$('#senha').addClass('erroCampo');
		$('#repsenha').addClass('erroCampo');
		i=1;
	}
	if($('#cidade').val()==''){
		$('#cidade').addClass('erroCampo');
		i=1;
	}
	if(i){
		mostraId('error');
	}else{
		escondeId('error');
		mostraId('enviando');
		xajax_cadastraCliente('', $('#nome').val(), $('#email').val(), $('#senha').val(), '', '', '', '', '', '', $('#telefone').val(), $('#cidade').val(), '');
	}
}

function limpaCadastroUsuario(){
	$('#nome').val('');
	$('#email').val('');
	$('#senha').val('');
	$('#repsenha').val('');
	$('#telefone').val('');
	$('#cidade').val('');
	escondeId('enviando');
	mostraId('sucesso');
	setTimeout("escondeId('sucesso');", 5000);
}

function limpaCampoEmail(){
	$('#email').val('');
}

function logaUsuario(){
	var email = $('#login_email');
	var senha = $('#login_senha');
	if(email.val()==''||senha.val()==''){
		alert("Preencha os campos login e senha para logar");
	}
	if(email.val()==''){
		email.focus();
		return false;
	}
	if(senha.val()==''){
		senha.focus();
		return false;
	}
	xajax_logaUsuario(email.val(),senha.val());
}

function logout(){
	xajax_logout();
}

function participaPromo(id_promocao){
	var condicao = document.getElementById('condicao');
	var resposta = $('#resposta');
	if(resposta.val()==''){
		alert("Preencha o campo com sua resposta");
		return false;
	}
	if(!condicao.checked){
		alert("Para participar da promocao, voce deve concordar com os termos");
		return false;
	}
	xajax_participaPromo( id_promocao , resposta.val() );
}

function alteraResposta(id_participante){
	var resposta = $('#alteraResp');
	if(resposta.val()==''){
		alert("Preencha o campo com sua resposta");
		return false;
	}
	xajax_alteraResposta( id_participante , resposta.val() );
}

function enviaComentarioNoticia(id_noticia){
	var condicao = document.getElementById('condicao');
	var comentario = $('#comentario');
	if(comentario.val()==''){
		alert("Preencha o campo com seu comentario");
		comentario.focus();
		return false;
	}
	if(!condicao.checked){
		alert("Para comentar noticias voce deve concordar com os termos");
		return false;
	}
	xajax_enviaComentarioNoticia( id_noticia , comentario.val() );
}

function votaEnquete(name){
	var radios = document.getElementsByName(name);
	var len = radios.length;
	for(i=0 ; i<len ; i++){
		if(radios[i].checked){
			var valor = radios[i].value;
		}
	}
	if(!valor){
		alert("Selecione uma opcao");
	}else{
		xajax_votaEnquete(valor);
	}
}

function enviaPedido(){
	var musica = $('#pedidoMusica');
	var artista = $('#pedidoArtista');
	var nome = $('#pedidoNome');
	var email = $('#pedidoEmail');
	var cidade = $('#pedidoCidade');
	if(musica.val()=='' || artista.val()=='' || nome.val()=='' || email.val()=='' || cidade.val()=='' || musica.val()=='Musica' || artista.val()=='Artista' || nome.val()=='Seu nome' || email.val()=='Seu email' || cidade.val()=='Cidade'){
		alert("Preencha todos os campos");
		return false;
	}
	document.getElementById("pedidoEnvia").disabled = true;
	xajax_enviaPedido(musica.val(), artista.val(), nome.val(), email.val(), cidade.val());
}

function enviaRecado(){
	var nome = $('#recadoNome');
	var email = $('#recadoEmail');
	var cidade = $('#recadoCidade');
	var recado = $('#msgRecado');
	if(nome.val()=='' || email.val()=='' || cidade.val()=='' || recado.val()=='' || nome.val()=='Seu nome' || email.val()=='Seu email' || cidade.val()=='Cidade' || recado.val()=='Recado'){
		alert("Preencha todos os campos");
		return false;
	}
	document.getElementById("recadoEnvia").disabled = true;
	xajax_enviaRecado(nome.val(), email.val(), cidade.val(), recado.val());
}
