function comboChange(comoBox,usado){
  window.location.href = comoBox.options[comoBox.selectedIndex].value;
  if (usado) comoBox.selectedIndex=0;
}
/*function Abre2(url, width, height)
{
    window.open(url,"_parent","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height)
}
function Fun_Enviar(formID, h, id_enq)
{
    alert(document.forms[0].opcao.length);
    formularios = document.forms.length;
    for(i=0;i<formularios;i++)
    {
        if(document.forms[i].name==formID)
        {
            formulario = i;
            break;
        }
    }
    num_respostas = document.forms[formulario].opcao.length;
    resposta = num_respostas;
    respostas = "";
    for(i=0;i<num_respostas;i++)
    {
        if(document.forms[formulario].opcao[i].checked)
        {
            resposta = i;
            if(respostas)
            {
                respostas=respostas + "&";
            }
            else
            {
                respostas=respostas + "?";
            }
            respostas=respostas + "opcao=" + document.forms[formulario].opcao[i].value;
        }
    }
    if(resposta==num_respostas)
    {
        alert("Uma opção deve ser escolhida!");
    }
    else
    {
        Abre("enq.php" + respostas + "id=" + id_enq,450,h);
    }
}

function Fun_Enviar_Pop(formID)
{
    formularios = document.forms.length;
    for(i=0;i<formularios;i++)
    {
        if(document.forms[i].name==formID)
        {
            formulario = i;
            break;
        }
    }
    num_respostas = document.forms[formulario].opcao.length;
    resposta = num_respostas;
    respostas = "";
    for(i=0;i<num_respostas;i++)
    {
        if(document.forms[formulario].opcao[i].checked)
        {
            resposta = i;
            if(respostas)
            {
                respostas=respostas + "&";
            }
            else
            {
                respostas=respostas + "?";
            }
            respostas=respostas + "opcao=" + document.forms[formulario].opcao[i].value;
        }
    }
    if(resposta==num_respostas)
    {
        alert("Uma opção deve ser escolhida!");
    }
    else
    {
        Abre2("enq.php" + respostas + "id=" + id_enq,450,h);
    }
}
*/

