function imgIn(obj, nome) {
	obj.src = "/imagens/menu/over" + nome;
}

function imgOut(obj, nome) {
	obj.src = "/imagens/menu/out" + nome;
}

function sortSelect(obj){
    var o = new Array();
    for (var i=0; i<obj.options.length; i++){
        o[o.length] = new Option(obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected);
    }
    o = o.sort(
        function(a,b){ 
            if ((a.text+"") < (b.text+"")) { return -1; }
            if ((a.text+"") > (b.text+"")) { return 1; }
            return 0;
        } 
    );

    for (var i=0; i<o.length; i++){
        obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
    }
}

function strToFloat(value) {
    value = strReplace(value, ".", "");
    value = (strReplace(value, ",", ".")*1);
    return value;
}

function testKey(obj, eve) {
    var keyPode = '48,49,50,51,52,53,54,55,56,57,58,59';
    if ((eve.keyCode == 46 || eve.keyCode == 44) && (obj.value.indexOf(',') == -1)) {
        eve.keyCode = 44
        return true;
    }
    if (keyPode.indexOf(eve.keyCode) != -1) {
        return true;
    }
    return false
}

function formatFloat(value) {
    if (value == 0)
    return "0,00";
    value = value.toString();

    if (value == parseFloat(value)) {
        value = strReplace(value, ".", ",");
    }
    else {
        value = strReplace(value, ".", "");
    }

    Dec = '00';
    Int = '0';
    if (value.indexOf(',') != -1) {
        Int = value.substring(0, value.indexOf(','));
        Dec = value.substring(value.indexOf(',') + 1);
    }
    else {
        Int = value;
    }

    if (Dec.length > 2) {
        Dec = Dec.substring(0, 2);
    }
    else {
        while (Dec.length < 2)
        Dec += '0';
    }

    Int = (Int*1);
    Int = Int.toString();
    aux = '';
    for (x = 1 ; x <= Int.length; x++) {
        sep = (((x % 3) == 0) && (x != Int.length))?'.':'';
        aux = sep + (Int.substring(Int.length - x, Int.length - x+1)) + aux;
    }
    Int = aux;

    return (Int + ',' + Dec);
}

function strReplace(value, antStr, newStr) {
    value = value.toString();
    while (value.indexOf(antStr) != -1) {
        value = value.replace(antStr, newStr);
    }
    return value;
}

function testFloat(obj) {
    if (!obj.value)
    return;

    val2 = strToFloat(obj.value);
    val1 = parseFloat(val2)
    if ((val1*1) != (val2*1)) {
        alert("Valor inválido!")
        obj.focus();
        obj.select();
    }
}

function processandoOpen() {
    div_aguarde.style.top  = 0;
    div_aguarde.style.left = (document.body.clientWidth) - 150;
    div_aguarde.style.visibility = '';
}

function processandoClose() {
    div_aguarde.style.visibility = 'hidden';
}

function findObj(n, d) {
    //n4 - n6 - ie5 - opera
    if (window.mmIsOpera)
    return (document.getElementById(n));

    if (document.all)
    return (document.all[n]);

    if (document.getElementById) {
        if (document.getElementById(n))
        return (document.getElementById(n));
    }

    if (document.getElementsByName) {
        if (document.getElementsByName(n)[0])
        return document.getElementsByName(n)[0];
    }

    var p,i,x;
    if (!d)
    d=document;
    if ((p=n.indexOf("?"))>0 && parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }

    if (!(x=d[n])&&d.all)
    x=d.all[n];

    for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];

    return x;
}

function pula(nc, cam, pcam) {
    if(cam.value.length == nc) {
        document.all[pcam].focus();
    }
}

function seTecla(event, tcl, comando) {
    var tecla;
    if (navigator.appName.indexOf("Netscape")!= -1)
        tecla = event.which;
    else
        tecla = event.keyCode;
    key = String.fromCharCode(tecla);
    if (tecla == tcl)
        eval(comando);                
}

function isNum(caractere) {
    var strValidos = "0123456789"
    if (strValidos.indexOf(caractere) == -1)
        return false;
    return true;
}

function onExitCPF(obj) {
    obj.value=deixaSoNumero(obj.value);
    if (obj.value.length>0)  {
        var valido = valida_CPF(obj);
        if (valido) {
            FormataCPF(obj);
        }
        else {
            obj.select();
            obj.focus();
        }
    }
}

function validaTecla(campo, event) {
    var BACKSPACE = 8;
    var TAB = 0;
    var key;
    var tecla;
    CheckTAB = true;
    if (navigator.appName.indexOf("Netscape")!= -1)
        tecla = event.which;
    else
        tecla = event.keyCode;
    key = String.fromCharCode(tecla);
    if (tecla == 13)
        return false;
    else
    if (tecla == BACKSPACE)
        return true;
    else
    if (tecla == TAB)
        return true;
    else
        return (isNum(key));
}

function deixaSoNumero(Data) {
    val = '';
    for (x = 0; x < Data.length; x++) {
        if (Data.charAt(x)=='0')
            val+=Data.charAt(x);
        else
            if (parseInt(Data.charAt(x)))
        val+=Data.charAt(x);
    }
    return(val)
}

function Mascarar_Data(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
	}
}

function dataBr2Db(dat, hor) {
    retorno  = dat.substring(6, 10);
    retorno += dat.substring(3, 5);
    retorno += dat.substring(0, 2);
    retorno += hor.substring(0, 2);
    retorno += hor.substring(3, 5);

    return retorno;
}

function BuscaCombo(in_sFormName, in_sInputName, in_sSelectName){
	sSearchString = document.forms[in_sFormName].elements[in_sInputName].value.toUpperCase();
	iSearchTextLength = sSearchString.length;

    if(document.forms[in_sFormName].onde.value == 1) {
        for (j=0; j < document.forms[in_sFormName].elements[in_sSelectName].options.length; j++){
            sOptionText = document.forms[in_sFormName].elements[in_sSelectName].options[j].text;
            sOptionComp = sOptionText.substr(0, iSearchTextLength).toUpperCase();

            if(sSearchString == sOptionComp){
                document.forms[in_sFormName].elements[in_sSelectName].selectedIndex = j;
                break;
            }
        }
    }
    else if(document.forms[in_sFormName].onde.value == 2) {
        for (j=0; j < document.forms[in_sFormName].elements[in_sSelectName].options.length; j++){
            sOptionText = document.forms[in_sFormName].elements[in_sSelectName].options[j].text;

            if(sOptionText.indexOf(sSearchString) != -1){
                document.forms[in_sFormName].elements[in_sSelectName].selectedIndex = j;
                break;
            }
        }
    }
}
