data = new Date();
ano = String(data.getFullYear());
mes = String(data.getMonth());
dia = String(data.getDate());
hora = String(data.getHours());
minutos = String(data.getMinutes());
segundos = String(data.getSeconds());
milisegundos = String(data.getMilliseconds());
pasta = ano+mes+dia+hora+minutos+segundos+milisegundos;
var qtd = 16;
function add_imagem(){
	$("#add_imagem1").append('<label for="imagem">Imagem '+qtd+': </label><input type="file" name="fotos_agitos[]"/><br/>');	
	qtd++;
}
function enviando_email(){
	$("#alterar_senha").fadeOut("normal");
	$("#resposta_ajax").show();
	$("#resposta_ajax").fadeIn("normal");
	$("#resposta_ajax").html("Enviando E-mail...");
}
function enviando_recado(){
	$("#form_recado").fadeOut("normal");
	$("#resposta_recado").show();
	$("#resposta_recado").html("Enviando recado...");
}
function resposta_recado(data){
	$("#resposta_recado").html(data);
	$("#load_recado").fadeOut('normal');
	$("#load_recado").load('view_recado.php');
	$("#load_recado").fadeIn('normal');
	view_pontos();
}
function view_pontos(){
	$("#pontos_usuario").load('get_pontos.php');
}
function novo_recado(){
	$("#resposta_recado").hide();
	$("#form_recado").fadeIn("normal");
}
function resposta(data){
	$("#resposta_ajax").html(data);
}
function tentar_novamente_email(){
	$("#alterar_senha").fadeIn("normal");
	$("#resposta_ajax").fadeOut("normal");
}
function tentar_novamente(){
	$("#alterar_senha").fadeIn("normal");
	$("#resposta_ajax").hide();
}
function ver_foto(id){
	$('#ver_foto').dialog('open');
	$('#ver_foto').html("Carregando...");
	$('#ver_foto').load('ver_foto_ampliada.php?id='+id);
	return false;
}
function add_comentario_foto(id){
	$('#add_comentario_foto').dialog('open');
	$('#form_comentario_foto').removeClass('hide');
	$('#form_add_comentario_foto').append('<input type="hidden" name="idfoto" value="'+id+'"/>');
}
function enviando_comentario_foto(){
	$('#form_comentario_foto').fadeOut('normal');	
	$('#resposta_add_comentario_foto').fadeIn('normal');
	$('#resposta_add_comentario_foto').html('Enviando...');
	//$('#comentario_foto').fadeOut('normal');	
	//$('#comentario_foto').load();
}
function resposta_comentario_foto(data){
	$('#resposta_add_comentario_foto').html(data);
}
function enviar_outro_comentario_foto(id){
	$('#resposta_add_comentario_foto').fadeOut('normal');
	$('#form_comentario_foto').fadeIn('normal');
	$('#form_add_comentario_foto').append('<input type="hidden" name="idfoto" value="'+id+'"/>');
}
function enviando_login(){
	$('#resposta_login').html('Autenticando...');	
}
function resposta_login(data){
	if(data == "Apelido ou Senha incorretos."){	
		$('#resposta_login').html(data);
	}else{
		window.location.href = data;	
	}
}
function enviando_evento(){
	$('#form_evento').fadeOut('normal');
	$('#resposta_evento').html('Publicando...');	
}
function resposta_evento(data){
	if(data != "Erro ao tentar cadastrar evento.&nbsp;<a onclick='enviar_outro_evento()'>Tentar novamente.</a>"){
		$('#form_add_evento').clearForm();
	}
	$('#resposta_evento').html(data);
	window.location.reload();
}
function enviar_outro_evento(){
	$('#resposta_evento').fadeOut('normal');
	$('#form_evento').fadeIn('normal');
}
function ver_agenda(id){
	$('#ver_agenda').fadeOut('normal');
	$('#ver_agenda').fadeIn('normal');
	$('#ver_agenda').load('ver_agenda.php?id='+id);
}
function alterar_senha(){
	$('#alterar_senha2').dialog('open');	
	$('#alterar_senha2').classRemove('hide');	
}
function excluir_cadastro(){
	$('#excluir_cadastro').dialog('open');
	$('#excluir_cadastro').removeClass('hide');
}
function cadastrando_usuario(){
	$('#resposta_cadastro').dialog("open");
	$('#resposta_cadastro').html("Cadastrando...");
}
function resposta_cadastro(data){
	if(data == "Cadastrado realizado com sucesso! Fa&ccedil;a sua identifica&ccedil;&atilde;o na &aacute;rea vip." || data == "Cadastro alterado com sucesso."){
		$('#form_cadastro').clearForm(true);
	}
	$('#resposta_cadastro').html(data);
	if(data == "Cadastro alterado com sucesso."){
		window.location.reload();	
	}
}
function alterando_senha(){
	$('#form_alterar_senha2').fadeOut('normal');
	$('#resposta_alterar_senha').html('Alterando Senha...');
}
function resposta_alterar_senha(data){
	$('#resposta_alterar_senha').html(data);
}
function excluindo_cadastro(){
	$('#form_excluir_cadastro').fadeOut('normal');
	$('#resposta_excluir_cadastro').html('Excluindo cadastro...');
}
function resposta_excluir_cadastro(data){
	$('#resposta_excluir_cadastro').html(data);
}
function add_foto(){
	$('#add_foto').dialog('open');
	$('#add_foto').removeClass('hide');
}
function adicionando_foto(){
	$('#form_mural_fotos').fadeOut('normal');	
	$('#resposta_add_foto').html("Enviando foto...");
}
function resposta_mural_foto(data){
	$('#resposta_add_foto').html(data);
	view_pontos();
	window.location.reload();	
}
function add_comentario_foto_mural(id){
	$('#add_comentario_foto_mural').dialog('open');
	$('#form_add_comentario_foto_mural').append('<input type="hidden" name="idfoto" value="'+id+'"/>');
}
function enviando_comentario_foto_mural(){
	$('#form_add_comentario_foto_mural').fadeOut('normal');	
	$('#resposta_add_comentario_foto_mural').fadeIn('normal');
	$('#resposta_add_comentario_foto_mural').html('Enviando...');
}
function resposta_comentario_foto_mural(data){
	$('#resposta_add_comentario_foto_mural').html(data);
	window.location.reload();	
}
function enviar_outro_comentario_foto_mural(id){
	$('#resposta_add_comentario_foto_mural').fadeOut('normal');
	$('#form_add_comentario_foto_mural').fadeIn('normal');
	$('#form_add_comentario_foto_mural').append('<input type="hidden" name="idfoto" value="'+id+'"/>');
}
function add_recado(){
	$('#deixe_seu_recado').dialog('open');
	$('#deixe_seu_recado').removeClass('hide');
}
function enviando_recados(){
	$("#form_recados").fadeOut("normal");
	$("#resposta_add_recado").show();
	$("#resposta_add_recado").html("Enviando recado...");
}
function resposta_recados(data){
	$("#resposta_add_recado").html(data);
	view_pontos();
	window.location.reload();	
	//$("#load_recado").fadeOut('normal');
	//$("#load_recado").load('view_recado.php');
	//$("#load_recado").fadeIn('normal');
}
function novo_recado_mural(){
	$('#resposta_add_recado').fadeOut('normal');	
	$('#form_recados').fadeIn('normal');
}
function show_addvideo(){
	$('#mural_video').dialog('open');
	$('#mural_video').removeClass('hide');
}
function publicando_video(){
	$('#form_video_galera').fadeOut('normal');
	$('#resposta_add_video').fadeIn('normal');
	$('#resposta_add_video').html("Publicando...");
}
function resposta_video(data){
	$('#resposta_add_video').html(data);
	window.location.reload();
}
function novo_video(){
	$('#resposta_add_video').fadeOut('normal');
	$('#form_video_galera').fadeIn('normal');
	$('#nome').clearFields();
	$('#codigo').clearFields();
	
}
function tentar_novo_video(){
	$('#resposta_add_video').fadeOut('normal');
	$('#form_video_galera').fadeIn('normal');
	$('#nome').clearFields();
	$('#codigo').clearFields();
	
}
function show_sugerir_tema(){
	$('#sugerir_tema').dialog('open');
	$('#sugerir_tema').removeClass('hide');
}
function sugerindo_tema(){
	$('#form_tema').fadeOut('normal');
	$('#resposta_tema').fadeIn('normal');	
	$('#resposta_tema').html('Sugerindo tema...');	
}
function resposta_tema(data){
	$('#resposta_tema').html(data);
}
function novo_tema(){
	$('#form_tema').fadeIn('normal');
	$('#resposta_tema').fadeOut('normal');	
	$('#titulo').clearFields();
	$('#tema').clearFields();
}
function tentar_novo_tema(){
	$('#form_tema').fadeIn('normal');
	$('#resposta_tema').fadeOut('normal');	
}
function show_comentario(id){
	$('#deixe_comentario').dialog('open');
	$('#form_add_comentario').append('<input type="hidden" id="idfalaaitema" name="idfalaaitema" value="'+id+'"/>');
}
function comentando_tema(){
	$('#form_add_comentario').fadeOut('normal');
	$('#resposta_comentario_tema').html('Enviando comentário');
}
function resposta_comentario_tema(data){
	$('#resposta_comentario_tema').html(data);
	window.location.reload();
}
function open_comentario_tema(id){
	$('#load_comentario_tema').dialog('open');	
	$('#load_comentario_tema').load('ver_comentario_falaai.php?id='+id);
}
function show_nosagitos(){
	//$('#publique_agito').dialog('open');
	window.open("form_nosagitos.php","Nos Agitos",'width=375,height=400,toolbar=no,scrollbars=auto,status=no,resizable=no,scrolling=no');
	$('#form_nosagitos').append('<input type="hidden" name="codigo" value="'+pasta+'"/>');
}

