var Usuario = {
	type:'POST',
	url: '/ajax/ajax-usuario.php',
	global:false,
	ERRO_LOGIN_VAZIO:'Informe seu login.',
	ERRO_LOGIN_INVALIDO:'Login inv&aacute;lido.',
	ERRO_LOGIN_EXISTE:'Login j&aacute; existente.',
	ERRO_EMAIL_VAZIO:'Informe seu e-mail.',
	ERRO_EMAIL_EXISTE:'E-mail j&aacute; existente.',
	ERRO_EMAIL2_VAZIO:'Confirma�� de email vazia.',
	ERRO_EMAIL_INVALIDO:'E-mail inv&aacute;lido.',
	ERRO_EMAIL2_DIFERENTE:'Confirma&ccedil;&atilde;o de e-mail diferente.',
	ERRO_SENHA_VAZIA:'Informe sua senha.',
	ERRO_SENHA2_VAZIA:'Confirma&ccedil;&aring;o de senha vazia.',
	ERRO_SENHA2_DIFERENTE:'Senhas diferentes.',
	ERRO_SENHA_INVALIDA:'Senha Inv�lida.',
	ERRO_TERMO:'O Termo tem que ser aceito.',
	ERRO_NOME_VAZIO:'Informe seu nome.',
	ERRO_NASC_INVALIDO:'Data de Nascimento inv&aacute;lido.',
	ERRO_NASC_VAZIO:'Informe sua data de nascimento.',
	ERRO_SEXO_INVALIDO:'Sexo inv&aacute;lido.',
	ERRO_BAIRRO_INVALIDO:'Bairro inv&aacute;lido.',
	ERRO_CIDADE_INVALIDO:'Cidade inv&aacute;lida.',
	ERRO_ESTADO_INVALIDO:'Estado inv&aacute;lido.',
	ERRO_PAIS_INVALIDO:'Pais inv&aacute;lido.',
	ERRO_CAPTCHA_VAZIO:'Imagem de valida vazia.',
	ERRO_CAPTCHA_ERRADO:'Imagem de validao errada.',
	novoUsuario: function(){
		var data = $("form").serialize();
		$.ajax({
			type:this.type,
			url:this.url,
			global:this.global,
			data:"acao=1&"+data,
                        beforeSend:function(){
                            var eregEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                            var eregLogin = /^[a-zA-Z_]+[a-zA-Z_0-9]+$/;

                            var dataNasc = "";
                            var msg = "";

                            var dia = $("#campo-diaNasc").val();
                            var mes = $("#campo-mesNasc").val();
                            var ano = $("#campo-anoNasc").val();

                            if( isEmpty($("#campo-login-cadastro").val()) ){
                                msg += "<p>"+this.ERRO_LOGIN_VAZIO+"<p>";
                            }else if( !$("#campo-login-cadastro").val().match(eregLogin) ){
                                msg += "<p>"+this.ERRO_LOGIN_INVALIDO+"</p>";
                            }

                            if(isEmpty($("#campo-senha-cadastro").val())){
                                msg += "<p>"+this.ERRO_SENHA_VAZIA+"</p>";
                            }
                            if(isEmpty($("#campo-senha2-cadastro").val())){
                                msg += "<p>"+this.ERRO_SENHA2_VAZIA+"</p>";
                            }
                            if($("#campo-senha-cadastro").val() != $("#campo-senha2-cadastro").val()){
                                msg += "<p>"+this.ERRO_SENHA2_DIFERENTE+"</p>";
                            }
                            if(isEmpty($("#campo-nome").val())){
                                msg += "<p>"+this.ERRO_NOME_VAZIO+"</p>";
                            }
                            if(isEmpty($("#campo-email").val()) ){
                                msg += "<p>"+this.ERRO_EMAIL_VAZIO+"</p>";
                            }else if(!$("#campo-email").val().match(eregEmail)){
                                msg += "<p>"+this.ERRO_EMAIL_INVALIDO+"</p>";
                            }
                            if(!$("#campo-termo").attr("checked")){
                                msg += "<p>"+this.ERRO_TERMO+"</p>";
                            }
                            if(isEmpty($("#combo-pais").val()) || $("#combo-pais").val() == 0){
                                 msg += "<p>"+this.ERRO_PAIS_INVALIDO+"</p>";
                            }
                            if(isEmpty($("#combo-estado").val()) || $("#combo-estado").val() == 0){
                                 msg += "<p>"+this.ERRO_ESTADO_INVALIDO+"</p>";
                            }
                            if(isEmpty($("#combo-cidade").val()) || $("#combo-cidade").val() == 0){
                                 msg += "<p>"+this.ERRO_CIDADE_INVALIDO+"</p>";
                            }
                            if((!isEmpty(dia) && !isEmpty(mes) && !isEmpty(ano))){
                                dataNasc = dia+"/"+mes+"/"+ano;
                                if(!validaData(dataNasc) || isEmpty(dataNasc)){
                                    msg += "<p>"+this.ERRO_NASC_INVALIDO+"</p>";
                                }
                            }else{
                                msg += "<p>"+this.ERRO_NASC_VAZIO+"</p>";
                            }
                            if(!isEmpty(msg)){
                                $("#box-erro").html(msg);
                                setTimeout('$("#campos-vazios").fadeIn()',400);
                                setTimeout('$("#box-erro").fadeIn()',400);
                                setTimeout('$("#box-erro").fadeOut()',5000);
                                setTimeout('$("#campos-vazios").fadeOut()',5000);
                                return false;
                            }else{
                                return true;
                            }
                        },
			success:function(response){
				if(response == "1" ){
					var varEndeavor = $("#s").val();
					if(varEndeavor == "") {
						window.location.href='/user';
					} else {
						window.location.href='/user/publicar.php';
					}
				}else{
					$("#box-erro").html(response);
					setTimeout('$("#box-erro").fadeIn()',400);
				}
			}
		})
	},
	novaAtivacao: function(){
		var data = $("form").serialize();
		$.ajax({
			type:this.type,
			url:this.url,
			global:this.global,
			data:"acao=6&"+data,
                        beforeSend:function(){
                            var eregEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                            var eregLogin = /^[a-zA-Z_]+[a-zA-Z_0-9]+$/;

                            var msg = "";

                            if( isEmpty($("#campo-login-cadastro").val()) ){
                                msg += "<p>"+this.ERRO_LOGIN_VAZIO+"<p>";
                            }else if( !$("#campo-login-cadastro").val().match(eregLogin) ){
                                msg += "<p>"+this.ERRO_LOGIN_INVALIDO+"</p>";
                            }

                            if(isEmpty($("#campo-senha-cadastro").val())){
                                msg += "<p>"+this.ERRO_SENHA_VAZIA+"</p>";
                            }

                            if(isEmpty($("#campo-email").val()) ){
                                msg += "<p>"+this.ERRO_EMAIL_VAZIO+"</p>";
                            }else if(!$("#campo-email").val().match(eregEmail)){
                                msg += "<p>"+this.ERRO_EMAIL_INVALIDO+"</p>";
                            }

                            if(!isEmpty(msg)){
                                $("#box-erro").html(msg);
                                setTimeout('$("#box-erro").fadeIn()',400)
                                return false;
                            }else{
                                return true;
                            }
                        },
			success:function(response){
				if(response == "1" ){
					setTimeout('$("#box-sucesso").fadeIn()',400);
				}else{
					$("#box-erro").html(response);
					setTimeout('$("#box-erro").fadeIn()',400);
				}
			}
		});
	},
	telaLogin: function(divShow,divHide){
		$("#"+divHide+"").fadeOut();
		$("#"+divShow+"").fadeIn(4000);
	},
	loginBox: function(login,senha,source){
		var valorLogin  = $("#"+login+"").val();
		var valorSenha  = $("#"+senha+"").val();
		var valorSource = $("#"+source+"").val();
		var msg    = "";		
		if(isEmpty(valorLogin)){
			msg += "- Informe seu Login.\n"
		}
		if(isEmpty(valorSenha)){
			msg += "- Informe sua Senha.\n"
		}		
		if(msg != ""){
			alert(msg);
		}else{
			$.ajax({
				type:this.type,
				url:this.url,
				global:this.global,
				data:"acao=2&login="+valorLogin+"&senha="+valorSenha,
				success:function(response){
					if(response == "1" ){
						window.location.href = valorSource;
					}else{
						resposta = new String(response);
						/*$("#barra-load").addClass("off");
						$("#lista-formulario").removeClass("off");
						$("#lista-formulario").addClass("on");*/
						if(resposta.match("Login Inv&aacute;lido.") != null){
							alert(resposta);
							$(".bloco-login .item-submenu").addClass("selecionado");
							$(".bloco-login .item-submenu form").show();
							$("#"+login+"").focus();
							/*$("#"+login+"").removeClass("campo-texto");
							$("#"+login+"").addClass("campo-texto-erro");
							setTimeout('$("#'+login+'").removeClass("campo-texto-erro")',400);
							$("#"+login+"").addClass("campo-texto");
							$("#"+login+"").focus();*/
						}else if(resposta.match("Senha incorreta") != null){
							alert(resposta);
							$(".bloco-login .item-submenu").addClass("selecionado");
							$(".bloco-login .item-submenu form").show();
							/*$("#"+senha+"").removeClass("campo-texto");
							$("#"+senha+"").addClass("campo-texto-erro");*/
						}
					}
				},
				beforeSend:function(){
					/*$("#lista-formulario").addClass("off");
					$("#barra-load").removeClass("off");
					$("#barra-load").addClass("on");*/
				}
			});
		}	
	},
	logout: function( pagina ){
		$.ajax({
			type:this.type,
			url:this.url,
			global:this.global,
			data:"acao=3",
			success:function(response){
				if(response == "1" ){
					window.location.href = pagina;
				}
			}
		});
	},
	verificarLogin: function(login){		
		var valorLogin = $("#"+login+"").val();
		if(!isEmpty(valorLogin)){
			$.ajax({
				type:this.type,
				url:this.url,
				global:this.global,
				data:"acao=4&login="+valorLogin,
				success:function(response){
					if(response == "1" ){
						$("#"+login+"").removeClass("campo-texto-ok");
						$("#"+login+"").addClass("campo-texto-erro");
						$("#msg-login").html("Login cadastrado.");
						$("#msg-login").show();
						setTimeout('$("#campos-vazios").fadeIn()',400);
						setTimeout('$("#campos-vazios").fadeOut();',2000);
					}else{
						$("#msg-login").hide();
						$("#"+login+"").removeClass("campo-texto-erro");
						$("#"+login+"").addClass("campo-texto-ok");	
					}
				}
			});
		}		
	},
	verificarEmail: function(email){
		var valorEmail = $("#"+email+"").val();
		if(!isEmpty(valorEmail)){
			$.ajax({
				type:this.type,
				url:this.url,
				global:this.global,
				data:"acao=5&email="+valorEmail,
				success:function(response){
					if(response != "0" ){
						$("#"+email+"").removeClass("campo-texto-ok");
						$("#"+email+"").addClass("campo-texto-erro");
						if(response == "1"){
							$("#msg-email").html("Email cadastrado.");
						}
						if(response == "2"){
							$("#msg-email").html("Email informado inexistente.");
						}
						setTimeout('$("#msg-email").fadeIn()',400);
						setTimeout('$("#msg-email").fadeOut()',2000);
					}else{
						$("#"+email+"").addClass("campo-texto-ok");
					}
				}
			});
		}
	},
	listagemVideos:function(idUsuario,idUsuarioLogado,tipo,pagina,parceiro){
		$.ajax({
			type:this.type,
			url:'/ajax/ajax-video-usuario.php',
			data:'id-usuario='+idUsuario+'&logado='+idUsuarioLogado+'&tipo='+tipo+'&pagina='+pagina+'&parceiro='+parceiro,
			success:function(response){
				if(response != "0"){										
					$("#box-ajax-lista-thumb-peq").empty();
					$("#box-ajax-lista-thumb-peq").html(response);
					$("#box-loading-ajax-videos").addClass("off");
				}
			},
			beforeSend:function(){
				$("#box-loading-ajax-videos").removeClass("off");
			}
		}); 		
	},
	videoInicial:function(idUsuario,tipo){
		$.ajax({
			type:this.type,
			url:"/ajax/assitir-video.php",
			data:"id-usuario="+idUsuario+"&tipo="+tipo,
			success:function(response){
				$("#video-usuario-topo-infos").html(response);
				$.scrollTo("#vdl-geral",800);
			}				
		});
	},
	notificacaoPublicacao:function(){
		$.ajax({
			type:this.type,
			url:"/ajax/ajax-usuario.php",
			data:"acao=7",
			success:function(response){
				if(response == 1){
					$.jGrowl("O seu v&iacute;deo enviado est&aacute; sendo convertido e ser&aacute; publicado em breve",
					{ sticky: true ,
					  beforeClose: function(e,m){
										$.ajax({
											type:'GET',
											url:"../ajax/ajax-usuario.php",
											data:"acao=8"
										});
    							   }
					});
				}
			}
		});
	}
}

$(document).ready(function(){	
	$("#box-usuario-video-selecionado .botao-fechar").click ( function() {
			$("#box-usuario-video-selecionado").removeClass("on");
			$("#box-usuario-video-selecionado").addClass("off");
			$("#box-flash-video-selecionado").html("");
			$("#box-dados-video-selecionado").html("");
			$.scrollTo("#vdl-geral",800);
			return false;
		}
	);
	$("#box-grupo-video-selecionado .botao-fechar").click ( function() {
			$("#box-grupo-video-selecionado").removeClass("on");
			$("#box-grupo-video-selecionado").addClass("off");
			$("#box-flash-video-selecionado").html("");
			$("#box-dados-video-selecionado").html("");
			$.scrollTo("#vdl-geral",800);
			return false;
		}
	);	
	Usuario.notificacaoPublicacao();
});

