var novo = false;
var selatual;
var excluir;
var selatualconciliar1;
var selatualconciliar2;


function Dia() {
    var dataHora,xHora,xDia,dia,mes,ano,txtSaudacao;
    dataHora = new Date();
    xDia = dataHora.getDay();
    diaSemana = new Array(7);
    diaSemana[0] = "Domingo";
    diaSemana[1] = "Segunda-feira";
    diaSemana[2] = "Terça-feira";
    diaSemana[3] = "Quarta-feira";
    diaSemana[4] = "Quinta-Feira";
    diaSemana[5] = "Sexta-Feira";
    diaSemana[6] = "Sábado";
    dia = dataHora.getDate();
    mes = dataHora.getMonth();
    mesDoAno = new Array(12);
    mesDoAno[0] = "janeiro";
    mesDoAno[1] = "fevereiro";
    mesDoAno[2] = "março";
    mesDoAno[3] = "abril";
    mesDoAno[4] = "maio";
    mesDoAno[5] = "junho";
    mesDoAno[6] = "julho";
    mesDoAno[7] = "agosto";
    mesDoAno[8] = "setembro";
    mesDoAno[9] = "outubro";
    mesDoAno[10] = "novembro";
    mesDoAno[11] = "dezembro";
    ano = dataHora.getFullYear();
    document.write(diaSemana[xDia] + ",  " + dia +  " de " + mesDoAno[mes] + " de " + ano + "  ");
}

function CloseTudo() {
  // Fecha os outros menus caso abertos
   var divs = document.body.getElementsByTagName("DIV");

   for (var i = 0; divs[i]; i++)
      if (divs[i].id.charAt(0) == 'm')
        divs[i].style.display = 'none';
}

function mostramenu(id, pai) {
    var o   = document.getElementById(id);

    if (o.style.display == 'none') {
        o.style.left = pai.offsetLeft;
        o.style.top  = 40;

        // :)
        CloseTudo();
        // Abre o que clicou
        o.style.display = '';
    }
    else
        o.style.display = 'none';
}

function VerificaData(data) {
  var date = new Date();

  if (date.parse(data) == null) {
   window.alert("Data errada");
   return false;
  }

  return true;
}

function tecla(e) {
  var cod = (window.navigator.appName == "Microsoft Internet Explorer") ? e.keyCode : e.which;

  if (cod == 13)
//    if (VerificaData(document.frmfiltro.data.value))
      document.frmfiltro.submit();
}

function MostraSplit(id) {
  var img = document.getElementById("imgs" + id);
  var obj;

    for (var i = 0;; i++) {
        obj = document.getElementById(id + "_" + i);

        if (obj)
          obj.style.display = (obj.style.display == "") ? "none" : "";
        else
          break;
    }

    if (img.src.indexOf("menos.gif") == -1)
        img.src = "imgs/menos.gif";
    else
        img.src = "imgs/mais.gif";
}


function OpenWindow(sPagina, w, h, s) {

    window.open(sPagina, '', 'width=' + w + ',height=' + h + ',top=60,left=160,scrollbars=' + s + ',menubar=0,toolbar=0,statusbar=0,resizable=1');

    return false;
}

function link(saiu, o) {

  if (saiu) {
    o.style.color = 'Navy';
    o.style.cursor = 'none';
    o.style.textDecoration = 'none';
  } else {
    o.style.color = 'Gray';
    o.style.cursor = 'hand';
    o.style.textDecoration = 'underline';
  }
}


/*function SelecionarId(o, filtro) {

    if (selatual)
       selatual.style.backgroundColor = "#EFEFEF";
    
    o.style.backgroundColor = "#FFF3C6";
    selatual = o;
    if (filtro)
       filtro.value = selatual.id.slice(1);
}*/

function SelecionarId(o, filtro, contador, valor) {
    if (selatual)
       selatual.style.backgroundColor = "#EFEFEF";
    o.style.backgroundColor = "#FFF3C6";
    selatual = o;
    if (filtro)
       filtro.value = selatual.id.slice(1);
    if (contador)
       contador.value =  valor;  
    
}