function publicando_nosagitos(){
	$('#form_nosagitos').fadeOut('normal');
	$('#resposta_nosagitos').html("Publicando...");
}
function resposta_nosagitos(data){
	$('#resposta_nosagitos').html(data);
	//window.location.reload(5);		
}
$(document).ready(function() {
		$('input.data').mask("99/99/9999");
		$('input.telefone').mask("(99) 9999-9999");
		$('input.cep').mask("99.999-999");
		var options = { 
			//target:        '#conteudo_box',   // target element(s) to be updated with server response 
			beforeSubmit:  enviando_email,  // pre-submit callback 
			success:       resposta // post-submit callback  
			// other available options: 
			//url:       url         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
		   // clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
	    };
		var opt_recado = {
			beforeSubmit:  enviando_recado, 
			success:       resposta_recado,
			clearForm: true
		};
		var opt_recados = {
			beforeSubmit:  enviando_recados, 
			success:       resposta_recados,
			clearForm: true
		};
		var opt_comentario_foto = {
			beforeSubmit:  enviando_comentario_foto, 
			success:       resposta_comentario_foto,
			clearForm: true	
		};
		var opt_comentario_foto_mural = {
			beforeSubmit:  enviando_comentario_foto_mural, 
			success:       resposta_comentario_foto_mural,
			clearForm: true	
		};
		var opt_login = {
			beforeSubmit:  enviando_login, 
			success:       resposta_login,
			clearForm: true	
		};
		var opt_add_evento = {
			beforeSubmit:  enviando_evento, 
			success:       resposta_evento,
		};
		var opt_cadastro = {
			beforeSubmit:  cadastrando_usuario, 
			success:       resposta_cadastro,
			clearForm: false	
		};
		var opt_alterar_senha = {
			beforeSubmit:  alterando_senha, 
			success:       resposta_alterar_senha,
			clearForm: false	
		};
		var opt_excluir_cadastro = {
			beforeSubmit:  excluindo_cadastro, 
			success:       resposta_excluir_cadastro,
			clearForm: false	
		};
		var opt_mural_fotos = {
			beforeSubmit:  adicionando_foto, 
			success:       resposta_mural_foto,
			clearForm: false	
		};
		var opt_video_galera = {
			beforeSubmit:  publicando_video, 
			success:       resposta_video,
			clearForm: false	
		};
		var opt_tema = {
			beforeSubmit:  sugerindo_tema, 
			success:       resposta_tema,
			clearForm: false	
		};
		var opt_add_comentario = {
			beforeSubmit:  comentando_tema, 
			success:       resposta_comentario_tema,
			clearForm: true	
		};
		var opt_nosagitos = {
			beforeSubmit:  publicando_nosagitos, 
			success:       resposta_nosagitos,
			clearForm: true	
		};
		$("#load_recado").load('view_recado.php');
		$('#error').hide();
		$('#form_login').validate({
			errorLabelContainer: ('#form_login span.error'),
			submitHandler: function(){
				$("#form_login").ajaxSubmit(opt_login);
			}
		});
		$('#form_fale').validate();
		$('#form_cadastro').validate({
			submitHandler: function(){
				$("#form_cadastro").ajaxSubmit(opt_cadastro);
			} 
		});
		$('#form_add_comentario').validate({
			submitHandler: function(){
				$("#form_add_comentario").ajaxSubmit(opt_add_comentario);
			} 
		});
		$('#form_cadastro').validate({
			submitHandler: function(){
				$("#form_cadastro").ajaxSubmit(opt_cadastro);
			} 
		});
		$('#form_tema').validate({
			submitHandler: function(){
				$("#form_tema").ajaxSubmit(opt_tema);
			} 
		});
		$('#form_video_galera').validate({
			submitHandler: function(){
				$("#form_video_galera").ajaxSubmit(opt_video_galera);
			} 
		});
		$('#form_nosagitos').validate({
			submitHandler: function(){
				$("#form_nosagitos").ajaxSubmit(opt_nosagitos);
			} 
		});
		$('#form_mural_fotos').validate({
			submitHandler: function(){
				$("#form_mural_fotos").ajaxSubmit(opt_mural_fotos);
			} 
		});
		$('#form_recados').validate({
			submitHandler: function(){
				$("#form_recados").ajaxSubmit(opt_recados);
			} 
		});
		$('#form_alterar_senha2').validate({
			submitHandler: function(){
				$("#form_alterar_senha2").ajaxSubmit(opt_alterar_senha);
			}
		});
		$('#form_excluir_cadastro').validate({
			submitHandler: function(){
				$("#form_excluir_cadastro").ajaxSubmit(opt_excluir_cadastro);
			}
		});
		$('#form_add_comentario_foto').validate({
			submitHandler: function(){
				$("#form_add_comentario_foto").ajaxSubmit(opt_comentario_foto);
			}
		});
		$('#form_add_comentario_foto_mural').validate({
			submitHandler: function(){
				$("#form_add_comentario_foto_mural").ajaxSubmit(opt_comentario_foto_mural);
			}
		});
		$('#form_add_evento').validate({
			submitHandler: function(){
				$("#form_add_evento").ajaxSubmit(opt_add_evento);
			}
		});
		$('#form_alterar_senha').validate({
			submitHandler: function(){
				$("#form_alterar_senha").ajaxSubmit(options);
			}
		});
		$('#form_enviar_recado').validate({
			submitHandler: function(){
				$("#form_enviar_recado").ajaxSubmit(opt_recado);
			}
		});
		$('#apelido_usuario').click(function(){
			$(this).attr('value', '');
		});
		$('#senha_usuario').click(function(){
			$(this).attr('value', '');
		});
	});
	$(function(){

		 $('a.remote').click( function(){
		 	if ($(this).attr('title') == "Principal"){
				$("#destaque").fadeIn("normal");
			}else{
				$("#destaque").fadeOut("normal");
			}
		 });
		$('#esqueci_senha').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}	
		});
		$('#resposta_cadastro').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		/*$('#publique_agito').dialog({
			autoOpen: false,
			width: 500,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});*/
		$('#load_comentario_tema').dialog({
			autoOpen: false,
			width: 450,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#deixe_comentario').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#sugerir_tema').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#mural_video').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#deixe_seu_recado').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#add_foto').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#add_comentario_foto_mural').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
		});
		$('#alterar_senha2').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}	
		});
		$('#excluir_cadastro').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}	
		});
		$('#add_evento').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}	
		});
		$('#add_evento_link').click(function(){
			$('#add_evento').dialog('open');
			$('#add_evento').removeClass('hide');
			return false;
		});
		$('#alterar_senha_link').click(function(){
			$('#esqueci_senha').dialog('open');
			$('#alterar_senha').removeClass('hide');
		});
		$('#enviar_recado').dialog({
			autoOpen: false,
			width: 300,
			position: 'center',
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}
			
		});
		$('#enviar_recado_link').click(function(){
			$('#enviar_recado').dialog('open');
			$('#form_recado').removeClass('hide');
			return false;
		});
		$('#ver_foto').dialog({
			autoOpen: false,
			width: 620,
			heigth: 600,
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				} 
			}
		});
		$('#add_comentario_foto').dialog({
			autoOpen: false,
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				} 
			}
		});
	});