﻿//---------------------------------------------------
// 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.br/Port/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 ##########
// O que eu vi que não era impotante eu deletei ou comentei, caso apareça
// algum xabu, basta descomentar o que não for comentário :)

function TagItByID(id, tag, opcao, textasopcao) {
    var clientPC = navigator.userAgent.toLowerCase();
    var clientVer = parseInt(navigator.appVersion);
    var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
    var is_nav = ((clientPC.indexOf('firefox') != -1) && (clientPC.indexOf('mozilla') != -1) && (clientPC.indexOf('spoofer') == -1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera') == -1) && (clientPC.indexOf('webtv') == -1) && (clientPC.indexOf('hotjava') == -1));
    var is_moz = 0;
    var is_win = ((clientPC.indexOf("win") != -1) || (clientPC.indexOf("16bit") != -1));
    var is_mac = (clientPC.indexOf("mac") != -1);
    var seltext;
    var selit;
    var mode_moz = 0;
    var subtagini = "";
    var subtagfim = "";
    var input = document.getElementById(id);

    if (window.getSelection) {
        seltext = window.getSelection;
        selit = window.getSelection;
    }
    else if (document.getSelection) {
        seltext = document.getSelection();
        selit = document.getSelection();
    }

    if (tag == "Link") {
        subtagini = "[link=http://www.]";
        subtagfim = "[/link]";
    }

    if ((clientVer >= 4) && is_ie && is_win) {
        seltext = (document.all) ? document.selection.createRange() : document.getSelection();
        selit = (document.all) ? document.selection.createRange().text : document.getSelection();
    }
    else {
        if (input.selectionEnd && (input.selectionEnd - input.selectionStart > 0)) mode_moz = 1;
    }
    if ((mode_moz == 1) && (is_moz == 0)) is_moz = 1;

    if (selit.length >= 1) {
        if (seltext) {
            if (textasopcao) opcao = seltext.text;
            if (tag == "*") {
                if (mode_moz == 0) seltext.text = "[*]" + seltext.text;
                if (mode_moz == 1) mozWrap(input, "[*]", "");
            }
            else {
                if (opcao == "") {
                    if (mode_moz == 0) seltext.text = "[" + tag + "]" + seltext.text + "[/" + tag + "]";
                    if (mode_moz == 1) mozWrap(input, "[" + tag + "]" + subtagini, subtagfim + "[/" + tag + "]");
                }
                else {
                    if (mode_moz == 0) seltext.text = "[" + tag + "=" + opcao + "]" + seltext.text + "[/" + tag + "]";
                    if (mode_moz == 1) mozWrap(input, "[" + tag + "=" + opcao + "]", "[/" + tag + "]");
                }
            }
        }
//        setCaretToEnd(input);
    }
    else {
        if (tag == "*") {
            if (mode_moz == 0) input.value = input.value + "[*]";
            if (mode_moz == 1) mozWrap(input, "[*]", "");
        }
        else {
            if (opcao == "") {                
                if (mode_moz == 0) input.value = input.value + "[" + tag + "]" + subtagini + "   " + subtagfim + "[/" + tag + "]";
                if (mode_moz == 1) mozWrap(input, "[" + tag + "]" + subtagini, subtagfim + "[/" + tag + "]");
            }
            else {
                if (mode_moz == 0) input.value = input.value + "[" + tag + "=" + opcao + "]  [/" + tag + "]";
                if (mode_moz == 1) mozWrap(input, "[" + tag + "=" + opcao + "]", "[/" + tag + "]");
            }
        }
        setCaretToPos(input, input.value.length - tag.length - 4);
    }
//    input.focus();
}

//function setCaretToEnd(input) {
//    setSelectionRange(input, input.value.length, input.value.length);
//}

function setCaretToBegin(input) {
    setSelectionRange(input, 0, 0);
}

function setCaretToPos(input, pos) {
    setSelectionRange(input, pos, pos);
}

function setSelectionRange(input, selectionStart, selectionEnd) {
    if (input.setSelectionRange) {
        input.focus();
        input.setSelectionRange(selectionStart, selectionEnd);
    }
    else if (input.createTextRange) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveEnd('character', selectionEnd);
        range.moveStart('character', selectionStart);
        range.select();
    }
}


