/*  * JAVASCRIPT FUNCOES BASICAS * Ojeto contendo as infomações do browser e plataforma */var is = {    ie:      navigator.appName.indexOf('Microsoft Internet Explorer') >= 0,    java:    navigator.javaEnabled(),    ns:      navigator.appName.indexOf('Netscape') >= 0,    ua:      navigator.userAgent.toLowerCase(),    version: parseFloat(navigator.appVersion.substr(21)) || parseFloat(navigator.appVersion),    win:     navigator.platform.indexOf('Win32') >= 0,    winCE:   navigator.platform.indexOf('Windows CE') >= 0}is.mac = is.ua.indexOf('mac') >= 0;if (is.ua.indexOf('opera') >= 0) {    is.ie = is.ns = false;    is.opera = true;}if (is.ua.indexOf('gecko') >= 0) {    is.ie = is.ns = false;    is.gecko = true;}/*  * getElementIndex(input_object) *  * Pass an input object, returns index in form.elements[] for the object *  * Returns -1 if error *  */function getElementIndex(obj) {    var theform = obj.form;    for (var i=0; i < theform.elements.length; i++) {        if (obj.name == theform.elements[i].name) {            return i;        }    }    return -1;}//-------------------------------------------------------------------// goto next filed if key <Enter> pressed// tabNext(field, event)//   Pass an form input object. Will focus() the next field in the form//   after the passed element.//   a) Will not focus to hidden or disabled fields//   b) If end of form is reached, it will loop to beginning//   c) If it loops through and reaches the original field again without//      finding a valid field to focus, it stops//  <input type="text" name="T2" onKeyDown="tabNext(this, event)">// -------------------------------------------------------------------// Author: Matt Kruse <matt@mattkruse.com>// WWW: http://www.mattkruse.com/// -------------------------------------------------------------------function tabNext(field, event, idNextField) {     // idNextField (opcional)    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {        if (navigator.platform.toUpperCase().indexOf("SUNOS") != -1) {            obj.blur();            return; // Sun's onFocus() is messed up        }        if(idNextField) {            var nField = document.getElementById(idNextField);            nField.focus();            if(nField.type && nField.type != "select-one" && nField.type != "button")                nField.select();            return;        }        var theform = field.form;        var i = getElementIndex(field);        var j = i+1;        if (i == -1) {            return;        }        while (j != i) {            if (j >= theform.elements.length){                j = 0;             }            if ((theform.elements[j].type!="hidden") && ( theform.elements[j].name != theform.elements[i].name) && (! theform.elements[j].disabled) && (theform.elements[j].tabIndex >= 0)) {                if (theform.elements[j].type == "select-one") {                    theform.elements[j].focus();                } else if (theform.elements[j].type == "button") {                    theform.elements[j].focus();                } else {                    theform.elements[j].focus();                    theform.elements[j].select();                }                return false;                break;            }            j++;        }    }    return true;}function autoTab(element,destination){    if (element.getAttribute && element.value.length == element.getAttribute("maxlength")) {        if(destination) {            var nField = document.getElementById(destination);            nField.focus();            if(nField.type && nField.type != "select-one" && nField.type != "button")                nField.select();            return;        }    }        //destination.focus()}//-------------------------------------------------------------------// isIEBrowser()//   verifica se eh o browser MSIE//   Returns boolean//-------------------------------------------------------------------function isIEBrowser(){    if (navigator.appName.indexOf("Microsoft")!=-1) {        return true;    } else {        return false;    }} //-------------------------------------------------------------------// isFirefox()//   verifica se eh o browser FireFox//   Returns boolean//-------------------------------------------------------------------function isFirefox(){    if (navigator.appName == "Netscape") {        return true;    } else {        return false;    }} //-------------------------------------------------------------------// isOpera()//   verifica se eh o browser Opera//   Returns boolean//-------------------------------------------------------------------function isOpera(){    if (is.opera) {        return true;    } else {        return false;    }} //-------------------------------------------------------------------// isWinCE()//   verifica se esta rodando o browser no windows ce//   Returns boolean//-------------------------------------------------------------------function isWinCE(){    if (is.winCE) {        return true;    } else {        return false;    }} //-------------------------------------------------------------------// getX()//   busca a posicao X do elemento//   Returns int//-------------------------------------------------------------------function getX(objName) {    var curleft = 0;    var obj = document.getElementById(objName);    if (obj.offsetParent)    {        while (obj.offsetParent)        {            curleft += obj.offsetLeft            obj = obj.offsetParent;        }    }    else if (obj.x)        curleft += obj.x;    return curleft;}//-------------------------------------------------------------------// getY()//   busca a posicao Y do elemento//   Returns int//-------------------------------------------------------------------function getY(objName) {    var curtop = 0;    var obj = document.getElementById(objName);    if (obj.offsetParent)    {        while (obj.offsetParent)        {            curtop += obj.offsetTop            obj = obj.offsetParent;        }    }    else if (obj.y)        curtop += obj.y;    return curtop;}//-------------------------------------------------------------------// getWindowHeight//   busca a altura da janela//   Return int//-------------------------------------------------------------------function getWindowHeight() {    var result = 0;    if (isFirefox()) {        result = window.innerHeight-16;    } else if (isIEBrowser()) {        result = document.body.offsetHeight-20;    }    return result;}//-------------------------------------------------------------------// getWindowWidth//   busca a largura da janela//   Return int//-------------------------------------------------------------------function getWindowWidth() {    var result = 0;    if (isFirefox()) {        result = window.innerWidth-16;    } else if (isIEBrowser()) {        result = document.body.offsetWidth-20;    }    return result;}//-------------------------------------------------------------------// getElementHeight(element)//   retirna a altura de um elemento//-------------------------------------------------------------------function getElementHeight(Elem) {    var elem;    if (document.getElementById) {        elem = document.getElementById(Elem);    } else if (document.all){        elem = document.all[Elem];    }    return elem.offsetHeight; }//-------------------------------------------------------------------// getElementWidth(element)//   retirna a altura de um elemento//-------------------------------------------------------------------function getElementWidth(Elem) {    if(document.getElementById) {        var elem = document.getElementById(Elem);    } else if (document.all){        var elem = document.all[Elem];    }    return elem.offsetWidth; }//-------------------------------------------------------------------// escaspe(key_event)//   verifica se o usuario precionou o ESC para fechar a tela//-------------------------------------------------------------------function escape(event){    if ((event.which && event.which == 27)        ||  (event.keyCode && event.keyCode == 27)) {        window.close();    }    return;}//-------------------------------------------------------------------// isescape(key_event)//   verifica se o usuario precionou o ESC//-------------------------------------------------------------------function isescape(event){    if ((event.which && event.which == 27)        ||  (event.keyCode && event.keyCode == 27)) {        return true;    }    return false;}//-------------------------------------------------------------------// round(number, decimal)//   faz o round com n casas decimais// number valor a ser aredondado// decimal n de casas decimais//-------------------------------------------------------------------function round(number, decimal) {    var newnumber = Math.round(number*Math.pow(10,decimal))/Math.pow(10,decimal);    return newnumber;}//-------------------------------------------------------------------// trunc(number, decimal)//   faz o trunc com n casas decimais// number valor a ser truncado// decimal n de casas decimais//-------------------------------------------------------------------function trunc(number, decimal) {    var newNumber =  Math.floor(number*Math.pow(10,decimal))/Math.pow(10,decimal);    return newNumber;}//-------------------------------------------------------------------// Parsea a data// @param String com data no formato ##/##/####//-------------------------------------------------------------------function parseDate(data){    var result = true;    if (data) {        var elems = data.split("/");        if (elems.length == 3)	{            var day = elems[0];            var month = elems[1];            var year = elems[2];			            result = ! isNaN(elems[0]) && (month > 0) && (month < 13) &&            ! isNaN(elems[1]) && (day > 0) && (day < 32) &&            ! isNaN(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));            if (! result) {                alert('Formato da data invalido! '+day+'/'+month+'/'+year);            }            var data = new Date();            data.setYear(year);            data.setMonth(month -1);            data.setDate(day);            return data;        } else {            alert('Formato da data valido!');        }    } else return new Date();}//-------------------------------------------------------------------// Intercepta a tecla e nao deixa retornar ao form// @param key-event//-------------------------------------------------------------------function interceptkey(event) {    if (event) {        if (isIEBrowser()){            event = window.event; // for IE            event.keyCode = 0;            event.returnValue = false;					        }    }    return false;}// Funcoes de janelasvar index = 0;var winModal;//-------------------------------------------------------------------// Mostra uma janela//-------------------------------------------------------------------function showModalWindow(titulo, x, y, w, h, showEffect, hideEffect) {    winModal = new Window('modal'+index, {        title: titulo,        left: parseInt(x),        top: parseInt(y),        width:  parseInt(w),         height:  parseInt(h),        resizable: true,         showEffect: showEffect,        hideEffect: hideEffect    });}function doCloseModal() {    if (winModal) {        Windows.close(winModal.getId());    }}//-------------------------------------------------------------------// Mostra a janela "Processando..."//-------------------------------------------------------------------function processando() {    showModalWindow("Processando...", 0, 0, 200, 80, Effect.BlindDown, Effect.BlindUp);    winModal.showCenter(true);    winModal.getContent().innerHTML = "<table style=\"background-color: white; FONT-SIZE: 12px; FONT-FAMILY: tahoma,sans-serif\" border=\"0\">" +"<tr>" +"<td><b><img alt=\"\" src=\"../img/indicator.gif\" />Processando, aguarde...</b></td>" +"</tr>" +"</table>";}//-------------------------------------------------------------------// Seta o stylesheet ativo//-------------------------------------------------------------------function setActiveStyleSheet(title) {    var i, a, main;    for(i=0;(a=document.getElementsByTagName("link")[i]);i++) {        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {            a.disabled = true;            if(a.getAttribute("title") == title) {                a.disabled = false;            }        }    }}/* cria uma window e posiciona no centro */function windowCenter(url, nome, atribs) {    var heightA = new RegExp("height\\s*=\\s*(\\d+)", "i").exec(atribs);    var widthA = new RegExp("width\\s*=\\s*(\\d+)", "i").exec(atribs);    if(heightA && widthA) {        var top = parseInt((screen.height - parseInt(heightA[1]) - 30) / 2);        var left = parseInt((screen.width - parseInt(widthA[1])) / 2);        atribs += ",top=" + top + ",left=" + left;    }    // cria window    return window.open(url, nome, atribs);}/* retorna o primeiro form do documento */function getFrm() {    return document.forms[0];}/* retorna o elemento conforme o id informado */function byId(id) {    return document.getElementById(id);}/* centraliza o componente na janela corrente *//* centraliza o componente na janela corrente */function centerComponent(comp) {    centerComponent(comp, 0, 0);}function centerComponent(comp, minX, minY) {    var posX = (getWindowWidth() - comp.offsetWidth) / 2;    var posY = (getWindowHeight() - comp.offsetHeight) / 2;    comp.style.left = (minX > posX ? minX : posX) + 'px';    comp.style.top =  (minY > posY ? minY : posY) + 'px';}/* abre uma popup com a mensagem, solicitando que seja selecionado algum botão */function selectDialog(msg, arrayBotoes, permiteEsc, fnNomeCallBack, atribs) {    var win = windowCenter('', '_blank', atribs);    var d = win.document;    d.writeln("<html><body " + (permiteEsc ? "onkeypress='escape(event);'" : "") + ">");    d.writeln("<SCRIPT type='text/javascript'>");    d.writeln("function escape(event) { ");    d.writeln("if((event.which && event.which == 27) || (event.keyCode && event.keyCode == 27)) { ");    d.writeln("window.opener." + fnNomeCallBack + "(''); window.close();");    d.writeln("}");    d.writeln("}");    d.writeln("</SCRIPT>");    d.writeln('<center><table width=90%><tr><th nowrap>' + msg + "</th></tr>");    d.writeln('<tr><td></td></tr>');    d.writeln('<tr><td nowrap align=right>');    for(var i = 0; i < arrayBotoes.length; i++) {        d.writeln("<input type=button onclick='window.opener." + fnNomeCallBack + "(" + i + "); window.close();' value='" + arrayBotoes[i] + "'>");    }    d.writeln('</td></tr></table></center>');    d.writeln('</body></html>');}
