//Variação do tamanho da fonte nas páginas
function fonte(action)
{
	if(action=="+") fontSize+=5;
	else if(action=="-") fontSize-=5;
	else if(action=="=") fontSize=100;
	$("#main").attr("style","font-size:"+fontSize+"%");
	return false;	
}
//habilita e desabilita opção do mural
function habMural()
{
	if($('#cred').val()==""){$('#mural').removeAttr('checked');$('#mural').attr('disabled','disabled');}
	else{$('#mural').removeAttr('disabled');$('#mural').attr('checked','checked');}
}
//mostra foto ampliada
function showFoto(fotoId,vertical)
{
	var width = 650;
	var height = 630;
	var div  = "#dialog";
	if(vertical)
	{
		width = 490;
		height = 790;
		div+="V";
	}
	var path="/m1/foto.php?id="+fotoId;
	//Esconde a publicidade 
	$("#publ").hide();
	$(div).html('<div style="text-align:center;margin-top:25%"><img src="/img/loading_big.gif" alt="Carregando..."/><br/>Aguarde, carregando...</div>');
	$(div).dialog({ modal:true, width:width, height:height, overlay:{opacity: 0.6,background: "black"}, 
		buttons:{"Fechar":function(){$(this).dialog("close"); /*Mostra publicidade*/ $("#publ").show();}}});
	$(div).load(path);
	$(div).dialog("open");
}
//valida qtd de caracteres em textarea
function checkLength(id,limit)
{
	var txt = $("#"+id).val();
	txt=txt.substr(0,limit);
	$("#"+id).val(txt);
	return limit-txt.length;
}
//Checa submit do formulário de contato
function submitContato()
{
	if($("#nome").val()=="") return "O campo \"Seu Nome\" é obrigatório e não foi preenchido.";
	if($("#email").val()=="") return "O campo \"Seu Email\" é obrigatório e não foi preenchido";
	if(!checkMail($("#email").val())) return "O e-mail informado não parece ser válido. Por favor, informe um e-mail válido.";
	if($("#msg").val()=="") return "O campo \"Mensagem\" é obrigatório e não foi preenchido";
	if($("#msg").val().length>256) return "O campo \"Mensagem\" tem mais caracteres que o limite estabelecido.";
}
//Validação de E-mail
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;
    }
}
//carrega comentário
function loadComentarios(id,location)
{
	$("#comentarios #list").html('<div style="text-align:center;"><img src="/img/loading_big.gif" alt="Carregando..."/><br/>Aguarde, carregando comentários...</div>');
	$("#comentarios #list").load("/comentario.php?action=list&id="+id, function(){if(location) window.location = location;});
}
function addComentario(id)
{
	$("#btncmt").attr("disabled","disabled");
	$(".cm").hide();
	var ok = true;
	var nome = $("#nome").val();
	if(nome==""){ alert("Informe seu nome."); ok=false; }
	var cmt = $("#comentario").val();
	if(cmt==""){ alert("Digite seu comentário."); ok=false; }
	if(cmt.length>2048){alert("Seu comentário possui "+cmt.length+" caracteres. Por favor, reduza-o para o limite de 2048 caracteres."); ok=false;}
	var notify = $("#nt").get(0).checked;
	var email = $("#email").val();
	if(notify)
	{
		if(email==""){ alert("Informe seu e-mail para receber notificações ou desabilite a opção de recebê-las."); ok=false;}
		if(ok){ if(!checkMail(email)){alert("O e-mail informado não parece ser válido. Por favor, digite-o corretamente."); ok=false;} }
	}
	
	if(ok)
	{
		$("#cmld").show();
		$.post("/comentario.php?action=add",{"nome":nome,"comentario":cmt,"id":id,"email":email,"notify":notify},function(rs){ $("#cmld").hide(); if(rs==1){ $("#cmok").show(); loadComentarios(id,"#lastcmt");  $('#comentario').val("");}else{ $("#cmer").show(); } $("#btncmt").removeAttr("disabled"); });
	}else $("#btncmt").removeAttr("disabled");
	return false;
}
//remover foto do mural
function rmfoto(id)
{
	if(!confirm("Você tem certeza que não quer que sua foto seja mostrada no mural?")) return false;
	$.get("/rmphoto.php",{"id":id},function(rs){ if(rs==1){ alert("Sua foto foi removida do mural."); }else{ alert("Você não tem permissão para executar esta ação."); }});
	return false;
}
//Valida placa
function valPlaca(pl)
{
	var er = new RegExp(/^[A-Za-z]{3}-[0-9]{4}?/);
	return er.test(pl);
}
//Pega o texto selecionado
function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
	return txt;
}