function setParametros(filtro, contador, valor, id) {
    
    selatual = document.getElementById(id);
    if (filtro)
       filtro.value = selatual.id.slice(1);
    if (contador)
       contador.value =  valor;  
    
}
function SelecionarIdConciliar1(oc1, filtro) {

    if (selatualconciliar1)
       selatualconciliar1.style.backgroundColor = "#EFEFEF";
    if (selatualconciliar1 == oc1){
        oc1.style.backgroundColor = "#EFEFEF";
        selatualconciliar1 = null;
    }else{
        oc1.style.backgroundColor = "#FFF3C6";
        selatualconciliar1 = oc1;
    }
    if (filtro)
       filtro.value = selatualconciliar1.id;
}

function SelecionarIdConciliar2(oc2, filtro) {

   var tam;    
   if (oc2.style.backgroundColor == "#fff3c6"){
        selatualconciliar2 = oc2;
        oc2.style.backgroundColor = "#EFEFEF";    
        if(filtro){
              if (filtro.value.indexOf("|") != -1){
                  tam = filtro.value.length;             
                  filtro.value = filtro.value.replace("|"+selatualconciliar2.id, "");
                  if(tam == filtro.value.length)
                      filtro.value = filtro.value.replace(selatualconciliar2.id, "");  
              }else{
                  filtro.value = filtro.value.replace(selatualconciliar2.id, "");
              }
        }
        
    }else{
        oc2.style.backgroundColor = "#FFF3C6";
        selatualconciliar2 = oc2; 
        if(filtro){
           if (filtro.value.length > 0){
              filtro.value = filtro.value + "|" +selatualconciliar2.id;
              //window.alert("filtro.value = "+filtro.value);
           }else{
              filtro.value = filtro.value + selatualconciliar2.id;
              //window.alert("filtro.value = "+filtro.value); 
           }
        }
    }
    
    //if (selatualconciliar2 == oc2){
    //    oc2.style.backgroundColor = "#EFEFEF";
    //    selatualconciliar2 = null;
    //}else{
    //    oc2.style.backgroundColor = "#FFF3C6";
    //    selatualconciliar2 = oc2;
    //}
    
    
    
    
}

function SelecionarIdConciliar3(oc2, filtro) {

    if (selatualconciliar1)
        selatualconciliar1.style.backgroundColor = "#EFEFEF";
    if (selatualconciliar2 == oc2){
        oc2.style.backgroundColor = "#EFEFEF";
        selatualconciliar2 = null;
    }else{
        oc2.style.backgroundColor = "#FFF3C6";
        selatualconciliar2 = oc2;
    }
    if (filtro)
        filtro.value = selatualconciliar2.id;
    
}
function SelecionarDescricao() {
  var valor;
  var id;
  valor = parent.document.conta.combodescricao.value;
  id =  valor.substring(0,valor.indexOf("|"));
  valor = valor.substring(valor.indexOf("|")+1);
  //parent.document.conta.combodescricao.value = id;
  parent.document.conta.descricao.value = valor;
  if (valor != "")
    parent.document.conta.descricao.readonly = true;  
  return true;
}

function Enviar(formulario) {

 if (selatual) {
    var param = selatual.id.slice(1);
    formulario.hdnfiltro.value = param;
 }
 else  {
     window.alert("Selecione um item.");
     return false;
 }

 return true;
}

function ValSel(filtro){

  if (!filtro)
    return true;

  if (filtro.value == "" && !novo) {
    window.alert("Selecione um item.");
    return false;
  }

  if (excluir) {
    if (!window.confirm("Tem certeza que deseja excluir este item?")) {
        return false;
    }
  }
  return true;
}

function ValSelConciliacao(botao, filtro1 , filtro2){

  if (!filtro)
    return true;

  if (filtro.value == "" && !novo) {
    window.alert("Selecione um item.");
    return false;
  }

  if (excluir) {
    if (!window.confirm("Tem certeza que deseja excluir este item?")) {
        return false;
    }
  }
  return true;
}