function FormataValor(campo,tammax,teclapres) {

    var tecla = teclapres.keyCode;
    var vr = campo.value;
    vr = vr.replace( "-", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    tam = vr.length;

    if (tam < tammax && tecla != 13){ tam = vr.length + 1 ; }

    if (tecla == 13 ){	tam = tam - 1 ; }

    if ( tecla == 13 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) ){
        if ( tam <= 2 ){
            campo.value = vr ; }
            tam = tam - 1;
            if ( (tam > 2) && (tam <= 5) ){
                campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
                if ( (tam >= 6) && (tam <= 8) ){
                    campo.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
                    if ( (tam >= 9) && (tam <= 11) ){
                        campo.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
                        if ( (tam >= 12) && (tam <= 14) ){
                            campo.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }

    }
}
function adjust_popup()
{
    var w, h, fixedW, fixedH, diffW, diffH;

    if (document.all) {
        fixedW = document.body.clientWidth;
        fixedH = document.body.clientHeight;
        window.resizeTo(fixedW, fixedH);
        diffW = fixedW - document.body.clientWidth;
        diffH = fixedH - document.body.clientHeight;
    } else {
        fixedW = window.innerWidth;
        fixedH = window.innerHeight;
        window.resizeTo(fixedW, fixedH);
        diffW = fixedW - window.innerWidth;
        diffH = fixedH - window.innerHeight;
    }
    w = fixedW + diffW;
    h = fixedH + diffH;
    if (h >= screen.availHeight) w += 16;
    if (w >= screen.availWidth)  h += 16;
    w = Math.min(w,screen.availWidth);
    h = Math.min(h,screen.availHeight);
    window.resizeTo(w,h);
    window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}
function conecta()
{
    document.getElementById("conecta").innerHTML = "Conectando ao Servidor...";
}
function inicia_depto(tipo)
{
    i = document.getElementById('filial');
    if(!tipo)
    {
        i.disabled = true;
    }
}
function escolhe_depto(tipo)
{
    i = document.getElementById('filial');
    a = document.getElementById('m_f');
    if(tipo == 'F')
    {
        i.disabled = false;
    }
    else
    {
        i.disabled = true;
    }
    if(a.value == 'M')
    {
        i.disabled = true;
    }
    else
    {
        i.disabled = false;
    }

}
function escreve_no_form(empresa,id,tipo_empresa)
{
    window.opener.document.getElementById('empresa').value = empresa;

    window.opener.document.getElementById('id_idempresa').value = id;
    
    window.opener.document.getElementById('tipo').value = tipo_empresa;
    
    if(tipo_empresa == 'O')
    {
        window.opener.document.form_users.departamento.disabled = false;
    }
    else
    {
        window.opener.document.form_users.departamento.disabled = true;
    }
    self.close();
}

function valida_sac(campo)
{
    if (campo.value = '') {
        alert("O campo sacado não pode estar vazio!");
        campo.focus();
        return false;
    }
}
function max(txarea)
{
    total = 600;
    tam = txarea.value.length;
    str="";
    str=str+tam;

    Restante.innerHTML = total - str;

    if (tam > total){

        aux = txarea.value;
        txarea.value = aux.substring(0,total);
        Restante.innerHTML = 0
    }
}
function emoticon(text) {
    var txtarea = document.mural.comentario;
    text = ' ' + text + ' ';
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
        txtarea.focus();
    }
    else {
        txtarea.value  += text;
        txtarea.focus();
    }
}
function limita_busca(form_busca)
{
    if (form_busca.palavra.value.length <= 3)
    {
        alert("O campo Busca deve ter no minimo 4 caracteres !!!")
        form_busca.palavra.value='';
        form_busca.palavra.focus()
        return (false);
    }
}
function prod_vazio(form_prod)
{
    if (form_prod.prod.value.length == 'P')
    {
        alert("Você deve escolher um produto!!!")
        form_prod.prod.focus()
        return (false);
    }
}
function mOvr(src,clrOver) {
    if (!src.contains(event.fromElement)) {
        src.style.cursor = 'hand';
        src.bgColor = clrOver;
    }
}
function mOut(src,clrIn) {
    if (!src.contains(event.toElement)) {
        src.style.cursor = 'default';
        src.bgColor = clrIn;
    }
}
function mClk(src) {
    if(event.srcElement.tagName=='TD')
    src.children.tags('A')[0].click();
}
// -->
function novajanela(link) { //v2.0
window.open(link,'janela','width=400,height=150,top=150,left=150');
}
function abrejanela(link, nome, w, h, t, l) { //v2.0
window.open(link,nome,'width='+w+',height='+h+', top='+t+',left='+l+',scrollbars=yes');
}
function newindow(link) { //v2.0
window.open(link,'window','width=190,height=100,top=150,left=150');
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
function clearText(thefield){if(thefield.defaultValue==thefield.value)
thefield.value=""}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function fechar_janela(x,y) {
    alert(x)
    window.location.replace(y);

}

var menuskin = "skin1";
var display_url = 0;
function showmenuie5() {
    var rightedge = document.body.clientWidth-event.clientX;
    var bottomedge = document.body.clientHeight-event.clientY;
    if (rightedge < ie5menu.offsetWidth)
    ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
    else
    ie5menu.style.left = document.body.scrollLeft + event.clientX;
    if (bottomedge < ie5menu.offsetHeight)
    ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
    else
    ie5menu.style.top = document.body.scrollTop + event.clientY;
    ie5menu.style.visibility = "visible";
    return false;
}
function hidemenuie5() {
    ie5menu.style.visibility = "hidden";
}
function highlightie5() {
    if (event.srcElement.className == "menuitems") {
        event.srcElement.style.backgroundColor = "highlight";
        event.srcElement.style.color = "white";
        if (display_url)
        window.status = event.srcElement.url;
    }
}
function lowlightie5() {
    if (event.srcElement.className == "menuitems") {
        event.srcElement.style.backgroundColor = "";
        event.srcElement.style.color = "black";
        window.status = "";
    }
}
function jumptoie5() {
    if (event.srcElement.className == "menuitems") {
        if (event.srcElement.getAttribute("target") != null)
        window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
        else
        window.location = event.srcElement.url;
    }
}

function prod_vazio(form_prod)
{
    if (input.value.length == '')
    {
        alert("Você deve escolher um produto!!!")
        input.focus()
        return (false);
    }
}

function fechar_janela(x,y) {
    alert(x)
    window.location.replace(y);

}

function confirmar()
{
    if (confirm ("Você deseja mesmo excluir o registro?"))
    return true
    else
    return false
}

function validaChar(obj,e){
    var keypress = window.event.keyCode;
    if ((keypress != 13 && keypress < 48) || keypress > 57 )
    return false;

    return true;
}

function validadata(obj,e){
    var keypress = window.event.keyCode;
    if ((keypress != 47 && keypress < 48) || keypress > 57 )
    return false;

    return true;
}

function validaForm(){
    if (        document.form_login.ddd.value.length<2
    ||        document.form_login.numero.value.length<8
    ||        document.form_login.senha.value.length<4
    )
    return false;

    return true;
}


// Script Tab automatico para formularios//
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
    function containsElement(arr, ele) {
        var found = false, index = 0;
        while(!found && index < arr.length)
        if(arr[index] == ele)
        found = true;
        else
        index++;
        return found;
    }
    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;

}