﻿//---------------------------------------------------
// Biblioteca de funções JavaScript
//---------------------------------------------------
// Autor: Motta - 03/08/2009
// 

//---------------------------------------------------
// Esta função abre uma mensagem de confirmação
// Para usar no botão excluir :
// cmdExcluir.Attributes.Add("OnClick", "return Confirma('Tem certeza que deseja excluir ?')")
function Confirma(Msg) {
    var vConfirmacao;
    vConfirmacao = window.confirm(Msg);
    return vConfirmacao;
}


//---------------------------------------------------
// Esta função abre o formulário para enviar
// a página a um conhecido
function enviar() {
    window.open("http://www.auesolucoes.com/pt-br/enviarpagina.aspx?url=" + document.URL, "", "resizable = no, width = 550, height = 300");
    window.location = document.URL;
}

//---------------------------------------------------
// Esta função imprime a página corrente
function imprimir() {
    self.print();
}

//---------------------------------------------------
// Esta função coloca a data de hoje na página
function Hoje() {
    now = new Date();
    day = new Object();
    month = new Object();
    day[0] = "Domingo";
    day[1] = "Segunda-feira";
    day[2] = "Terça-feira";
    day[3] = "Quarta-feira";
    day[4] = "Quinta-feira";
    day[5] = "Sexta-feira";
    day[6] = "Sábado";
    month[0] = "Janeiro";
    month[1] = "Fefereiro";
    month[2] = "Março";
    month[3] = "Abril";
    month[4] = "Maio";
    month[5] = "Junho";
    month[6] = "Julho";
    month[7] = "Agosto";
    month[8] = "Setembro";
    month[9] = "Outubro";
    month[10] = "Novembro";
    month[11] = "Dezembro";
    year = now.getYear();
    if (year < 1000) year += 1900;
    document.write(day[now.getDay()] + ", " + now.getDate() + " de " + month[now.getMonth()] + " de " + year);
}

//---------------------------------------------------
// Esta função abre uma janela tipo pop-up com
// uma URL passada como parâmetro
function showAs(URL) {
    window.open(URL, "AuESolucoes", "width=800,height=350,scrollbars=yes");
    return false;
}

//---------------------------------------------------
// Esta função esconde um elemento pelo Id
function mHide(id) {
    document.getElementById(id).style.display = 'none';
}

//---------------------------------------------------
// Esta função apresenta um elemento pelo id
function mShow(id) {
    document.getElementById(id).style.display = '';
}

//---------------------------------------------------
// Esta função faz o browser navegar para outro
// endereço
function mClick(url) {
    window.location = url;
}

//---------------------------------------------------
// Esta função altera a cor de fundo do objeto 
function mOvr(Obj, Cor) {
    Obj.bgColor = Cor;
}


// Funções do cronômetro
// Variáveis globais
var hrs = 0;
var mins = 0;
var segs = 0;
var timer;

function textReplace(vlu, id) {
    document.getElementById(id).value = vlu;
}

function cronoStart() {
    segs++;
    if (segs == 60) {
        mins++;
        segs = 0;
        if (mins == 60) {
            hrs++;
            mins = 0;
        }
    }

    var formSegs = (segs < 10) ? "0" + segs : segs;
    var formMins = (mins < 10) ? "0" + mins : mins;
    var formHrs = (hrs < 10) ? "0" + hrs : hrs;

    textReplace(formHrs + ":" + formMins + ":" + formSegs, "crono");
    timer = window.setTimeout("cronoStart();", 1000);
}

//########## Tags do Fórum ##########


/* As partes acima vieram do VBMania, são boas porque tem funções para identificar
o OS e o navegador, mas estava dando alguns xabus, mudei e adaptei a função para ficar
mais simples...
*/

function TagIt(Obj, tagAntes, tagApos) {
    /* var input = $(Obj); */
    var input = document.getElementById(Obj);
    input.focus();

    /* para Internet Explorer */
    if (typeof document.selection != 'undefined') {
        /* seleção */
        var range = document.selection.createRange();
        var insText = range.text;
        range.text = tagAntes + insText + tagApos;

        /* Cursorposition anpassen */
        range = document.selection.createRange();
        if (insText.length == 0) {
            range.move('character', -tagApos.length);
        } else {
            range.moveStart('character', tagAntes.length + insText.length + tagApos.length);
        }
        range.select();
    }

    /* para o Mozzila */
    else if (typeof input.selectionStart != 'undefined') {
        /* Seleção */
        var start = input.selectionStart;
        var end = input.selectionEnd;
        var insText = input.value.substring(start, end);
        input.value = input.value.substr(0, start) + tagAntes + insText + tagApos + input.value.substr(end);

        /* Cursorposition anpassen */
        var pos;
        if (insText.length == 0) {
            pos = start + tagAntes.length;
        } else {
            pos = start + tagAntes.length + insText.length + tagApos.length;
        }
        input.selectionStart = pos;
        input.selectionEnd = pos;
    }

}

function TagItByID(Obj, tag) {

    var seltext = "";

    seltext = (document.all) ? document.selection.createRange() : document.getSelection();

    if (seltext.text == "") {
        if (tag == "Link") {
            document.getElementById(Obj).value += "[link=http://www.]" + "[/link]";
        } else {
            document.getElementById(Obj).value += "[" + tag + "]" + "[/" + tag + "]";
        }
    }
    else {
        if (tag == "Link") {
            seltext.text = "[link=" + seltext.text + "]" + seltext.text + "[/link]";
        } else {
            seltext.text = "[" + tag + "]" + seltext.text + "[/" + tag + "]";
        }
    }

    document.getElementById(Obj).focus();

}

/* Função que verifica se o text do Obj passado é diferente de vazio.
Se for vazio, não será executado o procedimento definido no evento OnClick do botão. */
function VerificaCaixa(Obj) {
    var campo = Obj;
    campo.value = campo.value.trim();
    //Obj.value = Obj.value.trim();
    if (campo.value != "") return true;
    return false;
}