function ValSelConciliar1(filtro){

  if (!filtro)
    return true;

  if (filtro.value == "" && !novo) {
    window.alert("Selecione um item.");
    return false;
  }

  if (excluir) {
    if (!window.confirm("Tem certeza que deseja excluir este item?")) {
        return false;
    }
  }
  return true;
}

function ValSelConciliar2(filtro){
  if (!filtro)
    return true;
  if (filtro.value == "" && !novo) {
    window.alert("Selecione um item.");
    return false;
  }
  if (excluir) {
    if (!window.confirm("Tem certeza que deseja excluir este item?")) {
        return false;
    }
  }
  return true;
}

function AlertBusinesss(){
  window.alert("Não é possível excluir o item selecionado, pois esse item é uma tranferência do Business.");
  return true;
}

function OpenWindowParameter(pag, w, h, scroll, filtro) {

  if (!ValSel(filtro))
    return false;

  var texto;

  texto = escape(filtro.value);
  pag += "?filtro=" + texto;

  OpenWindow(pag, w, h, scroll);
}

function OpenWindowParameters(pag, w, h, scroll, tipo, filtro, filtro1, filtro2, datai) {

  if (!ValSel(filtro))
    return false;
  
  var texto, texto1;
  texto = escape(filtro.value);
  texto1 = escape(filtro2.value);
  
  pag += "?filtro=" + texto + "&filtro1=" + filtro1.value + "&filtro2=" + texto1 + "&"+tipo.name+"=" + tipo.value+"&datai="+datai;
  
  OpenWindow(pag, w, h, scroll);
}

function AtualizarParent(pag) {
    top.opener.window.location = pag;
    return true;
}

function ValidarFiltro(form) {
    //form.
    return true;
}

function PreparaControl() {

    if (document.forms[0].tipo.selectedIndex == 0) {
        document.forms[0].datai.value = "";
        document.forms[0].seldata.selectedIndex = -1;
    }

    return true;
}

function DebCred(obj) {

    if (obj.name == "debito")
        document.forms[0].credito.value = "";
    else
        document.forms[0].debito.value = "";

    return;
}

function Excluir(excl) {
 excluir = excl;
 return;
}

function Novo(nv) {
    novo = true;
    return;
}

function MostraMsg(msg){
    if (!window.confirm(msg)) {
        return false;
    }
    return true;
}
   
