var www = "http://www.ginasticshop.com.br/";
$(document).ready(function(){

//	$('.enviarsenha').click(function() {
//		var novasenha = $('input[name=password]').val();
//		if(novasenha == ''){
//			call ('.gerasenha').click();
//		}
//		return false;
//	});


	 $('input[name=email]').blur(function() {

		$('#retornoemail').html('Aguarde, verificando se email já existe ...');
		
		email = $('input[name=email]').val();
		id = $('input[name=id_registro]').val();
		endereco = '/admin/gestor/verificaExisteEmail/'+id+'/'+email;

		if(email == ''){
			$('#retornoemail').html('Informe e-mail corretamente!');
		}else{
			$.get(endereco, function(dados){
				if(dados == 0){
					$('#retornoemail').html('E-mail verificado!');
				}else{
					$('#retornoemail').html("<b><font color='red'>E-mail já existe, informe outro e-mail!</font></b>");
				}

			});
		}
      //return false;
    });


    $(".ok").click(function() {
	  $('input[name=enviaemail]').val('0');
      $(this).parent().submit();
      return false;
    });



	$(".okEnvia").click(function() {
		$('input[name=enviaemail]').val('1');
      $(this).parent().submit();
      return false;
    });
//    $(".enviasenha").click(function() {
//       //var id = $(this).attr('title');
//	   var pass = $('nome').val;
//	   alert('/admin/gestor/enviasenha/'+pass);
//       //if(id != 0){
//       //    $.getJSON('/admin/gestor/enviasenha/'+id+'/'+pass, function(data){
//        //       alert(data.msg);
//         //  });
//        //}else{
//        //    alert('Você precisa salvar antes de enviar a senha.');
//        //}
//
//        return false;
//    });
    $(".logar").click(function(){
        var href = $(this).attr('href');
        var user = $('input[name=username]').val();
        var pass = $('input[name=password]').val();
        if((user != '') && (pass !='')){
            $.post( href, {username : user, password : pass},function(data){
                if(data.logado == false){
                    alert(data.msg);
                }else{
                    window.location = www + data.url;
                }
            },"json");
        }else{
            alert('Preencha corretamente os campos de Login e Senha.');
        }

        return false;
    });
    $(".gerasenha").click(function() {
      $.get("/admin/gestor/gerasenha", function(data){
          $('.senhagerada').html("A senha gerada é: " + data);
		  // Transfere password
          $('input[name=password]').val(data);
		  // Exibe botão para salvar e enviar senha
		  $('input[name=enviaemail]').val('1');
		  $('#salvaEnvia').show();
      });
      return false;
    });
    $("input[name=pessoa]").click(function(){
        var tipo = $(this).val();
        if(tipo == "pf"){
            window.location = www + 'admin/gestor/addclienteF';
        }else{
            window.location = www + 'admin/gestor/addclienteJ';
        }
    });
    $(".apagar").click(function(){
        if(confirm('Deseja realmente apagar esse cliente?')){
            var href = this.href ;
            $.get(href, function(data){
                    alert(data);
                    window.location = www + 'admin/gestor/atualizarcliente';
            });
        }
        return false;
    });
    $(".apagarup").click(function(){
        if(confirm('Deseja realmente apagar esse arquivo?')){
            var href = this.href ;
            var title = $(this).attr('title');
            $.get(href, function(data){
                    alert(data);
                    window.location = www + 'admin/gestor/upload/' + title;
            });
        }
        return false;
    });
    $(".emailup").click(function(){
        var href = this.href ;
        $.get(href, function(data){
                alert(data);
        });
        return false;
    });
    $(".apagarsel").click(function(){
        var ids = '';
        if(confirm('Deseja realmente apagar os cliente(s) selecionado(s)?')){
            $(".listar tr td input[type=checkbox]").each(function() {
                if(this.checked){
                    ids = ids + this.value + ',';
                }
            });
            $.get(www + 'admin/gestor/delClientes/' + ids, function(data){
                alert(data);
                window.location = www + 'admin/gestor/atualizarcliente';
            });
        }
        return false;
    });
     $(".exportar").click(function(){
        var ids = '';
        $(".listar tr td input[type=checkbox]").each(function() {
            if(this.checked){
                ids = ids + this.value + ',';
            }
        });
        if(ids != ''){
            window.location = '/admin/gestor/exportar/' + ids;
        }else{
            alert('Selecione os clientes para exportar.')
        }
        return false;
    });
    $('.selecionar').click(function() {
		if(this.checked == true){
			$(".listar tr td input[type=checkbox]").each(function() {
				this.checked = true;
			});
		} else {
			$(".listar tr td input[type=checkbox]").each(function() {
				this.checked = false;
			});
		}
	});

    $(".editar").parent().parent().hover(function(){
        $(this).addClass('escuro_hover');
    },function(){
        $(this).removeClass('escuro_hover');
        });

    
    $(".listar tr:odd").addClass('escuro');
   $("input[type=text]").addClass("inputs-selects");

});

