$(function() {
    // VALIDACAO DE FORMULARIOS
    $("#formCadastro").validationEngine();

    showHideFaq();

    // BUSCA DE FAQ
    $("#fldBuscaFaq").keyup(function(){
        if ($(this).val().length > 3){
            query = $(this).val();

            $.ajax({
                url: $("#fldRootPath2").val() + "/ajax/faq/"+ query +"/",
                cache: true,
                success: function(html){
                    $("#faq_conteudo").html(html);
                    showHideFaq();
                }
            });
        }
        else {
            query = 'NULL';
        }
    });

    // SELEÇÃO DE PASTA NO ENVIO DE ARQUIVOS
    $("select.selectFolder").change(function(){
        if ($(this).val() > 0){
            $("#novaPasta").css('display','none');
        }
        else {
            $("#novaPasta").css('display','block');
        }
    });

    // PLACEHOLDER
    $(".placeholder").focus(function(){
    if ($(this).attr('title') == $(this).attr('value')){
    	$(this).attr('value','');
    }
    }).blur(function(){
	if ($(this).attr('value') == ''){
		$(this).attr('value',$(this).attr('title'));
	}
    });

    // POINTER NOS BOTOES
    $('input[type|=submit]').css('cursor','pointer');
    $('input[type|=button]').css('cursor','pointer');

    // MENSAGENS
    $("#destinatarios .destino").click(function(){
        if ($(this).css('background-color') == 'rgb(245, 245, 245)'){
            $(this).addClass('on');
        }
        else {
            $(this).removeClass('on');
        }
        selDestinos();
    })

    $("#linkFechar").click(function(){
        $("#destinatarios").css('display','none');
        return (false);
    })

    //$("#fldDestinos").focus(function(){
    //    $("#destinatarios").css('display','block');
    //})
    $("#linkAbrir").focus(function(){
        $("#destinatarios").css('display','block');
        return (false);
    })

});

function validaSenha(root_path){
    if ($('#fldEmail').val() != ''){
        document.location = root_path + "/login/index/" + $('#fldEmail').val() + "/";
    }
    else {
        alert('Preencha o campo E-mail.');
        return (false);
    }
}

function selDestinos(){
    emails = '';
    separador = '';

    $("#destinatarios .destino").each(function(){
        if ($(this).css('background-color') != 'rgb(245, 245, 245)'){
            emails = emails + separador + $(this).attr('rel');
            separador = ';';
        }
    });

    $("#fldDestinos").val(emails);
}

function showHideFaq(){
    $("div.faq-min").click(function(){
        obj = $(this).find("div.resposta");

	if (obj.css('display') == 'none'){
		$(this).find("div.ico").html("<p>-</p>");
		obj.slideDown("slow");
		return (false);
	}
	else {
		$(this).find("div.ico").html("<p>+</p>");
		obj.slideUp("slow");
		return (false);
	}

    }).mouseover(function(){
	$(this).css('cursor','pointer');
    });
}