function SetTabColors(TheSelectedTab)
{
	var TabBorderStyle="outset"
	var TabBorderColor="white"
	var TabBorderWidth=0
	
	var UNSELECTED_COLOR = 'white'
	var SELECTED_COLOR = 'white'
	
	var ITab = Tab1.style
	var PTab = Tab2.style
        var OTab = Tab3.style
	
	// RESET ALL TABS TO A DEFAULT STYLE
	Tab1.bgColor=UNSELECTED_COLOR
	Tab1.style.fontWeight=400
	Tab1.style.color = "black"
	
	Tab2.bgColor=UNSELECTED_COLOR
	Tab2.style.fontWeight=400
	Tab2.style.color = "black"
      
        Tab3.bgColor=UNSELECTED_COLOR
	Tab3.style.fontWeight=400
	Tab3.style.color = "black"
	
	// CHANGE THE SELECTED TAB
	TheSelectedTab.style.color = "black"
	TheSelectedTab.bgColor = SELECTED_COLOR
	TheSelectedTab.style.fontWeight=700
	
	switch(TheSelectedTab)
	{
		case Tab1:
			// SET MOUSE CURSOR LOOK
			ITab.cursor="default"
			PTab.cursor="hand"
                        OTab.cursor="hand"
		
			// SET THE PANELS TO BE HIDDEN OR DISPLAYED
			PanelForTab1.style.visibility="visible"
			PanelForTab2.style.visibility="hidden"
                        PanelForTab3.style.visibility="hidden"
			
			// SET TAB LOOK
			ITab.borderRightStyle=ITab.borderLeftStyle=ITab.borderTopStyle=""
			ITab.borderRightColor=ITab.borderLeftColor=ITab.borderTopColor=""
			ITab.borderRightWidth=ITab.borderLeftWidth=ITab.borderTopWidth=0
			
			PTab.borderRightStyle=PTab.borderLeftStyle=PTab.borderTopStyle=TabBorderStyle
			PTab.borderRightColor=PTab.borderLeftColor=PTab.borderTopColor=TabBorderColor
			PTab.borderRightWidth=PTab.borderLeftWidth=PTab.borderTopWidth=TabBorderWidth
                       
                        OTab.borderRightStyle=OTab.borderLeftStyle=OTab.borderTopStyle=TabBorderStyle
			OTab.borderRightColor=OTab.borderLeftColor=OTab.borderTopColor=TabBorderColor
			OTab.borderRightWidth=OTab.borderLeftWidth=OTab.borderTopWidth=TabBorderWidth
		
			break;
		
		case Tab2:
			// SET MOUSE CURSOR LOOK
			ITab.cursor="hand"
			PTab.cursor="default"
                        OTab.cursor="hand"
			
			// SET THE PANELS TO BE HIDDEN OR DISPLAYED
			PanelForTab1.style.visibility="hidden"
			PanelForTab2.style.visibility="visible"
                        PanelForTab3.style.visibility="hidden"
			
			// SET TAB LOOK
			PTab.borderRightStyle=PTab.borderLeftStyle=PTab.borderTopStyle=""
			PTab.borderRightColor=PTab.borderLeftColor=PTab.borderTopColor=""
			PTab.borderRightWidth=PTab.borderLeftWidth=PTab.borderTopWidth=0
			
			ITab.borderRightStyle=ITab.borderLeftStyle=ITab.borderTopStyle=TabBorderStyle
			ITab.borderRightColor=ITab.borderLeftColor=ITab.borderTopColor=TabBorderColor
			ITab.borderRightWidth=ITab.borderLeftWidth=ITab.borderTopWidth=TabBorderWidth
                       
                        OTab.borderRightStyle=OTab.borderLeftStyle=OTab.borderTopStyle=TabBorderStyle
			OTab.borderRightColor=OTab.borderLeftColor=OTab.borderTopColor=TabBorderColor
			OTab.borderRightWidth=OTab.borderLeftWidth=OTab.borderTopWidth=TabBorderWidth
					
			break;

                 case Tab3:
			// SET MOUSE CURSOR LOOK
			ITab.cursor="hand"
			PTab.cursor="hand"
                        OTab.cursor="default" 
			
			// SET THE PANELS TO BE HIDDEN OR DISPLAYED
			PanelForTab1.style.visibility="hidden"
			PanelForTab2.style.visibility="hidden"
                        PanelForTab3.style.visibility="visible"
			
			// SET TAB LOOK
			OTab.borderRightStyle=OTab.borderLeftStyle=OTab.borderTopStyle=""
			OTab.borderRightColor=OTab.borderLeftColor=OTab.borderTopColor=""
			OTab.borderRightWidth=OTab.borderLeftWidth=OTab.borderTopWidth=0
			
			ITab.borderRightStyle=ITab.borderLeftStyle=ITab.borderTopStyle=TabBorderStyle
			ITab.borderRightColor=ITab.borderLeftColor=ITab.borderTopColor=TabBorderColor
			ITab.borderRightWidth=ITab.borderLeftWidth=ITab.borderTopWidth=TabBorderWidth
                        
                        PTab.borderRightStyle=PTab.borderLeftStyle=PTab.borderTopStyle=TabBorderStyle
			PTab.borderRightColor=PTab.borderLeftColor=PTab.borderTopColor=TabBorderColor
			PTab.borderRightWidth=PTab.borderLeftWidth=PTab.borderTopWidth=TabBorderWidth
					
			break;
	}
}